@@ -17851,33 +17851,18 @@ where
1785117851 )?;
1785217852
1785317853 // Stage 2: Validation and reconstruction
17854- // Destructure DTO into local variables for the existing validation logic
17855- let chain_hash = data.chain_hash;
17856- let best_block_height = data.best_block_height;
17857- let best_block_hash = data.best_block_hash;
17854+ // Extract mutable/complex fields into local variables; simple fields accessed via data.*
1785817855 let mut forward_htlcs_legacy = data.forward_htlcs;
1785917856 let mut claimable_htlcs_list = data.claimable_htlcs;
17860- let highest_seen_timestamp = data.highest_seen_timestamp;
17861- let pending_outbound_payments_compat = data.pending_outbound_payments_compat;
17862- let pending_outbound_payments_no_retry = data.pending_outbound_payments_no_retry;
1786317857 let mut pending_intercepted_htlcs_legacy =
17864- data.pending_intercepted_htlcs.unwrap_or_else(|| new_hash_map() );
17858+ data.pending_intercepted_htlcs.unwrap_or_else(new_hash_map);
1786517859 let mut pending_outbound_payments = data.pending_outbound_payments;
17866- let pending_claiming_payments = data.pending_claiming_payments;
17867- let received_network_pubkey = data.received_network_pubkey;
17868- let monitor_update_blocked_actions_per_peer = data.monitor_update_blocked_actions_per_peer;
1786917860 let mut fake_scid_rand_bytes = data.fake_scid_rand_bytes;
17870- let events_override = data.events_override;
17871- let claimable_htlc_purposes = data.claimable_htlc_purposes;
17872- let legacy_in_flight_monitor_updates = data.legacy_in_flight_monitor_updates;
1787317861 let mut probing_cookie_secret = data.probing_cookie_secret;
17874- let claimable_htlc_onion_fields = data.claimable_htlc_onion_fields;
1787517862 let mut decode_update_add_htlcs_legacy =
17876- data.decode_update_add_htlcs.unwrap_or_else(|| new_hash_map() );
17863+ data.decode_update_add_htlcs.unwrap_or_else(new_hash_map);
1787717864 let mut inbound_payment_id_secret = data.inbound_payment_id_secret;
1787817865 let mut in_flight_monitor_updates = data.in_flight_monitor_updates;
17879- let peer_storage_dir = data.peer_storage_dir.unwrap_or_else(Vec::new);
17880- let async_receive_offer_cache = data.async_receive_offer_cache;
1788117866 let mut pending_events_read = data.pending_events;
1788217867
1788317868 let empty_peer_state = || PeerState {
@@ -18174,34 +18159,37 @@ where
1817418159 inbound_payment_id_secret = Some(args.entropy_source.get_secure_random_bytes());
1817518160 }
1817618161
18177- if let Some(events) = events_override {
18162+ if let Some(events) = data. events_override {
1817818163 pending_events_read = events;
1817918164 }
1818018165
1818118166 if !channel_closures.is_empty() {
1818218167 pending_events_read.append(&mut channel_closures);
1818318168 }
1818418169
18185- if pending_outbound_payments.is_none() && pending_outbound_payments_no_retry.is_none() {
18186- pending_outbound_payments = Some(pending_outbound_payments_compat);
18170+ if pending_outbound_payments.is_none() && data.pending_outbound_payments_no_retry.is_none()
18171+ {
18172+ pending_outbound_payments = Some(data.pending_outbound_payments_compat);
1818718173 } else if pending_outbound_payments.is_none() {
1818818174 let mut outbounds = new_hash_map();
18189- for (id, session_privs) in pending_outbound_payments_no_retry.unwrap().drain() {
18175+ for (id, session_privs) in data. pending_outbound_payments_no_retry.unwrap().drain() {
1819018176 outbounds.insert(id, PendingOutboundPayment::Legacy { session_privs });
1819118177 }
1819218178 pending_outbound_payments = Some(outbounds);
1819318179 }
1819418180 let pending_outbounds =
1819518181 OutboundPayments::new(pending_outbound_payments.unwrap(), args.logger.clone());
1819618182
18197- for (peer_pubkey, peer_storage) in peer_storage_dir {
18198- if let Some(peer_state) = per_peer_state.get_mut(&peer_pubkey) {
18199- peer_state.get_mut().unwrap().peer_storage = peer_storage;
18183+ if let Some(peer_storage_dir) = data.peer_storage_dir {
18184+ for (peer_pubkey, peer_storage) in peer_storage_dir {
18185+ if let Some(peer_state) = per_peer_state.get_mut(&peer_pubkey) {
18186+ peer_state.get_mut().unwrap().peer_storage = peer_storage;
18187+ }
1820018188 }
1820118189 }
1820218190
1820318191 // Handle transitioning from the legacy TLV to the new one on upgrades.
18204- if let Some(legacy_in_flight_upds) = legacy_in_flight_monitor_updates {
18192+ if let Some(legacy_in_flight_upds) = data. legacy_in_flight_monitor_updates {
1820518193 // We should never serialize an empty map.
1820618194 if legacy_in_flight_upds.is_empty() {
1820718195 return Err(DecodeError::InvalidValue);
@@ -18544,7 +18532,7 @@ where
1854418532 htlc.payment_hash,
1854518533 session_priv_bytes,
1854618534 &path,
18547- best_block_height,
18535+ data. best_block_height,
1854818536 );
1854918537 }
1855018538 }
@@ -18846,11 +18834,11 @@ where
1884618834 let expanded_inbound_key = args.node_signer.get_expanded_key();
1884718835
1884818836 let mut claimable_payments = hash_map_with_capacity(claimable_htlcs_list.len());
18849- if let Some(purposes) = claimable_htlc_purposes {
18837+ if let Some(purposes) = data. claimable_htlc_purposes {
1885018838 if purposes.len() != claimable_htlcs_list.len() {
1885118839 return Err(DecodeError::InvalidValue);
1885218840 }
18853- if let Some(onion_fields) = claimable_htlc_onion_fields {
18841+ if let Some(onion_fields) = data. claimable_htlc_onion_fields {
1885418842 if onion_fields.len() != claimable_htlcs_list.len() {
1885518843 return Err(DecodeError::InvalidValue);
1885618844 }
@@ -18948,7 +18936,7 @@ where
1894818936 Ok(key) => key,
1894918937 Err(()) => return Err(DecodeError::InvalidValue),
1895018938 };
18951- if let Some(network_pubkey) = received_network_pubkey {
18939+ if let Some(network_pubkey) = data. received_network_pubkey {
1895218940 if network_pubkey != our_network_pubkey {
1895318941 log_error!(args.logger, "Key that was generated does not match the existing key.");
1895418942 return Err(DecodeError::InvalidValue);
@@ -18967,8 +18955,8 @@ where
1896718955 loop {
1896818956 outbound_scid_alias = fake_scid::Namespace::OutboundAlias
1896918957 .get_fake_scid(
18970- best_block_height,
18971- &chain_hash,
18958+ data. best_block_height,
18959+ &data. chain_hash,
1897218960 fake_scid_rand_bytes.as_ref().unwrap(),
1897318961 &args.entropy_source,
1897418962 );
@@ -19015,7 +19003,7 @@ where
1901519003 let bounded_fee_estimator = LowerBoundedFeeEstimator::new(args.fee_estimator);
1901619004
1901719005 for (node_id, monitor_update_blocked_actions) in
19018- monitor_update_blocked_actions_per_peer.unwrap()
19006+ data. monitor_update_blocked_actions_per_peer.unwrap()
1901919007 {
1902019008 if let Some(peer_state) = per_peer_state.get(&node_id) {
1902119009 for (channel_id, actions) in monitor_update_blocked_actions.iter() {
@@ -19144,22 +19132,22 @@ where
1914419132 }
1914519133 }
1914619134
19147- let best_block = BestBlock::new(best_block_hash, best_block_height);
19135+ let best_block = BestBlock::new(data. best_block_hash, data. best_block_height);
1914819136 let flow = OffersMessageFlow::new(
19149- chain_hash,
19137+ data. chain_hash,
1915019138 best_block,
1915119139 our_network_pubkey,
19152- highest_seen_timestamp,
19140+ data. highest_seen_timestamp,
1915319141 expanded_inbound_key,
1915419142 args.node_signer.get_receive_auth_key(),
1915519143 secp_ctx.clone(),
1915619144 args.message_router,
1915719145 args.logger.clone(),
1915819146 )
19159- .with_async_payments_offers_cache(async_receive_offer_cache);
19147+ .with_async_payments_offers_cache(data. async_receive_offer_cache);
1916019148
1916119149 let channel_manager = ChannelManager {
19162- chain_hash,
19150+ chain_hash: data.chain_hash ,
1916319151 fee_estimator: bounded_fee_estimator,
1916419152 chain_monitor: args.chain_monitor,
1916519153 tx_broadcaster: args.tx_broadcaster,
@@ -19176,7 +19164,7 @@ where
1917619164 decode_update_add_htlcs: Mutex::new(decode_update_add_htlcs),
1917719165 claimable_payments: Mutex::new(ClaimablePayments {
1917819166 claimable_payments,
19179- pending_claiming_payments: pending_claiming_payments.unwrap(),
19167+ pending_claiming_payments: data. pending_claiming_payments.unwrap(),
1918019168 }),
1918119169 outbound_scid_aliases: Mutex::new(outbound_scid_aliases),
1918219170 short_to_chan_info: FairRwLock::new(short_to_chan_info),
@@ -19188,7 +19176,7 @@ where
1918819176 our_network_pubkey,
1918919177 secp_ctx,
1919019178
19191- highest_seen_timestamp: AtomicUsize::new(highest_seen_timestamp as usize),
19179+ highest_seen_timestamp: AtomicUsize::new(data. highest_seen_timestamp as usize),
1919219180
1919319181 per_peer_state: FairRwLock::new(per_peer_state),
1919419182
@@ -19500,7 +19488,7 @@ where
1950019488 //TODO: Broadcast channel update for closed channels, but only after we've made a
1950119489 //connection or two.
1950219490
19503- Ok((best_block_hash.clone() , channel_manager))
19491+ Ok((data.best_block_hash , channel_manager))
1950419492 }
1950519493}
1950619494
0 commit comments