From: Tobin Harding Date: Thu, 8 Jul 2021 01:56:05 +0000 (+1000) Subject: Return early if required UTXOs already big enough X-Git-Tag: 0.10.0~12^2~1 X-Git-Url: http://internal-gitweb-vhost/script/%22https:/database/enum.P2shError.html?a=commitdiff_plain;h=d2d37fc06d3b70470a48b099ac070dd773faf9cf;p=bdk 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. --- 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(),