Skip to content

Commit 890ebf5

Browse files
committed
Drop PendingHTLCsForwardable event
1 parent f6f2abf commit 890ebf5

14 files changed

+65
-375
lines changed

lightning/src/events/mod.rs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ use bitcoin::script::ScriptBuf;
5050
use bitcoin::secp256k1::PublicKey;
5151
use bitcoin::{OutPoint, Transaction};
5252
use core::ops::Deref;
53-
use core::time::Duration;
5453

5554
#[allow(unused_imports)]
5655
use crate::prelude::*;
@@ -1174,21 +1173,6 @@ pub enum Event {
11741173
/// with channels in the public network graph.
11751174
short_channel_id: Option<u64>,
11761175
},
1177-
/// Used to indicate that [`ChannelManager::process_pending_htlc_forwards`] should be called at
1178-
/// a time in the future.
1179-
///
1180-
/// # Failure Behavior and Persistence
1181-
/// This event will eventually be replayed after failures-to-handle (i.e., the event handler
1182-
/// returning `Err(ReplayEvent ())`) and will be regenerated after restarts.
1183-
///
1184-
/// [`ChannelManager::process_pending_htlc_forwards`]: crate::ln::channelmanager::ChannelManager::process_pending_htlc_forwards
1185-
PendingHTLCsForwardable {
1186-
/// The minimum amount of time that should be waited prior to calling
1187-
/// process_pending_htlc_forwards. To increase the effort required to correlate payments,
1188-
/// you should wait a random amount of time in roughly the range (now + time_forwardable,
1189-
/// now + 5*time_forwardable).
1190-
time_forwardable: Duration,
1191-
},
11921176
/// Used to indicate that we've intercepted an HTLC forward. This event will only be generated if
11931177
/// you've encoded an intercept scid in the receiver's invoice route hints using
11941178
/// [`ChannelManager::get_intercept_scid`] and have set [`UserConfig::accept_intercept_htlcs`].
@@ -1793,11 +1777,7 @@ impl Writeable for Event {
17931777
(13, failure, required),
17941778
});
17951779
},
1796-
&Event::PendingHTLCsForwardable { time_forwardable: _ } => {
1797-
4u8.write(writer)?;
1798-
// Note that we now ignore these on the read end as we'll re-generate them in
1799-
// ChannelManager, we write them here only for backwards compatibility.
1800-
},
1780+
// 4u8 used to be `PendingHTLCsForwardable`
18011781
&Event::SpendableOutputs { ref outputs, channel_id } => {
18021782
5u8.write(writer)?;
18031783
write_tlv_fields!(writer, {

lightning/src/ln/blinded_payment_tests.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -636,10 +636,6 @@ fn do_forward_fail_in_process_pending_htlc_fwds(check: ProcessPendingHTLCsCheck,
636636
$curr_node.node.force_close_broadcasting_latest_txn(&$failed_chan_id, &$next_node.node.get_our_node_id(), error_message.to_string()).unwrap();
637637
let events = $curr_node.node.get_and_clear_pending_events();
638638
match events[0] {
639-
crate::events::Event::PendingHTLCsForwardable { .. } => {},
640-
_ => panic!("Unexpected event {:?}", events),
641-
};
642-
match events[1] {
643639
crate::events::Event::ChannelClosed { .. } => {},
644640
_ => panic!("Unexpected event {:?}", events),
645641
}
@@ -1162,18 +1158,14 @@ fn blinded_path_retries() {
11621158
do_commitment_signed_dance(&nodes[0], &$intro_node, &updates.commitment_signed, false, false);
11631159

11641160
let mut events = nodes[0].node.get_and_clear_pending_events();
1165-
assert_eq!(events.len(), 2);
1161+
assert_eq!(events.len(), 1);
11661162
match events[0] {
11671163
Event::PaymentPathFailed { payment_hash: ev_payment_hash, payment_failed_permanently, .. } => {
11681164
assert_eq!(payment_hash, ev_payment_hash);
11691165
assert_eq!(payment_failed_permanently, false);
11701166
},
11711167
_ => panic!("Unexpected event"),
11721168
}
1173-
match events[1] {
1174-
Event::PendingHTLCsForwardable { .. } => {},
1175-
_ => panic!("Unexpected event"),
1176-
}
11771169
nodes[0].node.process_pending_htlc_forwards();
11781170
}
11791171
}

lightning/src/ln/chanmon_update_fail_tests.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2011,23 +2011,19 @@ fn test_monitor_update_on_pending_forwards() {
20112011
commitment_signed_dance!(nodes[0], nodes[1], bs_updates.commitment_signed, false, true);
20122012

20132013
let events = nodes[0].node.get_and_clear_pending_events();
2014-
assert_eq!(events.len(), 3);
2015-
if let Event::PaymentPathFailed { payment_hash, payment_failed_permanently, .. } = events[1] {
2014+
assert_eq!(events.len(), 2);
2015+
if let Event::PaymentPathFailed { payment_hash, payment_failed_permanently, .. } = events[0] {
20162016
assert_eq!(payment_hash, payment_hash_1);
20172017
assert!(payment_failed_permanently);
20182018
} else {
20192019
panic!("Unexpected event!");
20202020
}
2021-
match events[2] {
2021+
match events[1] {
20222022
Event::PaymentFailed { payment_hash, .. } => {
20232023
assert_eq!(payment_hash, Some(payment_hash_1));
20242024
},
20252025
_ => panic!("Unexpected event"),
20262026
}
2027-
match events[0] {
2028-
Event::PendingHTLCsForwardable { .. } => {},
2029-
_ => panic!("Unexpected event"),
2030-
};
20312027
nodes[0].node.process_pending_htlc_forwards();
20322028
expect_payment_claimable!(nodes[0], payment_hash_2, payment_secret_2, 1000000);
20332029

@@ -2810,12 +2806,8 @@ fn do_channel_holding_cell_serialize(disconnect: bool, reload_a: bool) {
28102806
commitment_signed_dance!(nodes[1], nodes[0], (), false, true, false, false);
28112807

28122808
let events = nodes[1].node.get_and_clear_pending_events();
2813-
assert_eq!(events.len(), 2);
2809+
assert_eq!(events.len(), 1);
28142810
match events[0] {
2815-
Event::PendingHTLCsForwardable { .. } => {},
2816-
_ => panic!("Unexpected event"),
2817-
};
2818-
match events[1] {
28192811
Event::PaymentPathSuccessful { .. } => {},
28202812
_ => panic!("Unexpected event"),
28212813
};

lightning/src/ln/channelmanager.rs

Lines changed: 7 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -964,12 +964,6 @@ impl MsgHandleErrInternal {
964964
}
965965
}
966966

967-
/// We hold back HTLCs we intend to relay for a random interval greater than this (see
968-
/// Event::PendingHTLCsForwardable for the API guidelines indicating how long should be waited).
969-
/// This provides some limited amount of privacy. Ideally this would range from somewhere like one
970-
/// second to 30 seconds, but people expect lightning to be, you know, kinda fast, sadly.
971-
pub(super) const MIN_HTLC_RELAY_HOLDING_CELL_MILLIS: u64 = 100;
972-
973967
/// For events which result in both a RevokeAndACK and a CommitmentUpdate, by default they should
974968
/// be sent in the order they appear in the return value, however sometimes the order needs to be
975969
/// variable at runtime (eg FundedChannel::channel_reestablish needs to re-send messages in the order
@@ -6360,8 +6354,7 @@ where
63606354

63616355
/// Processes HTLCs which are pending waiting on random forward delay.
63626356
///
6363-
/// Should only really ever be called in response to a PendingHTLCsForwardable event.
6364-
/// Will likely generate further events.
6357+
/// Will regularly be called by the background processor.
63656358
pub fn process_pending_htlc_forwards(&self) {
63666359
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
63676360

@@ -7776,23 +7769,20 @@ where
77767769
&self, source: &HTLCSource, payment_hash: &PaymentHash, onion_error: &HTLCFailReason,
77777770
destination: HTLCHandlingFailureType,
77787771
) {
7779-
let push_forward_event = self.fail_htlc_backwards_internal_without_forward_event(
7772+
self.fail_htlc_backwards_internal_without_forward_event(
77807773
source,
77817774
payment_hash,
77827775
onion_error,
77837776
destination,
77847777
);
7785-
if push_forward_event {
7786-
self.push_pending_forwards_ev();
7787-
}
77887778
}
77897779

77907780
/// Fails an HTLC backwards to the sender of it to us.
77917781
/// Note that we do not assume that channels corresponding to failed HTLCs are still available.
77927782
fn fail_htlc_backwards_internal_without_forward_event(
77937783
&self, source: &HTLCSource, payment_hash: &PaymentHash, onion_error: &HTLCFailReason,
77947784
failure_type: HTLCHandlingFailureType,
7795-
) -> bool {
7785+
) {
77967786
// Ensure that no peer state channel storage lock is held when calling this function.
77977787
// This ensures that future code doesn't introduce a lock-order requirement for
77987788
// `forward_htlcs` to be locked after the `per_peer_state` peer locks, which calling
@@ -7810,10 +7800,9 @@ where
78107800
// Note that we MUST NOT end up calling methods on self.chain_monitor here - we're called
78117801
// from block_connected which may run during initialization prior to the chain_monitor
78127802
// being fully configured. See the docs for `ChannelManagerReadArgs` for more.
7813-
let mut push_forward_event;
78147803
match source {
78157804
HTLCSource::OutboundRoute { ref path, ref session_priv, ref payment_id, .. } => {
7816-
push_forward_event = self.pending_outbound_payments.fail_htlc(
7805+
self.pending_outbound_payments.fail_htlc(
78177806
source,
78187807
payment_hash,
78197808
onion_error,
@@ -7869,9 +7858,7 @@ where
78697858
},
78707859
};
78717860

7872-
push_forward_event = self.decode_update_add_htlcs.lock().unwrap().is_empty();
78737861
let mut forward_htlcs = self.forward_htlcs.lock().unwrap();
7874-
push_forward_event &= forward_htlcs.is_empty();
78757862
match forward_htlcs.entry(*short_channel_id) {
78767863
hash_map::Entry::Occupied(mut entry) => {
78777864
entry.get_mut().push(failure);
@@ -7892,7 +7879,6 @@ where
78927879
));
78937880
},
78947881
}
7895-
push_forward_event
78967882
}
78977883

78987884
/// Provides a payment preimage in response to [`Event::PaymentClaimable`], generating any
@@ -10033,9 +10019,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1003310019
}
1003410020

1003510021
fn push_decode_update_add_htlcs(&self, mut update_add_htlcs: (u64, Vec<msgs::UpdateAddHTLC>)) {
10036-
let mut push_forward_event = self.forward_htlcs.lock().unwrap().is_empty();
1003710022
let mut decode_update_add_htlcs = self.decode_update_add_htlcs.lock().unwrap();
10038-
push_forward_event &= decode_update_add_htlcs.is_empty();
1003910023
let scid = update_add_htlcs.0;
1004010024
match decode_update_add_htlcs.entry(scid) {
1004110025
hash_map::Entry::Occupied(mut e) => {
@@ -10045,25 +10029,17 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1004510029
e.insert(update_add_htlcs.1);
1004610030
},
1004710031
}
10048-
if push_forward_event {
10049-
self.push_pending_forwards_ev();
10050-
}
1005110032
}
1005210033

1005310034
#[inline]
1005410035
fn forward_htlcs(&self, per_source_pending_forwards: &mut [PerSourcePendingForward]) {
10055-
let push_forward_event =
10056-
self.forward_htlcs_without_forward_event(per_source_pending_forwards);
10057-
if push_forward_event {
10058-
self.push_pending_forwards_ev()
10059-
}
10036+
self.forward_htlcs_without_forward_event(per_source_pending_forwards);
1006010037
}
1006110038

1006210039
#[inline]
1006310040
fn forward_htlcs_without_forward_event(
1006410041
&self, per_source_pending_forwards: &mut [PerSourcePendingForward],
10065-
) -> bool {
10066-
let mut push_forward_event = false;
10042+
) {
1006710043
for &mut (
1006810044
prev_short_channel_id,
1006910045
prev_counterparty_node_id,
@@ -10086,10 +10062,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1008610062
// Pull this now to avoid introducing a lock order with `forward_htlcs`.
1008710063
let is_our_scid = self.short_to_chan_info.read().unwrap().contains_key(&scid);
1008810064

10089-
let decode_update_add_htlcs_empty =
10090-
self.decode_update_add_htlcs.lock().unwrap().is_empty();
1009110065
let mut forward_htlcs = self.forward_htlcs.lock().unwrap();
10092-
let forward_htlcs_empty = forward_htlcs.is_empty();
1009310066
match forward_htlcs.entry(scid) {
1009410067
hash_map::Entry::Occupied(mut entry) => {
1009510068
entry.get_mut().push(HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo {
@@ -10189,10 +10162,6 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1018910162
},
1019010163
}
1019110164
} else {
10192-
// We don't want to generate a PendingHTLCsForwardable event if only intercepted
10193-
// payments are being processed.
10194-
push_forward_event |=
10195-
forward_htlcs_empty && decode_update_add_htlcs_empty;
1019610165
entry.insert(vec![HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo {
1019710166
prev_short_channel_id,
1019810167
prev_counterparty_node_id,
@@ -10211,7 +10180,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1021110180
for (htlc_source, payment_hash, failure_reason, destination) in
1021210181
failed_intercept_forwards.drain(..)
1021310182
{
10214-
push_forward_event |= self.fail_htlc_backwards_internal_without_forward_event(
10183+
self.fail_htlc_backwards_internal_without_forward_event(
1021510184
&htlc_source,
1021610185
&payment_hash,
1021710186
&failure_reason,
@@ -10224,30 +10193,6 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1022410193
events.append(&mut new_intercept_events);
1022510194
}
1022610195
}
10227-
push_forward_event
10228-
}
10229-
10230-
fn push_pending_forwards_ev(&self) {
10231-
let mut pending_events = self.pending_events.lock().unwrap();
10232-
let is_processing_events = self.pending_events_processor.load(Ordering::Acquire);
10233-
let num_forward_events = pending_events
10234-
.iter()
10235-
.filter(|(ev, _)| matches!(ev, events::Event::PendingHTLCsForwardable { .. }))
10236-
.count();
10237-
// We only want to push a PendingHTLCsForwardable event if no others are queued. Processing
10238-
// events is done in batches and they are not removed until we're done processing each
10239-
// batch. Since handling a `PendingHTLCsForwardable` event will call back into the
10240-
// `ChannelManager`, we'll still see the original forwarding event not removed. Phantom
10241-
// payments will need an additional forwarding event before being claimed to make them look
10242-
// real by taking more time.
10243-
if (is_processing_events && num_forward_events <= 1) || num_forward_events < 1 {
10244-
pending_events.push_back((
10245-
Event::PendingHTLCsForwardable {
10246-
time_forwardable: Duration::from_millis(MIN_HTLC_RELAY_HOLDING_CELL_MILLIS),
10247-
},
10248-
None,
10249-
));
10250-
}
1025110196
}
1025210197

1025310198
/// Checks whether [`ChannelMonitorUpdate`]s generated by the receipt of a remote
@@ -10838,15 +10783,6 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1083810783
has_pending_monitor_events
1083910784
}
1084010785

10841-
/// In chanmon_consistency_target, we'd like to be able to restore monitor updating without
10842-
/// handling all pending events (i.e. not PendingHTLCsForwardable). Thus, we expose monitor
10843-
/// update events as a separate process method here.
10844-
#[cfg(fuzzing)]
10845-
pub fn process_monitor_events(&self) {
10846-
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
10847-
self.process_pending_monitor_events();
10848-
}
10849-
1085010786
/// Check the holding cell in each channel and free any pending HTLCs in them if possible.
1085110787
/// Returns whether there were any updates such as if pending HTLCs were freed or a monitor
1085210788
/// update was applied.
@@ -16195,21 +16131,6 @@ where
1619516131
}
1619616132
}
1619716133

16198-
if !forward_htlcs.is_empty()
16199-
|| !decode_update_add_htlcs.is_empty()
16200-
|| pending_outbounds.needs_abandon()
16201-
{
16202-
// If we have pending HTLCs to forward, assume we either dropped a
16203-
// `PendingHTLCsForwardable` or the user received it but never processed it as they
16204-
// shut down before the timer hit. Either way, set the time_forwardable to a small
16205-
// constant as enough time has likely passed that we should simply handle the forwards
16206-
// now, or at least after the user gets a chance to reconnect to our peers.
16207-
pending_events_read.push_back((
16208-
events::Event::PendingHTLCsForwardable { time_forwardable: Duration::from_secs(2) },
16209-
None,
16210-
));
16211-
}
16212-
1621316134
let expanded_inbound_key = args.node_signer.get_inbound_payment_key();
1621416135

1621516136
let mut claimable_payments = hash_map_with_capacity(claimable_htlcs_list.len());

0 commit comments

Comments
 (0)