-
Notifications
You must be signed in to change notification settings - Fork 36
feat!: Persist utxo lock status #259
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
base: master
Are you sure you want to change the base?
Conversation
Pull Request Test Coverage Report for Build 16851016230Details
💛 - Coveralls |
How do you handle UTXO locking in concurrent wallet instances? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you expand a little bit more on how this mechanism could be used in broadcast scenarios?
From the test I guess all the logic of why a UTxO becomes available again is kept by the lib user? Like unlock UTxO after a height in the future if there is not transaction spending it in the blockchain.
This is a competing solution for #257, right?
@ChidiChuks could you be a bit more specific with this question? Do you mean sharing lock status between multiple instances of the same wallet? |
@nymius My understanding is that this is NOT a competing solution with #257. UTXO-locking will not fully solve #166 as we want unbroadcasted outputs to be available for selection. In fact, UTXO-locking is already available by using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this work.
I propose adding the following methods:
list_locked_outpoints
- Lists all locked outpoints.list_locked_unspents
- Lists locked outpoints that are unspent.
Imagine a situation where the caller broadcasts a tx and locks the prevouts. Then the tx gets evicted from the mempool. It will be helpful to list locked unspents at this point to recover those prevouts.
b083dff
to
a6b0f5d
Compare
@evanlinjin I took all of your suggestions other than I think the proposed |
a6b0f5d
to
13e024d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy to see this feature moving along. In addition to helping L2 users like @tnull it also helps support one of my personal goals of improving feature parity with the bitcoin core wallet.
} | ||
|
||
/// List unspent outpoints that are currently locked. | ||
pub fn list_locked_unspent(&self) -> impl Iterator<Item = OutPoint> + '_ { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⛏️ a nit, it's a little confusing to refer to the outpoints as "unspent" here and "outpoints" in the other new functions. Since we already have the "list_unspent" function would it make sense to use "unspent" for all the related functions (ie. locked_unspent, is_unspent_locked, lock_unspent, unlock_unspent)? Even though we all know what "outpoints" mean for those unfamiliar with bitcoin internals it's not a very descriptive term.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is okay since unspent
here is short for unspent_outpoint
whereas outpoint
elsewhere is short for outpoint
s which can be unspent/spent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implementation looks good. Just need a bit more clarity on expiration_height
before ACK.
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about an unlock_all_outpoints
method? Just in case the caller needs to reset their state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since it can be expressed with the current APIs I don't think it's essential, but I'm not opposed to someone adding it in the future.
37fac7d
to
ee0a88b
Compare
wallet/src/wallet/mod.rs
Outdated
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
#[non_exhaustive] | ||
pub struct UtxoLock { | ||
/// Outpoint. | ||
pub outpoint: OutPoint, | ||
/// Whether the outpoint is locked. | ||
pub is_locked: bool, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can get away with removing this for now.
- Internally, we can use
locked_outpoints: Map<OutPoint, Option<bool>>
. - We can have
list_locked_outpoints() -> Iterator<OutPoint>
instead oflocked_outpoints() -> Map<OutPoint, UtxoLock>
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point.
892ffd0
to
a6381de
Compare
New APIs added for locking and unlocking a UTXO by outpoint and to query the locked outpoints. Locking an outpoint means that it is excluded from coin selection. - Add `Wallet::lock_outpoint` - Add `Wallet::unlock_outpoint` - Add `Wallet::is_outpoint_locked` - Add `Wallet::list_locked_outpoints` - Add `Wallet::list_locked_unspent` `test_lock_outpoint_persist` tests the lock/unlock functionality and that the lock status is persistent. BREAKING: Added `locked_outpoints` member field to ChangeSet. A SQLite migration is included for adding the locked outpoints table.
..by `Box`ing the descriptor in `LoadMismatch` enum, and by boxing the ChangeSet in `DataAlreadyExists` variant of `CreateWithPersistError`. We allow the large_enum_variant lint for `FileStoreError` for now, as it is planned to be fixed in a future version of `bdk_file_store`.
a6381de
to
d020559
Compare
Added methods on
Wallet
to lock/unlock an outpoint, to query the locked outpoints, and updated the walletChangeSet
to persist the lock status of an outpoint.fixes #166
fixes #245
Changelog notice
Added these methods to
Wallet
lock_outpoint
unlock_outpoint
list_locked_outpoints
list_locked_unspent
is_outpoint_locked
Added
wallet::locked_outpoints::ChangeSet
wallet::ChangeSet::locked_outpoints
Checklists
All Submissions:
New Features: