@@ -17195,7 +17195,11 @@ where
1719517195
1719617196 const MAX_ALLOC_SIZE: usize = 1024 * 64;
1719717197 let forward_htlcs_count: u64 = Readable::read(reader)?;
17198- let mut forward_htlcs = hash_map_with_capacity(cmp::min(forward_htlcs_count as usize, 128));
17198+ // This map is read but may no longer be used because we'll attempt to rebuild the set of HTLC
17199+ // forwards from the `Channel{Monitor}`s instead, as a step towards removing the requirement of
17200+ // regularly persisting the `ChannelManager`.
17201+ let mut forward_htlcs_legacy: HashMap<u64, Vec<HTLCForwardInfo>> =
17202+ hash_map_with_capacity(cmp::min(forward_htlcs_count as usize, 128));
1719917203 for _ in 0..forward_htlcs_count {
1720017204 let short_channel_id = Readable::read(reader)?;
1720117205 let pending_forwards_count: u64 = Readable::read(reader)?;
@@ -17206,7 +17210,7 @@ where
1720617210 for _ in 0..pending_forwards_count {
1720717211 pending_forwards.push(Readable::read(reader)?);
1720817212 }
17209- forward_htlcs .insert(short_channel_id, pending_forwards);
17213+ forward_htlcs_legacy .insert(short_channel_id, pending_forwards);
1721017214 }
1721117215
1721217216 let claimable_htlcs_count: u64 = Readable::read(reader)?;
@@ -17294,12 +17298,18 @@ where
1729417298 };
1729517299 }
1729617300
17301+ // Some maps are read but may no longer be used because we attempt to rebuild the pending HTLC
17302+ // set from the `Channel{Monitor}`s instead, as a step towards removing the requirement of
17303+ // regularly persisting the `ChannelManager`.
17304+ let mut pending_intercepted_htlcs_legacy: Option<HashMap<InterceptId, PendingAddHTLCInfo>> =
17305+ Some(new_hash_map());
17306+ let mut decode_update_add_htlcs_legacy: Option<HashMap<u64, Vec<msgs::UpdateAddHTLC>>> =
17307+ None;
17308+
1729717309 // pending_outbound_payments_no_retry is for compatibility with 0.0.101 clients.
1729817310 let mut pending_outbound_payments_no_retry: Option<HashMap<PaymentId, HashSet<[u8; 32]>>> =
1729917311 None;
1730017312 let mut pending_outbound_payments = None;
17301- let mut pending_intercepted_htlcs: Option<HashMap<InterceptId, PendingAddHTLCInfo>> =
17302- Some(new_hash_map());
1730317313 let mut received_network_pubkey: Option<PublicKey> = None;
1730417314 let mut fake_scid_rand_bytes: Option<[u8; 32]> = None;
1730517315 let mut probing_cookie_secret: Option<[u8; 32]> = None;
@@ -17317,13 +17327,12 @@ where
1731717327 let mut in_flight_monitor_updates: Option<
1731817328 HashMap<(PublicKey, ChannelId), Vec<ChannelMonitorUpdate>>,
1731917329 > = None;
17320- let mut decode_update_add_htlcs: Option<HashMap<u64, Vec<msgs::UpdateAddHTLC>>> = None;
1732117330 let mut inbound_payment_id_secret = None;
1732217331 let mut peer_storage_dir: Option<Vec<(PublicKey, Vec<u8>)>> = None;
1732317332 let mut async_receive_offer_cache: AsyncReceiveOfferCache = AsyncReceiveOfferCache::new();
1732417333 read_tlv_fields!(reader, {
1732517334 (1, pending_outbound_payments_no_retry, option),
17326- (2, pending_intercepted_htlcs , option),
17335+ (2, pending_intercepted_htlcs_legacy , option),
1732717336 (3, pending_outbound_payments, option),
1732817337 (4, pending_claiming_payments, option),
1732917338 (5, received_network_pubkey, option),
@@ -17334,13 +17343,14 @@ where
1733417343 (10, legacy_in_flight_monitor_updates, option),
1733517344 (11, probing_cookie_secret, option),
1733617345 (13, claimable_htlc_onion_fields, optional_vec),
17337- (14, decode_update_add_htlcs , option),
17346+ (14, decode_update_add_htlcs_legacy , option),
1733817347 (15, inbound_payment_id_secret, option),
1733917348 (17, in_flight_monitor_updates, option),
1734017349 (19, peer_storage_dir, optional_vec),
1734117350 (21, async_receive_offer_cache, (default_value, async_receive_offer_cache)),
1734217351 });
17343- let mut decode_update_add_htlcs = decode_update_add_htlcs.unwrap_or_else(|| new_hash_map());
17352+ let mut decode_update_add_htlcs_legacy =
17353+ decode_update_add_htlcs_legacy.unwrap_or_else(|| new_hash_map());
1734417354 let peer_storage_dir: Vec<(PublicKey, Vec<u8>)> = peer_storage_dir.unwrap_or_else(Vec::new);
1734517355 if fake_scid_rand_bytes.is_none() {
1734617356 fake_scid_rand_bytes = Some(args.entropy_source.get_secure_random_bytes());
@@ -17714,12 +17724,12 @@ where
1771417724 // `pending_intercepted_htlcs`, we were apparently not persisted after
1771517725 // the monitor was when forwarding the payment.
1771617726 dedup_decode_update_add_htlcs(
17717- &mut decode_update_add_htlcs ,
17727+ &mut decode_update_add_htlcs_legacy ,
1771817728 &prev_hop_data,
1771917729 "HTLC was forwarded to the closed channel",
1772017730 &args.logger,
1772117731 );
17722- forward_htlcs .retain(|_, forwards| {
17732+ forward_htlcs_legacy .retain(|_, forwards| {
1772317733 forwards.retain(|forward| {
1772417734 if let HTLCForwardInfo::AddHTLC(htlc_info) = forward {
1772517735 if pending_forward_matches_htlc(&htlc_info) {
@@ -17731,7 +17741,7 @@ where
1773117741 });
1773217742 !forwards.is_empty()
1773317743 });
17734- pending_intercepted_htlcs .as_mut().unwrap().retain(|intercepted_id, htlc_info| {
17744+ pending_intercepted_htlcs_legacy .as_mut().unwrap().retain(|intercepted_id, htlc_info| {
1773517745 if pending_forward_matches_htlc(&htlc_info) {
1773617746 log_info!(logger, "Removing pending intercepted HTLC with hash {} as it was forwarded to the closed channel {}",
1773717747 &htlc.payment_hash, &monitor.channel_id());
@@ -18229,10 +18239,10 @@ where
1822918239
1823018240 inbound_payment_key: expanded_inbound_key,
1823118241 pending_outbound_payments: pending_outbounds,
18232- pending_intercepted_htlcs: Mutex::new(pending_intercepted_htlcs .unwrap()),
18242+ pending_intercepted_htlcs: Mutex::new(pending_intercepted_htlcs_legacy .unwrap()),
1823318243
18234- forward_htlcs: Mutex::new(forward_htlcs ),
18235- decode_update_add_htlcs: Mutex::new(decode_update_add_htlcs ),
18244+ forward_htlcs: Mutex::new(forward_htlcs_legacy ),
18245+ decode_update_add_htlcs: Mutex::new(decode_update_add_htlcs_legacy ),
1823618246 claimable_payments: Mutex::new(ClaimablePayments {
1823718247 claimable_payments,
1823818248 pending_claiming_payments: pending_claiming_payments.unwrap(),
0 commit comments