-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
multi: fix lnwallet.ErrDoubleSpend
#8887
Conversation
Important Review skippedAuto reviews are limited to specific labels. Labels to auto review (1)
Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the 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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configration File (
|
@@ -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), |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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,
- try to fee bump a tx when it doesn't signal RBF
- 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
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😈
Did some |
860e68b
to
9bb63f5
Compare
|
bf50c4f
to
99a9eff
Compare
There was a problem hiding this 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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
c288c3d
to
5085760
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🎉
There was a problem hiding this 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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 ?
These errors are now defined in `btcwallet/chain` instead of `btcd/rpcclient`.
5085760
to
e27a656
Compare
This PR fixes the matching errors used in
lnwallet.ErrDoubleSpend
, a misuse of error found in the rebroadcaster'sbroadcastErrorMapper
, and updates thebtcd
version to fix another error str mismatch among different versions.Depends on,
chain
btcsuite/btcwallet#937