From dbd6b94438df22c21be1bffdd1b04c549a07ffa0 Mon Sep 17 00:00:00 2001 From: Will Hester Date: Wed, 14 Aug 2024 09:04:56 +0100 Subject: [PATCH 1/2] reduce timeouts from 6min and add beacon health check --- integration/eth2network/main/main.go | 2 +- integration/eth2network/pos_eth2_network.go | 21 +++++++++++++------ .../eth2network/pos_eth2_network_test.go | 2 +- integration/simulation/network/geth_utils.go | 2 +- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/integration/eth2network/main/main.go b/integration/eth2network/main/main.go index bc00d23230..28ee2a9189 100644 --- a/integration/eth2network/main/main.go +++ b/integration/eth2network/main/main.go @@ -30,7 +30,7 @@ func main() { config.gethHTTPStartPort, config.prysmBeaconRPCStartPort, config.chainID, - 6*time.Minute, + 3*time.Minute, config.prefundedAddrs..., ) diff --git a/integration/eth2network/pos_eth2_network.go b/integration/eth2network/pos_eth2_network.go index fb65cab6d3..795df723a7 100644 --- a/integration/eth2network/pos_eth2_network.go +++ b/integration/eth2network/pos_eth2_network.go @@ -176,27 +176,36 @@ func (n *PosImpl) Stop() error { } func (n *PosImpl) checkExistingNetworks() error { - port := n.gethWSPort - _, err := ethclient.Dial(fmt.Sprintf("ws://127.0.0.1:%d", port)) + _, err := ethclient.Dial(fmt.Sprintf("ws://127.0.0.1:%d", n.gethWSPort)) if err == nil { return fmt.Errorf("unexpected geth node is active before the network is started") } + + _, err = ethclient.Dial(fmt.Sprintf("ws://127.0.0.1:%d", n.beaconP2PPort)) + if err == nil { + return fmt.Errorf("unexpected beacon node is active before the network is started") + } return nil } // waitForMergeEvent connects to the geth node and waits until block 2 (the merge block) is reached func (n *PosImpl) waitForMergeEvent(startTime time.Time) error { ctx := context.Background() - dial, err := ethclient.Dial(fmt.Sprintf("http://127.0.0.1:%d", n.gethHTTPPort)) + gethDial, err := ethclient.Dial(fmt.Sprintf("http://127.0.0.1:%d", n.gethHTTPPort)) if err != nil { return err } - time.Sleep(2 * time.Second) + // wait for beacon process to start + time.Sleep(10 * time.Second) number := uint64(0) + _, err = ethclient.Dial(fmt.Sprintf("http://127.0.0.1:%d", n.beaconP2PPort)) + if err != nil { + return err + } // wait for the merge block err = retry.Do( func() error { - number, err = dial.BlockNumber(ctx) + number, err = gethDial.BlockNumber(ctx) if err != nil { return err } @@ -213,7 +222,7 @@ func (n *PosImpl) waitForMergeEvent(startTime time.Time) error { fmt.Printf("Reached the merge block after %s\n", time.Since(startTime)) - if err = n.prefundedBalanceActive(dial); err != nil { + if err = n.prefundedBalanceActive(gethDial); err != nil { fmt.Printf("Error prefunding account %s\n", err.Error()) return err } diff --git a/integration/eth2network/pos_eth2_network_test.go b/integration/eth2network/pos_eth2_network_test.go index 7fb90bf3bb..bf835fcd77 100644 --- a/integration/eth2network/pos_eth2_network_test.go +++ b/integration/eth2network/pos_eth2_network_test.go @@ -49,7 +49,7 @@ func TestStartPosEth2Network(t *testing.T) { _startPort+integration.DefaultGethHTTPPortOffset, _startPort+integration.DefaultPrysmRPCPortOffset, integration.EthereumChainID, - 6*time.Minute, + 3*time.Minute, ) // wait until the merge has happened diff --git a/integration/simulation/network/geth_utils.go b/integration/simulation/network/geth_utils.go index bd0a247286..d6b8d56334 100644 --- a/integration/simulation/network/geth_utils.go +++ b/integration/simulation/network/geth_utils.go @@ -69,7 +69,7 @@ func StartGethNetwork(wallets *params.SimWallets, startPort int) (eth2network.Po startPort+integration.DefaultGethHTTPPortOffset, startPort+integration.DefaultPrysmRPCPortOffset, // RPC integration.EthereumChainID, - 6*time.Minute, + 3*time.Minute, walletAddresses..., ) From 61ad3835faedf8a3da611a92d3fe5b2b002082fa Mon Sep 17 00:00:00 2001 From: Will Hester Date: Wed, 14 Aug 2024 09:49:36 +0100 Subject: [PATCH 2/2] add gateway port to network script for checking connections --- integration/constants.go | 1 + integration/eth2network/main/cli.go | 61 +++++++++++-------- integration/eth2network/main/main.go | 1 + integration/eth2network/pos_eth2_network.go | 27 +++++--- .../eth2network/pos_eth2_network_test.go | 1 + integration/eth2network/start-pos-network.sh | 3 + integration/noderunner/noderunner_test.go | 1 + integration/simulation/network/geth_utils.go | 5 +- .../smartcontract/smartcontracts_test.go | 3 +- 9 files changed, 66 insertions(+), 37 deletions(-) diff --git a/integration/constants.go b/integration/constants.go index 386599e773..5b85cac7d4 100644 --- a/integration/constants.go +++ b/integration/constants.go @@ -24,6 +24,7 @@ const ( DefaultGethHTTPPortOffset = 400 DefaultPrysmP2PPortOffset = 500 DefaultPrysmRPCPortOffset = 550 + DefaultPrysmGatewayPortOffset = 560 DefaultHostP2pOffset = 600 // The default offset for the host P2p DefaultEnclaveOffset = 700 // The default offset between a Geth nodes port and the enclave ports. Used in Socket Simulations. DefaultHostRPCHTTPOffset = 800 // The default offset for the host's RPC HTTP port diff --git a/integration/eth2network/main/cli.go b/integration/eth2network/main/cli.go index 1f854d8736..26b04c36d9 100644 --- a/integration/eth2network/main/cli.go +++ b/integration/eth2network/main/cli.go @@ -27,6 +27,9 @@ const ( prysmBeaconRPCStartPortName = "prysmBeaconRPCStartPort" prysmBeaconRPCStartPortUsage = "The initial port to start allocating prysm rpc port" + prysmBeaconGatewayStartPortName = "prysmBeaconGatewayStartPort" + prysmBeaconGatewayStartPortUsage = "The gateway port to connect to prysm" + prysmBeaconP2PStartPortName = "prysmBeaconP2PtartPort" prysmBeaconP2PStartPortUsage = "The p2p udp prysm port" @@ -38,28 +41,30 @@ const ( ) type ethConfig struct { - chainID int - gethHTTPStartPort int - gethWSStartPort int - gethAuthRPCStartPort int - gethNetworkStartPort int - prysmBeaconRPCStartPort int - prysmBeaconP2PStartPort int - logLevel int - prefundedAddrs []string + chainID int + gethHTTPStartPort int + gethWSStartPort int + gethAuthRPCStartPort int + gethNetworkStartPort int + prysmBeaconRPCStartPort int + prysmBeaconP2PStartPort int + prysmBeaconGatewayStartPort int + logLevel int + prefundedAddrs []string } func defaultConfig() *ethConfig { return ðConfig{ - chainID: 1337, - gethHTTPStartPort: 12000, - gethWSStartPort: 12100, - gethAuthRPCStartPort: 12200, - gethNetworkStartPort: 12300, - prysmBeaconRPCStartPort: 12400, - prysmBeaconP2PStartPort: 12500, - prefundedAddrs: []string{}, - logLevel: int(gethlog.LvlDebug), + chainID: 1337, + gethHTTPStartPort: 12000, + gethWSStartPort: 12100, + gethAuthRPCStartPort: 12200, + gethNetworkStartPort: 12300, + prysmBeaconRPCStartPort: 12400, + prysmBeaconP2PStartPort: 12500, + prysmBeaconGatewayStartPort: 12600, + prefundedAddrs: []string{}, + logLevel: int(gethlog.LvlDebug), } } @@ -73,6 +78,7 @@ func parseCLIArgs() *ethConfig { gethNetworkStartPort := flag.Int(gethNetworkStartPortName, defaultConfig.gethNetworkStartPort, gethNetworkStartPortUsage) prysmBeaconP2PStartPort := flag.Int(prysmBeaconP2PStartPortName, defaultConfig.prysmBeaconP2PStartPort, prysmBeaconP2PStartPortUsage) prysmBeaconRPCStartPort := flag.Int(prysmBeaconRPCStartPortName, defaultConfig.prysmBeaconRPCStartPort, prysmBeaconRPCStartPortUsage) + prysmBeaconGatewayStartPort := flag.Int(prysmBeaconGatewayStartPortName, defaultConfig.prysmBeaconGatewayStartPort, prysmBeaconGatewayStartPortUsage) logLevel := flag.Int(logLevelName, defaultConfig.logLevel, logLevelUsage) prefundedAddrs := flag.String(prefundedAddrsName, "", prefundedAddrsUsage) @@ -91,14 +97,15 @@ func parseCLIArgs() *ethConfig { } return ðConfig{ - chainID: *chainID, - gethHTTPStartPort: *gethHTTPPort, - gethWSStartPort: *gethWSPort, - gethAuthRPCStartPort: *gethAuthRPCStartPort, - gethNetworkStartPort: *gethNetworkStartPort, - prysmBeaconRPCStartPort: *prysmBeaconRPCStartPort, - prysmBeaconP2PStartPort: *prysmBeaconP2PStartPort, - logLevel: *logLevel, - prefundedAddrs: parsedPrefundedAddrs, + chainID: *chainID, + gethHTTPStartPort: *gethHTTPPort, + gethWSStartPort: *gethWSPort, + gethAuthRPCStartPort: *gethAuthRPCStartPort, + gethNetworkStartPort: *gethNetworkStartPort, + prysmBeaconRPCStartPort: *prysmBeaconRPCStartPort, + prysmBeaconP2PStartPort: *prysmBeaconP2PStartPort, + prysmBeaconGatewayStartPort: *prysmBeaconGatewayStartPort, + logLevel: *logLevel, + prefundedAddrs: parsedPrefundedAddrs, } } diff --git a/integration/eth2network/main/main.go b/integration/eth2network/main/main.go index 28ee2a9189..3152b0b23f 100644 --- a/integration/eth2network/main/main.go +++ b/integration/eth2network/main/main.go @@ -29,6 +29,7 @@ func main() { config.gethWSStartPort, config.gethHTTPStartPort, config.prysmBeaconRPCStartPort, + config.prysmBeaconGatewayStartPort, config.chainID, 3*time.Minute, config.prefundedAddrs..., diff --git a/integration/eth2network/pos_eth2_network.go b/integration/eth2network/pos_eth2_network.go index 795df723a7..b2625e905b 100644 --- a/integration/eth2network/pos_eth2_network.go +++ b/integration/eth2network/pos_eth2_network.go @@ -5,6 +5,7 @@ import ( "context" "encoding/json" "fmt" + "net/http" "os" "os/exec" "path" @@ -49,6 +50,7 @@ type PosImpl struct { gethRPCPort int gethHTTPPort int beaconRPCPort int + beaconGatewayPort int gethLogFile string prysmBeaconLogFile string prysmValidatorLogFile string @@ -69,7 +71,7 @@ type PosEth2Network interface { GenesisBytes() []byte } -func NewPosEth2Network(binDir string, gethNetworkPort, beaconP2PPort, gethRPCPort, gethWSPort, gethHTTPPort, beaconRPCPort, chainID int, timeout time.Duration, walletsToFund ...string) PosEth2Network { +func NewPosEth2Network(binDir string, gethNetworkPort, beaconP2PPort, gethRPCPort, gethWSPort, gethHTTPPort, beaconRPCPort, beaconGatewayPort, chainID int, timeout time.Duration, walletsToFund ...string) PosEth2Network { build, err := getBuildNumber() if err != nil { panic(fmt.Sprintf("could not get build number: %s", err.Error())) @@ -129,6 +131,7 @@ func NewPosEth2Network(binDir string, gethNetworkPort, beaconP2PPort, gethRPCPor gethRPCPort: gethRPCPort, gethHTTPPort: gethHTTPPort, beaconRPCPort: beaconRPCPort, + beaconGatewayPort: beaconGatewayPort, gethBinaryPath: gethBinaryPath, prysmBinaryPath: prysmBinaryPath, prysmBeaconBinaryPath: prysmBeaconBinaryPath, @@ -155,7 +158,7 @@ func (n *PosImpl) Start() error { err := eg.Wait() go func() { n.gethProcessID, n.beaconProcessID, n.validatorProcessID, err = startNetworkScript(n.gethNetworkPort, n.beaconP2PPort, - n.gethRPCPort, n.gethHTTPPort, n.gethWSPort, n.beaconRPCPort, n.chainID, n.buildDir, n.prysmBeaconLogFile, + n.gethRPCPort, n.gethHTTPPort, n.gethWSPort, n.beaconRPCPort, n.beaconGatewayPort, n.chainID, n.buildDir, n.prysmBeaconLogFile, n.prysmValidatorLogFile, n.gethLogFile, n.prysmBeaconBinaryPath, n.prysmBinaryPath, n.prysmValidatorBinaryPath, n.gethBinaryPath, n.gethdataDir, n.beacondataDir, n.validatordataDir) time.Sleep(time.Second) @@ -181,8 +184,15 @@ func (n *PosImpl) checkExistingNetworks() error { return fmt.Errorf("unexpected geth node is active before the network is started") } - _, err = ethclient.Dial(fmt.Sprintf("ws://127.0.0.1:%d", n.beaconP2PPort)) + client := http.Client{ + Timeout: 2 * time.Second, + } + + url := fmt.Sprintf("http://127.0.0.1:%d", n.beaconGatewayPort) + + resp, err := client.Get(url) if err == nil { + defer resp.Body.Close() return fmt.Errorf("unexpected beacon node is active before the network is started") } return nil @@ -195,13 +205,14 @@ func (n *PosImpl) waitForMergeEvent(startTime time.Time) error { if err != nil { return err } + // wait for beacon process to start - time.Sleep(10 * time.Second) - number := uint64(0) - _, err = ethclient.Dial(fmt.Sprintf("http://127.0.0.1:%d", n.beaconP2PPort)) + time.Sleep(5 * time.Second) + _, err = ethclient.Dial(fmt.Sprintf("http://127.0.0.1:%d", n.beaconGatewayPort)) if err != nil { return err } + number := uint64(0) // wait for the merge block err = retry.Do( func() error { @@ -247,13 +258,14 @@ func (n *PosImpl) GenesisBytes() []byte { return n.gethGenesisBytes } -func startNetworkScript(gethNetworkPort, beaconP2PPort, gethRPCPort, gethHTTPPort, gethWSPort, beaconRPCPort, chainID int, buildDir, beaconLogFile, validatorLogFile, gethLogFile, +func startNetworkScript(gethNetworkPort, beaconP2PPort, gethRPCPort, gethHTTPPort, gethWSPort, beaconRPCPort, beaconGatewayPort, chainID int, buildDir, beaconLogFile, validatorLogFile, gethLogFile, beaconBinary, prysmBinary, validatorBinary, gethBinary, gethdataDir, beacondataDir, validatordataDir string, ) (int, int, int, error) { startScript := filepath.Join(basepath, "start-pos-network.sh") gethNetworkPortStr := strconv.Itoa(gethNetworkPort) beaconP2PPortStr := strconv.Itoa(beaconP2PPort) beaconRPCPortStr := strconv.Itoa(beaconRPCPort) + beaconGatewayPortStr := strconv.Itoa(beaconGatewayPort) gethHTTPPortStr := strconv.Itoa(gethHTTPPort) gethWSPortStr := strconv.Itoa(gethWSPort) gethRPCPortStr := strconv.Itoa(gethRPCPort) @@ -266,6 +278,7 @@ func startNetworkScript(gethNetworkPort, beaconP2PPort, gethRPCPort, gethHTTPPor "--geth-ws", gethWSPortStr, "--geth-rpc", gethRPCPortStr, "--beacon-rpc", beaconRPCPortStr, + "--grpc-gateway-port", beaconGatewayPortStr, "--chainid", chainStr, "--build-dir", buildDir, "--base-path", basepath, diff --git a/integration/eth2network/pos_eth2_network_test.go b/integration/eth2network/pos_eth2_network_test.go index bf835fcd77..37af521a4b 100644 --- a/integration/eth2network/pos_eth2_network_test.go +++ b/integration/eth2network/pos_eth2_network_test.go @@ -48,6 +48,7 @@ func TestStartPosEth2Network(t *testing.T) { _startPort+integration.DefaultGethWSPortOffset, _startPort+integration.DefaultGethHTTPPortOffset, _startPort+integration.DefaultPrysmRPCPortOffset, + _startPort+integration.DefaultPrysmGatewayPortOffset, integration.EthereumChainID, 3*time.Minute, ) diff --git a/integration/eth2network/start-pos-network.sh b/integration/eth2network/start-pos-network.sh index 96e7558d46..65293c122a 100755 --- a/integration/eth2network/start-pos-network.sh +++ b/integration/eth2network/start-pos-network.sh @@ -7,6 +7,7 @@ GETH_HTTP_PORT=8025 GETH_WS_PORT=9000 GETH_RPC_PORT=8552 BEACON_RPC_PORT=4000 +BEACON_GATEWAY_PORT=3500 CHAIN_ID=1337 BUILD_DIR="./build" BASE_PATH="./" @@ -50,6 +51,7 @@ while [[ "$#" -gt 0 ]]; do --geth-network) GETH_NETWORK_PORT="$2"; shift ;; --beacon-p2p) BEACON_P2P_PORT="$2"; shift ;; --beacon-rpc) BEACON_RPC_PORT="$2"; shift ;; + --grpc-gateway-port) BEACON_GATEWAY_PORT="$2"; shift ;; --geth-http) GETH_HTTP_PORT="$2"; shift ;; --geth-ws) GETH_WS_PORT="$2"; shift ;; --geth-rpc) GETH_RPC_PORT="$2"; shift ;; @@ -106,6 +108,7 @@ ${BEACON_BINARY} --datadir="${BEACONDATA_DIR}" \ --rpc-host=127.0.0.1 \ --rpc-port="${BEACON_RPC_PORT}" \ --p2p-udp-port="${BEACON_P2P_PORT}" \ + --grpc-gateway-port=${BEACON_GATEWAY_PORT} \ --accept-terms-of-use \ --jwt-secret "${BASE_PATH}/jwt.hex" \ --suggested-fee-recipient 0x123463a4B065722E99115D6c222f267d9cABb524 \ diff --git a/integration/noderunner/noderunner_test.go b/integration/noderunner/noderunner_test.go index ff25cf8434..1fe18cb1c2 100644 --- a/integration/noderunner/noderunner_test.go +++ b/integration/noderunner/noderunner_test.go @@ -48,6 +48,7 @@ func TestCanStartStandaloneTenHostAndEnclave(t *testing.T) { _startPort+integration.DefaultGethWSPortOffset, _startPort+integration.DefaultGethHTTPPortOffset, _startPort+integration.DefaultPrysmRPCPortOffset, + _startPort+integration.DefaultPrysmGatewayPortOffset, integration.EthereumChainID, 3*time.Minute, ) diff --git a/integration/simulation/network/geth_utils.go b/integration/simulation/network/geth_utils.go index d6b8d56334..855252483c 100644 --- a/integration/simulation/network/geth_utils.go +++ b/integration/simulation/network/geth_utils.go @@ -64,10 +64,11 @@ func StartGethNetwork(wallets *params.SimWallets, startPort int) (eth2network.Po binDir, startPort+integration.DefaultGethNetworkPortOffset, startPort+integration.DefaultPrysmP2PPortOffset, - startPort+integration.DefaultGethAUTHPortOffset, // RPC + startPort+integration.DefaultGethAUTHPortOffset, startPort+integration.DefaultGethWSPortOffset, startPort+integration.DefaultGethHTTPPortOffset, - startPort+integration.DefaultPrysmRPCPortOffset, // RPC + startPort+integration.DefaultPrysmRPCPortOffset, + startPort+integration.DefaultPrysmGatewayPortOffset, integration.EthereumChainID, 3*time.Minute, walletAddresses..., diff --git a/integration/smartcontract/smartcontracts_test.go b/integration/smartcontract/smartcontracts_test.go index 062e063607..8cc404993c 100644 --- a/integration/smartcontract/smartcontracts_test.go +++ b/integration/smartcontract/smartcontracts_test.go @@ -62,7 +62,8 @@ func runGethNetwork(t *testing.T) *netInfo { _startPort+integration.DefaultGethAUTHPortOffset, // RPC _startPort+integration.DefaultGethWSPortOffset, _startPort+integration.DefaultGethHTTPPortOffset, - _startPort+integration.DefaultPrysmRPCPortOffset, // RPC + _startPort+integration.DefaultPrysmRPCPortOffset, + _startPort+integration.DefaultPrysmGatewayPortOffset, integration.EthereumChainID, 3*time.Minute, workerWallet.Address().String(),