Skip to content

Commit 8a0c25b

Browse files
Roasbeefguggero
authored andcommitted
lnwallet/chanfunding: add optional tapscript root
1 parent 159f853 commit 8a0c25b

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,6 @@ func (w *WalletAssembler) ProvisionChannel(r *Request) (Intent, error) {
393393
// we will call the specialized coin selection function for
394394
// that.
395395
case r.FundUpToMaxAmt != 0 && r.MinFundAmt != 0:
396-
397396
// We need to ensure that manually selected coins, which
398397
// are spent entirely on the channel funding, leave
399398
// enough funds in the wallet to cover for a reserve.
@@ -538,6 +537,7 @@ func (w *WalletAssembler) ProvisionChannel(r *Request) (Intent, error) {
538537
localFundingAmt: localContributionAmt,
539538
remoteFundingAmt: r.RemoteAmt,
540539
musig2: r.Musig2,
540+
tapscriptRoot: r.TapscriptRoot,
541541
},
542542
InputCoins: selectedCoins,
543543
coinLeaser: w.cfg.CoinLeaser,

0 commit comments

Comments
 (0)