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.
This commit is contained in:
Olaoluwa Osuntokun 2024-04-04 17:26:03 -07:00 committed by Oliver Gugger
parent 7d86894634
commit 2ef9b377a6
No known key found for this signature in database
GPG Key ID: 8E4256593F177720
2 changed files with 37 additions and 6 deletions

View File

@ -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
}

View File

@ -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