mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-07-12 22:22:36 +02:00
lnwallet: update internal funding flow w/ tapscript root
This isn't hooked up yet to the funding manager, but with this commit, we can now start to write internal unit tests that handle musig2 channels with a tapscript root.
This commit is contained in:
committed by
Oliver Gugger
parent
a4a7d11e88
commit
9466224805
@ -412,6 +412,10 @@ func NewChannelReservation(capacity, localFundingAmt btcutil.Amount,
|
|||||||
chanType |= channeldb.ScidAliasFeatureBit
|
chanType |= channeldb.ScidAliasFeatureBit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if req.TapscriptRoot.IsSome() {
|
||||||
|
chanType |= channeldb.TapscriptRootBit
|
||||||
|
}
|
||||||
|
|
||||||
return &ChannelReservation{
|
return &ChannelReservation{
|
||||||
ourContribution: &ChannelContribution{
|
ourContribution: &ChannelContribution{
|
||||||
FundingAmount: ourBalance.ToSatoshis(),
|
FundingAmount: ourBalance.ToSatoshis(),
|
||||||
@ -445,6 +449,7 @@ func NewChannelReservation(capacity, localFundingAmt btcutil.Amount,
|
|||||||
InitialLocalBalance: ourBalance,
|
InitialLocalBalance: ourBalance,
|
||||||
InitialRemoteBalance: theirBalance,
|
InitialRemoteBalance: theirBalance,
|
||||||
Memo: req.Memo,
|
Memo: req.Memo,
|
||||||
|
TapscriptRoot: req.TapscriptRoot,
|
||||||
},
|
},
|
||||||
pushMSat: req.PushMSat,
|
pushMSat: req.PushMSat,
|
||||||
pendingChanID: req.PendingChanID,
|
pendingChanID: req.PendingChanID,
|
||||||
|
@ -23,6 +23,7 @@ import (
|
|||||||
"github.com/btcsuite/btcwallet/wallet"
|
"github.com/btcsuite/btcwallet/wallet"
|
||||||
"github.com/davecgh/go-spew/spew"
|
"github.com/davecgh/go-spew/spew"
|
||||||
"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/keychain"
|
"github.com/lightningnetwork/lnd/keychain"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
||||||
@ -200,6 +201,11 @@ type InitFundingReserveMsg struct {
|
|||||||
// channel that will be useful to our future selves.
|
// channel that will be useful to our future selves.
|
||||||
Memo []byte
|
Memo []byte
|
||||||
|
|
||||||
|
// TapscriptRoot is the root of the tapscript tree that will be used to
|
||||||
|
// create the funding output. This is an optional field that should
|
||||||
|
// only be set for taproot channels.
|
||||||
|
TapscriptRoot fn.Option[chainhash.Hash]
|
||||||
|
|
||||||
// err is a channel in which all errors will be sent across. Will be
|
// err is a channel in which all errors will be sent across. Will be
|
||||||
// nil if this initial set is successful.
|
// nil if this initial set is successful.
|
||||||
//
|
//
|
||||||
@ -2086,8 +2092,14 @@ func (l *LightningWallet) verifyCommitSig(res *ChannelReservation,
|
|||||||
// already. If we're the responder in the funding flow, we may
|
// already. If we're the responder in the funding flow, we may
|
||||||
// not have generated it already.
|
// not have generated it already.
|
||||||
if res.musigSessions == nil {
|
if res.musigSessions == nil {
|
||||||
|
fundingOpts := fn.MapOptionZ(
|
||||||
|
res.partialState.TapscriptRoot,
|
||||||
|
TapscriptRootToOpt,
|
||||||
|
)
|
||||||
|
|
||||||
_, fundingOutput, err := input.GenTaprootFundingScript(
|
_, fundingOutput, err := input.GenTaprootFundingScript(
|
||||||
localKey, remoteKey, channelValue,
|
localKey, remoteKey, channelValue,
|
||||||
|
fundingOpts...,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -2327,11 +2339,18 @@ func (l *LightningWallet) handleSingleFunderSigs(req *addSingleFunderSigsMsg) {
|
|||||||
fundingTxOut *wire.TxOut
|
fundingTxOut *wire.TxOut
|
||||||
)
|
)
|
||||||
if chanType.IsTaproot() {
|
if chanType.IsTaproot() {
|
||||||
fundingWitnessScript, fundingTxOut, err = input.GenTaprootFundingScript( //nolint:lll
|
fundingOpts := fn.MapOptionZ(
|
||||||
|
pendingReservation.partialState.TapscriptRoot,
|
||||||
|
TapscriptRootToOpt,
|
||||||
|
)
|
||||||
|
//nolint:lll
|
||||||
|
fundingWitnessScript, fundingTxOut, err = input.GenTaprootFundingScript(
|
||||||
ourKey.PubKey, theirKey.PubKey, channelValue,
|
ourKey.PubKey, theirKey.PubKey, channelValue,
|
||||||
|
fundingOpts...,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
fundingWitnessScript, fundingTxOut, err = input.GenFundingPkScript( //nolint:lll
|
//nolint:lll
|
||||||
|
fundingWitnessScript, fundingTxOut, err = input.GenFundingPkScript(
|
||||||
ourKey.PubKey.SerializeCompressed(),
|
ourKey.PubKey.SerializeCompressed(),
|
||||||
theirKey.PubKey.SerializeCompressed(), channelValue,
|
theirKey.PubKey.SerializeCompressed(), channelValue,
|
||||||
)
|
)
|
||||||
@ -2451,6 +2470,14 @@ func TapscriptRootToOpt(root chainhash.Hash) []input.FundingScriptOpt {
|
|||||||
return []input.FundingScriptOpt{input.WithTapscriptRoot(root)}
|
return []input.FundingScriptOpt{input.WithTapscriptRoot(root)}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TapscriptRootToTweak is a helper function that converts a tapscript root
|
||||||
|
// into a tweak that can be used with the MuSig2 API.
|
||||||
|
func TapscriptRootToTweak(root chainhash.Hash) input.MuSig2Tweaks {
|
||||||
|
return input.MuSig2Tweaks{
|
||||||
|
TaprootTweak: 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.
|
||||||
@ -2472,8 +2499,13 @@ func (l *LightningWallet) ValidateChannel(channelState *channeldb.OpenChannel,
|
|||||||
// funding transaction, and also commitment validity.
|
// funding transaction, and also commitment validity.
|
||||||
var fundingScript []byte
|
var fundingScript []byte
|
||||||
if channelState.ChanType.IsTaproot() {
|
if channelState.ChanType.IsTaproot() {
|
||||||
|
fundingOpts := fn.MapOptionZ(
|
||||||
|
channelState.TapscriptRoot, TapscriptRootToOpt,
|
||||||
|
)
|
||||||
|
|
||||||
fundingScript, _, err = input.GenTaprootFundingScript(
|
fundingScript, _, err = input.GenTaprootFundingScript(
|
||||||
localKey, remoteKey, int64(channel.Capacity),
|
localKey, remoteKey, int64(channel.Capacity),
|
||||||
|
fundingOpts...,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
Reference in New Issue
Block a user