Skip to content

Commit 2dcb379

Browse files
Check for abandon-able payments on startup
1 parent a8722d1 commit 2dcb379

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
@@ -7538,7 +7538,8 @@ where
75387538
}
75397539
}
75407540

7541-
if !forward_htlcs.is_empty() {
7541+
let pending_outbounds = OutboundPayments { pending_outbound_payments: Mutex::new(pending_outbound_payments.unwrap()) };
7542+
if !forward_htlcs.is_empty() || pending_outbounds.needs_abandon() {
75427543
// If we have pending HTLCs to forward, assume we either dropped a
75437544
// `PendingHTLCsForwardable` or the user received it but never processed it as they
75447545
// shut down before the timer hit. Either way, set the time_forwardable to a small
@@ -7706,7 +7707,7 @@ where
77067707

77077708
inbound_payment_key: expanded_inbound_key,
77087709
pending_inbound_payments: Mutex::new(pending_inbound_payments),
7709-
pending_outbound_payments: OutboundPayments { pending_outbound_payments: Mutex::new(pending_outbound_payments.unwrap()) },
7710+
pending_outbound_payments: pending_outbounds,
77107711
pending_intercepted_htlcs: Mutex::new(pending_intercepted_htlcs.unwrap()),
77117712

77127713
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
@@ -542,6 +542,12 @@ impl OutboundPayments {
542542
});
543543
}
544544

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

lightning/src/ln/payment_tests.rs

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

1721+
let mut events = nodes[0].node.get_and_clear_pending_events();
1722+
expect_pending_htlcs_forwardable_from_events!(nodes[0], events, true);
17211723
// Make sure we don't retry again.
1722-
nodes[0].node.process_pending_htlc_forwards();
17231724
let mut msg_events = nodes[0].node.get_and_clear_pending_msg_events();
17241725
assert_eq!(msg_events.len(), 0);
17251726

0 commit comments

Comments
 (0)