Commit 0c769680 authored by Maurelian's avatar Maurelian

chore(c-mon): rename state batch to output

parent a6ed3392
---
'@eth-optimism/chain-mon': patch
---
Update language in fault-mon from batches to outputs
...@@ -31,22 +31,22 @@ export const findOutputForIndex = async ( ...@@ -31,22 +31,22 @@ export const findOutputForIndex = async (
} }
/** /**
* Finds the first state batch index that has not yet passed the fault proof window. * Finds the first L2 output index that has not yet passed the fault proof window.
* *
* @param oracle Output oracle contract. * @param oracle Output oracle contract.
* @returns Starting state root batch index. * @returns Starting L2 output index.
*/ */
export const findFirstUnfinalizedStateBatchIndex = async ( export const findFirstUnfinalizedOutputIndex = async (
oracle: Contract, oracle: Contract,
fpw: number, fpw: number,
logger?: Logger logger?: Logger
): Promise<number> => { ): Promise<number> => {
const latestBlock = await oracle.provider.getBlock('latest') const latestBlock = await oracle.provider.getBlock('latest')
const totalBatches = (await oracle.nextOutputIndex()).toNumber() const totalOutputs = (await oracle.nextOutputIndex()).toNumber()
// Perform a binary search to find the next batch that will pass the challenge period. // Perform a binary search to find the next batch that will pass the challenge period.
let lo = 0 let lo = 0
let hi = totalBatches let hi = totalOutputs
while (lo !== hi) { while (lo !== hi) {
const mid = Math.floor((lo + hi) / 2) const mid = Math.floor((lo + hi) / 2)
const outputData = await findOutputForIndex(oracle, mid, logger) const outputData = await findOutputForIndex(oracle, mid, logger)
...@@ -60,7 +60,7 @@ export const findFirstUnfinalizedStateBatchIndex = async ( ...@@ -60,7 +60,7 @@ export const findFirstUnfinalizedStateBatchIndex = async (
// Result will be zero if the chain is less than FPW seconds old. Only returns undefined in the // Result will be zero if the chain is less than FPW seconds old. Only returns undefined in the
// case that no batches have been submitted for an entire challenge period. // case that no batches have been submitted for an entire challenge period.
if (lo === totalBatches) { if (lo === totalOutputs) {
return undefined return undefined
} else { } else {
return lo return lo
......
...@@ -25,20 +25,17 @@ import { Contract, ethers } from 'ethers' ...@@ -25,20 +25,17 @@ import { Contract, ethers } from 'ethers'
import dateformat from 'dateformat' import dateformat from 'dateformat'
import { version } from '../../package.json' import { version } from '../../package.json'
import { import { findFirstUnfinalizedOutputIndex, findOutputForIndex } from './helpers'
findFirstUnfinalizedStateBatchIndex,
findOutputForIndex,
} from './helpers'
type Options = { type Options = {
l1RpcProvider: Provider l1RpcProvider: Provider
l2RpcProvider: Provider l2RpcProvider: Provider
startBatchIndex: number startOutputIndex: number
optimismPortalAddress?: string optimismPortalAddress?: string
} }
type Metrics = { type Metrics = {
highestBatchIndex: Gauge highestOutputIndex: Gauge
isCurrentlyMismatched: Gauge isCurrentlyMismatched: Gauge
nodeConnectionFailures: Gauge nodeConnectionFailures: Gauge
} }
...@@ -47,7 +44,7 @@ type State = { ...@@ -47,7 +44,7 @@ type State = {
faultProofWindow: number faultProofWindow: number
outputOracle: Contract outputOracle: Contract
messenger: CrossChainMessenger messenger: CrossChainMessenger
currentBatchIndex: number currentOutputIndex: number
diverged: boolean diverged: boolean
} }
...@@ -70,7 +67,7 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> { ...@@ -70,7 +67,7 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> {
validator: validators.provider, validator: validators.provider,
desc: 'Provider for interacting with L2', desc: 'Provider for interacting with L2',
}, },
startBatchIndex: { startOutputIndex: {
validator: validators.num, validator: validators.num,
default: -1, default: -1,
desc: 'The L2 height to start from', desc: 'The L2 height to start from',
...@@ -84,9 +81,9 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> { ...@@ -84,9 +81,9 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> {
}, },
}, },
metricsSpec: { metricsSpec: {
highestBatchIndex: { highestOutputIndex: {
type: Gauge, type: Gauge,
desc: 'Highest batch indices (checked and known)', desc: 'Highest output indices (checked and known)',
labels: ['type'], labels: ['type'],
}, },
isCurrentlyMismatched: { isCurrentlyMismatched: {
...@@ -200,30 +197,32 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> { ...@@ -200,30 +197,32 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> {
this.state.outputOracle = this.state.messenger.contracts.l1.L2OutputOracle this.state.outputOracle = this.state.messenger.contracts.l1.L2OutputOracle
// Figure out where to start syncing from. // Figure out where to start syncing from.
if (this.options.startBatchIndex === -1) { if (this.options.startOutputIndex === -1) {
this.logger.info('finding appropriate starting unfinalized batch') this.logger.info('finding appropriate starting unfinalized output')
const firstUnfinalized = await findFirstUnfinalizedStateBatchIndex( const firstUnfinalized = await findFirstUnfinalizedOutputIndex(
this.state.outputOracle, this.state.outputOracle,
this.state.faultProofWindow, this.state.faultProofWindow,
this.logger this.logger
) )
// We may not have an unfinalized batches in the case where no batches have been submitted // We may not have an unfinalized outputs in the case where no outputs have been submitted
// for the entire duration of the FAULTPROOFWINDOW. We generally do not expect this to happen on mainnet, // for the entire duration of the FAULTPROOFWINDOW. We generally do not expect this to happen on mainnet,
// but it happens often on testnets because the FAULTPROOFWINDOW is very short. // but it happens often on testnets because the FAULTPROOFWINDOW is very short.
if (firstUnfinalized === undefined) { if (firstUnfinalized === undefined) {
this.logger.info('no unfinalized batches found. skipping all batches.') this.logger.info(
const totalBatches = await this.state.outputOracle.nextOutputIndex() 'no unfinalized outputes found. skipping all outputes.'
this.state.currentBatchIndex = totalBatches.toNumber() - 1 )
const totalOutputes = await this.state.outputOracle.nextOutputIndex()
this.state.currentOutputIndex = totalOutputes.toNumber() - 1
} else { } else {
this.state.currentBatchIndex = firstUnfinalized this.state.currentOutputIndex = firstUnfinalized
} }
} else { } else {
this.state.currentBatchIndex = this.options.startBatchIndex this.state.currentOutputIndex = this.options.startOutputIndex
} }
this.logger.info('starting batch', { this.logger.info('starting output', {
batchIndex: this.state.currentBatchIndex, outputIndex: this.state.currentOutputIndex,
}) })
// Set the initial metrics. // Set the initial metrics.
...@@ -241,12 +240,12 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> { ...@@ -241,12 +240,12 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> {
async main(): Promise<void> { async main(): Promise<void> {
const startMs = Date.now() const startMs = Date.now()
let latestBatchIndex: number let latestOutputIndex: number
try { try {
const totalBatches = await this.state.outputOracle.nextOutputIndex() const totalOutputes = await this.state.outputOracle.nextOutputIndex()
latestBatchIndex = totalBatches.toNumber() - 1 latestOutputIndex = totalOutputes.toNumber() - 1
} catch (err) { } catch (err) {
this.logger.error('failed to query total # of batches', { this.logger.error('failed to query total # of outputes', {
error: err, error: err,
node: 'l1', node: 'l1',
section: 'nextOutputIndex', section: 'nextOutputIndex',
...@@ -259,34 +258,34 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> { ...@@ -259,34 +258,34 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> {
return return
} }
if (this.state.currentBatchIndex > latestBatchIndex) { if (this.state.currentOutputIndex > latestOutputIndex) {
this.logger.info('batch index is ahead of the oracle. waiting...', { this.logger.info('output index is ahead of the oracle. waiting...', {
batchIndex: this.state.currentBatchIndex, outputIndex: this.state.currentOutputIndex,
latestBatchIndex, latestOutputIndex,
}) })
await sleep(15000) await sleep(15000)
return return
} }
this.metrics.highestBatchIndex.set({ type: 'known' }, latestBatchIndex) this.metrics.highestOutputIndex.set({ type: 'known' }, latestOutputIndex)
this.logger.info('checking batch', { this.logger.info('checking output', {
batchIndex: this.state.currentBatchIndex, outputIndex: this.state.currentOutputIndex,
latestBatchIndex, latestOutputIndex,
}) })
let outputData: BedrockOutputData let outputData: BedrockOutputData
try { try {
outputData = await findOutputForIndex( outputData = await findOutputForIndex(
this.state.outputOracle, this.state.outputOracle,
this.state.currentBatchIndex, this.state.currentOutputIndex,
this.logger this.logger
) )
} catch (err) { } catch (err) {
this.logger.error('failed to fetch output associated with batch', { this.logger.error('failed to fetch output associated with output', {
error: err, error: err,
node: 'l1', node: 'l1',
section: 'findOutputForIndex', section: 'findOutputForIndex',
batchIndex: this.state.currentBatchIndex, outputIndex: this.state.currentOutputIndex,
}) })
this.metrics.nodeConnectionFailures.inc({ this.metrics.nodeConnectionFailures.inc({
layer: 'l1', layer: 'l1',
...@@ -397,20 +396,20 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> { ...@@ -397,20 +396,20 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> {
const elapsedMs = Date.now() - startMs const elapsedMs = Date.now() - startMs
// Mark the current batch index as checked // Mark the current output index as checked
this.logger.info('checked batch ok', { this.logger.info('checked output ok', {
batchIndex: this.state.currentBatchIndex, outputIndex: this.state.currentOutputIndex,
timeMs: elapsedMs, timeMs: elapsedMs,
}) })
this.metrics.highestBatchIndex.set( this.metrics.highestOutputIndex.set(
{ type: 'checked' }, { type: 'checked' },
this.state.currentBatchIndex this.state.currentOutputIndex
) )
// If we got through the above without throwing an error, we should be // If we got through the above without throwing an error, we should be
// fine to reset and move onto the next batch // fine to reset and move onto the next output
this.state.diverged = false this.state.diverged = false
this.state.currentBatchIndex++ this.state.currentOutputIndex++
this.metrics.isCurrentlyMismatched.set(0) this.metrics.isCurrentlyMismatched.set(0)
} }
} }
......
...@@ -8,7 +8,7 @@ import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers' ...@@ -8,7 +8,7 @@ import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'
import { expect } from './setup' import { expect } from './setup'
import { import {
findOutputForIndex, findOutputForIndex,
findFirstUnfinalizedStateBatchIndex, findFirstUnfinalizedOutputIndex,
} from '../../src/fault-mon' } from '../../src/fault-mon'
describe('helpers', () => { describe('helpers', () => {
...@@ -122,7 +122,7 @@ describe('helpers', () => { ...@@ -122,7 +122,7 @@ describe('helpers', () => {
}) })
it('should find the first batch older than the FPW', async () => { it('should find the first batch older than the FPW', async () => {
const first = await findFirstUnfinalizedStateBatchIndex( const first = await findFirstUnfinalizedOutputIndex(
L2OutputOracle, L2OutputOracle,
deployConfig.finalizationPeriodSeconds deployConfig.finalizationPeriodSeconds
) )
...@@ -164,7 +164,7 @@ describe('helpers', () => { ...@@ -164,7 +164,7 @@ describe('helpers', () => {
}) })
it('should return zero', async () => { it('should return zero', async () => {
const first = await findFirstUnfinalizedStateBatchIndex( const first = await findFirstUnfinalizedOutputIndex(
L2OutputOracle, L2OutputOracle,
deployConfig.finalizationPeriodSeconds deployConfig.finalizationPeriodSeconds
) )
...@@ -214,7 +214,7 @@ describe('helpers', () => { ...@@ -214,7 +214,7 @@ describe('helpers', () => {
}) })
it('should return undefined', async () => { it('should return undefined', async () => {
const first = await findFirstUnfinalizedStateBatchIndex( const first = await findFirstUnfinalizedOutputIndex(
L2OutputOracle, L2OutputOracle,
deployConfig.finalizationPeriodSeconds deployConfig.finalizationPeriodSeconds
) )
......
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