Skip to content

Restrict drain_to usage#625

Merged
afilini merged 1 commit intobitcoindevkit:masterfrom
danielabrozzoni:620_drain_to_fix
Jun 30, 2022
Merged

Restrict drain_to usage#625
afilini merged 1 commit intobitcoindevkit:masterfrom
danielabrozzoni:620_drain_to_fix

Conversation

@danielabrozzoni
Copy link
Copy Markdown
Member

Description

Before this commit, you could create a transaction with drain_to set
without specifying recipients, nor drain_wallet, nor utxos. What would
happen is that BDK would pick one input from the wallet and send
that one to drain_to, which is quite weird.
This PR restricts the usage of drain_to: if you want to use it as a
change output, you need to set recipients as well. If you want to send
a specific utxo to the drain_to address, you specify it through
add_utxos. If you want to drain the whole wallet, you set
drain_wallet. In any other case, if drain_to is set, we return a
NoRecipients error.

Fixes #620

Checklists

All Submissions:

  • I've signed all my commits
  • I followed the contribution guidelines
  • I ran cargo fmt and cargo clippy before committing

Bugfixes:

  • This pull request breaks the existing API - kinda?
  • I've added tests to reproduce the issue which are now passing
  • I'm linking the issue being fixed by this PR

Copy link
Copy Markdown
Contributor

@csralvall csralvall left a comment

Choose a reason for hiding this comment

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

Tested ACK.

I prepared the following table to check if all the possible execution paths
including the new conditions in create_tx are tested:

x = doesn't care conditions

drain_to.is_some() drain_wallet !utxos.is_empty() drain_val.is_dust(...) Test
False x x x test_create_tx_empty_recipients
True False False False test_create_tx_drain_to_no_drain_wallet_no_utxos (NEW TEST)
True False True False test_create_tx_drain_to_and_utxos (NEW TEST) - test_bump_fee_reduce_single_recipient
True True x False test_create_tx_drain_wallet_and_drain_to
True True x True test_create_tx_absolute_high_fee - test_create_tx_drain_to_dust_amount
True False True True ?

I don't see much gain in including a test for the last case in terms of tested
functionality. However, it may worth the effort to document the possible ways
create_tx can be called.
Any test for RBF with a too high fee rate should do
the trick.

Copy link
Copy Markdown
Collaborator

@LLFourn LLFourn left a comment

Choose a reason for hiding this comment

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

ACK 098c448

Copy link
Copy Markdown
Contributor

@rajarshimaitra rajarshimaitra left a comment

Choose a reason for hiding this comment

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

tACK 098c448

Code changes looks good to me. Just one comment.

Comment thread src/wallet/mod.rs
Copy link
Copy Markdown
Contributor

@rajarshimaitra rajarshimaitra left a comment

Choose a reason for hiding this comment

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

ReAck 098c448

@notmandatory
Copy link
Copy Markdown
Member

I think this needs a rebase to pickup the "Blockchain test-rpc-legacy" CI test, then we can merge it.

@danielabrozzoni
Copy link
Copy Markdown
Member Author

Looks like Github Action got updated and now CI is broken 🔥
I'm working on it (but it might take a while) 🧯

Before this commit, you could create a transaction with `drain_to` set
without specifying recipients, nor `drain_wallet`, nor `utxos`. What would
happen is that BDK would pick one input from the wallet and send
that one to `drain_to`, which is quite weird.
This PR restricts the usage of `drain_to`: if you want to use it as a
change output, you need to set recipients as well. If you want to send
a specific utxo to the `drain_to` address, you specify it through
`add_utxos`. If you want to drain the whole wallet, you set
`drain_wallet`. In any other case, if `drain_to` is set, we return a
`NoRecipients` error.

Fixes bitcoindevkit#620
@danielabrozzoni
Copy link
Copy Markdown
Member Author

Rebased :)

Copy link
Copy Markdown
Member

@afilini afilini left a comment

Choose a reason for hiding this comment

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

ACK 6a15036

@afilini afilini merged commit 063d51f into bitcoindevkit:master Jun 30, 2022
@danielabrozzoni danielabrozzoni deleted the 620_drain_to_fix branch August 16, 2022 17:06
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.

Subtle wallet drain related to TxParams

6 participants