Skip to content

Commit 91be2cc

Browse files
Check for abandon-able payments on startup
1 parent 7588632 commit 91be2cc

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7530,7 +7530,8 @@ where
75307530
}
75317531
}
75327532

7533-
if !forward_htlcs.is_empty() {
7533+
let pending_outbounds = OutboundPayments { pending_outbound_payments: Mutex::new(pending_outbound_payments.unwrap()), retry_lock: Mutex::new(()) };
7534+
if !forward_htlcs.is_empty() || pending_outbounds.needs_abandon() {
75347535
// If we have pending HTLCs to forward, assume we either dropped a
75357536
// `PendingHTLCsForwardable` or the user received it but never processed it as they
75367537
// shut down before the timer hit. Either way, set the time_forwardable to a small
@@ -7698,7 +7699,7 @@ where
76987699

76997700
inbound_payment_key: expanded_inbound_key,
77007701
pending_inbound_payments: Mutex::new(pending_inbound_payments),
7701-
pending_outbound_payments: OutboundPayments { pending_outbound_payments: Mutex::new(pending_outbound_payments.unwrap()), retry_lock: Mutex::new(()), },
7702+
pending_outbound_payments: pending_outbounds,
77027703
pending_intercepted_htlcs: Mutex::new(pending_intercepted_htlcs.unwrap()),
77037704

77047705
forward_htlcs: Mutex::new(forward_htlcs),

lightning/src/ln/outbound_payment.rs

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

548+
pub(super) fn needs_abandon(&self) -> bool {
549+
let outbounds = self.pending_outbound_payments.lock().unwrap();
550+
outbounds.iter().any(|(_, pmt)|
551+
!pmt.is_auto_retryable_now() && pmt.remaining_parts() == 0 && !pmt.is_fulfilled())
552+
}
553+
548554
/// Will return `Ok(())` iff at least one HTLC is sent for the payment.
549555
fn pay_internal<R: Deref, NS: Deref, ES: Deref, IH, SP, L: Deref>(
550556
&self, payment_id: PaymentId,

lightning/src/ln/payment_tests.rs

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

1724+
let mut events = nodes[0].node.get_and_clear_pending_events();
1725+
expect_pending_htlcs_forwardable_from_events!(nodes[0], events, true);
17241726
// Make sure we don't retry again.
1725-
nodes[0].node.process_pending_htlc_forwards();
17261727
let mut msg_events = nodes[0].node.get_and_clear_pending_msg_events();
17271728
assert_eq!(msg_events.len(), 0);
17281729

0 commit comments

Comments
 (0)