config+test: use default port for RPC server if one isn't specified

This commit alters the configuration parsing a bit along with the
documentation to expect the RPCHost configuration paramter to also have
the target port specified. If the port isn’t included, then the default
btcd RPC port for that chain is used.

Additionally, within the integration testing framework, when creating
the lnd nodes, we now use the configuration from the btcd harness to
set the proper RPC host.
This commit is contained in:
Olaoluwa Osuntokun 2017-01-05 13:15:58 -08:00
parent 8fe5c09e21
commit ad76899a57
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2
3 changed files with 12 additions and 8 deletions

View File

@ -63,7 +63,7 @@ type config struct {
PeerPort int `long:"peerport" description:"The port to listen on for incoming p2p connections"` PeerPort int `long:"peerport" description:"The port to listen on for incoming p2p connections"`
RPCPort int `long:"rpcport" description:"The port for the rpc server"` RPCPort int `long:"rpcport" description:"The port for the rpc server"`
SPVMode bool `long:"spv" description:"assert to enter spv wallet mode"` SPVMode bool `long:"spv" description:"assert to enter spv wallet mode"`
RPCHost string `long:"btcdhost" description:"The btcd rpc listening address."` RPCHost string `long:"btcdhost" description:"The btcd rpc listening address. If a port is omitted, then the default port for the selected chain parameters will be used."`
RPCUser string `short:"u" long:"rpcuser" description:"Username for RPC connections"` RPCUser string `short:"u" long:"rpcuser" description:"Username for RPC connections"`
RPCPass string `short:"P" long:"rpcpass" default-mask:"-" description:"Password for RPC connections"` RPCPass string `short:"P" long:"rpcpass" default-mask:"-" description:"Password for RPC connections"`

16
lnd.go
View File

@ -11,6 +11,7 @@ import (
"path/filepath" "path/filepath"
"runtime" "runtime"
"strconv" "strconv"
"strings"
"golang.org/x/net/context" "golang.org/x/net/context"
@ -90,13 +91,16 @@ func lndMain() error {
} }
} }
rpcIP, err := net.LookupHost(cfg.RPCHost) // If the specified host for the btcd RPC server already has a port
if err != nil { // specified, then we use that directly. Otherwise, we assume the
fmt.Printf("unable to resolve rpc host: %v", err) // default port according to the selected chain parameters.
return err var btcdHost string
if strings.Contains(cfg.RPCHost, ":") {
btcdHost = cfg.RPCHost
} else {
btcdHost = fmt.Sprintf("%v:%v", cfg.RPCHost, activeNetParams.rpcPort)
} }
btcdHost := fmt.Sprintf("%v:%v", cfg.RPCHost, activeNetParams.rpcPort)
btcdUser := cfg.RPCUser btcdUser := cfg.RPCUser
btcdPass := cfg.RPCPass btcdPass := cfg.RPCPass
@ -120,7 +124,7 @@ func lndMain() error {
walletConfig := &btcwallet.Config{ walletConfig := &btcwallet.Config{
PrivatePass: []byte("hello"), PrivatePass: []byte("hello"),
DataDir: filepath.Join(cfg.DataDir, "lnwallet"), DataDir: filepath.Join(cfg.DataDir, "lnwallet"),
RpcHost: fmt.Sprintf("%v:%v", rpcIP[0], activeNetParams.rpcPort), RpcHost: btcdHost,
RpcUser: cfg.RPCUser, RpcUser: cfg.RPCUser,
RpcPass: cfg.RPCPass, RpcPass: cfg.RPCPass,
CACert: rpcCert, CACert: rpcCert,

View File

@ -106,7 +106,7 @@ func newLightningNode(rpcConfig *btcrpcclient.ConnConfig, lndArgs []string) (*li
var err error var err error
cfg := &config{ cfg := &config{
RPCHost: "127.0.0.1", RPCHost: rpcConfig.Host,
RPCUser: rpcConfig.User, RPCUser: rpcConfig.User,
RPCPass: rpcConfig.Pass, RPCPass: rpcConfig.Pass,
} }