Add Coin Selection Algos #1402
Replies: 16 comments 39 replies
-
rust-bitcoin seems more focused on strong typing for bitcoin crypto & serialization. Wallet management including coin selection seems to be more of the role of BDK, where you'll find lots of discussion about this problem already. After BDK 1.0 is released I hear rumors there will be a concerted effort to make coin selection a first class problem that BDK intends to solve. There are some musings here: bitcoindevkit/bdk#773. @evanlinjin would know more. |
Beta Was this translation helpful? Give feedback.
-
I agree that coin selection algorithms do not belong in rust-bitcoin the project. When we were talking on IRC @yancyribbens I thought you meant moving a coin selection crate into the rust-bitcoin organization, which I'd be fine with provided the crate met our requirements (mostly, being actively maintained and having a MSRV of 1.41). |
Beta Was this translation helpful? Give feedback.
-
@apoelstra when you suggested starting a discussion to include coin-selection as part of the rust bitcoin org I started the discussion here. Is there a place I should move this discussion so it's not confusing? I did intend to include coin-selection as a stand-alone repo in rust-bitcoin organization. |
Beta Was this translation helpful? Give feedback.
-
Hi all, I wanted to follow up on this discussion. It seems to me that the main objection to adding a standalone coin-selection repo to the rust-bitcoin organization is the rumor that BDK may be also working on this (or working on this in the future?). I think the other criteria have been met (active maintainer and compatible MSRV). Is there any other feedback, comments or considerations? If not, do we want to add this under the rust-bitcoin organization? |
Beta Was this translation helpful? Give feedback.
-
I added issue p2pderivatives/rust-bitcoin-coin-selection#9 with a few observations. |
Beta Was this translation helpful? Give feedback.
-
I glanced at the Branch and Bound algorithm in the https://github.com/p2pderivatives/rust-bitcoin-coin-selection repository. It seems to me that there might be some basic features missing before it should be merged into a production system. For example, I have the impression that it currently runs with the values of the UTXOs rather than the effective values. This means that the input selection will not account for the fees that the inputs need, it will be undershooting the target. I will also leave some issues on the repository to point out some additional observations. |
Beta Was this translation helpful? Give feedback.
-
I'm a bit disappointed that I didn't catch this earlier, however it's in part because the tests used worked primarily with whole numbers which I pulled from the current core implementation. If more tests with fractional inputs are considered, there are combinations of UTXO that should be found but are not. Here's the issue I created: p2pderivatives/rust-bitcoin-coin-selection#20 This will probably require a complete re-write taking into account some of @xekyo findings as well. |
Beta Was this translation helpful? Give feedback.
-
There's a new PR for SRD here: p2pderivatives/rust-bitcoin-coin-selection#23 |
Beta Was this translation helpful? Give feedback.
-
does anyone else have any suggestions before merging this? p2pderivatives/rust-bitcoin-coin-selection#23 |
Beta Was this translation helpful? Give feedback.
-
I was actually looking into coin selection recently and eventually ended up piggy backing BDK's implementation. I reached out to them about the idea of pulling some non-BDK-specific wallet-related things into the bitcoin-wallet crate that is archived now. It was kinda annoying having to use the BDK traits in order to use their impl. It could easily be generalized. But this new crate seems interesting. |
Beta Was this translation helpful? Give feedback.
-
I've merged an updated version of |
Beta Was this translation helpful? Give feedback.
-
Happy New Years all, I've created a new Rust BnB coin selection algo here: p2pderivatives/rust-bitcoin-coin-selection#28 Also of interest, I did a quick benchmark to compare this new Rust implementation vs the existing Bitcoin Core (timed on my laptop): Rust Implementation: C++ implementation: Maybe there's some Rust compiler tricks to improve the Rust implementation further? Appreciate any feedback or review. Cheers |
Beta Was this translation helpful? Give feedback.
-
I've created a new PR to change the return type of Single Random Draw: p2pderivatives/rust-bitcoin-coin-selection#33 cc @Kixunil |
Beta Was this translation helpful? Give feedback.
-
I think this interface is ready for a V1 version and can be published: interface in pub fn select_coins(
target: Amount,
cost_of_change: Amount,
fee_rate: FeeRate,
long_term_fee_rate: FeeRate,
weighted_utxos: &[WeightedUtxo],
) -> Option<std::vec::IntoIter<&WeightedUtxo>> { latest PR to cleanup interface: p2pderivatives/rust-bitcoin-coin-selection#36 @apoelstra @Kixunil does this interface seem sane? Is there any other items that should be complete before moving this over to the rust-bitcoin organization? @murchandamus friendly ping that p2pderivatives/rust-bitcoin-coin-selection#30 is still open for review. I believe this PR closes all the issues you opened. Cheers! |
Beta Was this translation helpful? Give feedback.
-
@apoelstra is this still something you would like to see done? @murchandamus was able to give it a review but I think there might be some confusion because the project is in Rust (i'm still trying to get some clarification). I believe fuzz testing or model testing could be added to show all solutions are found. The other disagreement is if this is actually a depth first search which I think can be shown that it is. Part of the issue I'm running into is that there's not really anybody that seems to know bitcoin cores implementation well enough to code review and that also has the time/knowledge of rust to offer feedback. I guess in short - any help/advice here would be greatly appreciated. |
Beta Was this translation helpful? Give feedback.
-
I'm going to go ahead and merge p2pderivatives/rust-bitcoin-coin-selection#30 since it's unlikely I'll get anymore feedback. I think it's 100x better than the previous implementation. Also the benchmark times are comparable to the bitcoin core implementation. Furthermore, I'm convinced after the review, feedback and addition of more tests, that the implementation results are correct. Thanks to all those that provided reviews so far, it's very much appreciated! |
Beta Was this translation helpful? Give feedback.
-
Bitcoin Core has a number of coin-selection strategies that are not currently represented here in rust-bitcoin. I'd like to start a discussion about adding the coin-selection algos used by Bitcoin Core to Rust Bitcoin, in particular, BnB search. To that end, I can offer an early implementation I began some time ago as a starting point.
The questions I have are:
Also note, there is a Rust coin-selection strategy in the BDK here that can also be used for inspiration and discussion.
Beta Was this translation helpful? Give feedback.
All reactions