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

lnwallet: fix closechannel for P2TR external addr #9223

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions itest/lnd_coop_close_external_delivery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,32 @@ import (
)

func testCoopCloseWithExternalDelivery(ht *lntest.HarnessTest) {
ht.Run("set delivery address at open", func(t *testing.T) {
ht.Run("set P2WPKH delivery address at open", func(t *testing.T) {
tt := ht.Subtest(t)
testCoopCloseWithExternalDeliveryImpl(tt, true)
testCoopCloseWithExternalDeliveryImpl(
tt, true, lnrpc.AddressType_UNUSED_WITNESS_PUBKEY_HASH,
)
})
ht.Run("set delivery address at close", func(t *testing.T) {

ht.Run("set P2WPKH delivery address at close", func(t *testing.T) {
tt := ht.Subtest(t)
testCoopCloseWithExternalDeliveryImpl(
tt, false, lnrpc.AddressType_UNUSED_WITNESS_PUBKEY_HASH,
)
})

ht.Run("set P2TR delivery address at open", func(t *testing.T) {
tt := ht.Subtest(t)
testCoopCloseWithExternalDeliveryImpl(
tt, true, lnrpc.AddressType_UNUSED_TAPROOT_PUBKEY,
)
})

ht.Run("set P2TR delivery address at close", func(t *testing.T) {
tt := ht.Subtest(t)
testCoopCloseWithExternalDeliveryImpl(tt, false)
testCoopCloseWithExternalDeliveryImpl(
tt, false, lnrpc.AddressType_UNUSED_TAPROOT_PUBKEY,
)
})
}

Expand All @@ -25,7 +44,7 @@ func testCoopCloseWithExternalDelivery(ht *lntest.HarnessTest) {
// not. Some users set this value to be an address in a different wallet and
// this should not affect our ability to accurately report the settled balance.
func testCoopCloseWithExternalDeliveryImpl(ht *lntest.HarnessTest,
upfrontShutdown bool) {
upfrontShutdown bool, deliveryAddressType lnrpc.AddressType) {

alice, bob := ht.Alice, ht.Bob
ht.ConnectNodes(alice, bob)
Expand All @@ -35,7 +54,7 @@ func testCoopCloseWithExternalDeliveryImpl(ht *lntest.HarnessTest,
// wallet. We already correctly track settled balances when the address
// is in the LND wallet.
addr := bob.RPC.NewAddress(&lnrpc.NewAddressRequest{
Type: lnrpc.AddressType_UNUSED_WITNESS_PUBKEY_HASH,
Type: deliveryAddressType,
})

// Prepare for channel open.
Expand Down
10 changes: 10 additions & 0 deletions lnwallet/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,16 @@ func InternalKeyForAddr(wallet WalletController, netParams *chaincfg.Params,

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
// option value.
var managerErr waddrmgr.ManagerError
if errors.As(err, &managerErr) {
if managerErr.ErrorCode == waddrmgr.ErrAddressNotFound {
return none, nil
}
}

return none, err
}

Expand Down
Loading