@aztec/sequencer-client 0.0.1-commit.96bb3f7 → 0.0.1-commit.993d52e

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/dest/client/sequencer-client.d.ts +12 -7
  2. package/dest/client/sequencer-client.d.ts.map +1 -1
  3. package/dest/client/sequencer-client.js +15 -4
  4. package/dest/config.d.ts +3 -4
  5. package/dest/config.d.ts.map +1 -1
  6. package/dest/config.js +28 -20
  7. package/dest/global_variable_builder/global_builder.d.ts +2 -4
  8. package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
  9. package/dest/global_variable_builder/global_builder.js +2 -2
  10. package/dest/index.d.ts +2 -2
  11. package/dest/index.d.ts.map +1 -1
  12. package/dest/index.js +1 -1
  13. package/dest/publisher/config.d.ts +31 -17
  14. package/dest/publisher/config.d.ts.map +1 -1
  15. package/dest/publisher/config.js +101 -42
  16. package/dest/publisher/sequencer-publisher-factory.d.ts +11 -3
  17. package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
  18. package/dest/publisher/sequencer-publisher-factory.js +13 -2
  19. package/dest/publisher/sequencer-publisher-metrics.d.ts +1 -1
  20. package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
  21. package/dest/publisher/sequencer-publisher-metrics.js +12 -4
  22. package/dest/publisher/sequencer-publisher.d.ts +16 -8
  23. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  24. package/dest/publisher/sequencer-publisher.js +80 -39
  25. package/dest/sequencer/checkpoint_proposal_job.d.ts +34 -9
  26. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
  27. package/dest/sequencer/checkpoint_proposal_job.js +184 -46
  28. package/dest/sequencer/checkpoint_voter.d.ts +3 -2
  29. package/dest/sequencer/checkpoint_voter.d.ts.map +1 -1
  30. package/dest/sequencer/checkpoint_voter.js +34 -10
  31. package/dest/sequencer/index.d.ts +1 -2
  32. package/dest/sequencer/index.d.ts.map +1 -1
  33. package/dest/sequencer/index.js +0 -1
  34. package/dest/sequencer/metrics.d.ts +17 -5
  35. package/dest/sequencer/metrics.d.ts.map +1 -1
  36. package/dest/sequencer/metrics.js +111 -30
  37. package/dest/sequencer/sequencer.d.ts +33 -13
  38. package/dest/sequencer/sequencer.d.ts.map +1 -1
  39. package/dest/sequencer/sequencer.js +95 -36
  40. package/dest/sequencer/timetable.d.ts +1 -4
  41. package/dest/sequencer/timetable.d.ts.map +1 -1
  42. package/dest/sequencer/timetable.js +1 -4
  43. package/dest/test/index.d.ts +3 -5
  44. package/dest/test/index.d.ts.map +1 -1
  45. package/dest/test/mock_checkpoint_builder.d.ts +19 -13
  46. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
  47. package/dest/test/mock_checkpoint_builder.js +31 -11
  48. package/dest/test/utils.d.ts +8 -8
  49. package/dest/test/utils.d.ts.map +1 -1
  50. package/dest/test/utils.js +12 -11
  51. package/package.json +30 -28
  52. package/src/client/sequencer-client.ts +25 -7
  53. package/src/config.ts +39 -28
  54. package/src/global_variable_builder/global_builder.ts +3 -3
  55. package/src/index.ts +1 -6
  56. package/src/publisher/config.ts +112 -43
  57. package/src/publisher/sequencer-publisher-factory.ts +23 -6
  58. package/src/publisher/sequencer-publisher-metrics.ts +7 -3
  59. package/src/publisher/sequencer-publisher.ts +96 -45
  60. package/src/sequencer/checkpoint_proposal_job.ts +273 -63
  61. package/src/sequencer/checkpoint_voter.ts +32 -7
  62. package/src/sequencer/index.ts +0 -1
  63. package/src/sequencer/metrics.ts +124 -32
  64. package/src/sequencer/sequencer.ts +118 -38
  65. package/src/sequencer/timetable.ts +6 -5
  66. package/src/test/index.ts +2 -4
  67. package/src/test/mock_checkpoint_builder.ts +75 -34
  68. package/src/test/utils.ts +24 -14
  69. package/dest/sequencer/block_builder.d.ts +0 -26
  70. package/dest/sequencer/block_builder.d.ts.map +0 -1
  71. package/dest/sequencer/block_builder.js +0 -129
  72. package/src/sequencer/block_builder.ts +0 -216
@@ -12,7 +12,7 @@ import type { DateProvider } from '@aztec/foundation/timer';
12
12
  import type { TypedEventEmitter } from '@aztec/foundation/types';
13
13
  import type { P2P } from '@aztec/p2p';
