Skip to content

Commit

Permalink
chain-mon: migrate fault detector
Browse files Browse the repository at this point in the history
This commit migrates the fault-detector service to the chain-mon
package. This is useful because it moves towards standardizing all
of the offchain monitoring services into a single typescript package,
following the pattern that is already used in the repo.

This simplifies all of the linting and removes boilerplate, as the
services in chain-mon are all very similar and use the same
dependencies.

This also ports the tests from fault-detector to chain-mon, making
it the first tests in the repo. Longer term we could likely remove
the need to test using hardhat, but no need to do that for now.
This will make it easier to upgrade to a newer version of hardhat
as the version we are currently on only supports up to node v16
which is no longer LTS.

This change will save a bit of build time and a bit of time before
each commit because it will be one less package that needs to be
built or linted.
  • Loading branch information
tynes committed Jul 20, 2023
1 parent 8be2b53 commit 1d09a6a
Show file tree
Hide file tree
Showing 35 changed files with 101 additions and 929 deletions.
35 changes: 1 addition & 34 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ jobs:
- "packages/common-ts/node_modules"
- "packages/contracts-bedrock/node_modules"
- "packages/core-utils/node_modules"
- "packages/fault-detector/node_modules"
- "packages/replica-healthcheck/node_modules"
- "packages/sdk/node_modules"
- "packages/contracts-ts/node_modules"
Expand Down Expand Up @@ -1363,13 +1362,6 @@ workflows:
dependencies: "(common-ts|contracts-bedrock|core-utils|sdk)"
requires:
- pnpm-monorepo
- js-lint-test:
name: fault-detector-tests
coverage_flag: fault-detector-tests
package_name: fault-detector
dependencies: "(common-ts|core-utils|sdk)"
requires:
- pnpm-monorepo
- js-lint-test:
name: contracts-ts-tests
coverage_flag: contracts-ts-tests
Expand Down Expand Up @@ -1616,14 +1608,6 @@ workflows:
docker_target: wd-mon
context:
- oplabs-gcr
- docker-publish:
name: fault-detector-docker-publish
docker_file: ./ops/docker/Dockerfile.packages
docker_name: fault-detector
docker_tags: <<pipeline.git.revision>>,<<pipeline.git.branch>>
docker_target: fault-detector
context:
- oplabs-gcr
- hive-test:
name: hive-test-rpc
version: <<pipeline.git.revision>>
Expand Down Expand Up @@ -1661,7 +1645,7 @@ workflows:
type: approval
filters:
tags:
only: /^(fault-detector|proxyd|indexer|ci-builder|op-[a-z0-9\-]*)\/v.*/
only: /^(proxyd|indexer|ci-builder|op-[a-z0-9\-]*)\/v.*/
branches:
ignore: /.*/
- docker-release:
Expand Down Expand Up @@ -1728,23 +1712,6 @@ workflows:
- oplabs-gcr-release
requires:
- hold
- docker-release:
name: fault-detector-docker-release
filters:
tags:
only: /^fault-detector\/v.*/
branches:
ignore: /.*/
docker_file: ./ops/docker/Dockerfile.packages
docker_name: fault-detector
docker_tags: <<pipeline.git.revision>>,<<pipeline.git.branch>>
docker_target: fault-detector
docker_context: .
platforms: "linux/amd64,linux/arm64"
context:
- oplabs-gcr-release
requires:
- hold
- docker-build:
name: op-migrate-docker-release
filters:
Expand Down
3 changes: 1 addition & 2 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
/packages/contracts @ethereum-optimism/contract-reviewers
/packages/contracts-bedrock @ethereum-optimism/contract-reviewers
/packages/core-utils @ethereum-optimism/legacy-reviewers
/packages/chain-mon @smartcontracts
/packages/fault-detector @ethereum-optimism/devxpod
/packages/chain-mon @ethereum-optimism/devxpod
/packages/replica-healthcheck @ethereum-optimism/legacy-reviewers
/packages/sdk @ethereum-optimism/devxpod
/packages/atst @ethereum-optimism/devxpod
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/release-docker-canary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
# map the step outputs to job outputs
outputs:
fault-detector: ${{ steps.packages.outputs.fault-detector }}
fault-mon: ${{ steps.packages.outputs.fault-mon }}
balance-mon: ${{ steps.packages.outputs.balance-mon }}
drippie-mon: ${{ steps.packages.outputs.drippie-mon }}
wd-mon: ${{ steps.packages.outputs.wd-mon }}
Expand Down Expand Up @@ -43,10 +43,10 @@ jobs:
env:
CUSTOM_IMAGE_NAME: ${{ github.event.inputs.customImageName }}

