Skip to content
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

DynComms [1/n]: Implement Quiescence Protocol #8270

Merged
merged 20 commits into from
Nov 27, 2024

Conversation

ProofOfKeags
Copy link
Collaborator

@ProofOfKeags ProofOfKeags commented Dec 12, 2023

Rebased on #9097 now.

NOTE: This PR is part of a series implementing Dynamic Commitments. This PR does not directly implement any Dynamic Commitments specific logic but quiescence is a protocol gadget that is a prerequisite for Dynamic Commitments.

Change Description

This change implements the behavior described in the Quiescence Specification. It allows us to respond to our peer's request to quiesce the channel as well as implementing some ChannelUpdateHandler operations that allow us to initiate the process ourselves.

Some commits towards the end of the series have been included to allow us to initiate quiescence via RPC for the purposes of integration and interop testing. These commits should be removed before this PR is considered ready to merge. They will ultimately be replaced by RPCs that initiate the Dynamic Commitments protocol itself which will implicitly initiate quiescence as part of its process.

NOTE: This PR does NOT include a mechanism for timing out a quiescence session. This means that if we have an intentionally or unintentionally uncooperative peer, the channel will remain quiesced indefinitely. This is not desirable and will either be addressed in later commits in this PR or into a subsequent PR. However, this PR is submitted without it as it is "complete" in its own right.

Steps to Test

Steps for reviewers to follow to test the change.

Pull Request Checklist

Testing

  • Your PR passes all CI checks.
  • Tests covering the positive and negative (error paths) are included.
  • Bug fixes contain tests triggering the bug to prevent regressions.

Code Style and Documentation

📝 Please see our Contribution Guidelines for further guidance.

@ProofOfKeags ProofOfKeags force-pushed the feature/stfu branch 3 times, most recently from d1aa5e5 to 9a6d107 Compare December 12, 2023 21:58
@ProofOfKeags ProofOfKeags marked this pull request as ready for review December 12, 2023 22:31
Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

Pretty straight forward diff! Missing some context from the other PR, and also still need to catch up w/ the latest state of the spec.

The main thing I think we need to zoom in on re unit tests is: the assumption that if we don't ACK a new settle/fail from the mailbox, then upon reconnection, all those items are retransmitted once again. If this is the case, then we can just force a disconnection after the stfu cycle is complete (see comment there about needing to send a special internal error to make that happen).

One other question I have is: is it the expected flow that a disconnect restores the channel lifecycle back to "active"? Or do we really want another protocol level message here so we can go back to normal w/o needing to re-create the peer connection?

lnwire/stfu.go Outdated Show resolved Hide resolved
lnwire/stfu.go Outdated Show resolved Hide resolved
htlcswitch/quiescer.go Outdated Show resolved Hide resolved
lnwallet/channel.go Outdated Show resolved Hide resolved
htlcswitch/link.go Outdated Show resolved Hide resolved
htlcswitch/link.go Outdated Show resolved Hide resolved
htlcswitch/link.go Outdated Show resolved Hide resolved
htlcswitch/link.go Outdated Show resolved Hide resolved
htlcswitch/link.go Outdated Show resolved Hide resolved
htlcswitch/link.go Outdated Show resolved Hide resolved
Copy link
Contributor

coderabbitai bot commented Jan 24, 2024

Important

Review skipped

Auto reviews are limited to specific labels.

🏷️ Labels to auto review (1)
  • llm-review

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The implementation of the Quiescence (stfu) protocol introduces a new mechanism for initiating quiescence on a link via RPC, enhancing channel synchronization, and error handling. It includes a state machine for managing the quiescence protocol, new RPC methods for testing purposes, and extends the functionality of existing structures to support these features. This change is pivotal for the advancement of Dynamic Commitments within the Lightning Network.

Changes