14
14
  import type { SlasherClientInterface } from '@aztec/slasher';
15
- import type { L2BlockNew, L2BlockSink, L2BlockSource, ValidateCheckpointResult } from '@aztec/stdlib/block';
15
+ import type { BlockData, L2BlockSink, L2BlockSource, ValidateCheckpointResult } from '@aztec/stdlib/block';
16
16
  import type { Checkpoint } from '@aztec/stdlib/checkpoint';
17
17
  import { getSlotAtTimestamp, getSlotStartBuildTimestamp } from '@aztec/stdlib/epoch-helpers';
18
18
  import {
@@ -25,7 +25,7 @@ import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
25
25
  import { pickFromSchema } from '@aztec/stdlib/schemas';
26
26
  import { MerkleTreeId } from '@aztec/stdlib/trees';
27
27
  import { Attributes, type TelemetryClient, type Tracer, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
28
- import { FullNodeCheckpointsBuilder, type ValidatorClient } from '@aztec/validator-client';
28
+ import { FullNodeCheckpointsBuilder, NodeKeystoreAdapter, type ValidatorClient } from '@aztec/validator-client';
29
29
 
30
30
  import EventEmitter from 'node:events';
31
31
 
@@ -57,8 +57,11 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
57
57
  private state = SequencerState.STOPPED;
58
58
  private metrics: SequencerMetrics;
59
59
 
60
- /** The last slot for which we attempted to vote when sync failed, to prevent duplicate attempts. */
61
- private lastSlotForVoteWhenSyncFailed: SlotNumber | undefined;
60
+ /** The last slot for which we attempted to perform our voting duties with degraded block production */
61
+ private lastSlotForFallbackVote: SlotNumber | undefined;
62
+
63
+ /** The last slot for which we logged "no committee" warning, to avoid spam */
64
+ private lastSlotForNoCommitteeWarning: SlotNumber | undefined;
62
65
 
63
66
  /** The last slot for which we triggered a checkpoint proposal job, to prevent duplicate attempts. */
64
67
  private lastSlotForCheckpointProposalJob: SlotNumber | undefined;
@@ -72,14 +75,6 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
72
75
  /** The maximum number of seconds that the sequencer can be into a slot to transition to a particular state. */
73
76
  protected timetable!: SequencerTimetable;
74
77
 
75
- // This shouldn't be here as this gets re-created each time we build/propose a block.
76
- // But we have a number of tests that abuse/rely on this class having a permanent publisher.
77
- // As long as those tests only configure a single publisher they will continue to work.
78
- // This will get re-assigned every time the sequencer goes to build a new block to a publisher that is valid
79
- // for the block proposer.
80
- // TODO(palla/mbps): Remove this field and fix tests
81
- protected publisher: SequencerPublisher | undefined;
82
-
83
78
  /** Config for the sequencer */
84
79
  protected config: ResolvedSequencerConfig = DefaultSequencerConfig;
85
80
 
@@ -131,10 +126,9 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
131
126
  );
132
127
  }
133
128
 
134
- /** Initializes the sequencer (precomputes tables and creates a publisher). Takes about 3s. */
135
- public async init() {
129
+ /** Initializes the sequencer (precomputes tables). Takes about 3s. */
130
+ public init() {
136
131
  getKzg();
137
- this.publisher = (await this.publisherFactory.create(undefined)).publisher;
138
132
  }
139
133
 
140
134
  /** Starts the sequencer and moves to IDLE state. */
@@ -153,7 +147,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
153
147
  public async stop(): Promise<void> {
154
148
  this.log.info(`Stopping sequencer`);
155
149
  this.setState(SequencerState.STOPPING, undefined, { force: true });
156
- this.publisher?.interrupt();
150
+ this.publisherFactory.interruptAll();
157
151
  await this.runningPromise?.stop();
158
152
  this.setState(SequencerState.STOPPED, undefined, { force: true });
159
153
  this.log.info('Stopped sequencer');
@@ -166,7 +160,6 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
166
160
  } catch (err) {
167
161
  this.emit('checkpoint-error', { error: err as Error });
168
162
  if (err instanceof SequencerTooSlowError) {
169
- // TODO(palla/mbps): Add missing states
170
163
  // Log as warn only if we had to abort halfway through the block proposal
171
164
  const logLvl = [SequencerState.INITIALIZING_CHECKPOINT, SequencerState.PROPOSER_CHECK].includes(
172
165
  err.proposedState,
@@ -202,7 +195,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
202
195
  const { slot, ts, now, epoch } = this.epochCache.getEpochAndSlotInNextL1Slot();
203
196
 
204
197
  // Check if we are synced and it's our slot, grab a publisher, check previous block invalidation, etc
205
- const checkpointProposalJob = await this.prepareCheckpointProposal(slot, ts, now);
198
+ const checkpointProposalJob = await this.prepareCheckpointProposal(epoch, slot, ts, now);
206
199
  if (!checkpointProposalJob) {
207
200
  return;
208
201
  }
@@ -234,6 +227,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
234
227
  */
235
228
  @trackSpan('Sequencer.prepareCheckpointProposal')
236
229
  private async prepareCheckpointProposal(
230
+ epoch: EpochNumber,
237
231
  slot: SlotNumber,
238
232
  ts: bigint,
239
233
  now: bigint,
@@ -263,6 +257,25 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
263
257
  return undefined;
264
258
  }
265
259
 
260
+ // If escape hatch is open for this epoch, do not start checkpoint proposal work and do not attempt invalidations.
261
+ // Still perform governance/slashing voting (as proposer) once per slot.
262
+ const isEscapeHatchOpen = await this.epochCache.isEscapeHatchOpen(epoch);
263
+
264
+ if (isEscapeHatchOpen) {
265
+ this.setState(SequencerState.PROPOSER_CHECK, slot);
266
+ const [canPropose, proposer] = await this.checkCanPropose(slot);
267
+ if (canPropose) {
268
+ await this.tryVoteWhenEscapeHatchOpen({ slot, proposer });
269
+ } else {
270
+ this.log.trace(`Escape hatch open but we are not proposer, skipping vote-only actions`, {
271
+ slot,
272
+ epoch,
273
+ proposer,
274
+ });
275
+ }
276
+ return undefined;
277
+ }
278
+
266
279
  // Next checkpoint follows from the last synced one
267
280
  const checkpointNumber = CheckpointNumber(syncedTo.checkpointNumber + 1);
268
281
 
@@ -287,12 +300,12 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
287
300
  }
288
301
 
289
302
  // Check that the slot is not taken by a block already (should never happen, since only us can propose for this slot)
290
- if (syncedTo.block && syncedTo.block.header.getSlot() >= slot) {
303
+ if (syncedTo.blockData && syncedTo.blockData.header.getSlot() >= slot) {
291
304
  this.log.warn(
292
305
  `Cannot propose block at next L2 slot ${slot} since that slot was taken by block ${syncedTo.blockNumber}`,
293
- { ...logCtx, block: syncedTo.block.header.toInspect() },
306
+ { ...logCtx, block: syncedTo.blockData.header.toInspect() },
294
307
  );
295
- this.metrics.recordBlockProposalPrecheckFailed('slot_already_taken');
308
+ this.metrics.recordCheckpointPrecheckFailed('slot_already_taken');
296
309
  return undefined;
297
310
  }
298
311
 
@@ -303,7 +316,6 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
303
316
  const proposerForPublisher = this.config.fishermanMode ? undefined : proposer;
304
317
  const { attestorAddress, publisher } = await this.publisherFactory.create(proposerForPublisher);
305
318
  this.log.verbose(`Created publisher at address ${publisher.getSenderAddress()} for attestor ${attestorAddress}`);
306
- this.publisher = publisher;
307
319
 
308
320
  // In fisherman mode, set the actual proposer's address for simulations
309
321
  if (this.config.fishermanMode && proposer) {
@@ -328,7 +340,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
328
340
  logCtx,
329
341
  );
330
342
  this.emit('proposer-rollup-check-failed', { reason: 'Rollup contract check failed', slot });
331
- this.metrics.recordBlockProposalPrecheckFailed('rollup_contract_check_failed');
343
+ this.metrics.recordCheckpointPrecheckFailed('rollup_contract_check_failed');
332
344
  return undefined;
333
345
  }
334
346
 
@@ -338,7 +350,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
338
350
  { ...logCtx, rollup: canProposeCheck, expectedSlot: slot },
339
351
  );
340
352
  this.emit('proposer-rollup-check-failed', { reason: 'Slot mismatch', slot });
341
- this.metrics.recordBlockProposalPrecheckFailed('slot_mismatch');
353
+ this.metrics.recordCheckpointPrecheckFailed('slot_mismatch');
342
354
  return undefined;
343
355
  }
344
356
 
@@ -348,15 +360,17 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
348
360
  { ...logCtx, rollup: canProposeCheck, expectedSlot: slot },
349
361
  );
350
362
  this.emit('proposer-rollup-check-failed', { reason: 'Block mismatch', slot });
351
- this.metrics.recordBlockProposalPrecheckFailed('block_number_mismatch');
363
+ this.metrics.recordCheckpointPrecheckFailed('block_number_mismatch');
352
364
  return undefined;
353
365
  }
354
366
 
355
367
  this.lastSlotForCheckpointProposalJob = slot;
368
+ await this.p2pClient.prepareForSlot(slot);
356
369
  this.log.info(`Preparing checkpoint proposal ${checkpointNumber} at slot ${slot}`, { ...logCtx, proposer });
357
370
 
358
371
  // Create and return the checkpoint proposal job
359
372
  return this.createCheckpointProposalJob(
373
+ epoch,
360
374
  slot,
361
375
  checkpointNumber,
362
376
  syncedTo.blockNumber,
@@ -368,6 +382,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
368
382
  }
369
383
 
370
384
  protected createCheckpointProposalJob(
385
+ epoch: EpochNumber,
371
386
  slot: SlotNumber,
372
387
  checkpointNumber: CheckpointNumber,
373
388
  syncedToBlockNumber: BlockNumber,
@@ -377,6 +392,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
377
392
  invalidateCheckpoint: InvalidateCheckpointRequest | undefined,
378
393
  ): CheckpointProposalJob {
379
394
  return new CheckpointProposalJob(
395
+ epoch,
380
396
  slot,
381
397
  checkpointNumber,
382
398
  syncedToBlockNumber,
@@ -389,6 +405,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
389
405
  this.p2pClient,
390
406
  this.worldState,
391
407
  this.l1ToL2MessageSource,
408
+ this.l2BlockSource,
392
409
  this.checkpointsBuilder,
393
410
  this.l2BlockSource,
394
411
  this.l1Constants,
@@ -400,11 +417,18 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
400
417
  this.metrics,
401
418
  this,
402
419
  this.setState.bind(this),
403
- this.log,
404
420
  this.tracer,
421
+ this.log.getBindings(),
405
422
  );
406
423
  }
407
424
 
425
+ /**
426
+ * Returns the current sequencer state.
427
+ */
428
+ public getState(): SequencerState {
429
+ return this.state;
430
+ }
431
+
408
432
  /**
409
433
  * Internal helper for setting the sequencer state and checks if we have enough time left in the slot to transition to the new state.
410
434
  * @param proposedState - The new state to transition to.
@@ -505,18 +529,18 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
505
529
  };
506
530
  }
507
531
 
508
- const block = await this.l2BlockSource.getL2BlockNew(blockNumber);
509
- if (!block) {
532
+ const blockData = await this.l2BlockSource.getBlockData(blockNumber);
533
+ if (!blockData) {
510
534
  // this shouldn't really happen because a moment ago we checked that all components were in sync
511
- this.log.error(`Failed to get L2 block ${blockNumber} from the archiver with all components in sync`);
535
+ this.log.error(`Failed to get L2 block data ${blockNumber} from the archiver with all components in sync`);
512
536
  return undefined;
513
537
  }
514
538
 
515
539
  return {
516
- block,
517
- blockNumber: block.number,
518
- checkpointNumber: block.checkpointNumber,
519
- archive: block.archive.root,
540
+ blockData,
541
+ blockNumber: blockData.header.getBlockNumber(),
542
+ checkpointNumber: blockData.checkpointNumber,
543
+ archive: blockData.archive.root,
520
544
  l1Timestamp,
521
545
  pendingChainValidationStatus,
522
546
  };
@@ -533,7 +557,10 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
533
557
  proposer = await this.epochCache.getProposerAttesterAddressInSlot(slot);
534
558
  } catch (e) {
535
559
  if (e instanceof NoCommitteeError) {
536
- this.log.warn(`Cannot propose at next L2 slot ${slot} since the committee does not exist on L1`);
560
+ if (this.lastSlotForNoCommitteeWarning !== slot) {
561
+ this.lastSlotForNoCommitteeWarning = slot;
562
+ this.log.warn(`Cannot propose at next L2 slot ${slot} since the committee does not exist on L1`);
563
+ }
537
564
  return [false, undefined];
538
565
  }
539
566
  this.log.error(`Error getting proposer for slot ${slot}`, e);
@@ -569,7 +596,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
569
596
  const { slot } = args;
570
597
 
571
598
  // Prevent duplicate attempts in the same slot
572
- if (this.lastSlotForVoteWhenSyncFailed === slot) {
599
+ if (this.lastSlotForFallbackVote === slot) {
573
600
  this.log.trace(`Already attempted to vote in slot ${slot} (skipping)`);
574
601
  return;
575
602
  }
@@ -601,7 +628,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
601
628
  }
602
629
 
603
630
  // Mark this slot as attempted
604
- this.lastSlotForVoteWhenSyncFailed = slot;
631
+ this.lastSlotForFallbackVote = slot;
605
632
 
606
633
  // Get a publisher for voting
607
634
  const { attestorAddress, publisher } = await this.publisherFactory.create(proposer);
@@ -636,7 +663,55 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
636
663
  }
637
664
 
638
665
  /**
639
- * Considers invalidating a checkpoint if the pending chain is invalid. Depends on how long the invalid checkpoint
666
+ * Tries to vote on slashing actions and governance proposals when escape hatch is open.
667
+ * This allows the sequencer to participate in voting without performing checkpoint proposal work.
668
+ */
669
+ @trackSpan('Sequencer.tryVoteWhenEscapeHatchOpen', ({ slot }) => ({ [Attributes.SLOT_NUMBER]: slot }))
670
+ protected async tryVoteWhenEscapeHatchOpen(args: {
671
+ slot: SlotNumber;
672
+ proposer: EthAddress | undefined;
673
+ }): Promise<void> {
674
+ const { slot, proposer } = args;
675
+
676
+ // Prevent duplicate attempts in the same slot
677
+ if (this.lastSlotForFallbackVote === slot) {
678
+ this.log.trace(`Already attempted to vote in slot ${slot} (escape hatch open, skipping)`);
679
+ return;
680
+ }
681
+
682
+ // Mark this slot as attempted
683
+ this.lastSlotForFallbackVote = slot;
684
+
685
+ const { attestorAddress, publisher } = await this.publisherFactory.create(proposer);
686
+
687
+ this.log.debug(`Escape hatch open for slot ${slot}, attempting vote-only actions`, { slot, attestorAddress });
688
+
689
+ const voter = new CheckpointVoter(
690
+ slot,
691
+ publisher,
692
+ attestorAddress,
693
+ this.validatorClient,
694
+ this.slasherClient,
695
+ this.l1Constants,
696
+ this.config,
697
+ this.metrics,
698
+ this.log,
699
+ );
700
+
701
+ const votesPromises = voter.enqueueVotes();
702
+ const votes = await Promise.all(votesPromises);
703
+
704
+ if (votes.every(p => !p)) {
705
+ this.log.debug(`No votes to enqueue for slot ${slot} (escape hatch open)`);
706
+ return;
707
+ }
708
+
709
+ this.log.info(`Voting in slot ${slot} (escape hatch open)`, { slot });
710
+ await publisher.sendRequests();
711
+ }
712
+
713
+ /**
714
+ * Considers invalidating a block if the pending chain is invalid. Depends on how long the invalid block
640
715
  * has been there without being invalidated and whether the sequencer is in the committee or not. We always
641
716
  * have the proposer try to invalidate, but if they fail, the sequencers in the committee are expected to try,
642
717
  * and if they fail, any sequencer will try as well.
@@ -788,6 +863,11 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
788
863
  return this.validatorClient?.getValidatorAddresses();
789
864
  }
790
865
 
866
+ /** Updates the publisher factory's node keystore adapter after a keystore reload. */
867
+ public updatePublisherNodeKeyStore(adapter: NodeKeystoreAdapter): void {
868
+ this.publisherFactory.updateNodeKeyStore(adapter);
869
+ }
870
+
791
871
  public getConfig() {
792
872
  return this.config;
793
873
  }
