Skip to content

Commit

Permalink
Merge bitcoindevkit#1581: Allow custom fallback algorithm for bnb
Browse files Browse the repository at this point in the history
65be4ea test(coin_selection): add test for deterministic utxo selection (Steve Myers)
c18204d feat(wallet)!: allow custom fallback algorithm for bnb (志宇)

Pull request description:

  ### Description

  This allows the caller to set a custom fallback algorithm when using `BranchAndBoundCoinSelection`. Previously, you were forced into using `SingleRandomDraw`.

  Signature of `CoinSelectionAlgorithm::coin_select` has been changed to take in a `&mut RangCore`. This allows us to pass the random number generator directly to the cs algorithm.

  Single random draw is now it's own type `SingleRandomDraw` and impls `CoinSelectionAlgorithm`.

  `BranchAndBoundCoinSelection` now handles it's own fallback algorithm internally, and a generic type parameter is added to specify the fallback algorithm.

  `coin_selection::Error` is renamed to `InsufficientFunds` and the BnB error variants are removed. The BnB error variants are no longer needed since those cases are handled internally by `BranchAndBoundCoinSelection` (via calling the fallback algorithm).

  ### Notes to the reviewers

  This is breaking change. Not sure how useful this is for our users. If it's deemed useful, consider including in beta.

  ### Changelog notice

  * Changed `CoinSelectionAlgorithm::coin_select` to take in an additional `&mut RangCore` variable. This allows us to pass a random number generator directly to the cs algorithm.
  * Added `SingeRandomDraw` type which impls `CoinSelectAlgorithm`.
  * Changed `BranchAndBoundCoinSelection` to call the fallback internally. An additional generic parameter is added set this.
  * Changed `coin_selection::Error` to `coin_selection::InsufficientFunds` (which is now a struct) and therefore removing bnb error variants.

  ### Checklists

  #### All Submissions:

  * [x] I've signed all my commits
  * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md)
  * [x] I ran `cargo fmt` and `cargo clippy` before committing

ACKs for top commit:
  oleonardolima:
    utACK 65be4ea
  evanlinjin:
    self-ACK 65be4ea

Tree-SHA512: 3699b65dd3e9b20ad5872a05321a54d0ece61ad582eabe340d4dafbf971cf23bf46b0daa7d1284ec7bc7472d52d54cfa592c9e869ace6e35b8a9dc6938c297a3
  • Loading branch information
evanlinjin committed Sep 12, 2024
2 parents 9020f44 + 65be4ea commit 1b50d88
Show file tree
Hide file tree
Showing 4 changed files with 347 additions and 174 deletions.
Loading

0 comments on commit 1b50d88

Please sign in to comment.