11import { EpochCache } from '@aztec/epoch-cache' ;
22import { SlotNumber } from '@aztec/foundation/branded-types' ;
33import { merge , pick } from '@aztec/foundation/collection' ;
4+ import { FifoSet } from '@aztec/foundation/fifo-set' ;
45import { type Logger , createLogger } from '@aztec/foundation/log' ;
56import {
67 type InvalidCheckpointDetectedEvent ,
78 type L2BlockSourceEventEmitter ,
89 L2BlockSourceEvents ,
910 type ValidateCheckpointNegativeResult ,
1011} from '@aztec/stdlib/block' ;
11- import type { CheckpointInfo } from '@aztec/stdlib/checkpoint' ;
1212import { OffenseType } from '@aztec/stdlib/slashing' ;
1313
1414import EventEmitter from 'node:events' ;
@@ -20,6 +20,7 @@ const AttestationsBlockWatcherConfigKeys = [
2020 'slashAttestDescendantOfInvalidPenalty' ,
2121 'slashProposeInvalidAttestationsPenalty' ,
2222] as const ;
23+ const MAX_INVALID_CHECKPOINTS = 100 ;
2324
2425type AttestationsBlockWatcherConfig = Pick < SlasherConfig , ( typeof AttestationsBlockWatcherConfigKeys ) [ number ] > ;
2526
@@ -32,11 +33,8 @@ type AttestationsBlockWatcherConfig = Pick<SlasherConfig, (typeof AttestationsBl
3233export class AttestationsBlockWatcher extends ( EventEmitter as new ( ) => WatcherEmitter ) implements Watcher {
3334 private log : Logger = createLogger ( 'attestations-block-watcher' ) ;
3435
35- // Only keep track of the last N invalid checkpoints
36- private maxInvalidCheckpoints = 100 ;
37-
38- // All invalid archive roots seen
39- private invalidArchiveRoots : Set < string > = new Set ( ) ;
36+ // Recently seen invalid archive roots.
37+ private invalidArchiveRoots = FifoSet . withLimit < string > ( MAX_INVALID_CHECKPOINTS ) ;
4038
4139 private config : AttestationsBlockWatcherConfig ;
4240
@@ -98,8 +96,7 @@ export class AttestationsBlockWatcher extends (EventEmitter as new () => Watcher
9896 reason : validationResult . valid === false ? validationResult . reason : 'unknown' ,
9997 } ) ;
10098
101- // Store the invalid checkpoint
102- this . addInvalidCheckpoint ( event . validationResult . checkpoint ) ;
99+ this . invalidArchiveRoots . add ( checkpoint . archive . toString ( ) ) ;
103100
104101 // Slash the proposer of the invalid checkpoint
105102 this . slashProposer ( event . validationResult ) ;
@@ -181,14 +178,4 @@ export class AttestationsBlockWatcher extends (EventEmitter as new () => Watcher
181178 }
182179 }
183180 }
184-
185- private addInvalidCheckpoint ( checkpoint : CheckpointInfo ) {
186- this . invalidArchiveRoots . add ( checkpoint . archive . toString ( ) ) ;
187-
188- // Prune old entries if we exceed the maximum
189- if ( this . invalidArchiveRoots . size > this . maxInvalidCheckpoints ) {
190- const oldestKey = this . invalidArchiveRoots . keys ( ) . next ( ) . value ! ;
191- this . invalidArchiveRoots . delete ( oldestKey ) ;
192- }
193- }
194181}
0 commit comments