Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/ten-protocol/go-ten into je…
Browse files Browse the repository at this point in the history
…nnifer/3248-bridge-develop-bridge-frontend
  • Loading branch information
Jennievon committed Aug 14, 2024
2 parents 1ec1146 + 76ad606 commit 86939a5
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 42 deletions.
1 change: 1 addition & 0 deletions integration/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
61 changes: 34 additions & 27 deletions integration/eth2network/main/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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 &ethConfig{
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),
}
}

Expand All @@ -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)

Expand All @@ -91,14 +97,15 @@ func parseCLIArgs() *ethConfig {
}

return &ethConfig{
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,
}
}
3 changes: 2 additions & 1 deletion integration/eth2network/main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ func main() {
config.gethWSStartPort,
config.gethHTTPStartPort,
config.prysmBeaconRPCStartPort,
config.prysmBeaconGatewayStartPort,
config.chainID,
6*time.Minute,
3*time.Minute,
config.prefundedAddrs...,
)

Expand Down
40 changes: 31 additions & 9 deletions integration/eth2network/pos_eth2_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"encoding/json"
"fmt"
"net/http"
"os"
"os/exec"
"path"
Expand Down Expand Up @@ -49,6 +50,7 @@ type PosImpl struct {
gethRPCPort int
gethHTTPPort int
beaconRPCPort int
beaconGatewayPort int
gethLogFile string
prysmBeaconLogFile string
prysmValidatorLogFile string
Expand All @@ -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()))
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand All @@ -176,27 +179,44 @@ 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")
}

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
}

// 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
}

// wait for beacon process to start
time.Sleep(5 * time.Second)
_, err = ethclient.Dial(fmt.Sprintf("http://127.0.0.1:%d", n.beaconGatewayPort))
if err != nil {
return err
}
time.Sleep(2 * time.Second)
number := uint64(0)
// 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
}
Expand All @@ -213,7 +233,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
}
Expand All @@ -238,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)
Expand All @@ -257,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,
Expand Down
3 changes: 2 additions & 1 deletion integration/eth2network/pos_eth2_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ func TestStartPosEth2Network(t *testing.T) {
_startPort+integration.DefaultGethWSPortOffset,
_startPort+integration.DefaultGethHTTPPortOffset,
_startPort+integration.DefaultPrysmRPCPortOffset,
_startPort+integration.DefaultPrysmGatewayPortOffset,
integration.EthereumChainID,
6*time.Minute,
3*time.Minute,
)

// wait until the merge has happened
Expand Down
3 changes: 3 additions & 0 deletions integration/eth2network/start-pos-network.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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="./"
Expand Down Expand Up @@ -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 ;;
Expand Down Expand Up @@ -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 \
Expand Down
1 change: 1 addition & 0 deletions integration/noderunner/noderunner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
7 changes: 4 additions & 3 deletions integration/simulation/network/geth_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,13 @@ 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,
6*time.Minute,
3*time.Minute,
walletAddresses...,
)

Expand Down
3 changes: 2 additions & 1 deletion integration/smartcontract/smartcontracts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit 86939a5

Please sign in to comment.