From 69264456b352c0c150031ac5fa570ceb65e46ea1 Mon Sep 17 00:00:00 2001 From: Tanmay Date: Thu, 20 Jun 2024 06:23:46 -0400 Subject: [PATCH 1/8] add import data --- cmd/zetacored/parse_genesis.go | 25 ++++++++++++++++++------- contrib/localnet/scripts/import-data.sh | 15 +++++++++++++++ 2 files changed, 33 insertions(+), 7 deletions(-) create mode 100644 contrib/localnet/scripts/import-data.sh diff --git a/cmd/zetacored/parse_genesis.go b/cmd/zetacored/parse_genesis.go index b2a4258995..573977c261 100644 --- a/cmd/zetacored/parse_genesis.go +++ b/cmd/zetacored/parse_genesis.go @@ -50,18 +50,29 @@ var Copy = map[string]bool{ vestingtypes.ModuleName: true, fungibletypes.ModuleName: true, emissionstypes.ModuleName: true, - authz.ModuleName: true, } // Skip represents a set of modules for which, the entire state is skipped and nothing gets imported var Skip = map[string]bool{ - evmtypes.ModuleName: true, - stakingtypes.ModuleName: true, - genutiltypes.ModuleName: true, - authtypes.ModuleName: true, - banktypes.ModuleName: true, + // Skipping evm this is done to reduce the size of the genesis file evm module uses the majority of the space due to smart contract data + evmtypes.ModuleName: true, + // Skipping staking as new validators would be created for the new chain + stakingtypes.ModuleName: true, + // Skipping genutil as new gentxs would be created + genutiltypes.ModuleName: true, + // Skipping auth as new accounts would be created for the new chain. This also needs to be done as we are skipping evm module + authtypes.ModuleName: true, + // Skipping bank module as it is not used when starting a new chain this is done to make sure the total supply invariant is maintained. + // This would need modification but might be possible to add in non evm based modules in the future + banktypes.ModuleName: true, + // Skipping distribution module as it is not used when starting a new chain , rewards are based on validators and delegators , and so rewards from a different chain do not hold any value distributiontypes.ModuleName: true, - group.ModuleName: true, + // Skipping group module as it is not used when starting a new chain, new groups should be created based on the validator operator keys + group.ModuleName: true, + // Skipping authz as it is not used when starting a new chain, new grants should be created based on the validator hotkeys abd operator keys + authz.ModuleName: true, + // Skipping fungible module as new fungible tokens would be created and system contract would be deployed + fungibletypes.ModuleName: true, } // Modify represents a set of modules for which, the state is modified before importing. Each Module should have a corresponding Modify function diff --git a/contrib/localnet/scripts/import-data.sh b/contrib/localnet/scripts/import-data.sh new file mode 100644 index 0000000000..d71d5c3656 --- /dev/null +++ b/contrib/localnet/scripts/import-data.sh @@ -0,0 +1,15 @@ +#!/bin/bash +if [ $# -lt 1 ] +then + echo "Usage: import-data.sh [network]" + exit 1 +fi + +NETWORK=$1 +echo "NETWORK: ${NETWORK}" +rm -rf ~/genesis_export/ +mkdir ~/genesis_export/ +echo "Download Latest State Export" +LATEST_EXPORT_URL=$(curl https://snapshots.zetachain.com/latest-state-export | jq -r ."${NETWORK}") +echo "LATEST EXPORT URL: ${LATEST_EXPORT_URL}" +wget -q ${LATEST_EXPORT_URL} -O ~/genesis_export/exported-genesis.json \ No newline at end of file From 32a5750c4b127bf9104d67d80a72f4e98611c06f Mon Sep 17 00:00:00 2001 From: Tanmay Date: Thu, 20 Jun 2024 09:28:39 -0400 Subject: [PATCH 2/8] add import data e2e --- Makefile | 4 + cmd/zetacored/parse_genesis.go | 11 +- .../localnet/docker-compose-import-data.yml | 155 ++++++++++++++++++ .../localnet/orchestrator/start-zetae2e.sh | 6 + contrib/localnet/scripts/start-zetaclientd.sh | 9 + contrib/localnet/scripts/start-zetacored.sh | 6 + 6 files changed, 185 insertions(+), 6 deletions(-) create mode 100644 contrib/localnet/docker-compose-import-data.yml diff --git a/Makefile b/Makefile index 480c956c9a..925a0cf237 100644 --- a/Makefile +++ b/Makefile @@ -252,6 +252,10 @@ start-localnet: zetanode @echo "--> Starting localnet" cd contrib/localnet/ && $(DOCKER) compose -f docker-compose.yml -f docker-compose-setup-only.yml up -d +start-e2e-import-mainnet-test: zetanode + @echo "--> Starting e2e import-data test" + cd contrib/localnet/ && $(DOCKER) compose -f docker-compose.yml -f docker-compose-import-data.yml up -d + stop-test: cd contrib/localnet/ && $(DOCKER) compose down --remove-orphans diff --git a/cmd/zetacored/parse_genesis.go b/cmd/zetacored/parse_genesis.go index 573977c261..8b6a067264 100644 --- a/cmd/zetacored/parse_genesis.go +++ b/cmd/zetacored/parse_genesis.go @@ -41,7 +41,6 @@ const MaxItemsForList = 10 // Copy represents a set of modules for which, the entire state is copied without any modifications var Copy = map[string]bool{ slashingtypes.ModuleName: true, - govtypes.ModuleName: true, crisistypes.ModuleName: true, feemarkettypes.ModuleName: true, paramstypes.ModuleName: true, @@ -72,14 +71,14 @@ var Skip = map[string]bool{ // Skipping authz as it is not used when starting a new chain, new grants should be created based on the validator hotkeys abd operator keys authz.ModuleName: true, // Skipping fungible module as new fungible tokens would be created and system contract would be deployed - fungibletypes.ModuleName: true, + fungibletypes.ModuleName: true, + observertypes.ModuleName: true, + crosschaintypes.ModuleName: true, + govtypes.ModuleName: true, } // Modify represents a set of modules for which, the state is modified before importing. Each Module should have a corresponding Modify function -var Modify = map[string]bool{ - crosschaintypes.ModuleName: true, - observertypes.ModuleName: true, -} +var Modify = map[string]bool{} func CmdParseGenesisFile() *cobra.Command { cmd := &cobra.Command{ diff --git a/contrib/localnet/docker-compose-import-data.yml b/contrib/localnet/docker-compose-import-data.yml new file mode 100644 index 0000000000..3b6f28a269 --- /dev/null +++ b/contrib/localnet/docker-compose-import-data.yml @@ -0,0 +1,155 @@ +version: "3" + +# This docker-compose file configures the localnet environment +# it contains the following services: +# - ZetaChain with 2 nodes (zetacore0, zetacore1) +# - A observer set with 2 clients (zetaclient0, zetaclient1) +# - An Ethereum node (eth) +# - A Bitcoin node (bitcoin) +# - A Rosetta API (rosetta) +# - An orchestrator to manage interaction with the localnet (orchestrator) + +networks: + mynetwork: + ipam: + config: + - subnet: 172.20.0.0/24 + +services: + rosetta: + image: zetanode:latest + container_name: rosetta + hostname: rosetta + ports: + - "8080:8080" + networks: + mynetwork: + ipv4_address: 172.20.0.200 + entrypoint: ["zetacored", "rosetta", "--tendermint", "zetacore0:26657", "--grpc", "zetacore0:9090", "--network", "athens_101-1", "--blockchain", "zetacore" ,"--retries", "500"] + volumes: + - ssh:/root/.ssh + + zetacore0: + image: zetanode:latest + container_name: zetacore0 + build: + context: .. + dockerfile: Dockerfile-localnet + hostname: zetacore0 + ports: + - "1317:1317" + - "9545:8545" + - "9546:8546" + - "26657:26657" + - "6060:6060" + - "9090:9090" + networks: + mynetwork: + ipv4_address: 172.20.0.11 + entrypoint: ["/root/start-zetacored.sh", "2","import-data"] + environment: + - HOTKEY_BACKEND=file + - HOTKEY_PASSWORD=password # test purposes only + volumes: + - ~/genesis_export/:/root/genesis_data + - ssh:/root/.ssh + + zetacore1: + image: zetanode:latest + container_name: zetacore1 + build: + context: .. + dockerfile: Dockerfile-localnet + hostname: zetacore1 + networks: + mynetwork: + ipv4_address: 172.20.0.12 + entrypoint: ["/root/start-zetacored.sh", "2","import-data"] + environment: + - HOTKEY_BACKEND=file + - HOTKEY_PASSWORD=password # test purposes only + volumes: + - ssh:/root/.ssh + + + zetaclient0: + image: zetanode:latest + container_name: zetaclient0 + build: + context: .. + dockerfile: Dockerfile-localnet + hostname: zetaclient0 + networks: + mynetwork: + ipv4_address: 172.20.0.21 + entrypoint: ["/root/start-zetaclientd.sh", "import-data"] + environment: + - ETHDEV_ENDPOINT=http://eth:8545 + - HOTKEY_BACKEND=file + - HOTKEY_PASSWORD=password # test purposes only + volumes: + - ssh:/root/.ssh + + zetaclient1: + image: zetanode:latest + container_name: zetaclient1 + build: + context: .. + dockerfile: Dockerfile-localnet + hostname: zetaclient1 + networks: + mynetwork: + ipv4_address: 172.20.0.22 + entrypoint: ["/root/start-zetaclientd.sh", "import-data"] + environment: + - ETHDEV_ENDPOINT=http://eth:8545 + - HOTKEY_BACKEND=file + - HOTKEY_PASSWORD=password # test purposes only + volumes: + - ssh:/root/.ssh + + eth: + image: ethereum/client-go:v1.10.26 + container_name: eth + hostname: eth + ports: + - "8545:8545" + networks: + mynetwork: + ipv4_address: 172.20.0.100 + entrypoint: ["geth", "--dev", "--http", "--http.addr", "172.20.0.100", "--http.vhosts", "*", "--http.api", "eth,web3,net", "--http.corsdomain", "https://remix.ethereum.org", "--dev.period", "2"] + + bitcoin: + image: ruimarinho/bitcoin-core:22 # version 23 is not working with btcd 0.22.0 due to change in createwallet rpc + container_name: bitcoin + hostname: bitcoin + networks: + mynetwork: + ipv4_address: 172.20.0.101 + ports: + - "18443:18443" + command: + -printtoconsole + -regtest=1 + -rpcallowip=0.0.0.0/0 + -rpcbind=0.0.0.0 + -rpcauth=smoketest:63acf9b8dccecce914d85ff8c044b78b$$5892f9bbc84f4364e79f0970039f88bdd823f168d4acc76099ab97b14a766a99 + -txindex=1 + + orchestrator: + image: orchestrator:latest + tty: true + container_name: orchestrator + build: + context: .. + dockerfile: contrib/localnet/orchestrator/Dockerfile + depends_on: + - zetacore0 + - eth + hostname: orchestrator + networks: + mynetwork: + ipv4_address: 172.20.0.2 + entrypoint: ["/work/start-zetae2e.sh", "local","import-data"] + volumes: + - ssh:/root/.ssh \ No newline at end of file diff --git a/contrib/localnet/orchestrator/start-zetae2e.sh b/contrib/localnet/orchestrator/start-zetae2e.sh index a297be595b..8dcb4ea271 100644 --- a/contrib/localnet/orchestrator/start-zetae2e.sh +++ b/contrib/localnet/orchestrator/start-zetae2e.sh @@ -29,6 +29,12 @@ while [ ! -f ~/.ssh/authorized_keys ]; do sleep 1 done +# need to wait for zetacore0 to be up +while ! curl -s -o /dev/null zetacore0:26657/status ; do + echo "Waiting for zetacore0 rpc" + sleep 10 +done + echo "waiting for geth RPC to start..." sleep 2 diff --git a/contrib/localnet/scripts/start-zetaclientd.sh b/contrib/localnet/scripts/start-zetaclientd.sh index ff2a3b9b99..56b8a05c0f 100755 --- a/contrib/localnet/scripts/start-zetaclientd.sh +++ b/contrib/localnet/scripts/start-zetaclientd.sh @@ -21,6 +21,15 @@ while [ ! -f ~/.ssh/authorized_keys ]; do sleep 1 done + + +# need to wait for zetacore0 to be up +while ! curl -s -o /dev/null zetacore0:26657/status ; do + echo "Waiting for zetacore0 rpc" + sleep 10 +done + + # read HOTKEY_BACKEND env var for hotkey keyring backend and set default to test BACKEND="test" if [ "$HOTKEY_BACKEND" == "file" ]; then diff --git a/contrib/localnet/scripts/start-zetacored.sh b/contrib/localnet/scripts/start-zetacored.sh index 1791742e66..7b7ce23eb6 100755 --- a/contrib/localnet/scripts/start-zetacored.sh +++ b/contrib/localnet/scripts/start-zetacored.sh @@ -71,6 +71,7 @@ then exit 1 fi NUMOFNODES=$1 +OPTION=$2 # create keys CHAINID="athens_101-1" @@ -254,6 +255,11 @@ then scp $NODE:~/.zetacored/config/gentx/* ~/.zetacored/config/gentx/z2gentx/ done + if [[ "$OPTION" == "import-data" || "$OPTION" == "import-data-upgrade" ]]; then + echo "Importing data" + zetacored parse-genesis-file /root/genesis_data/exported-genesis.json + fi + # 4. Collect all the gentx files in zetacore0 and create the final genesis.json zetacored collect-gentxs zetacored validate-genesis From 844af3d7f1210e1e3215b74a09d4430e35259cab Mon Sep 17 00:00:00 2001 From: Tanmay Date: Thu, 20 Jun 2024 13:30:42 -0400 Subject: [PATCH 3/8] add a flag for modifying genesis state --- cmd/zetacored/parse_genesis.go | 23 ++-- cmd/zetacored/parse_genesis_test.go | 103 ++++++++++----- .../localnet/docker-compose-import-data.yml | 121 +----------------- 3 files changed, 90 insertions(+), 157 deletions(-) diff --git a/cmd/zetacored/parse_genesis.go b/cmd/zetacored/parse_genesis.go index 8b6a067264..58053df36e 100644 --- a/cmd/zetacored/parse_genesis.go +++ b/cmd/zetacored/parse_genesis.go @@ -71,14 +71,16 @@ var Skip = map[string]bool{ // Skipping authz as it is not used when starting a new chain, new grants should be created based on the validator hotkeys abd operator keys authz.ModuleName: true, // Skipping fungible module as new fungible tokens would be created and system contract would be deployed - fungibletypes.ModuleName: true, - observertypes.ModuleName: true, - crosschaintypes.ModuleName: true, - govtypes.ModuleName: true, + fungibletypes.ModuleName: true, + // Skipping gov types as new parameters are set for the new chain + govtypes.ModuleName: true, } // Modify represents a set of modules for which, the state is modified before importing. Each Module should have a corresponding Modify function -var Modify = map[string]bool{} +var Modify = map[string]bool{ + observertypes.ModuleName: true, + crosschaintypes.ModuleName: true, +} func CmdParseGenesisFile() *cobra.Command { cmd := &cobra.Command{ @@ -88,6 +90,10 @@ func CmdParseGenesisFile() *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) cdc := clientCtx.Codec + modifyEnabled, err := cmd.Flags().GetBool("modify") + if err != nil { + return err + } genesisFilePath := filepath.Join(app.DefaultNodeHome, "config", "genesis.json") if len(args) == 2 { genesisFilePath = args[1] @@ -100,7 +106,7 @@ func CmdParseGenesisFile() *cobra.Command { if err != nil { return err } - err = ImportDataIntoFile(genDoc, importData, cdc) + err = ImportDataIntoFile(genDoc, importData, cdc, modifyEnabled) if err != nil { return err } @@ -113,10 +119,11 @@ func CmdParseGenesisFile() *cobra.Command { return nil }, } + cmd.PersistentFlags().Bool("modify", false, "Modify the genesis file before importing") return cmd } -func ImportDataIntoFile(genDoc *types.GenesisDoc, importFile *types.GenesisDoc, cdc codec.Codec) error { +func ImportDataIntoFile(genDoc *types.GenesisDoc, importFile *types.GenesisDoc, cdc codec.Codec, modifyEnabled bool) error { appState, err := genutiltypes.GenesisStateFromGenDoc(*genDoc) if err != nil { @@ -134,7 +141,7 @@ func ImportDataIntoFile(genDoc *types.GenesisDoc, importFile *types.GenesisDoc, if Copy[m] { appState[m] = importAppState[m] } - if Modify[m] { + if Modify[m] && modifyEnabled { switch m { case crosschaintypes.ModuleName: err := ModifyCrosschainState(appState, importAppState, cdc) diff --git a/cmd/zetacored/parse_genesis_test.go b/cmd/zetacored/parse_genesis_test.go index 7eb75f4a0f..689075eb32 100644 --- a/cmd/zetacored/parse_genesis_test.go +++ b/cmd/zetacored/parse_genesis_test.go @@ -92,43 +92,86 @@ func Test_ModifyObserverState(t *testing.T) { } func Test_ImportDataIntoFile(t *testing.T) { - setConfig(t) - cdc := keepertest.NewCodec() - genDoc := sample.GenDoc(t) - importGenDoc := ImportGenDoc(t, cdc, 100) + t.Run("successfully import data into file and modify data", func(t *testing.T) { + setConfig(t) + cdc := keepertest.NewCodec() + genDoc := sample.GenDoc(t) + importGenDoc := ImportGenDoc(t, cdc, 100) - err := zetacored.ImportDataIntoFile(genDoc, importGenDoc, cdc) - require.NoError(t, err) + err := zetacored.ImportDataIntoFile(genDoc, importGenDoc, cdc, true) + require.NoError(t, err) - appState, err := genutiltypes.GenesisStateFromGenDoc(*genDoc) - require.NoError(t, err) + appState, err := genutiltypes.GenesisStateFromGenDoc(*genDoc) + require.NoError(t, err) - // Crosschain module is in Modify list - crosschainStateAfterImport := crosschaintypes.GetGenesisStateFromAppState(cdc, appState) - require.Len(t, crosschainStateAfterImport.CrossChainTxs, zetacored.MaxItemsForList) - require.Len(t, crosschainStateAfterImport.InboundHashToCctxList, zetacored.MaxItemsForList) - require.Len(t, crosschainStateAfterImport.FinalizedInbounds, zetacored.MaxItemsForList) + // Crosschain module is in Modify list + crosschainStateAfterImport := crosschaintypes.GetGenesisStateFromAppState(cdc, appState) + require.Len(t, crosschainStateAfterImport.CrossChainTxs, zetacored.MaxItemsForList) + require.Len(t, crosschainStateAfterImport.InboundHashToCctxList, zetacored.MaxItemsForList) + require.Len(t, crosschainStateAfterImport.FinalizedInbounds, zetacored.MaxItemsForList) - // Bank module is in Skip list - var bankStateAfterImport banktypes.GenesisState - if appState[banktypes.ModuleName] != nil { - err := cdc.UnmarshalJSON(appState[banktypes.ModuleName], &bankStateAfterImport) - if err != nil { - panic(fmt.Sprintf("Failed to get genesis state from app state: %s", err.Error())) + // Bank module is in Skip list + var bankStateAfterImport banktypes.GenesisState + if appState[banktypes.ModuleName] != nil { + err := cdc.UnmarshalJSON(appState[banktypes.ModuleName], &bankStateAfterImport) + if err != nil { + panic(fmt.Sprintf("Failed to get genesis state from app state: %s", err.Error())) + } } - } - // 4 balances were present in the original genesis state - require.Len(t, bankStateAfterImport.Balances, 4) + // 4 balances were present in the original genesis state + require.Len(t, bankStateAfterImport.Balances, 4) - // Emissions module is in Copy list - var emissionStateAfterImport emissionstypes.GenesisState - if appState[emissionstypes.ModuleName] != nil { - err := cdc.UnmarshalJSON(appState[emissionstypes.ModuleName], &emissionStateAfterImport) - if err != nil { - panic(fmt.Sprintf("Failed to get genesis state from app state: %s", err.Error())) + // Emissions module is in Copy list + var emissionStateAfterImport emissionstypes.GenesisState + if appState[emissionstypes.ModuleName] != nil { + err := cdc.UnmarshalJSON(appState[emissionstypes.ModuleName], &emissionStateAfterImport) + if err != nil { + panic(fmt.Sprintf("Failed to get genesis state from app state: %s", err.Error())) + } } - } - require.Len(t, emissionStateAfterImport.WithdrawableEmissions, 100) + require.Len(t, emissionStateAfterImport.WithdrawableEmissions, 100) + }) + + t.Run("successfully import data into file without modifying data", func(t *testing.T) { + setConfig(t) + cdc := keepertest.NewCodec() + genDoc := sample.GenDoc(t) + importGenDoc := ImportGenDoc(t, cdc, 8) + + err := zetacored.ImportDataIntoFile(genDoc, importGenDoc, cdc, false) + require.NoError(t, err) + + appState, err := genutiltypes.GenesisStateFromGenDoc(*genDoc) + require.NoError(t, err) + + // Crosschain module is in Modify list + crosschainStateAfterImport := crosschaintypes.GetGenesisStateFromAppState(cdc, appState) + require.Len(t, crosschainStateAfterImport.CrossChainTxs, 0) + require.Len(t, crosschainStateAfterImport.InboundHashToCctxList, 0) + require.Len(t, crosschainStateAfterImport.FinalizedInbounds, 0) + + // Bank module is in Skip list + var bankStateAfterImport banktypes.GenesisState + if appState[banktypes.ModuleName] != nil { + err := cdc.UnmarshalJSON(appState[banktypes.ModuleName], &bankStateAfterImport) + if err != nil { + panic(fmt.Sprintf("Failed to get genesis state from app state: %s", err.Error())) + } + } + // 4 balances were present in the original genesis state + require.Len(t, bankStateAfterImport.Balances, 4) + + // Emissions module is in Copy list + var emissionStateAfterImport emissionstypes.GenesisState + if appState[emissionstypes.ModuleName] != nil { + err := cdc.UnmarshalJSON(appState[emissionstypes.ModuleName], &emissionStateAfterImport) + if err != nil { + panic(fmt.Sprintf("Failed to get genesis state from app state: %s", err.Error())) + } + } + require.Len(t, emissionStateAfterImport.WithdrawableEmissions, 8) + + }) } func Test_GetGenDoc(t *testing.T) { diff --git a/contrib/localnet/docker-compose-import-data.yml b/contrib/localnet/docker-compose-import-data.yml index 3b6f28a269..b8bfc50cbe 100644 --- a/contrib/localnet/docker-compose-import-data.yml +++ b/contrib/localnet/docker-compose-import-data.yml @@ -17,139 +17,22 @@ networks: services: rosetta: - image: zetanode:latest - container_name: rosetta - hostname: rosetta - ports: - - "8080:8080" - networks: - mynetwork: - ipv4_address: 172.20.0.200 entrypoint: ["zetacored", "rosetta", "--tendermint", "zetacore0:26657", "--grpc", "zetacore0:9090", "--network", "athens_101-1", "--blockchain", "zetacore" ,"--retries", "500"] - volumes: - - ssh:/root/.ssh + zetacore0: - image: zetanode:latest - container_name: zetacore0 - build: - context: .. - dockerfile: Dockerfile-localnet - hostname: zetacore0 - ports: - - "1317:1317" - - "9545:8545" - - "9546:8546" - - "26657:26657" - - "6060:6060" - - "9090:9090" - networks: - mynetwork: - ipv4_address: 172.20.0.11 entrypoint: ["/root/start-zetacored.sh", "2","import-data"] - environment: - - HOTKEY_BACKEND=file - - HOTKEY_PASSWORD=password # test purposes only volumes: - ~/genesis_export/:/root/genesis_data - - ssh:/root/.ssh zetacore1: - image: zetanode:latest - container_name: zetacore1 - build: - context: .. - dockerfile: Dockerfile-localnet - hostname: zetacore1 - networks: - mynetwork: - ipv4_address: 172.20.0.12 entrypoint: ["/root/start-zetacored.sh", "2","import-data"] - environment: - - HOTKEY_BACKEND=file - - HOTKEY_PASSWORD=password # test purposes only - volumes: - - ssh:/root/.ssh - zetaclient0: - image: zetanode:latest - container_name: zetaclient0 - build: - context: .. - dockerfile: Dockerfile-localnet - hostname: zetaclient0 - networks: - mynetwork: - ipv4_address: 172.20.0.21 entrypoint: ["/root/start-zetaclientd.sh", "import-data"] - environment: - - ETHDEV_ENDPOINT=http://eth:8545 - - HOTKEY_BACKEND=file - - HOTKEY_PASSWORD=password # test purposes only - volumes: - - ssh:/root/.ssh zetaclient1: - image: zetanode:latest - container_name: zetaclient1 - build: - context: .. - dockerfile: Dockerfile-localnet - hostname: zetaclient1 - networks: - mynetwork: - ipv4_address: 172.20.0.22 entrypoint: ["/root/start-zetaclientd.sh", "import-data"] - environment: - - ETHDEV_ENDPOINT=http://eth:8545 - - HOTKEY_BACKEND=file - - HOTKEY_PASSWORD=password # test purposes only - volumes: - - ssh:/root/.ssh - - eth: - image: ethereum/client-go:v1.10.26 - container_name: eth - hostname: eth - ports: - - "8545:8545" - networks: - mynetwork: - ipv4_address: 172.20.0.100 - entrypoint: ["geth", "--dev", "--http", "--http.addr", "172.20.0.100", "--http.vhosts", "*", "--http.api", "eth,web3,net", "--http.corsdomain", "https://remix.ethereum.org", "--dev.period", "2"] - - bitcoin: - image: ruimarinho/bitcoin-core:22 # version 23 is not working with btcd 0.22.0 due to change in createwallet rpc - container_name: bitcoin - hostname: bitcoin - networks: - mynetwork: - ipv4_address: 172.20.0.101 - ports: - - "18443:18443" - command: - -printtoconsole - -regtest=1 - -rpcallowip=0.0.0.0/0 - -rpcbind=0.0.0.0 - -rpcauth=smoketest:63acf9b8dccecce914d85ff8c044b78b$$5892f9bbc84f4364e79f0970039f88bdd823f168d4acc76099ab97b14a766a99 - -txindex=1 orchestrator: - image: orchestrator:latest - tty: true - container_name: orchestrator - build: - context: .. - dockerfile: contrib/localnet/orchestrator/Dockerfile - depends_on: - - zetacore0 - - eth - hostname: orchestrator - networks: - mynetwork: - ipv4_address: 172.20.0.2 - entrypoint: ["/work/start-zetae2e.sh", "local","import-data"] - volumes: - - ssh:/root/.ssh \ No newline at end of file + entrypoint: ["/work/start-zetae2e.sh", "local","import-data"] \ No newline at end of file From 92af96b0d549b0fc8a463579f065104bcccfc12d Mon Sep 17 00:00:00 2001 From: Tanmay Date: Thu, 20 Jun 2024 13:49:18 -0400 Subject: [PATCH 4/8] add rosetta script --- Makefile | 2 +- contrib/localnet/docker-compose-import-data.yml | 3 +-- contrib/localnet/scripts/start-rosetta.sh | 14 ++++++++++++++ contrib/localnet/scripts/start-zetacored.sh | 2 ++ 4 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 contrib/localnet/scripts/start-rosetta.sh diff --git a/Makefile b/Makefile index 925a0cf237..7a5da4cad8 100644 --- a/Makefile +++ b/Makefile @@ -254,7 +254,7 @@ start-localnet: zetanode start-e2e-import-mainnet-test: zetanode @echo "--> Starting e2e import-data test" - cd contrib/localnet/ && $(DOCKER) compose -f docker-compose.yml -f docker-compose-import-data.yml up -d + cd contrib/localnet/ && $(DOCKER) compose -f docker-compose.yml -f docker-compose-import-data.yml up -d --build-arg MODIFY_GENESIS='disable' . stop-test: cd contrib/localnet/ && $(DOCKER) compose down --remove-orphans diff --git a/contrib/localnet/docker-compose-import-data.yml b/contrib/localnet/docker-compose-import-data.yml index b8bfc50cbe..638d67a2fb 100644 --- a/contrib/localnet/docker-compose-import-data.yml +++ b/contrib/localnet/docker-compose-import-data.yml @@ -17,8 +17,7 @@ networks: services: rosetta: - entrypoint: ["zetacored", "rosetta", "--tendermint", "zetacore0:26657", "--grpc", "zetacore0:9090", "--network", "athens_101-1", "--blockchain", "zetacore" ,"--retries", "500"] - + entrypoint: ["/root/start-rosetta.sh"] zetacore0: entrypoint: ["/root/start-zetacored.sh", "2","import-data"] diff --git a/contrib/localnet/scripts/start-rosetta.sh b/contrib/localnet/scripts/start-rosetta.sh new file mode 100644 index 0000000000..e675da6a6a --- /dev/null +++ b/contrib/localnet/scripts/start-rosetta.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +# This script is used to start the Rosetta API server for the Zetacore network. + +echo "Waiting for network to start producing blocks" +CURRENT_HEIGHT=0 +WAIT_HEIGHT=1 +while [[ $CURRENT_HEIGHT -lt $WAIT_HEIGHT ]] +do + CURRENT_HEIGHT=$(curl -s zetacore0:26657/status | jq '.result.sync_info.latest_block_height' | tr -d '"') + sleep 5 +done + +zetacored rosetta --tendermint zetacore0:26657 --grpc zetacore0:9090 --network athens_101-1 --blockchain zetacore \ No newline at end of file diff --git a/contrib/localnet/scripts/start-zetacored.sh b/contrib/localnet/scripts/start-zetacored.sh index 7b7ce23eb6..9852fff434 100755 --- a/contrib/localnet/scripts/start-zetacored.sh +++ b/contrib/localnet/scripts/start-zetacored.sh @@ -4,6 +4,8 @@ # It initializes the nodes and creates the genesis.json file # It also starts the nodes # The number of nodes is passed as an first argument to the script +# The second argument is optional and can have the following value: +# - import-data: import data into the genesis file /usr/sbin/sshd From 2e005270721785cd6575af5b982815b2969e5f79 Mon Sep 17 00:00:00 2001 From: Tanmay Date: Thu, 20 Jun 2024 13:52:48 -0400 Subject: [PATCH 5/8] download import data --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 7a5da4cad8..0c3e17b293 100644 --- a/Makefile +++ b/Makefile @@ -254,7 +254,7 @@ start-localnet: zetanode start-e2e-import-mainnet-test: zetanode @echo "--> Starting e2e import-data test" - cd contrib/localnet/ && $(DOCKER) compose -f docker-compose.yml -f docker-compose-import-data.yml up -d --build-arg MODIFY_GENESIS='disable' . + cd contrib/localnet/ && ./scripts/import-data.sh mainnet && $(DOCKER) compose -f docker-compose.yml -f docker-compose-import-data.yml up -d stop-test: cd contrib/localnet/ && $(DOCKER) compose down --remove-orphans From 999b2220f88ee6fd76eb0056b52d40be3dd74100 Mon Sep 17 00:00:00 2001 From: Tanmay Date: Thu, 20 Jun 2024 14:09:49 -0400 Subject: [PATCH 6/8] remove unused params --- contrib/localnet/docker-compose-import-data.yml | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/contrib/localnet/docker-compose-import-data.yml b/contrib/localnet/docker-compose-import-data.yml index 638d67a2fb..c955df3eb6 100644 --- a/contrib/localnet/docker-compose-import-data.yml +++ b/contrib/localnet/docker-compose-import-data.yml @@ -8,13 +8,6 @@ version: "3" # - A Bitcoin node (bitcoin) # - A Rosetta API (rosetta) # - An orchestrator to manage interaction with the localnet (orchestrator) - -networks: - mynetwork: - ipam: - config: - - subnet: 172.20.0.0/24 - services: rosetta: entrypoint: ["/root/start-rosetta.sh"] @@ -28,10 +21,10 @@ services: entrypoint: ["/root/start-zetacored.sh", "2","import-data"] zetaclient0: - entrypoint: ["/root/start-zetaclientd.sh", "import-data"] + entrypoint: ["/root/start-zetaclientd.sh"] zetaclient1: - entrypoint: ["/root/start-zetaclientd.sh", "import-data"] + entrypoint: ["/root/start-zetaclientd.sh"] orchestrator: entrypoint: ["/work/start-zetae2e.sh", "local","import-data"] \ No newline at end of file From c91ffeb844b9b0b3ab5dbc1b6cf76f1b12863bde Mon Sep 17 00:00:00 2001 From: Tanmay Date: Thu, 20 Jun 2024 14:12:22 -0400 Subject: [PATCH 7/8] remove unused params --- contrib/localnet/docker-compose-import-data.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/localnet/docker-compose-import-data.yml b/contrib/localnet/docker-compose-import-data.yml index c955df3eb6..19f4068ad5 100644 --- a/contrib/localnet/docker-compose-import-data.yml +++ b/contrib/localnet/docker-compose-import-data.yml @@ -27,4 +27,4 @@ services: entrypoint: ["/root/start-zetaclientd.sh"] orchestrator: - entrypoint: ["/work/start-zetae2e.sh", "local","import-data"] \ No newline at end of file + entrypoint: ["/work/start-zetae2e.sh", "local"] \ No newline at end of file From a25028dcf876f4abb72ce0f5f7b93cfe56180652 Mon Sep 17 00:00:00 2001 From: Tanmay Date: Thu, 20 Jun 2024 17:19:52 -0400 Subject: [PATCH 8/8] generate files --- changelog.md | 1 + cmd/zetacored/parse_genesis.go | 7 ++++++- docs/cli/zetacored/zetacored_parse-genesis-file.md | 3 ++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/changelog.md b/changelog.md index d7bd6e96d7..4e666f1314 100644 --- a/changelog.md +++ b/changelog.md @@ -61,6 +61,7 @@ * [2329](https://github.com/zeta-chain/node/pull/2329) - fix TODOs in rpc unit tests * [2342](https://github.com/zeta-chain/node/pull/2342) - extend rpc unit tests with testing extension to include synthetic ethereum txs * [2299](https://github.com/zeta-chain/node/pull/2299) - add `zetae2e` command to deploy test contracts +* [2360](https://github.com/zeta-chain/node/pull/2360) - add stateful e2e tests. ### Fixes diff --git a/cmd/zetacored/parse_genesis.go b/cmd/zetacored/parse_genesis.go index 58053df36e..ec0a9bd313 100644 --- a/cmd/zetacored/parse_genesis.go +++ b/cmd/zetacored/parse_genesis.go @@ -123,7 +123,12 @@ func CmdParseGenesisFile() *cobra.Command { return cmd } -func ImportDataIntoFile(genDoc *types.GenesisDoc, importFile *types.GenesisDoc, cdc codec.Codec, modifyEnabled bool) error { +func ImportDataIntoFile( + genDoc *types.GenesisDoc, + importFile *types.GenesisDoc, + cdc codec.Codec, + modifyEnabled bool, +) error { appState, err := genutiltypes.GenesisStateFromGenDoc(*genDoc) if err != nil { diff --git a/docs/cli/zetacored/zetacored_parse-genesis-file.md b/docs/cli/zetacored/zetacored_parse-genesis-file.md index 44bcb41424..a7b66ebb73 100644 --- a/docs/cli/zetacored/zetacored_parse-genesis-file.md +++ b/docs/cli/zetacored/zetacored_parse-genesis-file.md @@ -9,7 +9,8 @@ zetacored parse-genesis-file [import-genesis-file] [optional-genesis-file] [flag ### Options ``` - -h, --help help for parse-genesis-file + -h, --help help for parse-genesis-file + --modify Modify the genesis file before importing ``` ### Options inherited from parent commands