Skip to content

feat: Add lock_utxos option to prevent double-spending unbroadcasted txs - #534

Open
dorinengabdoh wants to merge 1 commit into
bitcoindevkit:masterfrom
dorinengabdoh:fix-double-spend-issue-40
Open

feat: Add lock_utxos option to prevent double-spending unbroadcasted txs#534
dorinengabdoh wants to merge 1 commit into
bitcoindevkit:masterfrom
dorinengabdoh:fix-double-spend-issue-40

Conversation

@dorinengabdoh

Copy link
Copy Markdown

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

@dorinengabdoh

Copy link
Copy Markdown
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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant