Skip to content

Commit

Permalink
Check for abandon-able payments on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinewallace committed Feb 11, 2023
1 parent 78341ad commit 6e7c91e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7499,7 +7499,8 @@ where
}
}

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

inbound_payment_key: expanded_inbound_key,
pending_inbound_payments: Mutex::new(pending_inbound_payments),
pending_outbound_payments: OutboundPayments { pending_outbound_payments: Mutex::new(pending_outbound_payments.unwrap()) },
pending_outbound_payments: pending_outbounds,
pending_intercepted_htlcs: Mutex::new(pending_intercepted_htlcs.unwrap()),

forward_htlcs: Mutex::new(forward_htlcs),
Expand Down
12 changes: 12 additions & 0 deletions lightning/src/ln/outbound_payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,18 @@ impl OutboundPayments {
});
}

pub(super) fn needs_abandon(&self) -> bool {
let outbounds = self.pending_outbound_payments.lock().unwrap();
for (_, pmt) in outbounds.iter() {
if let PendingOutboundPayment::Retryable { pending_amt_msat, total_msat, .. } = pmt {
if !pmt.is_auto_retryable_now() && pending_amt_msat < total_msat {
return true
}
}
}
false
}

/// Errors with no attempt at payment if the route parameters have expired, we failed to find a
/// route to the destination, or we're attempting a retry when retries have been exhausted.
///
Expand Down
3 changes: 2 additions & 1 deletion lightning/src/ln/payment_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1671,8 +1671,9 @@ fn do_automatic_retries(test: AutoRetry) {
let chan_1_monitor_serialized = get_monitor!(nodes[0], channel_id_1).encode();
reload_node!(nodes[0], node_encoded, &[&chan_1_monitor_serialized], persister, new_chain_monitor, node_0_deserialized);

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

Expand Down

0 comments on commit 6e7c91e

Please sign in to comment.