fault-detector:
name: Publish Fault Detector Version ${{ needs.canary-publish.outputs.canary-docker-tag }}
fault-mon:
name: Publish fault-mon Version ${{ needs.canary-publish.outputs.canary-docker-tag }}
needs: canary-publish
if: needs.canary-publish.outputs.fault-detector != ''
if: needs.canary-publish.outputs.fault-mon != ''
runs-on: ubuntu-latest

steps:
Expand All @@ -66,9 +66,9 @@ jobs:
with:
context: .
file: ./ops/docker/Dockerfile.packages
target: fault-detector
target: fault-mon
push: true
tags: ethereumoptimism/fault-detector:${{ needs.canary-publish.outputs.canary-docker-tag }}
tags: ethereumoptimism/fault-mon:${{ needs.canary-publish.outputs.canary-docker-tag }}

balance-mon:
name: Publish Balance Monitor Version ${{ needs.canary-publish.outputs.canary-docker-tag }}
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
if: github.repository == 'ethereum-optimism/optimism'
# map the step outputs to job outputs
outputs:
fault-detector: ${{ steps.packages.outputs.fault-detector }}
fault-mon: ${{ steps.packages.outputs.fault-mon }}
balance-mon: ${{ steps.packages.outputs.drippie-mon }}
drippie-mon: ${{ steps.packages.outputs.drippie-mon }}
wd-mon: ${{ steps.packages.outputs.wd-mon }}
Expand Down Expand Up @@ -100,10 +100,10 @@ jobs:
GITCOMMIT=${{ steps.build_args.outputs.GITCOMMIT }}
GITVERSION=${{ steps.build_args.outputs.GITVERSION }}
fault-detector:
name: Publish Fault Detector Version ${{ needs.release.outputs.fault-detector }}
fault-mon:
name: Publish fault-mon Version ${{ needs.release.outputs.fault-mon }}
needs: release
if: needs.release.outputs.fault-detector != ''
if: needs.release.outputs.fault-mon != ''
runs-on: ubuntu-latest

steps:
Expand All @@ -123,9 +123,9 @@ jobs:
with:
context: .
file: ./ops/docker/Dockerfile.packages
target: fault-detector
target: fault-mon
push: true
tags: ethereumoptimism/fault-detector:${{ needs.release.outputs.fault-detector }},ethereumoptimism/fault-detector:latest
tags: ethereumoptimism/fault-mon:${{ needs.release.outputs.fault-mon }},ethereumoptimism/fault-mon:latest

wd-mon:
name: Publish Withdrawal Monitor Version ${{ needs.release.outputs.wd-mon }}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/tag-service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ on:
- op-proposer
- op-ufm
- proxyd
- indexer
- ci-builder
prerelease:
description: Increment major/minor/patch as prerelease?
required: false
Expand Down
6 changes: 1 addition & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,10 @@
{
"directory": "packages/chain-mon",
"changeProcessCWD": true
},
{
"directory": "packages/fault-detector",
"changeProcessCWD": true
}
],
"eslint.nodePath": "./node_modules/eslint/bin/",
"eslint.format.enable": true,
"editorconfig.generateAuto": false,
"files.trimTrailingWhitespace": true
}
}
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ Refer to the Directory Structure section below to understand which packages are
│ ├── <a href="./packages/contracts-bedrock">contracts-bedrock</a>: Bedrock smart contracts.
│ ├── <a href="./packages/core-utils">core-utils</a>: Low-level utilities that make building Optimism easier
│ ├── <a href="./packages/chain-mon">chain-mon</a>: Chain monitoring services
│ ├── <a href="./packages/fault-detector">fault-detector</a>: Service for detecting Sequencer faults
│ ├── <a href="./packages/replica-healthcheck">replica-healthcheck</a>: Service for monitoring the health of a replica node
│ └── <a href="./packages/sdk">sdk</a>: provides a set of tools for interacting with Optimism
├── <a href="./op-bindings">op-bindings</a>: Go bindings for Bedrock smart contracts.
Expand All @@ -80,7 +79,6 @@ Refer to the Directory Structure section below to understand which packages are
│ ├── <a href="./packages/common-ts">common-ts</a>: Common tools for building apps in TypeScript
│ ├── <a href="./packages/core-utils">core-utils</a>: Low-level utilities that make building Optimism easier
│ ├── <a href="./packages/chain-mon">chain-mon</a>: Chain monitoring services
│ ├── <a href="./packages/fault-detector">fault-detector</a>: Service for detecting Sequencer faults
│ ├── <a href="./packages/replica-healthcheck">replica-healthcheck</a>: Service for monitoring the health of a replica node
│ └── <a href="./packages/sdk">sdk</a>: provides a set of tools for interacting with Optimism
├── <a href="./indexer">indexer</a>: indexes and syncs transactions
Expand Down
1 change: 0 additions & 1 deletion codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,5 @@ flag_management:
- name: core-utils-tests
- name: dtl-tests
- name: chain-mon-tests
- name: fault-detector-tests
- name: replica-healthcheck-tests
- name: sdk-tests
6 changes: 3 additions & 3 deletions docs/op-stack/src/docs/releases/bedrock/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ lang: en-US

