feat: Add lock_utxos option to prevent double-spending unbroadcasted txs - #534
Open
dorinengabdoh wants to merge 1 commit into
Open
feat: Add lock_utxos option to prevent double-spending unbroadcasted txs#534dorinengabdoh wants to merge 1 commit into
dorinengabdoh wants to merge 1 commit into
Conversation
dorinengabdoh
requested review from
ValuedMammal and
oleonardolima
as code owners
August 15, 2026 09:23
Author
|
Hi everyone, I've worked on a fix for this issue. Since BDK 3.0 already supports persistent UTXO locking via lock_outpoint, I have opened a Pull Request that introduces a lock_utxos(bool) option on both TxBuilder and PsbtParams (disabled by default to maintain backward compatibility). When enabled, it automatically locks the selected inputs of the generated transaction so that subsequent transaction creations do not double-spend them. I've also added integration tests to verify this behavior. I would love to get your feedback on the PR! |
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
Title: feat: Add lock_utxos option to prevent double-spending created transactions
Description: This PR addresses #40 by introducing an option to automatically lock the selected UTXOs (inputs) of a transaction when it is created.
Added lock_utxos option (disabled by default) to TxParams and PsbtParams.
Implemented lock_utxos(bool) builder methods on TxBuilder and PsbtParams.
Updated Wallet::create_tx and Wallet::create_psbt_with_rng to call lock_outpoint on the transaction inputs if lock_utxos is enabled.
Verification: Added the following integration tests to verify that locked UTXOs are excluded from subsequent transaction creations:
test_tx_builder_lock_utxos in tests/wallet.rs
test_create_psbt_lock_utxos in tests/create_psbt.rs
Run tests with: RUSTFLAGS="--cfg bdk_wallet_unstable" cargo test