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

View File

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