Skip to content

Fix spurious panic on receipt of a block while awaiting funding #1711

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 1 commit into from
Sep 9, 2022

Conversation

TheBlueMatt
Copy link
Collaborator

When we receive a block we always test if we should send our channel_ready via check_get_channel_ready. If the channel in question requires confirmations, we quickly return if the funding transaction has not yet confirmed (or even been defined), however for 0conf channels the checks are necessarily more involved.

In any case, we wish to panic if the funding transaction has confirmations prior to when it should have been broadcasted. This is useful as it is easy for users to violate our broadcast-time invariants without noticing and the panic gives us an opportunity to catch it.

Sadly, in the case of 0conf channels, if we hadn't yet seen the funding transaction at all but receive a block we would hit this sanity check as we don't check whether there are actually funding transaction confirmations prior to panicing.

When we receive a block we always test if we should send our
channel_ready via `check_get_channel_ready`. If the channel in
question requires confirmations, we quickly return if the funding
transaction has not yet confirmed (or even been defined), however
for 0conf channels the checks are necessarily more involved.

In any case, we wish to panic if the funding transaction has
confirmations prior to when it should have been broadcasted. This
is useful as it is easy for users to violate our broadcast-time
invariants without noticing and the panic gives us an opportunity
to catch it.

Sadly, in the case of 0conf channels, if we hadn't yet seen the
funding transaction at all but receive a block we would hit this
sanity check as we don't check whether there are actually funding
transaction confirmations prior to panicing.
@TheBlueMatt TheBlueMatt added this to the 0.0.111 milestone Sep 9, 2022
Copy link
Contributor

@valentinewallace valentinewallace left a comment

Choose a reason for hiding this comment

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

Oops 🙈 I'm trying to think of how we could've caught this in review. Just more careful looking over of the code paths and brainstorming tests I suppose. But I do wonder if the ChannelState flags could somehow be made less confusing.

Test fails as expected on main

@ariard
Copy link

ariard commented Sep 9, 2022

Reviewing.

Copy link

@ariard ariard left a comment

Choose a reason for hiding this comment

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

ACK cb1db61

Code reviewed and test exercised to verify the fix.

@@ -4780,7 +4783,7 @@ impl<Signer: Sign> Channel<Signer> {
// We got a reorg but not enough to trigger a force close, just ignore.
false
} else {
if self.channel_state < ChannelState::ChannelFunded as u32 {
if self.funding_tx_confirmation_height != 0 && self.channel_state < ChannelState::ChannelFunded as u32 {
Copy link

Choose a reason for hiding this comment

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

Minor: comment could be stronger here it's preventing to hit the panic when we receive a transactions_confirmed() in the 0conf case as raised in pre-review.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You mean the top comment? I'm less worried about a new panic here, and more worried about someone breaking the logic. Its all a bit hairy, so good to be aware of the cases we have to handle correctly, panic or not.

@valentinewallace
Copy link
Contributor

OOC, was this found via fuzzing or?

@TheBlueMatt
Copy link
Collaborator Author

OOC, was this found via fuzzing or?

Prod, or at least testnet-prod-testing, 😭 .

@TheBlueMatt
Copy link
Collaborator Author

Gonna go ahead and land, can revisit the comment later if it matters.

@TheBlueMatt TheBlueMatt merged commit e94e403 into lightningdevkit:main Sep 9, 2022
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.

4 participants