From 23a63ef3284b02a0593a43e8c30ab15987b7ec34 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Thu, 3 Aug 2023 19:08:14 +0200 Subject: [PATCH] config: update to satisfy linter --- config.go | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/config.go b/config.go index 9dbc0ba30..c2aef5edd 100644 --- a/config.go +++ b/config.go @@ -228,6 +228,10 @@ const ( // BitcoinChainName is a string that represents the Bitcoin blockchain. BitcoinChainName = "bitcoin" + + bitcoindBackendName = "bitcoind" + btcdBackendName = "btcd" + neutrinoBackendName = "neutrino" ) var ( @@ -252,7 +256,7 @@ var ( defaultTLSKeyPath = filepath.Join(DefaultLndDir, defaultTLSKeyFilename) defaultLetsEncryptDir = filepath.Join(DefaultLndDir, defaultLetsEncryptDirname) - defaultBtcdDir = btcutil.AppDataDir("btcd", false) + defaultBtcdDir = btcutil.AppDataDir(btcdBackendName, false) defaultBtcdRPCCertFile = filepath.Join(defaultBtcdDir, "rpc.cert") defaultBitcoindDir = btcutil.AppDataDir("bitcoin", false) @@ -546,7 +550,7 @@ func DefaultConfig() Config { FeeRate: chainreg.DefaultBitcoinFeeRate, TimeLockDelta: chainreg.DefaultBitcoinTimeLockDelta, MaxLocalDelay: defaultMaxLocalCSVDelay, - Node: "btcd", + Node: btcdBackendName, }, BtcdMode: &lncfg.Btcd{ Dir: defaultBtcdDir, @@ -936,26 +940,32 @@ func ValidateConfig(cfg Config, interceptor signal.Interceptor, fileParser, // any of the autopilot params. if cfg.Autopilot.MaxChannels < 0 { str := "autopilot.maxchannels must be non-negative" + return nil, mkErr(str) } if cfg.Autopilot.Allocation < 0 { str := "autopilot.allocation must be non-negative" + return nil, mkErr(str) } if cfg.Autopilot.MinChannelSize < 0 { str := "autopilot.minchansize must be non-negative" + return nil, mkErr(str) } if cfg.Autopilot.MaxChannelSize < 0 { str := "autopilot.maxchansize must be non-negative" + return nil, mkErr(str) } if cfg.Autopilot.MinConfs < 0 { str := "autopilot.minconfs must be non-negative" + return nil, mkErr(str) } if cfg.Autopilot.ConfTarget < 1 { str := "autopilot.conftarget must be positive" + return nil, mkErr(str) } @@ -1061,6 +1071,7 @@ func ValidateConfig(cfg Config, interceptor signal.Interceptor, fileParser, // host:port. This would lead to lnd not starting up properly. if cfg.Tor.SOCKS == cfg.Tor.Control { str := "tor.socks and tor.control can not us the same host:port" + return nil, mkErr(str) } @@ -1196,6 +1207,7 @@ func ValidateConfig(cfg Config, interceptor signal.Interceptor, fileParser, str := "The mainnet, testnet, regtest, and simnet " + "params can't be used together -- choose one " + "of the four" + return nil, mkErr(str) } @@ -1205,6 +1217,7 @@ func ValidateConfig(cfg Config, interceptor signal.Interceptor, fileParser, str := "either --bitcoin.mainnet, or bitcoin.testnet," + "bitcoin.simnet, or bitcoin.regtest " + "must be specified" + return nil, mkErr(str) } @@ -1214,7 +1227,7 @@ func ValidateConfig(cfg Config, interceptor signal.Interceptor, fileParser, } switch cfg.Bitcoin.Node { - case "btcd": + case btcdBackendName: err := parseRPCParams( cfg.Bitcoin, cfg.BtcdMode, cfg.ActiveNetParams, ) @@ -1222,7 +1235,7 @@ func ValidateConfig(cfg Config, interceptor signal.Interceptor, fileParser, return nil, mkErr("unable to load RPC "+ "credentials for btcd: %v", err) } - case "bitcoind": + case bitcoindBackendName: if cfg.Bitcoin.SimNet { return nil, mkErr("bitcoind does not " + "support simnet") @@ -1235,7 +1248,7 @@ func ValidateConfig(cfg Config, interceptor signal.Interceptor, fileParser, return nil, mkErr("unable to load RPC "+ "credentials for bitcoind: %v", err) } - case "neutrino": + case neutrinoBackendName: // No need to get RPC parameters. case "nochainbackend": @@ -1245,6 +1258,7 @@ func ValidateConfig(cfg Config, interceptor signal.Interceptor, fileParser, default: str := "only btcd, bitcoind, and neutrino mode " + "supported for bitcoin at this time" + return nil, mkErr(str) } @@ -1256,18 +1270,22 @@ func ValidateConfig(cfg Config, interceptor signal.Interceptor, fileParser, // any of the autopilot params. if cfg.Autopilot.MaxChannels < 0 { str := "autopilot.maxchannels must be non-negative" + return nil, mkErr(str) } if cfg.Autopilot.Allocation < 0 { str := "autopilot.allocation must be non-negative" + return nil, mkErr(str) } if cfg.Autopilot.MinChannelSize < 0 { str := "autopilot.minchansize must be non-negative" + return nil, mkErr(str) } if cfg.Autopilot.MaxChannelSize < 0 { str := "autopilot.maxchansize must be non-negative" + return nil, mkErr(str) } @@ -1757,9 +1775,9 @@ func parseRPCParams(cConfig *lncfg.Chain, nodeConfig interface{}, } // Set the daemon name for displaying proper errors. - daemonName = "btcd" + daemonName = btcdBackendName confDir = conf.Dir - confFileBase = "btcd" + confFileBase = btcdBackendName // If only ONE of RPCUser or RPCPass is set, we assume the // user did that unintentionally. @@ -1790,7 +1808,7 @@ func parseRPCParams(cConfig *lncfg.Chain, nodeConfig interface{}, } // Set the daemon name for displaying proper errors. - daemonName = "bitcoind" + daemonName = bitcoindBackendName confDir = conf.Dir confFile = conf.ConfigPath confFileBase = "bitcoin" @@ -1864,7 +1882,7 @@ func parseRPCParams(cConfig *lncfg.Chain, nodeConfig interface{}, confFileBase)) } switch cConfig.Node { - case "btcd": + case btcdBackendName: nConf := nodeConfig.(*lncfg.Btcd) rpcUser, rpcPass, err := extractBtcdRPCParams(confFile) if err != nil { @@ -1873,7 +1891,7 @@ func parseRPCParams(cConfig *lncfg.Chain, nodeConfig interface{}, } nConf.RPCUser, nConf.RPCPass = rpcUser, rpcPass - case "bitcoind": + case bitcoindBackendName: nConf := nodeConfig.(*lncfg.Bitcoind) rpcUser, rpcPass, zmqBlockHost, zmqTxHost, err := extractBitcoindRPCParams(netParams.Params.Name,