Skip to content

Commit

Permalink
Reset the channel state before restarting the channel establishment p…
Browse files Browse the repository at this point in the history
…rocess.

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 [lightningdevkit#2982](lightningdevkit#2982)

(Identified by the full_stack_target fuzzer)
  • Loading branch information
shaavan committed Apr 8, 2024
1 parent 1d9e541 commit 52862e3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lightning/src/ln/channel.rs
Expand Up @@ -2123,6 +2123,10 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
self.channel_state > ChannelState::NegotiatingFunding(NegotiatingFundingFlags::OUR_INIT_SENT)
}

pub(super) fn reset_state(&mut self) {
self.channel_state = ChannelState::NegotiatingFunding(NegotiatingFundingFlags::OUR_INIT_SENT);
}

/// Returns true if this channel is fully established and not known to be closing.
/// Allowed in any state (including after shutdown)
pub fn is_usable(&self) -> bool {
Expand Down
4 changes: 4 additions & 0 deletions lightning/src/ln/channelmanager.rs
Expand Up @@ -10084,6 +10084,10 @@ where
}

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

0 comments on commit 52862e3

Please sign in to comment.