Skip to content

feat(wallet): add functions to lock and unlock utxos - #1669

Closed
notmandatory wants to merge 1 commit into
bitcoindevkit:masterfrom
notmandatory:feat/lock_utxos
Closed

notmandatory wants to merge 1 commit into
bitcoindevkit:masterfrom
notmandatory:feat/lock_utxos

Conversation

@notmandatory

@notmandatory notmandatory commented Nov 1, 2024 •

Copy link
Copy Markdown
Contributor

Description

fixes bitcoindevkit/bdk_wallet#166

Add functions to Wallet to lock and unlock utxos. The locked TxOuts are automatically added to TxBuilder's "unspendable" list. This is just a draft to see if this approach makes sense, if so then I'll add persisting the locked utxos.

TODO

  • add locked_unspent and unlocked_unspent to Wallet::Changeset
  • check the Wallet.locked_unspent list after Wallet::apply_update and remove locked spent UTXOs
  • update store crates to persist new locked_unspent data

Notes to the reviewers

The design is based on how the core wallet locks UTXOs except I think it's simpler to always persist locked utxos. See: https://bitcoincore.org/en/doc/28.0.0/rpc/wallet/lockunspent/

Should locked UTXOs that are found to be spent be removed from the locked list after only one confirmation?

If API looks good then it won't be a breaking change so I propose this PR goes into the 1.1 milestone.

Changelog notice

  • Add wallet functions to lock and unlock UTXOs. The list of locked UTXOs is persisted with other Wallet data.

Checklists

All Submissions:

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

New Features:

  • I've added tests for the new feature
  • I've added docs for the new feature

@tnull

tnull commented Nov 1, 2024 •

Copy link
Copy Markdown
Contributor

Should locked UTXOs that are found to be spent be removed from the locked list after only one confirmation?

I think that would be reasonable, although allowing for a larger reorg threshold (usually 6 conf) might be safer?. And, while having this explicit API available is great, as previouslydiscussed, it would be great if BDK could offer a way to specify to auto-unlock the UTXOs after some (block or time) delay. Otherwise users would still need to track these UTXOs independently/outside of the Wallet and remember when to unlock them.

@notmandatory

notmandatory commented Nov 1, 2024 •

Copy link
Copy Markdown
Contributor Author

@tnull for unlocking how would you feel about having explicit functions, something like this:

  1. add Wallet::lock_unspent_until_height(outpoint: OutPoint, block_height: u32) -> bool which would lock until the given block height.
  2. add Wallet::update_locked() -> Vec<OutPoint> which would unlock locked UTXO if they have 6 confirmations or their given unlock height was reached. Would return list of unlocked UTXOs.

@luisschwab

Copy link
Copy Markdown
Contributor

Hey @notmandatory, this PR needs to be closed and moved to the new bdk_wallet repo. Here's how:

  1. From your Github account, fork https://github.com/bitcoindevkit/bdk_wallet
  2. From your local system bdk repo folder, push your PR changes to your bdk_wallet fork on Github:
    git checkout <PR branch path>
    git push [email protected]:<username>/bdk_wallet.git
    
  3. Clone to your forked bdk_wallet repo to your local system and switch to your PR branch:
    git clone [email protected]:<username>/bdk_wallet.git
    cd bdk_wallet
    git fetch origin <PR branch path>
    git checkout -b <PR branch path> FETCH_HEAD
    git rebase master
    
  4. Resolve rebase conflicts (if any)
  5. Force push your PR branch: git push origin -f
  6. Create new PR in bitcoindevkit/bdk_wallet repo from your fork branch
  7. Copy/paste title and description from your original bdk PR and add a link back to it in your new PR.
  8. Close original PR with comment that includes link to new PR.

@notmandatory

Copy link
Copy Markdown
Contributor Author

Closing this for now without moving to bdk_wallet since other approaches are being discussed for fixing this issue.

@github-project-automation github-project-automation Bot moved this from Discussion to Done in BDK Wallet Apr 23, 2025
@notmandatory
notmandatory deleted the feat/lock_utxos branch May 26, 2025 21:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module-wallet new feature New feature or request

Projects

Archived in project
Archived in project

Development

Successfully merging this pull request may close these issues.

Let TxBuilder avoid previously used UTXOs (UTXO locking)

3 participants