peer: decorate delivery addr w/ internal key

In this commit, we move to add the internal key to the delivery addr. This way, we give the aux chan closer the extra information it may need to properly augment the normal co-op close process.
This commit is contained in:
Olaoluwa Osuntokun
2024-05-29 19:57:47 +02:00
committed by Oliver Gugger
parent 44ab7e6b10
commit 8dee76a1b8
4 changed files with 131 additions and 17 deletions

View File

@@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcec/v2/schnorr/musig2"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg"
@@ -106,6 +107,18 @@ const (
defaultMaxFeeMultiplier = 3
)
// DeliveryAddrWithKey wraps a normal delivery addr, but also includes the
// internal key for the delivery addr if known.
type DeliveryAddrWithKey struct {
// DeliveryAddress is the raw, serialized pkScript of the delivery
// address.
lnwire.DeliveryAddress
// InternalKey is the Taproot internal key of the delivery address, if
// the address is a P2TR output.
InternalKey fn.Option[btcec.PublicKey]
}
// ChanCloseCfg holds all the items that a ChanCloser requires to carry out its
// duties.
type ChanCloseCfg struct {
@@ -208,6 +221,10 @@ type ChanCloser struct {
// funds to.
localDeliveryScript []byte
// localInternalKey is the local delivery address Taproot internal key,
// if the local delivery script is a P2TR output.
localInternalKey fn.Option[btcec.PublicKey]
// remoteDeliveryScript is the script that we'll send the remote party's
// settled channel funds to.
remoteDeliveryScript []byte
@@ -284,7 +301,7 @@ func (d *SimpleCoopFeeEstimator) EstimateFee(chanType channeldb.ChannelType,
// NewChanCloser creates a new instance of the channel closure given the passed
// configuration, and delivery+fee preference. The final argument should only
// be populated iff, we're the initiator of this closing request.
func NewChanCloser(cfg ChanCloseCfg, deliveryScript []byte,
func NewChanCloser(cfg ChanCloseCfg, deliveryScript DeliveryAddrWithKey,
idealFeePerKw chainfee.SatPerKWeight, negotiationHeight uint32,
closeReq *htlcswitch.ChanClose,
closer lntypes.ChannelParty) *ChanCloser {
@@ -299,7 +316,8 @@ func NewChanCloser(cfg ChanCloseCfg, deliveryScript []byte,
cfg: cfg,
negotiationHeight: negotiationHeight,
idealFeeRate: idealFeePerKw,
localDeliveryScript: deliveryScript,
localInternalKey: deliveryScript.InternalKey,
localDeliveryScript: deliveryScript.DeliveryAddress,
priorFeeOffers: make(
map[btcutil.Amount]*lnwire.ClosingSigned,
),
@@ -362,6 +380,7 @@ func (c *ChanCloser) initChanShutdown() (*lnwire.Shutdown, error) {
ChanPoint: c.chanPoint,
ShortChanID: c.cfg.Channel.ShortChanID(),
Initiator: c.cfg.Channel.IsInitiator(),
InternalKey: c.localInternalKey,
CommitBlob: c.cfg.Channel.LocalCommitmentBlob(),
FundingBlob: c.cfg.Channel.FundingBlob(),
})
@@ -966,6 +985,7 @@ func (c *ChanCloser) ReceiveClosingSigned( //nolint:funlen
req := AuxShutdownReq{
ChanPoint: c.chanPoint,
ShortChanID: c.cfg.Channel.ShortChanID(),
InternalKey: c.localInternalKey,
Initiator: channel.IsInitiator(),
CommitBlob: channel.LocalCommitmentBlob(),
FundingBlob: channel.FundingBlob(),
@@ -1042,6 +1062,7 @@ func (c *ChanCloser) auxCloseOutputs(
req := AuxShutdownReq{
ChanPoint: c.chanPoint,
ShortChanID: c.cfg.Channel.ShortChanID(),
InternalKey: c.localInternalKey,
Initiator: c.cfg.Channel.IsInitiator(),
CommitBlob: c.cfg.Channel.LocalCommitmentBlob(),
FundingBlob: c.cfg.Channel.FundingBlob(),

View File

@@ -361,7 +361,8 @@ func TestMaxFeeClamp(t *testing.T) {
Channel: &channel,
MaxFee: test.inputMaxFee,
FeeEstimator: &SimpleCoopFeeEstimator{},
}, nil, test.idealFee, 0, nil, lntypes.Remote,
}, DeliveryAddrWithKey{}, test.idealFee, 0, nil,
lntypes.Remote,
)
// We'll call initFeeBaseline early here since we need
@@ -402,7 +403,8 @@ func TestMaxFeeBailOut(t *testing.T) {
MaxFee: idealFee * 2,
}
chanCloser := NewChanCloser(
closeCfg, nil, idealFee, 0, nil, lntypes.Remote,
closeCfg, DeliveryAddrWithKey{}, idealFee, 0,
nil, lntypes.Remote,
)
// We'll now force the channel state into the
@@ -526,7 +528,7 @@ func TestTaprootFastClose(t *testing.T) {
DisableChannel: func(wire.OutPoint) error {
return nil
},
}, nil, idealFee, 0, nil, lntypes.Local,
}, DeliveryAddrWithKey{}, idealFee, 0, nil, lntypes.Local,
)
aliceCloser.initFeeBaseline()
@@ -543,7 +545,7 @@ func TestTaprootFastClose(t *testing.T) {
DisableChannel: func(wire.OutPoint) error {
return nil
},
}, nil, idealFee, 0, nil, lntypes.Remote,
}, DeliveryAddrWithKey{}, idealFee, 0, nil, lntypes.Remote,
)
bobCloser.initFeeBaseline()