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

contractcourt: use the sweeper for HTLC offered remote timeout resolu… #9062

Merged
merged 2 commits into from
Sep 19, 2024

Conversation

Roasbeef
Copy link
Member

@Roasbeef Roasbeef commented Sep 4, 2024

…tion

In this commit, we bring the timeout resolver more in line with the success resolver by using the sweeper to handle the HTLC offered remote timeout outputs. These are outputs that we can sweep directly from the remote party's commitment transaction when they broadcast their version of the commitment transaction.

With this change, we slim down the scope slightly by only doing this for anchor channels. Non-anchor channels will continue to use the utxonursery for this output type for now.

@Roasbeef Roasbeef added enhancement Improvements to existing features / behaviour channel closing Related to the closing of channels cooperatively and uncooperatively HTLC taproot taproot chans labels Sep 4, 2024
Copy link
Contributor

coderabbitai bot commented Sep 4, 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.


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

@yyforyongyu yyforyongyu left a comment

Choose a reason for hiding this comment

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

Yeah I also noticed this in #8922 where the direct spend is not offered to the sweeper and was planning to fix it afterwards. I think we need to handle the case where there's already a force close in the process and the output has already been offered to the utxo nursery. In that case, during the startup, we need to delete it from the nursery and offer it to the sweeper?

@Roasbeef
Copy link
Member Author

Roasbeef commented Sep 9, 2024

I think we need to handle the case where there's already a force close in the process and the output has already been offered to the utxo nursery. In that case, during the startup, we need to delete it from the nursery and offer it to the sweeper?

My idea to handle that is if the close is already in process, and offered, then this proceeds as normal (re the incubated field). I fixed a unit test issue, but need to see why the itest is failing rn.

Copy link
Collaborator

@morehouse morehouse left a comment

Choose a reason for hiding this comment

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

Concept ACK

contractcourt/htlc_timeout_resolver.go Outdated Show resolved Hide resolved
@Roasbeef Roasbeef marked this pull request as ready for review September 11, 2024 01:43
@Roasbeef
Copy link
Member Author

Pushed up a new version, itests+unit tests should be passing now.

It also starts to send all new remote HTLC timeout outputs to the sweeper (prior commit was just taproot outputs).

@Roasbeef
Copy link
Member Author

I think we need to handle the case where there's already a force close in the process and the output has already been offered to the utxo nursery. In that case, during the startup, we need to delete it from the nursery and offer it to the sweeper?

