diff --git a/config.go b/config.go index 71044e898..9c346a81b 100644 --- a/config.go +++ b/config.go @@ -1794,6 +1794,47 @@ func parseRPCParams(cConfig *lncfg.Chain, nodeConfig interface{}, } } + // Get the daemon name for displaying proper errors. + switch net { + case chainreg.BitcoinChain: + daemonName = "bitcoind" + confDir = conf.Dir + confFile = conf.ConfigPath + confFileBase = "bitcoin" + case chainreg.LitecoinChain: + daemonName = "litecoind" + confDir = conf.Dir + confFile = conf.ConfigPath + confFileBase = "litecoin" + } + + // Check that cookie and credentials don't contradict each + // other. + if (conf.RPCUser != "" || conf.RPCPass != "") && + conf.RPCCookie != "" { + + return fmt.Errorf("please only provide either "+ + "%[1]v.rpccookie or %[1]v.rpcuser and "+ + "%[1]v.rpcpass", daemonName) + } + + // We convert the cookie into a user name and password. + if conf.RPCCookie != "" { + cookie, err := ioutil.ReadFile(conf.RPCCookie) + if err != nil { + return fmt.Errorf("cannot read cookie file: %w", + err) + } + + splitCookie := strings.Split(string(cookie), ":") + if len(splitCookie) != 2 { + return fmt.Errorf("cookie file has a wrong " + + "format") + } + conf.RPCUser = splitCookie[0] + conf.RPCPass = splitCookie[1] + } + if conf.RPCUser != "" && conf.RPCPass != "" { // If all of RPCUser, RPCPass, ZMQBlockHost, and // ZMQTxHost are set, we assume those parameters are @@ -1809,28 +1850,14 @@ func parseRPCParams(cConfig *lncfg.Chain, nodeConfig interface{}, } } - // Get the daemon name for displaying proper errors. - switch net { - case chainreg.BitcoinChain: - daemonName = "bitcoind" - confDir = conf.Dir - confFile = conf.ConfigPath - confFileBase = "bitcoin" - case chainreg.LitecoinChain: - daemonName = "litecoind" - confDir = conf.Dir - confFile = conf.ConfigPath - confFileBase = "litecoin" - } - // 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 != "" { - return fmt.Errorf("please set all or none of "+ - "%[1]v.rpcuser, %[1]v.rpcpass, "+ - "%[1]v.zmqpubrawblock, %[1]v.zmqpubrawtx", + return fmt.Errorf("please set %[1]v.rpcuser and "+ + "%[1]v.rpcpass (or %[1]v.rpccookie) together "+ + "with %[1]v.zmqpubrawblock, %[1]v.zmqpubrawtx", daemonName) } } diff --git a/docs/release-notes/release-notes-0.15.1.md b/docs/release-notes/release-notes-0.15.1.md index 976e1f33d..b0e9cbc40 100644 --- a/docs/release-notes/release-notes-0.15.1.md +++ b/docs/release-notes/release-notes-0.15.1.md @@ -115,6 +115,9 @@ * [Re-initialise registered middleware index lookup map after removal of a registered middleware](https://github.com/lightningnetwork/lnd/pull/6739) +* [Bitcoind cookie file path can be specified with zmq + options](https://github.com/lightningnetwork/lnd/pull/6736) + ## Code Health ### Code cleanup, refactor, typo fixes @@ -135,6 +138,7 @@ # Contributors (Alphabetical Order) +* bitromortac * Carsten Otto * Elle Mouton * ErikEk