lntest/node: make ProfilePort part of node config

This commit is contained in:
Johan T. Halseth committed 2019-07-11 14:36:59 +02:00
1 parent 93aad89f4c
commit 6028722d71
1 file changed
+33 -29
+33 -29
View File
@@ -33,35 +33,34 @@ import (
macaroon "gopkg.in/macaroon.v2" macaroon "gopkg.in/macaroon.v2"
) )
var ( const (
// numActiveNodes is the number of active nodes within the test network.
numActiveNodes = 0
// defaultNodePort is the initial p2p port which will be used by the // defaultNodePort is the initial p2p port which will be used by the
// first created lightning node to listen on for incoming p2p // first created lightning node to listen on for incoming p2p
// connections. Subsequent allocated ports for future Lightning nodes // connections. Subsequent allocated ports for future Lightning nodes
// instances will be monotonically increasing numbers calculated as // instances will be monotonically increasing numbers calculated as
// such: defaultP2pPort + (3 * harness.nodeNum). // such: defaultP2pPort + (4 * harness.nodeNum).
defaultNodePort = 19555 defaultNodePort = 19555
// defaultClientPort is the initial rpc port which will be used by the // defaultClientPort is the initial rpc port which will be used by the
// first created lightning node to listen on for incoming rpc // first created lightning node to listen on for incoming rpc
// connections. Subsequent allocated ports for future rpc harness // connections. Subsequent allocated ports for future rpc harness
// instances will be monotonically increasing numbers calculated // instances will be monotonically increasing numbers calculated
// as such: defaultP2pPort + (3 * harness.nodeNum). // as such: defaultP2pPort + (4 * harness.nodeNum).
defaultClientPort = 19556 defaultClientPort = defaultNodePort + 1
// defaultRestPort is the initial rest port which will be used by the // defaultRestPort is the initial rest port which will be used by the
// first created lightning node to listen on for incoming rest // first created lightning node to listen on for incoming rest
// connections. Subsequent allocated ports for future rpc harness // connections. Subsequent allocated ports for future rpc harness
// instances will be monotonically increasing numbers calculated // instances will be monotonically increasing numbers calculated
// as such: defaultP2pPort + (3 * harness.nodeNum). // as such: defaultP2pPort + (4 * harness.nodeNum).
defaultRestPort = 19557 defaultRestPort = defaultNodePort + 2
// logOutput is a flag that can be set to append the output from the // defaultProfilePort is the initial port which will be used for
// seed nodes to log files. // profiling by the first created lightning node. Subsequent allocated
logOutput = flag.Bool("logoutput", false, // ports for future rpc harness instances will be monotonically
"log output from node n to file outputn.log") // increasing numbers calculated as such:
// defaultProfilePort + (4 * harness.nodeNum).
defaultProfilePort = defaultNodePort + 3
// logPubKeyBytes is the number of bytes of the node's PubKey that // logPubKeyBytes is the number of bytes of the node's PubKey that
// will be appended to the log file name. The whole PubKey is too // will be appended to the log file name. The whole PubKey is too
@@ -74,24 +73,28 @@ var (
trickleDelay = 50 trickleDelay = 50
) )
var (
// numActiveNodes is the number of active nodes within the test network.
numActiveNodes = 0
// logOutput is a flag that can be set to append the output from the
// seed nodes to log files.
logOutput = flag.Bool("logoutput", false,
"log output from node n to file outputn.log")
)
// generateListeningPorts returns three ints representing ports to listen on // generateListeningPorts returns three ints representing ports to listen on
// designated for the current lightning network test. If there haven't been any // designated for the current lightning network test. If there haven't been any
// test instances created, the default ports are used. Otherwise, in order to // test instances created, the default ports are used. Otherwise, in order to
// support multiple test nodes running at once, the p2p, rpc, and rest ports // support multiple test nodes running at once, the p2p, rpc, rest and
// are incremented after each initialization. // profiling ports are incremented after each initialization.
func generateListeningPorts() (int, int, int) { func generateListeningPorts() (int, int, int, int) {
var p2p, rpc, rest int p2p := defaultNodePort + (4 * numActiveNodes)
if numActiveNodes == 0 { rpc := defaultClientPort + (4 * numActiveNodes)
p2p = defaultNodePort rest := defaultRestPort + (4 * numActiveNodes)
rpc = defaultClientPort profile := defaultProfilePort + (4 * numActiveNodes)
rest = defaultRestPort
} else {
p2p = defaultNodePort + (3 * numActiveNodes)
rpc = defaultClientPort + (3 * numActiveNodes)
rest = defaultRestPort + (3 * numActiveNodes)
}
return p2p, rpc, rest return p2p, rpc, rest, profile
} }
// BackendConfig is an interface that abstracts away the specific chain backend // BackendConfig is an interface that abstracts away the specific chain backend
@@ -132,6 +135,7 @@ type nodeConfig struct {
P2PPort int P2PPort int
RPCPort int RPCPort int
RESTPort int RESTPort int
ProfilePort int
} }
func (cfg nodeConfig) P2PAddr() string { func (cfg nodeConfig) P2PAddr() string {
@@ -195,6 +199,7 @@ func (cfg nodeConfig) genArgs() []string {
args = append(args, fmt.Sprintf("--readonlymacaroonpath=%v", cfg.ReadMacPath)) args = append(args, fmt.Sprintf("--readonlymacaroonpath=%v", cfg.ReadMacPath))
args = append(args, fmt.Sprintf("--invoicemacaroonpath=%v", cfg.InvoiceMacPath)) args = append(args, fmt.Sprintf("--invoicemacaroonpath=%v", cfg.InvoiceMacPath))
args = append(args, fmt.Sprintf("--trickledelay=%v", trickleDelay)) args = append(args, fmt.Sprintf("--trickledelay=%v", trickleDelay))
args = append(args, fmt.Sprintf("--profile=%d", cfg.ProfilePort))
if !cfg.HasSeed { if !cfg.HasSeed {
args = append(args, "--noseedbackup") args = append(args, "--noseedbackup")
@@ -280,7 +285,7 @@ func newNode(cfg nodeConfig) (*HarnessNode, error) {
cfg.ReadMacPath = filepath.Join(cfg.DataDir, "readonly.macaroon") cfg.ReadMacPath = filepath.Join(cfg.DataDir, "readonly.macaroon")
cfg.InvoiceMacPath = filepath.Join(cfg.DataDir, "invoice.macaroon") cfg.InvoiceMacPath = filepath.Join(cfg.DataDir, "invoice.macaroon")
cfg.P2PPort, cfg.RPCPort, cfg.RESTPort = generateListeningPorts() cfg.P2PPort, cfg.RPCPort, cfg.RESTPort, cfg.ProfilePort = generateListeningPorts()
nodeNum := numActiveNodes nodeNum := numActiveNodes
numActiveNodes++ numActiveNodes++
@@ -333,7 +338,6 @@ func (hn *HarnessNode) start(lndError chan<- error) error {
hn.quit = make(chan struct{}) hn.quit = make(chan struct{})
args := hn.cfg.genArgs() args := hn.cfg.genArgs()
args = append(args, fmt.Sprintf("--profile=%d", 9000+hn.NodeID))
hn.cmd = exec.Command("../../lnd-itest", args...) hn.cmd = exec.Command("../../lnd-itest", args...)
// Redirect stderr output to buffer // Redirect stderr output to buffer