Skip to content

Fix debug panic in full_stack fuzz test #3602

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 14, 2025

Conversation

jkczyz
Copy link
Contributor

@jkczyz jkczyz commented Feb 13, 2025

d4bd56f changed the logic for calling unset_funding_info such that it may be called on a channel that was already in ChannelPhase::Funded when handling funding_signed. This caused a debug panic in the full_stack fuzz test when calling FundedChannel::unset_funding_info. Fix this by only calling unset_funding_info on watch_channel error, as was previously the case.

This also reverts moving the channel back into ChannelPhase::UnfundedOutboundV1, which should be fine since the channel is about to be removed.

Fixes #3597

d4bd56f changed the logic for calling
unset_funding_info such that it may be called on a channel that was
already in ChannelPhase::Funded when handling funding_signed. This
caused a debug panic in the full_stack fuzz test when calling
FundedChannel::unset_funding_info. Fix this by only calling
unset_funding_info on watch_channel error, as was previously the case.

This also reverts moving the channel back into
ChannelPhase::UnfundedOutboundV1, which should be fine since the channel
is about to be removed.
wpaulino
wpaulino previously approved these changes Feb 13, 2025
})
{
Ok((funded_chan, persist_status)) => {
handle_new_monitor_update!(self, persist_status, peer_state_lock, peer_state, per_peer_state, funded_chan, INITIAL_MONITOR);
Ok(())
},
Err(e) => {
// We weren't able to watch the channel to begin with, so no
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't make any sense to me. Going by the comment, try_channel_entry will, when it hits a ChannelError::Close, call Channel::force_shutdown, which will create a ShutdownResult (ultimately stored as shutdown_finish) with a ChannelMonitorUpdate (since !self.channel_state.is_pre_funded_state()) but when we try to apply it we'll fail (as we never added the original monitor).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW I think this was also the case prior to d4bd56f. Wouldn't the monitor update be applied to the original monitor (since we found a duplicate, the original monitor must still be around)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh this actually shouldn't be reachable because the monitor update isn't generated without a funding_txo, which is unset in unset_funding_info

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, hmm, maybe the !self.channel_state.is_pre_funded_state check didn't pass then (and doesn't pass now) because initial_commitment_signed properly only advances the state after checks...so I guess its right, but it certainly is confusing.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is quite annoying that we have the channel_state which can be out of whack with the ChannelPhase...can we add an assertion in funding_signed that the channel_state matches the phase we decide to go with after we call the inner funding_signed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, pushed a change adding the assertion. Let me know if I misunderstood what you meant.

@TheBlueMatt
Copy link
Collaborator

Hmm, let's talk separately about adding files to fuzz/test_cases. I currently maintain a local repo that I usually put at that path and we might want to leave it that way (maintaining that repo separately publicly), which would make files in that folder always conflict.

@TheBlueMatt
Copy link
Collaborator

Otherwise LGTM

@jkczyz
Copy link
Contributor Author

jkczyz commented Feb 14, 2025

Hmm, let's talk separately about adding files to fuzz/test_cases. I currently maintain a local repo that I usually put at that path and we might want to leave it that way (maintaining that repo separately publicly), which would make files in that folder always conflict.

Whoops, accidentally added that but thought I had removed it. Will push a fix shortly.

@jkczyz jkczyz force-pushed the 2025-02-unset-funding-info branch from 549be04 to 5382fc7 Compare February 14, 2025 15:43
TheBlueMatt
TheBlueMatt previously approved these changes Feb 14, 2025
Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gonna go ahead and land, only changes since @wpaulino's ACK were some new debug assertions.

@TheBlueMatt
Copy link
Collaborator

Oh nvm, the build fails in --release mode - debug_assertions have to compile-check even in --release.

This is a sanity check that ChannelPhase and ChannelState do not go out
of sync.
Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, now gonna land it since the only changes since @wpaulino's ack were debug assertions.

@TheBlueMatt TheBlueMatt merged commit ec19ba1 into lightningdevkit:main Feb 14, 2025
25 of 26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

debug panic (and likely buggy behavior) when processing a funding_signed in a funded channel
3 participants