Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix geth network on PR build #2052

Merged
merged 16 commits into from
Sep 11, 2024
7 changes: 4 additions & 3 deletions .github/workflows/build-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ jobs:
# Close specified ports using lsof before testing / local port list compiled from ./integration/constants.go
- name: Close Integration Test Ports
run: |
killall -9 geth || true
killall -9 beacon || true
killall -9 validator || true
pkill -9 geth || true
pkill -9 beacon-chain || true
pkill -9 validator || true

lowest_port=8000 # Lowest starting port
highest_port=58000 # Highest port considering the offset
Expand Down Expand Up @@ -77,6 +77,7 @@ jobs:
integration/.build/noderunner/noderunner-*.txt
integration/.build/wallet_extension/wal-ext-*.txt
integration/.build/eth2/*
!integration/.build/eth2/**/geth.ipc
integration/.build/faucet/*
integration/.build/tenscan/*
integration/.build/tengateway/*
Expand Down
68 changes: 51 additions & 17 deletions integration/constants.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,8 @@
package integration

// Tracks the start ports handed out to different tests, in a bid to minimise conflicts.
// Note: the max should not exceed 30000 because the OS can use those ports and we'll get conflicts
const (
StartPortEth2NetworkTests = 10000
StartPortTenscanUnitTest = 11000
StartPortNodeRunnerTest = 12000
StartPortSimulationGethInMem = 14000
StartPortSimulationInMem = 15000
StartPortSimulationFullNetwork = 16000
DoNotUse = 17000 // port conflict on this address
StartPortSmartContractTests = 18000
StartPortContractDeployerTest1 = 19000
StartPortContractDeployerTest2 = 21000
StartPortFaucetUnitTest = 22000
StartPortFaucetHTTPUnitTest = 23000
StartPortTenGatewayUnitTest = 24000
StartPortNetworkTests = 25000
import "reflect"

const (
DefaultGethWSPortOffset = 100
DefaultGethAUTHPortOffset = 200
DefaultGethNetworkPortOffset = 300
Expand All @@ -43,3 +28,52 @@ const (
GethNodeAddress = "0x123463a4b065722e99115d6c222f267d9cabb524"
GethNodePK = "2e0834786285daccd064ca17f1654f67b4aef298acbb82cef9ec422fb4975622"
)

type Ports struct {
TestStartPosEth2NetworkPort int
TestTenscanPort int
TestCanStartStandaloneTenHostAndEnclavePort int
TestGethSimulationPort int
TestInMemoryMonteCarloSimulationPort int
TestFullNetworkMonteCarloSimulationPort int
DoNotUSePort int
TestManagementContractPort int
TestCanDeployLayer2ERC20ContractPort int
TestFaucetSendsFundsOnlyIfNeededPort int
TestFaucetPort int
TestFaucetHTTPPort int
TestTenGatewayPort int
NetworkTestsPort int
}

var TestPorts = Ports{
TestStartPosEth2NetworkPort: 10000,
TestTenscanPort: 11000,
TestCanStartStandaloneTenHostAndEnclavePort: 12000,
TestGethSimulationPort: 14000,
TestInMemoryMonteCarloSimulationPort: 15000,
TestFullNetworkMonteCarloSimulationPort: 16000,
DoNotUSePort: 17000,
TestManagementContractPort: 18000,
TestCanDeployLayer2ERC20ContractPort: 19000,
TestFaucetSendsFundsOnlyIfNeededPort: 21000,
TestFaucetPort: 22000,
TestFaucetHTTPPort: 23000,
TestTenGatewayPort: 24000,
NetworkTestsPort: 25000,
}

// GetTestName looks up the test name from the port number using reflection
func GetTestName(port int) string {
port = port - DefaultGethNetworkPortOffset
val := reflect.ValueOf(TestPorts)
typ := reflect.TypeOf(TestPorts)

for i := 0; i < val.NumField(); i++ {
fieldValue, ok := val.Field(i).Interface().(int)
if ok && fieldValue == port {
return typ.Field(i).Name
}
}
return "UnknownTest"
}
4 changes: 2 additions & 2 deletions integration/contractdeployer/contract_deployer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func init() { //nolint:gochecknoinits
}

func TestCanDeployLayer2ERC20Contract(t *testing.T) {
startPort := integration.StartPortContractDeployerTest1
startPort := integration.TestPorts.TestCanDeployLayer2ERC20ContractPort
hostWSPort := startPort + integration.DefaultHostRPCWSOffset
creatTenNetwork(t, startPort)
// This sleep is required to ensure the initial rollup exists, and thus contract deployer can check its balance.
Expand Down Expand Up @@ -81,7 +81,7 @@ func TestCanDeployLayer2ERC20Contract(t *testing.T) {
}

func TestFaucetSendsFundsOnlyIfNeeded(t *testing.T) {
startPort := integration.StartPortContractDeployerTest2
startPort := integration.TestPorts.TestFaucetSendsFundsOnlyIfNeededPort
hostWSPort := startPort + integration.DefaultHostRPCWSOffset
creatTenNetwork(t, startPort)

Expand Down
2 changes: 1 addition & 1 deletion integration/eth2network/build_number.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func getBuildNumber() (int, error) {
break
}
buildNumber++
if buildNumber > 9999 {
if buildNumber > 99 {
buildNumber = 1
}
}
Expand Down
10 changes: 8 additions & 2 deletions integration/eth2network/pos_eth2_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type PosImpl struct {
gethLogFile string
prysmBeaconLogFile string
prysmValidatorLogFile string
testNameLogFile string
gethdataDir string
beacondataDir string
validatordataDir string
Expand Down Expand Up @@ -98,9 +99,12 @@ func NewPosEth2Network(binDir string, gethNetworkPort, beaconP2PPort, gethRPCPor
panic(err)
}

testName := integration.GetTestName(gethNetworkPort)

gethLogFile := path.Join(buildDir, "geth.log")
prysmBeaconLogFile := path.Join(buildDir, "beacon-chain.log")
prysmValidatorLogFile := path.Join(buildDir, "validator.log")
testNameLogFile := path.Join(buildDir, fmt.Sprintf("%s.log", testName))

gethdataDir := path.Join(buildDir, "/gethdata")
beacondataDir := path.Join(buildDir, "/beacondata")
Expand Down Expand Up @@ -139,6 +143,7 @@ func NewPosEth2Network(binDir string, gethNetworkPort, beaconP2PPort, gethRPCPor
gethLogFile: gethLogFile,
prysmBeaconLogFile: prysmBeaconLogFile,
prysmValidatorLogFile: prysmValidatorLogFile,
testNameLogFile: testNameLogFile,
gethdataDir: gethdataDir,
beacondataDir: beacondataDir,
validatordataDir: validatordataDir,
Expand All @@ -159,7 +164,7 @@ func (n *PosImpl) Start() error {
go func() {
n.gethProcessID, n.beaconProcessID, n.validatorProcessID, err = startNetworkScript(n.gethNetworkPort, n.beaconP2PPort,
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.prysmValidatorLogFile, n.gethLogFile, n.testNameLogFile, n.prysmBeaconBinaryPath, n.prysmBinaryPath, n.prysmValidatorBinaryPath,
n.gethBinaryPath, n.gethdataDir, n.beacondataDir, n.validatordataDir)
time.Sleep(time.Second)
}()
Expand Down Expand Up @@ -258,7 +263,7 @@ func (n *PosImpl) GenesisBytes() []byte {
return n.gethGenesisBytes
}

func startNetworkScript(gethNetworkPort, beaconP2PPort, gethRPCPort, gethHTTPPort, gethWSPort, beaconRPCPort, beaconGatewayPort, chainID int, buildDir, beaconLogFile, validatorLogFile, gethLogFile,
func startNetworkScript(gethNetworkPort, beaconP2PPort, gethRPCPort, gethHTTPPort, gethWSPort, beaconRPCPort, beaconGatewayPort, chainID int, buildDir, beaconLogFile, validatorLogFile, gethLogFile, testLogFile,
beaconBinary, prysmBinary, validatorBinary, gethBinary, gethdataDir, beacondataDir, validatordataDir string,
) (int, int, int, error) {
startScript := filepath.Join(basepath, "start-pos-network.sh")
Expand Down Expand Up @@ -292,6 +297,7 @@ func startNetworkScript(gethNetworkPort, beaconP2PPort, gethRPCPort, gethHTTPPor
"--gethdata-dir", gethdataDir,
"--beacondata-dir", beacondataDir,
"--validatordata-dir", validatordataDir,
"--test-log", testLogFile,
)
fmt.Println(cmd.String())

Expand Down
37 changes: 17 additions & 20 deletions integration/eth2network/pos_eth2_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ import (
gethlog "github.com/ethereum/go-ethereum/log"
)

const (
_startPort = integration.StartPortEth2NetworkTests
)

func TestEnsureBinariesAreAvail(t *testing.T) {
path, err := EnsureBinariesExist()
assert.Nil(t, err)
Expand All @@ -40,15 +36,16 @@ func TestStartPosEth2Network(t *testing.T) {
binDir, err := EnsureBinariesExist()
assert.Nil(t, err)

startPort := integration.TestPorts.TestStartPosEth2NetworkPort
network := NewPosEth2Network(
binDir,
_startPort+integration.DefaultGethNetworkPortOffset,
_startPort+integration.DefaultPrysmP2PPortOffset,
_startPort+integration.DefaultGethAUTHPortOffset,
_startPort+integration.DefaultGethWSPortOffset,
_startPort+integration.DefaultGethHTTPPortOffset,
_startPort+integration.DefaultPrysmRPCPortOffset,
_startPort+integration.DefaultPrysmGatewayPortOffset,
startPort+integration.DefaultGethNetworkPortOffset,
startPort+integration.DefaultPrysmP2PPortOffset,
startPort+integration.DefaultGethAUTHPortOffset,
startPort+integration.DefaultGethWSPortOffset,
startPort+integration.DefaultGethHTTPPortOffset,
startPort+integration.DefaultPrysmRPCPortOffset,
startPort+integration.DefaultPrysmGatewayPortOffset,
integration.EthereumChainID,
3*time.Minute,
)
Expand All @@ -60,12 +57,12 @@ func TestStartPosEth2Network(t *testing.T) {

// test input configurations
t.Run("areConfigsUphold", func(t *testing.T) {
areConfigsUphold(t, gethcommon.HexToAddress(integration.GethNodeAddress), integration.EthereumChainID)
areConfigsUphold(t, startPort, gethcommon.HexToAddress(integration.GethNodeAddress), integration.EthereumChainID)
})

// test number of nodes
t.Run("numberOfNodes", func(t *testing.T) {
numberOfNodes(t)
numberOfNodes(t, startPort)
})

minerWallet := wallet.NewInMemoryWalletFromConfig(
Expand All @@ -74,12 +71,12 @@ func TestStartPosEth2Network(t *testing.T) {
gethlog.New())

t.Run("txsAreMinted", func(t *testing.T) {
txsAreMinted(t, minerWallet)
txsAreMinted(t, startPort, minerWallet)
})
}

func areConfigsUphold(t *testing.T, addr gethcommon.Address, chainID int) {
url := fmt.Sprintf("http://127.0.0.1:%d", _startPort+integration.DefaultGethHTTPPortOffset)
func areConfigsUphold(t *testing.T, startPort int, addr gethcommon.Address, chainID int) {
url := fmt.Sprintf("http://127.0.0.1:%d", startPort+integration.DefaultGethHTTPPortOffset)
conn, err := ethclient.Dial(url)
assert.Nil(t, err)

Expand All @@ -92,8 +89,8 @@ func areConfigsUphold(t *testing.T, addr gethcommon.Address, chainID int) {
assert.Equal(t, int64(chainID), id.Int64())
}

func numberOfNodes(t *testing.T) {
url := fmt.Sprintf("http://127.0.0.1:%d", _startPort+integration.DefaultGethHTTPPortOffset)
func numberOfNodes(t *testing.T, startPort int) {
url := fmt.Sprintf("http://127.0.0.1:%d", startPort+integration.DefaultGethHTTPPortOffset)

req, err := http.NewRequestWithContext(
context.Background(),
Expand Down Expand Up @@ -122,10 +119,10 @@ func numberOfNodes(t *testing.T) {
assert.Equal(t, fmt.Sprintf("0x%x", 0), res["result"])
}

func txsAreMinted(t *testing.T, w wallet.Wallet) {
func txsAreMinted(t *testing.T, startPort int, w wallet.Wallet) {
var err error

ethClient, err := ethadapter.NewEthClient("127.0.0.1", uint(_startPort+integration.DefaultGethWSPortOffset), 30*time.Second, common.L2Address{}, gethlog.New())
ethClient, err := ethadapter.NewEthClient("127.0.0.1", uint(startPort+integration.DefaultGethWSPortOffset), 30*time.Second, common.L2Address{}, gethlog.New())
assert.Nil(t, err)

toAddr := datagenerator.RandomAddress()
Expand Down
6 changes: 6 additions & 0 deletions integration/eth2network/start-pos-network.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ GETH_LOG_FILE="./geth.log"
GETHDATA_DIR="/gethdata"
BEACONDATA_DIR="/beacondata"
VALIDATORDATA_DIR="/validatordata"
TEST_LOG_FILE="./test.log"

# Function to display usage
usage() {
Expand Down Expand Up @@ -68,6 +69,7 @@ while [[ "$#" -gt 0 ]]; do
--gethdata-dir) GETHDATA_DIR="$2"; shift ;;
--beacondata-dir) BEACONDATA_DIR="$2"; shift ;;
--validatordata-dir) VALIDATORDATA_DIR="$2"; shift ;;
--test-log) TEST_LOG_FILE="$2"; shift ;;
*) usage ;;
esac
shift
Expand All @@ -76,6 +78,9 @@ done
mkdir -p "$(dirname "${BEACON_LOG_FILE}")"
mkdir -p "$(dirname "${VALIDATOR_LOG_FILE}")"
mkdir -p "$(dirname "${GETH_LOG_FILE}")"
mkdir -p "$(dirname "${TEST_LOG_FILE}")"

echo "Test" > "${TEST_LOG_FILE}" 2>&1 &

${PRYSMCTL_BINARY} testnet generate-genesis \
--fork deneb \
Expand Down Expand Up @@ -141,6 +146,7 @@ ${GETH_BINARY} --http \
--ws.origins "*" \
--authrpc.jwtsecret "${BASE_PATH}/jwt.hex" \
--authrpc.port "${GETH_RPC_PORT}" \
--authrpc.vhosts "*" \
--port="${GETH_NETWORK_PORT}" \
--datadir="${GETHDATA_DIR}" \
--networkid="${CHAIN_ID}" \
Expand Down
4 changes: 2 additions & 2 deletions integration/faucet/faucet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const (
func TestFaucet(t *testing.T) {
t.Skip("Skipping because it is too flaky")

startPort := integration.StartPortFaucetUnitTest
startPort := integration.TestPorts.TestFaucetPort
createObscuroNetwork(t, startPort)
// This sleep is required to ensure the initial rollup exists, and thus contract deployer can check its balance.
time.Sleep(2 * time.Second)
Expand All @@ -54,7 +54,7 @@ func TestFaucet(t *testing.T) {
PK: "0x" + contractDeployerPrivateKeyHex,
JWTSecret: "This_is_secret",
ChainID: big.NewInt(integration.TenChainID),
ServerPort: integration.StartPortFaucetHTTPUnitTest,
ServerPort: integration.TestPorts.TestFaucetHTTPPort,
DefaultFundAmount: new(big.Int).Mul(big.NewInt(100), big.NewInt(1e18)),
}
faucetContainer, err := container.NewFaucetContainerFromConfig(faucetConfig)
Expand Down
33 changes: 16 additions & 17 deletions integration/noderunner/noderunner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
const (
_testLogs = "../.build/noderunner/"
_localhost = "127.0.0.1"
_startPort = integration.StartPortNodeRunnerTest
)

// A smoke test to check that we can stand up a standalone TEN host and enclave.
Expand All @@ -31,9 +30,9 @@ func TestCanStartStandaloneTenHostAndEnclave(t *testing.T) {
TestSubtype: "test",
LogLevel: gethlog.LvlInfo,
})

// todo run the noderunner test with different obscuro node instances
newNode := createInMemoryNode()
startPort := integration.TestPorts.TestCanStartStandaloneTenHostAndEnclavePort
// todo run the noderunner test with different TEN node instances
newNode := createInMemoryNode(startPort)

binDir, err := eth2network.EnsureBinariesExist()
if err != nil {
Expand All @@ -42,13 +41,13 @@ func TestCanStartStandaloneTenHostAndEnclave(t *testing.T) {

network := eth2network.NewPosEth2Network(
binDir,
_startPort+integration.DefaultGethNetworkPortOffset,
_startPort+integration.DefaultPrysmP2PPortOffset,
_startPort+integration.DefaultGethAUTHPortOffset,
_startPort+integration.DefaultGethWSPortOffset,
_startPort+integration.DefaultGethHTTPPortOffset,
_startPort+integration.DefaultPrysmRPCPortOffset,
_startPort+integration.DefaultPrysmGatewayPortOffset,
startPort+integration.DefaultGethNetworkPortOffset,
startPort+integration.DefaultPrysmP2PPortOffset,
startPort+integration.DefaultGethAUTHPortOffset,
startPort+integration.DefaultGethWSPortOffset,
startPort+integration.DefaultGethHTTPPortOffset,
startPort+integration.DefaultPrysmRPCPortOffset,
startPort+integration.DefaultPrysmGatewayPortOffset,
integration.EthereumChainID,
3*time.Minute,
)
Expand All @@ -66,7 +65,7 @@ func TestCanStartStandaloneTenHostAndEnclave(t *testing.T) {
}

// we create the node RPC client
wsURL := fmt.Sprintf("ws://127.0.0.1:%d", _startPort+integration.DefaultGethWSPortOffset)
wsURL := fmt.Sprintf("ws://127.0.0.1:%d", startPort+integration.DefaultGethWSPortOffset)
var tenClient rpc.Client
wait := 30 // max wait in seconds
for {
Expand Down Expand Up @@ -109,14 +108,14 @@ func TestCanStartStandaloneTenHostAndEnclave(t *testing.T) {
t.Fatalf("Zero rollups have been produced after ten seconds. Something is wrong. Latest error was: %s", err)
}

func createInMemoryNode() node.Node {
func createInMemoryNode(startPort int) node.Node {
nodeCfg := node.NewNodeConfig(
node.WithPrivateKey(integration.GethNodePK),
node.WithHostID(integration.GethNodeAddress),
node.WithEnclaveWSPort(_startPort+integration.DefaultEnclaveOffset),
node.WithHostHTTPPort(_startPort+integration.DefaultHostRPCHTTPOffset),
node.WithHostWSPort(_startPort+integration.DefaultHostRPCWSOffset),
node.WithL1WebsocketURL(fmt.Sprintf("ws://%s:%d", _localhost, _startPort+integration.DefaultGethWSPortOffset)),
node.WithEnclaveWSPort(startPort+integration.DefaultEnclaveOffset),
node.WithHostHTTPPort(startPort+integration.DefaultHostRPCHTTPOffset),
node.WithHostWSPort(startPort+integration.DefaultHostRPCWSOffset),
node.WithL1WebsocketURL(fmt.Sprintf("ws://%s:%d", _localhost, startPort+integration.DefaultGethWSPortOffset)),
node.WithGenesis(true),
node.WithProfiler(true),
node.WithL1BlockTime(1*time.Second),
Expand Down
Loading
Loading