Skip to content

Feat/coin selection strategies - #151

Draft
Sosthene00 wants to merge 5 commits into
masterfrom
feat/coin_selection_strategies
Draft

Feat/coin selection strategies#151
Sosthene00 wants to merge 5 commits into
masterfrom
feat/coin_selection_strategies

Conversation

@Sosthene00

Copy link
Copy Markdown
Collaborator

No description provided.

@Sosthene00
Sosthene00 force-pushed the feat/coin_selection_strategies branch from e3ca307 to f77c5cc Compare August 12, 2026 10:34
use crate::client::{Recipient, RecipientAddress};

/// Upper bound on branch-and-bound iterations (see `bdk_coin_select` README).
const BNB_MAX_ROUNDS: usize = 10_000;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be 100_000?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for the review, 100_000 is indeed the value set in the example of the README of the coin_select project. It felt huge to me especially for the numbers of outputs we expect our users to have at once on a mobile hot wallet, so I decided to try 10_000, which already seems vastly overkill. Of course open to any rationale to set it to another value.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

100,000 is the default in bitcoin-core as well as rust-bitcoin-coinselection and also BDK coin_select as you mention. Setting it to less than that means you just get worse results. IE might not find the optimal solution.

It felt huge to me especially for the numbers of outputs we expect our users to have at once on a mobile hot wallet, so I decided to try 10_000

Have you tried bench-marking to see how it performs? There are some benchmarks you could try in bdk coin_select. I found the benchmarks in rust-bitcoin-coinselect to be much faster although I haven't investigated closely as to why.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

especially for the numbers of outputs we expect our users to have at once

Also, if you expect not many outputs, this is a non-issue, since that means BnB would simply run for less than 100,000 iterations since it would run out of combinations before hitting the iteration limit.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lastly, if you don't care about optimal results, and just want the fastest performance, you could ditch BnB and use SRD instead :)

Selecting in the pool's arbitrary order can leave a sub-dust excess
(e.g. a single big utxo barely covering the payment), forcing the
remainder into the fee although a change-creating selection exists.
Selecting smallest-first minimizes the excess, so the greedy fallback
produces a change output whenever one can be created.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants