From 2ef9b377a68320307a8ec0c49b7da7ab279877f6 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Thu, 4 Apr 2024 17:26:03 -0700 Subject: [PATCH] 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. --- lnwallet/reservation.go | 25 +++++++++++++++++++++++-- lnwallet/wallet.go | 18 ++++++++++++++---- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/lnwallet/reservation.go b/lnwallet/reservation.go index 4f0940fe9..f511ffb61 100644 --- a/lnwallet/reservation.go +++ b/lnwallet/reservation.go @@ -11,10 +11,12 @@ import ( "github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/wire" "github.com/lightningnetwork/lnd/channeldb" + "github.com/lightningnetwork/lnd/fn" "github.com/lightningnetwork/lnd/input" "github.com/lightningnetwork/lnd/keychain" "github.com/lightningnetwork/lnd/lnwallet/chanfunding" "github.com/lightningnetwork/lnd/lnwire" + "github.com/lightningnetwork/lnd/tlv" ) // CommitmentType is an enum indicating the commitment type we should use for @@ -217,6 +219,11 @@ type ChannelReservation struct { fundingIntent chanfunding.Intent + // initAuxLeaves is an optional set of aux commitment leaves that'll + // modify the way we construct the commitment transaction, in + // particular the tapscript leaves. + initAuxLeaves fn.Option[CommitAuxLeaves] + // nextRevocationKeyLoc stores the key locator information for this // channel. nextRevocationKeyLoc keychain.KeyLocator @@ -412,7 +419,7 @@ func NewChannelReservation(capacity, localFundingAmt btcutil.Amount, chanType |= channeldb.ScidAliasFeatureBit } - if req.TapscriptRoot.IsSome() { + if req.AuxFundingDesc.IsSome() { chanType |= channeldb.TapscriptRootBit } @@ -437,25 +444,39 @@ func NewChannelReservation(capacity, localFundingAmt btcutil.Amount, RemoteBalance: theirBalance, FeePerKw: btcutil.Amount(req.CommitFeePerKw), CommitFee: commitFee, + CustomBlob: fn.MapOption(func(desc AuxFundingDesc) tlv.Blob { + return desc.CustomLocalCommitBlob + })(req.AuxFundingDesc), }, RemoteCommitment: channeldb.ChannelCommitment{ LocalBalance: ourBalance, RemoteBalance: theirBalance, FeePerKw: btcutil.Amount(req.CommitFeePerKw), CommitFee: commitFee, + CustomBlob: fn.MapOption(func(desc AuxFundingDesc) tlv.Blob { + return desc.CustomRemoteCommitBlob + })(req.AuxFundingDesc), }, ThawHeight: thawHeight, Db: wallet.Cfg.Database, InitialLocalBalance: ourBalance, InitialRemoteBalance: theirBalance, Memo: req.Memo, - TapscriptRoot: req.TapscriptRoot, + CustomBlob: fn.MapOption(func(desc AuxFundingDesc) tlv.Blob { + return desc.CustomFundingBlob + })(req.AuxFundingDesc), + TapscriptRoot: fn.MapOption(func(desc AuxFundingDesc) chainhash.Hash { + return desc.TapscriptRoot + })(req.AuxFundingDesc), }, pushMSat: req.PushMSat, pendingChanID: req.PendingChanID, reservationID: id, wallet: wallet, chanFunder: req.ChanFunder, + initAuxLeaves: fn.MapOption(func(desc AuxFundingDesc) CommitAuxLeaves { + return desc.InitAuxLeaves + })(req.AuxFundingDesc), }, nil } diff --git a/lnwallet/wallet.go b/lnwallet/wallet.go index dac13f377..fa192d5a5 100644 --- a/lnwallet/wallet.go +++ b/lnwallet/wallet.go @@ -229,10 +229,9 @@ type InitFundingReserveMsg struct { // channel that will be useful to our future selves. 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] + // AuxFundingDesc is an optional descriptor that can be used to modify + // the way channel funding occurs. + AuxFundingDesc fn.Option[AuxFundingDesc] // err is a channel in which all errors will be sent across. Will be // nil if this initial set is successful. @@ -1497,6 +1496,14 @@ func defaultCommitOpts() createCommitOpts { return createCommitOpts{} } +// WithAuxLeaves is a functional option that can be used to set the aux leaves +// for a new commitment transaction. +func WithAuxLeaves(leaves fn.Option[CommitAuxLeaves]) CreateCommitOpt { + return func(o *createCommitOpts) { + o.auxLeaves = leaves + } +} + // CreateCommitOpt is a functional option that can be used to modify the way a // new commitment transaction is created. type CreateCommitOpt func(*createCommitOpts) @@ -1885,6 +1892,7 @@ func (l *LightningWallet) handleChanPointReady(req *continueContributionMsg) { if pendingReservation.partialState.ChanType.HasLeaseExpiration() { leaseExpiry = pendingReservation.partialState.ThawHeight } + ourCommitTx, theirCommitTx, err := CreateCommitmentTxns( localBalance, remoteBalance, ourContribution.ChannelConfig, theirContribution.ChannelConfig, @@ -1892,6 +1900,7 @@ func (l *LightningWallet) handleChanPointReady(req *continueContributionMsg) { theirContribution.FirstCommitmentPoint, fundingTxIn, pendingReservation.partialState.ChanType, pendingReservation.partialState.IsInitiator, leaseExpiry, + WithAuxLeaves(pendingReservation.initAuxLeaves), ) if err != nil { req.err <- err @@ -2331,6 +2340,7 @@ func (l *LightningWallet) handleSingleFunderSigs(req *addSingleFunderSigsMsg) { pendingReservation.theirContribution.FirstCommitmentPoint, *fundingTxIn, chanType, pendingReservation.partialState.IsInitiator, leaseExpiry, + WithAuxLeaves(pendingReservation.initAuxLeaves), ) if err != nil { req.err <- err