Skip to content

Commit 7d3c83b

Browse files
committed
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.
1 parent 1e07ba3 commit 7d3c83b

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

contractcourt/chain_watcher.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/davecgh/go-spew/spew"
1717
"github.com/lightningnetwork/lnd/chainntnfs"
1818
"github.com/lightningnetwork/lnd/channeldb"
19+
"github.com/lightningnetwork/lnd/fn"
1920
"github.com/lightningnetwork/lnd/input"
2021
"github.com/lightningnetwork/lnd/lnwallet"
2122
)
@@ -301,8 +302,11 @@ func (c *chainWatcher) Start() error {
301302
err error
302303
)
303304
if chanState.ChanType.IsTaproot() {
305+
fundingOpts := fn.MapOptionZ(
306+
chanState.TapscriptRoot, lnwallet.TapscriptRootToOpt,
307+
)
304308
c.fundingPkScript, _, err = input.GenTaprootFundingScript(
305-
localKey, remoteKey, 0,
309+
localKey, remoteKey, 0, fundingOpts...,
306310
)
307311
if err != nil {
308312
return err

funding/manager.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/lightningnetwork/lnd/channeldb"
2424
"github.com/lightningnetwork/lnd/channeldb/models"
2525
"github.com/lightningnetwork/lnd/discovery"
26+
"github.com/lightningnetwork/lnd/fn"
2627
"github.com/lightningnetwork/lnd/input"
2728
"github.com/lightningnetwork/lnd/keychain"
2829
"github.com/lightningnetwork/lnd/labels"
@@ -2853,8 +2854,12 @@ func makeFundingScript(channel *channeldb.OpenChannel) ([]byte, error) {
28532854
remoteKey := channel.RemoteChanCfg.MultiSigKey.PubKey
28542855

28552856
if channel.ChanType.IsTaproot() {
2857+
fundingOpts := fn.MapOptionZ(
2858+
channel.TapscriptRoot, lnwallet.TapscriptRootToOpt,
2859+
)
28562860
pkScript, _, err := input.GenTaprootFundingScript(
28572861
localKey, remoteKey, int64(channel.Capacity),
2862+
fundingOpts...,
28582863
)
28592864
if err != nil {
28602865
return nil, err

lnwallet/wallet.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2442,6 +2442,12 @@ func initStateHints(commit1, commit2 *wire.MsgTx,
24422442
return nil
24432443
}
24442444

2445+
// TapscriptRootToOpt is a helper function that converts a tapscript root into
2446+
// the functional option we can use to pass into GenTaprootFundingScript.
2447+
func TapscriptRootToOpt(root chainhash.Hash) []input.FundingScriptOpt {
2448+
return []input.FundingScriptOpt{input.WithTapscriptRoot(root)}
2449+
}
2450+
24452451
// ValidateChannel will attempt to fully validate a newly mined channel, given
24462452
// its funding transaction and existing channel state. If this method returns
24472453
// an error, then the mined channel is invalid, and shouldn't be used.

routing/router.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,6 +1549,8 @@ func makeFundingScript(bitcoinKey1, bitcoinKey2 []byte,
15491549
return nil, err
15501550
}
15511551

1552+
// TODO(roasbeef): add tapscript root to gossip v1.5
1553+
15521554
return fundingScript, nil
15531555
}
15541556

0 commit comments

Comments
 (0)