Skip to content

Commit 52862e3

Browse files
committed
Reset the channel state before restarting the channel establishment process.
1. When our counterparty disconnects during channel creation, we could have progressed along the channel creation process. 2. In such cases, retrying to send the OpenChannel message would fail because the channel state had progressed, leading to a panic in the `get_open_channel`. 3. To prevent this issue, introduce a new function, `reset_channel_state`, which resets the channel state to its initial state and use it before regenerating the OpenChannel message for an Unfunded Outbound channel. Fixes [#2982](#2982) (Identified by the full_stack_target fuzzer)
1 parent 1d9e541 commit 52862e3

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

lightning/src/ln/channel.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2123,6 +2123,10 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
21232123
self.channel_state > ChannelState::NegotiatingFunding(NegotiatingFundingFlags::OUR_INIT_SENT)
21242124
}
21252125

2126+
pub(super) fn reset_state(&mut self) {
2127+
self.channel_state = ChannelState::NegotiatingFunding(NegotiatingFundingFlags::OUR_INIT_SENT);
2128+
}
2129+
21262130
/// Returns true if this channel is fully established and not known to be closing.
21272131
/// Allowed in any state (including after shutdown)
21282132
pub fn is_usable(&self) -> bool {

lightning/src/ln/channelmanager.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10084,6 +10084,10 @@ where
1008410084
}
1008510085

1008610086
ChannelPhase::UnfundedOutboundV1(chan) => {
10087+
// Reset the channel state before resending the OpenChannel message.
10088+
// This step ensures that the channel is in its initial state before
10089+
// starting the channel establishment process.
10090+
chan.context.reset_state();
1008710091
pending_msg_events.push(events::MessageSendEvent::SendOpenChannel {
1008810092
node_id: chan.context.get_counterparty_node_id(),
1008910093
msg: chan.get_open_channel(self.chain_hash),

0 commit comments

Comments
 (0)