Skip to content

Commit 5ea433f

Browse files
Check for abandon-able payments on startup
1 parent d0b8f45 commit 5ea433f

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
@@ -7526,7 +7526,8 @@ where
75267526
}
75277527
}
75287528

7529-
if !forward_htlcs.is_empty() {
7529+
let pending_outbounds = OutboundPayments { pending_outbound_payments: Mutex::new(pending_outbound_payments.unwrap()), retry_lock: Mutex::new(()) };
7530+
if !forward_htlcs.is_empty() || pending_outbounds.needs_abandon() {
75307531
// If we have pending HTLCs to forward, assume we either dropped a
75317532
// `PendingHTLCsForwardable` or the user received it but never processed it as they
75327533
// shut down before the timer hit. Either way, set the time_forwardable to a small
@@ -7694,7 +7695,7 @@ where
76947695

76957696
inbound_payment_key: expanded_inbound_key,
76967697
pending_inbound_payments: Mutex::new(pending_inbound_payments),
7697-
pending_outbound_payments: OutboundPayments { pending_outbound_payments: Mutex::new(pending_outbound_payments.unwrap()), retry_lock: Mutex::new(()), },
7698+
pending_outbound_payments: pending_outbounds,
76987699
pending_intercepted_htlcs: Mutex::new(pending_intercepted_htlcs.unwrap()),
76997700

77007701
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
@@ -546,6 +546,12 @@ impl OutboundPayments {
546546
});
547547
}
548548

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