mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-28 19:06:24 +02:00
peer: send taproot addrs during co-op close based on new feature bit
If the ShutdownAnySegwitOptional option is active, then we can safely send these newer addresses.
This commit is contained in:
@@ -657,6 +657,13 @@ func (p *Brontide) initGossipSync() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// taprootShutdownAllowed returns true if both parties have negotiated the
|
||||||
|
// shutdown-any-segwit feature.
|
||||||
|
func (p *Brontide) taprootShutdownAllowed() bool {
|
||||||
|
return p.RemoteFeatures().HasFeature(lnwire.ShutdownAnySegwitOptional) &&
|
||||||
|
p.LocalFeatures().HasFeature(lnwire.ShutdownAnySegwitOptional)
|
||||||
|
}
|
||||||
|
|
||||||
// QuitSignal is a method that should return a channel which will be sent upon
|
// QuitSignal is a method that should return a channel which will be sent upon
|
||||||
// or closed once the backing peer exits. This allows callers using the
|
// or closed once the backing peer exits. This allows callers using the
|
||||||
// interface to cancel any processing in the event the backing implementation
|
// interface to cancel any processing in the event the backing implementation
|
||||||
@@ -2244,8 +2251,15 @@ func (p *Brontide) ChannelSnapshots() []*channeldb.ChannelSnapshot {
|
|||||||
// genDeliveryScript returns a new script to be used to send our funds to in
|
// genDeliveryScript returns a new script to be used to send our funds to in
|
||||||
// the case of a cooperative channel close negotiation.
|
// the case of a cooperative channel close negotiation.
|
||||||
func (p *Brontide) genDeliveryScript() ([]byte, error) {
|
func (p *Brontide) genDeliveryScript() ([]byte, error) {
|
||||||
|
// We'll send a normal p2wkh address unless we've negotiated the
|
||||||
|
// shutdown-any-segwit feature.
|
||||||
|
addrType := lnwallet.WitnessPubKey
|
||||||
|
if p.taprootShutdownAllowed() {
|
||||||
|
addrType = lnwallet.TaprootPubkey
|
||||||
|
}
|
||||||
|
|
||||||
deliveryAddr, err := p.cfg.Wallet.NewAddress(
|
deliveryAddr, err := p.cfg.Wallet.NewAddress(
|
||||||
lnwallet.WitnessPubKey, false, lnwallet.DefaultAccountName,
|
addrType, false, lnwallet.DefaultAccountName,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@@ -55,6 +55,8 @@ func TestPeerChannelClosureAcceptFeeResponder(t *testing.T) {
|
|||||||
mockLink := newMockUpdateHandler(chanID)
|
mockLink := newMockUpdateHandler(chanID)
|
||||||
mockSwitch.links = append(mockSwitch.links, mockLink)
|
mockSwitch.links = append(mockSwitch.links, mockLink)
|
||||||
|
|
||||||
|
dummyDeliveryScript := genScript(t, p2wshAddress)
|
||||||
|
|
||||||
// We send a shutdown request to Alice. She will now be the responding
|
// We send a shutdown request to Alice. She will now be the responding
|
||||||
// node in this shutdown procedure. We first expect Alice to answer
|
// node in this shutdown procedure. We first expect Alice to answer
|
||||||
// this shutdown request with a Shutdown message.
|
// this shutdown request with a Shutdown message.
|
||||||
@@ -156,6 +158,8 @@ func TestPeerChannelClosureAcceptFeeInitiator(t *testing.T) {
|
|||||||
mockLink := newMockUpdateHandler(chanID)
|
mockLink := newMockUpdateHandler(chanID)
|
||||||
mockSwitch.links = append(mockSwitch.links, mockLink)
|
mockSwitch.links = append(mockSwitch.links, mockLink)
|
||||||
|
|
||||||
|
dummyDeliveryScript := genScript(t, p2wshAddress)
|
||||||
|
|
||||||
// We make Alice send a shutdown request.
|
// We make Alice send a shutdown request.
|
||||||
updateChan := make(chan interface{}, 1)
|
updateChan := make(chan interface{}, 1)
|
||||||
errChan := make(chan error, 1)
|
errChan := make(chan error, 1)
|
||||||
@@ -281,6 +285,7 @@ func TestPeerChannelClosureFeeNegotiationsResponder(t *testing.T) {
|
|||||||
// Bob sends a shutdown request to Alice. She will now be the responding
|
// Bob sends a shutdown request to Alice. She will now be the responding
|
||||||
// node in this shutdown procedure. We first expect Alice to answer this
|
// node in this shutdown procedure. We first expect Alice to answer this
|
||||||
// Shutdown request with a Shutdown message.
|
// Shutdown request with a Shutdown message.
|
||||||
|
dummyDeliveryScript := genScript(t, p2wshAddress)
|
||||||
alicePeer.chanCloseMsgs <- &closeMsg{
|
alicePeer.chanCloseMsgs <- &closeMsg{
|
||||||
cid: chanID,
|
cid: chanID,
|
||||||
msg: lnwire.NewShutdown(chanID,
|
msg: lnwire.NewShutdown(chanID,
|
||||||
@@ -492,6 +497,7 @@ func TestPeerChannelClosureFeeNegotiationsInitiator(t *testing.T) {
|
|||||||
aliceDeliveryScript := shutdownMsg.Address
|
aliceDeliveryScript := shutdownMsg.Address
|
||||||
|
|
||||||
// Bob will answer the Shutdown message with his own Shutdown.
|
// Bob will answer the Shutdown message with his own Shutdown.
|
||||||
|
dummyDeliveryScript := genScript(t, p2wshAddress)
|
||||||
respShutdown := lnwire.NewShutdown(chanID, dummyDeliveryScript)
|
respShutdown := lnwire.NewShutdown(chanID, dummyDeliveryScript)
|
||||||
alicePeer.chanCloseMsgs <- &closeMsg{
|
alicePeer.chanCloseMsgs <- &closeMsg{
|
||||||
cid: chanID,
|
cid: chanID,
|
||||||
|
@@ -45,9 +45,6 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// Just use some arbitrary bytes as delivery script.
|
|
||||||
dummyDeliveryScript = channels.AlicesPrivKey
|
|
||||||
|
|
||||||
testKeyLoc = keychain.KeyLocator{Family: keychain.KeyFamilyNodeKey}
|
testKeyLoc = keychain.KeyLocator{Family: keychain.KeyFamilyNodeKey}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -368,26 +365,26 @@ func createTestPeer(notifier chainntnfs.ChainNotifier,
|
|||||||
}
|
}
|
||||||
|
|
||||||
cfg := &Config{
|
cfg := &Config{
|
||||||
Addr: cfgAddr,
|
Addr: cfgAddr,
|
||||||
PubKeyBytes: pubKey,
|
PubKeyBytes: pubKey,
|
||||||
ErrorBuffer: errBuffer,
|
ErrorBuffer: errBuffer,
|
||||||
ChainIO: chainIO,
|
ChainIO: chainIO,
|
||||||
Switch: mockSwitch,
|
Switch: mockSwitch,
|
||||||
|
|
||||||
ChanActiveTimeout: chanActiveTimeout,
|
ChanActiveTimeout: chanActiveTimeout,
|
||||||
InterceptSwitch: htlcswitch.NewInterceptableSwitch(
|
InterceptSwitch: htlcswitch.NewInterceptableSwitch(
|
||||||
nil, testCltvRejectDelta, false,
|
nil, testCltvRejectDelta, false,
|
||||||
),
|
),
|
||||||
|
|
||||||
ChannelDB: dbAlice.ChannelStateDB(),
|
ChannelDB: dbAlice.ChannelStateDB(),
|
||||||
FeeEstimator: estimator,
|
FeeEstimator: estimator,
|
||||||
Wallet: wallet,
|
Wallet: wallet,
|
||||||
ChainNotifier: notifier,
|
ChainNotifier: notifier,
|
||||||
ChanStatusMgr: chanStatusMgr,
|
ChanStatusMgr: chanStatusMgr,
|
||||||
|
Features: lnwire.NewFeatureVector(nil, lnwire.Features),
|
||||||
DisconnectPeer: func(b *btcec.PublicKey) error { return nil },
|
DisconnectPeer: func(b *btcec.PublicKey) error { return nil },
|
||||||
}
|
}
|
||||||
|
|
||||||
alicePeer := NewBrontide(*cfg)
|
alicePeer := NewBrontide(*cfg)
|
||||||
|
alicePeer.remoteFeatures = lnwire.NewFeatureVector(nil, lnwire.Features)
|
||||||
|
|
||||||
chanID := lnwire.NewChanIDFromOutPoint(channelAlice.ChannelPoint())
|
chanID := lnwire.NewChanIDFromOutPoint(channelAlice.ChannelPoint())
|
||||||
alicePeer.activeChannels[chanID] = channelAlice
|
alicePeer.activeChannels[chanID] = channelAlice
|
||||||
|
Reference in New Issue
Block a user