Commit 47854533 authored by OptimismBot's avatar OptimismBot Committed by GitHub

Merge pull request #5729 from ethereum-optimism/hamdi/fd.checked.batch.index

[fault-detector] current batch index
parents df65becb 78db51b4
...@@ -46,7 +46,7 @@ type State = { ...@@ -46,7 +46,7 @@ type State = {
fpw: number fpw: number
oo: OutputOracle<any> oo: OutputOracle<any>
messenger: CrossChainMessenger messenger: CrossChainMessenger
highestCheckedBatchIndex: number currentBatchIndex: number
diverged: boolean diverged: boolean
} }
...@@ -254,27 +254,22 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> { ...@@ -254,27 +254,22 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> {
// but it happens often on testnets because the FPW is very short. // but it happens often on testnets because the FPW is very short.
if (firstUnfinalized === undefined) { if (firstUnfinalized === undefined) {
this.logger.info(`no unfinalized batches found, starting from latest`) this.logger.info(`no unfinalized batches found, starting from latest`)
this.state.highestCheckedBatchIndex = ( this.state.currentBatchIndex = (
await this.state.oo.getTotalElements() await this.state.oo.getTotalElements()
).toNumber() ).toNumber()
} else { } else {
this.state.highestCheckedBatchIndex = firstUnfinalized this.state.currentBatchIndex = firstUnfinalized
} }
} else { } else {
this.state.highestCheckedBatchIndex = this.options.startBatchIndex this.state.currentBatchIndex = this.options.startBatchIndex
} }
this.logger.info(`starting height`, { this.logger.info('starting height', {
startBatchIndex: this.state.highestCheckedBatchIndex, startBatchIndex: this.state.currentBatchIndex,
}) })
// Set the initial metrics. // Set the initial metrics.
this.metrics.highestBatchIndex.set( this.metrics.isCurrentlyMismatched.set(0)
{
type: 'checked',
},
this.state.highestCheckedBatchIndex
)
} }
async routes(router: ExpressRouter): Promise<void> { async routes(router: ExpressRouter): Promise<void> {
...@@ -286,6 +281,8 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> { ...@@ -286,6 +281,8 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> {
} }
async main(): Promise<void> { async main(): Promise<void> {
const startMs = Date.now()
let latestBatchIndex: number let latestBatchIndex: number
try { try {
latestBatchIndex = (await this.state.oo.getTotalElements()).toNumber() latestBatchIndex = (await this.state.oo.getTotalElements()).toNumber()
...@@ -303,7 +300,7 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> { ...@@ -303,7 +300,7 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> {
return return
} }
if (this.state.highestCheckedBatchIndex >= latestBatchIndex) { if (this.state.currentBatchIndex >= latestBatchIndex) {
await sleep(15000) await sleep(15000)
return return
} else { } else {
...@@ -316,7 +313,7 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> { ...@@ -316,7 +313,7 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> {
} }
this.logger.info(`checking batch`, { this.logger.info(`checking batch`, {
batchIndex: this.state.highestCheckedBatchIndex, batchIndex: this.state.currentBatchIndex,
latestIndex: latestBatchIndex, latestIndex: latestBatchIndex,
}) })
...@@ -324,7 +321,7 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> { ...@@ -324,7 +321,7 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> {
try { try {
event = await findEventForStateBatch( event = await findEventForStateBatch(
this.state.oo, this.state.oo,
this.state.highestCheckedBatchIndex this.state.currentBatchIndex
) )
} catch (err) { } catch (err) {
this.logger.error(`got error when connecting to node`, { this.logger.error(`got error when connecting to node`, {
...@@ -528,20 +525,24 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> { ...@@ -528,20 +525,24 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> {
} }
} }
this.logger.info(`checked batch ok`, { const elapsedMs = Date.now() - startMs
batchIndex: this.state.highestCheckedBatchIndex,
})
this.state.highestCheckedBatchIndex++ // Mark the current batch index as checked
this.logger.info('checked batch ok', {
batchIndex: this.state.currentBatchIndex,
timeMs: elapsedMs,
})
this.metrics.highestBatchIndex.set( this.metrics.highestBatchIndex.set(
{ {
type: 'checked', type: 'checked',
}, },
this.state.highestCheckedBatchIndex this.state.currentBatchIndex
) )
// If we got through the above without throwing an error, we should be fine to reset. // If we got through the above without throwing an error, we should be
// fine to reset and move onto the next batch
this.state.diverged = false this.state.diverged = false
this.state.currentBatchIndex++
this.metrics.isCurrentlyMismatched.set(0) this.metrics.isCurrentlyMismatched.set(0)
} }
} }
......
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