Skip to content

Commit 1e07ba3

Browse files
committed
lnwallet/chanfunding: add optional tapscript root
1 parent 733e192 commit 1e07ba3

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

lnwallet/chanfunding/canned_assembler.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import (
55

66
"github.com/btcsuite/btcd/btcec/v2"
77
"github.com/btcsuite/btcd/btcutil"
8+
"github.com/btcsuite/btcd/chaincfg/chainhash"
89
"github.com/btcsuite/btcd/wire"
10+
"github.com/lightningnetwork/lnd/fn"
911
"github.com/lightningnetwork/lnd/input"
1012
"github.com/lightningnetwork/lnd/keychain"
1113
)
@@ -56,6 +58,14 @@ type ShimIntent struct {
5658
// generate an aggregate key to use as the taproot-native multi-sig
5759
// output.
5860
musig2 bool
61+
62+
// tapscriptRoot is the root of the tapscript tree that will be used to
63+
// create the funding output. This field will only be utilized if the
64+
// musig2 flag above is set to true.
65+
//
66+
// TODO(roasbeef): fold above into new chan type? sum type like thing,
67+
// includes the tapscript root, etc
68+
tapscriptRoot fn.Option[chainhash.Hash]
5969
}
6070

6171
// FundingOutput returns the witness script, and the output that creates the
@@ -73,12 +83,18 @@ func (s *ShimIntent) FundingOutput() ([]byte, *wire.TxOut, error) {
7383
// If musig2 is active, then we'll return a single aggregated key
7484
// rather than using the "existing" funding script.
7585
if s.musig2 {
86+
var scriptOpts []input.FundingScriptOpt
87+
s.tapscriptRoot.WhenSome(func(root chainhash.Hash) {
88+
scriptOpts = append(
89+
scriptOpts, input.WithTapscriptRoot(root),
90+
)
91+
})
92+
7693
// Similar to the existing p2wsh script, we'll always ensure
7794
// the keys are sorted before use.
7895
return input.GenTaprootFundingScript(
79-
s.localKey.PubKey,
80-
s.remoteKey,
81-
int64(totalAmt),
96+
s.localKey.PubKey, s.remoteKey, int64(totalAmt),
97+
scriptOpts...,
8298
)
8399
}
84100

lnwallet/chanfunding/psbt_assembler.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,7 @@ func (p *PsbtAssembler) ProvisionChannel(req *Request) (Intent, error) {
534534
ShimIntent: ShimIntent{
535535
localFundingAmt: p.fundingAmt,
536536
musig2: req.Musig2,
537+
tapscriptRoot: req.TapscriptRoot,
537538
},
538539
State: PsbtShimRegistered,
539540
BasePsbt: p.basePsbt,

lnwallet/chanfunding/wallet_assembler.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -362,10 +362,10 @@ func (w *WalletAssembler) ProvisionChannel(r *Request) (Intent, error) {
362362
// we will call the specialized coin selection function for
363363
// that.
364364
case r.FundUpToMaxAmt != 0 && r.MinFundAmt != 0:
365-
366-
// We need to ensure that manually selected coins, which
367-
// are spent entirely on the channel funding, leave
368-
// enough funds in the wallet to cover for a reserve.
365+
// We need to ensure that manually selected coins,
366+
// which are spent entirely on the channel funding,
367+
// leave enough funds in the wallet to cover for a
368+
// reserve.
369369
reserve := r.WalletReserve
370370
if len(manuallySelectedCoins) > 0 {
371371
sumCoins := func(
@@ -386,8 +386,8 @@ func (w *WalletAssembler) ProvisionChannel(r *Request) (Intent, error) {
386386

387387
// If sufficient reserve funds are available we
388388
// don't have to provide for it during coin
389-
// selection. The manually selected coins can be
390-
// spent entirely on the channel funding. If
389+
// selection. The manually selected coins can
390+
// be spent entirely on the channel funding. If
391391
// the excess of coins cover the reserve
392392
// partially then we have to provide for the
393393
// rest during coin selection.
@@ -501,6 +501,7 @@ func (w *WalletAssembler) ProvisionChannel(r *Request) (Intent, error) {
501501
localFundingAmt: localContributionAmt,
502502
remoteFundingAmt: r.RemoteAmt,
503503
musig2: r.Musig2,
504+
tapscriptRoot: r.TapscriptRoot,
504505
},
505506
InputCoins: selectedCoins,
506507
coinLocker: w.cfg.CoinLocker,

0 commit comments

Comments
 (0)