Skip to content

Commit 6074e8a

Browse files
Check for abandon-able payments on startup
1 parent 965e828 commit 6074e8a

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7499,7 +7499,8 @@ where
74997499
}
75007500
}
75017501

7502-
if !forward_htlcs.is_empty() {
7502+
let pending_outbounds = OutboundPayments { pending_outbound_payments: Mutex::new(pending_outbound_payments.unwrap()) };
7503+
if !forward_htlcs.is_empty() || pending_outbounds.needs_abandon() {
75037504
// If we have pending HTLCs to forward, assume we either dropped a
75047505
// `PendingHTLCsForwardable` or the user received it but never processed it as they
75057506
// shut down before the timer hit. Either way, set the time_forwardable to a small
@@ -7667,7 +7668,7 @@ where
76677668

76687669
inbound_payment_key: expanded_inbound_key,
76697670
pending_inbound_payments: Mutex::new(pending_inbound_payments),
7670-
pending_outbound_payments: OutboundPayments { pending_outbound_payments: Mutex::new(pending_outbound_payments.unwrap()) },
7671+
pending_outbound_payments: pending_outbounds,
76717672
pending_intercepted_htlcs: Mutex::new(pending_intercepted_htlcs.unwrap()),
76727673

76737674
forward_htlcs: Mutex::new(forward_htlcs),

lightning/src/ln/outbound_payment.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,18 @@ impl OutboundPayments {
544544
});
545545
}
546546

547+
pub(super) fn needs_abandon(&self) -> bool {
548+
let outbounds = self.pending_outbound_payments.lock().unwrap();
549+
for (_, pmt) in outbounds.iter() {
550+
if let PendingOutboundPayment::Retryable { pending_amt_msat, total_msat, .. } = pmt {
551+
if !pmt.is_auto_retryable_now() && pending_amt_msat < total_msat {
552+
return true
553+
}
554+
}
555+
}
556+
false
557+
}
558+
547559
/// Errors with no attempt at payment if the route parameters have expired, we failed to find a
548560
/// route to the destination, or we're attempting a retry when retries have been exhausted.
549561
///

lightning/src/ln/payment_tests.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1671,8 +1671,9 @@ fn do_automatic_retries(test: AutoRetry) {
16711671
let chan_1_monitor_serialized = get_monitor!(nodes[0], channel_id_1).encode();
16721672
reload_node!(nodes[0], node_encoded, &[&chan_1_monitor_serialized], persister, new_chain_monitor, node_0_deserialized);
16731673

1674+
let mut events = nodes[0].node.get_and_clear_pending_events();
1675+
expect_pending_htlcs_forwardable_from_events!(nodes[0], events, true);
16741676
// Make sure we don't retry again.
1675-
nodes[0].node.process_pending_htlc_forwards();
16761677
let mut msg_events = nodes[0].node.get_and_clear_pending_msg_events();
16771678
assert_eq!(msg_events.len(), 0);
16781679

0 commit comments

Comments
 (0)