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 [4/4]: implement Consumer in chainWatcher #9277

Open
wants to merge 12 commits into
base: yy-blockbeat-finalize
Choose a base branch
from

Conversation

yyforyongyu
Copy link
Member

@yyforyongyu yyforyongyu commented Nov 18, 2024

This PR implements the Consumer interface in chainWatcher with necessary refactors.

TODOs

  • add a release note

Depends on

NOTE: itest is fixed in the final PR

Copy link
Contributor

coderabbitai bot commented Nov 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 generate docstrings to generate docstrings for this PR. (Experiment)
  • @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.

@yyforyongyu yyforyongyu force-pushed the yy-blockbeat-finalize branch from ac8ce82 to a16b2d4 Compare November 18, 2024 11:34
@yyforyongyu yyforyongyu force-pushed the yy-blockbeat-end branch 2 times, most recently from 0ddd693 to 07631c0 Compare November 18, 2024 11:50
@saubyk saubyk added this to the v0.19.0 milestone Nov 18, 2024
@yyforyongyu yyforyongyu force-pushed the yy-blockbeat-finalize branch 3 times, most recently from c5f77e3 to 3456f2e Compare November 20, 2024 06:06
@yyforyongyu yyforyongyu force-pushed the yy-blockbeat-finalize branch from 3456f2e to 3d08b74 Compare November 20, 2024 06:21
@yyforyongyu yyforyongyu force-pushed the yy-blockbeat-finalize branch from 3d08b74 to e69cd41 Compare November 21, 2024 13:16
@yyforyongyu yyforyongyu force-pushed the yy-blockbeat-finalize branch from e69cd41 to cdd805f Compare November 21, 2024 14:45
// we proceed with the rest of the close observer logic for taproot channels.
func (c *chainWatcher) chanPointConfirmed() bool {
op := c.cfg.chanState.FundingOutpoint
confNtfn, err := c.cfg.notifier.RegisterConfirmationsNtfn(
Copy link
Member

Choose a reason for hiding this comment

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

I think we need to be careful about some of these assumptions of insta conf sends here. This won't always be the case for the neutrino backend.

Copy link
Member Author

Choose a reason for hiding this comment

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

cool we now moved the subscription earlier so it's more likely we can get this "on beat".

Copy link
Collaborator

Choose a reason for hiding this comment

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

so is it not possible to open a zeroconf channel and then close it even though it is not confirmed ?

Copy link
Member Author

Choose a reason for hiding this comment

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

good q - i think theoratically we could do a package of [zero-conf funding tx -> coop close], but usually we want it to be confirmed to be safe.

// closure type.
func (c *chainWatcher) handleBlockbeat(beat chainio.Blockbeat) {
// Notify the chain arbitrator has processed the block.
defer c.NotifyBlockProcessed(beat, nil)
Copy link
Member

Choose a reason for hiding this comment

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

Do you mean "chain watcher" here in the comment.

Copy link
Member Author

@yyforyongyu yyforyongyu Nov 22, 2024

Choose a reason for hiding this comment

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

yikes now fixed!

default:
log.Infof("Taproot ChannelPoint(%v) not confirmed yet", op)

return false
Copy link
Member

Choose a reason for hiding this comment

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

I think we should cancel the conf request here, otherwise we'll have a new one stack up each block the transaction isn't confirmed.

Copy link
Member Author

@yyforyongyu yyforyongyu Nov 22, 2024

Choose a reason for hiding this comment

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

nice catch - we now register it early during the initialization, similar to how fundingSpendNtfn works, we register it once and cancel it when the funding tx is confirmed. The fix is in the final commit.

@@ -891,7 +891,7 @@ func (c *ChainArbitrator) Stop() error {
}
for chanPoint, arbitrator := range activeChannels {
log.Tracef("Attempting to stop ChannelArbitrator(%v)",
chanPoint)
arbitrator.id())
Copy link
Member

Choose a reason for hiding this comment

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

IMO, the scid is much less useful than the chan point. For the chan point we can easily use it to look up the transaction/channel. This is frequently done in incoming user bug reports. If you only have the scid, you need to translate it to get the outpoint, which is what's commonly used.

Copy link
Member Author

Choose a reason for hiding this comment

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

Got it, changed to chan point instead.

return
}

// The remote has breached the channel! We now launch the
Copy link
Member

Choose a reason for hiding this comment

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

Comment can be reflowed to the left.

Copy link
Member Author

Choose a reason for hiding this comment

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

my bad, fixed.

@yyforyongyu yyforyongyu force-pushed the yy-blockbeat-finalize branch 2 times, most recently from 1e58126 to abbee3b Compare November 22, 2024 11:58
@yyforyongyu yyforyongyu force-pushed the yy-blockbeat-finalize branch from abbee3b to aeafa63 Compare November 25, 2024 05:49
@yyforyongyu yyforyongyu force-pushed the yy-blockbeat-end branch 2 times, most recently from 0032fd7 to 5c9c6d0 Compare November 25, 2024 06:21
@ellemouton ellemouton removed their request for review November 27, 2024 08:54
@yyforyongyu yyforyongyu force-pushed the yy-blockbeat-finalize branch from 29521a1 to 7b19d5c Compare November 27, 2024 12:24
@yyforyongyu yyforyongyu force-pushed the yy-blockbeat-finalize branch from 23ee2e3 to 897e642 Compare December 3, 2024 20:12
@yyforyongyu yyforyongyu force-pushed the yy-blockbeat-end branch 3 times, most recently from a9f29f6 to 9793973 Compare December 3, 2024 21:55
@yyforyongyu yyforyongyu force-pushed the yy-blockbeat-finalize branch from 897e642 to d854e87 Compare December 4, 2024 22:41
@yyforyongyu yyforyongyu force-pushed the yy-blockbeat-finalize branch from d854e87 to 0397aaf Compare December 5, 2024 05:12
@yyforyongyu yyforyongyu force-pushed the yy-blockbeat-finalize branch from 0397aaf to 1a6653f Compare December 5, 2024 13:34
@yyforyongyu yyforyongyu force-pushed the yy-blockbeat-finalize branch from 1a6653f to 33064a3 Compare December 6, 2024 08:14
@yyforyongyu yyforyongyu force-pushed the yy-blockbeat-finalize branch 2 times, most recently from ef85fb5 to cebad6d Compare December 10, 2024 07:14
This commit moves the creation of the spending notification from `Start`
to `newChainWatcher` so we subscribe the spending event before handling
the block, which is needed to properly handle the blockbeat.
To prepare for the blockbeat handler.
We now start notifying the blockbeat from the ChainArbitrator to the
chainWatcher.
This commit adds the closing height to the logging and fixes a wrong
height used in handling the breach event.
This commit adds a new method to enable us resending the blockbeat in
`ChainArbitrator`, which is needed for the channel restore as the chain
watcher and channel arbitrator are added after the start of the chain
arbitrator.
To prepare the next commit where we would handle the event upon
receiving a blockbeat.
We need to check `dispatched` before sending conf details, otherwise the
channel `ntfn.Event.Confirmed` will be blocking, which is the leftover
from lightningnetwork#9275.
@lightninglabs-deploy
Copy link

@Roasbeef: review reminder
@ziggie1984: review reminder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

5 participants