Merge pull request #1802 from wpaulino/equal-zmq-conf-error
config: ensure ZMQ options are not equal and defer creating lnddir until all flag parsing is done
This commit is contained in:
commit
146e0efe71
91
config.go
91
config.go
@ -328,23 +328,42 @@ func loadConfig() (*config, error) {
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
// If the config file path has not been modified by the user, then we'll
|
||||
// use the default config file path. However, if the user has modified
|
||||
// their lnddir, then we should assume they intend to use the config
|
||||
// file within it.
|
||||
configFileDir := cleanAndExpandPath(preCfg.LndDir)
|
||||
configFilePath := cleanAndExpandPath(preCfg.ConfigFile)
|
||||
if configFileDir != defaultLndDir {
|
||||
if configFilePath == defaultConfigFile {
|
||||
configFilePath = filepath.Join(
|
||||
configFileDir, defaultConfigFilename,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// Next, load any additional configuration options from the file.
|
||||
var configFileError error
|
||||
cfg := preCfg
|
||||
if err := flags.IniParse(configFilePath, &cfg); err != nil {
|
||||
configFileError = err
|
||||
}
|
||||
|
||||
// Finally, parse the remaining command line options again to ensure
|
||||
// they take precedence.
|
||||
if _, err := flags.Parse(&cfg); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// If the provided lnd directory is not the default, we'll modify the
|
||||
// path to all of the files and directories that will live within it.
|
||||
lndDir := cleanAndExpandPath(preCfg.LndDir)
|
||||
configFilePath := cleanAndExpandPath(preCfg.ConfigFile)
|
||||
lndDir := cleanAndExpandPath(cfg.LndDir)
|
||||
if lndDir != defaultLndDir {
|
||||
// If the config file path has not been modified by the user,
|
||||
// then we'll use the default config file path. However, if the
|
||||
// user has modified their lnddir, then we should assume they
|
||||
// intend to use the config file within it.
|
||||
if configFilePath == defaultConfigFile {
|
||||
preCfg.ConfigFile = filepath.Join(lndDir, defaultConfigFilename)
|
||||
}
|
||||
preCfg.DataDir = filepath.Join(lndDir, defaultDataDirname)
|
||||
preCfg.TLSCertPath = filepath.Join(lndDir, defaultTLSCertFilename)
|
||||
preCfg.TLSKeyPath = filepath.Join(lndDir, defaultTLSKeyFilename)
|
||||
preCfg.LogDir = filepath.Join(lndDir, defaultLogDirname)
|
||||
preCfg.Tor.V2PrivateKeyPath = filepath.Join(lndDir, defaultTorV2PrivateKeyFilename)
|
||||
cfg.DataDir = filepath.Join(lndDir, defaultDataDirname)
|
||||
cfg.TLSCertPath = filepath.Join(lndDir, defaultTLSCertFilename)
|
||||
cfg.TLSKeyPath = filepath.Join(lndDir, defaultTLSKeyFilename)
|
||||
cfg.LogDir = filepath.Join(lndDir, defaultLogDirname)
|
||||
cfg.Tor.V2PrivateKeyPath = filepath.Join(lndDir, defaultTorV2PrivateKeyFilename)
|
||||
}
|
||||
|
||||
// Create the lnd directory if it doesn't already exist.
|
||||
@ -366,19 +385,6 @@ func loadConfig() (*config, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Next, load any additional configuration options from the file.
|
||||
var configFileError error
|
||||
cfg := preCfg
|
||||
if err := flags.IniParse(cfg.ConfigFile, &cfg); err != nil {
|
||||
configFileError = err
|
||||
}
|
||||
|
||||
// Finally, parse the remaining command line options again to ensure
|
||||
// they take precedence.
|
||||
if _, err := flags.Parse(&cfg); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// As soon as we're done parsing configuration options, ensure all paths
|
||||
// to directories and files are cleaned and expanded before attempting
|
||||
// to use them later on.
|
||||
@ -1080,6 +1086,17 @@ func parseRPCParams(cConfig *chainConfig, nodeConfig interface{}, net chainCode,
|
||||
}
|
||||
|
||||
case *bitcoindConfig:
|
||||
// Ensure that if the ZMQ options are set, that they are not
|
||||
// equal.
|
||||
if conf.ZMQPubRawBlock != "" && conf.ZMQPubRawTx != "" {
|
||||
err := checkZMQOptions(
|
||||
conf.ZMQPubRawBlock, conf.ZMQPubRawTx,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// If all of RPCUser, RPCPass, ZMQBlockHost, and ZMQTxHost are
|
||||
// set, we assume those parameters are good to use.
|
||||
if conf.RPCUser != "" && conf.RPCPass != "" &&
|
||||
@ -1099,8 +1116,8 @@ func parseRPCParams(cConfig *chainConfig, nodeConfig interface{}, net chainCode,
|
||||
confFile = "litecoin"
|
||||
}
|
||||
|
||||
// If only one or two of the parameters are set, we assume the
|
||||
// user did that unintentionally.
|
||||
// If not all of the parameters are set, we'll assume the user
|
||||
// did this unintentionally.
|
||||
if conf.RPCUser != "" || conf.RPCPass != "" ||
|
||||
conf.ZMQPubRawBlock != "" || conf.ZMQPubRawTx != "" {
|
||||
|
||||
@ -1241,9 +1258,8 @@ func extractBitcoindRPCParams(bitcoindConfigPath string) (string, string, string
|
||||
}
|
||||
zmqBlockHost := string(zmqBlockHostSubmatches[1])
|
||||
zmqTxHost := string(zmqTxHostSubmatches[1])
|
||||
if zmqBlockHost == zmqTxHost {
|
||||
return "", "", "", "", errors.New("zmqpubrawblock and " +
|
||||
"zmqpubrawtx must be different")
|
||||
if err := checkZMQOptions(zmqBlockHost, zmqTxHost); err != nil {
|
||||
return "", "", "", "", err
|
||||
}
|
||||
|
||||
// Next, we'll try to find an auth cookie. We need to detect the chain
|
||||
@ -1307,6 +1323,17 @@ func extractBitcoindRPCParams(bitcoindConfigPath string) (string, string, string
|
||||
zmqBlockHost, zmqTxHost, nil
|
||||
}
|
||||
|
||||
// checkZMQOptions ensures that the provided addresses to use as the hosts for
|
||||
// ZMQ rawblock and rawtx notifications are different.
|
||||
func checkZMQOptions(zmqBlockHost, zmqTxHost string) error {
|
||||
if zmqBlockHost == zmqTxHost {
|
||||
return errors.New("zmqpubrawblock and zmqpubrawtx must be set" +
|
||||
"to different addresses")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// normalizeNetwork returns the common name of a network type used to create
|
||||
// file paths. This allows differently versioned networks to use the same path.
|
||||
func normalizeNetwork(network string) string {
|
||||
|
Loading…
Reference in New Issue
Block a user