Commit 412688d5 authored by Richard Guan's avatar Richard Guan Committed by GitHub

Replace getNetwork() calls with getChainId() utility (#2535)

* refactor: replace calls to getNetwork() with getChainId util

* requested changes
parent f414d95f
---
'@eth-optimism/integration-tests': patch
'@eth-optimism/contracts': patch
'@eth-optimism/data-transport-layer': patch
'@eth-optimism/message-relayer': patch
---
Replace calls to getNetwork() with getChainId util
import { task } from 'hardhat/config'
import { providers } from 'ethers'
import { getChainId } from '@eth-optimism/core-utils'
import { die, logStderr } from '../test/shared/utils'
......@@ -13,22 +14,22 @@ task(
const providerA = new providers.JsonRpcProvider(replicaA)
const providerB = new providers.JsonRpcProvider(replicaB)
let netA
let netB
let chainIdA
let chainIdB
try {
netA = await providerA.getNetwork()
chainIdA = await getChainId(providerA)
} catch (e) {
console.error(`Error getting network from ${replicaA}:`)
console.error(`Error getting network chainId from ${replicaA}:`)
die(e)
}
try {
netB = await providerA.getNetwork()
chainIdB = await getChainId(providerB)
} catch (e) {
console.error(`Error getting network from ${replicaB}:`)
console.error(`Error getting network chainId from ${replicaB}:`)
die(e)
}
if (netA.chainId !== netB.chainId) {
if (chainIdA !== chainIdB) {
die('Chain IDs do not match')
return
}
......
/* Imports: External */
import { expectApprox, sleep } from '@eth-optimism/core-utils'
import { expectApprox, getChainId, sleep } from '@eth-optimism/core-utils'
import { Wallet, BigNumber, Contract, ContractFactory, constants } from 'ethers'
import { serialize } from '@ethersproject/transactions'
import { ethers } from 'hardhat'
......@@ -471,8 +471,7 @@ describe('Basic RPC tests', () => {
describe('eth_chainId', () => {
it('should get the correct chainid', async () => {
const { chainId } = await env.l2Provider.getNetwork()
expect(chainId).to.be.eq(L2_CHAINID)
expect(await getChainId(env.l2Provider)).to.be.eq(L2_CHAINID)
})
})
......
import { ethers, Contract } from 'ethers'
import { Provider } from '@ethersproject/abstract-provider'
import { Signer } from '@ethersproject/abstract-signer'
import { sleep, awaitCondition } from '@eth-optimism/core-utils'
import { sleep, awaitCondition, getChainId } from '@eth-optimism/core-utils'
import { HttpNetworkConfig } from 'hardhat/types'
import { getDeployConfig } from './deploy-config'
......@@ -270,8 +270,7 @@ export const getContractFromArtifact = async (
}
export const isHardhatNode = async (hre) => {
const { chainId } = await hre.ethers.provider.getNetwork()
return chainId === 31337
return (await getChainId(hre.ethers.provider)) === 31337
}
// Large balance to fund accounts with.
......
/* Imports: External */
import { BaseService, Metrics } from '@eth-optimism/common-ts'
import { StaticJsonRpcProvider } from '@ethersproject/providers'
import { sleep, toRpcHexString } from '@eth-optimism/core-utils'
import { getChainId, sleep, toRpcHexString } from '@eth-optimism/core-utils'
import { BigNumber } from 'ethers'
import { LevelUp } from 'levelup'
import axios from 'axios'
......@@ -127,9 +127,9 @@ export class L2IngestionService extends BaseService<L2IngestionServiceOptions> {
}
protected async checkConsistency(): Promise<void> {
const network = await this.state.l2RpcProvider.getNetwork()
const chainId = await getChainId(this.state.l2RpcProvider)
const shouldDoCheck = !(await this.state.db.getConsistencyCheckFlag())
if (shouldDoCheck && network.chainId === 69) {
if (shouldDoCheck && chainId === 69) {
this.logger.info('performing consistency check')
const highestBlock =
await this.state.db.getHighestSyncedUnconfirmedBlock()
......
/* Imports: External */
import { Signer } from 'ethers'
import { sleep } from '@eth-optimism/core-utils'
import { getChainId, sleep } from '@eth-optimism/core-utils'
import {
BaseServiceV2,
validators,
......@@ -80,12 +80,10 @@ export class MessageRelayerService extends BaseServiceV2<
this.options.l1RpcProvider
)
const l1Network = await this.state.wallet.provider.getNetwork()
const l1ChainId = l1Network.chainId
this.state.messenger = new CrossChainMessenger({
l1SignerOrProvider: this.state.wallet,
l2SignerOrProvider: this.options.l2RpcProvider,
l1ChainId,
l1ChainId: await getChainId(this.state.wallet.provider),
})
this.state.highestCheckedL2Tx = this.options.fromL2TransactionIndex || 1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment