-
Notifications
You must be signed in to change notification settings - Fork 27
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
Open
ValuedMammal
wants to merge
5
commits into
bitcoindevkit:master
Choose a base branch
from
ValuedMammal:feat/lock-unspent
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+385
−3
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
cbaeecf
feat!: Enable persistent utxo locking
ValuedMammal 13e024d
clippy: increase allowable error and enum size
ValuedMammal 3113509
feat: Add `list_locked_unspent`
ValuedMammal 618f2fa
ref(changeset): rename constant `WALLET_OUTPOINT_LOCK_TABLE_NAME`
ValuedMammal cfac1aa
feat: Add `wallet::locked_outpoints::ChangeSet`
ValuedMammal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# TODO fix, see: https://rust-lang.github.io/rust-clippy/master/index.html#large_enum_variant | ||
enum-variant-size-threshold = 1032 | ||
enum-variant-size-threshold = 2048 | ||
# TODO fix, see: https://rust-lang.github.io/rust-clippy/master/index.html#result_large_err | ||
large-error-threshold = 993 | ||
large-error-threshold = 2048 |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
//! Module containing the locked outpoints change set. | ||
|
||
use bdk_chain::Merge; | ||
use bitcoin::OutPoint; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use crate::collections::BTreeMap; | ||
|
||
/// Represents changes to locked outpoints. | ||
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)] | ||
pub struct ChangeSet { | ||
/// The lock status of an outpoint, `true == is_locked`. | ||
pub locked_outpoints: BTreeMap<OutPoint, bool>, | ||
/// The expiration height of the lock. | ||
pub expiration_heights: BTreeMap<OutPoint, Option<u32>>, | ||
} | ||
|
||
impl Merge for ChangeSet { | ||
fn merge(&mut self, other: Self) { | ||
self.locked_outpoints.extend(other.locked_outpoints); | ||
self.expiration_heights.extend(other.expiration_heights); | ||
} | ||
|
||
fn is_empty(&self) -> bool { | ||
self.locked_outpoints.is_empty() && self.expiration_heights.is_empty() | ||
} | ||
} |
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
Oops, something went wrong.
Oops, something went wrong.
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.
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 would be the usecases for this
expiration_height
feature?If the only goal is to forget about locked outpoints if a transaction fails to be included in a block or is dropped from the mempool due to insufficient feerates, it may result in the caller creating a second transaction that is intended to replace the original payment which does not conflict the original. Now we have a situation where the original and replacement can belong in the same history resulting in double-payment. As suggested in #257, it is only safe to forget about a tx if there is a conflict which is x-confirmations deep (where x is defined by the caller, based on their assumptions).
Let me know if there is any other usecase that I am unaware of. Otherwise, I recommend removing this feature as it seems dangerous.
cc. @tnull
References:
TxBuilder
avoid previously used UTXOs (UTXO locking) #166 (comment)BroadcastQueue
#257 (comment). Note that this does not automatically "untrack" transactions if a conflict has reached x-confirmations. If automation is important, it can be implemented in a separate PR. The API would be: "automatically forget if a conflicting tx reasons x-confirmations deep". For transactions that are evicted from the mempool due to insufficient fee, the safe thing to do would be to explicitly replace, or cancel with a replacement transaction.Uh oh!
There was an error while loading. Please reload this page.
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.
Yes, I agree with everything you said. It's just that if you don't offer that API, the user will implement such a thing themselves, as at some point the user would need unlock previously-locked UTXOs for which the spend 'failed'. And usually that means that they'd do a worse job as they have less context, less access to wallet internals, and presumably less time spent thinking through the issues. So while we often tend to leave things we can't decide on to our users, it unfortunately also means that we set them up to do a worse job than us.
All that said, I agree that it might be tricky to get the API right to avoid any footguns, and maybe it could happen in a follow-up/separate PR, especially if it's undecided yet and would block this PR.
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.
The use case I had in mind was to prevent a utxo from being selected for a specific duration of time measured in blocks. As mentioned, it frees the user from having to explicitly unlock it in the future.