Skip to content

Commit 6023353

Browse files
committed
Prune lockedtime packages when inputs are spent
We have to prune lockedtime packages when their inputs are spent, otherwise the notification of the watched outputs might be missed. This can lead to lockedtime packages with spent inputs being added back to the pending claim requests in the future, and never being cleaned up. Resolves: #3859
1 parent 4aa1335 commit 6023353

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

lightning/src/chain/onchaintx.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,17 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
994994
panic!("Inconsistencies between pending_claim_requests map and claimable_outpoints map");
995995
}
996996
}
997+
998+
// Also remove/split any locktimed packages whose inputs have been spent by this transaction.
999+
self.locktimed_packages.retain(|_, packages|{
1000+
packages.retain_mut(|package| {
1001+
if let Some(p) = package.split_package(&inp.previous_output) {
1002+
claimed_outputs_material.push(p);
1003+
}
1004+
!package.outpoints().is_empty()
1005+
});
1006+
!packages.is_empty()
1007+
});
9971008
}
9981009
for package in claimed_outputs_material.drain(..) {
9991010
let entry = OnchainEventEntry {
@@ -1135,6 +1146,12 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
11351146
//- resurect outpoint back in its claimable set and regenerate tx
11361147
match entry.event {
11371148
OnchainEvent::ContentiousOutpoint { package } => {
1149+
let package_locktime = package.package_locktime(height);
1150+
if package_locktime > height {
1151+
self.locktimed_packages.entry(package_locktime).or_default().push(package);
1152+
continue;
1153+
}
1154+
11381155
if let Some(pending_claim) = self.claimable_outpoints.get(package.outpoints()[0]) {
11391156
if let Some(request) = self.pending_claim_requests.get_mut(&pending_claim.0) {
11401157
assert!(request.merge_package(package, height).is_ok());

0 commit comments

Comments
 (0)