mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-18 13:52:02 +01:00
funding+lnwallet: only blind tapscript root early in funding flow
In this commit, we modify the aux funding work flow slightly. We won't be able to generate the full AuxFundingDesc until both sides has sent+received funding params. So we'll now only attempt to bind the tapscript root as soon as we send+recv the open_channel message. We'll now also make sure that we pass the tapscript root all the way down into the musig2 session creation.
This commit is contained in:
parent
39b1080166
commit
f2dff16c37
@ -10,6 +10,7 @@ import (
|
||||
"github.com/btcsuite/btcd/btcutil"
|
||||
"github.com/btcsuite/btcd/btcutil/psbt"
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/btcsuite/btcd/txscript"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/lightningnetwork/lnd/fn"
|
||||
@ -164,6 +165,13 @@ func (i *PsbtIntent) BindKeys(localKey *keychain.KeyDescriptor,
|
||||
i.State = PsbtOutputKnown
|
||||
}
|
||||
|
||||
// BindTapscriptRoot takes an optional tapscript root and binds it to the
|
||||
// underlying funding intent. This only applies to musig2 channels, and will be
|
||||
// used to make the musig2 funding output.
|
||||
func (i *PsbtIntent) BindTapscriptRoot(root fn.Option[chainhash.Hash]) {
|
||||
i.tapscriptRoot = root
|
||||
}
|
||||
|
||||
// FundingParams returns the parameters that are necessary to start funding the
|
||||
// channel output this intent was created for. It returns the P2WSH funding
|
||||
// address, the exact funding amount and a PSBT packet that contains exactly one
|
||||
|
@ -278,7 +278,6 @@ type fundingReserveCancelMsg struct {
|
||||
type addContributionMsg struct {
|
||||
pendingFundingID uint64
|
||||
|
||||
// TODO(roasbeef): Should also carry SPV proofs in we're in SPV mode
|
||||
contribution *ChannelContribution
|
||||
|
||||
// NOTE: In order to avoid deadlocks, this channel MUST be buffered.
|
||||
@ -457,8 +456,6 @@ type LightningWallet struct {
|
||||
quit chan struct{}
|
||||
|
||||
wg sync.WaitGroup
|
||||
|
||||
// TODO(roasbeef): handle wallet lock/unlock
|
||||
}
|
||||
|
||||
// NewLightningWallet creates/opens and initializes a LightningWallet instance.
|
||||
@ -503,7 +500,6 @@ func (l *LightningWallet) Startup() error {
|
||||
}
|
||||
|
||||
l.wg.Add(1)
|
||||
// TODO(roasbeef): multiple request handlers?
|
||||
go l.requestHandler()
|
||||
|
||||
return nil
|
||||
@ -1459,7 +1455,6 @@ func (l *LightningWallet) initOurContribution(reservation *ChannelReservation,
|
||||
// transaction via coin selection are freed allowing future reservations to
|
||||
// include them.
|
||||
func (l *LightningWallet) handleFundingCancelRequest(req *fundingReserveCancelMsg) {
|
||||
// TODO(roasbeef): holding lock too long
|
||||
l.limboMtx.Lock()
|
||||
defer l.limboMtx.Unlock()
|
||||
|
||||
@ -1484,11 +1479,6 @@ func (l *LightningWallet) handleFundingCancelRequest(req *fundingReserveCancelMs
|
||||
)
|
||||
}
|
||||
|
||||
// TODO(roasbeef): is it even worth it to keep track of unused keys?
|
||||
|
||||
// TODO(roasbeef): Is it possible to mark the unused change also as
|
||||
// available?
|
||||
|
||||
delete(l.fundingLimbo, req.pendingFundingID)
|
||||
|
||||
pid := pendingReservation.pendingChanID
|
||||
@ -1668,16 +1658,24 @@ func (l *LightningWallet) handleContributionMsg(req *addContributionMsg) {
|
||||
// and remote key which will be needed to calculate the multisig
|
||||
// funding output in a next step.
|
||||
pendingChanID := pendingReservation.pendingChanID
|
||||
|
||||
walletLog.Debugf("Advancing PSBT funding flow for "+
|
||||
"pending_id(%x), binding keys local_key=%v, "+
|
||||
"remote_key=%x", pendingChanID,
|
||||
&ourContribution.MultiSigKey,
|
||||
theirContribution.MultiSigKey.PubKey.SerializeCompressed())
|
||||
|
||||
fundingIntent.BindKeys(
|
||||
&ourContribution.MultiSigKey,
|
||||
theirContribution.MultiSigKey.PubKey,
|
||||
)
|
||||
|
||||
// We might have a tapscript root, so we'll bind that now to
|
||||
// ensure we make the proper funding output.
|
||||
fundingIntent.BindTapscriptRoot(
|
||||
pendingReservation.partialState.TapscriptRoot,
|
||||
)
|
||||
|
||||
// Exit early because we can't continue the funding flow yet.
|
||||
req.err <- &PsbtFundingRequired{
|
||||
Intent: fundingIntent,
|
||||
@ -1750,16 +1748,17 @@ func (l *LightningWallet) handleContributionMsg(req *addContributionMsg) {
|
||||
// the commitment transaction for the remote party, and verify their incoming
|
||||
// partial signature.
|
||||
func genMusigSession(ourContribution, theirContribution *ChannelContribution,
|
||||
signer input.MuSig2Signer,
|
||||
fundingOutput *wire.TxOut) *MusigPairSession {
|
||||
signer input.MuSig2Signer, fundingOutput *wire.TxOut,
|
||||
tapscriptRoot fn.Option[chainhash.Hash]) *MusigPairSession {
|
||||
|
||||
return NewMusigPairSession(&MusigSessionCfg{
|
||||
LocalKey: ourContribution.MultiSigKey,
|
||||
RemoteKey: theirContribution.MultiSigKey,
|
||||
LocalNonce: *ourContribution.LocalNonce,
|
||||
RemoteNonce: *theirContribution.LocalNonce,
|
||||
Signer: signer,
|
||||
InputTxOut: fundingOutput,
|
||||
LocalKey: ourContribution.MultiSigKey,
|
||||
RemoteKey: theirContribution.MultiSigKey,
|
||||
LocalNonce: *ourContribution.LocalNonce,
|
||||
RemoteNonce: *theirContribution.LocalNonce,
|
||||
Signer: signer,
|
||||
InputTxOut: fundingOutput,
|
||||
TapscriptTweak: tapscriptRoot,
|
||||
})
|
||||
}
|
||||
|
||||
@ -1809,6 +1808,7 @@ func (l *LightningWallet) signCommitTx(pendingReservation *ChannelReservation,
|
||||
musigSessions := genMusigSession(
|
||||
ourContribution, theirContribution,
|
||||
l.Cfg.Signer, fundingOutput,
|
||||
pendingReservation.partialState.TapscriptRoot,
|
||||
)
|
||||
pendingReservation.musigSessions = musigSessions
|
||||
}
|
||||
@ -2198,6 +2198,7 @@ func (l *LightningWallet) verifyCommitSig(res *ChannelReservation,
|
||||
res.musigSessions = genMusigSession(
|
||||
res.ourContribution, res.theirContribution,
|
||||
l.Cfg.Signer, fundingOutput,
|
||||
res.partialState.TapscriptRoot,
|
||||
)
|
||||
}
|
||||
|
||||
@ -2288,9 +2289,6 @@ func (l *LightningWallet) handleFundingCounterPartySigs(msg *addCounterPartySigs
|
||||
|
||||
// As we're about to broadcast the funding transaction, we'll take note
|
||||
// of the current height for record keeping purposes.
|
||||
//
|
||||
// TODO(roasbeef): this info can also be piped into light client's
|
||||
// basic fee estimation?
|
||||
_, bestHeight, err := l.Cfg.ChainIO.GetBestBlock()
|
||||
if err != nil {
|
||||
msg.err <- err
|
||||
|
Loading…
x
Reference in New Issue
Block a user