mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-11-19 10:37:23 +01:00
Merge pull request #9223 from starius/close-to-external-p2tr
lnwallet: fix closechannel for P2TR external addr
This commit is contained in:
@@ -10,13 +10,44 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func testCoopCloseWithExternalDelivery(ht *lntest.HarnessTest) {
|
func testCoopCloseWithExternalDelivery(ht *lntest.HarnessTest) {
|
||||||
ht.Run("set delivery address at open", func(t *testing.T) {
|
ok := ht.Run("set P2WPKH delivery address at open", func(t *testing.T) {
|
||||||
tt := ht.Subtest(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) {
|
// Abort the test if failed.
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ok = ht.Run("set P2WPKH delivery address at close", func(t *testing.T) {
|
||||||
tt := ht.Subtest(t)
|
tt := ht.Subtest(t)
|
||||||
testCoopCloseWithExternalDeliveryImpl(tt, false)
|
testCoopCloseWithExternalDeliveryImpl(
|
||||||
|
tt, false, lnrpc.AddressType_UNUSED_WITNESS_PUBKEY_HASH,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
// Abort the test if failed.
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ok = ht.Run("set P2TR delivery address at open", func(t *testing.T) {
|
||||||
|
tt := ht.Subtest(t)
|
||||||
|
testCoopCloseWithExternalDeliveryImpl(
|
||||||
|
tt, true, lnrpc.AddressType_UNUSED_TAPROOT_PUBKEY,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
// Abort the test if failed.
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ht.Run("set P2TR delivery address at close", func(t *testing.T) {
|
||||||
|
tt := ht.Subtest(t)
|
||||||
|
testCoopCloseWithExternalDeliveryImpl(
|
||||||
|
tt, false, lnrpc.AddressType_UNUSED_TAPROOT_PUBKEY,
|
||||||
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,7 +56,7 @@ func testCoopCloseWithExternalDelivery(ht *lntest.HarnessTest) {
|
|||||||
// not. Some users set this value to be an address in a different wallet and
|
// 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.
|
// this should not affect our ability to accurately report the settled balance.
|
||||||
func testCoopCloseWithExternalDeliveryImpl(ht *lntest.HarnessTest,
|
func testCoopCloseWithExternalDeliveryImpl(ht *lntest.HarnessTest,
|
||||||
upfrontShutdown bool) {
|
upfrontShutdown bool, deliveryAddressType lnrpc.AddressType) {
|
||||||
|
|
||||||
alice, bob := ht.Alice, ht.Bob
|
alice, bob := ht.Alice, ht.Bob
|
||||||
ht.ConnectNodes(alice, bob)
|
ht.ConnectNodes(alice, bob)
|
||||||
@@ -35,7 +66,7 @@ func testCoopCloseWithExternalDeliveryImpl(ht *lntest.HarnessTest,
|
|||||||
// wallet. We already correctly track settled balances when the address
|
// wallet. We already correctly track settled balances when the address
|
||||||
// is in the LND wallet.
|
// is in the LND wallet.
|
||||||
addr := bob.RPC.NewAddress(&lnrpc.NewAddressRequest{
|
addr := bob.RPC.NewAddress(&lnrpc.NewAddressRequest{
|
||||||
Type: lnrpc.AddressType_UNUSED_WITNESS_PUBKEY_HASH,
|
Type: deliveryAddressType,
|
||||||
})
|
})
|
||||||
|
|
||||||
// Prepare for channel open.
|
// Prepare for channel open.
|
||||||
|
|||||||
@@ -636,6 +636,19 @@ func InternalKeyForAddr(wallet WalletController, netParams *chaincfg.Params,
|
|||||||
|
|
||||||
walletAddr, err := wallet.AddressInfo(addr)
|
walletAddr, err := wallet.AddressInfo(addr)
|
||||||
if err != nil {
|
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.
|
||||||
|
var managerErr waddrmgr.ManagerError
|
||||||
|
if errors.As(err, &managerErr) &&
|
||||||
|
managerErr.ErrorCode == waddrmgr.ErrAddressNotFound {
|
||||||
|
|
||||||
|
return none, nil
|
||||||
|
}
|
||||||
|
|
||||||
return none, err
|
return none, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user