How bitcoin node selects the output unspent transactions when sending bitcoin?

[ad_1]

By default, Bitcoin Core will only spend foreign inputs that have at least six confirmations, and change outputs that have at least one confirmation. If you want to use younger foreign inputs, you can use the minconf parameter present e.g. on sendmany.

Beyond that, Bitcoin Core will split its UTXO pool by output type, and then for each output type uses multiple algorithms to construct one input set candidate. Among all of these candidate input sets, it chooses the least wasteful per the waste metric.

The algorithms in use in Bitcoin Core v25.1 are knapsack algorithm, single random draw, and branch and bound.

  • Knapsack will perform numerous random walks on all UTXOs with amounts lower than the target to assemble an input set that overshoots target + min_change the least, or pick the lowest larger UTXO if that is closer to target + min_change.
  • SRD will shuffle all UTXOs and pick from this shuffled list until it has collected enough funds to fund the transaction
  • BnB will attempt to find an input set that avoids creating change. If there are multiple solutions, it will prefer the least wasteful.

None of the above algorithms actually minimize the input set weight. Hence, I am proposing that we add an algorithm that minimizes the input set weight in PR#27877, which at the very least should be run at high feerates. The downside of such an algorithm would be that it could bloat a wallet’s UTXO pool when used excessively, but it would ensure an optimal outcome in the short-term. So far, this proposal has not gotten sufficient support to be added to Bitcoin Core.

There are currently no configuration options that directly affect the general coin selection behavior. You would have to perform coin selection manually or externally and build raw transactions to optimize fee expenditure.

[ad_2]

Source link

Leave a Comment