Skip to content

Commit 8de316f

Browse files
tersecetan-status
andauthored
use eth_chainId instead of net_version (#3804)
* use eth_chainId instead of net_version * Update beacon_chain/eth1/eth1_monitor.nim Co-authored-by: Etan Kissling <[email protected]> * fix logging for Quantity types Co-authored-by: Etan Kissling <[email protected]>
1 parent 8b6f05a commit 8de316f

File tree

1 file changed

+30
-17
lines changed

1 file changed

+30
-17
lines changed

beacon_chain/eth1/eth1_monitor.nim

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,8 +1061,7 @@ proc detectPrimaryProviderComingOnline(m: Eth1Monitor) {.async.} =
10611061
# Use one of the get/request-type methods from
10621062
# https://github.com/ethereum/execution-apis/blob/v1.0.0-alpha.9/src/engine/specification.md#underlying-protocol
10631063
# which does nit take parameters and returns a small structure, to ensure
1064-
# this works with engine API endpoints. Either eth_chainId or eth_syncing
1065-
# works for this purpose.
1064+
# this works with engine API endpoints.
10661065
let testRequest = tempProvider.web3.provider.eth_syncing()
10671066

10681067
yield testRequest or sleepAsync(web3Timeouts)
@@ -1343,18 +1342,28 @@ proc startEth1Syncing(m: Eth1Monitor, delayBeforeStart: Duration) {.async.} =
13431342
contract = $m.depositContractAddress
13441343

13451344
if isFirstRun and m.eth1Network.isSome:
1346-
let
1347-
providerNetwork = awaitWithRetries m.dataProvider.web3.provider.net_version()
1348-
expectedNetwork = case m.eth1Network.get
1349-
of mainnet: "1"
1350-
of ropsten: "3"
1351-
of rinkeby: "4"
1352-
of goerli: "5"
1353-
of sepolia: "11155111"
1354-
if expectedNetwork != providerNetwork:
1355-
fatal "The specified web3 provider serves data for a different network",
1356-
expectedNetwork, providerNetwork
1357-
quit 1
1345+
try:
1346+
let
1347+
providerChain =
1348+
awaitWithRetries m.dataProvider.web3.provider.eth_chainId()
1349+
1350+
# https://eips.ethereum.org/EIPS/eip-155#list-of-chain-ids
1351+
expectedChain = case m.eth1Network.get
1352+
of mainnet: 1.Quantity
1353+
of ropsten: 3.Quantity
1354+
of rinkeby: 4.Quantity
1355+
of goerli: 5.Quantity
1356+
of sepolia: 11155111.Quantity # https://chainid.network/
1357+
if expectedChain != providerChain:
1358+
fatal "The specified Web3 provider serves data for a different chain",
1359+
expectedChain = distinctBase(expectedChain),
1360+
providerChain = distinctBase(providerChain)
1361+
quit 1
1362+
except CatchableError as exc:
1363+
# Typically because it's not synced through EIP-155, assuming this Web3
1364+
# endpoint has been otherwise working.
1365+
debug "startEth1Syncing: eth_chainId failed: ",
1366+
error = exc.msg
13581367

13591368
var mustUsePolling = m.forcePolling or
13601369
web3Url.startsWith("http://") or
@@ -1526,8 +1535,6 @@ proc testWeb3Provider*(web3Url: Uri,
15261535
web3 = mustSucceed "connect to web3 provider":
15271536
await newWeb3(
15281537
$web3Url, getJsonRpcRequestHeaders(jwtSecret))
1529-
networkVersion = mustSucceed "get network version":
1530-
awaitWithRetries web3.provider.net_version()
15311538
latestBlock = mustSucceed "get latest block":
15321539
awaitWithRetries web3.provider.eth_getBlockByNumber(blockId("latest"), false)
15331540
syncStatus = mustSucceed "get sync status":
@@ -1543,13 +1550,19 @@ proc testWeb3Provider*(web3Url: Uri,
15431550
awaitWithRetries web3.provider.eth_mining()
15441551

15451552
echo "Client Version: ", clientVersion
1546-
echo "Network Version: ", networkVersion
15471553
echo "Network Peers: ", peers
15481554
echo "Syncing: ", syncStatus
15491555
echo "Latest block: ", latestBlock.number.uint64
15501556
echo "Last Known Nonce: ", web3.lastKnownNonce
15511557
echo "Mining: ", mining
15521558

1559+
try:
1560+
let chainId = awaitWithRetries web3.provider.eth_chainId()
1561+
echo "Chain ID: ", chainId.uint64
1562+
except DataProviderFailure as exc:
1563+
# Typically because it's not synced through EIP-155.
1564+
echo "Web3 provider does not provide chain ID: " & exc.msg
1565+
15531566
let ns = web3.contractSender(DepositContract, depositContractAddress)
15541567
try:
15551568
let depositRoot = awaitWithRetries(

0 commit comments

Comments
 (0)