@@ -1178,6 +1178,8 @@ where
1178
1178
// | |
1179
1179
// | |__`pending_intercepted_htlcs`
1180
1180
// |
1181
+ // |__`decode_update_add_htlcs`
1182
+ // |
1181
1183
// |__`per_peer_state`
1182
1184
// |
1183
1185
// |__`pending_inbound_payments`
@@ -1268,6 +1270,18 @@ where
1268
1270
/// See `ChannelManager` struct-level documentation for lock order requirements.
1269
1271
pending_intercepted_htlcs: Mutex<HashMap<InterceptId, PendingAddHTLCInfo>>,
1270
1272
1273
+ /// SCID/SCID Alias -> pending `update_add_htlc`s to decode.
1274
+ ///
1275
+ /// Note that because we may have an SCID Alias as the key we can have two entries per channel,
1276
+ /// though in practice we probably won't be receiving HTLCs for a channel both via the alias
1277
+ /// and via the classic SCID.
1278
+ ///
1279
+ /// Note that no consistency guarantees are made about the existence of a channel with the
1280
+ /// `short_channel_id` here, nor the `channel_id` in `UpdateAddHTLC`!
1281
+ ///
1282
+ /// See `ChannelManager` struct-level documentation for lock order requirements.
1283
+ decode_update_add_htlcs: Mutex<HashMap<u64, Vec<msgs::UpdateAddHTLC>>>,
1284
+
1271
1285
/// The sets of payments which are claimable or currently being claimed. See
1272
1286
/// [`ClaimablePayments`]' individual field docs for more info.
1273
1287
///
@@ -2235,9 +2249,9 @@ macro_rules! handle_monitor_update_completion {
2235
2249
let update_actions = $peer_state.monitor_update_blocked_actions
2236
2250
.remove(&$chan.context.channel_id()).unwrap_or(Vec::new());
2237
2251
2238
- let htlc_forwards = $self.handle_channel_resumption(
2252
+ let ( htlc_forwards, decode_update_add_htlcs) = $self.handle_channel_resumption(
2239
2253
&mut $peer_state.pending_msg_events, $chan, updates.raa,
2240
- updates.commitment_update, updates.order, updates.accepted_htlcs,
2254
+ updates.commitment_update, updates.order, updates.accepted_htlcs, updates.pending_update_adds,
2241
2255
updates.funding_broadcastable, updates.channel_ready,
2242
2256
updates.announcement_sigs);
2243
2257
if let Some(upd) = channel_update {
@@ -2298,6 +2312,9 @@ macro_rules! handle_monitor_update_completion {
2298
2312
if let Some(forwards) = htlc_forwards {
2299
2313
$self.forward_htlcs(&mut [forwards][..]);
2300
2314
}
2315
+ if let Some(decode) = decode_update_add_htlcs {
2316
+ $self.decode_update_add_htlcs(decode);
2317
+ }
2301
2318
$self.finalize_claims(updates.finalized_claimed_htlcs);
2302
2319
for failure in updates.failed_htlcs.drain(..) {
2303
2320
let receiver = HTLCDestination::NextHopChannel { node_id: Some(counterparty_node_id), channel_id };
@@ -2474,6 +2491,7 @@ where
2474
2491
pending_inbound_payments: Mutex::new(new_hash_map()),
2475
2492
pending_outbound_payments: OutboundPayments::new(),
2476
2493
forward_htlcs: Mutex::new(new_hash_map()),
2494
+ decode_update_add_htlcs: Mutex::new(new_hash_map()),
2477
2495
claimable_payments: Mutex::new(ClaimablePayments { claimable_payments: new_hash_map(), pending_claiming_payments: new_hash_map() }),
2478
2496
pending_intercepted_htlcs: Mutex::new(new_hash_map()),
2479
2497
outpoint_to_peer: Mutex::new(new_hash_map()),
@@ -5922,24 +5940,31 @@ where
5922
5940
fn handle_channel_resumption(&self, pending_msg_events: &mut Vec<MessageSendEvent>,
5923
5941
channel: &mut Channel<SP>, raa: Option<msgs::RevokeAndACK>,
5924
5942
commitment_update: Option<msgs::CommitmentUpdate>, order: RAACommitmentOrder,
5925
- pending_forwards: Vec<(PendingHTLCInfo, u64)>, funding_broadcastable: Option<Transaction>,
5943
+ pending_forwards: Vec<(PendingHTLCInfo, u64)>, pending_update_adds: Vec<msgs::UpdateAddHTLC>,
5944
+ funding_broadcastable: Option<Transaction>,
5926
5945
channel_ready: Option<msgs::ChannelReady>, announcement_sigs: Option<msgs::AnnouncementSignatures>)
5927
- -> Option<(u64, OutPoint, ChannelId, u128, Vec<(PendingHTLCInfo, u64)>)> {
5946
+ -> ( Option<(u64, OutPoint, ChannelId, u128, Vec<(PendingHTLCInfo, u64)>)>, Option<(u64, Vec<msgs::UpdateAddHTLC>)>) {
5928
5947
let logger = WithChannelContext::from(&self.logger, &channel.context);
5929
- log_trace!(logger, "Handling channel resumption for channel {} with {} RAA, {} commitment update, {} pending forwards, {}broadcasting funding, {} channel ready, {} announcement",
5948
+ log_trace!(logger, "Handling channel resumption for channel {} with {} RAA, {} commitment update, {} pending forwards, {} pending update_add_htlcs, {} broadcasting funding, {} channel ready, {} announcement",
5930
5949
&channel.context.channel_id(),
5931
5950
if raa.is_some() { "an" } else { "no" },
5932
- if commitment_update.is_some() { "a" } else { "no" }, pending_forwards.len(),
5951
+ if commitment_update.is_some() { "a" } else { "no" },
5952
+ pending_forwards.len(), pending_update_adds.len(),
5933
5953
if funding_broadcastable.is_some() { "" } else { "not " },
5934
5954
if channel_ready.is_some() { "sending" } else { "without" },
5935
5955
if announcement_sigs.is_some() { "sending" } else { "without" });
5936
5956
5937
- let mut htlc_forwards = None;
5938
-
5939
5957
let counterparty_node_id = channel.context.get_counterparty_node_id();
5958
+ let short_channel_id = channel.context.get_short_channel_id().unwrap_or(channel.context.outbound_scid_alias());
5959
+
5960
+ let mut htlc_forwards = None;
5940
5961
if !pending_forwards.is_empty() {
5941
- htlc_forwards = Some((channel.context.get_short_channel_id().unwrap_or(channel.context.outbound_scid_alias()),
5942
- channel.context.get_funding_txo().unwrap(), channel.context.channel_id(), channel.context.get_user_id(), pending_forwards));
5962
+ htlc_forwards = Some((short_channel_id, channel.context.get_funding_txo().unwrap(),
5963
+ channel.context.channel_id(), channel.context.get_user_id(), pending_forwards));
5964
+ }
5965
+ let mut decode_update_add_htlcs = None;
5966
+ if !pending_update_adds.is_empty() {
5967
+ decode_update_add_htlcs = Some((short_channel_id, pending_update_adds));
5943
5968
}
5944
5969
5945
5970
if let Some(msg) = channel_ready {
@@ -5990,7 +6015,7 @@ where
5990
6015
emit_channel_ready_event!(pending_events, channel);
5991
6016
}
5992
6017
5993
- htlc_forwards
6018
+ ( htlc_forwards, decode_update_add_htlcs)
5994
6019
}
5995
6020
5996
6021
fn channel_monitor_updated(&self, funding_txo: &OutPoint, channel_id: &ChannelId, highest_applied_update_id: u64, counterparty_node_id: Option<&PublicKey>) {
@@ -6953,6 +6978,17 @@ where
6953
6978
}
6954
6979
}
6955
6980
6981
+ fn decode_update_add_htlcs(&self, update_add_htlcs: (u64, Vec<msgs::UpdateAddHTLC>)) {
6982
+ let mut decode_update_add_htlcs = self.decode_update_add_htlcs.lock().unwrap();
6983
+ let scid = update_add_htlcs.0;
6984
+ for update_add_htlc in update_add_htlcs.1 {
6985
+ match decode_update_add_htlcs.entry(scid) {
6986
+ hash_map::Entry::Occupied(mut e) => { e.get_mut().push(update_add_htlc); },
6987
+ hash_map::Entry::Vacant(e) => { e.insert(vec![update_add_htlc]); },
6988
+ }
6989
+ }
6990
+ }
6991
+
6956
6992
#[inline]
6957
6993
fn forward_htlcs(&self, per_source_pending_forwards: &mut [(u64, OutPoint, ChannelId, u128, Vec<(PendingHTLCInfo, u64)>)]) {
6958
6994
for &mut (prev_short_channel_id, prev_funding_outpoint, prev_channel_id, prev_user_channel_id, ref mut pending_forwards) in per_source_pending_forwards {
@@ -7289,10 +7325,10 @@ where
7289
7325
}
7290
7326
}
7291
7327
let need_lnd_workaround = chan.context.workaround_lnd_bug_4006.take();
7292
- let htlc_forwards = self.handle_channel_resumption(
7328
+ let ( htlc_forwards, decode_update_add_htlcs) = self.handle_channel_resumption(
7293
7329
&mut peer_state.pending_msg_events, chan, responses.raa, responses.commitment_update, responses.order,
7294
- Vec::new(), None, responses.channel_ready, responses.announcement_sigs);
7295
- debug_assert!(htlc_forwards.is_none());
7330
+ Vec::new(), Vec::new(), None, responses.channel_ready, responses.announcement_sigs);
7331
+ debug_assert!(htlc_forwards.is_none() && decode_update_add_htlcs.is_none() );
7296
7332
if let Some(upd) = channel_update {
7297
7333
peer_state.pending_msg_events.push(upd);
7298
7334
}
@@ -10146,6 +10182,12 @@ where
10146
10182
}
10147
10183
}
10148
10184
10185
+ let mut decode_update_add_htlcs_opt = None;
10186
+ let decode_update_add_htlcs = self.decode_update_add_htlcs.lock().unwrap();
10187
+ if !decode_update_add_htlcs.is_empty() {
10188
+ decode_update_add_htlcs_opt = Some(decode_update_add_htlcs);
10189
+ }
10190
+
10149
10191
let per_peer_state = self.per_peer_state.write().unwrap();
10150
10192
10151
10193
let pending_inbound_payments = self.pending_inbound_payments.lock().unwrap();
@@ -10297,6 +10339,7 @@ where
10297
10339
(10, in_flight_monitor_updates, option),
10298
10340
(11, self.probing_cookie_secret, required),
10299
10341
(13, htlc_onion_fields, optional_vec),
10342
+ (14, decode_update_add_htlcs_opt, option),
10300
10343
});
10301
10344
10302
10345
Ok(())
@@ -10762,6 +10805,7 @@ where
10762
10805
let mut monitor_update_blocked_actions_per_peer: Option<Vec<(_, BTreeMap<_, Vec<_>>)>> = Some(Vec::new());
10763
10806
let mut events_override = None;
10764
10807
let mut in_flight_monitor_updates: Option<HashMap<(PublicKey, OutPoint), Vec<ChannelMonitorUpdate>>> = None;
10808
+ let mut decode_update_add_htlcs: Option<HashMap<u64, Vec<msgs::UpdateAddHTLC>>> = None;
10765
10809
read_tlv_fields!(reader, {
10766
10810
(1, pending_outbound_payments_no_retry, option),
10767
10811
(2, pending_intercepted_htlcs, option),
@@ -10775,7 +10819,9 @@ where
10775
10819
(10, in_flight_monitor_updates, option),
10776
10820
(11, probing_cookie_secret, option),
10777
10821
(13, claimable_htlc_onion_fields, optional_vec),
10822
+ (14, decode_update_add_htlcs, option),
10778
10823
});
10824
+ let decode_update_add_htlcs = decode_update_add_htlcs.unwrap_or(new_hash_map());
10779
10825
if fake_scid_rand_bytes.is_none() {
10780
10826
fake_scid_rand_bytes = Some(args.entropy_source.get_secure_random_bytes());
10781
10827
}
@@ -11310,6 +11356,7 @@ where
11310
11356
pending_intercepted_htlcs: Mutex::new(pending_intercepted_htlcs.unwrap()),
11311
11357
11312
11358
forward_htlcs: Mutex::new(forward_htlcs),
11359
+ decode_update_add_htlcs: Mutex::new(decode_update_add_htlcs),
11313
11360
claimable_payments: Mutex::new(ClaimablePayments { claimable_payments, pending_claiming_payments: pending_claiming_payments.unwrap() }),
11314
11361
outbound_scid_aliases: Mutex::new(outbound_scid_aliases),
11315
11362
outpoint_to_peer: Mutex::new(outpoint_to_peer),
0 commit comments