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

Beat [3/4]: prepare resolvers to handle the blockbeat #8922

Merged

Conversation

yyforyongyu
Copy link
Member

@yyforyongyu yyforyongyu commented Jul 18, 2024

Depends on #8894

NOTE: itest is fixed in the final PR #9227.

WIP: don't review it yet (created to check CI).

Turns out mounting blockbeat in ChannelArbitrator can be quite challenging (unit tests, itest, etc). This PR attempts to implement it in hopefully the least disruptive way - only chainWatcher implements Consumer, and the contract resolvers are kept stateless (in terms of blocks). The main changes are,

  1. contract resolvers are refactored - the original Resolve method is broken into two steps: 1) Launch the resolver, which handles sending the sweep request, and 2) Resolve the resolver, which handles monitoring the spending of the output.
  2. chainWatcher now implements Consumer.
  3. itests are now fixed.

Alternatives

The original attempt is to make the resolvers subscribe to a blockbeat chan, as implemented in #8717. The second attempt is to make the resolvers also blockbeat Consumer, as implemented here.

This third approach is chosen as 1) it greatly limits the scope otherwise a bigger refactor of channel arbitrator may be needed, and 2) the resolvers can be made stateless in terms of blocks, and be fully managed by the channel arbitrator. In other words, when a new block arrives, the channel arbitrator decides whether to launch the resolvers or not, so the resolvers themselves don't need this block info.

In fact, there are only two resolvers that subscribe to blocks, the incoming contest resolver, which uses block height to decide whether to give up resolving an expired incoming htlc; and the outgoing contest resolver, which uses the block height to choose to transform itself into a timeout resolver. IMO if we can remove the inheritance pattern used in contest resolver -> time/success resolver and manage to transform resolvers in channel arbitrator, we can further remove those two block subscriptions. As for now, we can leave them there as they have little impact on the block consumption order enforced by the blockbeat.

Copy link
Contributor

coderabbitai bot commented Jul 18, 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.

@saubyk saubyk modified the milestones: v0.18.3, v0.19.0 Jul 18, 2024
@yyforyongyu yyforyongyu force-pushed the yy-blockbeat-finalize branch from be50d50 to 5d8ea80 Compare October 15, 2024 09:14
@yyforyongyu yyforyongyu force-pushed the yy-blockbeat branch 2 times, most recently from 7b05026 to d76a26e Compare October 15, 2024 09:18
@yyforyongyu yyforyongyu force-pushed the yy-blockbeat-finalize branch from 5d8ea80 to e568154 Compare October 15, 2024 09:19
@yyforyongyu yyforyongyu force-pushed the yy-blockbeat-finalize branch from e568154 to 0ab9846 Compare October 28, 2024 10:31
@yyforyongyu yyforyongyu force-pushed the yy-blockbeat branch 2 times, most recently from 7b1b444 to d900f98 Compare October 29, 2024 14:17
@yyforyongyu yyforyongyu force-pushed the yy-blockbeat-finalize branch from 0ab9846 to a5d0e99 Compare October 29, 2024 14:17
@yyforyongyu yyforyongyu force-pushed the yy-blockbeat branch 7 times, most recently from 45b97aa to 4359f45 Compare November 1, 2024 01:51
@yyforyongyu yyforyongyu force-pushed the yy-blockbeat-finalize branch from a5d0e99 to 550ffbe Compare November 1, 2024 12:51
@ziggie1984 ziggie1984 self-requested a review November 5, 2024 12:15
@yyforyongyu yyforyongyu force-pushed the yy-blockbeat branch 6 times, most recently from 032866b to 103f551 Compare November 12, 2024 18:04
@yyforyongyu yyforyongyu force-pushed the yy-blockbeat-finalize branch 2 times, most recently from b340b4c to d620291 Compare November 17, 2024 02:58
@yyforyongyu yyforyongyu changed the title Beat [3/4]: Implement Consumer on chainWatcher and resolvers Beat [3/4]: prepare resolvers to handle the blockbeat Nov 17, 2024
@yyforyongyu yyforyongyu force-pushed the yy-blockbeat-finalize branch from d620291 to 6819393 Compare November 18, 2024 01:49
@yyforyongyu yyforyongyu force-pushed the yy-blockbeat-finalize branch from 6819393 to 2bdbe76 Compare November 18, 2024 03:23
@yyforyongyu yyforyongyu force-pushed the yy-blockbeat branch 2 times, most recently from 3674ed3 to 737b0a0 Compare November 18, 2024 04:10
We now put the outpoint in the resolvers's logging so it's easier to
debug. Also use the short channel ID whenever possible to shorten the
log line length.
This commit adds a few helper methods to decide how the htlc output
should be spent.
This commit is a pure refactor in which moves the sweep handling logic
into the new methods.
This commit refactors the `Resolve` method by adding two resolver
handlers to handle waiting for spending confirmations.
This commit adds new methods to handle making sweep requests based on
the spending path used by the outgoing htlc output.
This commit adds checkpoint methods in `htlcTimeoutResolver`, which are
similar to those used in `htlcSuccessResolver`.
This commit adds more methods to handle resolving the spending of the
output based on different spending paths.
We will use this and its following commits to break the original
`Resolve` methods into two parts - the first part is moved to a new
method `Launch`, which handles sending a sweep request to the sweeper.
The second part remains in `Resolve`, which is mainly waiting for a
spending tx.

Breach resolver currently doesn't do anything in its `Launch` since the
sweeping of justice outputs are not handled by the sweeper yet.
This commit breaks the `Resolve` into two parts - the first part is
moved into a `Launch` method that handles sending sweep requests, and
the second part remains in `Resolve` which handles waiting for the
spend. Since we are using both utxo nursery and sweeper at the same
time, to make sure this change doesn't break the existing behavior, we
implement the `Launch` as following,
- zero-fee htlc - handled by the sweeper
- direct output from the remote commit - handled by the sweeper
- legacy htlc - handled by the utxo nursery
This commit breaks the `Resolve` into two parts - the first part is
moved into a `Launch` method that handles sending sweep requests, and
the second part remains in `Resolve` which handles waiting for the
spend. Since we are using both utxo nursery and sweeper at the same
time, to make sure this change doesn't break the existing behavior, we
implement the `Launch` as following,
- zero-fee htlc - handled by the sweeper
- direct output from the remote commit - handled by the sweeper
- legacy htlc - handled by the utxo nursery
A minor refactor is done to support implementing `Launch`.
This commit makes `resolved` an atomic bool to avoid data race. This
field is now defined in `contractResolverKit` to avoid code duplication.
In this commit, we break the old `launchResolvers` into two steps - step
one is to launch the resolvers synchronously, and step two is to
actually waiting for the resolvers to be resolved. This is critical as
in the following commit we will require the resolvers to be launched at
the same blockbeat when a force close event is sent by the chain watcher.
@yyforyongyu yyforyongyu force-pushed the yy-blockbeat-finalize branch from 2bdbe76 to f9deab4 Compare November 18, 2024 04:19
@yyforyongyu yyforyongyu merged commit f9deab4 into lightningnetwork:yy-blockbeat Nov 18, 2024
8 of 27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants