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 <etan@status.im> * fix logging for Quantity types Co-authored-by: Etan Kissling <etan@status.im>
This commit is contained in:
parent
baf38c3416
commit
b178999225
|
@ -1060,8 +1060,7 @@ proc detectPrimaryProviderComingOnline(m: Eth1Monitor) {.async.} =
|
||||||
# Use one of the get/request-type methods from
|
# 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
|
# 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
|
# which does nit take parameters and returns a small structure, to ensure
|
||||||
# this works with engine API endpoints. Either eth_chainId or eth_syncing
|
# this works with engine API endpoints.
|
||||||
# works for this purpose.
|
|
||||||
let testRequest = tempProvider.web3.provider.eth_syncing()
|
let testRequest = tempProvider.web3.provider.eth_syncing()
|
||||||
|
|
||||||
yield testRequest or sleepAsync(web3Timeouts)
|
yield testRequest or sleepAsync(web3Timeouts)
|
||||||
|
@ -1342,18 +1341,28 @@ proc startEth1Syncing(m: Eth1Monitor, delayBeforeStart: Duration) {.async.} =
|
||||||
contract = $m.depositContractAddress
|
contract = $m.depositContractAddress
|
||||||
|
|
||||||
if isFirstRun and m.eth1Network.isSome:
|
if isFirstRun and m.eth1Network.isSome:
|
||||||
let
|
try:
|
||||||
providerNetwork = awaitWithRetries m.dataProvider.web3.provider.net_version()
|
let
|
||||||
expectedNetwork = case m.eth1Network.get
|
providerChain =
|
||||||
of mainnet: "1"
|
awaitWithRetries m.dataProvider.web3.provider.eth_chainId()
|
||||||
of ropsten: "3"
|
|
||||||
of rinkeby: "4"
|
# https://eips.ethereum.org/EIPS/eip-155#list-of-chain-ids
|
||||||
of goerli: "5"
|
expectedChain = case m.eth1Network.get
|
||||||
of sepolia: "11155111"
|
of mainnet: 1.Quantity
|
||||||
if expectedNetwork != providerNetwork:
|
of ropsten: 3.Quantity
|
||||||
fatal "The specified web3 provider serves data for a different network",
|
of rinkeby: 4.Quantity
|
||||||
expectedNetwork, providerNetwork
|
of goerli: 5.Quantity
|
||||||
quit 1
|
of sepolia: 11155111.Quantity # https://chainid.network/
|
||||||
|
if 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
|
||||||
|
# endpoint has been otherwise working.
|
||||||
|
debug "startEth1Syncing: eth_chainId failed: ",
|
||||||
|
error = exc.msg
|
||||||
|
|
||||||
var mustUsePolling = m.forcePolling or
|
var mustUsePolling = m.forcePolling or
|
||||||
web3Url.startsWith("http://") or
|
web3Url.startsWith("http://") or
|
||||||
|
@ -1525,8 +1534,6 @@ proc testWeb3Provider*(web3Url: Uri,
|
||||||
web3 = mustSucceed "connect to web3 provider":
|
web3 = mustSucceed "connect to web3 provider":
|
||||||
await newWeb3(
|
await newWeb3(
|
||||||
$web3Url, getJsonRpcRequestHeaders(jwtSecret))
|
$web3Url, getJsonRpcRequestHeaders(jwtSecret))
|
||||||
networkVersion = mustSucceed "get network version":
|
|
||||||
awaitWithRetries web3.provider.net_version()
|
|
||||||
latestBlock = mustSucceed "get latest block":
|
latestBlock = mustSucceed "get latest block":
|
||||||
awaitWithRetries web3.provider.eth_getBlockByNumber(blockId("latest"), false)
|
awaitWithRetries web3.provider.eth_getBlockByNumber(blockId("latest"), false)
|
||||||
syncStatus = mustSucceed "get sync status":
|
syncStatus = mustSucceed "get sync status":
|
||||||
|
@ -1542,13 +1549,19 @@ proc testWeb3Provider*(web3Url: Uri,
|
||||||
awaitWithRetries web3.provider.eth_mining()
|
awaitWithRetries web3.provider.eth_mining()
|
||||||
|
|
||||||
echo "Client Version: ", clientVersion
|
echo "Client Version: ", clientVersion
|
||||||
echo "Network Version: ", networkVersion
|
|
||||||
echo "Network Peers: ", peers
|
echo "Network Peers: ", peers
|
||||||
echo "Syncing: ", syncStatus
|
echo "Syncing: ", syncStatus
|
||||||
echo "Latest block: ", latestBlock.number.uint64
|
echo "Latest block: ", latestBlock.number.uint64
|
||||||
echo "Last Known Nonce: ", web3.lastKnownNonce
|
echo "Last Known Nonce: ", web3.lastKnownNonce
|
||||||
echo "Mining: ", mining
|
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)
|
let ns = web3.contractSender(DepositContract, depositContractAddress)
|
||||||
try:
|
try:
|
||||||
let depositRoot = awaitWithRetries(
|
let depositRoot = awaitWithRetries(
|
||||||
|
|
Loading…
Reference in New Issue