@@ -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 //
@@ -2086,8 +2092,14 @@ func (l *LightningWallet) verifyCommitSig(res *ChannelReservation,
20862092 // already. If we're the responder in the funding flow, we may
20872093 // not have generated it already.
20882094 if res .musigSessions == nil {
2095+ fundingOpts := fn .MapOptionZ (
2096+ res .partialState .TapscriptRoot ,
2097+ TapscriptRootToOpt ,
2098+ )
2099+
20892100 _ , fundingOutput , err := input .GenTaprootFundingScript (
20902101 localKey , remoteKey , channelValue ,
2102+ fundingOpts ... ,
20912103 )
20922104 if err != nil {
20932105 return err
@@ -2327,11 +2339,18 @@ func (l *LightningWallet) handleSingleFunderSigs(req *addSingleFunderSigsMsg) {
23272339 fundingTxOut * wire.TxOut
23282340 )
23292341 if chanType .IsTaproot () {
2330- fundingWitnessScript , fundingTxOut , err = input .GenTaprootFundingScript ( //nolint:lll
2342+ fundingOpts := fn .MapOptionZ (
2343+ pendingReservation .partialState .TapscriptRoot ,
2344+ TapscriptRootToOpt ,
2345+ )
2346+ //nolint:lll
2347+ fundingWitnessScript , fundingTxOut , err = input .GenTaprootFundingScript (
23312348 ourKey .PubKey , theirKey .PubKey , channelValue ,
2349+ fundingOpts ... ,
23322350 )
23332351 } else {
2334- fundingWitnessScript , fundingTxOut , err = input .GenFundingPkScript ( //nolint:lll
2352+ //nolint:lll
2353+ fundingWitnessScript , fundingTxOut , err = input .GenFundingPkScript (
23352354 ourKey .PubKey .SerializeCompressed (),
23362355 theirKey .PubKey .SerializeCompressed (), channelValue ,
23372356 )
@@ -2451,6 +2470,14 @@ func TapscriptRootToOpt(root chainhash.Hash) []input.FundingScriptOpt {
24512470 return []input.FundingScriptOpt {input .WithTapscriptRoot (root )}
24522471}
24532472
2473+ // TapscriptRootToTweak is a helper function that converts a tapscript root
2474+ // into a tweak that can be used with the MuSig2 API.
2475+ func TapscriptRootToTweak (root chainhash.Hash ) input.MuSig2Tweaks {
2476+ return input.MuSig2Tweaks {
2477+ TaprootTweak : root [:],
2478+ }
2479+ }
2480+
24542481// ValidateChannel will attempt to fully validate a newly mined channel, given
24552482// its funding transaction and existing channel state. If this method returns
24562483// an error, then the mined channel is invalid, and shouldn't be used.
@@ -2472,8 +2499,13 @@ func (l *LightningWallet) ValidateChannel(channelState *channeldb.OpenChannel,
24722499 // funding transaction, and also commitment validity.
24732500 var fundingScript []byte
24742501 if channelState .ChanType .IsTaproot () {
2502+ fundingOpts := fn .MapOptionZ (
2503+ channelState .TapscriptRoot , TapscriptRootToOpt ,
2504+ )
2505+
24752506 fundingScript , _ , err = input .GenTaprootFundingScript (
24762507 localKey , remoteKey , int64 (channel .Capacity ),
2508+ fundingOpts ... ,
24772509 )
24782510 if err != nil {
24792511 return err
0 commit comments