From d2d37fc06d3b70470a48b099ac070dd773faf9cf Mon Sep 17 00:00:00 2001 From: Tobin Harding Date: Thu, 8 Jul 2021 11:56:05 +1000 Subject: [PATCH] Return early if required UTXOs already big enough If the required UTXO set is already bigger (including fees) than the amount required for the transaction we can return early, no need to go through the BNB algorithm or random selection. --- src/wallet/coin_selection.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/wallet/coin_selection.rs b/src/wallet/coin_selection.rs index 978f3d16..1dcc2c9e 100644 --- a/src/wallet/coin_selection.rs +++ b/src/wallet/coin_selection.rs @@ -345,6 +345,14 @@ impl CoinSelectionAlgorithm for BranchAndBoundCoinSelection { .try_into() .expect("Bitcoin amount to fit into i64"); + if curr_value > actual_target { + return Ok(BranchAndBoundCoinSelection::calculate_cs_result( + vec![], + required_utxos, + fee_amount, + )); + } + Ok(self .bnb( required_utxos.clone(),