Skip to content

Commit 71f99fb

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 0f3cc73 commit 71f99fb

1 file changed

Lines changed: 8 additions & 11 deletions

File tree

lightning/src/ln/channelmanager.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17402,7 +17402,7 @@ where
1740217402
// Marked `_legacy` because in versions > 0.2 we are taking steps to remove the requirement of
1740317403
// regularly persisting the `ChannelManager` and instead rebuild the set of HTLC forwards from
1740417404
// `Channel{Monitor}` data. See [`ChannelManager::read`].
17405-
pending_intercepted_htlcs_legacy: Option<HashMap<InterceptId, PendingAddHTLCInfo>>,
17405+
pending_intercepted_htlcs_legacy: HashMap<InterceptId, PendingAddHTLCInfo>,
1740617406
pending_outbound_payments: HashMap<PaymentId, PendingOutboundPayment>,
1740717407
pending_claiming_payments: HashMap<PaymentHash, ClaimingPayment>,
1740817408
received_network_pubkey: Option<PublicKey>,
@@ -17415,7 +17415,7 @@ where
1741517415
// Marked `_legacy` because in versions > 0.2 we are taking steps to remove the requirement of
1741617416
// regularly persisting the `ChannelManager` and instead rebuild the set of HTLC forwards from
1741717417
// `Channel{Monitor}` data. See [`ChannelManager::read`].
17418-
decode_update_add_htlcs_legacy: Option<HashMap<u64, Vec<msgs::UpdateAddHTLC>>>,
17418+
decode_update_add_htlcs_legacy: HashMap<u64, Vec<msgs::UpdateAddHTLC>>,
1741917419
inbound_payment_id_secret: Option<[u8; 32]>,
1742017420
in_flight_monitor_updates: Option<HashMap<(PublicKey, ChannelId), Vec<ChannelMonitorUpdate>>>,
1742117421
peer_storage_dir: Option<Vec<(PublicKey, Vec<u8>)>>,
@@ -17673,7 +17673,8 @@ where
1767317673
peer_init_features,
1767417674
pending_events_read,
1767517675
highest_seen_timestamp,
17676-
pending_intercepted_htlcs_legacy,
17676+
pending_intercepted_htlcs_legacy: pending_intercepted_htlcs_legacy
17677+
.unwrap_or_else(new_hash_map),
1767717678
pending_outbound_payments,
1767817679
// unwrap safety: pending_claiming_payments is guaranteed to be `Some` after read_tlv_fields
1767917680
pending_claiming_payments: pending_claiming_payments.unwrap(),
@@ -17685,7 +17686,8 @@ where
1768517686
claimable_htlc_purposes,
1768617687
probing_cookie_secret,
1768717688
claimable_htlc_onion_fields,
17688-
decode_update_add_htlcs_legacy,
17689+
decode_update_add_htlcs_legacy: decode_update_add_htlcs_legacy
17690+
.unwrap_or_else(new_hash_map),
1768917691
inbound_payment_id_secret,
1769017692
in_flight_monitor_updates,
1769117693
peer_storage_dir,
@@ -18022,7 +18024,7 @@ where
1802218024
peer_init_features,
1802318025
mut pending_events_read,
1802418026
highest_seen_timestamp,
18025-
pending_intercepted_htlcs_legacy,
18027+
mut pending_intercepted_htlcs_legacy,
1802618028
pending_outbound_payments,
1802718029
pending_claiming_payments,
1802818030
received_network_pubkey,
@@ -18031,18 +18033,13 @@ where
1803118033
claimable_htlc_purposes,
1803218034
mut probing_cookie_secret,
1803318035
claimable_htlc_onion_fields,
18034-
decode_update_add_htlcs_legacy,
18036+
mut decode_update_add_htlcs_legacy,
1803518037
mut inbound_payment_id_secret,
1803618038
mut in_flight_monitor_updates,
1803718039
peer_storage_dir,
1803818040
async_receive_offer_cache,
1803918041
} = data;
1804018042

18041-
let mut pending_intercepted_htlcs_legacy =
18042-
pending_intercepted_htlcs_legacy.unwrap_or_else(new_hash_map);
18043-
let mut decode_update_add_htlcs_legacy =
18044-
decode_update_add_htlcs_legacy.unwrap_or_else(new_hash_map);
18045-
1804618043
let empty_peer_state = || PeerState {
1804718044
channel_by_id: new_hash_map(),
1804818045
inbound_channel_request_by_id: new_hash_map(),

0 commit comments

Comments
 (0)