Skip to content

Commit 9cc2097

Browse files
committed
Stop timing out payments automatically, requiring abandon_payment
When the `abandon_payment` flow was added there was some concern that upgrading users may not migrate to the new flow, causing memory leaks in the pending-payment tracking. While this is true, now that we're relying on the pending_outbound_payments map for `send_payment` idempotency, the risk of removing a payment prematurely goes up from "spurious retry failure" to "sending a duplicative payment", which is much worse. Thus, we simply remove the automated payment timeout here, explicitly requiring that users call `abandon_payment` when they give up retrying a payment.
1 parent 0204741 commit 9cc2097

File tree

3 files changed

+17
-44
lines changed

3 files changed

+17
-44
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -960,10 +960,6 @@ const CHECK_CLTV_EXPIRY_SANITY: u32 = MIN_CLTV_EXPIRY_DELTA as u32 - LATENCY_GRA
960960
#[allow(dead_code)]
961961
const CHECK_CLTV_EXPIRY_SANITY_2: u32 = MIN_CLTV_EXPIRY_DELTA as u32 - LATENCY_GRACE_PERIOD_BLOCKS - 2*CLTV_CLAIM_BUFFER;
962962

963-
/// The number of blocks before we consider an outbound payment for expiry if it doesn't have any
964-
/// pending HTLCs in flight.
965-
pub(crate) const PAYMENT_EXPIRY_BLOCKS: u32 = 3;
966-
967963
/// The number of ticks of [`ChannelManager::timer_tick_occurred`] until expiry of incomplete MPPs
968964
pub(crate) const MPP_TIMEOUT_TICKS: u8 = 3;
969965

@@ -5800,21 +5796,6 @@ where
58005796
payment_secrets.retain(|_, inbound_payment| {
58015797
inbound_payment.expiry_time > header.time as u64
58025798
});
5803-
5804-
let mut outbounds = self.pending_outbound_payments.lock().unwrap();
5805-
let mut pending_events = self.pending_events.lock().unwrap();
5806-
outbounds.retain(|payment_id, payment| {
5807-
if payment.remaining_parts() != 0 { return true }
5808-
if let PendingOutboundPayment::Retryable { starting_block_height, payment_hash, .. } = payment {
5809-
if *starting_block_height + PAYMENT_EXPIRY_BLOCKS <= height {
5810-
log_info!(self.logger, "Timing out payment with id {} and hash {}", log_bytes!(payment_id.0), log_bytes!(payment_hash.0));
5811-
pending_events.push(events::Event::PaymentFailed {
5812-
payment_id: *payment_id, payment_hash: *payment_hash,
5813-
});
5814-
false
5815-
} else { true }
5816-
} else { true }
5817-
});
58185799
}
58195800

