Skip to content

Commit 9909c01

Browse files
committed
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 75c9c8c commit 9909c01

File tree

2 files changed

+36
-11
lines changed

2 files changed

+36
-11
lines changed

lnwallet/reservation.go

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/lightningnetwork/lnd/keychain"
1717
"github.com/lightningnetwork/lnd/lnwallet/chanfunding"
1818
"github.com/lightningnetwork/lnd/lnwire"
19+
"github.com/lightningnetwork/lnd/tlv"
1920
)
2021

2122
// CommitmentType is an enum indicating the commitment type we should use for
@@ -213,16 +214,16 @@ type ChannelReservation struct {
213214
// commitment state.
214215
pushMSat lnwire.MilliSatoshi
215216

216-
// tapscriptRoot is the root of the tapscript tree that will be used to
217-
// create the musig2 funding output. This is only used for taproot
218-
// channels.
219-
tapscriptRoot fn.Option[chainhash.Hash]
220-
221217
wallet *LightningWallet
222218
chanFunder chanfunding.Assembler
223219

224220
fundingIntent chanfunding.Intent
225221

222+
// initAuxLeaves is an optional set of aux commitment leaves that'll
223+
// modify the way we construct the commitment transaction, in
224+
// particular the tapscript leaves.
225+
initAuxLeaves fn.Option[CommitAuxLeaves]
226+
226227
// nextRevocationKeyLoc stores the key locator information for this
227228
// channel.
228229
nextRevocationKeyLoc keychain.KeyLocator
@@ -418,7 +419,7 @@ func NewChannelReservation(capacity, localFundingAmt btcutil.Amount,
418419
chanType |= channeldb.ScidAliasFeatureBit
419420
}
420421

421-
if req.TapscriptRoot.IsSome() {
422+
if req.AuxFundingDesc.IsSome() {
422423
chanType |= channeldb.TapscriptRootBit
423424
}
424425

@@ -443,25 +444,39 @@ func NewChannelReservation(capacity, localFundingAmt btcutil.Amount,
443444
RemoteBalance: theirBalance,
444445
FeePerKw: btcutil.Amount(req.CommitFeePerKw),
445446
CommitFee: commitFee,
447+
CustomBlob: fn.MapOption(func(desc AuxFundingDesc) tlv.Blob {
448+
return desc.CustomLocalCommitBlob
449+
})(req.AuxFundingDesc),
446450
},
447451
RemoteCommitment: channeldb.ChannelCommitment{
448452
LocalBalance: ourBalance,
449453
RemoteBalance: theirBalance,
450454
FeePerKw: btcutil.Amount(req.CommitFeePerKw),
451455
CommitFee: commitFee,
456+
CustomBlob: fn.MapOption(func(desc AuxFundingDesc) tlv.Blob {
457+
return desc.CustomRemoteCommitBlob
458+
})(req.AuxFundingDesc),
452459
},
453460
ThawHeight: thawHeight,
454461
Db: wallet.Cfg.Database,
455462
InitialLocalBalance: ourBalance,
456463
InitialRemoteBalance: theirBalance,
457464
Memo: req.Memo,
458-
TapscriptRoot: req.TapscriptRoot,
465+
CustomBlob: fn.MapOption(func(desc AuxFundingDesc) tlv.Blob {
466+
return desc.CustomFundingBlob
467+
})(req.AuxFundingDesc),
468+
TapscriptRoot: fn.MapOption(func(desc AuxFundingDesc) chainhash.Hash {
469+
return desc.TapscriptRoot
470+
})(req.AuxFundingDesc),
459471
},
460472
pushMSat: req.PushMSat,
461473
pendingChanID: req.PendingChanID,
462474
reservationID: id,
463475
wallet: wallet,
464476
chanFunder: req.ChanFunder,
477+
initAuxLeaves: fn.MapOption(func(desc AuxFundingDesc) CommitAuxLeaves {
478+
return desc.InitAuxLeaves
479+
})(req.AuxFundingDesc),
465480
}, nil
466481
}
467482

lnwallet/wallet.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,9 @@ 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,
235-
TapscriptRoot fn.Option[chainhash.Hash]
232+
// AuxFundingDesc is an optional descriptor that can be used to modify
233+
// the way channel funding occurs.
234+
AuxFundingDesc fn.Option[AuxFundingDesc]
236235

237236
// err is a channel in which all errors will be sent across. Will be
238237
// nil if this initial set is successful.
@@ -1494,6 +1493,14 @@ func defaultCommitOpts() createCommitOpts {
14941493
return createCommitOpts{}
14951494
}
14961495

1496+
// WithAuxLeaves is a functional option that can be used to set the aux leaves
1497+
// for a new commitment transaction.
1498+
func WithAuxLeaves(leaves fn.Option[CommitAuxLeaves]) CreateCommitOpt {
1499+
return func(o *createCommitOpts) {
1500+
o.auxLeaves = leaves
1501+
}
1502+
}
1503+
14971504
// CreateCommitOpt is a functional option that can be used to modify the way a
14981505
// new commitment transaction is created.
14991506
type CreateCommitOpt func(*createCommitOpts)
@@ -1881,13 +1888,15 @@ func (l *LightningWallet) handleChanPointReady(req *continueContributionMsg) {
18811888
if pendingReservation.partialState.ChanType.HasLeaseExpiration() {
18821889
leaseExpiry = pendingReservation.partialState.ThawHeight
18831890
}
1891+
18841892
ourCommitTx, theirCommitTx, err := CreateCommitmentTxns(
18851893
localBalance, remoteBalance, ourContribution.ChannelConfig,
18861894
theirContribution.ChannelConfig,
18871895
ourContribution.FirstCommitmentPoint,
18881896
theirContribution.FirstCommitmentPoint, fundingTxIn,
18891897
pendingReservation.partialState.ChanType,
18901898
pendingReservation.partialState.IsInitiator, leaseExpiry,
1899+
WithAuxLeaves(pendingReservation.initAuxLeaves),
18911900
)
18921901
if err != nil {
18931902
req.err <- err
@@ -2327,6 +2336,7 @@ func (l *LightningWallet) handleSingleFunderSigs(req *addSingleFunderSigsMsg) {
23272336
pendingReservation.theirContribution.FirstCommitmentPoint,
23282337
*fundingTxIn, chanType,
23292338
pendingReservation.partialState.IsInitiator, leaseExpiry,
2339+
WithAuxLeaves(pendingReservation.initAuxLeaves),
23302340
)
23312341
if err != nil {
23322342
req.err <- err

0 commit comments

Comments
 (0)