]> Untitled Git - bdk/commitdiff
Return early if required UTXOs already big enough
authorTobin Harding <me@tobin.cc>
Thu, 8 Jul 2021 01:56:05 +0000 (11:56 +1000)
committerTobin Harding <me@tobin.cc>
Thu, 22 Jul 2021 23:48:22 +0000 (09:48 +1000)
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

index 978f3d163b0bad20375fe4686a757462f2316246..1dcc2c9e85cdcefaa7821b941f353e8df79f4650 100644 (file)
@@ -345,6 +345,14 @@ impl<D: Database> CoinSelectionAlgorithm<D> 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(),