lnwallet: fix closechannel for P2TR external addr#9223
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 using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
ab0b961 to
e86e4af
Compare
guggero
left a comment
There was a problem hiding this comment.
Thanks for the fix! LGTM 🎉
| walletAddr, err := wallet.AddressInfo(addr) | ||
| if err != nil { | ||
| // If the error is that the address can't be found, it is not | ||
| // an error, as callers can use the .Option() method to get an |
There was a problem hiding this comment.
Not sure I follow here, could you elaborate a bit? If there's no internal key associated shouldn't we return an error?
There was a problem hiding this comment.
I changed the comment:
walletAddr, err := wallet.AddressInfo(addr)
if err != nil {
// If the error is that the address can't be found, it is not
// an error. This happens when any channel which is not a custom
// taproot channel is cooperatively closed to an external P2TR
// address. In this case there is no internal key associated
// with the address. Callers can use the .Option() method to get
// an option value.| }) | ||
| ht.Run("set delivery address at close", func(t *testing.T) { | ||
|
|
||
| ht.Run("set P2WPKH delivery address at close", func(t *testing.T) { |
There was a problem hiding this comment.
Nice tests - can we add success := ht.Run and stop the test if !success? this is helpful for future development as it's easier to debug that way.
There was a problem hiding this comment.
Thanks! Done:
ok := ht.Run("set P2WPKH delivery address at open", func(t *testing.T) {
tt := ht.Subtest(t)
testCoopCloseWithExternalDeliveryImpl(
tt, true, lnrpc.AddressType_UNUSED_WITNESS_PUBKEY_HASH,
)
})
// Abort the test if failed.
if !ok {
return
}
...If the delivery address is P2TR, function InternalKeyForAddr checks its existance in the wallet to return internal key for it in case it is a custom taproot channel. It used to return the error returned by wallet.AddressInfo. The error is now ignored if it is ErrAddressNotFound error. This fixes "lncli closechannel --delivery_addr <external p2tr address" case.
Customize the itest with the type of external delivery address. Test with P2TR address type in addition to P2WKPH.
e86e4af to
4b87072
Compare
yyforyongyu
left a comment
There was a problem hiding this comment.
A few more questions then this should be good to go!
| }) | ||
| ht.Run("set delivery address at close", func(t *testing.T) { | ||
| // Abort the test if failed. | ||
| if !ok { |
|
|
||
| walletAddr, err := wallet.AddressInfo(addr) | ||
| if err != nil { | ||
| // If the error is that the address can't be found, it is not |
| // an error. This happens when any channel which is not a custom | ||
| // taproot channel is cooperatively closed to an external P2TR | ||
| // address. In this case there is no internal key associated | ||
| // with the address. Callers can use the .Option() method to get |
There was a problem hiding this comment.
Q: how can the callers get the value, don't we return a none option here?
There was a problem hiding this comment.
I copy-pasted this part of the comment from the check below:
// No wallet addr. No error, but we'll return an nil error value here,
// as callers can use the .Option() method to get an option value.
if walletAddr == nil {
return none, nil
}I propose to modify it in both cases to the following: "callers can inspect the returned option to determine if it has a value".
cc @guggero
| // an option value. | ||
| var managerErr waddrmgr.ManagerError | ||
| if errors.As(err, &managerErr) && | ||
| managerErr.ErrorCode == waddrmgr.ErrAddressNotFound { |
There was a problem hiding this comment.
I don't have the full pic here, but just wanna point out that there probably should have a dedicated method to do this job since this method is named InternalKeyForAddr and the caller would expect an error when there's no internal key. In addition, we are fixing the case "non-custom tap channel closed to an external addr", then what about "custom tap chan closed but no internal key found" case? Previously we'd have an error but now it's ignored. Is that handled elsewhere? cc @guggero
There was a problem hiding this comment.
We only need the internal key in case of a custom (tap) channel. So for a normal taproot channel, we don't want this to error out and return a None. If we also return a None for custom (tap) channels, then that is fine here, as it will lead to an error elsewhere.
So the fix is good, we basically shouldn't error out for anything that can happen during normal operation (and specifying an external shutdown address definitely is normal operation).
Basically the
if walletAddr == nil {
return none, nil
}
further below is what we thought would happen if a key wasn't found. But apparently an error is returned, so we need this special case.
There was a problem hiding this comment.
cool thanks for the explanation!
Change Description
Customize the itest with the type of external delivery address. Test with P2TR address type in addition to P2WKPH.
Steps to Test
Pull Request Checklist
Testing
Code Style and Documentation
[skip ci]in the commit message for small changes.📝 Please see our Contribution Guidelines for further guidance.