Skip to content

Commit 586bd76

Browse files
Set finality violation conditions (#30)
1 parent 3c71fef commit 586bd76

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

chains/heads/tracker.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,12 +260,14 @@ func (t *tracker[HTH, S, ID, BLOCK_HASH]) Backfill(ctx context.Context, headWith
260260
}
261261

262262
if !t.instantFinality() {
263+
finalityViolationCondition := fmt.Sprintf("backfill %v", types.ErrFinalityViolated)
263264
// verify block hashes since calculateLatestFinalized made an additional RPC call
264265
err = t.verifyFinalizedBlockHashes(latestFinalized, prevHeadWithChain.LatestFinalizedHead())
265266
if err != nil {
266-
t.eng.EmitHealthErr(err)
267+
t.eng.SetHealthCond(finalityViolationCondition, err)
267268
return err
268269
}
270+
t.eng.ClearHealthCond(finalityViolationCondition)
269271
}
270272

271273
return t.backfill(ctx, headWithChain, latestFinalized)
@@ -291,20 +293,22 @@ func (t *tracker[HTH, S, ID, BLOCK_HASH]) handleNewHead(ctx context.Context, hea
291293
prevLatestFinalized = prevHead.LatestFinalizedHead()
292294
}
293295

296+
finalityViolationCondition := fmt.Sprintf("handleNewHead %v", types.ErrFinalityViolated)
294297
if prevLatestFinalized != nil && head.BlockNumber() < prevLatestFinalized.BlockNumber() {
295298
promOldHead.WithLabelValues(t.chainID.String()).Inc()
296299
t.log.Critical("Got very old block. Either a very deep re-org occurred, one of the RPC nodes has gotten far out of sync, or the chain went backwards in block numbers. This node may not function correctly without manual intervention.", "err", types.ErrFinalityViolated)
297300
oldBlockErr := fmt.Errorf("got very old block with number %d (highest seen was %d)", head.BlockNumber(), prevHead.BlockNumber())
298301
err := fmt.Errorf("%w: %w", oldBlockErr, types.ErrFinalityViolated)
299-
t.eng.EmitHealthErr(err)
302+
t.eng.SetHealthCond(finalityViolationCondition, err)
300303
return err
301304
}
302305

303306
if err := t.verifyFinalizedBlockHashes(head.LatestFinalizedHead(), prevHead); err != nil {
304307
t.log.Critical(err)
305-
t.eng.EmitHealthErr(err)
308+
t.eng.SetHealthCond(finalityViolationCondition, err)
306309
return err
307310
}
311+
t.eng.ClearHealthCond(finalityViolationCondition)
308312

309313
if err := t.headSaver.Save(ctx, head); ctx.Err() != nil {
310314
return nil

0 commit comments

Comments
 (0)