Skip to content

Commit cd357df

Browse files
joostjagerclaude
andcommitted
Resolve optional hash map TLV fields during ChannelManagerData deserialization
Move the unwrap_or_else(new_hash_map) resolution for pending_intercepted_htlcs and decode_update_add_htlcs from stage 2 (from_channel_manager_data) to stage 1 (ChannelManagerData::read). This changes the struct fields from Option<HashMap> to HashMap, making it explicit that these are always present after deserialization. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 2e95d36 commit cd357df

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17399,7 +17399,7 @@ where
1739917399
peer_init_features: Vec<(PublicKey, InitFeatures)>,
1740017400
pending_events_read: VecDeque<(events::Event, Option<EventCompletionAction>)>,
1740117401
highest_seen_timestamp: u32,
17402-
pending_intercepted_htlcs_legacy: Option<HashMap<InterceptId, PendingAddHTLCInfo>>,
17402+
pending_intercepted_htlcs_legacy: HashMap<InterceptId, PendingAddHTLCInfo>,
1740317403
pending_outbound_payments: HashMap<PaymentId, PendingOutboundPayment>,
1740417404
pending_claiming_payments: HashMap<PaymentHash, ClaimingPayment>,
1740517405
received_network_pubkey: Option<PublicKey>,
@@ -17412,7 +17412,7 @@ where
1741217412
// Marked `_legacy` because in versions > 0.2 we are taking steps to remove the requirement of
1741317413
// regularly persisting the `ChannelManager` and instead rebuild the set of HTLC forwards from
1741417414
// `Channel{Monitor}` data. See [`ChannelManager::read`].
17415-
decode_update_add_htlcs_legacy: Option<HashMap<u64, Vec<msgs::UpdateAddHTLC>>>,
17415+
decode_update_add_htlcs_legacy: HashMap<u64, Vec<msgs::UpdateAddHTLC>>,
1741617416
inbound_payment_id_secret: Option<[u8; 32]>,
1741717417
in_flight_monitor_updates: Option<HashMap<(PublicKey, ChannelId), Vec<ChannelMonitorUpdate>>>,
1741817418
peer_storage_dir: Option<Vec<(PublicKey, Vec<u8>)>>,
@@ -17670,7 +17670,8 @@ where
1767017670
peer_init_features,
1767117671
pending_events_read,
1767217672
highest_seen_timestamp,
17673-
pending_intercepted_htlcs_legacy,
17673+
pending_intercepted_htlcs_legacy: pending_intercepted_htlcs_legacy
17674+
.unwrap_or_else(new_hash_map),
1767417675
pending_outbound_payments,
1767517676
// unwrap safety: pending_claiming_payments is guaranteed to be `Some` after read_tlv_fields
1767617677
pending_claiming_payments: pending_claiming_payments.unwrap(),
@@ -17682,7 +17683,8 @@ where
1768217683
claimable_htlc_purposes,
1768317684
probing_cookie_secret,
1768417685
claimable_htlc_onion_fields,
17685-
decode_update_add_htlcs_legacy,
17686+
decode_update_add_htlcs_legacy: decode_update_add_htlcs_legacy
17687+
.unwrap_or_else(new_hash_map),
1768617688
inbound_payment_id_secret,
1768717689
in_flight_monitor_updates,
1768817690
peer_storage_dir,
@@ -18019,7 +18021,7 @@ where
1801918021
peer_init_features,
1802018022
mut pending_events_read,
1802118023
highest_seen_timestamp,
18022-
pending_intercepted_htlcs_legacy,
18024+
mut pending_intercepted_htlcs_legacy,
1802318025
pending_outbound_payments,
1802418026
pending_claiming_payments,
1802518027
received_network_pubkey,
@@ -18028,18 +18030,13 @@ where
1802818030
claimable_htlc_purposes,
1802918031
mut probing_cookie_secret,
1803018032
claimable_htlc_onion_fields,
18031-
decode_update_add_htlcs_legacy,
18033+
mut decode_update_add_htlcs_legacy,
1803218034
mut inbound_payment_id_secret,
1803318035
mut in_flight_monitor_updates,
1803418036
peer_storage_dir,
1803518037
async_receive_offer_cache,
1803618038
} = data;
1803718039

18038-
let mut pending_intercepted_htlcs_legacy =
18039-
pending_intercepted_htlcs_legacy.unwrap_or_else(new_hash_map);
18040-
let mut decode_update_add_htlcs_legacy =
18041-
decode_update_add_htlcs_legacy.unwrap_or_else(new_hash_map);
18042-
1804318040
let empty_peer_state = || PeerState {
1804418041
channel_by_id: new_hash_map(),
1804518042
inbound_channel_request_by_id: new_hash_map(),

0 commit comments

Comments
 (0)