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.
This commit is contained in:
Olaoluwa Osuntokun committed 2023-08-22 16:30:54 -07:00
1 parent 05b5391614
commit f7ba08e147
1 file changed
+37 -2
+37 -2
View File
@@ -6,6 +6,7 @@ import (
"sync" "sync"
"github.com/btcsuite/btcd/btcec/v2" "github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcec/v2/schnorr/musig2"
"github.com/btcsuite/btcd/btcutil" "github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcd/wire"
@@ -42,6 +43,11 @@ const (
// guarantee that the channel initiator has no incentives to close a // guarantee that the channel initiator has no incentives to close a
// leased channel before its maturity date. // leased channel before its maturity date.
CommitmentTypeScriptEnforcedLease 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 // HasStaticRemoteKey returns whether the commitment type supports remote
@@ -50,7 +56,8 @@ func (c CommitmentType) HasStaticRemoteKey() bool {
switch c { switch c {
case CommitmentTypeTweakless, case CommitmentTypeTweakless,
CommitmentTypeAnchorsZeroFeeHtlcTx, CommitmentTypeAnchorsZeroFeeHtlcTx,
CommitmentTypeScriptEnforcedLease: CommitmentTypeScriptEnforcedLease,
CommitmentTypeSimpleTaproot:
return true return true
default: default:
return false return false
@@ -61,13 +68,19 @@ func (c CommitmentType) HasStaticRemoteKey() bool {
func (c CommitmentType) HasAnchors() bool { func (c CommitmentType) HasAnchors() bool {
switch c { switch c {
case CommitmentTypeAnchorsZeroFeeHtlcTx, case CommitmentTypeAnchorsZeroFeeHtlcTx,
CommitmentTypeScriptEnforcedLease: CommitmentTypeScriptEnforcedLease,
CommitmentTypeSimpleTaproot:
return true return true
default: default:
return false 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. // String returns the name of the CommitmentType.
func (c CommitmentType) String() string { func (c CommitmentType) String() string {
switch c { switch c {
@@ -79,6 +92,8 @@ func (c CommitmentType) String() string {
return "anchors-zero-fee-second-level" return "anchors-zero-fee-second-level"
case CommitmentTypeScriptEnforcedLease: case CommitmentTypeScriptEnforcedLease:
return "script-enforced-lease" return "script-enforced-lease"
case CommitmentTypeSimpleTaproot:
return "simple-taproot"
default: default:
return "invalid" return "invalid"
} }
@@ -117,6 +132,11 @@ type ChannelContribution struct {
// UpfrontShutdown is an optional address to which the channel should be // UpfrontShutdown is an optional address to which the channel should be
// paid out to on cooperative close. // paid out to on cooperative close.
UpfrontShutdown lnwire.DeliveryAddress 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 // 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 // nextRevocationKeyLoc stores the key locator information for this
// channel. // channel.
nextRevocationKeyLoc keychain.KeyLocator nextRevocationKeyLoc keychain.KeyLocator
musigSessions *MusigPairSession
} }
// NewChannelReservation creates a new channel reservation. This function is // NewChannelReservation creates a new channel reservation. This function is
@@ -372,6 +394,10 @@ func NewChannelReservation(capacity, localFundingAmt btcutil.Amount,
chanType |= channeldb.FrozenBit chanType |= channeldb.FrozenBit
} }
if req.CommitType == CommitmentTypeSimpleTaproot {
chanType |= channeldb.SimpleTaprootFeatureBit
}
if req.ZeroConf { if req.ZeroConf {
chanType |= channeldb.ZeroConfBit chanType |= channeldb.ZeroConfBit
} }
@@ -455,6 +481,15 @@ func (r *ChannelReservation) IsZeroConf() bool {
return r.partialState.IsZeroConf() 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 // CommitConstraints takes the constraints that the remote party specifies for
// the type of commitments that we can generate for them. These constraints // the type of commitments that we can generate for them. These constraints
// include several parameters that serve as flow control restricting the amount // include several parameters that serve as flow control restricting the amount