@@ -1181,6 +1181,8 @@ where
1181
1181
// | |
1182
1182
// | |__`pending_intercepted_htlcs`
1183
1183
// |
1184
+ // |__`decode_update_add_htlcs`
1185
+ // |
1184
1186
// |__`per_peer_state`
1185
1187
// |
1186
1188
// |__`pending_inbound_payments`
@@ -1271,6 +1273,18 @@ where
1271
1273
/// See `ChannelManager` struct-level documentation for lock order requirements.
1272
1274
pending_intercepted_htlcs: Mutex<HashMap<InterceptId, PendingAddHTLCInfo>>,
1273
1275
1276
+ /// SCID/SCID Alias -> pending `update_add_htlc`s to decode.
1277
+ ///
1278
+ /// Note that because we may have an SCID Alias as the key we can have two entries per channel,
1279
+ /// though in practice we probably won't be receiving HTLCs for a channel both via the alias
1280
+ /// and via the classic SCID.
1281
+ ///
1282
+ /// Note that no consistency guarantees are made about the existence of a channel with the
1283
+ /// `short_channel_id` here, nor the `channel_id` in `UpdateAddHTLC`!
1284
+ ///
1285
+ /// See `ChannelManager` struct-level documentation for lock order requirements.
1286
+ decode_update_add_htlcs: Mutex<HashMap<u64, Vec<msgs::UpdateAddHTLC>>>,
1287
+
1274
1288
/// The sets of payments which are claimable or currently being claimed. See
1275
1289
/// [`ClaimablePayments`]' individual field docs for more info.
1276
1290
///
@@ -2238,9 +2252,9 @@ macro_rules! handle_monitor_update_completion {
2238
2252
let update_actions = $peer_state.monitor_update_blocked_actions
2239
2253
.remove(&$chan.context.channel_id()).unwrap_or(Vec::new());
2240
2254
2241
- let htlc_forwards = $self.handle_channel_resumption(
2255
+ let ( htlc_forwards, decode_update_add_htlcs) = $self.handle_channel_resumption(
2242
2256
&mut $peer_state.pending_msg_events, $chan, updates.raa,
2243
- updates.commitment_update, updates.order, updates.accepted_htlcs,
2257
+ updates.commitment_update, updates.order, updates.accepted_htlcs, updates.pending_update_adds,
2244
2258
updates.funding_broadcastable, updates.channel_ready,
2245
2259
updates.announcement_sigs);
2246
2260
if let Some(upd) = channel_update {
@@ -2301,6 +2315,9 @@ macro_rules! handle_monitor_update_completion {
2301
2315
if let Some(forwards) = htlc_forwards {
2302
2316
$self.forward_htlcs(&mut [forwards][..]);
2303
2317
}
2318
+ if let Some(decode) = decode_update_add_htlcs {
2319
+ $self.push_decode_update_add_htlcs(decode);
2320
+ }
2304
2321
$self.finalize_claims(updates.finalized_claimed_htlcs);
2305
2322
for failure in updates.failed_htlcs.drain(..) {
2306
2323
let receiver = HTLCDestination::NextHopChannel { node_id: Some(counterparty_node_id), channel_id };
@@ -2477,6 +2494,7 @@ where
2477
2494
pending_inbound_payments: Mutex::new(new_hash_map()),
2478
2495
pending_outbound_payments: OutboundPayments::new(),
2479
2496
forward_htlcs: Mutex::new(new_hash_map()),
2497
+ decode_update_add_htlcs: Mutex::new(new_hash_map()),
2480
2498
claimable_payments: Mutex::new(ClaimablePayments { claimable_payments: new_hash_map(), pending_claiming_payments: new_hash_map() }),
2481
2499
pending_intercepted_htlcs: Mutex::new(new_hash_map()),
2482
2500
outpoint_to_peer: Mutex::new(new_hash_map()),
@@ -5929,24 +5947,31 @@ where
5929
5947
fn handle_channel_resumption(&self, pending_msg_events: &mut Vec<MessageSendEvent>,
5930
5948
channel: &mut Channel<SP>, raa: Option<msgs::RevokeAndACK>,
5931
5949
commitment_update: Option<msgs::CommitmentUpdate>, order: RAACommitmentOrder,
5932
- pending_forwards: Vec<(PendingHTLCInfo, u64)>, funding_broadcastable: Option<Transaction>,
5950
+ pending_forwards: Vec<(PendingHTLCInfo, u64)>, pending_update_adds: Vec<msgs::UpdateAddHTLC>,
5951
+ funding_broadcastable: Option<Transaction>,
5933
5952
channel_ready: Option<msgs::ChannelReady>, announcement_sigs: Option<msgs::AnnouncementSignatures>)
5934
- -> Option<(u64, OutPoint, ChannelId, u128, Vec<(PendingHTLCInfo, u64)>)> {
5953
+ -> ( Option<(u64, OutPoint, ChannelId, u128, Vec<(PendingHTLCInfo, u64)>)>, Option<(u64, Vec<msgs::UpdateAddHTLC>)>) {
5935
5954
let logger = WithChannelContext::from(&self.logger, &channel.context);
5936
- log_trace!(logger, "Handling channel resumption for channel {} with {} RAA, {} commitment update, {} pending forwards, {}broadcasting funding, {} channel ready, {} announcement",
5955
+ log_trace!(logger, "Handling channel resumption for channel {} with {} RAA, {} commitment update, {} pending forwards, {} pending update_add_htlcs, {} broadcasting funding, {} channel ready, {} announcement",
5937
5956
&channel.context.channel_id(),
5938
5957
if raa.is_some() { "an" } else { "no" },
5939
- if commitment_update.is_some() { "a" } else { "no" }, pending_forwards.len(),
5958
+ if commitment_update.is_some() { "a" } else { "no" },
5959
+ pending_forwards.len(), pending_update_adds.len(),
5940
5960
if funding_broadcastable.is_some() { "" } else { "not " },
5941
5961
if channel_ready.is_some() { "sending" } else { "without" },
5942
5962
if announcement_sigs.is_some() { "sending" } else { "without" });
5943
5963
5944
- let mut htlc_forwards = None;
5945
-
5946
5964
let counterparty_node_id = channel.context.get_counterparty_node_id();
5965
+ let short_channel_id = channel.context.get_short_channel_id().unwrap_or(channel.context.outbound_scid_alias());
5966
+
5967
+ let mut htlc_forwards = None;
5947
5968
if !pending_forwards.is_empty() {
5948
- htlc_forwards = Some((channel.context.get_short_channel_id().unwrap_or(channel.context.outbound_scid_alias()),
5949
- channel.context.get_funding_txo().unwrap(), channel.context.channel_id(), channel.context.get_user_id(), pending_forwards));
5969
+ htlc_forwards = Some((short_channel_id, channel.context.get_funding_txo().unwrap(),
5970
+ channel.context.channel_id(), channel.context.get_user_id(), pending_forwards));
5971
+ }
5972
+ let mut decode_update_add_htlcs = None;
5973
+ if !pending_update_adds.is_empty() {
5974
+ decode_update_add_htlcs = Some((short_channel_id, pending_update_adds));
5950
5975
}
5951
5976
5952
5977
if let Some(msg) = channel_ready {
@@ -5997,7 +6022,7 @@ where
5997
6022
emit_channel_ready_event!(pending_events, channel);
5998
6023
}
5999
6024
6000
- htlc_forwards
6025
+ ( htlc_forwards, decode_update_add_htlcs)
6001
6026
}
6002
6027
6003
6028
fn channel_monitor_updated(&self, funding_txo: &OutPoint, channel_id: &ChannelId, highest_applied_update_id: u64, counterparty_node_id: Option<&PublicKey>) {
@@ -6971,6 +6996,15 @@ where
6971
6996
}
6972
6997
}
6973
6998
6999
+ fn push_decode_update_add_htlcs(&self, mut update_add_htlcs: (u64, Vec<msgs::UpdateAddHTLC>)) {
7000
+ let mut decode_update_add_htlcs = self.decode_update_add_htlcs.lock().unwrap();
7001
+ let scid = update_add_htlcs.0;
7002
+ match decode_update_add_htlcs.entry(scid) {
7003
+ hash_map::Entry::Occupied(mut e) => { e.get_mut().append(&mut update_add_htlcs.1); },
7004
+ hash_map::Entry::Vacant(e) => { e.insert(update_add_htlcs.1); },
7005
+ }
7006
+ }
7007
+
6974
7008
#[inline]
6975
7009
fn forward_htlcs(&self, per_source_pending_forwards: &mut [(u64, OutPoint, ChannelId, u128, Vec<(PendingHTLCInfo, u64)>)]) {
6976
7010
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 {
@@ -7307,10 +7341,11 @@ where
7307
7341
}
7308
7342
}
7309
7343
let need_lnd_workaround = chan.context.workaround_lnd_bug_4006.take();
7310
- let htlc_forwards = self.handle_channel_resumption(
7344
+ let ( htlc_forwards, decode_update_add_htlcs) = self.handle_channel_resumption(
7311
7345
&mut peer_state.pending_msg_events, chan, responses.raa, responses.commitment_update, responses.order,
7312
- Vec::new(), None, responses.channel_ready, responses.announcement_sigs);
7346
+ Vec::new(), Vec::new(), None, responses.channel_ready, responses.announcement_sigs);
7313
7347
debug_assert!(htlc_forwards.is_none());
7348
+ debug_assert!(decode_update_add_htlcs.is_none());
7314
7349
if let Some(upd) = channel_update {
7315
7350
peer_state.pending_msg_events.push(upd);
7316
7351
}
@@ -10192,6 +10227,12 @@ where
10192
10227
}
10193
10228
}
10194
10229
10230
+ let mut decode_update_add_htlcs_opt = None;
10231
+ let decode_update_add_htlcs = self.decode_update_add_htlcs.lock().unwrap();
10232
+ if !decode_update_add_htlcs.is_empty() {
10233
+ decode_update_add_htlcs_opt = Some(decode_update_add_htlcs);
10234
+ }
10235
+
10195
10236
let per_peer_state = self.per_peer_state.write().unwrap();
10196
10237
10197
10238
let pending_inbound_payments = self.pending_inbound_payments.lock().unwrap();
@@ -10343,6 +10384,7 @@ where
10343
10384
(10, in_flight_monitor_updates, option),
10344
10385
(11, self.probing_cookie_secret, required),
10345
10386
(13, htlc_onion_fields, optional_vec),
10387
+ (14, decode_update_add_htlcs_opt, option),
10346
10388
});
10347
10389
10348
10390
Ok(())
@@ -10808,6 +10850,7 @@ where
10808
10850
let mut monitor_update_blocked_actions_per_peer: Option<Vec<(_, BTreeMap<_, Vec<_>>)>> = Some(Vec::new());
10809
10851
let mut events_override = None;
10810
10852
let mut in_flight_monitor_updates: Option<HashMap<(PublicKey, OutPoint), Vec<ChannelMonitorUpdate>>> = None;
10853
+ let mut decode_update_add_htlcs: Option<HashMap<u64, Vec<msgs::UpdateAddHTLC>>> = None;
10811
10854
read_tlv_fields!(reader, {
10812
10855
(1, pending_outbound_payments_no_retry, option),
10813
10856
(2, pending_intercepted_htlcs, option),
@@ -10821,7 +10864,9 @@ where
10821
10864
(10, in_flight_monitor_updates, option),
10822
10865
(11, probing_cookie_secret, option),
10823
10866
(13, claimable_htlc_onion_fields, optional_vec),
10867
+ (14, decode_update_add_htlcs, option),
10824
10868
});
10869
+ let decode_update_add_htlcs = decode_update_add_htlcs.unwrap_or_else(|| new_hash_map());
10825
10870
if fake_scid_rand_bytes.is_none() {
10826
10871
fake_scid_rand_bytes = Some(args.entropy_source.get_secure_random_bytes());
10827
10872
}
@@ -11356,6 +11401,7 @@ where
11356
11401
pending_intercepted_htlcs: Mutex::new(pending_intercepted_htlcs.unwrap()),
11357
11402
11358
11403
forward_htlcs: Mutex::new(forward_htlcs),
11404
+ decode_update_add_htlcs: Mutex::new(decode_update_add_htlcs),
11359
11405
claimable_payments: Mutex::new(ClaimablePayments { claimable_payments, pending_claiming_payments: pending_claiming_payments.unwrap() }),
11360
11406
outbound_scid_aliases: Mutex::new(outbound_scid_aliases),
11361
11407
outpoint_to_peer: Mutex::new(outpoint_to_peer),
0 commit comments