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

Add New Node Flow fixes #1712

Merged
merged 19 commits into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/build-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ jobs:
integration/.build/faucet/*
integration/.build/obscuroscan/*
integration/.build/tengateway/*
integration/.build/smartcontracts/*
retention-days: 1


59 changes: 31 additions & 28 deletions .github/workflows/manual-deploy-testnet-validator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@
# This script uses GitHub Environments for variables (vars) and secrets - these are configured on GitHub and
# the environments match the input.testnet_type options
#
# # # # README # # # #
#
# 1 - Fetch the Management, Msg Bus Contract addresses and L1 Start Hash from:
# curl -X POST erpc.dev-testnet.obscu.ro:80 -H 'Content-Type: application/json' \
# -d '{"jsonrpc":"2.0","method":"obscuro_config","params":[],"id":1}'
#
# 2 - Update the secrets in Github
# ADD_NEW_NODE_L1_WS_URL -> l1 WS url
# ADD_NEW_NODE_PRIVATE_KEY -> L1 and L2 Private Key
# Note: L1 PK Must have funds in it
#
# 3 - Trigger the flow and supply data from Step 1.
# Node Id: is the node number
# Node Account Address: is the Account Address of the ADD_NEW_NODE_PRIVATE_KEY
#

name: '[M] Deploy Testnet Validator'
run-name: '[M] Deploy Testnet Validator ( ${{ github.event.inputs.testnet_type }} )'
Expand All @@ -23,18 +38,14 @@ on:
required: true
default: 3
type: number
node_private_key:
description: 'Node Private Key'
node_id:
description: 'Node id'
required: true
type: string
node_account_address:
description: 'Node Account Address'
required: true
type: string
node_l1_ws_url:
description: 'Node L1 Connection String'
required: true
type: string
MGMT_CONTRACT_ADDR:
description: 'Management Contract Addr'
required: true
Comment on lines 38 to 51
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 NOTE
Codebase verification is a beta feature.

The removal of HOC_ERC20_ADDR and POC_ERC20_ADDR from manual-deploy-testnet-validator.yml is confirmed. However, these variables are still referenced in .github/workflows/manual-deploy-testnet-l2.yml. This could be an oversight or intentional, depending on whether these workflows are interconnected or independent.

  • HOC_ERC20_ADDR and POC_ERC20_ADDR are still used in .github/workflows/manual-deploy-testnet-l2.yml.
Analysis chain

Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [41-60]

The declarations for node_l1_ws_url, HOC_ERC20_ADDR, and POC_ERC20_ADDR have been removed. Confirm that there are no lingering references to these variables in the workflow.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Check for any remaining references to the removed variables.
rg --type yaml 'node_l1_ws_url' .github/workflows/
rg --type yaml 'HOC_ERC20_ADDR' .github/workflows/
rg --type yaml 'POC_ERC20_ADDR' .github/workflows/

Length of output: 394

Expand All @@ -47,14 +58,7 @@ on:
description: 'L1 Starting Hash'
required: true
type: string
HOC_ERC20_ADDR:
description: 'HOC ERC20 Contract Addr'
required: true
type: string
POC_ERC20_ADDR:
description: 'POC ERC20 Contract Addr'
required: true
type: string


jobs:
build:
Expand Down Expand Up @@ -115,34 +119,34 @@ jobs:
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}

- name: 'Create VM for Obscuro node-${{ matrix.host_id }} on Azure'
- name: 'Create VM for Obscuro node-${{ github.event.inputs.node_id }} on Azure'
uses: azure/CLI@v1
with:
inlineScript: |
az vm create -g Testnet -n "${{ vars.AZURE_RESOURCE_PREFIX }}-${{ matrix.host_id }}-${{ GITHUB.RUN_NUMBER }}" \
az vm create -g Testnet -n "${{ vars.AZURE_RESOURCE_PREFIX }}-${{ github.event.inputs.node_id }}-${{ GITHUB.RUN_NUMBER }}" \
--admin-username obscurouser --admin-password "${{ secrets.OBSCURO_NODE_VM_PWD }}" \
--public-ip-address-dns-name "obscuronode-${{ matrix.host_id }}-${{ github.event.inputs.testnet_type }}-${{ GITHUB.RUN_NUMBER }}" \
--public-ip-address-dns-name "obscuronode-${{ github.event.inputs.node_id }}-${{ github.event.inputs.testnet_type }}-${{ GITHUB.RUN_NUMBER }}" \
--tags deploygroup=ObscuroNode-${{ github.event.inputs.testnet_type }}-${{ GITHUB.RUN_NUMBER }} ${{ vars.AZURE_DEPLOY_GROUP_L2 }}=true \
--vnet-name ${{ github.event.inputs.testnet_type }}-virtual-network --subnet ${{ github.event.inputs.testnet_type }}-sub-network \
--size Standard_DC8_v2 --storage-sku StandardSSD_LRS --image ObscuroConfUbuntu \
--public-ip-sku Standard --authentication-type password

- name: 'Open Obscuro node-${{ matrix.host_id }} ports on Azure'
- name: 'Open Obscuro node-${{ github.event.inputs.host_id }} ports on Azure'
uses: azure/CLI@v1
with:
inlineScript: |
az vm open-port -g Testnet -n "${{ vars.AZURE_RESOURCE_PREFIX }}-${{ matrix.host_id }}-${{ GITHUB.RUN_NUMBER }}" --port 80,81,6060,6061,10000
az vm open-port -g Testnet -n "${{ vars.AZURE_RESOURCE_PREFIX }}-${{ github.event.inputs.node_id }}-${{ GITHUB.RUN_NUMBER }}" --port 80,81,6060,6061,10000

# To overcome issues with critical VM resources being unavailable, we need to wait for the VM to be ready
- name: 'Allow time for VM initialization'
shell: bash
run: sleep 60
Comment on lines 141 to 143
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using sleep 60 for VM initialization could lead to flaky behavior if the VM takes longer to initialize. Consider implementing a health check loop that confirms the VM is ready.

- sleep 60
+ while ! nc -z $VM_IP $VM_PORT; do   
+   sleep 1 # wait for 1 second before check again
+ done

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
- name: 'Allow time for VM initialization'
shell: bash
run: sleep 60
- name: 'Allow time for VM initialization'
shell: bash
run: |
while ! nc -z $VM_IP $VM_PORT; do
sleep 1 # wait for 1 second before check again
done


- name: 'Start Obscuro node-${{ matrix.host_id }} on Azure'
- name: 'Start Obscuro node-${{ github.event.inputs.node_id }} on Azure'
uses: azure/CLI@v1
with:
inlineScript: |
az vm run-command invoke -g Testnet -n "${{ vars.AZURE_RESOURCE_PREFIX }}-${{ matrix.host_id }}-${{ GITHUB.RUN_NUMBER }}" \
az vm run-command invoke -g Testnet -n "${{ vars.AZURE_RESOURCE_PREFIX }}-${{ github.event.inputs.node_id }}-${{ GITHUB.RUN_NUMBER }}" \
--command-id RunShellScript \
--scripts 'mkdir -p /home/obscuro \
&& git clone --depth 1 -b ${{ env.BRANCH_NAME }} https://github.com/ten-protocol/go-ten.git /home/obscuro/go-obscuro \
Expand All @@ -166,13 +170,13 @@ jobs:
-node_type=validator \
-is_sgx_enabled=true \
-host_id=${{ github.event.inputs.node_account_address }} \
-l1_ws_url=${{ github.event.inputs.node_l1_ws_url }} \
-l1_ws_url=${{ secrets.ADD_NEW_NODE_L1_WS_URL }} \
-management_contract_addr=${{ github.event.inputs.MGMT_CONTRACT_ADDR }} \
-message_bus_contract_addr=${{ github.event.inputs.MSG_BUS_CONTRACT_ADDR }} \
-l1_start=${{ github.event.inputs.L1_START_HASH }} \
-private_key=${{ github.event.inputs.node_private_key }} \
-private_key=${{ secrets.ADD_NEW_NODE_PRIVATE_KEY }} \
-sequencer_id=${{ vars.ACCOUNT_ADDR_NODE_0 }} \
-host_public_p2p_addr=obscuronode-${{ matrix.host_id }}-${{ github.event.inputs.testnet_type }}-${{ GITHUB.RUN_NUMBER }}.uksouth.cloudapp.azure.com:10000 \
-host_public_p2p_addr=obscuronode-${{ github.event.inputs.node_id }}-${{ github.event.inputs.testnet_type }}-${{ GITHUB.RUN_NUMBER }}.uksouth.cloudapp.azure.com:10000 \
-host_p2p_port=10000 \
-enclave_docker_image=${{ vars.L2_ENCLAVE_DOCKER_BUILD_TAG }} \
-host_docker_image=${{ vars.L2_HOST_DOCKER_BUILD_TAG }} \
Expand Down Expand Up @@ -209,8 +213,8 @@ jobs:
inlineScript: |
az network nic ip-config address-pool add \
--address-pool ${{ github.event.inputs.testnet_type }}-backend-pool \
--ip-config-name ipconfig${{ vars.AZURE_RESOURCE_PREFIX }}-1-${{ GITHUB.RUN_NUMBER }} \
--nic-name ${{ vars.AZURE_RESOURCE_PREFIX }}-1-${{ GITHUB.RUN_NUMBER }}VMNic \
--ip-config-name ipconfig${{ vars.AZURE_RESOURCE_PREFIX }}-${{ github.event.inputs.node_id }}-${{ GITHUB.RUN_NUMBER }} \
--nic-name ${{ vars.AZURE_RESOURCE_PREFIX }}-${{ github.event.inputs.node_id }}-${{ GITHUB.RUN_NUMBER }}VMNic \
--resource-group Testnet \
--lb-name ${{ github.event.inputs.testnet_type }}-loadbalancer

Expand All @@ -227,5 +231,4 @@ jobs:
- name: "Wait until obscuro node is healthy"
shell: bash
run: |
./.github/workflows/runner-scripts/wait-node-healthy.sh --host=obscuronode-0-${{ github.event.inputs.testnet_type }}-${{ GITHUB.RUN_NUMBER }}.uksouth.cloudapp.azure.com
./.github/workflows/runner-scripts/wait-node-healthy.sh --host=obscuronode-1-${{ github.event.inputs.testnet_type }}-${{ GITHUB.RUN_NUMBER }}.uksouth.cloudapp.azure.com
./.github/workflows/runner-scripts/wait-node-healthy.sh --host=obscuronode-${{ github.event.inputs.node_id }}-${{ github.event.inputs.testnet_type }}-${{ GITHUB.RUN_NUMBER }}.uksouth.cloudapp.azure.com
12 changes: 6 additions & 6 deletions .github/workflows/runner-scripts/testnet-clear-loadbalancer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ if [[ -z "${ipconfig_id}" ]]; then
exit 0
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using a non-zero exit status when the script exits due to not finding the nic_id or ipconfig_id. Exiting with a status of 0 usually indicates success, which might not be appropriate in this context.

fi

az network nic ip-config address-pool remove \
--address-pool ${pool} \
--ip-config-name "${ipconfig_id}" \
--nic-name "${nic_id}" \
--resource-group Testnet \
--lb-name ${lb} \
#az network nic ip-config address-pool remove \
# --address-pool ${pool} \
# --ip-config-name "${ipconfig_id}" \
# --nic-name "${nic_id}" \
# --resource-group Testnet \
# --lb-name ${lb} \
Comment on lines +46 to +51
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The block of code that removes an address pool from the network interface configuration has been commented out. If this is intentional to prevent the removal for now, ensure that there is a tracking mechanism (like a TODO or a ticket) to revisit this if the functionality needs to be restored in the future.



echo 'Load balancer removed successfully'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The message 'Load balancer removed successfully' is misleading because the code that performs the removal is commented out. This message should be updated to reflect the current behavior of the script.

Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
return l2Network.deployments.execute("CrossChainMessenger", {
from: l2Accounts.deployer,
log: true,
gasLimit: 2_500_000
gasLimit: 5_000_000
}, "relayMessage", msg);
};

Expand Down
4 changes: 2 additions & 2 deletions go/config/enclave_cli_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ var EnclaveFlags = map[string]*flag.TenFlag{
MaxRollupSizeFlag: flag.NewUint64Flag(MaxRollupSizeFlag, 1024*64, "The maximum size a rollup is allowed to reach"),
L2BaseFeeFlag: flag.NewUint64Flag(L2BaseFeeFlag, 1, ""),
L2CoinbaseFlag: flag.NewStringFlag(L2CoinbaseFlag, "0xd6C9230053f45F873Cb66D8A02439380a37A4fbF", ""),
GasBatchExecutionLimit: flag.NewUint64Flag(GasBatchExecutionLimit, 3_000_000, "Max gas that can be executed in a single batch"),
GasBatchExecutionLimit: flag.NewUint64Flag(GasBatchExecutionLimit, 30_000_000, "Max gas that can be executed in a single batch"),
ObscuroGenesisFlag: flag.NewStringFlag(ObscuroGenesisFlag, "", "The json string with the obscuro genesis"),
L1ChainIDFlag: flag.NewInt64Flag(L1ChainIDFlag, 1337, "An integer representing the unique chain id of the Ethereum chain used as an L1 (default 1337)"),
ObscuroChainIDFlag: flag.NewInt64Flag(ObscuroChainIDFlag, 443, "An integer representing the unique chain id of the Obscuro chain (default 443)"),
UseInMemoryDBFlag: flag.NewBoolFlag(UseInMemoryDBFlag, true, "Whether the enclave will use an in-memory DB rather than persist data"),
ProfilerEnabledFlag: flag.NewBoolFlag(ProfilerEnabledFlag, false, "Runs a profiler instance (Defaults to false)"),
DebugNamespaceEnabledFlag: flag.NewBoolFlag(DebugNamespaceEnabledFlag, false, "Whether the debug namespace is enabled"),
GasLocalExecutionCapFlag: flag.NewUint64Flag(GasLocalExecutionCapFlag, 3_000_000, "Max gas usage when executing local transactions"),
GasLocalExecutionCapFlag: flag.NewUint64Flag(GasLocalExecutionCapFlag, 40_000_000, "Max gas usage when executing local transactions"),
}

// enclaveRestrictedFlags are the flags that the enclave can receive ONLY over the Ego signed enclave.json
Expand Down
4 changes: 2 additions & 2 deletions go/enclave/crosschain/message_bus_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (m *MessageBusManager) GenerateMessageBusDeployTx() (*common.L2Tx, error) {
tx := &types.LegacyTx{
Nonce: 0, // The first transaction of the owner identity should always be deploying the contract
Value: gethcommon.Big0,
Gas: 2_000_000, // It's quite the expensive contract.
Gas: 5_000_000, // It's quite the expensive contract.
GasPrice: gethcommon.Big0, // Synthetic transactions are on the house. Or the house.
Data: gethcommon.FromHex(MessageBus.MessageBusMetaData.Bin),
To: nil, // Geth requires nil instead of gethcommon.Address{} which equates to zero address in order to return receipt.
Expand Down Expand Up @@ -219,7 +219,7 @@ func (m *MessageBusManager) CreateSyntheticTransactions(messages common.CrossCha
tx := &types.LegacyTx{
Nonce: startingNonce + uint64(idx),
Value: gethcommon.Big0,
Gas: 2_000_000,
Gas: 5_000_000,
GasPrice: gethcommon.Big0, // Synthetic transactions are on the house. Or the house.
Data: data,
To: m.messageBusAddress,
Expand Down
19 changes: 11 additions & 8 deletions go/enclave/enclave.go
Original file line number Diff line number Diff line change
Expand Up @@ -685,15 +685,18 @@ func (e *enclaveImpl) GetTransactionCount(encryptedParams common.EncryptedParams
}

var nonce uint64
l2Head, err := e.storage.FetchBatchBySeqNo(e.registry.HeadBatchSeq().Uint64())
if err == nil {
// todo - we should return an error when head state is not available, but for current test situations with race
// conditions we allow it to return zero while head state is uninitialized
s, err := e.storage.CreateStateDB(l2Head.Hash())
if err != nil {
return nil, responses.ToInternalError(err)
headBatch := e.registry.HeadBatchSeq()
if headBatch != nil {
l2Head, err := e.storage.FetchBatchBySeqNo(headBatch.Uint64())
if err == nil {
// todo - we should return an error when head state is not available, but for current test situations with race
// conditions we allow it to return zero while head state is uninitialized
s, err := e.storage.CreateStateDB(l2Head.Hash())
if err != nil {
return nil, responses.ToInternalError(err)
}
nonce = s.GetNonce(address)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The refactoring of the logic for fetching the head batch sequence and creating a state DB includes a new conditional check for headBatch. This check ensures that the headBatch is not nil before proceeding to fetch the batch by sequence number and create the state DB. This is a good practice as it prevents potential nil dereferences.

However, the error handling inside the conditional block could be improved. The comment on line 692 suggests that there are known race conditions that are being temporarily tolerated by allowing a zero nonce to be returned when the head state is uninitialized. This could lead to unexpected behavior and should be addressed as soon as possible.

Additionally, the error from e.storage.FetchBatchBySeqNo(headBatch.Uint64()) is being swallowed if it is not nil. It would be better to handle this error explicitly, even if it's just logging it for debugging purposes.

  l2Head, err := e.storage.FetchBatchBySeqNo(headBatch.Uint64())
  if err == nil {
    // TODO: We should return an error when head state is not available, but for current test situations with race
    // conditions we allow it to return zero while head state is uninitialized
    s, err := e.storage.CreateStateDB(l2Head.Hash())
    if err != nil {
      return nil, responses.ToInternalError(err)
    }
    nonce = s.GetNonce(address)

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
headBatch := e.registry.HeadBatchSeq()
if headBatch != nil {
l2Head, err := e.storage.FetchBatchBySeqNo(headBatch.Uint64())
if err == nil {
// todo - we should return an error when head state is not available, but for current test situations with race
// conditions we allow it to return zero while head state is uninitialized
s, err := e.storage.CreateStateDB(l2Head.Hash())
if err != nil {
return nil, responses.ToInternalError(err)
}
nonce = s.GetNonce(address)
headBatch := e.registry.HeadBatchSeq()
if headBatch != nil {
l2Head, err := e.storage.FetchBatchBySeqNo(headBatch.Uint64())
if err != nil {
// Handle the error appropriately
return nil, responses.ToInternalError(err)
}
// TODO: We should return an error when head state is not available, but for current test situations with race
// conditions we allow it to return zero while head state is uninitialized
s, err := e.storage.CreateStateDB(l2Head.Hash())
if err != nil {
return nil, responses.ToInternalError(err)
}
nonce = s.GetNonce(address)

}
nonce = s.GetNonce(address)
}

encoded := hexutil.EncodeUint64(nonce)
Expand Down
3 changes: 3 additions & 0 deletions go/enclave/nodetype/sequencer.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ func (s *sequencer) createGenesisBatch(block *common.L1Block) error {
return err
}

// errors in unit test seem to suggest that batch 2 was received before batch 1
// this ensures that there is enough gap so that batch 1 is issued before batch 2
time.Sleep(time.Second)
// produce batch #2 which has the message bus and any other system contracts
cb, err := s.produceBatch(
big.NewInt(0).Add(batch.Header.SequencerOrderNo, big.NewInt(1)),
Expand Down
4 changes: 2 additions & 2 deletions integration/common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func DefaultEnclaveConfig() *config.EnclaveConfig {
MaxRollupSize: 1024 * 64,
GasPaymentAddress: gethcommon.HexToAddress("0xd6C9230053f45F873Cb66D8A02439380a37A4fbF"),
BaseFee: new(big.Int).SetUint64(1),
GasLocalExecutionCapFlag: 3_000_000,
GasBatchExecutionLimit: 3_000_000,
GasBatchExecutionLimit: 30_000_000,
GasLocalExecutionCapFlag: 40_000_000,
}
}
2 changes: 1 addition & 1 deletion integration/common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func PrefundWallets(ctx context.Context, faucetWallet wallet.Wallet, faucetClien
tx := &types.LegacyTx{
Nonce: startingNonce + uint64(idx),
Value: alloc,
Gas: uint64(1_000_000),
Gas: uint64(100_000),
GasPrice: gethcommon.Big1,
To: &destAddr,
}
Expand Down
30 changes: 15 additions & 15 deletions integration/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ package integration

// Tracks the start ports handed out to different tests, in a bid to minimise conflicts.
const (
StartPortEth2NetworkTests = 31000
StartPortNodeRunnerTest = 32000
StartPortSimulationGethInMem = 34000
StartPortSimulationInMem = 35000
StartPortSimulationFullNetwork = 37000
StartPortSmartContractTests = 38000
StartPortContractDeployerTest = 39000
StartPortWalletExtensionUnitTest = 40000
StartPortFaucetUnitTest = 41000
StartPortFaucetHTTPUnitTest = 42000
StartPortTenscanUnitTest = 43000
StartPortTenGatewayUnitTest = 44000
StartPortEth2NetworkTests = 10000
StartPortNodeRunnerTest = 14000
StartPortSimulationGethInMem = 18000
StartPortSimulationInMem = 22000
StartPortSimulationFullNetwork = 26000
StartPortSmartContractTests = 30000
StartPortContractDeployerTest = 34000
StartPortWalletExtensionUnitTest = 38000
StartPortFaucetUnitTest = 42000
StartPortFaucetHTTPUnitTest = 48000
StartPortTenscanUnitTest = 52000
StartPortTenGatewayUnitTest = 56000
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a comment explaining the rationale for choosing these specific port numbers, as they are now in a range that might be more commonly used by other applications.


DefaultGethWSPortOffset = 100
DefaultGethAUTHPortOffset = 200
Expand All @@ -24,9 +24,9 @@ const (
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
DefaultHostRPCWSOffset = 900 // The default offset for the host's RPC websocket port
DefaultTenscanHTTPPortOffset = 910
DefaultTenGatewayHTTPPortOffset = 930
DefaultTenGatewayWSPortOffset = 940
DefaultTenscanHTTPPortOffset = 1000
DefaultTenGatewayHTTPPortOffset = 1001
DefaultTenGatewayWSPortOffset = 1002
)

const (
Expand Down
36 changes: 36 additions & 0 deletions integration/eth2network/eth2_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ten-protocol/go-ten/integration/datagenerator"
"golang.org/x/sync/errgroup"

gethcommon "github.com/ethereum/go-ethereum/common"
)

const (
Expand Down Expand Up @@ -206,6 +208,10 @@ func (n *Impl) Start() error {
startTime := time.Now()
var eg errgroup.Group

if err := n.ensureNoDuplicatedNetwork(); err != nil {
return err
}

// initialize the genesis data on the nodes
for _, nodeDataDir := range n.dataDirs {
dataDir := nodeDataDir
Expand Down Expand Up @@ -506,6 +512,11 @@ func (n *Impl) waitForMergeEvent(startTime time.Time) error {
}

fmt.Printf("Reached the merge block after %s\n", time.Since(startTime))

if err = n.prefundedBalancesActive(dial); err != nil {
fmt.Printf("Error prefunding accounts %s\n", err.Error())
return err
}
return nil
}

Expand Down Expand Up @@ -589,6 +600,31 @@ func (n *Impl) gethImportEnodes(enodes []string) error {
return nil
}

func (n *Impl) prefundedBalancesActive(client *ethclient.Client) error {
for _, addr := range n.preFundedMinerAddrs {
balance, err := client.BalanceAt(context.Background(), gethcommon.HexToAddress(addr), nil)
if err != nil {
return fmt.Errorf("unable to check balance for account %s - %w", addr, err)
}
if balance.Cmp(gethcommon.Big0) == 0 {
return fmt.Errorf("unexpected %s balance for account %s", balance.String(), addr)
}
fmt.Printf("Account %s prefunded with %s\n", addr, balance.String())
}

return nil
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The prefundedBalancesActive method checks if the prefunded accounts have a balance greater than zero. It's important to ensure that the balance check is against the expected minimum balance rather than just zero to avoid potential issues with underfunded accounts.

if balance.Cmp(expectedMinimumBalance) < 0 {
	return fmt.Errorf("insufficient balance for account %s: %s", addr, balance.String())
}

}

func (n *Impl) ensureNoDuplicatedNetwork() error {
for nodeIdx, port := range n.gethWSPorts {
_, err := ethclient.Dial(fmt.Sprintf("ws://127.0.0.1:%d", port))
if err == nil {
return fmt.Errorf("unexpected geth node %d is active before the network is started", nodeIdx)
}
}
return nil
}

func min(a, b int) int {
if a < b {
return a
Expand Down
Loading
Loading