From 38e43b27b1ee7b551e534a7886283d04a8946bac Mon Sep 17 00:00:00 2001 From: Duncan Dean Date: Fri, 29 Nov 2024 14:18:19 +0200 Subject: [PATCH] Allow writing V2 channels that are in a Funded phase We allow persisting `Channel`s in a `ChannelState::FundingNegotiated` only if the holder commitment number has advanced to the second commitment number. Currently we don't need new persistence, but we will need to persist some information such as `tx_signatures` when we allow contributing funds to dual-funded channels. --- lightning/src/ln/channel.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index 78248e977cb..b2e44f12924 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -9239,7 +9239,14 @@ impl Writeable for Channel where SP::Target: SignerProvider { self.context.channel_id.write(writer)?; { let mut channel_state = self.context.channel_state; - if matches!(channel_state, ChannelState::AwaitingChannelReady(_)|ChannelState::ChannelReady(_)) { + if matches!(channel_state, ChannelState::AwaitingChannelReady(_)|ChannelState::ChannelReady(_)) + { + channel_state.set_peer_disconnected(); + } else if matches!(channel_state, ChannelState::FundingNegotiated) && + self.context.holder_commitment_point.transaction_number() == INITIAL_COMMITMENT_NUMBER - 1 { + // This is a V2 session which has an active signing session + // TODO(dual_funding): When we allow contributing funds to dual-funded channels, + // we will need to handle persisting appropriate signing session state. channel_state.set_peer_disconnected(); } else { debug_assert!(false, "Pre-funded/shutdown channels should not be written");