-
Notifications
You must be signed in to change notification settings - Fork 307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move change logic to coin_select #630
Move change logic to coin_select #630
Conversation
coin_select
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept ACK, it looks good to me! Just a couple of comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept ACK, this looks very similar to what I had in mind in terms of architecture
9cbf925
to
eb53376
Compare
Can you rebase on master to pick up the CI fixes? |
514af7d
to
504133d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking really good! I have a small comment about decide_change
, otherwise it's good to go
Edit: also it needs a rebase for conflicts
ce3c86f
to
515cc7c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you squash the two commits together plz? Then I'll ACK :)
515cc7c
to
816f6f8
Compare
08c1f34
to
b0f6a20
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tACK b0f6a20
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tACK. Just Nits
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few small comments.
Also I was thinking: do you think we should add some tests for the coin selection? I noticed that most of the tests were just updated to assume an empty drain_script and I'm actually a bit suprised none of the tests started failing (I was assuming at least some tests were asserting conditions on BDK not adding a change output, and reducing the size of the drain_script should cause them to potentially start adding one).
Can you double check if we are missing something there maybe?
They are not failing because the former code didn't make any change computations inside
So yes, I'm going to edit those empty scripts and see how I can improve the tests. |
The former way to compute and create change was inside `create_tx`, just after performing coin selection. It blocked the opportunity to have an "ensemble" algorithm to decide between multiple coin selection algorithms based on a metric, like Waste. Now, change isn't created inside `coin_select` but the change amount and the possibility to create change is decided inside the `coin_select` method. In this way, change is associated with the coin selection algorithm that generated it, and a method to decide between them can be implemented.
b0f6a20
to
32ae95f
Compare
I've pushed some changes in this branch underpinning the view that my proposal for the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 32ae95f
419dc24 test: Document `test_bump_fee_add_input_change_dust` (Daniela Brozzoni) 632daba test: Check tx feerate with longer signatures (Daniela Brozzoni) 2756411 test: Reproduce #660 conditions (Daniela Brozzoni) 50af51d test: Fix P2WPKH_FAKE_WITNESS_SIZE (Daniela Brozzoni) ae91906 Take into account the segwit tx header when... ...selecting coins (Daniela Brozzoni) 7ac87b8 TXIN_BASE_WEIGHT shouldn't include the script len (Daniela Brozzoni) ac051d7 Calculate fee amount after output addition (Daniela Brozzoni) 00d426b test: Check that the feerate is never below... ...the requested one in assert_fee_rate (Daniela Brozzoni) 42fde6d test: Check fee_amount in assert_fee_rate (Daniela Brozzoni) Pull request description: ### Description This PR mainly fixes two bugs: 1. TXIN_BASE_WEIGHT wrongly included the `script_len` (Fixes #160) 2. We wouldn't take into account the segwit header in the fee calculation, which could have resulted in a transaction with a lower feerate than the requested one 3. In tests we used to push 108 bytes on the witness as a fake signature, but we should have pushed 106 instead I also add a test to reproduce the conditions of #660, to check if it's solved. Turns out it's been solved already in #630, but if you're curious about what the bug was, here it is: #660 (comment) ### 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 #### Bugfixes: * [ ] This pull request breaks the existing API * [x] I've added tests to reproduce the issue which are now passing * [x] I'm linking the issue being fixed by this PR ACKs for top commit: afilini: ACK 419dc24 Tree-SHA512: c7b55342eac440a3607a16b94560cb9c08c4805c853432adfda8e21c5177f85d5a8afe0e7e61140e92c8f10934332459c6234fc5f1509ea699d97b1d04f030c6
Description
The former way to compute and create change was inside
create_tx
, just afterperforming coin selection.
It blocked the opportunity to have an "ensemble" algorithm to decide between
multiple coin selection algorithms based on a metric, like Waste.
Now, change is not created inside
coin_select
but the change amount and thepossibility to create change is decided inside the
coin_select
method. Inthis way, change is associated with the coin selection algorithm that generated
it, and a method to decide between them can be implemented.
Fixes #147.
Checklists
All Submissions:
cargo fmt
andcargo clippy
before committingNew Features:
CHANGELOG.md