@@ -1060,8 +1060,7 @@ proc detectPrimaryProviderComingOnline(m: Eth1Monitor) {.async.} =
10601060 # Use one of the get/request-type methods from
10611061 # https://github.com/ethereum/execution-apis/blob/v1.0.0-alpha.9/src/engine/specification.md#underlying-protocol
10621062 # which does nit take parameters and returns a small structure, to ensure
1063- # this works with engine API endpoints. Either eth_chainId or eth_syncing
1064- # works for this purpose.
1063+ # this works with engine API endpoints.
10651064 let testRequest = tempProvider.web3.provider.eth_syncing ()
10661065
10671066 yield testRequest or sleepAsync (web3Timeouts)
@@ -1342,18 +1341,28 @@ proc startEth1Syncing(m: Eth1Monitor, delayBeforeStart: Duration) {.async.} =
13421341 contract = $ m.depositContractAddress
13431342
13441343 if isFirstRun and m.eth1Network.isSome:
1345- let
1346- providerNetwork = awaitWithRetries m.dataProvider.web3.provider.net_version ()
1347- expectedNetwork = case m.eth1Network.get
1348- of mainnet: " 1"
1349- of ropsten: " 3"
1350- of rinkeby: " 4"
1351- of goerli: " 5"
1352- of sepolia: " 11155111"
1353- if expectedNetwork != providerNetwork:
1354- fatal " The specified web3 provider serves data for a different network" ,
1355- expectedNetwork, providerNetwork
1356- quit 1
1344+ try :
1345+ let
1346+ providerChain =
1347+ awaitWithRetries m.dataProvider.web3.provider.eth_chainId ()
1348+
1349+ # https://eips.ethereum.org/EIPS/eip-155#list-of-chain-ids
1350+ expectedChain = case m.eth1Network.get
1351+ of mainnet: 1 .Quantity
1352+ of ropsten: 3 .Quantity
1353+ of rinkeby: 4 .Quantity
1354+ of goerli: 5 .Quantity
1355+ of sepolia: 11155111 .Quantity # https://chainid.network/
1356+ if expectedChain != providerChain:
1357+ fatal " The specified Web3 provider serves data for a different chain" ,
1358+ expectedChain = distinctBase (expectedChain),
1359+ providerChain = distinctBase (providerChain)
1360+ quit 1
1361+ except CatchableError as exc:
1362+ # Typically because it's not synced through EIP-155, assuming this Web3
1363+ # endpoint has been otherwise working.
1364+ debug " startEth1Syncing: eth_chainId failed: " ,
1365+ error = exc.msg
13571366
13581367 var mustUsePolling = m.forcePolling or
13591368 web3Url.startsWith (" http://" ) or
@@ -1525,8 +1534,6 @@ proc testWeb3Provider*(web3Url: Uri,
15251534 web3 = mustSucceed " connect to web3 provider" :
15261535 await newWeb3 (
15271536 $ web3Url, getJsonRpcRequestHeaders (jwtSecret))
1528- networkVersion = mustSucceed " get network version" :
1529- awaitWithRetries web3.provider.net_version ()
15301537 latestBlock = mustSucceed " get latest block" :
15311538 awaitWithRetries web3.provider.eth_getBlockByNumber (blockId (" latest" ), false )
15321539 syncStatus = mustSucceed " get sync status" :
@@ -1542,13 +1549,19 @@ proc testWeb3Provider*(web3Url: Uri,
15421549 awaitWithRetries web3.provider.eth_mining ()
15431550
15441551 echo " Client Version: " , clientVersion
1545- echo " Network Version: " , networkVersion
15461552 echo " Network Peers: " , peers
15471553 echo " Syncing: " , syncStatus
15481554 echo " Latest block: " , latestBlock.number.uint64
15491555 echo " Last Known Nonce: " , web3.lastKnownNonce
15501556 echo " Mining: " , mining
15511557
1558+ try :
1559+ let chainId = awaitWithRetries web3.provider.eth_chainId ()
1560+ echo " Chain ID: " , chainId.uint64
1561+ except DataProviderFailure as exc:
1562+ # Typically because it's not synced through EIP-155.
1563+ echo " Web3 provider does not provide chain ID: " & exc.msg
1564+
15521565 let ns = web3.contractSender (DepositContract , depositContractAddress)
15531566 try :
15541567 let depositRoot = awaitWithRetries (
0 commit comments