From f18086c152ffa033def8cbed52895fd1d99ffc6d Mon Sep 17 00:00:00 2001 From: Antoine Poinsot Date: Thu, 7 Dec 2023 14:46:15 +0100 Subject: [PATCH] spend: scale down the number of BnB rounds as number of candidates increases --- src/spend.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/spend.rs b/src/spend.rs index 1b89167a..d4a46b92 100644 --- a/src/spend.rs +++ b/src/spend.rs @@ -296,8 +296,8 @@ fn select_coins_for_spend( let change_policy = change_policy::min_value_and_waste(drain_weights, DUST_OUTPUT_SATS, long_term_feerate); - // Finally, run the coin selection algorithm. We use a BnB with 100k iterations and if it - // couldn't find any solution we fall back to selecting coins by descending value. + // Finally, run the coin selection algorithm. We use an opportunistic BnB and if it couldn't + // find any solution we fall back to selecting coins by descending value. let target = Target { value: out_value_nochange, feerate: FeeRate::from_sat_per_vb(feerate_vb), @@ -312,7 +312,13 @@ fn select_coins_for_spend( lowest_fee, must_have_change, }; - if let Err(e) = selector.run_bnb(lowest_fee_change_cond, 100_000) { + // Scale down the number of rounds to perform if there is too many candidates. + let bnb_rounds = match candidate_coins.len() { + i if i >= 500 => 1_000, + i if i >= 100 => 10_000, + _ => 100_000, + }; + if let Err(e) = selector.run_bnb(lowest_fee_change_cond, bnb_rounds) { log::warn!( "Coin selection error: '{}'. Selecting coins by descending value per weight unit...", e.to_string()