config: update to satisfy linter

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