lnwallet: add awareness of taproot overlay chan type to reservations

This commit is contained in:
Olaoluwa Osuntokun 2024-06-25 15:31:32 -07:00 committed by Oliver Gugger
parent 745f3a6181
commit 4efa39ddb1
No known key found for this signature in database
GPG key ID: 8E4256593F177720
2 changed files with 29 additions and 6 deletions

View file

@ -2,6 +2,7 @@ package lnwallet
import (
"errors"
"fmt"
"net"
"sync"
@ -50,6 +51,11 @@ const (
// channels that use a musig2 funding output and the tapscript tree
// where relevant for the commitment transaction pk scripts.
CommitmentTypeSimpleTaproot
// CommitmentTypeSimpleTaprootOverlay builds on the existing
// CommitmentTypeSimpleTaproot type but layers on a special overlay
// protocol.
CommitmentTypeSimpleTaprootOverlay
)
// HasStaticRemoteKey returns whether the commitment type supports remote
@ -59,8 +65,11 @@ func (c CommitmentType) HasStaticRemoteKey() bool {
case CommitmentTypeTweakless,
CommitmentTypeAnchorsZeroFeeHtlcTx,
CommitmentTypeScriptEnforcedLease,
CommitmentTypeSimpleTaproot:
CommitmentTypeSimpleTaproot,
CommitmentTypeSimpleTaprootOverlay:
return true
default:
return false
}
@ -71,8 +80,11 @@ func (c CommitmentType) HasAnchors() bool {
switch c {
case CommitmentTypeAnchorsZeroFeeHtlcTx,
CommitmentTypeScriptEnforcedLease,
CommitmentTypeSimpleTaproot:
CommitmentTypeSimpleTaproot,
CommitmentTypeSimpleTaprootOverlay:
return true
default:
return false
}
@ -80,7 +92,8 @@ func (c CommitmentType) HasAnchors() bool {
// IsTaproot returns true if the channel type is a taproot channel.
func (c CommitmentType) IsTaproot() bool {
return c == CommitmentTypeSimpleTaproot
return c == CommitmentTypeSimpleTaproot ||
c == CommitmentTypeSimpleTaprootOverlay
}
// String returns the name of the CommitmentType.
@ -96,6 +109,8 @@ func (c CommitmentType) String() string {
return "script-enforced-lease"
case CommitmentTypeSimpleTaproot:
return "simple-taproot"
case CommitmentTypeSimpleTaprootOverlay:
return "simple-taproot-overlay"
default:
return "invalid"
}
@ -424,7 +439,7 @@ func NewChannelReservation(capacity, localFundingAmt btcutil.Amount,
chanType |= channeldb.FrozenBit
}
if req.CommitType == CommitmentTypeSimpleTaproot {
if req.CommitType.IsTaproot() {
chanType |= channeldb.SimpleTaprootFeatureBit
}
@ -440,7 +455,15 @@ func NewChannelReservation(capacity, localFundingAmt btcutil.Amount,
chanType |= channeldb.ScidAliasFeatureBit
}
if req.TapscriptRoot.IsSome() {
taprootOverlay := req.CommitType == CommitmentTypeSimpleTaprootOverlay
switch {
case taprootOverlay && req.TapscriptRoot.IsNone():
fallthrough
case !taprootOverlay && req.TapscriptRoot.IsSome():
return nil, fmt.Errorf("taproot overlay chans must be set " +
"with tapscript root")
case taprootOverlay && req.TapscriptRoot.IsSome():
chanType |= channeldb.TapscriptRootBit
}

View file

@ -983,7 +983,7 @@ func (l *LightningWallet) handleFundingReserveRequest(req *InitFundingReserveMsg
TaprootPubkey, true, DefaultAccountName,
)
},
Musig2: req.CommitType == CommitmentTypeSimpleTaproot,
Musig2: req.CommitType.IsTaproot(),
}
fundingIntent, err = req.ChanFunder.ProvisionChannel(
fundingReq,