Skip to content

Commit 0150b1f

Browse files
Antoine RiardTheBlueMatt
authored andcommitted
Sanitize pending_claim_requests if no more outpoints to claim
1 parent 6a775ea commit 0150b1f

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

lightning/src/ln/channelmonitor.rs

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2414,26 +2414,36 @@ impl ChannelMonitor {
24142414
}
24152415
}
24162416

2417-
// If this is our transaction (or our counterparty spent all the outputs
2418-
// before we could anyway), wait for ANTI_REORG_DELAY and clean the RBF
2419-
// tracking map.
2420-
if set_equality {
2421-
let new_event = OnchainEvent::Claim { claim_request: ancestor_claimable_txid.0.clone() };
2422-
match self.onchain_events_waiting_threshold_conf.entry(height + ANTI_REORG_DELAY - 1) {
2423-
hash_map::Entry::Occupied(mut entry) => {
2424-
if !entry.get().contains(&new_event) {
2425-
entry.get_mut().push(new_event);
2417+
macro_rules! clean_claim_request_after_safety_delay {
2418+
() => {
2419+
let new_event = OnchainEvent::Claim { claim_request: ancestor_claimable_txid.0.clone() };
2420+
match self.onchain_events_waiting_threshold_conf.entry(height + ANTI_REORG_DELAY - 1) {
2421+
hash_map::Entry::Occupied(mut entry) => {
2422+
if !entry.get().contains(&new_event) {
2423+
entry.get_mut().push(new_event);
2424+
}
2425+
},
2426+
hash_map::Entry::Vacant(entry) => {
2427+
entry.insert(vec![new_event]);
24262428
}
2427-
},
2428-
hash_map::Entry::Vacant(entry) => {
2429-
entry.insert(vec![new_event]);
24302429
}
24312430
}
2431+
}
2432+
2433+
// If this is our transaction (or our counterparty spent all the outputs
2434+
// before we could anyway with same inputs order than us), wait for
2435+
// ANTI_REORG_DELAY and clean the RBF tracking map.
2436+
if set_equality {
2437+
clean_claim_request_after_safety_delay!();
24322438
} else { // If false, generate new claim request with update outpoint set
24332439
for input in tx.input.iter() {
24342440
if let Some(input_material) = claim_material.per_input_material.remove(&input.previous_output) {
24352441
claimed_outputs_material.push((input.previous_output, input_material));
24362442
}
2443+
// If there are no outpoints left to claim in this request, drop it entirely after ANTI_REORG_DELAY.
2444+
if claim_material.per_input_material.is_empty() {
2445+
clean_claim_request_after_safety_delay!();
2446+
}
24372447
}
24382448
//TODO: recompute soonest_timelock to avoid wasting a bit on fees
24392449
bump_candidates.insert(ancestor_claimable_txid.0.clone(), claim_material.clone());

0 commit comments

Comments
 (0)