From fb8de147984a5d95a95333107550d4cbdef02716 Mon Sep 17 00:00:00 2001 From: Keagan McClelland Date: Mon, 5 Feb 2024 11:40:36 -0800 Subject: [PATCH] lnwallet+funding+lnd: trim unused parameters, from lnwallet.Config chainreg: remove unused GenDefaultBtcConstraints lnwallet+funding+lnd: remove DefaultDustLimit from lnwallet.Config --- chainreg/chainregistry.go | 13 ------------- config_builder.go | 34 ++++++++++++++++----------------- funding/manager_test.go | 17 ++++++++--------- lnwallet/config.go | 4 ---- lnwallet/parameters.go | 5 +++++ lnwallet/reservation.go | 2 +- lnwallet/test/test_interface.go | 13 +++---------- lnwallet/wallet.go | 3 ++- 8 files changed, 35 insertions(+), 56 deletions(-) diff --git a/chainreg/chainregistry.go b/chainreg/chainregistry.go index 89ca044da..02da26391 100644 --- a/chainreg/chainregistry.go +++ b/chainreg/chainregistry.go @@ -200,19 +200,6 @@ type ChainControl struct { Wallet *lnwallet.LightningWallet } -// GenDefaultBtcConstraints generates the default set of channel constraints -// that are to be used when funding a Bitcoin channel. -func GenDefaultBtcConstraints() channeldb.ChannelConstraints { - // We use the dust limit for the maximally sized witness program with - // a 40-byte data push. - dustLimit := lnwallet.DustLimitForSize(input.UnknownWitnessSize) - - return channeldb.ChannelConstraints{ - DustLimit: dustLimit, - MaxAcceptedHtlcs: input.MaxHTLCNumber / 2, - } -} - // NewPartialChainControl creates a new partial chain control that contains all // the parts that can be purely constructed from the passed in global // configuration and doesn't need any wallet instance yet. diff --git a/config_builder.go b/config_builder.go index 5ea550321..f1858cfd2 100644 --- a/config_builder.go +++ b/config_builder.go @@ -686,15 +686,14 @@ func (d *DefaultWalletImpl) BuildChainControl( // Create, and start the lnwallet, which handles the core payment // channel logic, and exposes control via proxy state machines. lnWalletConfig := lnwallet.Config{ - Database: partialChainControl.Cfg.ChanStateDB, - Notifier: partialChainControl.ChainNotifier, - WalletController: walletController, - Signer: walletController, - FeeEstimator: partialChainControl.FeeEstimator, - SecretKeyRing: keyRing, - ChainIO: walletController, - DefaultConstraints: chainreg.GenDefaultBtcConstraints(), - NetParams: *walletConfig.NetParams, + Database: partialChainControl.Cfg.ChanStateDB, + Notifier: partialChainControl.ChainNotifier, + WalletController: walletController, + Signer: walletController, + FeeEstimator: partialChainControl.FeeEstimator, + SecretKeyRing: keyRing, + ChainIO: walletController, + NetParams: *walletConfig.NetParams, } // The broadcast is already always active for neutrino nodes, so we @@ -801,15 +800,14 @@ func (d *RPCSignerWalletImpl) BuildChainControl( // Create, and start the lnwallet, which handles the core payment // channel logic, and exposes control via proxy state machines. lnWalletConfig := lnwallet.Config{ - Database: partialChainControl.Cfg.ChanStateDB, - Notifier: partialChainControl.ChainNotifier, - WalletController: rpcKeyRing, - Signer: rpcKeyRing, - FeeEstimator: partialChainControl.FeeEstimator, - SecretKeyRing: rpcKeyRing, - ChainIO: walletController, - DefaultConstraints: chainreg.GenDefaultBtcConstraints(), - NetParams: *walletConfig.NetParams, + Database: partialChainControl.Cfg.ChanStateDB, + Notifier: partialChainControl.ChainNotifier, + WalletController: rpcKeyRing, + Signer: rpcKeyRing, + FeeEstimator: partialChainControl.FeeEstimator, + SecretKeyRing: rpcKeyRing, + ChainIO: walletController, + NetParams: *walletConfig.NetParams, } // We've created the wallet configuration now, so we can finish diff --git a/funding/manager_test.go b/funding/manager_test.go index d6a0a4427..83ff6c12b 100644 --- a/funding/manager_test.go +++ b/funding/manager_test.go @@ -360,15 +360,14 @@ func createTestWallet(cdb *channeldb.ChannelStateDB, netParams *chaincfg.Params, estimator chainfee.Estimator) (*lnwallet.LightningWallet, error) { wallet, err := lnwallet.NewLightningWallet(lnwallet.Config{ - Database: cdb, - Notifier: notifier, - SecretKeyRing: keyRing, - WalletController: wc, - Signer: signer, - ChainIO: bio, - FeeEstimator: estimator, - NetParams: *netParams, - DefaultConstraints: chainreg.GenDefaultBtcConstraints(), + Database: cdb, + Notifier: notifier, + SecretKeyRing: keyRing, + WalletController: wc, + Signer: signer, + ChainIO: bio, + FeeEstimator: estimator, + NetParams: *netParams, }) if err != nil { return nil, err diff --git a/lnwallet/config.go b/lnwallet/config.go index f18d6e529..e85761693 100644 --- a/lnwallet/config.go +++ b/lnwallet/config.go @@ -49,10 +49,6 @@ type Config struct { // used to lookup the existence of outputs within the UTXO set. ChainIO BlockChainIO - // DefaultConstraints is the set of default constraints that will be - // used for any incoming or outgoing channel reservation requests. - DefaultConstraints channeldb.ChannelConstraints - // NetParams is the set of parameters that tells the wallet which chain // it will be operating on. NetParams chaincfg.Params diff --git a/lnwallet/parameters.go b/lnwallet/parameters.go index 36ee4baf8..41509ef9a 100644 --- a/lnwallet/parameters.go +++ b/lnwallet/parameters.go @@ -80,3 +80,8 @@ func DustLimitForSize(scriptSize int) btcutil.Amount { return dustlimit } + +// DustLimitUnknownWitness returns the dust limit for an UnknownWitnessSize. +func DustLimitUnknownWitness() btcutil.Amount { + return DustLimitForSize(input.UnknownWitnessSize) +} diff --git a/lnwallet/reservation.go b/lnwallet/reservation.go index 97e2d2ea2..a99448768 100644 --- a/lnwallet/reservation.go +++ b/lnwallet/reservation.go @@ -262,7 +262,7 @@ func NewChannelReservation(capacity, localFundingAmt btcutil.Amount, } // Used to cut down on verbosity. - defaultDust := wallet.Cfg.DefaultConstraints.DustLimit + defaultDust := DustLimitUnknownWitness() // If we're the responder to a single-funder reservation, then we have // no initial balance in the channel unless the remote party is pushing diff --git a/lnwallet/test/test_interface.go b/lnwallet/test/test_interface.go index aa3a6625e..19633f23c 100644 --- a/lnwallet/test/test_interface.go +++ b/lnwallet/test/test_interface.go @@ -356,14 +356,7 @@ func createTestWallet(tempTestDir string, miningNode *rpctest.Harness, Signer: signer, ChainIO: bio, FeeEstimator: chainfee.NewStaticEstimator(2500, 0), - DefaultConstraints: channeldb.ChannelConstraints{ - DustLimit: 500, - MaxPendingAmount: lnwire.NewMSatFromSatoshis(btcutil.SatoshiPerBitcoin) * 100, - ChanReserve: 100, - MinHTLC: 400, - MaxAcceptedHtlcs: 900, - }, - NetParams: *netParams, + NetParams: *netParams, } wallet, err := lnwallet.NewLightningWallet(cfg) @@ -458,7 +451,7 @@ func testDualFundingReservationWorkflow(miner *rpctest.Harness, require.NoError(t, err, "unable to initialize funding reservation") aliceChanReservation.SetNumConfsRequired(numReqConfs) channelConstraints := &channeldb.ChannelConstraints{ - DustLimit: alice.Cfg.DefaultConstraints.DustLimit, + DustLimit: lnwallet.DustLimitUnknownWitness(), ChanReserve: fundingAmount / 100, MaxPendingAmount: lnwire.NewMSatFromSatoshis(fundingAmount), MinHTLC: 1, @@ -863,7 +856,7 @@ func testSingleFunderReservationWorkflow(miner *rpctest.Harness, require.NoError(t, err, "unable to init channel reservation") aliceChanReservation.SetNumConfsRequired(numReqConfs) channelConstraints := &channeldb.ChannelConstraints{ - DustLimit: alice.Cfg.DefaultConstraints.DustLimit, + DustLimit: lnwallet.DustLimitUnknownWitness(), ChanReserve: fundingAmt / 100, MaxPendingAmount: lnwire.NewMSatFromSatoshis(fundingAmt), MinHTLC: 1, diff --git a/lnwallet/wallet.go b/lnwallet/wallet.go index 497b89129..7b9009fb1 100644 --- a/lnwallet/wallet.go +++ b/lnwallet/wallet.go @@ -1363,7 +1363,8 @@ func (l *LightningWallet) initOurContribution(reservation *ChannelReservation, ) reservation.partialState.RevocationProducer = producer - reservation.ourContribution.ChannelConstraints = l.Cfg.DefaultConstraints + reservation.ourContribution.ChannelConstraints.DustLimit = + DustLimitUnknownWitness() // If taproot channels are active, then we'll generate our verification // nonce here. We'll use this nonce to verify the signature for our