Skip to content

Log and panic when fallen behind remote commitment number #2717

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

Conversation

AnthonyRonning
Copy link
Contributor

@AnthonyRonning AnthonyRonning commented Nov 8, 2023

Pretty sure this is the source of many of our force closes. The if-else going on here does not consider when we have fallen behind, and the last else state assumes that the other peer is the one that is fallen behind, which is not accurate in all of our revoked transaction cases. When we get that log, it always ends with our users losing funds.

I just copied and pasted the identical text from above where some of the state is checked, not sure what exactly it should say.

@codecov-commenter
Copy link

codecov-commenter commented Nov 8, 2023

Codecov Report

Attention: 10 lines in your changes are missing coverage. Please review.

Comparison is base (1e25979) 88.80% compared to head (585bb07) 88.81%.
Report is 2 commits behind head on main.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2717   +/-   ##
=======================================
  Coverage   88.80%   88.81%           
=======================================
  Files         113      113           
  Lines       89170    89179    +9     
  Branches    89170    89179    +9     
=======================================
+ Hits        79191    79205   +14     
+ Misses       7735     7726    -9     
- Partials     2244     2248    +4     
Files Coverage Δ
lightning/src/ln/channel.rs 88.52% <0.00%> (-0.14%) ⬇️

... and 7 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@AnthonyRonning AnthonyRonning force-pushed the fix-previous-commitment-number-error branch from 22ed16f to 585bb07 Compare November 8, 2023 04:45
} else {
return Err(ChannelError::Close("Peer attempted to reestablish channel with a very old local commitment transaction".to_owned()));
Copy link
Contributor

Choose a reason for hiding this comment

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

Even if we can't panic (as matt suggests).
I think it would be helpful to at-least add a log.
I was thinking about it earlier when you posted to channel, currently we assume if commitment numbers don't match, peer must be stale. It could be helpful to distinguish b/w < and > cases here.

@TheBlueMatt
Copy link
Collaborator

I need to write some tests, but I do think there's an off-by-one in the original panic, can you try applying this and seeing if it fixes the issue:

diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs
index 1b5d6cfa7..b6a13bcd3 100644
--- a/lightning/src/ln/channel.rs
+++ b/lightning/src/ln/channel.rs
@@ -4159,7 +4159,7 @@ impl<SP: Deref> Channel<SP> where
                        if expected_point != PublicKey::from_secret_key(&self.context.secp_ctx, &given_secret) {
                                return Err(ChannelError::Close("Peer sent a garbage channel_reestablish with secret key not matching the commitment height provided".to_owned()));
                        }
-                       if msg.next_remote_commitment_number > INITIAL_COMMITMENT_NUMBER - self.context.cur_holder_commitment_transaction_number {
+                       if msg.next_remote_commitment_number >= INITIAL_COMMITMENT_NUMBER - self.context.cur_holder_commitment_transaction_number {
                                macro_rules! log_and_panic {
                                        ($err_msg: expr) => {
                                                log_error!(logger, $err_msg, &self.context.channel_id, log_pubkey!(self.context.counterparty_node_id));

@TheBlueMatt
Copy link
Collaborator

Closing in favor of #2721 (which is the above patch ++)

@TheBlueMatt TheBlueMatt closed this Nov 9, 2023
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