mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-08 23:18:15 -05:00
Refactor E2E port registration (#10306)
* Refactor e2e port registration * uncomment tests * explain calculation * fix things * change param to pointer * fix errors * unit test and constant
This commit is contained in:
@@ -117,14 +117,14 @@ func (node *BeaconNode) Start(ctx context.Context) error {
|
||||
fmt.Sprintf("--%s=%s/eth2-beacon-node-%d", cmdshared.DataDirFlag.Name, e2e.TestParams.TestPath, index),
|
||||
fmt.Sprintf("--%s=%s", cmdshared.LogFileName.Name, stdOutFile.Name()),
|
||||
fmt.Sprintf("--%s=%s", flags.DepositContractFlag.Name, e2e.TestParams.ContractAddress.Hex()),
|
||||
fmt.Sprintf("--%s=%d", flags.RPCPort.Name, e2e.TestParams.BeaconNodeRPCPort+index),
|
||||
fmt.Sprintf("--%s=http://127.0.0.1:%d", flags.HTTPWeb3ProviderFlag.Name, e2e.TestParams.Eth1RPCPort),
|
||||
fmt.Sprintf("--%s=%d", flags.RPCPort.Name, e2e.TestParams.Ports.PrysmBeaconNodeRPCPort+index),
|
||||
fmt.Sprintf("--%s=http://127.0.0.1:%d", flags.HTTPWeb3ProviderFlag.Name, e2e.TestParams.Ports.Eth1RPCPort),
|
||||
fmt.Sprintf("--%s=%d", flags.MinSyncPeers.Name, e2e.TestParams.BeaconNodeCount-1),
|
||||
fmt.Sprintf("--%s=%d", cmdshared.P2PUDPPort.Name, e2e.TestParams.BeaconNodeRPCPort+index+e2e.PrysmBeaconUDPOffset),
|
||||
fmt.Sprintf("--%s=%d", cmdshared.P2PTCPPort.Name, e2e.TestParams.BeaconNodeRPCPort+index+e2e.PrysmBeaconTCPOffset),
|
||||
fmt.Sprintf("--%s=%d", cmdshared.P2PUDPPort.Name, e2e.TestParams.Ports.PrysmBeaconNodeUDPPort+index),
|
||||
fmt.Sprintf("--%s=%d", cmdshared.P2PTCPPort.Name, e2e.TestParams.Ports.PrysmBeaconNodeTCPPort+index),
|
||||
fmt.Sprintf("--%s=%d", cmdshared.P2PMaxPeers.Name, expectedNumOfPeers),
|
||||
fmt.Sprintf("--%s=%d", flags.MonitoringPortFlag.Name, e2e.TestParams.BeaconNodeMetricsPort+index),
|
||||
fmt.Sprintf("--%s=%d", flags.GRPCGatewayPort.Name, e2e.TestParams.BeaconNodeRPCPort+index+e2e.PrysmBeaconGatewayOffset),
|
||||
fmt.Sprintf("--%s=%d", flags.MonitoringPortFlag.Name, e2e.TestParams.Ports.PrysmBeaconNodeMetricsPort+index),
|
||||
fmt.Sprintf("--%s=%d", flags.GRPCGatewayPort.Name, e2e.TestParams.Ports.PrysmBeaconNodeGatewayPort+index),
|
||||
fmt.Sprintf("--%s=%d", flags.ContractDeploymentBlock.Name, 0),
|
||||
fmt.Sprintf("--%s=%d", flags.MinPeersPerSubnet.Name, 0),
|
||||
fmt.Sprintf("--%s=%d", cmdshared.RPCMaxPageSizeFlag.Name, params.BeaconConfig().MinGenesisActiveValidatorCount),
|
||||
@@ -136,7 +136,7 @@ func (node *BeaconNode) Start(ctx context.Context) error {
|
||||
"--" + flags.EnableDebugRPCEndpoints.Name,
|
||||
}
|
||||
if config.UsePprof {
|
||||
args = append(args, "--pprof", fmt.Sprintf("--pprofport=%d", e2e.TestParams.BeaconNodeRPCPort+index+e2e.PrysmPprofOffset))
|
||||
args = append(args, "--pprof", fmt.Sprintf("--pprofport=%d", e2e.TestParams.Ports.PrysmBeaconNodePprofPort+index))
|
||||
}
|
||||
args = append(args, features.E2EBeaconChainFlags...)
|
||||
args = append(args, config.BeaconFlags...)
|
||||
|
||||
@@ -50,8 +50,8 @@ func (node *BootNode) Start(ctx context.Context) error {
|
||||
|
||||
args := []string{
|
||||
fmt.Sprintf("--log-file=%s", stdOutFile.Name()),
|
||||
fmt.Sprintf("--discv5-port=%d", e2e.TestParams.BootNodePort),
|
||||
fmt.Sprintf("--metrics-port=%d", e2e.TestParams.BootNodePort+e2e.BootnodeMetricsOffset),
|
||||
fmt.Sprintf("--discv5-port=%d", e2e.TestParams.Ports.BootNodePort),
|
||||
fmt.Sprintf("--metrics-port=%d", e2e.TestParams.Ports.BootNodeMetricsPort),
|
||||
"--debug",
|
||||
}
|
||||
|
||||
|
||||
@@ -67,8 +67,8 @@ func (node *Eth1Node) Start(ctx context.Context) error {
|
||||
|
||||
args := []string{
|
||||
fmt.Sprintf("--datadir=%s", eth1Path),
|
||||
fmt.Sprintf("--http.port=%d", e2e.TestParams.Eth1RPCPort),
|
||||
fmt.Sprintf("--ws.port=%d", e2e.TestParams.Eth1RPCPort+e2e.ETH1WSOffset),
|
||||
fmt.Sprintf("--http.port=%d", e2e.TestParams.Ports.Eth1RPCPort),
|
||||
fmt.Sprintf("--ws.port=%d", e2e.TestParams.Ports.Eth1WSPort),
|
||||
"--http",
|
||||
"--http.addr=127.0.0.1",
|
||||
"--http.corsdomain=\"*\"",
|
||||
@@ -97,7 +97,7 @@ func (node *Eth1Node) Start(ctx context.Context) error {
|
||||
}
|
||||
|
||||
// Connect to the started geth dev chain.
|
||||
client, err := rpc.DialHTTP(fmt.Sprintf("http://127.0.0.1:%d", e2e.TestParams.Eth1RPCPort))
|
||||
client, err := rpc.DialHTTP(fmt.Sprintf("http://127.0.0.1:%d", e2e.TestParams.Ports.Eth1RPCPort))
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to connect to ipc: %w", err)
|
||||
}
|
||||
|
||||
@@ -107,14 +107,14 @@ func (node *LighthouseBeaconNode) Start(ctx context.Context) error {
|
||||
fmt.Sprintf("--testnet-dir=%s", testDir),
|
||||
"--staking",
|
||||
"--enr-address=127.0.0.1",
|
||||
fmt.Sprintf("--enr-udp-port=%d", e2e.TestParams.BeaconNodeRPCPort+index+e2e.LighthouseP2PPortOffset),
|
||||
fmt.Sprintf("--enr-tcp-port=%d", e2e.TestParams.BeaconNodeRPCPort+index+e2e.LighthouseP2PPortOffset),
|
||||
fmt.Sprintf("--port=%d", e2e.TestParams.BeaconNodeRPCPort+index+e2e.LighthouseP2PPortOffset),
|
||||
fmt.Sprintf("--http-port=%d", e2e.TestParams.BeaconNodeRPCPort+index+e2e.LighthouseHTTPPortOffset),
|
||||
fmt.Sprintf("--enr-udp-port=%d", e2e.TestParams.Ports.LighthouseBeaconNodeP2PPort+index),
|
||||
fmt.Sprintf("--enr-tcp-port=%d", e2e.TestParams.Ports.LighthouseBeaconNodeP2PPort+index),
|
||||
fmt.Sprintf("--port=%d", e2e.TestParams.Ports.LighthouseBeaconNodeP2PPort+index),
|
||||
fmt.Sprintf("--http-port=%d", e2e.TestParams.Ports.LighthouseBeaconNodeHTTPPort+index),
|
||||
fmt.Sprintf("--target-peers=%d", 10),
|
||||
fmt.Sprintf("--eth1-endpoints=http://127.0.0.1:%d", e2e.TestParams.Eth1RPCPort),
|
||||
fmt.Sprintf("--eth1-endpoints=http://127.0.0.1:%d", e2e.TestParams.Ports.Eth1RPCPort),
|
||||
fmt.Sprintf("--boot-nodes=%s", node.enr),
|
||||
fmt.Sprintf("--metrics-port=%d", e2e.TestParams.BeaconNodeMetricsPort+index+e2e.LighthouseMetricsPortOffset),
|
||||
fmt.Sprintf("--metrics-port=%d", e2e.TestParams.Ports.LighthouseBeaconNodeMetricsPort+index),
|
||||
"--metrics",
|
||||
"--http",
|
||||
"--debug-level=debug",
|
||||
|
||||
@@ -103,19 +103,19 @@ func (v *LighthouseValidatorNode) Start(ctx context.Context) error {
|
||||
}
|
||||
|
||||
_, _, index, _ := v.config, v.validatorNum, v.index, v.offset
|
||||
beaconRPCPort := e2e.TestParams.BeaconNodeRPCPort + index
|
||||
if beaconRPCPort >= e2e.TestParams.BeaconNodeRPCPort+e2e.TestParams.BeaconNodeCount {
|
||||
beaconRPCPort := e2e.TestParams.Ports.PrysmBeaconNodeRPCPort + index
|
||||
if beaconRPCPort >= e2e.TestParams.Ports.PrysmBeaconNodeRPCPort+e2e.TestParams.BeaconNodeCount {
|
||||
// Point any extra validator clients to a node we know is running.
|
||||
beaconRPCPort = e2e.TestParams.BeaconNodeRPCPort
|
||||
beaconRPCPort = e2e.TestParams.Ports.PrysmBeaconNodeRPCPort
|
||||
}
|
||||
kPath := e2e.TestParams.TestPath + fmt.Sprintf("/lighthouse-validator-%d", index)
|
||||
testNetDir := e2e.TestParams.TestPath + fmt.Sprintf("/lighthouse-testnet-%d", index)
|
||||
httpOffset := e2e.LighthouseHTTPPortOffset
|
||||
httpPort := e2e.TestParams.Ports.LighthouseBeaconNodeHTTPPort
|
||||
// In the event we want to run a LH validator with a non LH
|
||||
// beacon node, we split half the validators to run with
|
||||
// lighthouse and the other half with prysm.
|
||||
if v.config.UseValidatorCrossClient && index%2 == 0 {
|
||||
httpOffset = e2e.PrysmBeaconGatewayOffset
|
||||
httpPort = e2e.TestParams.Ports.PrysmBeaconNodeGatewayPort
|
||||
}
|
||||
args := []string{
|
||||
"validator_client",
|
||||
@@ -123,7 +123,7 @@ func (v *LighthouseValidatorNode) Start(ctx context.Context) error {
|
||||
"--init-slashing-protection",
|
||||
fmt.Sprintf("--datadir=%s", kPath),
|
||||
fmt.Sprintf("--testnet-dir=%s", testNetDir),
|
||||
fmt.Sprintf("--beacon-nodes=http://localhost:%d", e2e.TestParams.BeaconNodeRPCPort+index+httpOffset),
|
||||
fmt.Sprintf("--beacon-nodes=http://localhost:%d", httpPort+index),
|
||||
}
|
||||
|
||||
cmd := exec.CommandContext(ctx, binaryPath, args...) // #nosec G204 -- Safe
|
||||
|
||||
@@ -118,10 +118,10 @@ func (v *ValidatorNode) Start(ctx context.Context) error {
|
||||
}
|
||||
|
||||
config, validatorNum, index, offset := v.config, v.validatorNum, v.index, v.offset
|
||||
beaconRPCPort := e2e.TestParams.BeaconNodeRPCPort + index
|
||||
if beaconRPCPort >= e2e.TestParams.BeaconNodeRPCPort+e2e.TestParams.BeaconNodeCount {
|
||||
beaconRPCPort := e2e.TestParams.Ports.PrysmBeaconNodeRPCPort + index
|
||||
if beaconRPCPort >= e2e.TestParams.Ports.PrysmBeaconNodeRPCPort+e2e.TestParams.BeaconNodeCount {
|
||||
// Point any extra validator clients to a node we know is running.
|
||||
beaconRPCPort = e2e.TestParams.BeaconNodeRPCPort
|
||||
beaconRPCPort = e2e.TestParams.Ports.PrysmBeaconNodeRPCPort
|
||||
}
|
||||
|
||||
file, err := helpers.DeleteAndCreateFile(e2e.TestParams.LogPath, fmt.Sprintf(e2e.ValidatorLogFileName, index))
|
||||
@@ -136,8 +136,8 @@ func (v *ValidatorNode) Start(ctx context.Context) error {
|
||||
fmt.Sprintf("--%s=%s/eth2-val-%d", cmdshared.DataDirFlag.Name, e2e.TestParams.TestPath, index),
|
||||
fmt.Sprintf("--%s=%s", cmdshared.LogFileName.Name, file.Name()),
|
||||
fmt.Sprintf("--%s=%s", flags.GraffitiFileFlag.Name, gFile),
|
||||
fmt.Sprintf("--%s=%d", flags.MonitoringPortFlag.Name, e2e.TestParams.ValidatorMetricsPort+index),
|
||||
fmt.Sprintf("--%s=%d", flags.GRPCGatewayPort.Name, e2e.TestParams.ValidatorGatewayPort+index),
|
||||
fmt.Sprintf("--%s=%d", flags.MonitoringPortFlag.Name, e2e.TestParams.Ports.ValidatorMetricsPort+index),
|
||||
fmt.Sprintf("--%s=%d", flags.GRPCGatewayPort.Name, e2e.TestParams.Ports.ValidatorGatewayPort+index),
|
||||
fmt.Sprintf("--%s=localhost:%d", flags.BeaconRPCProviderFlag.Name, beaconRPCPort),
|
||||
fmt.Sprintf("--%s=%s", flags.GrpcHeadersFlag.Name, "dummy=value,foo=bar"), // Sending random headers shouldn't break anything.
|
||||
fmt.Sprintf("--%s=%s", cmdshared.VerbosityFlag.Name, "debug"),
|
||||
@@ -215,7 +215,7 @@ func (v *ValidatorNode) Started() <-chan struct{} {
|
||||
|
||||
// SendAndMineDeposits sends the requested amount of deposits and mines the chain after to ensure the deposits are seen.
|
||||
func SendAndMineDeposits(keystorePath string, validatorNum, offset int, partial bool) error {
|
||||
client, err := rpc.DialHTTP(fmt.Sprintf("http://127.0.0.1:%d", e2e.TestParams.Eth1RPCPort))
|
||||
client, err := rpc.DialHTTP(fmt.Sprintf("http://127.0.0.1:%d", e2e.TestParams.Ports.Eth1RPCPort))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -344,7 +344,7 @@ func (r *testRunner) testBeaconChainSync(ctx context.Context, g *errgroup.Group,
|
||||
if err := helpers.ComponentsStarted(ctx, []e2etypes.ComponentRunner{syncBeaconNode}); err != nil {
|
||||
return fmt.Errorf("sync beacon node not ready: %w", err)
|
||||
}
|
||||
syncConn, err := grpc.Dial(fmt.Sprintf("127.0.0.1:%d", e2e.TestParams.BeaconNodeRPCPort+index), grpc.WithInsecure())
|
||||
syncConn, err := grpc.Dial(fmt.Sprintf("127.0.0.1:%d", e2e.TestParams.Ports.PrysmBeaconNodeRPCPort+index), grpc.WithInsecure())
|
||||
require.NoError(t, err, "Failed to dial")
|
||||
conns = append(conns, syncConn)
|
||||
|
||||
|
||||
@@ -456,7 +456,7 @@ func withCompareChainHead(beaconNodeIdx int, conn *grpc.ClientConn) error {
|
||||
}
|
||||
|
||||
func doGatewayJSONRequest(requestPath string, beaconNodeIdx int, dst interface{}) error {
|
||||
basePath := fmt.Sprintf(v1Alpha1GatewayPathTemplate, e2e.TestParams.BeaconNodeRPCPort+beaconNodeIdx+40)
|
||||
basePath := fmt.Sprintf(v1Alpha1GatewayPathTemplate, e2e.TestParams.Ports.PrysmBeaconNodeGatewayPort+beaconNodeIdx)
|
||||
httpResp, err := http.Get(
|
||||
basePath + requestPath,
|
||||
)
|
||||
|
||||
@@ -238,7 +238,7 @@ func withCompareAttesterDuties(beaconNodeIdx int, conn *grpc.ClientConn) error {
|
||||
}
|
||||
|
||||
func doMiddlewareJSONGetRequestV1(requestPath string, beaconNodeIdx int, dst interface{}) error {
|
||||
basePath := fmt.Sprintf(v1MiddlewarePathTemplate, params.TestParams.BeaconNodeRPCPort+beaconNodeIdx+40)
|
||||
basePath := fmt.Sprintf(v1MiddlewarePathTemplate, params.TestParams.Ports.PrysmBeaconNodeGatewayPort+beaconNodeIdx)
|
||||
httpResp, err := http.Get(
|
||||
basePath + requestPath,
|
||||
)
|
||||
@@ -253,7 +253,7 @@ func doMiddlewareJSONPostRequestV1(requestPath string, beaconNodeIdx int, postDa
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
basePath := fmt.Sprintf(v1MiddlewarePathTemplate, params.TestParams.BeaconNodeRPCPort+beaconNodeIdx+40)
|
||||
basePath := fmt.Sprintf(v1MiddlewarePathTemplate, params.TestParams.Ports.PrysmBeaconNodeGatewayPort+beaconNodeIdx)
|
||||
httpResp, err := http.Post(
|
||||
basePath+requestPath,
|
||||
"application/json",
|
||||
|
||||
@@ -95,7 +95,7 @@ func metricsTest(conns ...*grpc.ClientConn) error {
|
||||
return err
|
||||
}
|
||||
for i := 0; i < len(conns); i++ {
|
||||
response, err := http.Get(fmt.Sprintf("http://localhost:%d/metrics", e2e.TestParams.BeaconNodeMetricsPort+i))
|
||||
response, err := http.Get(fmt.Sprintf("http://localhost:%d/metrics", e2e.TestParams.Ports.PrysmBeaconNodeMetricsPort+i))
|
||||
if err != nil {
|
||||
// Continue if the connection fails, regular flake.
|
||||
continue
|
||||
|
||||
@@ -55,7 +55,7 @@ var AllNodesHaveSameHead = e2etypes.Evaluator{
|
||||
func healthzCheck(conns ...*grpc.ClientConn) error {
|
||||
count := len(conns)
|
||||
for i := 0; i < count; i++ {
|
||||
resp, err := http.Get(fmt.Sprintf("http://localhost:%d/healthz", e2e.TestParams.BeaconNodeMetricsPort+i))
|
||||
resp, err := http.Get(fmt.Sprintf("http://localhost:%d/healthz", e2e.TestParams.Ports.PrysmBeaconNodeMetricsPort+i))
|
||||
if err != nil {
|
||||
// Continue if the connection fails, regular flake.
|
||||
continue
|
||||
@@ -74,7 +74,7 @@ func healthzCheck(conns ...*grpc.ClientConn) error {
|
||||
}
|
||||
|
||||
for i := 0; i < count; i++ {
|
||||
resp, err := http.Get(fmt.Sprintf("http://localhost:%d/healthz", e2e.TestParams.ValidatorMetricsPort+i))
|
||||
resp, err := http.Get(fmt.Sprintf("http://localhost:%d/healthz", e2e.TestParams.Ports.ValidatorMetricsPort+i))
|
||||
if err != nil {
|
||||
// Continue if the connection fails, regular flake.
|
||||
continue
|
||||
|
||||
@@ -201,12 +201,12 @@ func LogErrorOutput(t *testing.T, file io.Reader, title string, index int) {
|
||||
|
||||
// WritePprofFiles writes the memory heap and cpu profile files to the test path.
|
||||
func WritePprofFiles(testDir string, index int) error {
|
||||
url := fmt.Sprintf("http://127.0.0.1:%d/debug/pprof/heap", e2e.TestParams.BeaconNodeRPCPort+50+index)
|
||||
url := fmt.Sprintf("http://127.0.0.1:%d/debug/pprof/heap", e2e.TestParams.Ports.PrysmBeaconNodePprofPort+index)
|
||||
filePath := filepath.Join(testDir, fmt.Sprintf(memoryHeapFileName, index))
|
||||
if err := writeURLRespAtPath(url, filePath); err != nil {
|
||||
return err
|
||||
}
|
||||
url = fmt.Sprintf("http://127.0.0.1:%d/debug/pprof/profile", e2e.TestParams.BeaconNodeRPCPort+50+index)
|
||||
url = fmt.Sprintf("http://127.0.0.1:%d/debug/pprof/profile", e2e.TestParams.Ports.PrysmBeaconNodePprofPort+index)
|
||||
filePath = filepath.Join(testDir, fmt.Sprintf(cpuProfileFileName, index))
|
||||
return writeURLRespAtPath(url, filePath)
|
||||
}
|
||||
@@ -255,7 +255,7 @@ func NewLocalConnection(ctx context.Context, port int) (*grpc.ClientConn, error)
|
||||
func NewLocalConnections(ctx context.Context, numConns int) ([]*grpc.ClientConn, func(), error) {
|
||||
conns := make([]*grpc.ClientConn, numConns)
|
||||
for i := 0; i < len(conns); i++ {
|
||||
conn, err := NewLocalConnection(ctx, e2e.TestParams.BeaconNodeRPCPort+i)
|
||||
conn, err := NewLocalConnection(ctx, e2e.TestParams.Ports.PrysmBeaconNodeRPCPort+i)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
load("@prysm//tools/go:def.bzl", "go_library")
|
||||
load("@prysm//tools/go:def.bzl", "go_library", "go_test")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
@@ -11,3 +11,13 @@ go_library(
|
||||
"@io_bazel_rules_go//go/tools/bazel:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = ["params_test.go"],
|
||||
embed = [":go_default_library"],
|
||||
deps = [
|
||||
"//testing/assert:go_default_library",
|
||||
"//testing/require:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -20,13 +20,26 @@ type params struct {
|
||||
TestShardIndex int
|
||||
BeaconNodeCount int
|
||||
LighthouseBeaconNodeCount int
|
||||
Eth1RPCPort int
|
||||
ContractAddress common.Address
|
||||
BootNodePort int
|
||||
BeaconNodeRPCPort int
|
||||
BeaconNodeMetricsPort int
|
||||
ValidatorMetricsPort int
|
||||
ValidatorGatewayPort int
|
||||
Ports *ports
|
||||
}
|
||||
|
||||
type ports struct {
|
||||
BootNodePort int
|
||||
BootNodeMetricsPort int
|
||||
Eth1RPCPort int
|
||||
Eth1WSPort int
|
||||
PrysmBeaconNodeRPCPort int
|
||||
PrysmBeaconNodeUDPPort int
|
||||
PrysmBeaconNodeTCPPort int
|
||||
PrysmBeaconNodeGatewayPort int
|
||||
PrysmBeaconNodeMetricsPort int
|
||||
PrysmBeaconNodePprofPort int
|
||||
LighthouseBeaconNodeP2PPort int
|
||||
LighthouseBeaconNodeHTTPPort int
|
||||
LighthouseBeaconNodeMetricsPort int
|
||||
ValidatorMetricsPort int
|
||||
ValidatorGatewayPort int
|
||||
}
|
||||
|
||||
// TestParams is the globally accessible var for getting config elements.
|
||||
@@ -53,20 +66,29 @@ var StandardLighthouseNodeCount = 2
|
||||
// DepositCount is the amount of deposits E2E makes on a separate validator client.
|
||||
var DepositCount = uint64(64)
|
||||
|
||||
// Values that are used by both the beacon node and validator clients
|
||||
// to assign the relevant ports to.
|
||||
// Base port values.
|
||||
const (
|
||||
BootnodeMetricsOffset = 20
|
||||
ETH1WSOffset = 1
|
||||
portSpan = 50
|
||||
|
||||
PrysmBeaconUDPOffset = 10
|
||||
PrysmBeaconTCPOffset = 20
|
||||
PrysmBeaconGatewayOffset = 40
|
||||
PrysmPprofOffset = 50
|
||||
BootNodePort = 2150
|
||||
BootNodeMetricsPort = BootNodePort + portSpan
|
||||
|
||||
LighthouseP2PPortOffset = 200
|
||||
LighthouseHTTPPortOffset = 250
|
||||
LighthouseMetricsPortOffset = 300
|
||||
Eth1RPCPort = 3150
|
||||
Eth1WSPort = Eth1RPCPort + portSpan
|
||||
|
||||
PrysmBeaconNodeRPCPort = 4150
|
||||
PrysmBeaconNodeUDPPort = PrysmBeaconNodeRPCPort + portSpan
|
||||
PrysmBeaconNodeTCPPort = PrysmBeaconNodeRPCPort + 2*portSpan
|
||||
PrysmBeaconNodeGatewayPort = PrysmBeaconNodeRPCPort + 3*portSpan
|
||||
PrysmBeaconNodeMetricsPort = PrysmBeaconNodeRPCPort + 4*portSpan
|
||||
PrysmBeaconNodePprofPort = PrysmBeaconNodeRPCPort + 5*portSpan
|
||||
|
||||
LighthouseBeaconNodeP2PPort = 5150
|
||||
LighthouseBeaconNodeHTTPPort = LighthouseBeaconNodeP2PPort + portSpan
|
||||
LighthouseBeaconNodeMetricsPort = LighthouseBeaconNodeP2PPort + 2*portSpan
|
||||
|
||||
ValidatorGatewayPort = 6150
|
||||
ValidatorMetricsPort = ValidatorGatewayPort + portSpan
|
||||
)
|
||||
|
||||
// Init initializes the E2E config, properly handling test sharding.
|
||||
@@ -76,27 +98,93 @@ func Init(beaconNodeCount int) error {
|
||||
if !ok {
|
||||
return errors.New("expected TEST_UNDECLARED_OUTPUTS_DIR to be defined")
|
||||
}
|
||||
testIndexStr, ok := os.LookupEnv("TEST_SHARD_INDEX")
|
||||
testTotalShardsStr, ok := os.LookupEnv("TEST_TOTAL_SHARDS")
|
||||
if !ok {
|
||||
testIndexStr = "0"
|
||||
testTotalShardsStr = "1"
|
||||
}
|
||||
testIndex, err := strconv.Atoi(testIndexStr)
|
||||
testTotalShards, err := strconv.Atoi(testTotalShardsStr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
testPath = filepath.Join(testPath, fmt.Sprintf("shard-%d", testIndex))
|
||||
testShardIndexStr, ok := os.LookupEnv("TEST_SHARD_INDEX")
|
||||
if !ok {
|
||||
testShardIndexStr = "0"
|
||||
}
|
||||
testShardIndex, err := strconv.Atoi(testShardIndexStr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var existingRegistrations []int
|
||||
bootnodePort, err := port(BootNodePort, testTotalShards, testShardIndex, &existingRegistrations)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
bootnodeMetricsPort, err := port(BootNodeMetricsPort, testTotalShards, testShardIndex, &existingRegistrations)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
eth1RPCPort, err := port(Eth1RPCPort, testTotalShards, testShardIndex, &existingRegistrations)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
eth1WSPort, err := port(Eth1WSPort, testTotalShards, testShardIndex, &existingRegistrations)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
beaconNodeRPCPort, err := port(PrysmBeaconNodeRPCPort, testTotalShards, testShardIndex, &existingRegistrations)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
beaconNodeUDPPort, err := port(PrysmBeaconNodeUDPPort, testTotalShards, testShardIndex, &existingRegistrations)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
beaconNodeTCPPort, err := port(PrysmBeaconNodeTCPPort, testTotalShards, testShardIndex, &existingRegistrations)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
beaconNodeGatewayPort, err := port(PrysmBeaconNodeGatewayPort, testTotalShards, testShardIndex, &existingRegistrations)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
beaconNodeMetricsPort, err := port(PrysmBeaconNodeMetricsPort, testTotalShards, testShardIndex, &existingRegistrations)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
beaconNodePprofPort, err := port(PrysmBeaconNodePprofPort, testTotalShards, testShardIndex, &existingRegistrations)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
validatorGatewayPort, err := port(ValidatorGatewayPort, testTotalShards, testShardIndex, &existingRegistrations)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
validatorMetricsPort, err := port(ValidatorMetricsPort, testTotalShards, testShardIndex, &existingRegistrations)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
testPorts := &ports{
|
||||
BootNodePort: bootnodePort,
|
||||
BootNodeMetricsPort: bootnodeMetricsPort,
|
||||
Eth1RPCPort: eth1RPCPort,
|
||||
Eth1WSPort: eth1WSPort,
|
||||
PrysmBeaconNodeRPCPort: beaconNodeRPCPort,
|
||||
PrysmBeaconNodeUDPPort: beaconNodeUDPPort,
|
||||
PrysmBeaconNodeTCPPort: beaconNodeTCPPort,
|
||||
PrysmBeaconNodeGatewayPort: beaconNodeGatewayPort,
|
||||
PrysmBeaconNodeMetricsPort: beaconNodeMetricsPort,
|
||||
PrysmBeaconNodePprofPort: beaconNodePprofPort,
|
||||
ValidatorMetricsPort: validatorMetricsPort,
|
||||
ValidatorGatewayPort: validatorGatewayPort,
|
||||
}
|
||||
|
||||
TestParams = ¶ms{
|
||||
TestPath: testPath,
|
||||
LogPath: logPath,
|
||||
TestShardIndex: testIndex,
|
||||
BeaconNodeCount: beaconNodeCount,
|
||||
Eth1RPCPort: 3100 + testIndex*100, // Multiplying 100 here so the test index doesn't conflict with the other node ports.
|
||||
BootNodePort: 4100 + testIndex*100,
|
||||
BeaconNodeRPCPort: 4150 + testIndex*100,
|
||||
BeaconNodeMetricsPort: 5100 + testIndex*100,
|
||||
ValidatorMetricsPort: 6100 + testIndex*100,
|
||||
ValidatorGatewayPort: 7150 + testIndex*100,
|
||||
TestPath: filepath.Join(testPath, fmt.Sprintf("shard-%d", testShardIndex)),
|
||||
LogPath: logPath,
|
||||
TestShardIndex: testShardIndex,
|
||||
BeaconNodeCount: beaconNodeCount,
|
||||
Ports: testPorts,
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -108,28 +196,126 @@ func InitMultiClient(beaconNodeCount int, lighthouseNodeCount int) error {
|
||||
if !ok {
|
||||
return errors.New("expected TEST_UNDECLARED_OUTPUTS_DIR to be defined")
|
||||
}
|
||||
testIndexStr, ok := os.LookupEnv("TEST_SHARD_INDEX")
|
||||
testTotalShardsStr, ok := os.LookupEnv("TEST_TOTAL_SHARDS")
|
||||
if !ok {
|
||||
testIndexStr = "0"
|
||||
testTotalShardsStr = "1"
|
||||
}
|
||||
testIndex, err := strconv.Atoi(testIndexStr)
|
||||
testTotalShards, err := strconv.Atoi(testTotalShardsStr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
testPath = filepath.Join(testPath, fmt.Sprintf("shard-%d", testIndex))
|
||||
testShardIndexStr, ok := os.LookupEnv("TEST_SHARD_INDEX")
|
||||
if !ok {
|
||||
testShardIndexStr = "0"
|
||||
}
|
||||
testShardIndex, err := strconv.Atoi(testShardIndexStr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var existingRegistrations []int
|
||||
bootnodePort, err := port(BootNodePort, testTotalShards, testShardIndex, &existingRegistrations)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
bootnodeMetricsPort, err := port(BootNodeMetricsPort, testTotalShards, testShardIndex, &existingRegistrations)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
eth1RPCPort, err := port(Eth1RPCPort, testTotalShards, testShardIndex, &existingRegistrations)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
eth1WSPort, err := port(Eth1WSPort, testTotalShards, testShardIndex, &existingRegistrations)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
prysmBeaconNodeRPCPort, err := port(PrysmBeaconNodeRPCPort, testTotalShards, testShardIndex, &existingRegistrations)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
prysmBeaconNodeUDPPort, err := port(PrysmBeaconNodeUDPPort, testTotalShards, testShardIndex, &existingRegistrations)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
prysmBeaconNodeTCPPort, err := port(PrysmBeaconNodeTCPPort, testTotalShards, testShardIndex, &existingRegistrations)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
prysmBeaconNodeGatewayPort, err := port(PrysmBeaconNodeGatewayPort, testTotalShards, testShardIndex, &existingRegistrations)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
prysmBeaconNodeMetricsPort, err := port(PrysmBeaconNodeMetricsPort, testTotalShards, testShardIndex, &existingRegistrations)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
prysmBeaconNodePprofPort, err := port(PrysmBeaconNodePprofPort, testTotalShards, testShardIndex, &existingRegistrations)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
lighthouseBeaconNodeP2PPort, err := port(LighthouseBeaconNodeP2PPort, testTotalShards, testShardIndex, &existingRegistrations)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
lighthouseBeaconNodeHTTPPort, err := port(LighthouseBeaconNodeHTTPPort, testTotalShards, testShardIndex, &existingRegistrations)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
lighthouseBeaconNodeMetricsPort, err := port(LighthouseBeaconNodeMetricsPort, testTotalShards, testShardIndex, &existingRegistrations)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
validatorGatewayPort, err := port(ValidatorGatewayPort, testTotalShards, testShardIndex, &existingRegistrations)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
validatorMetricsPort, err := port(ValidatorMetricsPort, testTotalShards, testShardIndex, &existingRegistrations)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
testPorts := &ports{
|
||||
BootNodePort: bootnodePort,
|
||||
BootNodeMetricsPort: bootnodeMetricsPort,
|
||||
Eth1RPCPort: eth1RPCPort,
|
||||
Eth1WSPort: eth1WSPort,
|
||||
PrysmBeaconNodeRPCPort: prysmBeaconNodeRPCPort,
|
||||
PrysmBeaconNodeUDPPort: prysmBeaconNodeUDPPort,
|
||||
PrysmBeaconNodeTCPPort: prysmBeaconNodeTCPPort,
|
||||
PrysmBeaconNodeGatewayPort: prysmBeaconNodeGatewayPort,
|
||||
PrysmBeaconNodeMetricsPort: prysmBeaconNodeMetricsPort,
|
||||
PrysmBeaconNodePprofPort: prysmBeaconNodePprofPort,
|
||||
LighthouseBeaconNodeP2PPort: lighthouseBeaconNodeP2PPort,
|
||||
LighthouseBeaconNodeHTTPPort: lighthouseBeaconNodeHTTPPort,
|
||||
LighthouseBeaconNodeMetricsPort: lighthouseBeaconNodeMetricsPort,
|
||||
ValidatorMetricsPort: validatorMetricsPort,
|
||||
ValidatorGatewayPort: validatorGatewayPort,
|
||||
}
|
||||
|
||||
TestParams = ¶ms{
|
||||
TestPath: testPath,
|
||||
TestPath: filepath.Join(testPath, fmt.Sprintf("shard-%d", testShardIndex)),
|
||||
LogPath: logPath,
|
||||
TestShardIndex: testIndex,
|
||||
TestShardIndex: testShardIndex,
|
||||
BeaconNodeCount: beaconNodeCount,
|
||||
LighthouseBeaconNodeCount: lighthouseNodeCount,
|
||||
Eth1RPCPort: 3100 + testIndex*100, // Multiplying 100 here so the test index doesn't conflict with the other node ports.
|
||||
BootNodePort: 4100 + testIndex*100,
|
||||
BeaconNodeRPCPort: 4150 + testIndex*100,
|
||||
BeaconNodeMetricsPort: 5100 + testIndex*100,
|
||||
ValidatorMetricsPort: 6100 + testIndex*100,
|
||||
ValidatorGatewayPort: 7150 + testIndex*100,
|
||||
Ports: testPorts,
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// port returns a safe port number based on the seed and shard data.
|
||||
func port(seed, shardCount, shardIndex int, existingRegistrations *[]int) (int, error) {
|
||||
portToRegister := seed + portSpan/shardCount*shardIndex
|
||||
for _, p := range *existingRegistrations {
|
||||
if portToRegister >= p && portToRegister <= p+(portSpan/shardCount)-1 {
|
||||
return 0, fmt.Errorf("port %d overlaps with already registered port %d", seed, p)
|
||||
}
|
||||
}
|
||||
*existingRegistrations = append(*existingRegistrations, portToRegister)
|
||||
|
||||
// Calculation example: 3 shards, seed 2000, port span 50.
|
||||
// Shard 0: 2000 + (50 / 3 * 0) = 2000 (we can safely use ports 2000-2015)
|
||||
// Shard 1: 2000 + (50 / 3 * 1) = 2016 (we can safely use ports 2016-2031)
|
||||
// Shard 2: 2000 + (50 / 3 * 2) = 2032 (we can safely use ports 2032-2047, and in reality 2032-2049)
|
||||
return portToRegister, nil
|
||||
}
|
||||
|
||||
27
testing/endtoend/params/params_test.go
Normal file
27
testing/endtoend/params/params_test.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package params
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/testing/assert"
|
||||
"github.com/prysmaticlabs/prysm/testing/require"
|
||||
)
|
||||
|
||||
func Test_port(t *testing.T) {
|
||||
var existingRegistrations []int
|
||||
|
||||
p, err := port(2000, 3, 0, &existingRegistrations)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 2000, p)
|
||||
p, err = port(2000, 3, 1, &existingRegistrations)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 2016, p)
|
||||
p, err = port(2000, 3, 2, &existingRegistrations)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 2032, p)
|
||||
_, err = port(2000, 3, 2, &existingRegistrations)
|
||||
assert.NotNil(t, err)
|
||||
// We pass the last unavailable port
|
||||
_, err = port(2047, 3, 0, &existingRegistrations)
|
||||
assert.NotNil(t, err)
|
||||
}
|
||||
Reference in New Issue
Block a user