Commit 21ee72b3 authored by Kelvin Fichter's avatar Kelvin Fichter

feat(ctb): nicer error for wrong RPC

Gives users a nicer error when they provide the L2 RPC endpoint for the
L1 node.
parent b1b35c92
---
'@eth-optimism/data-transport-layer': patch
---
Give users a nicer revert when connected to wrong RPC
/* Imports: External */ /* Imports: External */
import { fromHexString, sleep } from '@eth-optimism/core-utils' import { fromHexString, getChainId, sleep } from '@eth-optimism/core-utils'
import { BaseService, Metrics } from '@eth-optimism/common-ts' import { BaseService, Metrics } from '@eth-optimism/common-ts'
import { TypedEvent } from '@eth-optimism/contracts/dist/types/common' import { TypedEvent } from '@eth-optimism/contracts/dist/types/common'
import { BaseProvider, StaticJsonRpcProvider } from '@ethersproject/providers' import { BaseProvider, StaticJsonRpcProvider } from '@ethersproject/providers'
...@@ -123,6 +123,14 @@ export class L1IngestionService extends BaseService<L1IngestionServiceOptions> { ...@@ -123,6 +123,14 @@ export class L1IngestionService extends BaseService<L1IngestionServiceOptions> {
this.state.l1RpcProvider = this.options.l1RpcProvider this.state.l1RpcProvider = this.options.l1RpcProvider
} }
// Make sure that the given provider is connected to L1 and not L2
const connectedChainId = await getChainId(this.state.l1RpcProvider)
if (connectedChainId === this.options.l2ChainId) {
throw new Error(
`Given L1 RPC provider is actually an L2 provider, please provide an L1 provider`
)
}
this.logger.info('Using AddressManager', { this.logger.info('Using AddressManager', {
addressManager: this.options.addressManager, addressManager: this.options.addressManager,
}) })
......
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