funding: send taproot addrs as upfront shutdown if ShutdownAnySegwitOptional is active
This commit is contained in:
2 files changed
+36
-29
No files matched your search
+32
-25
@@ -131,7 +131,7 @@ var (
|
|||||||
// via a local signal such as RPC.
|
// via a local signal such as RPC.
|
||||||
//
|
//
|
||||||
// TODO(roasbeef): actually use the context package
|
// TODO(roasbeef): actually use the context package
|
||||||
// * deadlines, etc.
|
// - deadlines, etc.
|
||||||
type reservationWithCtx struct {
|
type reservationWithCtx struct {
|
||||||
reservation *lnwallet.ChannelReservation
|
reservation *lnwallet.ChannelReservation
|
||||||
peer lnpeer.Peer
|
peer lnpeer.Peer
|
||||||
@@ -1486,16 +1486,7 @@ func (f *Manager) handleFundingOpen(peer lnpeer.Peer,
|
|||||||
// (if any) in lieu of user input.
|
// (if any) in lieu of user input.
|
||||||
shutdown, err := getUpfrontShutdownScript(
|
shutdown, err := getUpfrontShutdownScript(
|
||||||
f.cfg.EnableUpfrontShutdown, peer, acceptorResp.UpfrontShutdown,
|
f.cfg.EnableUpfrontShutdown, peer, acceptorResp.UpfrontShutdown,
|
||||||
func() (lnwire.DeliveryAddress, error) {
|
f.selectShutdownScript,
|
||||||
addr, err := f.cfg.Wallet.NewAddress(
|
|
||||||
lnwallet.WitnessPubKey, false,
|
|
||||||
lnwallet.DefaultAccountName,
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return txscript.PayToAddrScript(addr)
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
f.failFundingFlow(
|
f.failFundingFlow(
|
||||||
@@ -3689,7 +3680,7 @@ func (f *Manager) InitFundingWorkflow(msg *InitFundingMsg) {
|
|||||||
// upfront shutdown scripts automatically.
|
// upfront shutdown scripts automatically.
|
||||||
func getUpfrontShutdownScript(enableUpfrontShutdown bool, peer lnpeer.Peer,
|
func getUpfrontShutdownScript(enableUpfrontShutdown bool, peer lnpeer.Peer,
|
||||||
script lnwire.DeliveryAddress,
|
script lnwire.DeliveryAddress,
|
||||||
getScript func() (lnwire.DeliveryAddress, error)) (lnwire.DeliveryAddress,
|
getScript func(bool) (lnwire.DeliveryAddress, error)) (lnwire.DeliveryAddress,
|
||||||
error) {
|
error) {
|
||||||
|
|
||||||
// Check whether the remote peer supports upfront shutdown scripts.
|
// Check whether the remote peer supports upfront shutdown scripts.
|
||||||
@@ -3721,7 +3712,12 @@ func getUpfrontShutdownScript(enableUpfrontShutdown bool, peer lnpeer.Peer,
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return getScript()
|
// We can safely send a taproot address iff, both sides have negotiated
|
||||||
|
// the shutdown-any-segwit feature.
|
||||||
|
taprootOK := peer.RemoteFeatures().HasFeature(lnwire.ShutdownAnySegwitOptional) &&
|
||||||
|
peer.LocalFeatures().HasFeature(lnwire.ShutdownAnySegwitOptional)
|
||||||
|
|
||||||
|
return getScript(taprootOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
// handleInitFundingMsg creates a channel reservation within the daemon's
|
// handleInitFundingMsg creates a channel reservation within the daemon's
|
||||||
@@ -3780,18 +3776,8 @@ func (f *Manager) handleInitFundingMsg(msg *InitFundingMsg) {
|
|||||||
// address from the wallet if our node is configured to set shutdown
|
// address from the wallet if our node is configured to set shutdown
|
||||||
// address by default).
|
// address by default).
|
||||||
shutdown, err := getUpfrontShutdownScript(
|
shutdown, err := getUpfrontShutdownScript(
|
||||||
f.cfg.EnableUpfrontShutdown, msg.Peer,
|
f.cfg.EnableUpfrontShutdown, msg.Peer, msg.ShutdownScript,
|
||||||
msg.ShutdownScript,
|
f.selectShutdownScript,
|
||||||
func() (lnwire.DeliveryAddress, error) {
|
|
||||||
addr, err := f.cfg.Wallet.NewAddress(
|
|
||||||
lnwallet.WitnessPubKey, false,
|
|
||||||
lnwallet.DefaultAccountName,
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return txscript.PayToAddrScript(addr)
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
msg.Err <- err
|
msg.Err <- err
|
||||||
@@ -4270,3 +4256,24 @@ func (f *Manager) deleteChannelOpeningState(chanPoint *wire.OutPoint) error {
|
|||||||
outpointBytes.Bytes(),
|
outpointBytes.Bytes(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// selectShutdownScript selects the shutdown script we should send to the peer.
|
||||||
|
// If we can use taproot, then we prefer that, otherwise we'll use a p2wkh
|
||||||
|
// script.
|
||||||
|
func (f *Manager) selectShutdownScript(taprootOK bool,
|
||||||
|
) (lnwire.DeliveryAddress, error) {
|
||||||
|
|
||||||
|
addrType := lnwallet.WitnessPubKey
|
||||||
|
if taprootOK {
|
||||||
|
addrType = lnwallet.TaprootPubkey
|
||||||
|
}
|
||||||
|
|
||||||
|
addr, err := f.cfg.Wallet.NewAddress(
|
||||||
|
addrType, false, lnwallet.DefaultAccountName,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return txscript.PayToAddrScript(addr)
|
||||||
|
}
|
||||||
@@ -3331,13 +3331,13 @@ func TestGetUpfrontShutdownScript(t *testing.T) {
|
|||||||
upfrontScript := []byte("upfront script")
|
upfrontScript := []byte("upfront script")
|
||||||
generatedScript := []byte("generated script")
|
generatedScript := []byte("generated script")
|
||||||
|
|
||||||
getScript := func() (lnwire.DeliveryAddress, error) {
|
getScript := func(_ bool) (lnwire.DeliveryAddress, error) {
|
||||||
return generatedScript, nil
|
return generatedScript, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
getScript func() (lnwire.DeliveryAddress, error)
|
getScript func(bool) (lnwire.DeliveryAddress, error)
|
||||||
upfrontScript lnwire.DeliveryAddress
|
upfrontScript lnwire.DeliveryAddress
|
||||||
peerEnabled bool
|
peerEnabled bool
|
||||||
localEnabled bool
|
localEnabled bool
|
||||||
@@ -3628,14 +3628,14 @@ func TestFundingManagerUpfrontShutdown(t *testing.T) {
|
|||||||
pkscript: []byte("\xa9\x14\xfe\x44\x10\x65\xb6\x53" +
|
pkscript: []byte("\xa9\x14\xfe\x44\x10\x65\xb6\x53" +
|
||||||
"\x22\x31\xde\x2f\xac\x56\x31\x52\x20\x5e" +
|
"\x22\x31\xde\x2f\xac\x56\x31\x52\x20\x5e" +
|
||||||
"\xc4\xf5\x9c\x74\x87"),
|
"\xc4\xf5\x9c\x74\x87"),
|
||||||
expectErr: false,
|
expectErr: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "p2pkh script",
|
name: "p2pkh script",
|
||||||
pkscript: []byte("\x76\xa9\x14\x64\x1a\xd5\x05\x1e" +
|
pkscript: []byte("\x76\xa9\x14\x64\x1a\xd5\x05\x1e" +
|
||||||
"\xdd\x97\x02\x9a\x00\x3f\xe9\xef\xb2\x93" +
|
"\xdd\x97\x02\x9a\x00\x3f\xe9\xef\xb2\x93" +
|
||||||
"\x59\xfc\xee\x40\x9d\x88\xac"),
|
"\x59\xfc\xee\x40\x9d\x88\xac"),
|
||||||
expectErr: false,
|
expectErr: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "p2wpkh script",
|
name: "p2wpkh script",
|
||||||
|
|||||||
Reference in new issue
Block a user