Skip to content

Commit 9a05daf

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 397cc1d commit 9a05daf

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
@@ -17234,7 +17234,7 @@ pub(super) struct ChannelManagerData<SP: SignerProvider> {
1723417234
// Marked `_legacy` because in versions > 0.2 we are taking steps to remove the requirement of
1723517235
// regularly persisting the `ChannelManager` and instead rebuild the set of HTLC forwards from
1723617236
// `Channel{Monitor}` data. See [`ChannelManager::read`].
17237-
pending_intercepted_htlcs_legacy: Option<HashMap<InterceptId, PendingAddHTLCInfo>>,
17237+
pending_intercepted_htlcs_legacy: HashMap<InterceptId, PendingAddHTLCInfo>,
1723817238
pending_outbound_payments: HashMap<PaymentId, PendingOutboundPayment>,
1723917239
pending_claiming_payments: HashMap<PaymentHash, ClaimingPayment>,
1724017240
received_network_pubkey: Option<PublicKey>,
@@ -17247,7 +17247,7 @@ pub(super) struct ChannelManagerData<SP: SignerProvider> {
1724717247
// Marked `_legacy` because in versions > 0.2 we are taking steps to remove the requirement of
1724817248
// regularly persisting the `ChannelManager` and instead rebuild the set of HTLC forwards from
1724917249
// `Channel{Monitor}` data. See [`ChannelManager::read`].
17250-
decode_update_add_htlcs_legacy: Option<HashMap<u64, Vec<msgs::UpdateAddHTLC>>>,
17250+
decode_update_add_htlcs_legacy: HashMap<u64, Vec<msgs::UpdateAddHTLC>>,
1725117251
inbound_payment_id_secret: Option<[u8; 32]>,
1725217252
in_flight_monitor_updates: Option<HashMap<(PublicKey, ChannelId), Vec<ChannelMonitorUpdate>>>,
1725317253
peer_storage_dir: Option<Vec<(PublicKey, Vec<u8>)>>,
@@ -17496,7 +17496,8 @@ impl<'a, ES: EntropySource, SP: SignerProvider, L: Logger>
1749617496
peer_init_features,
1749717497
pending_events_read,
1749817498
highest_seen_timestamp,
17499-
pending_intercepted_htlcs_legacy,
17499+
pending_intercepted_htlcs_legacy: pending_intercepted_htlcs_legacy
17500+
.unwrap_or_else(new_hash_map),
1750017501
pending_outbound_payments,
1750117502
// unwrap safety: pending_claiming_payments is guaranteed to be `Some` after read_tlv_fields
1750217503
pending_claiming_payments: pending_claiming_payments.unwrap(),
@@ -17508,7 +17509,8 @@ impl<'a, ES: EntropySource, SP: SignerProvider, L: Logger>
1750817509
claimable_htlc_purposes,
1750917510
probing_cookie_secret,
1751017511
claimable_htlc_onion_fields,
17511-
decode_update_add_htlcs_legacy,
17512+
decode_update_add_htlcs_legacy: decode_update_add_htlcs_legacy
17513+
.unwrap_or_else(new_hash_map),
1751217514
inbound_payment_id_secret,
1751317515
in_flight_monitor_updates,
1751417516
peer_storage_dir,
@@ -17791,7 +17793,7 @@ impl<
1779117793
peer_init_features,
1779217794
mut pending_events_read,
1779317795
highest_seen_timestamp,
17794-
pending_intercepted_htlcs_legacy,
17796+
mut pending_intercepted_htlcs_legacy,
1779517797
pending_outbound_payments,
1779617798
pending_claiming_payments,
1779717799
received_network_pubkey,
@@ -17800,18 +17802,13 @@ impl<
1780017802
claimable_htlc_purposes,
1780117803
mut probing_cookie_secret,
1780217804
claimable_htlc_onion_fields,
17803-
decode_update_add_htlcs_legacy,
17805+
mut decode_update_add_htlcs_legacy,
1780417806
mut inbound_payment_id_secret,
1780517807
mut in_flight_monitor_updates,
1780617808
peer_storage_dir,
1780717809
async_receive_offer_cache,
1780817810
} = data;
1780917811

17810-
let mut pending_intercepted_htlcs_legacy =
17811-
pending_intercepted_htlcs_legacy.unwrap_or_else(new_hash_map);
17812-
let mut decode_update_add_htlcs_legacy =
17813-
decode_update_add_htlcs_legacy.unwrap_or_else(new_hash_map);
17814-
1781517812
let empty_peer_state = || PeerState {
1781617813
channel_by_id: new_hash_map(),
1781717814
inbound_channel_request_by_id: new_hash_map(),

0 commit comments

Comments
 (0)