Skip to content

Commit 54bbc25

Browse files
Roasbeefguggero
authored andcommitted
lnwallet: use AuxFundingDesc to populate all custom chan info
With this commit, we'll now populate all the custom channel information within the OpenChannel and ChannelCommitment structs.
1 parent f2c2a82 commit 54bbc25

File tree

1 file changed

+51
-6
lines changed

1 file changed

+51
-6
lines changed

lnwallet/wallet.go

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,8 @@ type InitFundingReserveMsg struct {
229229
// channel that will be useful to our future selves.
230230
Memo []byte
231231

232-
// TapscriptRoot is the root of the tapscript tree that will be used to
233-
// create the funding output. This is an optional field that should
234-
// only be set for taproot channels.
232+
// TapscriptRoot is an optional tapscript root that if provided, will
233+
// be used to create the combined key for musig2 based channels.
235234
TapscriptRoot fn.Option[chainhash.Hash]
236235

237236
// err is a channel in which all errors will be sent across. Will be
@@ -282,6 +281,10 @@ type addContributionMsg struct {
282281
type continueContributionMsg struct {
283282
pendingFundingID uint64
284283

284+
// auxFundingDesc is an optional descriptor that contains information
285+
// about the custom channel funding flow.
286+
auxFundingDesc fn.Option[AuxFundingDesc]
287+
285288
// NOTE: In order to avoid deadlocks, this channel MUST be buffered.
286289
err chan error
287290
}
@@ -337,6 +340,10 @@ type addCounterPartySigsMsg struct {
337340
type addSingleFunderSigsMsg struct {
338341
pendingFundingID uint64
339342

343+
// auxFundingDesc is an optional descriptor that contains information
344+
// about the custom channel funding flow.
345+
auxFundingDesc fn.Option[AuxFundingDesc]
346+
340347
// fundingOutpoint is the outpoint of the completed funding
341348
// transaction as assembled by the workflow initiator.
342349
fundingOutpoint *wire.OutPoint
@@ -1489,14 +1496,26 @@ func (l *LightningWallet) handleFundingCancelRequest(req *fundingReserveCancelMs
14891496
// createCommitOpts is a struct that holds the options for creating a new
14901497
// commitment transaction.
14911498
type createCommitOpts struct {
1492-
auxLeaves fn.Option[CommitAuxLeaves]
1499+
localAuxLeaves fn.Option[CommitAuxLeaves]
1500+
remoteAuxLeaves fn.Option[CommitAuxLeaves]
14931501
}
14941502

14951503
// defaultCommitOpts returns a new createCommitOpts with default values.
14961504
func defaultCommitOpts() createCommitOpts {
14971505
return createCommitOpts{}
14981506
}
14991507

1508+
// WithAuxLeaves is a functional option that can be used to set the aux leaves
1509+
// for a new commitment transaction.
1510+
func WithAuxLeaves(localLeaves,
1511+
remoteLeaves fn.Option[CommitAuxLeaves]) CreateCommitOpt {
1512+
1513+
return func(o *createCommitOpts) {
1514+
o.localAuxLeaves = localLeaves
1515+
o.remoteAuxLeaves = remoteLeaves
1516+
}
1517+
}
1518+
15001519
// CreateCommitOpt is a functional option that can be used to modify the way a
15011520
// new commitment transaction is created.
15021521
type CreateCommitOpt func(*createCommitOpts)
@@ -1528,7 +1547,7 @@ func CreateCommitmentTxns(localBalance, remoteBalance btcutil.Amount,
15281547
ourCommitTx, err := CreateCommitTx(
15291548
chanType, fundingTxIn, localCommitmentKeys, ourChanCfg,
15301549
theirChanCfg, localBalance, remoteBalance, 0, initiator,
1531-
leaseExpiry, options.auxLeaves,
1550+
leaseExpiry, options.localAuxLeaves,
15321551
)
15331552
if err != nil {
15341553
return nil, nil, err
@@ -1542,7 +1561,7 @@ func CreateCommitmentTxns(localBalance, remoteBalance btcutil.Amount,
15421561
theirCommitTx, err := CreateCommitTx(
15431562
chanType, fundingTxIn, remoteCommitmentKeys, theirChanCfg,
15441563
ourChanCfg, remoteBalance, localBalance, 0, !initiator,
1545-
leaseExpiry, options.auxLeaves,
1564+
leaseExpiry, options.remoteAuxLeaves,
15461565
)
15471566
if err != nil {
15481567
return nil, nil, err
@@ -1885,13 +1904,26 @@ func (l *LightningWallet) handleChanPointReady(req *continueContributionMsg) {
18851904
if pendingReservation.partialState.ChanType.HasLeaseExpiration() {
18861905
leaseExpiry = pendingReservation.partialState.ThawHeight
18871906
}
1907+
1908+
localAuxLeaves := fn.MapOption(
1909+
func(desc AuxFundingDesc) CommitAuxLeaves {
1910+
return desc.LocalInitAuxLeaves
1911+
},
1912+
)(req.auxFundingDesc)
1913+
remoteAuxLeaves := fn.MapOption(
1914+
func(desc AuxFundingDesc) CommitAuxLeaves {
1915+
return desc.RemoteInitAuxLeaves
1916+
},
1917+
)(req.auxFundingDesc)
1918+
18881919
ourCommitTx, theirCommitTx, err := CreateCommitmentTxns(
18891920
localBalance, remoteBalance, ourContribution.ChannelConfig,
18901921
theirContribution.ChannelConfig,
18911922
ourContribution.FirstCommitmentPoint,
18921923
theirContribution.FirstCommitmentPoint, fundingTxIn,
18931924
pendingReservation.partialState.ChanType,
18941925
pendingReservation.partialState.IsInitiator, leaseExpiry,
1926+
WithAuxLeaves(localAuxLeaves, remoteAuxLeaves),
18951927
)
18961928
if err != nil {
18971929
req.err <- err
@@ -2323,6 +2355,18 @@ func (l *LightningWallet) handleSingleFunderSigs(req *addSingleFunderSigsMsg) {
23232355
if pendingReservation.partialState.ChanType.HasLeaseExpiration() {
23242356
leaseExpiry = pendingReservation.partialState.ThawHeight
23252357
}
2358+
2359+
localAuxLeaves := fn.MapOption(
2360+
func(desc AuxFundingDesc) CommitAuxLeaves {
2361+
return desc.LocalInitAuxLeaves
2362+
},
2363+
)(req.auxFundingDesc)
2364+
remoteAuxLeaves := fn.MapOption(
2365+
func(desc AuxFundingDesc) CommitAuxLeaves {
2366+
return desc.RemoteInitAuxLeaves
2367+
},
2368+
)(req.auxFundingDesc)
2369+
23262370
ourCommitTx, theirCommitTx, err := CreateCommitmentTxns(
23272371
localBalance, remoteBalance,
23282372
pendingReservation.ourContribution.ChannelConfig,
@@ -2331,6 +2375,7 @@ func (l *LightningWallet) handleSingleFunderSigs(req *addSingleFunderSigsMsg) {
23312375
pendingReservation.theirContribution.FirstCommitmentPoint,
23322376
*fundingTxIn, chanType,
23332377
pendingReservation.partialState.IsInitiator, leaseExpiry,
2378+
WithAuxLeaves(localAuxLeaves, remoteAuxLeaves),
23342379
)
23352380
if err != nil {
23362381
req.err <- err

0 commit comments

Comments
 (0)