Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

notmandatory
Copy link
Member

@notmandatory notmandatory commented Nov 1, 2024

Description

fixes #849

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
Copy link
Contributor

tnull commented Nov 1, 2024

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
Copy link
Member Author

notmandatory commented Nov 1, 2024

@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.

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
Status: Discussion
Development

Successfully merging this pull request may close these issues.

Let TxBuilder avoid previously used UTXOs (UTXO locking)
2 participants