Simplify peer_storage_dir from Option<Vec> to Vec in ChannelManagerData
What changed, and why it matters
This is a small internal code cleanup in the Lightning Dev Kit's Rust implementation. It changes a data structure field from 'optional list' to just 'list', because an empty list and a missing list meant the same thing. There is no security-relevant change here.
No security action needed. Treat as routine refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors ChannelManagerData.peer_storage_dir from Option<Vec<(PublicKey, Vec<u8>)>> to Vec<(PublicKey, Vec<u8>)>. Serialization/deserialization behavior is preserved by using unwrap_or_default() when reading the optional TLV field, so legacy persisted data with None still loads as an empty vector. The downstream loop that populates per-peer state now iterates directly over the vector instead of matching on Some(...). This is a pure type simplification with no functional or security behavior change.
Changed components
lightning/src/ln/channelmanager.rsInspect captured patch +5 / −7
diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs
index 2df6576..3b3b9c8 100644
--- a/lightning/src/ln/channelmanager.rs
+++ b/lightning/src/ln/channelmanager.rs
@@ -17239,7 +17239,7 @@ pub(super) struct ChannelManagerData<SP: SignerProvider> {
claimable_htlc_onion_fields: Option<Vec<Option<RecipientOnionFields>>>,
inbound_payment_id_secret: Option<[u8; 32]>,
in_flight_monitor_updates: Option<HashMap<(PublicKey, ChannelId), Vec<ChannelMonitorUpdate>>>,
- peer_storage_dir: Option<Vec<(PublicKey, Vec<u8>)>>,
+ peer_storage_dir: Vec<(PublicKey, Vec<u8>)>,
async_receive_offer_cache: AsyncReceiveOfferCache,
// Marked `_legacy` because in versions > 0.2 we are taking steps to remove the requirement of
// regularly persisting the `ChannelManager` and instead rebuild the set of HTLC forwards from
@@ -17506,7 +17506,7 @@ impl<'a, ES: EntropySource, SP: SignerProvider, L: Logger>
.unwrap_or_else(new_hash_map),
inbound_payment_id_secret,
in_flight_monitor_updates,
- peer_storage_dir,
+ peer_storage_dir: peer_storage_dir.unwrap_or_default(),
async_receive_offer_cache,
})
}
@@ -18102,11 +18102,9 @@ impl<
let pending_outbounds = OutboundPayments::new(pending_outbound_payments);
- if let Some(peer_storage_dir) = peer_storage_dir {
- for (peer_pubkey, peer_storage) in peer_storage_dir {
- if let Some(peer_state) = per_peer_state.get_mut(&peer_pubkey) {
- peer_state.get_mut().unwrap().peer_storage = peer_storage;
- }
+ for (peer_pubkey, peer_storage) in peer_storage_dir {
+ if let Some(peer_state) = per_peer_state.get_mut(&peer_pubkey) {
+ peer_state.get_mut().unwrap().peer_storage = peer_storage;
}
}
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.