diff --git a/contractcourt/chain_watcher.go b/contractcourt/chain_watcher.go index 89280d1bd..9cc56f999 100644 --- a/contractcourt/chain_watcher.go +++ b/contractcourt/chain_watcher.go @@ -308,7 +308,7 @@ func (c *chainWatcher) Start() error { fundingOpts := fn.MapOptionZ( chanState.TapscriptRoot, lnwallet.TapscriptRootToOpt, ) - c.fundingPkScript, _, err = input.GenTaprootFundingScript( + c.fundingPkScript, _, _, err = input.GenTaprootFundingScript( localKey, remoteKey, 0, fundingOpts..., ) if err != nil { diff --git a/funding/manager.go b/funding/manager.go index c7cc22f81..05f03deed 100644 --- a/funding/manager.go +++ b/funding/manager.go @@ -2890,7 +2890,7 @@ func makeFundingScript(channel *channeldb.OpenChannel) ([]byte, error) { fundingOpts := fn.MapOptionZ( channel.TapscriptRoot, lnwallet.TapscriptRootToOpt, ) - pkScript, _, err := input.GenTaprootFundingScript( + pkScript, _, _, err := input.GenTaprootFundingScript( localKey, remoteKey, int64(channel.Capacity), fundingOpts..., ) diff --git a/input/script_utils.go b/input/script_utils.go index 5ad0a0e90..08110ed2c 100644 --- a/input/script_utils.go +++ b/input/script_utils.go @@ -224,9 +224,12 @@ func WithTapscriptRoot(root chainhash.Hash) FundingScriptOpt { } // GenTaprootFundingScript constructs the taproot-native funding output that -// uses MuSig2 to create a single aggregated key to anchor the channel. -func GenTaprootFundingScript(aPub, bPub *btcec.PublicKey, - amt int64, opts ...FundingScriptOpt) ([]byte, *wire.TxOut, error) { +// uses MuSig2 to create a single aggregated key to anchor the channel. This +// also returns the MuSig2 aggregated key to allow the callers to examine the +// pre tweaked key as well as the final combined key. +func GenTaprootFundingScript(aPub, bPub *btcec.PublicKey, amt int64, + opts ...FundingScriptOpt) ([]byte, *wire.TxOut, + *musig2.AggregateKey, error) { options := defaultFundingScriptOpts() for _, optFunc := range opts { @@ -247,14 +250,15 @@ func GenTaprootFundingScript(aPub, bPub *btcec.PublicKey, []*btcec.PublicKey{aPub, bPub}, true, muSig2Opt, ) if err != nil { - return nil, nil, fmt.Errorf("unable to combine keys: %w", err) + return nil, nil, nil, fmt.Errorf("unable to combine "+ + "keys: %w", err) } // Now that we have the combined key, we can create a taproot pkScript // from this, and then make the txOut given the amount. pkScript, err := PayToTaprootScript(combinedKey.FinalKey) if err != nil { - return nil, nil, fmt.Errorf("unable to make taproot "+ + return nil, nil, nil, fmt.Errorf("unable to make taproot "+ "pkscript: %w", err) } @@ -262,7 +266,7 @@ func GenTaprootFundingScript(aPub, bPub *btcec.PublicKey, // For the "witness program" we just return the raw pkScript since the // output we create can _only_ be spent with a MuSig2 signature. - return pkScript, txOut, nil + return pkScript, txOut, combinedKey, nil } // SpendMultiSig generates the witness stack required to redeem the 2-of-2 p2wsh diff --git a/itest/lnd_funding_test.go b/itest/lnd_funding_test.go index 97613429e..a376c5906 100644 --- a/itest/lnd_funding_test.go +++ b/itest/lnd_funding_test.go @@ -1164,7 +1164,7 @@ func deriveFundingShim(ht *lntest.HarnessTest, carol, dave *node.HarnessNode, daveKey, err = btcec.ParsePubKey(daveFundingKey.RawKeyBytes) require.NoError(ht, err) - _, fundingOutput, err = input.GenTaprootFundingScript( + _, fundingOutput, _, err = input.GenTaprootFundingScript( carolKey, daveKey, int64(chanSize), ) require.NoError(ht, err) diff --git a/lnwallet/chanfunding/canned_assembler.go b/lnwallet/chanfunding/canned_assembler.go index 6b95c2bd2..bc4f83531 100644 --- a/lnwallet/chanfunding/canned_assembler.go +++ b/lnwallet/chanfunding/canned_assembler.go @@ -92,10 +92,12 @@ func (s *ShimIntent) FundingOutput() ([]byte, *wire.TxOut, error) { // Similar to the existing p2wsh script, we'll always ensure // the keys are sorted before use. - return input.GenTaprootFundingScript( + pkScript, txOut, _, err := input.GenTaprootFundingScript( s.localKey.PubKey, s.remoteKey, int64(totalAmt), scriptOpts..., ) + + return pkScript, txOut, err } return input.GenFundingPkScript( diff --git a/lnwallet/channel.go b/lnwallet/channel.go index a361f8b47..ae485e577 100644 --- a/lnwallet/channel.go +++ b/lnwallet/channel.go @@ -1552,7 +1552,7 @@ func (lc *LightningChannel) createSignDesc() error { chanState.TapscriptRoot, TapscriptRootToOpt, ) - fundingPkScript, _, err = input.GenTaprootFundingScript( + fundingPkScript, _, _, err = input.GenTaprootFundingScript( localKey, remoteKey, int64(lc.channelState.Capacity), fundingOpts..., ) diff --git a/lnwallet/wallet.go b/lnwallet/wallet.go index fa192d5a5..0e9521188 100644 --- a/lnwallet/wallet.go +++ b/lnwallet/wallet.go @@ -2155,7 +2155,7 @@ func (l *LightningWallet) verifyCommitSig(res *ChannelReservation, TapscriptRootToOpt, ) - _, fundingOutput, err := input.GenTaprootFundingScript( + _, fundingOutput, _, err := input.GenTaprootFundingScript( localKey, remoteKey, channelValue, fundingOpts..., ) @@ -2403,7 +2403,7 @@ func (l *LightningWallet) handleSingleFunderSigs(req *addSingleFunderSigsMsg) { TapscriptRootToOpt, ) //nolint:lll - fundingWitnessScript, fundingTxOut, err = input.GenTaprootFundingScript( + fundingWitnessScript, fundingTxOut, _, err = input.GenTaprootFundingScript( ourKey.PubKey, theirKey.PubKey, channelValue, fundingOpts..., ) @@ -2569,7 +2569,7 @@ func (l *LightningWallet) ValidateChannel(channelState *channeldb.OpenChannel, channelState.TapscriptRoot, TapscriptRootToOpt, ) - fundingScript, _, err = input.GenTaprootFundingScript( + fundingScript, _, _, err = input.GenTaprootFundingScript( localKey, remoteKey, int64(channel.Capacity), fundingOpts..., ) diff --git a/routing/router.go b/routing/router.go index aa3201f88..5bc1bca2c 100644 --- a/routing/router.go +++ b/routing/router.go @@ -1550,7 +1550,7 @@ func makeFundingScript(bitcoinKey1, bitcoinKey2 []byte, return nil, err } - fundingScript, _, err := input.GenTaprootFundingScript( + fundingScript, _, _, err := input.GenTaprootFundingScript( pubKey1, pubKey2, 0, ) if err != nil {