Repository navigation
feat(psbt): reject dust recipients unless allow_dust is set - #650
Open
LakshyaBagani wants to merge 2 commits into
Open
LakshyaBagani wants to merge 2 commits into
LakshyaBagani wants to merge 2 commits into
Conversation
`TxBuilder` rejects a recipient whose amount is below the dust limit with `CreateTxError::OutputBelowDustLimit`, unless `TxBuilder::allow_dust` is set. `create_psbt` and `replace_by_fee` never checked recipient amounts, so they built non-standard transactions with dust or zero-value outputs and returned no error. Add `PsbtParams::allow_dust` and a `CreatePsbtError::OutputBelowDustLimit(index)` variant. Both entry points now call `PsbtParams::check_recipients` before coin selection. It rejects an amount below the dust limit of its script, which is zero for `OP_RETURN` outputs. `allow_dust` carries over through `replace_txs`. This changes the default behaviour of the unstable `create_psbt` and `replace_by_fee` APIs. The `create_psbt` doc example sent `Amount::ZERO`, so it now sends 50 000 sats. The `AllOutputsBelowDust` doc now says it only happens in a sweep with no recipients. Part of bitcoindevkit#632.
Check that `create_psbt` accepts an amount equal to the dust limit and rejects one sat less, reporting the index of that recipient. A zero-value recipient is rejected by default and kept with `allow_dust`, and a zero-value `OP_RETURN` output needs no `allow_dust`. `replace_by_fee` applies the same rule, and `allow_dust` set before `replace_txs` carries over to the replacement. Part of bitcoindevkit#632.
Author
|
@reez @oleonardolima This pull request covers the |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Part of #632. This covers the
allow_dustparity item.TxBuilderrejects a recipient whose amount is below the dust limit unlessTxBuilder::allow_dustis set.Wallet::create_psbtandWallet::replace_by_feedid not check recipient amounts at all, so they built non-standard transactions with dust or zero-value outputs and returned no error.This pull request adds
PsbtParams::allow_dustand aCreatePsbtError::OutputBelowDustLimit(index)variant. Both entry points now check the recipients before coin selection with the same rule asTxBuilder: an amount belowScript::minimal_non_dustfor its script is rejected, andOP_RETURNoutputs have a dust limit of zero. Theallow_dustsetting carries over throughreplace_txs.Notes to the reviewers
create_psbtandreplace_by_feeAPIs. A recipient below the dust limit now returns an error unlessallow_dust(true)is set.PsbtParams::check_recipientsinbdk_wallet. Implement builder interface for SelectorParams. bdk-tx#41 plans a validating builder forSelectorParamsthat would also reject dust recipients, and I am happy to move the check there if you prefer.CreatePsbtErroris#[non_exhaustive], so adding the variant does not break the type.create_psbtdocumentation example sentAmount::ZERO, which the new check rejects, so it now sends 50 000 satoshis. TheAllOutputsBelowDustdocumentation now says it only happens in a sweep with no recipients, because recipients are never dropped.fee_absoluteparity item is not part of this pull request.RUSTFLAGS="--cfg bdk_wallet_unstable" cargo test --workspace --all-features, the stable feature test suite,cargo clippyandcargo docwith-D warningson both the stable and unstable surfaces, theno_stdchecks, andcargo fmt --all --check.Changelog notice
Wallet::create_psbtandWallet::replace_by_feenow returnCreatePsbtError::OutputBelowDustLimitwhen a recipient's amount is below the dust limit. Use the newPsbtParams::allow_dustto allow it.Before submitting