Skip to content

Commit

Permalink
Calculate cost_of_change
Browse files Browse the repository at this point in the history
Instead of passing the cost_of_change param, calculate the cost of
creating a change output using InputWeightPrediction.
  • Loading branch information
yancyribbens committed Feb 21, 2024
1 parent 30886e6 commit 75ff46e
Show file tree
Hide file tree
Showing 3 changed files with 205 additions and 87 deletions.
7 changes: 3 additions & 4 deletions benches/coin_selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ use bitcoin::FeeRate;
use bitcoin::ScriptBuf;
use bitcoin::TxOut;
use bitcoin::Weight;

use bitcoin::transaction::InputWeightPrediction;
use rust_bitcoin_coin_selection::select_coins_bnb;
use rust_bitcoin_coin_selection::WeightedUtxo;

pub fn criterion_benchmark(c: &mut Criterion) {
// https://github.com/bitcoin/bitcoin/blob/f3bc1a72825fe2b51f4bc20e004cef464f05b965/src/wallet/coinselection.h#L18
let cost_of_change = Amount::from_sat(50_000);

let one = WeightedUtxo {
satisfaction_weight: Weight::ZERO,
utxo: TxOut { value: Amount::from_sat(1_000), script_pubkey: ScriptBuf::new() },
Expand All @@ -30,7 +29,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
b.iter(|| {
let result: Vec<_> = select_coins_bnb(
black_box(target),
black_box(cost_of_change),
black_box(InputWeightPrediction::P2WPKH_MAX),
black_box(FeeRate::ZERO),
black_box(FeeRate::ZERO),
black_box(&utxo_pool),
Expand Down
Loading

0 comments on commit 75ff46e

Please sign in to comment.