@aztec/sequencer-client 0.0.1-commit.21ecf947b → 0.0.1-commit.2448fdb

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 (58) hide show
  1. package/dest/client/sequencer-client.d.ts +16 -7
  2. package/dest/client/sequencer-client.d.ts.map +1 -1
  3. package/dest/client/sequencer-client.js +56 -23
  4. package/dest/config.d.ts +25 -5
  5. package/dest/config.d.ts.map +1 -1
  6. package/dest/config.js +42 -20
  7. package/dest/global_variable_builder/global_builder.d.ts +14 -10
  8. package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
  9. package/dest/global_variable_builder/global_builder.js +22 -21
  10. package/dest/global_variable_builder/index.d.ts +2 -2
  11. package/dest/global_variable_builder/index.d.ts.map +1 -1
  12. package/dest/publisher/config.d.ts +31 -17
  13. package/dest/publisher/config.d.ts.map +1 -1
  14. package/dest/publisher/config.js +101 -42
  15. package/dest/publisher/sequencer-publisher-factory.d.ts +11 -3
  16. package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
  17. package/dest/publisher/sequencer-publisher-factory.js +13 -2
  18. package/dest/publisher/sequencer-publisher.d.ts +22 -13
  19. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  20. package/dest/publisher/sequencer-publisher.js +92 -52
  21. package/dest/sequencer/checkpoint_proposal_job.d.ts +4 -4
  22. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
  23. package/dest/sequencer/checkpoint_proposal_job.js +129 -75
  24. package/dest/sequencer/checkpoint_voter.d.ts +1 -2
  25. package/dest/sequencer/checkpoint_voter.d.ts.map +1 -1
  26. package/dest/sequencer/checkpoint_voter.js +2 -5
  27. package/dest/sequencer/metrics.d.ts +13 -5
  28. package/dest/sequencer/metrics.d.ts.map +1 -1
  29. package/dest/sequencer/metrics.js +32 -10
  30. package/dest/sequencer/sequencer.d.ts +27 -13
  31. package/dest/sequencer/sequencer.d.ts.map +1 -1
  32. package/dest/sequencer/sequencer.js +41 -42
  33. package/dest/sequencer/timetable.d.ts +4 -3
  34. package/dest/sequencer/timetable.d.ts.map +1 -1
  35. package/dest/sequencer/timetable.js +6 -7
  36. package/dest/sequencer/types.d.ts +2 -2
  37. package/dest/sequencer/types.d.ts.map +1 -1
  38. package/dest/test/index.d.ts +3 -5
  39. package/dest/test/index.d.ts.map +1 -1
  40. package/dest/test/mock_checkpoint_builder.d.ts +7 -9
  41. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
  42. package/dest/test/mock_checkpoint_builder.js +41 -30
  43. package/package.json +28 -28
  44. package/src/client/sequencer-client.ts +78 -21
  45. package/src/config.ts +52 -27
  46. package/src/global_variable_builder/global_builder.ts +23 -24
  47. package/src/global_variable_builder/index.ts +1 -1
  48. package/src/publisher/config.ts +112 -43
  49. package/src/publisher/sequencer-publisher-factory.ts +23 -6
  50. package/src/publisher/sequencer-publisher.ts +96 -66
  51. package/src/sequencer/checkpoint_proposal_job.ts +200 -106
  52. package/src/sequencer/checkpoint_voter.ts +1 -12
  53. package/src/sequencer/metrics.ts +39 -13
  54. package/src/sequencer/sequencer.ts +52 -48
  55. package/src/sequencer/timetable.ts +7 -7
  56. package/src/sequencer/types.ts +1 -1
  57. package/src/test/index.ts +2 -4
  58. package/src/test/mock_checkpoint_builder.ts +53 -48
@@ -18,7 +18,6 @@ import { type Hex, formatUnits } from 'viem';
18
18
 
19
19
  import type { SequencerState } from './utils.js';
20
20
 
