Skip to content

Commit 26ab758

Browse files
Roasbeefguggero
authored andcommitted
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.
1 parent 28cb488 commit 26ab758

File tree

2 files changed

+27
-21
lines changed

2 files changed

+27
-21
lines changed

lnwallet/chanfunding/psbt_assembler.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/btcsuite/btcd/btcutil"
1111
"github.com/btcsuite/btcd/btcutil/psbt"
1212
"github.com/btcsuite/btcd/chaincfg"
13+
"github.com/btcsuite/btcd/chaincfg/chainhash"
1314
"github.com/btcsuite/btcd/txscript"
1415
"github.com/btcsuite/btcd/wire"
1516
"github.com/lightningnetwork/lnd/fn"
@@ -164,6 +165,13 @@ func (i *PsbtIntent) BindKeys(localKey *keychain.KeyDescriptor,
164165
i.State = PsbtOutputKnown
165166
}
166167

168+
// BindTapscriptRoot takes an optional tapscript root and binds it to the
169+
// underlying funding intent. This only applies to musig2 channels, and will be
170+
// used to make the musig2 funding output.
171+
func (i *PsbtIntent) BindTapscriptRoot(root fn.Option[chainhash.Hash]) {
172+
i.tapscriptRoot = root
173+
}
174+
167175
// FundingParams returns the parameters that are necessary to start funding the
168176
// channel output this intent was created for. It returns the P2WSH funding
169177
// address, the exact funding amount and a PSBT packet that contains exactly one

lnwallet/wallet.go

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,6 @@ type fundingReserveCancelMsg struct {
268268
type addContributionMsg struct {
269269
pendingFundingID uint64
270270

271-
// TODO(roasbeef): Should also carry SPV proofs in we're in SPV mode
272271
contribution *ChannelContribution
273272

274273
// NOTE: In order to avoid deadlocks, this channel MUST be buffered.
@@ -447,8 +446,6 @@ type LightningWallet struct {
447446
quit chan struct{}
448447

449448
wg sync.WaitGroup
450-
451-
// TODO(roasbeef): handle wallet lock/unlock
452449
}
453450

454451
// NewLightningWallet creates/opens and initializes a LightningWallet instance.
@@ -493,7 +490,6 @@ func (l *LightningWallet) Startup() error {
493490
}
494491

495492
l.wg.Add(1)
496-
// TODO(roasbeef): multiple request handlers?
497493
go l.requestHandler()
498494

499495
return nil
@@ -1447,7 +1443,6 @@ func (l *LightningWallet) initOurContribution(reservation *ChannelReservation,
14471443
// transaction via coin selection are freed allowing future reservations to
14481444
// include them.
14491445
func (l *LightningWallet) handleFundingCancelRequest(req *fundingReserveCancelMsg) {
1450-
// TODO(roasbeef): holding lock too long
14511446
l.limboMtx.Lock()
14521447
defer l.limboMtx.Unlock()
14531448

@@ -1472,11 +1467,6 @@ func (l *LightningWallet) handleFundingCancelRequest(req *fundingReserveCancelMs
14721467
)
14731468
}
14741469

1475-
// TODO(roasbeef): is it even worth it to keep track of unused keys?
1476-
1477-
// TODO(roasbeef): Is it possible to mark the unused change also as
1478-
// available?
1479-
14801470
delete(l.fundingLimbo, req.pendingFundingID)
14811471

14821472
pid := pendingReservation.pendingChanID
@@ -1654,16 +1644,24 @@ func (l *LightningWallet) handleContributionMsg(req *addContributionMsg) {
16541644
// and remote key which will be needed to calculate the multisig
16551645
// funding output in a next step.
16561646
pendingChanID := pendingReservation.pendingChanID
1647+
16571648
walletLog.Debugf("Advancing PSBT funding flow for "+
16581649
"pending_id(%x), binding keys local_key=%v, "+
16591650
"remote_key=%x", pendingChanID,
16601651
&ourContribution.MultiSigKey,
16611652
theirContribution.MultiSigKey.PubKey.SerializeCompressed())
1653+
16621654
fundingIntent.BindKeys(
16631655
&ourContribution.MultiSigKey,
16641656
theirContribution.MultiSigKey.PubKey,
16651657
)
16661658

1659+
// We might have a tapscript root, so we'll bind that now to
1660+
// ensure we make the proper funding output.
1661+
fundingIntent.BindTapscriptRoot(
1662+
pendingReservation.partialState.TapscriptRoot,
1663+
)
1664+
16671665
// Exit early because we can't continue the funding flow yet.
16681666
req.err <- &PsbtFundingRequired{
16691667
Intent: fundingIntent,
@@ -1736,16 +1734,17 @@ func (l *LightningWallet) handleContributionMsg(req *addContributionMsg) {
17361734
// the commitment transaction for the remote party, and verify their incoming
17371735
// partial signature.
17381736
func genMusigSession(ourContribution, theirContribution *ChannelContribution,
1739-
signer input.MuSig2Signer,
1740-
fundingOutput *wire.TxOut) *MusigPairSession {
1737+
signer input.MuSig2Signer, fundingOutput *wire.TxOut,
1738+
tapscriptRoot fn.Option[chainhash.Hash]) *MusigPairSession {
17411739

17421740
return NewMusigPairSession(&MusigSessionCfg{
1743-
LocalKey: ourContribution.MultiSigKey,
1744-
RemoteKey: theirContribution.MultiSigKey,
1745-
LocalNonce: *ourContribution.LocalNonce,
1746-
RemoteNonce: *theirContribution.LocalNonce,
1747-
Signer: signer,
1748-
InputTxOut: fundingOutput,
1741+
LocalKey: ourContribution.MultiSigKey,
1742+
RemoteKey: theirContribution.MultiSigKey,
1743+
LocalNonce: *ourContribution.LocalNonce,
1744+
RemoteNonce: *theirContribution.LocalNonce,
1745+
Signer: signer,
1746+
InputTxOut: fundingOutput,
1747+
TapscriptTweak: tapscriptRoot,
17491748
})
17501749
}
17511750

@@ -1795,6 +1794,7 @@ func (l *LightningWallet) signCommitTx(pendingReservation *ChannelReservation,
17951794
musigSessions := genMusigSession(
17961795
ourContribution, theirContribution,
17971796
l.Cfg.Signer, fundingOutput,
1797+
pendingReservation.partialState.TapscriptRoot,
17981798
)
17991799
pendingReservation.musigSessions = musigSessions
18001800
}
@@ -2189,6 +2189,7 @@ func (l *LightningWallet) verifyCommitSig(res *ChannelReservation,
21892189
res.musigSessions = genMusigSession(
21902190
res.ourContribution, res.theirContribution,
21912191
l.Cfg.Signer, fundingOutput,
2192+
res.partialState.TapscriptRoot,
21922193
)
21932194
}
21942195

@@ -2279,9 +2280,6 @@ func (l *LightningWallet) handleFundingCounterPartySigs(msg *addCounterPartySigs
22792280

22802281
// As we're about to broadcast the funding transaction, we'll take note
22812282
// of the current height for record keeping purposes.
2282-
//
2283-
// TODO(roasbeef): this info can also be piped into light client's
2284-
// basic fee estimation?
22852283
_, bestHeight, err := l.Cfg.ChainIO.GetBestBlock()
22862284
if err != nil {
22872285
msg.err <- err

0 commit comments

Comments
 (0)