Skip to content

Commit d8ac152

Browse files
committed
Properly provide PaymentPathSuccessful event for replay claims
When a payment was sent and ultimately completed through an on-chain HTLC claim which we discover during startup, we deliberately break the payment tracking logic to keep it around forever, declining to send a `PaymentPathSuccessful` event but ensuring that we don't constantly replay the claim on every startup. However, now that we now have logic to complete a claim by marking it as completed in a `ChannelMonitor` and not replaying information about the claim on every startup. Thus, we no longer need to take the conservative stance and can correctly replay claims now, generating `PaymentPathSuccessful` events and allowing the state to be removed. Backport of ba6528f Fixed conflicts in: * lightning/src/ln/channelmanager.rs * lightning/src/ln/payment_tests.rs
1 parent 6a0316f commit d8ac152

File tree

3 files changed

+32
-20
lines changed

3 files changed

+32
-20
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14154,20 +14154,12 @@ where
1415414154
log_warn!(logger, "Missing counterparty node id in monitor when trying to re-claim a payment resolved on chain. This may lead to redundant payment claims on restart");
1415514155
None
1415614156
};
14157-
// Note that we set `from_onchain` to "false" here,
14158-
// deliberately keeping the pending payment around forever.
14159-
// Given it should only occur when we have a channel we're
14160-
// force-closing for being stale that's okay.
14161-
// The alternative would be to wipe the state when claiming,
14162-
// generating a `PaymentPathSuccessful` event but regenerating
14163-
// it and the `PaymentSent` on every restart until the
14164-
// `ChannelMonitor` is removed.
1416514157
pending_outbounds.claim_htlc(
1416614158
payment_id,
1416714159
preimage,
1416814160
session_priv,
1416914161
path,
14170-
false,
14162+
true,
1417114163
&mut compl_action,
1417214164
&pending_events,
1417314165
&&logger,

lightning/src/ln/monitor_tests.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3408,12 +3408,15 @@ fn do_test_lost_preimage_monitor_events(on_counterparty_tx: bool) {
34083408

34093409
check_added_monitors(&nodes[1], 0);
34103410
let preimage_events = nodes[1].node.get_and_clear_pending_events();
3411-
assert_eq!(preimage_events.len(), 2, "{preimage_events:?}");
3411+
assert_eq!(preimage_events.len(), 3, "{preimage_events:?}");
34123412
for ev in preimage_events {
34133413
match ev {
34143414
Event::PaymentSent { payment_hash, .. } => {
34153415
assert_eq!(payment_hash, hash_b);
34163416
},
3417+
Event::PaymentPathSuccessful { payment_hash, .. } => {
3418+
assert_eq!(payment_hash, Some(hash_b));
3419+
},
34173420
Event::PaymentForwarded { claim_from_onchain_tx, .. } => {
34183421
assert!(claim_from_onchain_tx);
34193422
},

lightning/src/ln/payment_tests.rs

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,13 +1158,19 @@ fn do_test_dup_htlc_onchain_doesnt_fail_on_reload(
11581158
} else {
11591159
expect_payment_sent(&nodes[0], payment_preimage, None, true, false);
11601160
}
1161-
// After reload, the ChannelManager identified the failed payment and queued up the
1162-
// PaymentSent (or not, if `persist_manager_post_event` resulted in us detecting we
1163-
// already did that) and corresponding ChannelMonitorUpdate to mark the payment
1164-
// handled, but while processing the pending `MonitorEvent`s (which were not processed
1165-
// before the monitor was persisted) we will end up with a duplicate
1166-
// ChannelMonitorUpdate.
1167-
check_added_monitors(&nodes[0], 2);
1161+
if persist_manager_post_event {
1162+
// After reload, the ChannelManager identified the failed payment and queued up the
1163+
// PaymentSent (or not, if `persist_manager_post_event` resulted in us detecting we
1164+
// already did that) and corresponding ChannelMonitorUpdate to mark the payment
1165+
// handled, but while processing the pending `MonitorEvent`s (which were not processed
1166+
// before the monitor was persisted) we will end up with a duplicate
1167+
// ChannelMonitorUpdate.
1168+
check_added_monitors(&nodes[0], 2);
1169+
} else {
1170+
// ...unless we got the PaymentSent event, in which case we have de-duplication logic
1171+
// preventing a redundant monitor event.
1172+
check_added_monitors(&nodes[0], 1);
1173+
}
11681174
}
11691175

11701176
// Note that if we re-connect the block which exposed nodes[0] to the payment preimage (but
@@ -3516,9 +3522,20 @@ fn do_no_missing_sent_on_reload(persist_manager_with_payment: bool, at_midpoint:
35163522
// pending payment from being re-hydrated on the next startup.
35173523
let events = nodes[0].node.get_and_clear_pending_events();
35183524
check_added_monitors(&nodes[0], 1);
3519-
assert_eq!(events.len(), 2);
3520-
if let Event::ChannelClosed { reason: ClosureReason::OutdatedChannelManager, .. } = events[0] {} else { panic!(); }
3521-
if let Event::PaymentSent { payment_preimage, .. } = events[1] { assert_eq!(payment_preimage, our_payment_preimage); } else { panic!(); }
3525+
assert_eq!(events.len(), 3, "{events:?}");
3526+
if let Event::ChannelClosed { reason: ClosureReason::OutdatedChannelManager, .. } = events[0] {
3527+
} else {
3528+
panic!();
3529+
}
3530+
if let Event::PaymentSent { payment_preimage, .. } = events[1] {
3531+
assert_eq!(payment_preimage, our_payment_preimage);
3532+
} else {
3533+
panic!();
3534+
}
3535+
if let Event::PaymentPathSuccessful { .. } = events[2] {
3536+
} else {
3537+
panic!();
3538+
}
35223539
// Note that we don't get a PaymentPathSuccessful here as we leave the HTLC pending to avoid
35233540
// the double-claim that would otherwise appear at the end of this test.
35243541
nodes[0].node.timer_tick_occurred();

0 commit comments

Comments
 (0)