58205801
fn get_relevant_txids(&self) -> Vec<Txid> {

lightning/src/ln/functional_tests.rs

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use chain::transaction::OutPoint;
2020
use chain::keysinterface::{BaseSign, KeysInterface};
2121
use ln::{PaymentPreimage, PaymentSecret, PaymentHash};
2222
use ln::channel::{commitment_tx_base_weight, COMMITMENT_TX_WEIGHT_PER_HTLC, CONCURRENT_INBOUND_HTLC_FEE_BUFFER, FEE_SPIKE_BUFFER_FEE_INCREASE_MULTIPLE, MIN_AFFORDABLE_HTLC_COUNT};
23-
use ln::channelmanager::{self, ChannelManager, ChannelManagerReadArgs, PaymentId, RAACommitmentOrder, PaymentSendFailure, BREAKDOWN_TIMEOUT, MIN_CLTV_EXPIRY_DELTA, PAYMENT_EXPIRY_BLOCKS};
23+
use ln::channelmanager::{self, ChannelManager, ChannelManagerReadArgs, PaymentId, RAACommitmentOrder, PaymentSendFailure, BREAKDOWN_TIMEOUT, MIN_CLTV_EXPIRY_DELTA};
2424
use ln::channel::{Channel, ChannelError};
2525
use ln::{chan_utils, onion_utils};
2626
use ln::chan_utils::{OFFERED_HTLC_SCRIPT_WEIGHT, htlc_success_tx_weight, htlc_timeout_tx_weight, HTLCOutputInCommitment};
@@ -3184,10 +3184,9 @@ fn do_test_commitment_revoked_fail_backward_exhaustive(deliver_bs_raa: bool, use
31843184
mine_transaction(&nodes[1], &revoked_local_txn[0]);
31853185
check_added_monitors!(nodes[1], 1);
31863186
connect_blocks(&nodes[1], ANTI_REORG_DELAY - 1);
3187-
assert!(ANTI_REORG_DELAY > PAYMENT_EXPIRY_BLOCKS); // We assume payments will also expire
31883187

31893188
let events = nodes[1].node.get_and_clear_pending_events();
3190-
assert_eq!(events.len(), if deliver_bs_raa { 2 + (nodes.len() - 1) } else { 4 + nodes.len() });
3189+
assert_eq!(events.len(), if deliver_bs_raa { 2 + nodes.len() - 1 } else { 3 + nodes.len() });
31913190
match events[0] {
31923191
Event::ChannelClosed { reason: ClosureReason::CommitmentTxConfirmed, .. } => { },
31933192
_ => panic!("Unexepected event"),
@@ -3200,15 +3199,18 @@ fn do_test_commitment_revoked_fail_backward_exhaustive(deliver_bs_raa: bool, use
32003199
}
32013200
if !deliver_bs_raa {
32023201
match events[2] {
3202+
Event::PendingHTLCsForwardable { .. } => { },
3203+
_ => panic!("Unexpected event"),
3204+
};
3205+
nodes[1].node.abandon_payment(PaymentId(fourth_payment_hash.0));
3206+
let payment_failed_events = nodes[1].node.get_and_clear_pending_events();
3207+
assert_eq!(payment_failed_events.len(), 1);
3208+
match payment_failed_events[0] {
32033209
Event::PaymentFailed { ref payment_hash, .. } => {
32043210
assert_eq!(*payment_hash, fourth_payment_hash);
32053211
},
32063212
_ => panic!("Unexpected event"),
32073213
}
3208-
match events[3] {
3209-
Event::PendingHTLCsForwardable { .. } => { },
3210-
_ => panic!("Unexpected event"),
3211-
};
32123214
}
32133215
nodes[1].node.process_pending_htlc_forwards();
32143216
check_added_monitors!(nodes[1], 1);
@@ -4325,14 +4327,7 @@ fn do_test_holding_cell_htlc_add_timeouts(forwarded_htlc: bool) {
43254327
}
43264328
expect_payment_failed_with_update!(nodes[0], second_payment_hash, false, chan_2.0.contents.short_channel_id, false);
43274329
} else {
4328-
let events = nodes[1].node.get_and_clear_pending_events();
4329-
assert_eq!(events.len(), 2);
4330-
if let Event::PaymentPathFailed { ref payment_hash, .. } = events[0] {
4331-
assert_eq!(*payment_hash, second_payment_hash);
4332-
} else { panic!("Unexpected event"); }
4333-
if let Event::PaymentFailed { ref payment_hash, .. } = events[1] {
4334-
assert_eq!(*payment_hash, second_payment_hash);
4335-
} else { panic!("Unexpected event"); }
4330+
expect_payment_failed!(nodes[1], second_payment_hash, false);
43364331
}
43374332
}
43384333

@@ -6047,14 +6042,7 @@ fn do_htlc_claim_previous_remote_commitment_only(use_dust: bool, check_revoke_no
60476042
check_added_monitors!(nodes[0], 1);
60486043
check_closed_event!(nodes[0], 1, ClosureReason::CommitmentTxConfirmed);
60496044
} else {
6050-
let events = nodes[0].node.get_and_clear_pending_events();
6051-
assert_eq!(events.len(), 2);
6052-
if let Event::PaymentPathFailed { ref payment_hash, .. } = events[0] {
6053-
assert_eq!(*payment_hash, our_payment_hash);
6054-
} else { panic!("Unexpected event"); }
6055-
if let Event::PaymentFailed { ref payment_hash, .. } = events[1] {
6056-
assert_eq!(*payment_hash, our_payment_hash);
6057-
} else { panic!("Unexpected event"); }
6045+
expect_payment_failed!(nodes[0], our_payment_hash, true);
60586046
}
60596047
}
60606048

lightning/src/util/events.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,8 @@ pub enum Event {
317317
/// provide failure information for each MPP part in the payment.
318318
///
319319
/// This event is provided once there are no further pending HTLCs for the payment and the
320-
/// payment is no longer retryable, either due to a several-block timeout or because
321-
/// [`ChannelManager::abandon_payment`] was previously called for the corresponding payment.
320+
/// payment is no longer retryable due to [`ChannelManager::abandon_payment`] having been
321+
/// called for the corresponding payment.
322322
///
323323
/// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
324324
PaymentFailed {
@@ -357,9 +357,13 @@ pub enum Event {
357357
/// Indicates an outbound HTLC we sent failed. Probably some intermediary node dropped
358358
/// something. You may wish to retry with a different route.
359359
///
360+
/// If you have given up retrying this payment and wish to fail it, you MUST call
361+
/// [`ChannelManager::abandon_payment`] or memory related to payment tracking will leak.
362+
///
360363
/// Note that this does *not* indicate that all paths for an MPP payment have failed, see
361364
/// [`Event::PaymentFailed`] and [`all_paths_failed`].
362365
///
366+
/// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
363367
/// [`all_paths_failed`]: Self::PaymentPathFailed::all_paths_failed
364368
PaymentPathFailed {
365369
/// The id returned by [`ChannelManager::send_payment`] and used with

0 commit comments

Comments
 (0)