21
- // TODO(palla/mbps): Review all metrics and add any missing ones per checkpoint
22
21
  export class SequencerMetrics {
23
22
  public readonly tracer: Tracer;
24
23
  private meter: Meter;
@@ -40,11 +39,16 @@ export class SequencerMetrics {
40
39
  private filledSlots: UpDownCounter;
41
40
 
42
41
  private blockProposalFailed: UpDownCounter;
43
- private blockProposalSuccess: UpDownCounter;
44
- private blockProposalPrecheckFailed: UpDownCounter;
42
+ private checkpointProposalSuccess: UpDownCounter;
43
+ private checkpointPrecheckFailed: UpDownCounter;
44
+ private checkpointProposalFailed: UpDownCounter;
45
45
  private checkpointSuccess: UpDownCounter;
46
46
  private slashingAttempts: UpDownCounter;
47
47
  private checkpointAttestationDelay: Histogram;
48
+ private checkpointBuildDuration: Histogram;
49
+ private checkpointBlockCount: Gauge;
50
+ private checkpointTxCount: Gauge;
51
+ private checkpointTotalMana: Gauge;
48
52
 
49
53
  // Fisherman fee analysis metrics
50
54
  private fishermanWouldBeIncluded: UpDownCounter;
@@ -84,7 +88,7 @@ export class SequencerMetrics {
84
88
 
85
89
  this.checkpointAttestationDelay = this.meter.createHistogram(Metrics.SEQUENCER_CHECKPOINT_ATTESTATION_DELAY);
86
90
 
87
- this.rewards = this.meter.createGauge(Metrics.SEQUENCER_CURRENT_BLOCK_REWARDS);
91
+ this.rewards = this.meter.createGauge(Metrics.SEQUENCER_CURRENT_SLOT_REWARDS);
88
92
 
89
93
  this.slots = createUpDownCounterWithDefault(this.meter, Metrics.SEQUENCER_SLOT_COUNT);
90
94
 
@@ -107,16 +111,16 @@ export class SequencerMetrics {
107
111
  Metrics.SEQUENCER_BLOCK_PROPOSAL_FAILED_COUNT,
108
112
  );
109
113
 
110
- this.blockProposalSuccess = createUpDownCounterWithDefault(
114
+ this.checkpointProposalSuccess = createUpDownCounterWithDefault(
111
115
  this.meter,
112
- Metrics.SEQUENCER_BLOCK_PROPOSAL_SUCCESS_COUNT,
116
+ Metrics.SEQUENCER_CHECKPOINT_PROPOSAL_SUCCESS_COUNT,
113
117
  );
114
118
 
115
119
  this.checkpointSuccess = createUpDownCounterWithDefault(this.meter, Metrics.SEQUENCER_CHECKPOINT_SUCCESS_COUNT);
116
120
 
117
- this.blockProposalPrecheckFailed = createUpDownCounterWithDefault(
121
+ this.checkpointPrecheckFailed = createUpDownCounterWithDefault(
118
122
  this.meter,
119
- Metrics.SEQUENCER_BLOCK_PROPOSAL_PRECHECK_FAILED_COUNT,
123
+ Metrics.SEQUENCER_CHECKPOINT_PRECHECK_FAILED_COUNT,
120
124
  {
121
125
  [Attributes.ERROR_TYPE]: [
122
126
  'slot_already_taken',
@@ -127,6 +131,16 @@ export class SequencerMetrics {
127
131
  },
128
132
  );
129
133
 
134
+ this.checkpointProposalFailed = createUpDownCounterWithDefault(
135
+ this.meter,
136
+ Metrics.SEQUENCER_CHECKPOINT_PROPOSAL_FAILED_COUNT,
137
+ );
138
+
139
+ this.checkpointBuildDuration = this.meter.createHistogram(Metrics.SEQUENCER_CHECKPOINT_BUILD_DURATION);
140
+ this.checkpointBlockCount = this.meter.createGauge(Metrics.SEQUENCER_CHECKPOINT_BLOCK_COUNT);
141
+ this.checkpointTxCount = this.meter.createGauge(Metrics.SEQUENCER_CHECKPOINT_TX_COUNT);
142
+ this.checkpointTotalMana = this.meter.createGauge(Metrics.SEQUENCER_CHECKPOINT_TOTAL_MANA);
143
+
130
144
  this.slashingAttempts = createUpDownCounterWithDefault(this.meter, Metrics.SEQUENCER_SLASHING_ATTEMPTS_COUNT);
131
145
 
132
146
  // Fisherman fee analysis metrics
@@ -262,18 +276,30 @@ export class SequencerMetrics {
262
276
  });
263
277
  }
264
278
 
265
- recordBlockProposalSuccess() {
266
- this.blockProposalSuccess.add(1);
279
+ recordCheckpointProposalSuccess() {
280
+ this.checkpointProposalSuccess.add(1);
267
281
  }
268
282
 
269
- recordBlockProposalPrecheckFailed(
283
+ recordCheckpointPrecheckFailed(
270
284
  checkType: 'slot_already_taken' | 'rollup_contract_check_failed' | 'slot_mismatch' | 'block_number_mismatch',
271
285
  ) {
272
- this.blockProposalPrecheckFailed.add(1, {
273
- [Attributes.ERROR_TYPE]: checkType,
286
+ this.checkpointPrecheckFailed.add(1, { [Attributes.ERROR_TYPE]: checkType });
287
+ }
288
+
289
+ recordCheckpointProposalFailed(reason?: string) {
290
+ this.checkpointProposalFailed.add(1, {
291
+ ...(reason && { [Attributes.ERROR_TYPE]: reason }),
274
292
  });
275
293
  }
276
294
 
295
+ /** Records aggregate metrics for a completed checkpoint build. */
296
+ recordCheckpointBuild(durationMs: number, blockCount: number, txCount: number, totalMana: number) {
297
+ this.checkpointBuildDuration.record(Math.ceil(durationMs));
298
+ this.checkpointBlockCount.record(blockCount);
299
+ this.checkpointTxCount.record(txCount);
300
+ this.checkpointTotalMana.record(totalMana);
301
+ }
302
+
277
303
  recordSlashingAttempt(actionCount: number) {
278
304
  this.slashingAttempts.add(actionCount);
279
305
  }
@@ -12,9 +12,9 @@ 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 { L2Block, 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
- import { getSlotAtTimestamp, getSlotStartBuildTimestamp } from '@aztec/stdlib/epoch-helpers';
17
+ import { getSlotStartBuildTimestamp } from '@aztec/stdlib/epoch-helpers';
18
18
  import {
19
19
  type ResolvedSequencerConfig,
20
20
  type SequencerConfig,
@@ -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
 
@@ -75,14 +75,6 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
75
75
  /** The maximum number of seconds that the sequencer can be into a slot to transition to a particular state. */
76
76
  protected timetable!: SequencerTimetable;
77
77
 
78
- // This shouldn't be here as this gets re-created each time we build/propose a block.
79
- // But we have a number of tests that abuse/rely on this class having a permanent publisher.
80
- // As long as those tests only configure a single publisher they will continue to work.
81
- // This will get re-assigned every time the sequencer goes to build a new block to a publisher that is valid
82
- // for the block proposer.
83
- // TODO(palla/mbps): Remove this field and fix tests
84
- protected publisher: SequencerPublisher | undefined;
85
-
86
78
  /** Config for the sequencer */
87
79
  protected config: ResolvedSequencerConfig = DefaultSequencerConfig;
88
80
 
@@ -118,7 +110,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
118
110
  /** Updates sequencer config by the defined values and updates the timetable */
119
111
  public updateConfig(config: Partial<SequencerConfig>) {
120
112
  const filteredConfig = pickFromSchema(config, SequencerConfigSchema);
121
- this.log.info(`Updated sequencer config`, omit(filteredConfig, 'txPublicSetupAllowList'));
113
+ this.log.info(`Updated sequencer config`, omit(filteredConfig, 'txPublicSetupAllowListExtend'));
122
114
  this.config = merge(this.config, filteredConfig);
123
115
  this.timetable = new SequencerTimetable(
124
116
  {
@@ -134,10 +126,9 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
134
126
  );
135
127
  }
136
128
 
137
- /** Initializes the sequencer (precomputes tables and creates a publisher). Takes about 3s. */
138
- public async init() {
129
+ /** Initializes the sequencer (precomputes tables). Takes about 3s. */
130
+ public init() {
139
131
  getKzg();
140
- this.publisher = (await this.publisherFactory.create(undefined)).publisher;
141
132
  }
142
133
 
143
134
  /** Starts the sequencer and moves to IDLE state. */
@@ -152,11 +143,16 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
152
143
  this.log.info('Started sequencer');
153
144
  }
154
145
 
146
+ /** Triggers an immediate run of the sequencer, bypassing the polling interval. */
147
+ public trigger() {
148
+ return this.runningPromise?.trigger();
149
+ }
150
+
155
151
  /** Stops the sequencer from building blocks and moves to STOPPED state. */
156
152
  public async stop(): Promise<void> {
157
153
  this.log.info(`Stopping sequencer`);
158
154
  this.setState(SequencerState.STOPPING, undefined, { force: true });
159
- this.publisher?.interrupt();
155
+ this.publisherFactory.interruptAll();
160
156
  await this.runningPromise?.stop();
161
157
  this.setState(SequencerState.STOPPED, undefined, { force: true });
162
158
  this.log.info('Stopped sequencer');
@@ -169,7 +165,6 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
169
165
  } catch (err) {
170
166
  this.emit('checkpoint-error', { error: err as Error });
171
167
  if (err instanceof SequencerTooSlowError) {
172
- // TODO(palla/mbps): Add missing states
173
168
  // Log as warn only if we had to abort halfway through the block proposal
174
169
  const logLvl = [SequencerState.INITIALIZING_CHECKPOINT, SequencerState.PROPOSER_CHECK].includes(
175
170
  err.proposedState,
@@ -291,8 +286,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
291
286
 
292
287
  const logCtx = {
293
288
  now,
294
- syncedToL1Ts: syncedTo.l1Timestamp,
295
- syncedToL2Slot: getSlotAtTimestamp(syncedTo.l1Timestamp, this.l1Constants),
289
+ syncedToL2Slot: syncedTo.syncedL2Slot,
296
290
  slot,
297
291
  slotTs: ts,
298
292
  checkpointNumber,
@@ -310,12 +304,12 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
310
304
  }
311
305
 
312
306
  // Check that the slot is not taken by a block already (should never happen, since only us can propose for this slot)
313
- if (syncedTo.block && syncedTo.block.header.getSlot() >= slot) {
307
+ if (syncedTo.blockData && syncedTo.blockData.header.getSlot() >= slot) {
314
308
  this.log.warn(
315
309
  `Cannot propose block at next L2 slot ${slot} since that slot was taken by block ${syncedTo.blockNumber}`,
316
- { ...logCtx, block: syncedTo.block.header.toInspect() },
310
+ { ...logCtx, block: syncedTo.blockData.header.toInspect() },
317
311
  );
318
- this.metrics.recordBlockProposalPrecheckFailed('slot_already_taken');
312
+ this.metrics.recordCheckpointPrecheckFailed('slot_already_taken');
319
313
  return undefined;
320
314
  }
321
315
 
@@ -326,7 +320,6 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
326
320
  const proposerForPublisher = this.config.fishermanMode ? undefined : proposer;
327
321
  const { attestorAddress, publisher } = await this.publisherFactory.create(proposerForPublisher);
328
322
  this.log.verbose(`Created publisher at address ${publisher.getSenderAddress()} for attestor ${attestorAddress}`);
329
- this.publisher = publisher;
330
323
 
331
324
  // In fisherman mode, set the actual proposer's address for simulations
332
325
  if (this.config.fishermanMode && proposer) {
@@ -339,7 +332,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
339
332
 
340
333
  // Check with the rollup contract if we can indeed propose at the next L2 slot. This check should not fail
341
334
  // if all the previous checks are good, but we do it just in case.
342
- const canProposeCheck = await publisher.canProposeAtNextEthBlock(
335
+ const canProposeCheck = await publisher.canProposeAt(
343
336
  syncedTo.archive,
344
337
  proposer ?? EthAddress.ZERO,
345
338
  invalidateCheckpoint,
@@ -351,7 +344,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
351
344
  logCtx,
352
345
  );
353
346
  this.emit('proposer-rollup-check-failed', { reason: 'Rollup contract check failed', slot });
354
- this.metrics.recordBlockProposalPrecheckFailed('rollup_contract_check_failed');
347
+ this.metrics.recordCheckpointPrecheckFailed('rollup_contract_check_failed');
355
348
  return undefined;
356
349
  }
357
350
 
@@ -361,7 +354,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
361
354
  { ...logCtx, rollup: canProposeCheck, expectedSlot: slot },
362
355
  );
363
356
  this.emit('proposer-rollup-check-failed', { reason: 'Slot mismatch', slot });
364
- this.metrics.recordBlockProposalPrecheckFailed('slot_mismatch');
357
+ this.metrics.recordCheckpointPrecheckFailed('slot_mismatch');
365
358
  return undefined;
366
359
  }
367
360
 
@@ -371,7 +364,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
371
364
  { ...logCtx, rollup: canProposeCheck, expectedSlot: slot },
372
365
  );
373
366
  this.emit('proposer-rollup-check-failed', { reason: 'Block mismatch', slot });
374
- this.metrics.recordBlockProposalPrecheckFailed('block_number_mismatch');
367
+ this.metrics.recordCheckpointPrecheckFailed('block_number_mismatch');
375
368
  return undefined;
376
369
  }
377
370
 
@@ -433,6 +426,13 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
433
426
  );
434
427
  }
435
428
 
429
+ /**
430
+ * Returns the current sequencer state.
431
+ */
432
+ public getState(): SequencerState {
433
+ return this.state;
434
+ }
435
+
436
436
  /**
437
437
  * Internal helper for setting the sequencer state and checks if we have enough time left in the slot to transition to the new state.
438
438
  * @param proposedState - The new state to transition to.
@@ -479,16 +479,15 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
479
479
  * We don't check against the previous block submitted since it may have been reorg'd out.
480
480
  */
481
481
  protected async checkSync(args: { ts: bigint; slot: SlotNumber }): Promise<SequencerSyncCheckResult | undefined> {
482
- // Check that the archiver and dependencies have synced to the previous L1 slot at least
483
- // TODO(#14766): Archiver reports L1 timestamp based on L1 blocks seen, which means that a missed L1 block will
484
- // cause the archiver L1 timestamp to fall behind, and cause this sequencer to start processing one L1 slot later.
485
- const l1Timestamp = await this.l2BlockSource.getL1Timestamp();
486
- const { slot, ts } = args;
487
- if (l1Timestamp === undefined || l1Timestamp + BigInt(this.l1Constants.ethereumSlotDuration) < ts) {
482
+ // Check that the archiver has fully synced the L2 slot before the one we want to propose in.
483
+ // The archiver reports sync progress via L1 block timestamps and synced checkpoint slots.
484
+ // See getSyncedL2SlotNumber for how missed L1 blocks are handled.
485
+ const syncedL2Slot = await this.l2BlockSource.getSyncedL2SlotNumber();
486
+ const { slot } = args;
487
+ if (syncedL2Slot === undefined || syncedL2Slot + 1 < slot) {
488
488
  this.log.debug(`Cannot propose block at next L2 slot ${slot} due to pending sync from L1`, {
489
489
  slot,
490
- ts,
491
- l1Timestamp,
490
+ syncedL2Slot,
492
491
  });
493
492
  return undefined;
494
493
  }
@@ -528,24 +527,24 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
528
527
  checkpointNumber: CheckpointNumber.ZERO,
529
528
  blockNumber: BlockNumber.ZERO,
530
529
  archive,
531
- l1Timestamp,
530
+ syncedL2Slot,
532
531
  pendingChainValidationStatus,
533
532
  };
534
533
  }
535
534
 
536
- const block = await this.l2BlockSource.getL2Block(blockNumber);
537
- if (!block) {
535
+ const blockData = await this.l2BlockSource.getBlockData(blockNumber);
536
+ if (!blockData) {
538
537
  // this shouldn't really happen because a moment ago we checked that all components were in sync
539
- this.log.error(`Failed to get L2 block ${blockNumber} from the archiver with all components in sync`);
538
+ this.log.error(`Failed to get L2 block data ${blockNumber} from the archiver with all components in sync`);
540
539
  return undefined;
541
540
  }
542
541
 
543
542
  return {
544
- block,
545
- blockNumber: block.number,
546
- checkpointNumber: block.checkpointNumber,
547
- archive: block.archive.root,
548
- l1Timestamp,
543
+ blockData,
544
+ blockNumber: blockData.header.getBlockNumber(),
545
+ checkpointNumber: blockData.checkpointNumber,
546
+ archive: blockData.archive.root,
547
+ syncedL2Slot,
549
548
  pendingChainValidationStatus,
550
549
  };
551
550
  }
@@ -724,7 +723,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
724
723
  syncedTo: SequencerSyncCheckResult,
725
724
  currentSlot: SlotNumber,
726
725
  ): Promise<void> {
727
- const { pendingChainValidationStatus, l1Timestamp } = syncedTo;
726
+ const { pendingChainValidationStatus, syncedL2Slot } = syncedTo;
728
727
  if (pendingChainValidationStatus.valid) {
729
728
  return;
730
729
  }
@@ -739,7 +738,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
739
738
 
740
739
  const logData = {
741
740
  invalidL1Timestamp: invalidCheckpointTimestamp,
742
- l1Timestamp,
741
+ syncedL2Slot,
743
742
  invalidCheckpoint: pendingChainValidationStatus.checkpoint,
744
743
  secondsBeforeInvalidatingBlockAsCommitteeMember,
745
744
  secondsBeforeInvalidatingBlockAsNonCommitteeMember,
@@ -867,6 +866,11 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
867
866
  return this.validatorClient?.getValidatorAddresses();
868
867
  }
869
868
 
869
+ /** Updates the publisher factory's node keystore adapter after a keystore reload. */
870
+ public updatePublisherNodeKeyStore(adapter: NodeKeystoreAdapter): void {
871
+ this.publisherFactory.updateNodeKeyStore(adapter);
872
+ }
873
+
870
874
  public getConfig() {
871
875
  return this.config;
872
876
  }
@@ -877,10 +881,10 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
877
881
  }
878
882
 
879
883
  type SequencerSyncCheckResult = {
880
- block?: L2Block;
884
+ blockData?: BlockData;
881
885
  checkpointNumber: CheckpointNumber;
882
886
  blockNumber: BlockNumber;
883
887
  archive: Fr;
884
- l1Timestamp: bigint;
888
+ syncedL2Slot: SlotNumber;
885
889
  pendingChainValidationStatus: ValidateCheckpointResult;
886
890
  };
@@ -1,4 +1,4 @@
1
- import { createLogger } from '@aztec/aztec.js/log';
1
+ import type { Logger } from '@aztec/foundation/log';
2
2
  import {
3
3
  CHECKPOINT_ASSEMBLE_TIME,
4
4
  CHECKPOINT_INITIALIZATION_TIME,
@@ -80,7 +80,7 @@ export class SequencerTimetable {
80
80
  enforce: boolean;
81
81
  },
82
82
  private readonly metrics?: SequencerMetrics,
83
- private readonly log = createLogger('sequencer:timetable'),
83
+ private readonly log?: Logger,
84
84
  ) {
85
85
  this.ethereumSlotDuration = opts.ethereumSlotDuration;
86
86
  this.aztecSlotDuration = opts.aztecSlotDuration;
@@ -132,7 +132,7 @@ export class SequencerTimetable {
132
132
  const initializeDeadline = this.aztecSlotDuration - minWorkToDo;
133
133
  this.initializeDeadline = initializeDeadline;
134
134
 
135
- this.log.verbose(
135
+ this.log?.info(
136
136
  `Sequencer timetable initialized with ${this.maxNumberOfBlocks} blocks per slot (${this.enforce ? 'enforced' : 'not enforced'})`,
137
137
  {
138
138
  ethereumSlotDuration: this.ethereumSlotDuration,
@@ -206,7 +206,7 @@ export class SequencerTimetable {
206
206
  }
207
207
 
208
208
  this.metrics?.recordStateTransitionBufferMs(Math.floor(bufferSeconds * 1000), newState);
209
- this.log.trace(`Enough time to transition to ${newState}`, { maxAllowedTime, secondsIntoSlot });
209
+ this.log?.trace(`Enough time to transition to ${newState}`, { maxAllowedTime, secondsIntoSlot });
210
210
  }
211
211
 
212
212
  /**
@@ -242,7 +242,7 @@ export class SequencerTimetable {
242
242
  const canStart = available >= this.minExecutionTime;
243
243
  const deadline = secondsIntoSlot + available;
244
244
 
245
- this.log.verbose(
245
+ this.log?.verbose(
246
246
  `${canStart ? 'Can' : 'Cannot'} start single-block checkpoint at ${secondsIntoSlot}s into slot`,
247
247
  { secondsIntoSlot, maxAllowed, available, deadline },
248
248
  );
@@ -262,7 +262,7 @@ export class SequencerTimetable {
262
262
  // Found an available sub-slot! Is this the last one?
263
263
  const isLastBlock = subSlot === this.maxNumberOfBlocks;
264
264
 
265
- this.log.verbose(
265
+ this.log?.verbose(
266
266
  `Can start ${isLastBlock ? 'last block' : 'block'} in sub-slot ${subSlot} with deadline ${deadline}s`,
267
267
  { secondsIntoSlot, deadline, timeUntilDeadline, subSlot, maxBlocks: this.maxNumberOfBlocks },
268
268
  );
@@ -272,7 +272,7 @@ export class SequencerTimetable {
272
272
  }
273
273
 
274
274
  // No sub-slots available with enough time
275
- this.log.verbose(`No time left to start any more blocks`, {
275
+ this.log?.verbose(`No time left to start any more blocks`, {
276
276
  secondsIntoSlot,
277
277
  maxBlocks: this.maxNumberOfBlocks,
278
278
  initializationOffset: this.initializationOffset,
@@ -2,5 +2,5 @@ import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
2
2
 
3
3
  export type SequencerRollupConstants = Pick<
4
4
  L1RollupConstants,
5
- 'ethereumSlotDuration' | 'l1GenesisTime' | 'slotDuration'
5
+ 'ethereumSlotDuration' | 'l1GenesisTime' | 'slotDuration' | 'rollupManaLimit'
6
6
  >;
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,14 +1,14 @@
1
- import { type BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
1
+ import { type BlockNumber, CheckpointNumber, IndexWithinCheckpoint } from '@aztec/foundation/branded-types';
2
2
  import { Fr } from '@aztec/foundation/curves/bn254';
3
+ import { unfreeze } from '@aztec/foundation/types';
3
4
  import { L2Block } from '@aztec/stdlib/block';
4
5
  import { Checkpoint } from '@aztec/stdlib/checkpoint';
5
- import { Gas } from '@aztec/stdlib/gas';
6
6
  import type {
7
+ BlockBuilderOptions,
7
8
  FullNodeBlockBuilderConfig,
8
9
  ICheckpointBlockBuilder,
9
10
  ICheckpointsBuilder,
10
11
  MerkleTreeWriteOperations,
11
- PublicProcessorLimits,
12
12
  } from '@aztec/stdlib/interfaces/server';
13
13
  import { CheckpointHeader } from '@aztec/stdlib/rollup';
14
14
  import { makeAppendOnlyTreeSnapshot } from '@aztec/stdlib/testing';
@@ -32,7 +32,7 @@ export class MockCheckpointBuilder implements ICheckpointBlockBuilder {
32
32
  public buildBlockCalls: Array<{
33
33
  blockNumber: BlockNumber;
34
34
  timestamp: bigint;
35
- opts: PublicProcessorLimits;
35
+ opts: BlockBuilderOptions;
36
36
  }> = [];
37
37
  /** Track all consumed transaction hashes across buildBlock calls */
38
38
  public consumedTxHashes: Set<string> = new Set();
@@ -74,7 +74,7 @@ export class MockCheckpointBuilder implements ICheckpointBlockBuilder {
74
74
  pendingTxs: Iterable<Tx> | AsyncIterable<Tx>,
75
75
  blockNumber: BlockNumber,
76
76
  timestamp: bigint,
77
- opts: PublicProcessorLimits,
77
+ opts: BlockBuilderOptions,
78
78
  ): Promise<BuildBlockInCheckpointResult> {
79
79
  this.buildBlockCalls.push({ blockNumber, timestamp, opts });
80
80
 
@@ -86,8 +86,10 @@ export class MockCheckpointBuilder implements ICheckpointBlockBuilder {
86
86
  let usedTxs: Tx[];
87
87
 
88
88
  if (this.blockProvider) {
89
- // Dynamic mode: get block from provider
90
- block = this.blockProvider();
89
+ // Dynamic mode: get block from provider, cloning to avoid shared references across multiple buildBlock calls
90
+ block = L2Block.fromBuffer(this.blockProvider().toBuffer());
91
+ block.header.globalVariables.blockNumber = blockNumber;
92
+ await block.header.recomputeHash();
91
93
  usedTxs = [];
92
94
  this.builtBlocks.push(block);
93
95
  } else {
@@ -113,81 +115,79 @@ export class MockCheckpointBuilder implements ICheckpointBlockBuilder {
113
115
 
114
116
  return {
115
117
  block,
116
- publicGas: Gas.empty(),
117
118
  publicProcessorDuration: 0,
118
119
  numTxs: block?.body?.txEffects?.length ?? usedTxs.length,
119
120
  usedTxs,
120
121
  failedTxs: [],
121
- usedTxBlobFields: block?.body?.txEffects?.reduce((sum, tx) => sum + tx.getNumBlobFields(), 0) ?? 0,
122
122
  };
123
123
  }
124
124
 
125
125
  completeCheckpoint(): Promise<Checkpoint> {
126
126
  this.completeCheckpointCalled = true;
127
127
  const allBlocks = this.blockProvider ? this.builtBlocks : this.blocks;
128
- const lastBlock = allBlocks[allBlocks.length - 1];
129
- // Create a CheckpointHeader from the last block's header for testing
130
- const checkpointHeader = this.createCheckpointHeader(lastBlock);
131
- return Promise.resolve(
132
- new Checkpoint(
133
- makeAppendOnlyTreeSnapshot(lastBlock.header.globalVariables.blockNumber + 1),
134
- checkpointHeader,
135
- allBlocks,
136
- this.checkpointNumber,
137
- ),
138
- );
128
+ return this.buildCheckpoint(allBlocks);
139
129
  }
140
130
 
141
131
  getCheckpoint(): Promise<Checkpoint> {
142
132
  this.getCheckpointCalled = true;
143
133
  const builtBlocks = this.blockProvider ? this.builtBlocks : this.blocks.slice(0, this.blockIndex);
144
- const lastBlock = builtBlocks[builtBlocks.length - 1];
145
- if (!lastBlock) {
134
+ if (builtBlocks.length === 0) {
146
135
  throw new Error('No blocks built yet');
147
136
  }
148
- // Create a CheckpointHeader from the last block's header for testing
149
- const checkpointHeader = this.createCheckpointHeader(lastBlock);
150
- return Promise.resolve(
151
- new Checkpoint(
152
- makeAppendOnlyTreeSnapshot(lastBlock.header.globalVariables.blockNumber + 1),
153
- checkpointHeader,
154
- builtBlocks,
155
- this.checkpointNumber,
156
- ),
157
- );
137
+ return this.buildCheckpoint(builtBlocks);
158
138
  }
159
139
 
160
- /**
161
- * Creates a CheckpointHeader from a block's header for testing.
162
- * This is a simplified version that creates a minimal CheckpointHeader.
163
- */
164
- private createCheckpointHeader(block: L2Block): CheckpointHeader {
165
- const header = block.header;
166
- const gv = header.globalVariables;
167
- return CheckpointHeader.empty({
168
- lastArchiveRoot: header.lastArchive.root,
169
- blockHeadersHash: Fr.random(), // Use random for testing
140
+ /** Builds a structurally valid Checkpoint from a list of blocks, fixing up indexes and archive chaining. */
141
+ private async buildCheckpoint(blocks: L2Block[]): Promise<Checkpoint> {
142
+ // Fix up indexWithinCheckpoint and archive chaining so the checkpoint passes structural validation.
143
+ for (let i = 0; i < blocks.length; i++) {
144
+ blocks[i].indexWithinCheckpoint = IndexWithinCheckpoint(i);
145
+ if (i > 0) {
146
+ unfreeze(blocks[i].header).lastArchive = blocks[i - 1].archive;
147
+ await blocks[i].header.recomputeHash();
148
+ }
149
+ }
150
+
151
+ const firstBlock = blocks[0];
152
+ const lastBlock = blocks[blocks.length - 1];
153
+ const gv = firstBlock.header.globalVariables;
154
+
155
+ const checkpointHeader = CheckpointHeader.empty({
156
+ lastArchiveRoot: firstBlock.header.lastArchive.root,
157
+ blockHeadersHash: Fr.random(),
170
158
  slotNumber: gv.slotNumber,
171
159
  timestamp: gv.timestamp,
172
160
  coinbase: gv.coinbase,
173
161
  feeRecipient: gv.feeRecipient,
174
162
  gasFees: gv.gasFees,
175
- totalManaUsed: header.totalManaUsed,
163
+ totalManaUsed: lastBlock.header.totalManaUsed,
176
164
  });
165
+
166
+ return new Checkpoint(
167
+ makeAppendOnlyTreeSnapshot(lastBlock.header.globalVariables.blockNumber + 1),
168
+ checkpointHeader,
169
+ blocks,
170
+ this.checkpointNumber,
171
+ );
177
172
  }
178
173
 
179
- /** Reset for reuse in another test */
180
- reset(): void {
181
- this.blocks = [];
174
+ /** Resets per-checkpoint state (built blocks, consumed txs) while preserving config (blockProvider, seeded blocks). */
175
+ resetCheckpointState(): void {
182
176
  this.builtBlocks = [];
183
- this.usedTxsPerBlock = [];
184
177
  this.blockIndex = 0;
185
- this.buildBlockCalls = [];
186
178
  this.consumedTxHashes.clear();
187
179
  this.completeCheckpointCalled = false;
188
180
  this.getCheckpointCalled = false;
181
+ }
182
+
183
+ /** Reset for reuse in another test */
184
+ reset(): void {
185
+ this.blocks = [];
186
+ this.usedTxsPerBlock = [];
187
+ this.buildBlockCalls = [];
189
188
  this.errorOnBuild = undefined;
190
189
  this.blockProvider = undefined;
190
+ this.resetCheckpointState();
191
191
  }
192
192
  }
193
193
 
@@ -249,6 +249,7 @@ export class MockCheckpointsBuilder implements ICheckpointsBuilder {
249
249
  slotDuration: 24,
250
250
  l1ChainId: 1,
251
251
  rollupVersion: 1,
252
+ rollupManaLimit: 200_000_000,
252
253
  };
253
254
  }
254
255
 
@@ -275,6 +276,8 @@ export class MockCheckpointsBuilder implements ICheckpointsBuilder {
275
276
  if (!this.checkpointBuilder) {
276
277
  // Auto-create a builder if none was set
277
278
  this.checkpointBuilder = new MockCheckpointBuilder(constants, checkpointNumber);
279
+ } else {
280
+ this.checkpointBuilder.resetCheckpointState();
278
281
  }
279
282
 
280
283
  return Promise.resolve(this.checkpointBuilder);
@@ -301,6 +304,8 @@ export class MockCheckpointsBuilder implements ICheckpointsBuilder {
301
304
  if (!this.checkpointBuilder) {
302
305
  // Auto-create a builder if none was set
303
306
  this.checkpointBuilder = new MockCheckpointBuilder(constants, checkpointNumber);
307
+ } else {
308
+ this.checkpointBuilder.resetCheckpointState();
304
309
  }
305
310
 
306
311
  return Promise.resolve(this.checkpointBuilder);