File Pattern Change Summary
htlcswitch/... Introduced InitStfu() method, quiescence protocol logic, and related error handling.
itest/... Added test cases for validating the quiescence protocol.
lnrpc/... New RPC method Quiesce and related entities for quiescence protocol handling.
lnwire/... Added MsgStfu message type and quiescence-related feature bits.
peer/... Handling of lnwire.Stfu messages.

Assessment against linked issues

Objective Addressed Explanation
Implement Quiescence (stfu) as a prerequisite for Dynamic Commitments (#8260)
Track state of Dynamic Commitments and upgrade channels to Taproot Channels (#7878) The PR focuses on the Quiescence protocol, not directly on Dynamic Commitments or Taproot Channels.
Address retransmission of shutdown message upon reconnection (#8397) This PR does not address the retransmission issues described.
Improve handling of dust HTLCs in channel closure (#7969) The changes are unrelated to dust HTLCs handling.

Possibly related issues

🐇✨
In the land of code and wire,
A rabbit hopped, with dreams so dire.
"Let's quiesce," it said, with glee,
For quieter channels, we all agree.
With stfu in place, and tests to run,
Our Lightning paths are second to none.
🌩️🐰💻


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Collaborator

@carlaKC carlaKC left a comment

Choose a reason for hiding this comment

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

lgtm 🏅

last few comments from me - none blocking merge!

htlcswitch/link.go Show resolved Hide resolved
@@ -398,6 +426,10 @@ func (q *QuiescerLive) sendOwedStfu(numPendingLocalUpdates uint64) error {
// state. If so, we will try to resolve any outstanding
// StfuReqs.
q.tryResolveStfuReq()

if q.isQuiescent() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

non-blocking / can be done in a followup if we feel strongly: we're doubling up on q.isQuiescent checks here and in tryResolveStfuReq - could be combined into one function that handles all our tasks once we're quiescent.

htlcswitch/quiescer.go Show resolved Hide resolved
); err != nil {
l.stfuFailf("%s", err.Error())
qReq.Resolve(fn.Err[lntypes.ChannelParty](err))
if l.noDanglingUpdates(lntypes.Local) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this commit going to be squashed before merge?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah I'll squash it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nvm the conflicts are ridiculous if I try and squash it.

htlcswitch: add sendOwedStfu method to quiescer
htlcswitch: use quiescer SendOwedStfu method in link stfu implementation
In this commit we defer processRemoteAdds using a new mechanism on
the quiescer where we capture a closure that needs to be run. We
do this because we need to avoid the scenario where we send back
immediate resolutions to the newly added HTLCs when quiescent as
it is a protocol violation. It is not enough for us to simply defer
sending the messages since the purpose of quiescence itself is to
have well-defined and agreed upon channel state. If, for whatever
reason, the node (or connection) is restarted between when these
hooks are captured and when they are ultimately run, they will
be resolved by the resolveFwdPkgs logic when the link comes back
up.

In a future commit we will explicitly call the quiescer's resume
method when it is OK for htlc traffic to commence.
In this commit we implement a noop quiescer that we will use when
the feature hasn't been negotiated. This will make it far easier to
manage quiescence operations without having a number of if statements
in the link logic.
Here we add a flag where we can disable quiescence. This will be used
in the case where the feature is not negotiated with our peer.
This change simplifies some of the quiescer responsibilities in
favor of making the link check whether or not it has a clean state
to be able to send or receive an stfu. This change was made on the
basis that the only use the quiescer makes of this information is
to assess that it is or is not zero. Further the difficulty of
checking this condition in the link is barely more burdensome than
selecting the proper information to pass to the quiescer anyway.
@guggero
Copy link
Collaborator

guggero commented Nov 27, 2024

Ran the failed "check commits" and "cross compile" locally since they fail on GitHub due to not enough space being available. Everything checks out, merging.

@guggero guggero merged commit c8cfa59 into lightningnetwork:master Nov 27, 2024
27 of 33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dynamic commitments P1 MUST be fixed or reviewed
Projects
Status: High Priority
Status: Done
Development

Successfully merging this pull request may close these issues.

8 participants