-
Notifications
You must be signed in to change notification settings - Fork 417
Prune locktimed packages when inputs are spent #3860
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: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -269,6 +269,9 @@ pub struct OnchainTxHandler<ChannelSigner: EcdsaChannelSigner> { | |
#[cfg(not(any(test, feature = "_test_utils")))] | ||
claimable_outpoints: HashMap<BitcoinOutPoint, (ClaimId, u32)>, | ||
|
||
#[cfg(any(test, feature = "_test_utils"))] | ||
pub(crate) locktimed_packages: BTreeMap<u32, Vec<PackageTemplate>>, | ||
#[cfg(not(any(test, feature = "_test_utils")))] | ||
locktimed_packages: BTreeMap<u32, Vec<PackageTemplate>>, | ||
|
||
onchain_events_awaiting_threshold_conf: Vec<OnchainEventEntry>, | ||
|
@@ -994,6 +997,17 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> { | |
panic!("Inconsistencies between pending_claim_requests map and claimable_outpoints map"); | ||
} | ||
} | ||
|
||
// Also remove/split any locktimed packages whose inputs have been spent by this transaction. | ||
self.locktimed_packages.retain(|_locktime, packages|{ | ||
packages.retain_mut(|package| { | ||
if let Some(p) = package.split_package(&inp.previous_output) { | ||
claimed_outputs_material.push(p); | ||
} | ||
!package.outpoints().is_empty() | ||
}); | ||
!packages.is_empty() | ||
}); | ||
} | ||
for package in claimed_outputs_material.drain(..) { | ||
let entry = OnchainEventEntry { | ||
|
@@ -1135,6 +1149,13 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> { | |
//- resurect outpoint back in its claimable set and regenerate tx | ||
match entry.event { | ||
OnchainEvent::ContentiousOutpoint { package } => { | ||
// We pass 0 to `package_locktime` to get the actual required locktime. | ||
let package_locktime = package.package_locktime(0); | ||
Comment on lines
+1152
to
+1153
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Uh, another bug found by the reorg test. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ha, nice. I jumped the gun and was also writing a test, which led to an unrelated bug in reorg handling. I hadn't gotten as far as figuring out why the <= change wasn't passing all tests, though, thanks for handling that! The test I had written I think covers all the cases yours does plus a few more, so I opened #3923 with your commit here with the test removed, and added a separate test at the end. Let me know what you think of that PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great! Feel free to close this one when ready. |
||
if package_locktime >= height { | ||
self.locktimed_packages.entry(package_locktime).or_default().push(package); | ||
whfuyn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
continue; | ||
} | ||
|
||
if let Some(pending_claim) = self.claimable_outpoints.get(package.outpoints()[0]) { | ||
if let Some(request) = self.pending_claim_requests.get_mut(&pending_claim.0) { | ||
assert!(request.merge_package(package, height).is_ok()); | ||
|
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 we only aggregate
locktimed_packages
with the same locktime, I think the original package would still have the same one, otherwise we'd have to reinsert it. Let's add adebug_assert
that it's true.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.
Do you mean the locktime in the key of
locktime_packages
equal to the locktime calculated from the package?The calculated locktime may depend on
cur_height
. I'm not sure if it's still the same here.