@@ -960,12 +960,6 @@ impl MsgHandleErrInternal {
960
960
}
961
961
}
962
962
963
- /// We hold back HTLCs we intend to relay for a random interval greater than this (see
964
- /// Event::PendingHTLCsForwardable for the API guidelines indicating how long should be waited).
965
- /// This provides some limited amount of privacy. Ideally this would range from somewhere like one
966
- /// second to 30 seconds, but people expect lightning to be, you know, kinda fast, sadly.
967
- pub(super) const MIN_HTLC_RELAY_HOLDING_CELL_MILLIS: u64 = 100;
968
-
969
963
/// For events which result in both a RevokeAndACK and a CommitmentUpdate, by default they should
970
964
/// be sent in the order they appear in the return value, however sometimes the order needs to be
971
965
/// variable at runtime (eg FundedChannel::channel_reestablish needs to re-send messages in the order
@@ -6315,8 +6309,7 @@ where
6315
6309
6316
6310
/// Processes HTLCs which are pending waiting on random forward delay.
6317
6311
///
6318
- /// Should only really ever be called in response to a PendingHTLCsForwardable event.
6319
- /// Will likely generate further events.
6312
+ /// Will regularly be called by the background processor.
6320
6313
pub fn process_pending_htlc_forwards(&self) {
6321
6314
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
6322
6315
@@ -7721,23 +7714,20 @@ where
7721
7714
&self, source: &HTLCSource, payment_hash: &PaymentHash, onion_error: &HTLCFailReason,
7722
7715
destination: HTLCHandlingFailureType,
7723
7716
) {
7724
- let push_forward_event = self.fail_htlc_backwards_internal_without_forward_event(
7717
+ self.fail_htlc_backwards_internal_without_forward_event(
7725
7718
source,
7726
7719
payment_hash,
7727
7720
onion_error,
7728
7721
destination,
7729
7722
);
7730
- if push_forward_event {
7731
- self.push_pending_forwards_ev();
7732
- }
7733
7723
}
7734
7724
7735
7725
/// Fails an HTLC backwards to the sender of it to us.
7736
7726
/// Note that we do not assume that channels corresponding to failed HTLCs are still available.
7737
7727
fn fail_htlc_backwards_internal_without_forward_event(
7738
7728
&self, source: &HTLCSource, payment_hash: &PaymentHash, onion_error: &HTLCFailReason,
7739
7729
failure_type: HTLCHandlingFailureType,
7740
- ) -> bool {
7730
+ ) {
7741
7731
// Ensure that no peer state channel storage lock is held when calling this function.
7742
7732
// This ensures that future code doesn't introduce a lock-order requirement for
7743
7733
// `forward_htlcs` to be locked after the `per_peer_state` peer locks, which calling
@@ -7755,10 +7745,9 @@ where
7755
7745
// Note that we MUST NOT end up calling methods on self.chain_monitor here - we're called
7756
7746
// from block_connected which may run during initialization prior to the chain_monitor
7757
7747
// being fully configured. See the docs for `ChannelManagerReadArgs` for more.
7758
- let mut push_forward_event;
7759
7748
match source {
7760
7749
HTLCSource::OutboundRoute { ref path, ref session_priv, ref payment_id, .. } => {
7761
- push_forward_event = self.pending_outbound_payments.fail_htlc(
7750
+ self.pending_outbound_payments.fail_htlc(
7762
7751
source,
7763
7752
payment_hash,
7764
7753
onion_error,
@@ -7814,9 +7803,7 @@ where
7814
7803
},
7815
7804
};
7816
7805
7817
- push_forward_event = self.decode_update_add_htlcs.lock().unwrap().is_empty();
7818
7806
let mut forward_htlcs = self.forward_htlcs.lock().unwrap();
7819
- push_forward_event &= forward_htlcs.is_empty();
7820
7807
match forward_htlcs.entry(*short_channel_id) {
7821
7808
hash_map::Entry::Occupied(mut entry) => {
7822
7809
entry.get_mut().push(failure);
@@ -7837,7 +7824,6 @@ where
7837
7824
));
7838
7825
},
7839
7826
}
7840
- push_forward_event
7841
7827
}
7842
7828
7843
7829
/// Provides a payment preimage in response to [`Event::PaymentClaimable`], generating any
@@ -9978,9 +9964,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
9978
9964
}
9979
9965
9980
9966
fn push_decode_update_add_htlcs(&self, mut update_add_htlcs: (u64, Vec<msgs::UpdateAddHTLC>)) {
9981
- let mut push_forward_event = self.forward_htlcs.lock().unwrap().is_empty();
9982
9967
let mut decode_update_add_htlcs = self.decode_update_add_htlcs.lock().unwrap();
9983
- push_forward_event &= decode_update_add_htlcs.is_empty();
9984
9968
let scid = update_add_htlcs.0;
9985
9969
match decode_update_add_htlcs.entry(scid) {
9986
9970
hash_map::Entry::Occupied(mut e) => {
@@ -9990,25 +9974,17 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
9990
9974
e.insert(update_add_htlcs.1);
9991
9975
},
9992
9976
}
9993
- if push_forward_event {
9994
- self.push_pending_forwards_ev();
9995
- }
9996
9977
}
9997
9978
9998
9979
#[inline]
9999
9980
fn forward_htlcs(&self, per_source_pending_forwards: &mut [PerSourcePendingForward]) {
10000
- let push_forward_event =
10001
- self.forward_htlcs_without_forward_event(per_source_pending_forwards);
10002
- if push_forward_event {
10003
- self.push_pending_forwards_ev()
10004
- }
9981
+ self.forward_htlcs_without_forward_event(per_source_pending_forwards);
10005
9982
}
10006
9983
10007
9984
#[inline]
10008
9985
fn forward_htlcs_without_forward_event(
10009
9986
&self, per_source_pending_forwards: &mut [PerSourcePendingForward],
10010
- ) -> bool {
10011
- let mut push_forward_event = false;
9987
+ ) {
10012
9988
for &mut (
10013
9989
prev_short_channel_id,
10014
9990
prev_counterparty_node_id,
@@ -10031,10 +10007,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
10031
10007
// Pull this now to avoid introducing a lock order with `forward_htlcs`.
10032
10008
let is_our_scid = self.short_to_chan_info.read().unwrap().contains_key(&scid);
10033
10009
10034
- let decode_update_add_htlcs_empty =
10035
- self.decode_update_add_htlcs.lock().unwrap().is_empty();
10036
10010
let mut forward_htlcs = self.forward_htlcs.lock().unwrap();
10037
- let forward_htlcs_empty = forward_htlcs.is_empty();
10038
10011
match forward_htlcs.entry(scid) {
10039
10012
hash_map::Entry::Occupied(mut entry) => {
10040
10013
entry.get_mut().push(HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo {
@@ -10132,8 +10105,6 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
10132
10105
} else {
10133
10106
// We don't want to generate a PendingHTLCsForwardable event if only intercepted
10134
10107
// payments are being processed.
10135
- push_forward_event |=
10136
- forward_htlcs_empty && decode_update_add_htlcs_empty;
10137
10108
entry.insert(vec![HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo {
10138
10109
prev_short_channel_id,
10139
10110
prev_counterparty_node_id,
@@ -10152,7 +10123,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
10152
10123
for (htlc_source, payment_hash, failure_reason, destination) in
10153
10124
failed_intercept_forwards.drain(..)
10154
10125
{
10155
- push_forward_event |= self.fail_htlc_backwards_internal_without_forward_event(
10126
+ self.fail_htlc_backwards_internal_without_forward_event(
10156
10127
&htlc_source,
10157
10128
&payment_hash,
10158
10129
&failure_reason,
@@ -10165,30 +10136,6 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
10165
10136
events.append(&mut new_intercept_events);
10166
10137
}
10167
10138
}
10168
- push_forward_event
10169
- }
10170
-
10171
- fn push_pending_forwards_ev(&self) {
10172
- let mut pending_events = self.pending_events.lock().unwrap();
10173
- let is_processing_events = self.pending_events_processor.load(Ordering::Acquire);
10174
- let num_forward_events = pending_events
10175
- .iter()
10176
- .filter(|(ev, _)| matches!(ev, events::Event::PendingHTLCsForwardable { .. }))
10177
- .count();
10178
- // We only want to push a PendingHTLCsForwardable event if no others are queued. Processing
10179
- // events is done in batches and they are not removed until we're done processing each
10180
- // batch. Since handling a `PendingHTLCsForwardable` event will call back into the
10181
- // `ChannelManager`, we'll still see the original forwarding event not removed. Phantom
10182
- // payments will need an additional forwarding event before being claimed to make them look
10183
- // real by taking more time.
10184
- if (is_processing_events && num_forward_events <= 1) || num_forward_events < 1 {
10185
- pending_events.push_back((
10186
- Event::PendingHTLCsForwardable {
10187
- time_forwardable: Duration::from_millis(MIN_HTLC_RELAY_HOLDING_CELL_MILLIS),
10188
- },
10189
- None,
10190
- ));
10191
- }
10192
10139
}
10193
10140
10194
10141
/// Checks whether [`ChannelMonitorUpdate`]s generated by the receipt of a remote
@@ -15951,21 +15898,6 @@ where
15951
15898
}
15952
15899
}
15953
15900
15954
- if !forward_htlcs.is_empty()
15955
- || !decode_update_add_htlcs.is_empty()
15956
- || pending_outbounds.needs_abandon()
15957
- {
15958
- // If we have pending HTLCs to forward, assume we either dropped a
15959
- // `PendingHTLCsForwardable` or the user received it but never processed it as they
15960
- // shut down before the timer hit. Either way, set the time_forwardable to a small
15961
- // constant as enough time has likely passed that we should simply handle the forwards
15962
- // now, or at least after the user gets a chance to reconnect to our peers.
15963
- pending_events_read.push_back((
15964
- events::Event::PendingHTLCsForwardable { time_forwardable: Duration::from_secs(2) },
15965
- None,
15966
- ));
15967
- }
15968
-
15969
15901
let expanded_inbound_key = args.node_signer.get_inbound_payment_key();
15970
15902
15971
15903
let mut claimable_payments = hash_map_with_capacity(claimable_htlcs_list.len());
0 commit comments