## Overview

The first release of the OP Stack codebase is called **Bedrock**.
The first release of the OP Stack codebase is called **Bedrock**.
The Bedrock release primarily consists of the core software required to run L2 blockchains and was originally designed to power an upgrade to the Optimism Mainnet network.

## Resources
Expand All @@ -29,6 +29,6 @@ Dive deep into the specifications for the Bedrock release in the [specs folder o
- [`op-batcher`](https://github.com/ethereum-optimism/optimism/tree/develop/op-batcher)
- [`op-proposer`](https://github.com/ethereum-optimism/optimism/tree/develop/op-proposer)
- [`contracts-bedrock`](https://github.com/ethereum-optimism/optimism/tree/develop/packages/contracts-bedrock)
- [`fault-detector`](https://github.com/ethereum-optimism/optimism/tree/develop/packages/fault-detector)
- [`fault-mon`](https://github.com/ethereum-optimism/optimism/tree/develop/packages/packages/chain-mon/src/fault-mon)
- [`sdk`](https://github.com/ethereum-optimism/optimism/tree/develop/packages/sdk)
- [`chain-mon`](https://github.com/ethereum-optimism/optimism/tree/develop/packages/chain-mon)
- [`chain-mon`](https://github.com/ethereum-optimism/optimism/tree/develop/packages/chain-mon)
10 changes: 4 additions & 6 deletions ops/docker/Dockerfile.packages
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,6 @@ COPY ./packages ./packages

RUN pnpm build

FROM base as fault-detector
WORKDIR /opt/optimism/packages/fault-detector
COPY ./ops/scripts/detector.sh .
CMD ["pnpm", "run", "start"]

FROM base as replica-healthcheck
WORKDIR /opt/optimism/packages/replica-healthcheck
ENTRYPOINT ["pnpm", "run", "start"]
Expand All @@ -92,11 +87,14 @@ FROM base as drippie-mon
WORKDIR /opt/optimism/packages/chain-mon
ENTRYPOINT ["pnpm", "run", "start:drippie-mon"]


FROM base as wd-mon
WORKDIR /opt/optimism/packages/chain-mon
ENTRYPOINT ["pnpm", "run", "start:wd-mon"]

FROM base as wallet-mon
WORKDIR /opt/optimism/packages/chain-mon
ENTRYPOINT ["pnpm", "run", "start:wallet-mon"]

from base as fault-mon
WORKDIR /opt/optimism/packages/chain-mon
ENTRYPOINT ["pnpm", "run", "start:fault-mon"]
2 changes: 1 addition & 1 deletion ops/scripts/ci-docker-tag-op-stack-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ DOCKER_REPO=$1
GIT_TAG=$2
GIT_SHA=$3

IMAGE_NAME=$(echo "$GIT_TAG" | grep -Eow '^(ci-builder|fault-detector|proxyd|indexer|op-[a-z0-9\-]*)' || true)
IMAGE_NAME=$(echo "$GIT_TAG" | grep -Eow '^(ci-builder|proxyd|indexer|op-[a-z0-9\-]*)' || true)
if [ -z "$IMAGE_NAME" ]; then
echo "image name could not be parsed from git tag '$GIT_TAG'"
exit 1
Expand Down
19 changes: 0 additions & 19 deletions ops/scripts/detector.sh

This file was deleted.

1 change: 0 additions & 1 deletion ops/tag-service/tag-service.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
'op-proposer': '0.10.14',
'proxyd': '3.16.0',
'indexer': '0.5.0',
'fault-detector': '0.6.3',
'ci-builder': '0.6.0'
}

Expand Down
28 changes: 28 additions & 0 deletions packages/chain-mon/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,31 @@ TWO_STEP_MONITOR__L2_RPC_PROVIDER=

# The block number to start monitoring from
TWO_STEP_MONITOR__START_BLOCK_NUMBER=

###############################################################################
# ↓ fault-mon ↓ #
###############################################################################

# --l1rpcprovider Provider for interacting with L1 (env: FAULT_DETECTOR__L1_RPC_PROVIDER)
FAULT_DETECTOR__L1_RPC_PROVIDER=
# --l2rpcprovider Provider for interacting with L2 (env: FAULT_DETECTOR__L2_RPC_PROVIDER)
FAULT_DETECTOR__L2_RPC_PROVIDER=
# --bedrock Whether or not the service is running against a Bedrock chain (env: FAULT_DETECTOR__BEDROCK)
BEDROCK=true

# Optional Params

# --startbatchindex Batch index to start checking from. For bedrock chains, this is the L2 height to start from (env: FAULT_DETECTOR__START_BATCH_INDEX)
# FAULT_DETECTOR__START_BATCH_INDEX=
# --optimismportaladdress [Custom Bedrock Chains] Deployed OptimismPortal contract address. Used to retrieve necessary info for ouput verification (env: FAULT_DETECTOR__OPTIMISM_PORTAL_ADDRESS)
# FAULT_DETECTOR__OPTIMISM_PORTAL_ADDRESS=
# --statecommitmentchainaddress [Custom Legacy Chains] Deployed StateCommitmentChain contract address. Used to fetch necessary info for output verification. (env: FAULT_DETECTOR__STATE_COMMITMENT_CHAIN_ADDRESS)
# FAULT_DETECTOR__STATE_COMMITMENT_CHAIN_ADDRESS=
# --loopintervalms Loop interval in milliseconds, only applies if service is set to loop (env: FAULT_DETECTOR__LOOP_INTERVAL_MS)
# FAULT_DETECTOR__LOOP_INTERVAL_MS=
# --port Port for the app server (env: FAULT_DETECTOR__PORT)
# FAULT_DETECTOR__PORT=
# --hostname Hostname for the app server (env: FAULT_DETECTOR__HOSTNAME)
# FAULT_DETECTOR__HOSTNAME=
# --loglevel Log level (env: FAULT_DETECTOR__LOG_LEVEL)
# FAULT_DETECTOR__LOG_LEVEL=
File renamed without changes.
8 changes: 7 additions & 1 deletion packages/chain-mon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
"start:wallet-mon": "ts-node ./src/wallet-mon/service.ts",
"start:drippie-mon": "ts-node ./src/drippie-mon/service.ts",
"start:wd-mon": "ts-node ./src/wd-mon/service.ts",
"test:coverage": "echo 'No tests defined.'",
"start:fault-mon": "ts-node ./src/fault-mon/service.ts",
"test": "hardhat test",
"test:coverage": "nyc hardhat test && nyc merge .nyc_output coverage.json",
"build": "tsc -p ./tsconfig.json",
"clean": "rimraf dist/ ./tsconfig.tsbuildinfo",
"lint": "pnpm lint:fix && pnpm lint:check",
Expand All @@ -40,12 +42,16 @@
"@eth-optimism/core-utils": "0.12.2",
"@eth-optimism/sdk": "3.1.0",
"ethers": "^5.7.0",
"dotenv": "^16.1.4",
"@types/dateformat": "^5.0.0",
"chai-as-promised": "^7.1.1",
"dateformat": "^4.5.1"
},
"devDependencies": {
"@ethersproject/abstract-provider": "^5.7.0",
"@nomiclabs/hardhat-ethers": "^2.0.6",
"@nomiclabs/hardhat-waffle": "^2.0.3",
"hardhat": "^2.9.6",
"ts-node": "^10.9.1"
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# @eth-optimism/fault-detector
# @eth-optimism/fault-mon

[![codecov](https://codecov.io/gh/ethereum-optimism/optimism/branch/develop/graph/badge.svg?token=0VTG7PG7YR&flag=fault-detector-tests)](https://codecov.io/gh/ethereum-optimism/optimism)

The `fault-detector` is a simple service for detecting discrepancies between your local view of the Optimism network and the L2 output proposals published to Ethereum.
The `fault-mon` is a simple service for detecting discrepancies between your local view of the Optimism network and the L2 output proposals published to Ethereum.

## Installation

Expand Down Expand Up @@ -34,7 +34,7 @@ pnpm start

## What this service does

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-mon` 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).

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.
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { Provider } from '@ethersproject/abstract-provider'
import { Contract, ethers } from 'ethers'
import dateformat from 'dateformat'

import { version } from '../package.json'
import { version } from '../../package.json'
import {
findFirstUnfinalizedStateBatchIndex,
findOutputForIndex,
Expand Down Expand Up @@ -387,7 +387,7 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> {
new Date(
(ethers.BigNumber.from(outputBlock.timestamp).toNumber() +
this.state.faultProofWindow) *
1000
1000
),
'mmmm dS, yyyy, h:MM:ss TT'
),
Expand Down
1 change: 1 addition & 0 deletions packages/chain-mon/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './balance-mon/service'
export * from './drippie-mon/service'
export * from './wd-mon/service'
export * from './wallet-mon/service'
export * from './fault-mon/index'
Loading

0 comments on commit 1d09a6a

Please sign in to comment.