mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-01-18 21:35:24 +01:00
config: allow independent rpccookie config
The bitcoind .cookie contains an autogenerated user (__cookie__) and password (random string), which can be used instead of the rpc user name and password. This commit allows for running against bitcoind without having to access bitcoin.conf like in the case for pure user/password/zmq configuration.
This commit is contained in:
parent
7e225f6aa5
commit
d27c622568
61
config.go
61
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)
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user