Skip to content

Split commitment_signed handling by check-accept #3633

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

Conversation

jkczyz
Copy link
Contributor

@jkczyz jkczyz commented Feb 28, 2025

When handling commitment_signed messages, a number of checks are performed before a ChannelMonitorUpdate is created and returned. Once splicing is added, these checks need to be performed on the primary FundingScope and any pending scopes that resulted from splicing or RBF.

This PR splits the handling into a check and accept methods, taking &self and &mut self, respectively. This ensures that the ChannelContext is not modified between checks. Once all funding scopes have been checked successfully, the accept portion of the code can then execute.

@jkczyz jkczyz force-pushed the 2025-02-split-commitment-signed branch from d8bdc8f to 3a52856 Compare February 28, 2025 21:26
Copy link
Contributor

@wpaulino wpaulino left a comment

Choose a reason for hiding this comment

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

This was much simpler than we expected :)

@jkczyz jkczyz force-pushed the 2025-02-split-commitment-signed branch from 9c29928 to 5d9e8f1 Compare February 28, 2025 21:38
@jkczyz
Copy link
Contributor Author

jkczyz commented Feb 28, 2025

Latest pushes were just to address cargo doc failures in CI. Will address the comments shortly.

@jkczyz jkczyz force-pushed the 2025-02-split-commitment-signed branch from 5d9e8f1 to 08cef17 Compare February 28, 2025 22:07
@jkczyz jkczyz added the weekly goal Someone wants to land this this week label Feb 28, 2025
@jkczyz
Copy link
Contributor Author

jkczyz commented Feb 28, 2025

This was much simpler than we expected :)

Yeah, luckily compiling after removing the mut from the &self mut parameter showed the mutability wasn't needed until all the checks were done. So it turned out to be a relatively straightforward refactor.

@jkczyz jkczyz requested a review from wpaulino February 28, 2025 22:10
@jkczyz jkczyz force-pushed the 2025-02-split-commitment-signed branch from 08cef17 to baa9e76 Compare February 28, 2025 22:12
@wpaulino
Copy link
Contributor

wpaulino commented Mar 1, 2025

Feel free to squash

@jkczyz jkczyz force-pushed the 2025-02-split-commitment-signed branch from baa9e76 to 119b64a Compare March 1, 2025 00:12
@jkczyz
Copy link
Contributor Author

jkczyz commented Mar 1, 2025

Squashed

Copy link

codecov bot commented Mar 1, 2025

Codecov Report

Attention: Patch coverage is 93.38843% with 8 lines in your changes missing coverage. Please review.

Project coverage is 89.19%. Comparing base (36ba27a) to head (119b64a).

Files with missing lines Patch % Lines
lightning/src/ln/channel.rs 93.38% 6 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3633      +/-   ##
==========================================
- Coverage   89.19%   89.19%   -0.01%     
==========================================
  Files         152      152              
  Lines      118681   118696      +15     
  Branches   118681   118696      +15     
==========================================
+ Hits       105860   105869       +9     
- Misses      10236    10242       +6     
  Partials     2585     2585              

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

Copy link
Contributor

@wpaulino wpaulino left a comment

Choose a reason for hiding this comment

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

LGTM, one last minor comment

@wpaulino wpaulino requested a review from TheBlueMatt March 3, 2025 15:33
@jkczyz jkczyz requested a review from wpaulino March 3, 2025 17:36
wpaulino
wpaulino previously approved these changes Mar 3, 2025
@@ -529,6 +529,14 @@ impl_writeable_tlv_based_enum_upgradable!(OnchainEvent,

);

/// Partial data from ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo used to simplify the
/// return type of `FundedChannel::validate_commitment_signed`.
pub(crate) struct LatestHolderCommitmentTXInfo {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this here when its only used in channel.rs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, it's copied partly from ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo , so made sense to keep it close. Happy to move it if you prefer.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I mean we could (should?) use it in ChannelMonitorUpdateStep::LatestHolderCommitmentTxInfo, but if we're not gonna use it it feels really weird to not just define it in the file we're using it in.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, I didn't use it here because it seems it would require introducing custom serialization code, which we'd want to avoid. Having it here was more so because if the enum is updated, this probably should be, too. I suppose a comment would suffice, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to channel.rs and added a comment in channelmonitor.rs.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess I'm still confused why rustc wont enforce that for us by just making things not compile, but okay.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Someone can mistakenly compute the new field once for all funding scopes when it should be computed individually for each. This is all hypothetical since the right way may be entirely obvious depending on the particulars.

@jkczyz jkczyz requested a review from TheBlueMatt March 5, 2025 15:57
@jkczyz jkczyz force-pushed the 2025-02-split-commitment-signed branch 2 times, most recently from 4c758a8 to 7d1097a Compare March 5, 2025 21:37
jkczyz added 4 commits March 5, 2025 15:37
When handling commitment_signed messages, a number of checks are
performed before a ChannelMonitorUpdate is created and returned. Once
splicing is added, these checks need to be performed on the primary
FundingScope and any pending scopes that resulted from splicing or RBF.

This commit splits the handling into a check and accept methods, taking
&self and &mut self, respectively. This ensures that the ChannelContext
is not modified between checks. Once all funding scopes have been
checked successfully, the accept portion of the code can then execute.
Now that commitment_signed is split into check and accept methods, move
the check portion from FundedChannel to ChannelContext. This allows
calling it with a different FundingScope when there are pending splices
and RBF attempts.
Now that validate_commitment_signed encapsulates all funding-specific
checks, move the holder_commitment_point advancement immediately
following the call to it. While there should be any early returns at
that point, it's good to have move it earlier in case of future changes.
@jkczyz jkczyz force-pushed the 2025-02-split-commitment-signed branch from 7d1097a to 2be03ce Compare March 5, 2025 21:38
@jkczyz
Copy link
Contributor Author

jkczyz commented Mar 5, 2025

Sorry, ended up rebasing on main since I accidentally got the branch in a weird state while interactively rebasing.

@jkczyz jkczyz requested a review from wpaulino March 5, 2025 21:40
@TheBlueMatt TheBlueMatt merged commit c4d0560 into lightningdevkit:main Mar 6, 2025
25 of 27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
weekly goal Someone wants to land this this week
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants