From 4559438c4b348f5136c810408307bb83ba0438cd Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 18 Jan 2018 13:54:41 -0700 Subject: [PATCH] config.go: check for RPCUser AND RPCPass (AND ZMQPath for bitcoind) This commit causes the configuration parser to accept the values of RPCUser, RPCPass, and (for the bitcoind back-end) ZMQPath configured in lnd.conf or on the command line ONLY when all are specified. It causes the configuration parser to look in btcd.conf or bitcoin.conf ONLY when none are specified, and causes an error to be returned when only some are specified, as users have done so erroneously and the lack of clear feedback has caused difficulties. --- config.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/config.go b/config.go index f1310595..ceae22f5 100644 --- a/config.go +++ b/config.go @@ -621,13 +621,30 @@ func parseRPCParams(cConfig *chainConfig, nodeConfig interface{}, net chainCode, // specified, we can return. switch conf := nodeConfig.(type) { case *btcdConfig: - if conf.RPCUser != "" || conf.RPCPass != "" { + // If both RPCUser and RPCPass are set, we assume those + // credentials are good to use. + if conf.RPCUser != "" && conf.RPCPass != "" { return nil } + // If only ONE of RPCUser or RPCPass is set, we assume the + // user did that unintentionally. + if conf.RPCUser != "" || conf.RPCPass != "" { + return fmt.Errorf("please set both or neither of " + + "btcd.rpcuser and btcd.rpcpass") + } case *bitcoindConfig: - if conf.RPCUser != "" || conf.RPCPass != "" || conf.ZMQPath != "" { + // If all of RPCUser, RPCPass, and ZMQPath are set, we assume + // those parameters are good to use. + if conf.RPCUser != "" && conf.RPCPass != "" && conf.ZMQPath != "" { return nil } + // If only one or two of the parameters are set, we assume the + // user did that unintentionally. + if conf.RPCUser != "" || conf.RPCPass != "" || conf.ZMQPath != "" { + return fmt.Errorf("please set all or none of " + + "bitcoind.rpcuser, bitcoind.rpcpass, and " + + "bitcoind.zmqpath") + } } // If we're in simnet mode, then the running btcd instance won't read