Extract second stage of ChannelManager::read into from_channel_manager_data
What changed, and why it matters
This commit is a pure code refactoring: it moves an existing block of logic from one place inside a function into a newly created helper function, without changing what the logic actually does. There is no security-relevant behavior change visible in the diff.
No security action required; treat as routine refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change extracts the second stage of ChannelManager::read (validation and reconstruction from ChannelManagerData) into a new pub(super) constructor from_channel_manager_data. The read method now deserializes into ChannelManagerData and delegates to the new helper. The mut keyword on args is moved from the read signature to the helper signature because the helper now owns the mutation. No logic, validation, or security checks were added, removed, or altered.
Changed components
lightning/src/ln/channelmanager.rsInspect captured patch +29 / −1
diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs
index be3c8f5..43a8e1d 100644
--- a/lightning/src/ln/channelmanager.rs
+++ b/lightning/src/ln/channelmanager.rs
@@ -17700,7 +17700,7 @@ impl<
for (BlockHash, ChannelManager<M, T, ES, NS, SP, F, R, MR, L>)
{
fn read<Reader: io::Read>(
- reader: &mut Reader, mut args: ChannelManagerReadArgs<'a, M, T, ES, NS, SP, F, R, MR, L>,
+ reader: &mut Reader, args: ChannelManagerReadArgs<'a, M, T, ES, NS, SP, F, R, MR, L>,
) -> Result<Self, DecodeError> {
// Stage 1: Pure deserialization into DTO
let data: ChannelManagerData<SP> = ChannelManagerData::read(
@@ -17714,6 +17714,34 @@ impl<
)?;
// Stage 2: Validation and reconstruction
+ ChannelManager::from_channel_manager_data(data, args)
+ }
+}
+
+impl<
+ M: chain::Watch<SP::EcdsaSigner>,
+ T: BroadcasterInterface,
+ ES: EntropySource,
+ NS: NodeSigner,
+ SP: SignerProvider,
+ F: FeeEstimator,
+ R: Router,
+ MR: MessageRouter,
+ L: Logger + Clone,
+ > ChannelManager<M, T, ES, NS, SP, F, R, MR, L>
+{
+ /// Constructs a `ChannelManager` from deserialized data and runtime dependencies.
+ ///
+ /// This is the second stage of deserialization, taking the raw [`ChannelManagerData`] and combining it with the
+ /// provided [`ChannelManagerReadArgs`] to produce a fully functional `ChannelManager`.
+ ///
+ /// This method performs validation, reconciliation with [`ChannelMonitor`]s, and reconstruction of internal state.
+ /// It may close channels if monitors are ahead of the serialized state, and will replay any pending
+ /// [`ChannelMonitorUpdate`]s.
+ pub(super) fn from_channel_manager_data(
+ data: ChannelManagerData<SP>,
+ mut args: ChannelManagerReadArgs<'_, M, T, ES, NS, SP, F, R, MR, L>,
+ ) -> Result<(BlockHash, Self), DecodeError> {
let ChannelManagerData {
chain_hash,
best_block_height,
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.