Merge pull request #6064 from dongcarl/2021-12-admin-cli-args

config: Add bitcoind.{config,rpccookie} configuration options
This commit is contained in:
Olaoluwa Osuntokun 2022-04-21 16:52:45 -07:00 committed by GitHub
commit 9572b49922
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 45 additions and 14 deletions

View File

@ -1723,7 +1723,7 @@ func parseRPCParams(cConfig *lncfg.Chain, nodeConfig interface{},
// First, we'll check our node config to make sure the RPC parameters
// were set correctly. We'll also determine the path to the conf file
// depending on the backend node.
var daemonName, confDir, confFile string
var daemonName, confDir, confFile, confFileBase string
switch conf := nodeConfig.(type) {
case *lncfg.Btcd:
// If both RPCUser and RPCPass are set, we assume those
@ -1737,11 +1737,11 @@ func parseRPCParams(cConfig *lncfg.Chain, nodeConfig interface{},
case chainreg.BitcoinChain:
daemonName = "btcd"
confDir = conf.Dir
confFile = "btcd"
confFileBase = "btcd"
case chainreg.LitecoinChain:
daemonName = "ltcd"
confDir = conf.Dir
confFile = "ltcd"
confFileBase = "ltcd"
}
// If only ONE of RPCUser or RPCPass is set, we assume the
@ -1784,11 +1784,13 @@ func parseRPCParams(cConfig *lncfg.Chain, nodeConfig interface{},
case chainreg.BitcoinChain:
daemonName = "bitcoind"
confDir = conf.Dir
confFile = "bitcoin"
confFile = conf.ConfigPath
confFileBase = "bitcoin"
case chainreg.LitecoinChain:
daemonName = "litecoind"
confDir = conf.Dir
confFile = "litecoin"
confFile = conf.ConfigPath
confFileBase = "litecoin"
}
// If not all of the parameters are set, we'll assume the user
@ -1813,7 +1815,10 @@ func parseRPCParams(cConfig *lncfg.Chain, nodeConfig interface{},
fmt.Println("Attempting automatic RPC configuration to " + daemonName)
confFile = filepath.Join(confDir, fmt.Sprintf("%v.conf", confFile))
if confFile == "" {
confFile = filepath.Join(confDir, fmt.Sprintf("%v.conf",
confFileBase))
}
switch cConfig.Node {
case "btcd", "ltcd":
nConf := nodeConfig.(*lncfg.Btcd)
@ -1827,7 +1832,8 @@ func parseRPCParams(cConfig *lncfg.Chain, nodeConfig interface{},
case "bitcoind", "litecoind":
nConf := nodeConfig.(*lncfg.Bitcoind)
rpcUser, rpcPass, zmqBlockHost, zmqTxHost, err :=
extractBitcoindRPCParams(netParams.Params.Name, confFile)
extractBitcoindRPCParams(netParams.Params.Name,
nConf.Dir, confFile, nConf.RPCCookie)
if err != nil {
return fmt.Errorf("unable to extract RPC credentials: "+
"%v, cannot start w/o RPC connection", err)
@ -1887,12 +1893,11 @@ func extractBtcdRPCParams(btcdConfigPath string) (string, string, error) {
}
// extractBitcoindRPCParams attempts to extract the RPC credentials for an
// existing bitcoind node instance. The passed path is expected to be the
// location of bitcoind's bitcoin.conf on the target system. The routine looks
// for a cookie first, optionally following the datadir configuration option in
// the bitcoin.conf. If it doesn't find one, it looks for rpcuser/rpcpassword.
func extractBitcoindRPCParams(networkName string,
bitcoindConfigPath string) (string, string, string, string, error) {
// existing bitcoind node instance. The routine looks for a cookie first,
// optionally following the datadir configuration option in the bitcoin.conf. If
// it doesn't find one, it looks for rpcuser/rpcpassword.
func extractBitcoindRPCParams(networkName, bitcoindDataDir, bitcoindConfigPath,
rpcCookiePath string) (string, string, string, string, error) {
// First, we'll open up the bitcoind configuration file found at the
// target destination.
@ -1940,6 +1945,9 @@ func extractBitcoindRPCParams(networkName string,
// Next, we'll try to find an auth cookie. We need to detect the chain
// by seeing if one is specified in the configuration file.
dataDir := filepath.Dir(bitcoindConfigPath)
if bitcoindDataDir != "" {
dataDir = bitcoindDataDir
}
dataDirRE, err := regexp.Compile(`(?m)^\s*datadir\s*=\s*([^\s]+)`)
if err != nil {
return "", "", "", "", err
@ -1959,7 +1967,11 @@ func extractBitcoindRPCParams(networkName string,
return "", "", "", "", fmt.Errorf("unexpected networkname %v", networkName)
}
cookie, err := ioutil.ReadFile(filepath.Join(dataDir, chainDir, ".cookie"))
cookiePath := filepath.Join(dataDir, chainDir, ".cookie")
if rpcCookiePath != "" {
cookiePath = rpcCookiePath
}
cookie, err := ioutil.ReadFile(cookiePath)
if err == nil {
splitCookie := strings.Split(string(cookie), ":")
if len(splitCookie) == 2 {

View File

@ -189,6 +189,10 @@ then watch it on chain. Taproot script spends are also supported through the
* [Add a new method in `tlv` to encode an uint64/uint32 field using `BigSize`
format.](https://github.com/lightningnetwork/lnd/pull/6421)
* [Add new `bitcoind.config` and `bitcoind.rpccookie`
options](https://github.com/lightningnetwork/lnd/pull/6064) to allow
specifying non-default paths for the configuration and RPC cookie files.
## RPC Server
* [Add value to the field
@ -287,6 +291,7 @@ gRPC performance metrics (latency to process `GetInfo`, etc)](https://github.com
* bitromortac
* Bjarne Magnussen
* BTCparadigm
* Carl Dong
* Carla Kirk-Cohen
* Carsten Otto
* Dan Bolser

View File

@ -4,6 +4,8 @@ package lncfg
// bitcoind.
type Bitcoind struct {
Dir string `long:"dir" description:"The base directory that contains the node's data, logs, configuration file, etc."`
ConfigPath string `long:"config" description:"Configuration filepath. If not set, will default to the default filename under 'dir'."`
RPCCookie string `long:"rpccookie" description:"Authentication cookie file for RPC connections. If not set, will default to .cookie under 'dir'."`
RPCHost string `long:"rpchost" description:"The daemon's rpc listening address. If a port is omitted, then the default port for the selected chain parameters will be used."`
RPCUser string `long:"rpcuser" description:"Username for RPC connections"`
RPCPass string `long:"rpcpass" default-mask:"-" description:"Password for RPC connections"`

View File

@ -578,6 +578,12 @@ bitcoin.node=btcd
; etc.
; bitcoind.dir=~/.bitcoin
; Configuration filepath.
; bitcoind.config=~/.bitcoin/bitcoin.conf
; Authentication cookie file for RPC connections.
; bitcoind.rpccookie=~/.bitcoin/.cookie
; The host that your local bitcoind daemon is listening on. By default, this
; setting is assumed to be localhost with the default port for the current
; network.
@ -779,6 +785,12 @@ litecoin.node=ltcd
; etc.
; litecoind.dir=~/.litecoin
; Configuration filepath.
; litecoind.config=~/.litecoin/litecoin.conf
; Authentication cookie file for RPC connections.
; litecoind.rpccookie=~/.litecoin/.cookie
; The host that your local litecoind daemon is listening on. By default, this
; setting is assumed to be localhost with the default port for the current
; network.