Commit 4611198b authored by OptimismBot's avatar OptimismBot Committed by GitHub

Merge pull request #5701 from ethereum-optimism/hamdi/fault.detector

fault-detector: add readme for custom op-chains (+ bugfix)
parents e5fc8961 64a6649a
...@@ -16,8 +16,13 @@ yarn build ...@@ -16,8 +16,13 @@ yarn build
## Running the service ## Running the service
Copy `.env.example` into a new file named `.env`, then set the environment variables listed there. Copy `.env.example` into a new file named `.env`, then set the environment variables listed there. Additional env setting are listed on `--help`. If running the fault detector against
Once your environment variables have been set, run the service via: a custom op chain, the necessary contract addresses must also be set associated with the op-chain.
- Bedrock: `OptimismPortal`
- Legacy: `StateCommitmentChain`
Once your environment variables or flags have been set, run the service via:
``` ```
yarn start yarn start
...@@ -34,8 +39,14 @@ yarn start ...@@ -34,8 +39,14 @@ yarn start
The `fault-detector` detects differences between the transaction results generated by your local Optimism node and the transaction results actually published to Ethereum. The `fault-detector` detects differences between the transaction results generated by your local Optimism node and the transaction results actually published to Ethereum.
Currently, transaction results take the form of [the root of the Optimism state trie](https://medium.com/@eiki1212/ethereum-state-trie-architecture-explained-a30237009d4e). Currently, transaction results take the form of [the root of the Optimism state trie](https://medium.com/@eiki1212/ethereum-state-trie-architecture-explained-a30237009d4e).
For every Optimism block, the state root of the block is published to the [`StateCommitmentChain`](https://github.com/ethereum-optimism/optimism/blob/39b7262cc3ffd78cd314341b8512b2683c1d9af7/packages/contracts/contracts/L1/rollup/StateCommitmentChain.sol) contract on Ethereum.
- For bedrock chains, the state root of the block is published to the [`L2OutputOracle`](https://github.com/ethereum-optimism/optimism/blob/39b7262cc3ffd78cd314341b8512b2683c1d9af7/packages/contracts-bedrock/contracts/L1/L2OutputOracle.sol) contract on Ethereum.
- ***Note***: The service accepts the `OptimismPortal` as a flag instead of the `L2OutputOracle` for backwards compatibility with early versions of these contracts. The `L2OutputOracle`
is inferred from the portal contract.
- For bedrock chains, the state root of the block is published to the [`StateCommitmentChain`](https://github.com/ethereum-optimism/optimism/blob/39b7262cc3ffd78cd314341b8512b2683c1d9af7/packages/contracts/contracts/L1/rollup/StateCommitmentChain.sol) contract on Ethereum.
We can therefore detect differences by, for each block, checking the state root of the given block as reported by an Optimism node and the state root as published to Ethereum. We can therefore detect differences by, for each block, checking the state root of the given block as reported by an Optimism node and the state root as published to Ethereum.
In order for the fault detector to differentiate between bedrock and legacy chains, please make sure to specify `--bedrock`.
We export a series of Prometheus metrics that you can use to trigger alerting when issues are detected. We export a series of Prometheus metrics that you can use to trigger alerting when issues are detected.
Check the list of available metrics via `yarn start --help`: Check the list of available metrics via `yarn start --help`:
...@@ -52,6 +63,9 @@ Options: ...@@ -52,6 +63,9 @@ Options:
--startbatchindex Batch index to start checking from. Setting it to -1 will cause the fault detector to find the first state batch index that has not yet passed the fault proof window (env: FAULT_DETECTOR__START_BATCH_INDEX, default value: -1) --startbatchindex Batch index to start checking from. Setting it to -1 will cause the fault detector to find the first state batch index that has not yet passed the fault proof window (env: FAULT_DETECTOR__START_BATCH_INDEX, default value: -1)
--loopintervalms Loop interval in milliseconds (env: FAULT_DETECTOR__LOOP_INTERVAL_MS) --loopintervalms Loop interval in milliseconds (env: FAULT_DETECTOR__LOOP_INTERVAL_MS)
--bedrock Whether or not the service is running against a Bedrock chain (env: FAULT_DETECTOR__BEDROCK, default value: false) --bedrock Whether or not the service is running against a Bedrock chain (env: FAULT_DETECTOR__BEDROCK, default value: false)
--optimismportaladdress [Custom Bedrock Chains] Deployed OptimismPortal contract address. Used to retrieve necessary info for ouput verification (env: FAULT_DETECTOR__OPTIMISM_PORTAL_ADDRESS, default 0x0)
--statecommitmentchainaddress [Custom Legacy Chains] Deployed StateCommitmentChain contract address. Used to fetch necessary info for output verification. (env: FAULT_DETECTOR__STATE_COMMITMENT_CHAIN_ADDRESS, default 0x0)
--port Port for the app server (env: FAULT_DETECTOR__PORT) --port Port for the app server (env: FAULT_DETECTOR__PORT)
--hostname Hostname for the app server (env: FAULT_DETECTOR__HOSTNAME) --hostname Hostname for the app server (env: FAULT_DETECTOR__HOSTNAME)
-h, --help display help for command -h, --help display help for command
......
...@@ -10,7 +10,6 @@ import { getChainId, sleep, toRpcHexString } from '@eth-optimism/core-utils' ...@@ -10,7 +10,6 @@ import { getChainId, sleep, toRpcHexString } from '@eth-optimism/core-utils'
import { import {
CONTRACT_ADDRESSES, CONTRACT_ADDRESSES,
CrossChainMessenger, CrossChainMessenger,
DeepPartial,
getOEContract, getOEContract,
L2ChainID, L2ChainID,
OEL1ContractsLike, OEL1ContractsLike,
...@@ -85,13 +84,13 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> { ...@@ -85,13 +84,13 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> {
optimismPortalAddress: { optimismPortalAddress: {
validator: validators.str, validator: validators.str,
default: ethers.constants.AddressZero, default: ethers.constants.AddressZero,
desc: '[Bedrock] Deployed OptimismPortal contract address. Used to retrieve necessary info for ouput verification. **Required** for custom op chains', desc: '[Custom Bedrock Chains] Deployed OptimismPortal contract address. Used to retrieve necessary info for ouput verification ',
public: true, public: true,
}, },
stateCommitmentChainAddress: { stateCommitmentChainAddress: {
validator: validators.str, validator: validators.str,
default: ethers.constants.AddressZero, default: ethers.constants.AddressZero,
desc: '[Legacy] Deployed StateCommitmentChain contract address. Used to fetch necessary info for output verification. **Required** for custom op chains', desc: '[Custom Legacy Chains] Deployed StateCommitmentChain contract address. Used to fetch necessary info for output verification.',
public: true, public: true,
}, },
}, },
...@@ -125,12 +124,21 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> { ...@@ -125,12 +124,21 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> {
* - Legacy: StateCommitmentChain to query for output roots. * - Legacy: StateCommitmentChain to query for output roots.
* *
* @param l2ChainId op chain id * @param l2ChainId op chain id
* @returns DeepPartial<OEL1ContractsLike> addresses needed just for the fault detector * @returns OEL1ContractsLike set of L1 contracts with only the required addresses set
*/ */
async getOEL1Contracts( async getOEL1Contracts(l2ChainId: number): Promise<OEL1ContractsLike> {
l2ChainId: number // CrossChainMessenger requires all address to be defined. Default to `AddressZero` to ignore unused contracts
): Promise<DeepPartial<OEL1ContractsLike>> { let contracts: OEL1ContractsLike = {
let contracts = {} as OEL1ContractsLike AddressManager: ethers.constants.AddressZero,
L1CrossDomainMessenger: ethers.constants.AddressZero,
L1StandardBridge: ethers.constants.AddressZero,
StateCommitmentChain: ethers.constants.AddressZero,
CanonicalTransactionChain: ethers.constants.AddressZero,
BondManager: ethers.constants.AddressZero,
OptimismPortal: ethers.constants.AddressZero,
L2OutputOracle: ethers.constants.AddressZero,
}
const chainType = this.options.bedrock ? 'bedrock' : 'legacy' const chainType = this.options.bedrock ? 'bedrock' : 'legacy'
this.logger.info(`Setting contracts for OP chain type: ${chainType}`) this.logger.info(`Setting contracts for OP chain type: ${chainType}`)
...@@ -157,7 +165,7 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> { ...@@ -157,7 +165,7 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> {
contracts.OptimismPortal = address contracts.OptimismPortal = address
this.logger.info('fetching L2OutputOracle contract from OptimismPortal') this.logger.info('fetching L2OutputOracle contract from OptimismPortal')
const opts = { address, signerOrPovider: this.options.l1RpcProvider } const opts = { address, signerOrProvider: this.options.l1RpcProvider }
const portalContract = getOEContract('OptimismPortal', l2ChainId, opts) const portalContract = getOEContract('OptimismPortal', l2ChainId, opts)
contracts.L2OutputOracle = await portalContract.L2_ORACLE() contracts.L2OutputOracle = await portalContract.L2_ORACLE()
} }
......
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