From fa2df66dc2a0487b5736e990da3a30abea565094 Mon Sep 17 00:00:00 2001 From: Dustin Brody Date: Mon, 27 Jun 2022 09:16:29 +0000 Subject: [PATCH 1/3] use eth_chainId instead of net_version --- beacon_chain/eth1/eth1_monitor.nim | 46 +++++++++++++++++++----------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/beacon_chain/eth1/eth1_monitor.nim b/beacon_chain/eth1/eth1_monitor.nim index b74cc0c724..9e0f86d680 100644 --- a/beacon_chain/eth1/eth1_monitor.nim +++ b/beacon_chain/eth1/eth1_monitor.nim @@ -1061,8 +1061,7 @@ proc detectPrimaryProviderComingOnline(m: Eth1Monitor) {.async.} = # Use one of the get/request-type methods from # https://github.com/ethereum/execution-apis/blob/v1.0.0-alpha.9/src/engine/specification.md#underlying-protocol # which does nit take parameters and returns a small structure, to ensure - # this works with engine API endpoints. Either eth_chainId or eth_syncing - # works for this purpose. + # this works with engine API endpoints. let testRequest = tempProvider.web3.provider.eth_syncing() yield testRequest or sleepAsync(web3Timeouts) @@ -1343,18 +1342,27 @@ proc startEth1Syncing(m: Eth1Monitor, delayBeforeStart: Duration) {.async.} = contract = $m.depositContractAddress if isFirstRun and m.eth1Network.isSome: - let - 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" - of sepolia: "11155111" - if expectedNetwork != providerNetwork: - fatal "The specified web3 provider serves data for a different network", - expectedNetwork, providerNetwork - quit 1 + try: + let + providerChain = + (awaitWithRetries m.dataProvider.web3.provider.eth_chainId()).uint64 + + # https://eips.ethereum.org/EIPS/eip-155#list-of-chain-ids + expectedChain = case m.eth1Network.get + of mainnet: 1'u64 + of ropsten: 3'u64 + of rinkeby: 4'u64 + of goerli: 5'u64 + of sepolia: 11155111'u64 # https://chainid.network/ + if expectedChain != providerChain: + fatal "The specified web3 provider serves data for a different chain", + expectedChain, providerChain + quit 1 + except CatchableError as exc: + # Typically because it's not synced through EIP-155, assuming this Web3 + # endpoint has been otherwise working. + debug "startEth1Syncing: eth_chainId failed: ", + error = exc.msg var mustUsePolling = m.forcePolling or web3Url.startsWith("http://") or @@ -1526,8 +1534,6 @@ proc testWeb3Provider*(web3Url: Uri, web3 = mustSucceed "connect to web3 provider": await newWeb3( $web3Url, getJsonRpcRequestHeaders(jwtSecret)) - networkVersion = mustSucceed "get network version": - awaitWithRetries web3.provider.net_version() latestBlock = mustSucceed "get latest block": awaitWithRetries web3.provider.eth_getBlockByNumber(blockId("latest"), false) syncStatus = mustSucceed "get sync status": @@ -1543,13 +1549,19 @@ proc testWeb3Provider*(web3Url: Uri, awaitWithRetries web3.provider.eth_mining() echo "Client Version: ", clientVersion - echo "Network Version: ", networkVersion echo "Network Peers: ", peers echo "Syncing: ", syncStatus echo "Latest block: ", latestBlock.number.uint64 echo "Last Known Nonce: ", web3.lastKnownNonce echo "Mining: ", mining + try: + let chainId = awaitWithRetries web3.provider.eth_chainId() + echo "Chain ID: ", chainId.uint64 + except DataProviderFailure as exc: + # Typically because it's not synced through EIP-155. + echo "Web3 provider does not provide chain ID: " & exc.msg + let ns = web3.contractSender(DepositContract, depositContractAddress) try: let depositRoot = awaitWithRetries( From e5be1e828d1fdeee9df4f5d3ef8283e9f1379ef8 Mon Sep 17 00:00:00 2001 From: tersec Date: Mon, 27 Jun 2022 10:53:37 +0000 Subject: [PATCH 2/3] Update beacon_chain/eth1/eth1_monitor.nim Co-authored-by: Etan Kissling --- beacon_chain/eth1/eth1_monitor.nim | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/beacon_chain/eth1/eth1_monitor.nim b/beacon_chain/eth1/eth1_monitor.nim index 9e0f86d680..8dd048cbcc 100644 --- a/beacon_chain/eth1/eth1_monitor.nim +++ b/beacon_chain/eth1/eth1_monitor.nim @@ -1345,15 +1345,15 @@ proc startEth1Syncing(m: Eth1Monitor, delayBeforeStart: Duration) {.async.} = try: let providerChain = - (awaitWithRetries m.dataProvider.web3.provider.eth_chainId()).uint64 + awaitWithRetries m.dataProvider.web3.provider.eth_chainId() # https://eips.ethereum.org/EIPS/eip-155#list-of-chain-ids expectedChain = case m.eth1Network.get - of mainnet: 1'u64 - of ropsten: 3'u64 - of rinkeby: 4'u64 - of goerli: 5'u64 - of sepolia: 11155111'u64 # https://chainid.network/ + of mainnet: 1.Quantity + of ropsten: 3.Quantity + of rinkeby: 4.Quantity + of goerli: 5.Quantity + of sepolia: 11155111.Quantity # https://chainid.network/ if expectedChain != providerChain: fatal "The specified web3 provider serves data for a different chain", expectedChain, providerChain From da9a1c4cfc38b12f39cfabecff23df34b105f729 Mon Sep 17 00:00:00 2001 From: Dustin Brody Date: Mon, 27 Jun 2022 11:32:44 +0000 Subject: [PATCH 3/3] fix logging for Quantity types --- beacon_chain/eth1/eth1_monitor.nim | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/beacon_chain/eth1/eth1_monitor.nim b/beacon_chain/eth1/eth1_monitor.nim index 8dd048cbcc..47d5989159 100644 --- a/beacon_chain/eth1/eth1_monitor.nim +++ b/beacon_chain/eth1/eth1_monitor.nim @@ -1355,8 +1355,9 @@ proc startEth1Syncing(m: Eth1Monitor, delayBeforeStart: Duration) {.async.} = of goerli: 5.Quantity of sepolia: 11155111.Quantity # https://chainid.network/ if expectedChain != providerChain: - fatal "The specified web3 provider serves data for a different chain", - expectedChain, providerChain + fatal "The specified Web3 provider serves data for a different chain", + expectedChain = distinctBase(expectedChain), + providerChain = distinctBase(providerChain) quit 1 except CatchableError as exc: # Typically because it's not synced through EIP-155, assuming this Web3