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

multi: fix lnwallet.ErrDoubleSpend #8887

Merged
merged 6 commits into from
Jul 8, 2024

Conversation

yyforyongyu
Copy link
Collaborator

@yyforyongyu yyforyongyu commented Jul 2, 2024

This PR fixes the matching errors used in lnwallet.ErrDoubleSpend, a misuse of error found in the rebroadcaster's broadcastErrorMapper, and updates the btcd version to fix another error str mismatch among different versions.

Depends on,

@yyforyongyu yyforyongyu added this to the v0.18.2 milestone Jul 2, 2024
@yyforyongyu yyforyongyu self-assigned this Jul 2, 2024
Copy link
Contributor

coderabbitai bot commented Jul 2, 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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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.

@@ -1202,7 +1202,8 @@ func mapRpcclientError(err error) error {
switch {
// If the wallet reports a double spend, convert it to our internal
// ErrDoubleSpend and return.
case errors.Is(err, rpcclient.ErrMempoolConflict),
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 ErrMempoolConflict handling removed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think we only get this error when,

  1. try to fee bump a tx when it doesn't signal RBF
  2. try to spend the same output in a different tx

Either way it shouldn't ever happen in ln. However I decided to not change it now to focus on fixing the error matching issue.

go.mod Outdated
Comment on lines 212 to 214
replace github.com/btcsuite/btcd => github.com/yyforyongyu/btcd v0.21.0-beta.0.20240702184211-31cf2383abd1

replace github.com/btcsuite/btcwallet => github.com/yyforyongyu/btcwallet v0.16.11-0.20240702184603-cf50b410fcb1
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we want to replace btcsuite with your fork.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

😈

@Roasbeef
Copy link
Member

Roasbeef commented Jul 3, 2024

Did some git archeology to put together the series of changes that led to these issues, I think I understand what went wrong here, and how we can improve the state of things to avoid issues like this in the future: btcsuite/btcd#2209 (review).

@yyforyongyu yyforyongyu force-pushed the fix-err-match branch 3 times, most recently from 860e68b to 9bb63f5 Compare July 3, 2024 15:44
@yyforyongyu
Copy link
Collaborator Author

yyforyongyu commented Jul 3, 2024

Will do a local test like this one once the approach is ACKed, and update the release notes.

@yyforyongyu yyforyongyu force-pushed the fix-err-match branch 2 times, most recently from bf50c4f to 99a9eff Compare July 4, 2024 05:44
@saubyk saubyk requested a review from bhandras July 4, 2024 15:23
@saubyk saubyk requested a review from ziggie1984 July 4, 2024 15:36
Copy link
Collaborator

@bhandras bhandras left a comment

Choose a reason for hiding this comment

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

Looks good, pending btcd PR. I just have a question regarding double spend mapping.

@@ -1475,27 +1478,27 @@ func parseHeaderStateAssertion(state string) (*headerfs.FilterHeader, error) {
// the neutrino BroadcastError which allows the Rebroadcaster which currently
// resides in the neutrino package to use all of its functionalities.
func broadcastErrorMapper(err error) error {
returnErr := rpcclient.MapRPCErr(err)
var returnErr error
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not map the error here like before?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

To use the method MapRPCErr we need to access the chain backend, which cannot be used here. Instead, we pass the already mapped error to broadcastErrorMapper, and access the method via cs.MapRPCErr above.

errors.Is(err, chain.ErrMissingInputs):
errors.Is(err, chain.ErrMissingInputs),
errors.Is(err, chain.ErrTxAlreadyKnown),
errors.Is(err, chain.ErrTxAlreadyConfirmed):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure if I'd consider ErrTxAlreadyConfirmed as double spend. Is there a reason to do so?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So during startup, we may rebroadcast our force close tx that can cause this error, which matches the issue voltage has. I think previously we also considered this as ErrDoubleSpend here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe add a comment here why we classify a already confirmed tx as doublespend ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

tbh I don't think it should be considered as a double spend - we are doing it to keep the existing behavior. IMO it's better to check whether the to-be-published tx already exists in the blockchain or in the mempool before broadcasting it during startup. Or even better, understand why it's broadcast again as I believe there are some internal state updates once a tx is published, but it looks like that state was not persisted.

Copy link
Collaborator

@bhandras bhandras left a comment

Choose a reason for hiding this comment

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

LGTM 🎉

Copy link
Collaborator

@ziggie1984 ziggie1984 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for your work 🙏

NOTE: No need to backport this because its only in LND 18

@@ -1202,15 +1202,15 @@ func mapRpcclientError(err error) error {
switch {
// If the wallet reports a double spend, convert it to our internal
Copy link
Collaborator

Choose a reason for hiding this comment

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

Comment of this function still references the rpcclient pkg.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

cool updated.

errors.Is(err, chain.ErrMissingInputs):
errors.Is(err, chain.ErrMissingInputs),
errors.Is(err, chain.ErrTxAlreadyKnown),
errors.Is(err, chain.ErrTxAlreadyConfirmed):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe add a comment here why we classify a already confirmed tx as doublespend ?

@yyforyongyu yyforyongyu merged commit 3526f82 into lightningnetwork:master Jul 8, 2024
28 of 33 checks passed
@yyforyongyu yyforyongyu deleted the fix-err-match branch July 8, 2024 06:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants