multi: update GenTaprootFundingScript to pass tapscript root

In most cases, we won't yet be passing a root. The option usage helps us keep the control flow mostly unchanged.
This commit is contained in:
Olaoluwa Osuntokun
2024-03-13 10:52:07 -04:00
committed by Oliver Gugger
parent 64ec9523a0
commit ebeb3afb04
4 changed files with 18 additions and 1 deletions

View File

@@ -16,6 +16,7 @@ import (
"github.com/davecgh/go-spew/spew" "github.com/davecgh/go-spew/spew"
"github.com/lightningnetwork/lnd/chainntnfs" "github.com/lightningnetwork/lnd/chainntnfs"
"github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/fn"
"github.com/lightningnetwork/lnd/input" "github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/lnwallet" "github.com/lightningnetwork/lnd/lnwallet"
) )
@@ -301,8 +302,11 @@ func (c *chainWatcher) Start() error {
err error err error
) )
if chanState.ChanType.IsTaproot() { if chanState.ChanType.IsTaproot() {
fundingOpts := fn.MapOptionZ(
chanState.TapscriptRoot, lnwallet.TapscriptRootToOpt,
)
c.fundingPkScript, _, err = input.GenTaprootFundingScript( c.fundingPkScript, _, err = input.GenTaprootFundingScript(
localKey, remoteKey, 0, localKey, remoteKey, 0, fundingOpts...,
) )
if err != nil { if err != nil {
return err return err

View File

@@ -23,6 +23,7 @@ import (
"github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/channeldb/models" "github.com/lightningnetwork/lnd/channeldb/models"
"github.com/lightningnetwork/lnd/discovery" "github.com/lightningnetwork/lnd/discovery"
"github.com/lightningnetwork/lnd/fn"
"github.com/lightningnetwork/lnd/input" "github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/keychain" "github.com/lightningnetwork/lnd/keychain"
"github.com/lightningnetwork/lnd/labels" "github.com/lightningnetwork/lnd/labels"
@@ -2853,8 +2854,12 @@ func makeFundingScript(channel *channeldb.OpenChannel) ([]byte, error) {
remoteKey := channel.RemoteChanCfg.MultiSigKey.PubKey remoteKey := channel.RemoteChanCfg.MultiSigKey.PubKey
if channel.ChanType.IsTaproot() { if channel.ChanType.IsTaproot() {
fundingOpts := fn.MapOptionZ(
channel.TapscriptRoot, lnwallet.TapscriptRootToOpt,
)
pkScript, _, err := input.GenTaprootFundingScript( pkScript, _, err := input.GenTaprootFundingScript(
localKey, remoteKey, int64(channel.Capacity), localKey, remoteKey, int64(channel.Capacity),
fundingOpts...,
) )
if err != nil { if err != nil {
return nil, err return nil, err

View File

@@ -2445,6 +2445,12 @@ func initStateHints(commit1, commit2 *wire.MsgTx,
return nil return nil
} }
// TapscriptRootToOpt is a helper function that converts a tapscript root into
// the functional option we can use to pass into GenTaprootFundingScript.
func TapscriptRootToOpt(root chainhash.Hash) []input.FundingScriptOpt {
return []input.FundingScriptOpt{input.WithTapscriptRoot(root)}
}
// ValidateChannel will attempt to fully validate a newly mined channel, given // ValidateChannel will attempt to fully validate a newly mined channel, given
// its funding transaction and existing channel state. If this method returns // its funding transaction and existing channel state. If this method returns
// an error, then the mined channel is invalid, and shouldn't be used. // an error, then the mined channel is invalid, and shouldn't be used.

View File

@@ -1557,6 +1557,8 @@ func makeFundingScript(bitcoinKey1, bitcoinKey2 []byte,
return nil, err return nil, err
} }
// TODO(roasbeef): add tapscript root to gossip v1.5
return fundingScript, nil return fundingScript, nil
} }