@@ -798,7 +878,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
798
878
  }
799
879
 
800
880
  type SequencerSyncCheckResult = {
801
- block?: L2BlockNew;
881
+ blockData?: BlockData;
802
882
  checkpointNumber: CheckpointNumber;
803
883
  blockNumber: BlockNumber;
804
884
  archive: Fr;
@@ -1,14 +1,15 @@
1
1
  import { createLogger } from '@aztec/aztec.js/log';
2
+ import {
3
+ CHECKPOINT_ASSEMBLE_TIME,
4
+ CHECKPOINT_INITIALIZATION_TIME,
5
+ DEFAULT_P2P_PROPAGATION_TIME,
6
+ MIN_EXECUTION_TIME,
7
+ } from '@aztec/stdlib/timetable';
2
8
 
3
- import { DEFAULT_ATTESTATION_PROPAGATION_TIME as DEFAULT_P2P_PROPAGATION_TIME } from '../config.js';
4
9
  import { SequencerTooSlowError } from './errors.js';
5
10
  import type { SequencerMetrics } from './metrics.js';
6
11
  import { SequencerState } from './utils.js';
7
12
 
8
- export const MIN_EXECUTION_TIME = 2;
9
- export const CHECKPOINT_INITIALIZATION_TIME = 1;
10
- export const CHECKPOINT_ASSEMBLE_TIME = 1;
11
-
12
13
  export class SequencerTimetable {
13
14
  /**
14
15
  * How late into the slot can we be to start working. Computed as the total time needed for assembling and publishing a block,
package/src/test/index.ts CHANGED
@@ -1,18 +1,16 @@
1
- import type { L1TxUtilsWithBlobs } from '@aztec/ethereum/l1-tx-utils-with-blobs';
1
+ import type { L1TxUtils } from '@aztec/ethereum/l1-tx-utils';
2
2
  import type { PublisherManager } from '@aztec/ethereum/publisher-manager';
3
3
  import type { PublicProcessorFactory } from '@aztec/simulator/server';
4
4
  import type { FullNodeCheckpointsBuilder, ValidatorClient } from '@aztec/validator-client';
5
5
 
6
6
  import { SequencerClient } from '../client/sequencer-client.js';
7
7
  import type { SequencerPublisherFactory } from '../publisher/sequencer-publisher-factory.js';
8
- import type { SequencerPublisher } from '../publisher/sequencer-publisher.js';
9
8
  import { Sequencer } from '../sequencer/sequencer.js';
10
9
  import type { SequencerTimetable } from '../sequencer/timetable.js';
11
10
 
12
11
  class TestSequencer_ extends Sequencer {
13
12
  declare public publicProcessorFactory: PublicProcessorFactory;
14
13
  declare public timetable: SequencerTimetable;
15
- declare public publisher: SequencerPublisher;
16
14
  declare public publisherFactory: SequencerPublisherFactory;
17
15
  declare public validatorClient: ValidatorClient;
18
16
  declare public checkpointsBuilder: FullNodeCheckpointsBuilder;
@@ -22,7 +20,7 @@ export type TestSequencer = TestSequencer_;
22
20
 
23
21
  class TestSequencerClient_ extends SequencerClient {
24
22
  declare public sequencer: TestSequencer;
25
- declare public publisherManager: PublisherManager<L1TxUtilsWithBlobs>;
23
+ declare public publisherManager: PublisherManager<L1TxUtils>;
26
24
  }
27
25
 
28
26
  export type TestSequencerClient = TestSequencerClient_;
@@ -1,32 +1,32 @@
1
1
  import { type BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
2
2
  import { Fr } from '@aztec/foundation/curves/bn254';
3
- import { Timer } from '@aztec/foundation/timer';
4
- import type { FunctionsOf } from '@aztec/foundation/types';
5
- import { L2BlockNew } from '@aztec/stdlib/block';
3
+ import { L2Block } from '@aztec/stdlib/block';
6
4
  import { Checkpoint } from '@aztec/stdlib/checkpoint';
7
5
  import { Gas } from '@aztec/stdlib/gas';
8
- import type { FullNodeBlockBuilderConfig, PublicProcessorLimits } from '@aztec/stdlib/interfaces/server';
6
+ import type {
7
+ FullNodeBlockBuilderConfig,
8
+ ICheckpointBlockBuilder,
9
+ ICheckpointsBuilder,
10
+ MerkleTreeWriteOperations,
11
+ PublicProcessorLimits,
12
+ } from '@aztec/stdlib/interfaces/server';
9
13
  import { CheckpointHeader } from '@aztec/stdlib/rollup';
10
14
  import { makeAppendOnlyTreeSnapshot } from '@aztec/stdlib/testing';
11
15
  import type { CheckpointGlobalVariables, Tx } from '@aztec/stdlib/tx';
12
- import type {
13
- BuildBlockInCheckpointResult,
14
- CheckpointBuilder,
15
- FullNodeCheckpointsBuilder,
16
- } from '@aztec/validator-client';
16
+ import type { BuildBlockInCheckpointResult } from '@aztec/validator-client';
17
17
 
18
18
  /**
19
19
  * A fake CheckpointBuilder for testing that implements the same interface as the real one.
20
20
  * Can be seeded with blocks to return sequentially on each `buildBlock` call.
21
21
  */
22
- export class MockCheckpointBuilder implements FunctionsOf<CheckpointBuilder> {
23
- private blocks: L2BlockNew[] = [];
24
- private builtBlocks: L2BlockNew[] = [];
22
+ export class MockCheckpointBuilder implements ICheckpointBlockBuilder {
23
+ private blocks: L2Block[] = [];
24
+ private builtBlocks: L2Block[] = [];
25
25
  private usedTxsPerBlock: Tx[][] = [];
26
26
  private blockIndex = 0;
27
27
 
28
28
  /** Optional function to dynamically provide the block (alternative to seedBlocks) */
29
- private blockProvider: (() => L2BlockNew) | undefined = undefined;
29
+ private blockProvider: (() => L2Block) | undefined = undefined;
30
30
 
31
31
  /** Track calls for assertions */
32
32
  public buildBlockCalls: Array<{
@@ -34,6 +34,8 @@ export class MockCheckpointBuilder implements FunctionsOf<CheckpointBuilder> {
34
34
  timestamp: bigint;
35
35
  opts: PublicProcessorLimits;
36
36
  }> = [];
37
+ /** Track all consumed transaction hashes across buildBlock calls */
38
+ public consumedTxHashes: Set<string> = new Set();
37
39
  public completeCheckpointCalled = false;
38
40
  public getCheckpointCalled = false;
39
41
 
@@ -46,7 +48,7 @@ export class MockCheckpointBuilder implements FunctionsOf<CheckpointBuilder> {
46
48
  ) {}
47
49
 
48
50
  /** Seed the builder with blocks to return on successive buildBlock calls */
49
- seedBlocks(blocks: L2BlockNew[], usedTxsPerBlock?: Tx[][]): this {
51
+ seedBlocks(blocks: L2Block[], usedTxsPerBlock?: Tx[][]): this {
50
52
  this.blocks = blocks;
51
53
  this.usedTxsPerBlock = usedTxsPerBlock ?? blocks.map(() => []);
52
54
  this.blockIndex = 0;
@@ -58,7 +60,7 @@ export class MockCheckpointBuilder implements FunctionsOf<CheckpointBuilder> {
58
60
  * Set a function that provides blocks dynamically.
59
61
  * Useful for tests where the block is determined at call time (e.g., sequencer tests).
60
62
  */
61
- setBlockProvider(provider: () => L2BlockNew): this {
63
+ setBlockProvider(provider: () => L2Block): this {
62
64
  this.blockProvider = provider;
63
65
  this.blocks = [];
64
66
  return this;
@@ -68,8 +70,8 @@ export class MockCheckpointBuilder implements FunctionsOf<CheckpointBuilder> {
68
70
  return this.constants;
69
71
  }
70
72
 
71
- buildBlock(
72
- _pendingTxs: Iterable<Tx> | AsyncIterable<Tx>,
73
+ async buildBlock(
74
+ pendingTxs: Iterable<Tx> | AsyncIterable<Tx>,
73
75
  blockNumber: BlockNumber,
74
76
  timestamp: bigint,
75
77
  opts: PublicProcessorLimits,
@@ -77,10 +79,10 @@ export class MockCheckpointBuilder implements FunctionsOf<CheckpointBuilder> {
77
79
  this.buildBlockCalls.push({ blockNumber, timestamp, opts });
78
80
 
79
81
  if (this.errorOnBuild) {
80
- return Promise.reject(this.errorOnBuild);
82
+ throw this.errorOnBuild;
81
83
  }
82
84
 
83
- let block: L2BlockNew;
85
+ let block: L2Block;
84
86
  let usedTxs: Tx[];
85
87
 
86
88
  if (this.blockProvider) {
@@ -96,15 +98,28 @@ export class MockCheckpointBuilder implements FunctionsOf<CheckpointBuilder> {
96
98
  this.builtBlocks.push(block);
97
99
  }
98
100
 
99
- return Promise.resolve({
101
+ // Check that no pending tx has already been consumed
102
+ for await (const tx of pendingTxs) {
103
+ const hash = tx.getTxHash().toString();
104
+ if (this.consumedTxHashes.has(hash)) {
105
+ throw new Error(`Transaction ${hash} was already consumed in a previous block`);
106
+ }
107
+ }
108
+
109
+ // Add used txs to consumed set
110
+ for (const tx of usedTxs) {
111
+ this.consumedTxHashes.add(tx.getTxHash().toString());
112
+ }
113
+
114
+ return {
100
115
  block,
101
116
  publicGas: Gas.empty(),
102
117
  publicProcessorDuration: 0,
103
118
  numTxs: block?.body?.txEffects?.length ?? usedTxs.length,
104
- blockBuildingTimer: new Timer(),
105
119
  usedTxs,
106
120
  failedTxs: [],
107
- });
121
+ usedTxBlobFields: block?.body?.txEffects?.reduce((sum, tx) => sum + tx.getNumBlobFields(), 0) ?? 0,
122
+ };
108
123
  }
109
124
 
110
125
  completeCheckpoint(): Promise<Checkpoint> {
@@ -146,7 +161,7 @@ export class MockCheckpointBuilder implements FunctionsOf<CheckpointBuilder> {
146
161
  * Creates a CheckpointHeader from a block's header for testing.
147
162
  * This is a simplified version that creates a minimal CheckpointHeader.
148
163
  */
149
- private createCheckpointHeader(block: L2BlockNew): CheckpointHeader {
164
+ private createCheckpointHeader(block: L2Block): CheckpointHeader {
150
165
  const header = block.header;
151
166
  const gv = header.globalVariables;
152
167
  return CheckpointHeader.empty({
@@ -168,6 +183,7 @@ export class MockCheckpointBuilder implements FunctionsOf<CheckpointBuilder> {
168
183
  this.usedTxsPerBlock = [];
169
184
  this.blockIndex = 0;
170
185
  this.buildBlockCalls = [];
186
+ this.consumedTxHashes.clear();
171
187
  this.completeCheckpointCalled = false;
172
188
  this.getCheckpointCalled = false;
173
189
  this.errorOnBuild = undefined;
@@ -180,7 +196,7 @@ export class MockCheckpointBuilder implements FunctionsOf<CheckpointBuilder> {
180
196
  * as FullNodeCheckpointsBuilder. Returns MockCheckpointBuilder instances.
181
197
  * Does NOT use jest mocks - this is a proper test double.
182
198
  */
183
- export class MockCheckpointsBuilder implements FunctionsOf<FullNodeCheckpointsBuilder> {
199
+ export class MockCheckpointsBuilder implements ICheckpointsBuilder {
184
200
  private checkpointBuilder: MockCheckpointBuilder | undefined;
185
201
 
186
202
  /** Track calls for assertions */
@@ -188,12 +204,16 @@ export class MockCheckpointsBuilder implements FunctionsOf<FullNodeCheckpointsBu
188
204
  checkpointNumber: CheckpointNumber;
189
205
  constants: CheckpointGlobalVariables;
190
206
  l1ToL2Messages: Fr[];
207
+ previousCheckpointOutHashes: Fr[];
208
+ feeAssetPriceModifier: bigint;
191
209
  }> = [];
192
210
  public openCheckpointCalls: Array<{
193
211
  checkpointNumber: CheckpointNumber;
194
212
  constants: CheckpointGlobalVariables;
195
213
  l1ToL2Messages: Fr[];
196
- existingBlocks: L2BlockNew[];
214
+ previousCheckpointOutHashes: Fr[];
215
+ existingBlocks: L2Block[];
216
+ feeAssetPriceModifier: bigint;
197
217
  }> = [];
198
218
  public updateConfigCalls: Array<Partial<FullNodeBlockBuilderConfig>> = [];
199
219
 
@@ -239,34 +259,55 @@ export class MockCheckpointsBuilder implements FunctionsOf<FullNodeCheckpointsBu
239
259
  startCheckpoint(
240
260
  checkpointNumber: CheckpointNumber,
241
261
  constants: CheckpointGlobalVariables,
262
+ feeAssetPriceModifier: bigint,
242
263
  l1ToL2Messages: Fr[],
243
- _fork: unknown,
244
- ): Promise<CheckpointBuilder> {
245
- this.startCheckpointCalls.push({ checkpointNumber, constants, l1ToL2Messages });
264
+ previousCheckpointOutHashes: Fr[],
265
+ _fork: MerkleTreeWriteOperations,
266
+ ): Promise<ICheckpointBlockBuilder> {
267
+ this.startCheckpointCalls.push({
268
+ checkpointNumber,
269
+ constants,
270
+ l1ToL2Messages,
271
+ previousCheckpointOutHashes,
272
+ feeAssetPriceModifier,
273
+ });
246
274
 
247
275
  if (!this.checkpointBuilder) {
248
276
  // Auto-create a builder if none was set
249
277
  this.checkpointBuilder = new MockCheckpointBuilder(constants, checkpointNumber);
250
278
  }
251
279
 
252
- return Promise.resolve(this.checkpointBuilder as unknown as CheckpointBuilder);
280
+ return Promise.resolve(this.checkpointBuilder);
253
281
  }
254
282
 
255
283
  openCheckpoint(
256
284
  checkpointNumber: CheckpointNumber,
257
285
  constants: CheckpointGlobalVariables,
286
+ feeAssetPriceModifier: bigint,
258
287
  l1ToL2Messages: Fr[],
259
- _fork: unknown,
260
- existingBlocks: L2BlockNew[] = [],
261
- ): Promise<CheckpointBuilder> {
262
- this.openCheckpointCalls.push({ checkpointNumber, constants, l1ToL2Messages, existingBlocks });
288
+ previousCheckpointOutHashes: Fr[],
289
+ _fork: MerkleTreeWriteOperations,
290
+ existingBlocks: L2Block[] = [],
291
+ ): Promise<ICheckpointBlockBuilder> {
292
+ this.openCheckpointCalls.push({
293
+ checkpointNumber,
294
+ constants,
295
+ l1ToL2Messages,
296
+ previousCheckpointOutHashes,
297
+ existingBlocks,
298
+ feeAssetPriceModifier,
299
+ });
263
300
 
264
301
  if (!this.checkpointBuilder) {
265
302
  // Auto-create a builder if none was set
266
303
  this.checkpointBuilder = new MockCheckpointBuilder(constants, checkpointNumber);
267
304
  }
268
305
 
269
- return Promise.resolve(this.checkpointBuilder as unknown as CheckpointBuilder);
306
+ return Promise.resolve(this.checkpointBuilder);
307
+ }
308
+
309
+ getFork(_blockNumber: BlockNumber): Promise<MerkleTreeWriteOperations> {
310
+ throw new Error('MockCheckpointsBuilder.getFork not implemented');
270
311
  }
271
312
 
272
313
  /** Reset for reuse in another test */