@@ -17200,7 +17200,11 @@ where
1720017200
1720117201 const MAX_ALLOC_SIZE: usize = 1024 * 64;
1720217202 let forward_htlcs_count: u64 = Readable::read(reader)?;
17203- let mut forward_htlcs = hash_map_with_capacity(cmp::min(forward_htlcs_count as usize, 128));
17203+ // This map is read but may no longer be used because we'll attempt to rebuild the set of HTLC
17204+ // forwards from the `Channel{Monitor}`s instead, as a step towards removing the requirement of
17205+ // regularly persisting the `ChannelManager`.
17206+ let mut forward_htlcs_legacy: HashMap<u64, Vec<HTLCForwardInfo>> =
17207+ hash_map_with_capacity(cmp::min(forward_htlcs_count as usize, 128));
1720417208 for _ in 0..forward_htlcs_count {
1720517209 let short_channel_id = Readable::read(reader)?;
1720617210 let pending_forwards_count: u64 = Readable::read(reader)?;
@@ -17211,7 +17215,7 @@ where
1721117215 for _ in 0..pending_forwards_count {
1721217216 pending_forwards.push(Readable::read(reader)?);
1721317217 }
17214- forward_htlcs .insert(short_channel_id, pending_forwards);
17218+ forward_htlcs_legacy .insert(short_channel_id, pending_forwards);
1721517219 }
1721617220
1721717221 let claimable_htlcs_count: u64 = Readable::read(reader)?;
@@ -17299,12 +17303,18 @@ where
1729917303 };
1730017304 }
1730117305
17306+ // Some maps are read but may no longer be used because we attempt to rebuild the pending HTLC
17307+ // set from the `Channel{Monitor}`s instead, as a step towards removing the requirement of
17308+ // regularly persisting the `ChannelManager`.
17309+ let mut pending_intercepted_htlcs_legacy: Option<HashMap<InterceptId, PendingAddHTLCInfo>> =
17310+ Some(new_hash_map());
17311+ let mut decode_update_add_htlcs_legacy: Option<HashMap<u64, Vec<msgs::UpdateAddHTLC>>> =
17312+ None;
17313+
1730217314 // pending_outbound_payments_no_retry is for compatibility with 0.0.101 clients.
1730317315 let mut pending_outbound_payments_no_retry: Option<HashMap<PaymentId, HashSet<[u8; 32]>>> =
1730417316 None;
1730517317 let mut pending_outbound_payments = None;
17306- let mut pending_intercepted_htlcs: Option<HashMap<InterceptId, PendingAddHTLCInfo>> =
17307- Some(new_hash_map());
1730817318 let mut received_network_pubkey: Option<PublicKey> = None;
1730917319 let mut fake_scid_rand_bytes: Option<[u8; 32]> = None;
1731017320 let mut probing_cookie_secret: Option<[u8; 32]> = None;
@@ -17322,13 +17332,12 @@ where
1732217332 let mut in_flight_monitor_updates: Option<
1732317333 HashMap<(PublicKey, ChannelId), Vec<ChannelMonitorUpdate>>,
1732417334 > = None;
17325- let mut decode_update_add_htlcs: Option<HashMap<u64, Vec<msgs::UpdateAddHTLC>>> = None;
1732617335 let mut inbound_payment_id_secret = None;
1732717336 let mut peer_storage_dir: Option<Vec<(PublicKey, Vec<u8>)>> = None;
1732817337 let mut async_receive_offer_cache: AsyncReceiveOfferCache = AsyncReceiveOfferCache::new();
1732917338 read_tlv_fields!(reader, {
1733017339 (1, pending_outbound_payments_no_retry, option),
17331- (2, pending_intercepted_htlcs , option),
17340+ (2, pending_intercepted_htlcs_legacy , option),
1733217341 (3, pending_outbound_payments, option),
1733317342 (4, pending_claiming_payments, option),
1733417343 (5, received_network_pubkey, option),
@@ -17339,13 +17348,14 @@ where
1733917348 (10, legacy_in_flight_monitor_updates, option),
1734017349 (11, probing_cookie_secret, option),
1734117350 (13, claimable_htlc_onion_fields, optional_vec),
17342- (14, decode_update_add_htlcs , option),
17351+ (14, decode_update_add_htlcs_legacy , option),
1734317352 (15, inbound_payment_id_secret, option),
1734417353 (17, in_flight_monitor_updates, option),
1734517354 (19, peer_storage_dir, optional_vec),
1734617355 (21, async_receive_offer_cache, (default_value, async_receive_offer_cache)),
1734717356 });
17348- let mut decode_update_add_htlcs = decode_update_add_htlcs.unwrap_or_else(|| new_hash_map());
17357+ let mut decode_update_add_htlcs_legacy =
17358+ decode_update_add_htlcs_legacy.unwrap_or_else(|| new_hash_map());
1734917359 let peer_storage_dir: Vec<(PublicKey, Vec<u8>)> = peer_storage_dir.unwrap_or_else(Vec::new);
1735017360 if fake_scid_rand_bytes.is_none() {
1735117361 fake_scid_rand_bytes = Some(args.entropy_source.get_secure_random_bytes());
@@ -17719,12 +17729,12 @@ where
1771917729 // `pending_intercepted_htlcs`, we were apparently not persisted after
1772017730 // the monitor was when forwarding the payment.
1772117731 dedup_decode_update_add_htlcs(
17722- &mut decode_update_add_htlcs ,
17732+ &mut decode_update_add_htlcs_legacy ,
1772317733 &prev_hop_data,
1772417734 "HTLC was forwarded to the closed channel",
1772517735 &args.logger,
1772617736 );
17727- forward_htlcs .retain(|_, forwards| {
17737+ forward_htlcs_legacy .retain(|_, forwards| {
1772817738 forwards.retain(|forward| {
1772917739 if let HTLCForwardInfo::AddHTLC(htlc_info) = forward {
1773017740 if pending_forward_matches_htlc(&htlc_info) {
@@ -17736,7 +17746,7 @@ where
1773617746 });
1773717747 !forwards.is_empty()
1773817748 });
17739- pending_intercepted_htlcs .as_mut().unwrap().retain(|intercepted_id, htlc_info| {
17749+ pending_intercepted_htlcs_legacy .as_mut().unwrap().retain(|intercepted_id, htlc_info| {
1774017750 if pending_forward_matches_htlc(&htlc_info) {
1774117751 log_info!(logger, "Removing pending intercepted HTLC with hash {} as it was forwarded to the closed channel {}",
1774217752 &htlc.payment_hash, &monitor.channel_id());
@@ -18234,10 +18244,10 @@ where
1823418244
1823518245 inbound_payment_key: expanded_inbound_key,
1823618246 pending_outbound_payments: pending_outbounds,
18237- pending_intercepted_htlcs: Mutex::new(pending_intercepted_htlcs .unwrap()),
18247+ pending_intercepted_htlcs: Mutex::new(pending_intercepted_htlcs_legacy .unwrap()),
1823818248
18239- forward_htlcs: Mutex::new(forward_htlcs ),
18240- decode_update_add_htlcs: Mutex::new(decode_update_add_htlcs ),
18249+ forward_htlcs: Mutex::new(forward_htlcs_legacy ),
18250+ decode_update_add_htlcs: Mutex::new(decode_update_add_htlcs_legacy ),
1824118251 claimable_payments: Mutex::new(ClaimablePayments {
1824218252 claimable_payments,
1824318253 pending_claiming_payments: pending_claiming_payments.unwrap(),
0 commit comments