From e7ce3cacd075c8492462006dfddd806e9ed98a3b Mon Sep 17 00:00:00 2001 From: zah Date: Fri, 20 May 2022 18:26:07 +0300 Subject: [PATCH] Add support for the Ropsten beacon chain (#3648) --- .gitmodules | 4 +++ Makefile | 27 +++++++++++++++++++ beacon_chain/eth1/eth1_monitor.nim | 1 + beacon_chain/networking/network_metadata.nim | 18 +++++++++++++ beacon_chain/nimbus_beacon_node.nim | 3 ++- beacon_chain/spec/presets.nim | 2 ++ docker/dist/README.md.tpl | 2 +- docs/e2store.md | 2 +- .../src/attestation-performance.md | 4 +-- run-ropsten-beacon-node.sh | 12 +++++++++ vendor/merge-testnets | 1 + 11 files changed, 71 insertions(+), 5 deletions(-) create mode 100755 run-ropsten-beacon-node.sh create mode 160000 vendor/merge-testnets diff --git a/.gitmodules b/.gitmodules index 12db4603b..664412617 100644 --- a/.gitmodules +++ b/.gitmodules @@ -223,3 +223,7 @@ url = https://github.com/status-im/nim-toml-serialization.git ignore = untracked branch = master +[submodule "vendor/merge-testnets"] + path = vendor/merge-testnets + url = https://github.com/eth-clients/merge-testnets.git + branch = main diff --git a/Makefile b/Makefile index e81a1bfca..b0c4730c8 100644 --- a/Makefile +++ b/Makefile @@ -26,6 +26,7 @@ BASE_PORT := 9000 BASE_REST_PORT := 5052 BASE_METRICS_PORT := 8008 +ROPSTEN_WEB3_URL := "--web3-url=wss://ropsten.infura.io/ws/v3/809a18497dd74102b5f37d25aae3c85a" GOERLI_WEB3_URL := "--web3-url=wss://goerli.infura.io/ws/v3/809a18497dd74102b5f37d25aae3c85a" GNOSIS_WEB3_URLS := "--web3-url=wss://rpc.gnosischain.com/wss --web3-url=wss://xdai.poanetwork.dev/wss" @@ -399,6 +400,32 @@ prater-dev-deposit: | prater-build deposit_contract clean-prater: $(call CLEAN_NETWORK,prater) +### +### Ropsten +### +ropsten-build: | nimbus_beacon_node nimbus_signing_node + +# https://www.gnu.org/software/make/manual/html_node/Call-Function.html#Call-Function +ropsten: | ropsten-build + $(call CONNECT_TO_NETWORK,ropsten,nimbus_beacon_node,$(ROPSTEN_WEB3_URL)) + +ropsten-vc: | ropsten-build nimbus_validator_client + $(call CONNECT_TO_NETWORK_WITH_VALIDATOR_CLIENT,ropsten,nimbus_beacon_node,$(ROPSTEN_WEB3_URL)) + +ifneq ($(LOG_LEVEL), TRACE) +ropsten-dev: + + "$(MAKE)" LOG_LEVEL=TRACE $@ +else +ropsten-dev: | ropsten-build + $(call CONNECT_TO_NETWORK_IN_DEV_MODE,ropsten,nimbus_beacon_node,$(ROPSTEN_WEB3_URL)) +endif + +ropsten-dev-deposit: | ropsten-build deposit_contract + $(call MAKE_DEPOSIT,ropsten,$(ROPSTEN_WEB3_URL)) + +clean-ropsten: + $(call CLEAN_NETWORK,ropsten) + ### ### Gnosis chain binary ### diff --git a/beacon_chain/eth1/eth1_monitor.nim b/beacon_chain/eth1/eth1_monitor.nim index 772e9b410..ed55f6479 100644 --- a/beacon_chain/eth1/eth1_monitor.nim +++ b/beacon_chain/eth1/eth1_monitor.nim @@ -1292,6 +1292,7 @@ proc startEth1Syncing(m: Eth1Monitor, delayBeforeStart: Duration) {.async.} = providerNetwork = awaitWithRetries m.dataProvider.web3.provider.net_version() expectedNetwork = case m.eth1Network.get of mainnet: "1" + of ropsten: "3" of rinkeby: "4" of goerli: "5" if expectedNetwork != providerNetwork: diff --git a/beacon_chain/networking/network_metadata.nim b/beacon_chain/networking/network_metadata.nim index 8b15d4234..a0d836e7b 100644 --- a/beacon_chain/networking/network_metadata.nim +++ b/beacon_chain/networking/network_metadata.nim @@ -37,6 +37,7 @@ type Eth1Network* = enum mainnet + ropsten rinkeby goerli @@ -86,6 +87,7 @@ type const eth2NetworksDir = currentSourcePath.parentDir.replace('\\', '/') & "/../../vendor/eth2-networks" + mergeTestnetsDir = currentSourcePath.parentDir.replace('\\', '/') & "/../../vendor/merge-testnets" proc readBootstrapNodes*(path: string): seq[string] {.raises: [IOError, Defect].} = # Read a list of ENR values from a YAML file containing a flat list of entries @@ -115,6 +117,7 @@ proc loadEth2NetworkMetadata*(path: string, eth1Network = none(Eth1Network)): Et genesisPath = path & "/genesis.ssz" genesisDepositsSnapshotPath = path & "/genesis_deposit_contract_snapshot.ssz" configPath = path & "/config.yaml" + deployBlockPath = path & "/deploy_block.txt" depositContractBlockPath = path & "/deposit_contract_block.txt" bootstrapNodesPath = path & "/bootstrap_nodes.txt" bootEnrPath = path & "/boot_enr.yaml" @@ -134,8 +137,16 @@ proc loadEth2NetworkMetadata*(path: string, eth1Network = none(Eth1Network)): Et readFile(depositContractBlockPath).strip else: "" + + deployBlock = if fileExists(deployBlockPath): + readFile(deployBlockPath).strip + else: + "" + depositContractDeployedAt = if depositContractBlock.len > 0: BlockHashOrNumber.init(depositContractBlock) + elif deployBlock.len > 0: + BlockHashOrNumber.init(deployBlock) else: BlockHashOrNumber(isHash: false, number: 1) @@ -217,11 +228,16 @@ template eth2Network(path: string, eth1Network: Eth1Network): Eth2NetworkMetadat loadCompileTimeNetworkMetadata(eth2NetworksDir & "/" & path, some eth1Network) +template mergeTestnet(path: string, eth1Network: Eth1Network): Eth2NetworkMetadata = + loadCompileTimeNetworkMetadata(mergeTestnetsDir & "/" & path, + some eth1Network) + when not defined(gnosisChainBinary): when const_preset == "mainnet": const mainnetMetadata* = eth2Network("shared/mainnet", mainnet) praterMetadata* = eth2Network("shared/prater", goerli) + ropstenMetadata = mergeTestnet("ropsten-beacon-chain", ropsten) proc getMetadataForNetwork*(networkName: string): Eth2NetworkMetadata {.raises: [Defect, IOError].} = template loadRuntimeMetadata: auto = @@ -242,6 +258,8 @@ when not defined(gnosisChainBinary): mainnetMetadata of "prater": praterMetadata + of "ropsten": + ropstenMetadata else: loadRuntimeMetadata() else: diff --git a/beacon_chain/nimbus_beacon_node.nim b/beacon_chain/nimbus_beacon_node.nim index 36772fe3e..c13202e63 100644 --- a/beacon_chain/nimbus_beacon_node.nim +++ b/beacon_chain/nimbus_beacon_node.nim @@ -429,7 +429,8 @@ proc init*(T: type BeaconNode, if snapshotRes.isErr: fatal "Failed to locate the deposit contract deployment block", depositContract = cfg.DEPOSIT_CONTRACT_ADDRESS, - deploymentBlock = $depositContractDeployedAt + deploymentBlock = $depositContractDeployedAt, + err = snapshotRes.error quit 1 else: some snapshotRes.get diff --git a/beacon_chain/spec/presets.nim b/beacon_chain/spec/presets.nim index 6255370c5..8766b2855 100644 --- a/beacon_chain/spec/presets.nim +++ b/beacon_chain/spec/presets.nim @@ -169,6 +169,7 @@ when const_preset == "mainnet": # canonical network names include: # * 'mainnet' - there can be only one # * 'prater' - testnet + # * 'ropsten' - testnet # Must match the regex: [a-z0-9\-] CONFIG_NAME: "mainnet", @@ -271,6 +272,7 @@ elif const_preset == "minimal": # canonical network names include: # * 'mainnet' - there can be only one # * 'prater' - testnet + # * 'ropsten' - testnet # Must match the regex: [a-z0-9\-] CONFIG_NAME: "minimal", diff --git a/docker/dist/README.md.tpl b/docker/dist/README.md.tpl index 33dab2770..73825f252 100644 --- a/docker/dist/README.md.tpl +++ b/docker/dist/README.md.tpl @@ -67,5 +67,5 @@ The `prater` testnet runs on ```bash # using a local Goerli instance -WEB3_URL="ws://localhost:8545" ./run-mainnet-node.sh --max-peers=150 +WEB3_URL="ws://localhost:8545" ./run-prater-node.sh --max-peers=150 ``` diff --git a/docs/e2store.md b/docs/e2store.md index 6a3b762dd..125f5142f 100644 --- a/docs/e2store.md +++ b/docs/e2store.md @@ -178,7 +178,7 @@ Each era is identified by when it ends. Thus, the genesis era is era `0`, follow `.era` file names follow a simple convention: `---.era`: -* `config-name` is the `CONFIG_NAME` field of the runtime configation (`mainnet`, `prater`, etc) +* `config-name` is the `CONFIG_NAME` field of the runtime configation (`mainnet`, `prater`, `ropsten`, etc) * `era-number` is the number of the _first_ era stored in the file - for example, the genesis era file has number 0 - as a 5-digit 0-filled decimal integer * `short-era-root` is the first 4 bytes of the last historical root in the _last_ state in the era file, lower-case hex-encoded (8 characters), except the genesis era which instead uses the `genesis_validators_root` field from the genesis state. * The root is available as `state.historical_roots[era - 1]` except for genesis, which is `state.genesis_validators_root` diff --git a/docs/the_nimbus_book/src/attestation-performance.md b/docs/the_nimbus_book/src/attestation-performance.md index f8f047b64..5628cf1d6 100644 --- a/docs/the_nimbus_book/src/attestation-performance.md +++ b/docs/the_nimbus_book/src/attestation-performance.md @@ -32,9 +32,9 @@ The following options are available: Where: -- The `network` can either be `mainnet` or `prater` +- The `network` can either be `mainnet`, `prater` or `ropsten` -- The default location of the `db` is either `build/data/shared_mainnet_0/db` or `build/data/shared_prater_0/db` +- The default location of the `db` is either `build/data/shared_mainnet_0/db`, `build/data/shared_prater_0/db` or `build/data/shared_ropsten_0/db` Near the bottom, you should see diff --git a/run-ropsten-beacon-node.sh b/run-ropsten-beacon-node.sh new file mode 100755 index 000000000..56a85c8a3 --- /dev/null +++ b/run-ropsten-beacon-node.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +# Copyright (c) 2020-2021 Status Research & Development GmbH. Licensed under +# either of: +# - Apache License, version 2.0 +# - MIT license +# at your option. This file may not be copied, modified, or distributed except +# according to those terms. + +cd "$(dirname $0)" +# Allow the binary to receive signals directly. +exec scripts/run-beacon-node.sh nimbus_beacon_node ropsten $@ diff --git a/vendor/merge-testnets b/vendor/merge-testnets new file mode 160000 index 000000000..5b1b44aa9 --- /dev/null +++ b/vendor/merge-testnets @@ -0,0 +1 @@ +Subproject commit 5b1b44aa912dd3433ba30d381345659c53918955