With the latest version, I modified the logic slightly:

  • We no longer attempt to set outputIncubated to true, nor checkpoint (needed to change some tests as now there's only a single checkpoint).
  • As a result, we'll always re-offer the direct expired HTLC outputs to the sweeper.
  • Post upgrade, if an existing HTLC has already been offered to the sweeper, then outputIncubated will be true, skipping the section that attempts to re-offer the output.

I also needed to make a change to the way we generate reports for outputs. Previously it would skip asking the CNCT for the report if SignDetails was nil, instead assuming the nursery would have the data necessary to generate a report. Now we'll only ask the nursery if SignDetails is nil and SignedTimeoutTx is not nil (only non-anchor channels fall into this bucket).

@Roasbeef Roasbeef force-pushed the htlc-resolution-sweeper branch 2 times, most recently from 6c191bd to 2491692 Compare September 12, 2024 00:34
@Roasbeef Roasbeef added this to the v0.19.0 milestone Sep 12, 2024
Copy link
Collaborator

@yyforyongyu yyforyongyu left a comment

Choose a reason for hiding this comment

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

Is there a chance we fix this after #8922 - think things would be more clear there. However if the custom channel PR depends on this then nvm.

contractcourt/htlc_timeout_resolver_test.go Show resolved Hide resolved
contractcourt/htlc_timeout_resolver.go Show resolved Hide resolved
// the nursery.Sign details are only non-nil for anchor channels. We
// then further restrict this path by ensuring we'll only return nil for
// non-anchor local commitmetn sweeps.
if h.htlcResolution.SignDetails == nil && h.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Trying to digest the change - I think it means we won't create reports here for spending of outputs from a local commitment with a legacy channel type, but for direct spending, aka, spending of the remote commitment, we'd always handle it here no matter it's anchor or legacy?

Copy link
Member Author

@Roasbeef Roasbeef Sep 13, 2024

Choose a reason for hiding this comment

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

Yeah I think we can make this section a bit more readable if we break out the various != checks into a new enum that explains the type of resolution we're doing.

I think would look something like:

var timeoutResolution uint8 

const (
    anchorLocalResolution = iota // h.htlcResolution.SignDetails != nil
    remoteResolution  // h.htlcResolution.SignedTimeoutTx == nil
    legacyNurseryResolution // h.htlcResolution.SignDetails == nil
)

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it means we won't create reports here for spending of outputs from a local commitment with a legacy channel type, but for direct spending, aka, spending of the remote commitment, we'd always handle it here no matter it's anchor or legacy?

With this change, the goal is that only non-anchor, local force close sweeps go through the nursery.

The CNCT now handles generating the report when the remote party has gone to chain and we want to sweep their output.

The nursery handles the report for legacy channels, where we've gone to chain ourselves.

Copy link
Collaborator

Choose a reason for hiding this comment

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

An enum would help a lot with readability and reducing confusion in the future.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The CNCT now handles generating the report when the remote party has gone to chain and we want to sweep their output.

Cool didn't notice that before. Btw there are helpers created here already so i guess things will be more clear once that pr is merged.

contractcourt/htlc_timeout_resolver.go Outdated Show resolved Hide resolved
contractcourt/htlc_timeout_resolver.go Outdated Show resolved Hide resolved
contractcourt/htlc_timeout_resolver.go Outdated Show resolved Hide resolved
contractcourt/htlc_timeout_resolver.go Show resolved Hide resolved
contractcourt/htlc_timeout_resolver_test.go Show resolved Hide resolved
@Roasbeef
Copy link
Member Author

Is there a chance we fix this after

Originally I set out to fix some existing TODOs/bugs as relates to the new aux chan feature, then realized that I'd have to update the nursery to understand some of the new interfaces. Instead of doing that, I opted to do this existing item on our wish list so things are more uniform.

With this PR, this issue (assuming all the edge cases re upgrades are accounted for) is in sight: #3688

Along the way we refactor the test to eliminate some unnecessary line
length.
…tion

In this commit, we bring the timeout resolver more in line with the
success resolver by using the sweeper to handle the HTLC offered remote
timeout outputs. These are outputs that we can sweep directly from the
remote party's commitment transaction when they broadcast their version
of the commitment transaction.

With this change, we slim down the scope slightly by only doing this for
anchor channels. Non-anchor channels will continue to use the
utxonursery for this output type for now.
// the nursery.Sign details are only non-nil for anchor channels. We
// then further restrict this path by ensuring we'll only return nil for
// non-anchor local commitmetn sweeps.
if h.htlcResolution.SignDetails == nil && h.
Copy link
Collaborator

Choose a reason for hiding this comment

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

An enum would help a lot with readability and reducing confusion in the future.

Copy link
Collaborator

@yyforyongyu yyforyongyu left a comment

Choose a reason for hiding this comment

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

LGTM🙏

// the nursery.Sign details are only non-nil for anchor channels. We
// then further restrict this path by ensuring we'll only return nil for
// non-anchor local commitmetn sweeps.
if h.htlcResolution.SignDetails == nil && h.
Copy link
Collaborator

Choose a reason for hiding this comment

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

The CNCT now handles generating the report when the remote party has gone to chain and we want to sweep their output.

Cool didn't notice that before. Btw there are helpers created here already so i guess things will be more clear once that pr is merged.

@guggero guggero merged commit 84c91f7 into lightningnetwork:master Sep 19, 2024
27 of 34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
channel closing Related to the closing of channels cooperatively and uncooperatively enhancement Improvements to existing features / behaviour HTLC no-changelog taproot chans taproot
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants