@@ -23,6 +23,7 @@ import (
2323 "github.com/btcsuite/btcwallet/wallet"
2424 "github.com/davecgh/go-spew/spew"
2525 "github.com/lightningnetwork/lnd/channeldb"
26+ "github.com/lightningnetwork/lnd/fn"
2627 "github.com/lightningnetwork/lnd/input"
2728 "github.com/lightningnetwork/lnd/keychain"
2829 "github.com/lightningnetwork/lnd/lnwallet/chainfee"
@@ -200,6 +201,11 @@ type InitFundingReserveMsg struct {
200201 // channel that will be useful to our future selves.
201202 Memo []byte
202203
204+ // TapscriptRoot is the root of the tapscript tree that will be used to
205+ // create the funding output. This is an optional field that should
206+ // only be set for taproot channels,
207+ TapscriptRoot fn.Option [chainhash.Hash ]
208+
203209 // err is a channel in which all errors will be sent across. Will be
204210 // nil if this initial set is successful.
205211 //
@@ -2083,8 +2089,14 @@ func (l *LightningWallet) verifyCommitSig(res *ChannelReservation,
20832089 // already. If we're the responder in the funding flow, we may
20842090 // not have generated it already.
20852091 if res .musigSessions == nil {
2092+ fundingOpts := fn .MapOptionZ (
2093+ res .partialState .TapscriptRoot ,
2094+ TapscriptRootToOpt ,
2095+ )
2096+
20862097 _ , fundingOutput , err := input .GenTaprootFundingScript (
20872098 localKey , remoteKey , channelValue ,
2099+ fundingOpts ... ,
20882100 )
20892101 if err != nil {
20902102 return err
@@ -2324,8 +2336,13 @@ func (l *LightningWallet) handleSingleFunderSigs(req *addSingleFunderSigsMsg) {
23242336 fundingTxOut * wire.TxOut
23252337 )
23262338 if chanType .IsTaproot () {
2339+ fundingOpts := fn .MapOptionZ (
2340+ pendingReservation .partialState .TapscriptRoot ,
2341+ TapscriptRootToOpt ,
2342+ )
23272343 fundingWitnessScript , fundingTxOut , err = input .GenTaprootFundingScript ( //nolint:lll
23282344 ourKey .PubKey , theirKey .PubKey , channelValue ,
2345+ fundingOpts ... ,
23292346 )
23302347 } else {
23312348 fundingWitnessScript , fundingTxOut , err = input .GenFundingPkScript ( //nolint:lll
@@ -2448,6 +2465,14 @@ func TapscriptRootToOpt(root chainhash.Hash) []input.FundingScriptOpt {
24482465 return []input.FundingScriptOpt {input .WithTapscriptRoot (root )}
24492466}
24502467
2468+ // TapscriptRootToTweak is a helper function that converts a tapscript root
2469+ // into a tweak that can be used with the musig2 API.
2470+ func TapscriptRootToTweak (root chainhash.Hash ) input.MuSig2Tweaks {
2471+ return input.MuSig2Tweaks {
2472+ TaprootTweak : root [:],
2473+ }
2474+ }
2475+
24512476// ValidateChannel will attempt to fully validate a newly mined channel, given
24522477// its funding transaction and existing channel state. If this method returns
24532478// an error, then the mined channel is invalid, and shouldn't be used.
@@ -2469,8 +2494,13 @@ func (l *LightningWallet) ValidateChannel(channelState *channeldb.OpenChannel,
24692494 // funding transaction, and also commitment validity.
24702495 var fundingScript []byte
24712496 if channelState .ChanType .IsTaproot () {
2497+ fundingOpts := fn .MapOptionZ (
2498+ channelState .TapscriptRoot , TapscriptRootToOpt ,
2499+ )
2500+
24722501 fundingScript , _ , err = input .GenTaprootFundingScript (
24732502 localKey , remoteKey , int64 (channel .Capacity ),
2503+ fundingOpts ... ,
24742504 )
24752505 if err != nil {
24762506 return err
0 commit comments