Skip to content

Commit 1944ac0

Browse files
joostjagerclaude
andcommitted
Extract second stage of ChannelManager::read into from_channel_manager_data
Move the validation and reconstruction logic (stage 2) from the ReadableArgs::read implementation into a new pub(super) constructor `from_channel_manager_data`. This separates the pure deserialization from the complex reconstruction logic, making the code more modular and easier to test. The read function now: 1. Deserializes into ChannelManagerData (stage 1) 2. Calls from_channel_manager_data for validation/reconstruction (stage 2) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent ae60beb commit 1944ac0

1 file changed

Lines changed: 39 additions & 1 deletion

File tree

lightning/src/ln/channelmanager.rs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17838,7 +17838,7 @@ where
1783817838
L::Target: Logger,
1783917839
{
1784017840
fn read<Reader: io::Read>(
17841-
reader: &mut Reader, mut args: ChannelManagerReadArgs<'a, M, T, ES, NS, SP, F, R, MR, L>,
17841+
reader: &mut Reader, args: ChannelManagerReadArgs<'a, M, T, ES, NS, SP, F, R, MR, L>,
1784217842
) -> Result<Self, DecodeError> {
1784317843
// Stage 1: Pure deserialization into DTO
1784417844
let data: ChannelManagerData<SP> = ChannelManagerData::read(
@@ -17852,6 +17852,44 @@ where
1785217852
)?;
1785317853

1785417854
// Stage 2: Validation and reconstruction
17855+
ChannelManager::from_channel_manager_data(data, args)
17856+
}
17857+
}
17858+
17859+
impl<
17860+
M: Deref,
17861+
T: Deref,
17862+
ES: Deref,
17863+
NS: Deref,
17864+
SP: Deref,
17865+
F: Deref,
17866+
R: Deref,
17867+
MR: Deref,
17868+
L: Deref + Clone,
17869+
> ChannelManager<M, T, ES, NS, SP, F, R, MR, L>
17870+
where
17871+
M::Target: chain::Watch<<SP::Target as SignerProvider>::EcdsaSigner>,
17872+
T::Target: BroadcasterInterface,
17873+
ES::Target: EntropySource,
17874+
NS::Target: NodeSigner,
17875+
SP::Target: SignerProvider,
17876+
F::Target: FeeEstimator,
17877+
R::Target: Router,
17878+
MR::Target: MessageRouter,
17879+
L::Target: Logger,
17880+
{
17881+
/// Constructs a `ChannelManager` from deserialized data and runtime dependencies.
17882+
///
17883+
/// This is the second stage of deserialization, taking the raw [`ChannelManagerData`] and combining it with the
17884+
/// provided [`ChannelManagerReadArgs`] to produce a fully functional `ChannelManager`.
17885+
///
17886+
/// This method performs validation, reconciliation with [`ChannelMonitor`]s, and reconstruction of internal state.
17887+
/// It may close channels if monitors are ahead of the serialized state, and will replay any pending
17888+
/// [`ChannelMonitorUpdate`]s.
17889+
pub(super) fn from_channel_manager_data(
17890+
data: ChannelManagerData<SP>,
17891+
mut args: ChannelManagerReadArgs<'_, M, T, ES, NS, SP, F, R, MR, L>,
17892+
) -> Result<(BlockHash, Self), DecodeError> {
1785517893
// Extract mutable/complex fields into local variables; simple fields accessed via data.*
1785617894
let mut forward_htlcs_legacy = data.forward_htlcs;
1785717895
let mut claimable_htlcs_list = data.claimable_htlcs;

0 commit comments

Comments
 (0)