From f7ba08e147b41aa8257c758274321f3ae100f0fc Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Thu, 19 Jan 2023 17:02:32 -0800 Subject: [PATCH] lnwallet: add new CommitmentTypeSimpleTaproot chan type In this commit, we add a new wallet level channel type, along with the new fields we'll need to accept from both parties within the contribution messages. In this case, we now have a local nonce, along with the internal musig session. --- lnwallet/reservation.go | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/lnwallet/reservation.go b/lnwallet/reservation.go index 916184c6b..bfb22b816 100644 --- a/lnwallet/reservation.go +++ b/lnwallet/reservation.go @@ -6,6 +6,7 @@ import ( "sync" "github.com/btcsuite/btcd/btcec/v2" + "github.com/btcsuite/btcd/btcec/v2/schnorr/musig2" "github.com/btcsuite/btcd/btcutil" "github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/wire" @@ -42,6 +43,11 @@ const ( // guarantee that the channel initiator has no incentives to close a // leased channel before its maturity date. CommitmentTypeScriptEnforcedLease + + // CommitmentTypeSimpleTaproot is the base commitment type for the + // channels that use a musig2 funding output and the tapscript tree + // where relevant for the commitment transaciton pk scripts. + CommitmentTypeSimpleTaproot ) // HasStaticRemoteKey returns whether the commitment type supports remote @@ -50,7 +56,8 @@ func (c CommitmentType) HasStaticRemoteKey() bool { switch c { case CommitmentTypeTweakless, CommitmentTypeAnchorsZeroFeeHtlcTx, - CommitmentTypeScriptEnforcedLease: + CommitmentTypeScriptEnforcedLease, + CommitmentTypeSimpleTaproot: return true default: return false @@ -61,13 +68,19 @@ func (c CommitmentType) HasStaticRemoteKey() bool { func (c CommitmentType) HasAnchors() bool { switch c { case CommitmentTypeAnchorsZeroFeeHtlcTx, - CommitmentTypeScriptEnforcedLease: + CommitmentTypeScriptEnforcedLease, + CommitmentTypeSimpleTaproot: return true default: return false } } +// IsTaproot returns true if the channel type is a taproot channel. +func (c CommitmentType) IsTaproot() bool { + return c == CommitmentTypeSimpleTaproot +} + // String returns the name of the CommitmentType. func (c CommitmentType) String() string { switch c { @@ -79,6 +92,8 @@ func (c CommitmentType) String() string { return "anchors-zero-fee-second-level" case CommitmentTypeScriptEnforcedLease: return "script-enforced-lease" + case CommitmentTypeSimpleTaproot: + return "simple-taproot" default: return "invalid" } @@ -117,6 +132,11 @@ type ChannelContribution struct { // UpfrontShutdown is an optional address to which the channel should be // paid out to on cooperative close. UpfrontShutdown lnwire.DeliveryAddress + + // LocalNonce is populated if the channel type is a simple taproot + // channel. This stores the public (and secret) nonce that will be used + // to generate commitments for the local party. + LocalNonce *musig2.Nonces } // toChanConfig returns the raw channel configuration generated by a node's @@ -200,6 +220,8 @@ type ChannelReservation struct { // nextRevocationKeyLoc stores the key locator information for this // channel. nextRevocationKeyLoc keychain.KeyLocator + + musigSessions *MusigPairSession } // NewChannelReservation creates a new channel reservation. This function is @@ -372,6 +394,10 @@ func NewChannelReservation(capacity, localFundingAmt btcutil.Amount, chanType |= channeldb.FrozenBit } + if req.CommitType == CommitmentTypeSimpleTaproot { + chanType |= channeldb.SimpleTaprootFeatureBit + } + if req.ZeroConf { chanType |= channeldb.ZeroConfBit } @@ -455,6 +481,15 @@ func (r *ChannelReservation) IsZeroConf() bool { return r.partialState.IsZeroConf() } +// IsTaproot returns if the reservation's underlying partial channel state is a +// taproot channel. +func (r *ChannelReservation) IsTaproot() bool { + r.RLock() + defer r.RUnlock() + + return r.partialState.ChanType.IsTaproot() +} + // CommitConstraints takes the constraints that the remote party specifies for // the type of commitments that we can generate for them. These constraints // include several parameters that serve as flow control restricting the amount