@aztec/sequencer-client 0.0.1-commit.f1df4d2 → 0.0.1-commit.f224bb98b

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 (73) hide show
  1. package/dest/client/sequencer-client.d.ts +23 -7
  2. package/dest/client/sequencer-client.d.ts.map +1 -1
  3. package/dest/client/sequencer-client.js +99 -16
  4. package/dest/config.d.ts +24 -6
  5. package/dest/config.d.ts.map +1 -1
  6. package/dest/config.js +40 -28
  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/publisher/config.d.ts +35 -17
  10. package/dest/publisher/config.d.ts.map +1 -1
  11. package/dest/publisher/config.js +106 -42
  12. package/dest/publisher/index.d.ts +2 -1
  13. package/dest/publisher/index.d.ts.map +1 -1
  14. package/dest/publisher/l1_tx_failed_store/factory.d.ts +11 -0
  15. package/dest/publisher/l1_tx_failed_store/factory.d.ts.map +1 -0
  16. package/dest/publisher/l1_tx_failed_store/factory.js +22 -0
  17. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts +59 -0
  18. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -0
  19. package/dest/publisher/l1_tx_failed_store/failed_tx_store.js +1 -0
  20. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts +15 -0
  21. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts.map +1 -0
  22. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.js +34 -0
  23. package/dest/publisher/l1_tx_failed_store/index.d.ts +4 -0
  24. package/dest/publisher/l1_tx_failed_store/index.d.ts.map +1 -0
  25. package/dest/publisher/l1_tx_failed_store/index.js +2 -0
  26. package/dest/publisher/sequencer-publisher-factory.d.ts +11 -3
  27. package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
  28. package/dest/publisher/sequencer-publisher-factory.js +27 -2
  29. package/dest/publisher/sequencer-publisher.d.ts +26 -7
  30. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  31. package/dest/publisher/sequencer-publisher.js +299 -30
  32. package/dest/sequencer/checkpoint_proposal_job.d.ts +4 -4
  33. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
  34. package/dest/sequencer/checkpoint_proposal_job.js +109 -52
  35. package/dest/sequencer/metrics.d.ts +17 -5
  36. package/dest/sequencer/metrics.d.ts.map +1 -1
  37. package/dest/sequencer/metrics.js +86 -15
  38. package/dest/sequencer/sequencer.d.ts +24 -13
  39. package/dest/sequencer/sequencer.d.ts.map +1 -1
  40. package/dest/sequencer/sequencer.js +36 -39
  41. package/dest/sequencer/timetable.d.ts +4 -6
  42. package/dest/sequencer/timetable.d.ts.map +1 -1
  43. package/dest/sequencer/timetable.js +7 -11
  44. package/dest/sequencer/types.d.ts +2 -2
  45. package/dest/sequencer/types.d.ts.map +1 -1
  46. package/dest/test/index.d.ts +3 -5
  47. package/dest/test/index.d.ts.map +1 -1
  48. package/dest/test/mock_checkpoint_builder.d.ts +8 -8
  49. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
  50. package/dest/test/mock_checkpoint_builder.js +45 -34
  51. package/dest/test/utils.d.ts +3 -3
  52. package/dest/test/utils.d.ts.map +1 -1
  53. package/dest/test/utils.js +5 -4
  54. package/package.json +28 -28
  55. package/src/client/sequencer-client.ts +135 -18
  56. package/src/config.ts +54 -38
  57. package/src/global_variable_builder/global_builder.ts +1 -1
  58. package/src/publisher/config.ts +121 -43
  59. package/src/publisher/index.ts +3 -0
  60. package/src/publisher/l1_tx_failed_store/factory.ts +32 -0
  61. package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +55 -0
  62. package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +46 -0
  63. package/src/publisher/l1_tx_failed_store/index.ts +3 -0
  64. package/src/publisher/sequencer-publisher-factory.ts +38 -6
  65. package/src/publisher/sequencer-publisher.ts +300 -43
  66. package/src/sequencer/checkpoint_proposal_job.ts +146 -59
  67. package/src/sequencer/metrics.ts +92 -18
  68. package/src/sequencer/sequencer.ts +45 -45
  69. package/src/sequencer/timetable.ts +13 -12
  70. package/src/sequencer/types.ts +1 -1
  71. package/src/test/index.ts +2 -4
  72. package/src/test/mock_checkpoint_builder.ts +60 -46
  73. package/src/test/utils.ts +5 -2
@@ -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. */
@@ -156,7 +147,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
156
147
  public async stop(): Promise<void> {
157
148
  this.log.info(`Stopping sequencer`);
158
149
  this.setState(SequencerState.STOPPING, undefined, { force: true });
159
- this.publisher?.interrupt();
150
+ this.publisherFactory.interruptAll();
160
151
  await this.runningPromise?.stop();
161
152
  this.setState(SequencerState.STOPPED, undefined, { force: true });
162
153
  this.log.info('Stopped sequencer');
@@ -169,7 +160,6 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
169
160
  } catch (err) {
170
161
  this.emit('checkpoint-error', { error: err as Error });
171
162
  if (err instanceof SequencerTooSlowError) {
172
- // TODO(palla/mbps): Add missing states
173
163
  // Log as warn only if we had to abort halfway through the block proposal
174
164
  const logLvl = [SequencerState.INITIALIZING_CHECKPOINT, SequencerState.PROPOSER_CHECK].includes(
175
165
  err.proposedState,
@@ -291,8 +281,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
291
281
 
292
282
  const logCtx = {
293
283
  now,
294
- syncedToL1Ts: syncedTo.l1Timestamp,
295
- syncedToL2Slot: getSlotAtTimestamp(syncedTo.l1Timestamp, this.l1Constants),
284
+ syncedToL2Slot: syncedTo.syncedL2Slot,
296
285
  slot,
297
286
  slotTs: ts,
298
287
  checkpointNumber,
@@ -310,12 +299,12 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
310
299
  }
311
300
 
312
301
  // 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) {
302
+ if (syncedTo.blockData && syncedTo.blockData.header.getSlot() >= slot) {
314
303
  this.log.warn(
315
304
  `Cannot propose block at next L2 slot ${slot} since that slot was taken by block ${syncedTo.blockNumber}`,
316
- { ...logCtx, block: syncedTo.block.header.toInspect() },
305
+ { ...logCtx, block: syncedTo.blockData.header.toInspect() },
317
306
  );
318
- this.metrics.recordBlockProposalPrecheckFailed('slot_already_taken');
307
+ this.metrics.recordCheckpointPrecheckFailed('slot_already_taken');
319
308
  return undefined;
320
309
  }
321
310
 
@@ -326,7 +315,6 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
326
315
  const proposerForPublisher = this.config.fishermanMode ? undefined : proposer;
327
316
  const { attestorAddress, publisher } = await this.publisherFactory.create(proposerForPublisher);
328
317
  this.log.verbose(`Created publisher at address ${publisher.getSenderAddress()} for attestor ${attestorAddress}`);
329
- this.publisher = publisher;
330
318
 
331
319
  // In fisherman mode, set the actual proposer's address for simulations
332
320
  if (this.config.fishermanMode && proposer) {
@@ -351,7 +339,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
351
339
  logCtx,
352
340
  );
353
341
  this.emit('proposer-rollup-check-failed', { reason: 'Rollup contract check failed', slot });
354
- this.metrics.recordBlockProposalPrecheckFailed('rollup_contract_check_failed');
342
+ this.metrics.recordCheckpointPrecheckFailed('rollup_contract_check_failed');
355
343
  return undefined;
356
344
  }
357
345
 
@@ -361,7 +349,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
361
349
  { ...logCtx, rollup: canProposeCheck, expectedSlot: slot },
362
350
  );
363
351
  this.emit('proposer-rollup-check-failed', { reason: 'Slot mismatch', slot });
364
- this.metrics.recordBlockProposalPrecheckFailed('slot_mismatch');
352
+ this.metrics.recordCheckpointPrecheckFailed('slot_mismatch');
365
353
  return undefined;
366
354
  }
367
355
 
@@ -371,11 +359,12 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
371
359
  { ...logCtx, rollup: canProposeCheck, expectedSlot: slot },
372
360
  );
373
361
  this.emit('proposer-rollup-check-failed', { reason: 'Block mismatch', slot });
374
- this.metrics.recordBlockProposalPrecheckFailed('block_number_mismatch');
362
+ this.metrics.recordCheckpointPrecheckFailed('block_number_mismatch');
375
363
  return undefined;
376
364
  }
377
365
 
378
366
  this.lastSlotForCheckpointProposalJob = slot;
367
+ await this.p2pClient.prepareForSlot(slot);
379
368
  this.log.info(`Preparing checkpoint proposal ${checkpointNumber} at slot ${slot}`, { ...logCtx, proposer });
380
369
 
381
370
  // Create and return the checkpoint proposal job
@@ -432,6 +421,13 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
432
421
  );
433
422
  }
434
423
 
424
+ /**
425
+ * Returns the current sequencer state.
426
+ */
427
+ public getState(): SequencerState {
428
+ return this.state;
429
+ }
430
+
435
431
  /**
436
432
  * Internal helper for setting the sequencer state and checks if we have enough time left in the slot to transition to the new state.
437
433
  * @param proposedState - The new state to transition to.
@@ -478,16 +474,15 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
478
474
  * We don't check against the previous block submitted since it may have been reorg'd out.
479
475
  */
480
476
  protected async checkSync(args: { ts: bigint; slot: SlotNumber }): Promise<SequencerSyncCheckResult | undefined> {
481
- // Check that the archiver and dependencies have synced to the previous L1 slot at least
477
+ // Check that the archiver has fully synced the L2 slot before the one we want to propose in.
482
478
  // TODO(#14766): Archiver reports L1 timestamp based on L1 blocks seen, which means that a missed L1 block will
483
479
  // cause the archiver L1 timestamp to fall behind, and cause this sequencer to start processing one L1 slot later.
484
- const l1Timestamp = await this.l2BlockSource.getL1Timestamp();
485
- const { slot, ts } = args;
486
- if (l1Timestamp === undefined || l1Timestamp + BigInt(this.l1Constants.ethereumSlotDuration) < ts) {
480
+ const syncedL2Slot = await this.l2BlockSource.getSyncedL2SlotNumber();
481
+ const { slot } = args;
482
+ if (syncedL2Slot === undefined || syncedL2Slot + 1 < slot) {
487
483
  this.log.debug(`Cannot propose block at next L2 slot ${slot} due to pending sync from L1`, {
488
484
  slot,
489
- ts,
490
- l1Timestamp,
485
+ syncedL2Slot,
491
486
  });
492
487
  return undefined;
493
488
  }
@@ -527,24 +522,24 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
527
522
  checkpointNumber: CheckpointNumber.ZERO,
528
523
  blockNumber: BlockNumber.ZERO,
529
524
  archive,
530
- l1Timestamp,
525
+ syncedL2Slot,
531
526
  pendingChainValidationStatus,
532
527
  };
533
528
  }
534
529
 
535
- const block = await this.l2BlockSource.getL2Block(blockNumber);
536
- if (!block) {
530
+ const blockData = await this.l2BlockSource.getBlockData(blockNumber);
531
+ if (!blockData) {
537
532
  // this shouldn't really happen because a moment ago we checked that all components were in sync
538
- this.log.error(`Failed to get L2 block ${blockNumber} from the archiver with all components in sync`);
533
+ this.log.error(`Failed to get L2 block data ${blockNumber} from the archiver with all components in sync`);
539
534
  return undefined;
540
535
  }
541
536
 
542
537
  return {
543
- block,
544
- blockNumber: block.number,
545
- checkpointNumber: block.checkpointNumber,
546
- archive: block.archive.root,
547
- l1Timestamp,
538
+ blockData,
539
+ blockNumber: blockData.header.getBlockNumber(),
540
+ checkpointNumber: blockData.checkpointNumber,
541
+ archive: blockData.archive.root,
542
+ syncedL2Slot,
548
543
  pendingChainValidationStatus,
549
544
  };
550
545
  }
@@ -723,7 +718,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
723
718
  syncedTo: SequencerSyncCheckResult,
724
719
  currentSlot: SlotNumber,
725
720
  ): Promise<void> {
726
- const { pendingChainValidationStatus, l1Timestamp } = syncedTo;
721
+ const { pendingChainValidationStatus, syncedL2Slot } = syncedTo;
727
722
  if (pendingChainValidationStatus.valid) {
728
723
  return;
729
724
  }
@@ -738,7 +733,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
738
733
 
739
734
  const logData = {
740
735
  invalidL1Timestamp: invalidCheckpointTimestamp,
741
- l1Timestamp,
736
+ syncedL2Slot,
742
737
  invalidCheckpoint: pendingChainValidationStatus.checkpoint,
743
738
  secondsBeforeInvalidatingBlockAsCommitteeMember,
744
739
  secondsBeforeInvalidatingBlockAsNonCommitteeMember,
@@ -866,6 +861,11 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
866
861
  return this.validatorClient?.getValidatorAddresses();
867
862
  }
868
863
 
864
+ /** Updates the publisher factory's node keystore adapter after a keystore reload. */
865
+ public updatePublisherNodeKeyStore(adapter: NodeKeystoreAdapter): void {
866
+ this.publisherFactory.updateNodeKeyStore(adapter);
867
+ }
868
+
869
869
  public getConfig() {
870
870
  return this.config;
871
871
  }
@@ -876,10 +876,10 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
876
876
  }
877
877
 
878
878
  type SequencerSyncCheckResult = {
879
- block?: L2Block;
879
+ blockData?: BlockData;
880
880
  checkpointNumber: CheckpointNumber;
881
881
  blockNumber: BlockNumber;
882
882
  archive: Fr;
883
- l1Timestamp: bigint;
883
+ syncedL2Slot: SlotNumber;
884
884
  pendingChainValidationStatus: ValidateCheckpointResult;
885
885
  };
@@ -1,14 +1,15 @@
1
- import { createLogger } from '@aztec/aztec.js/log';
1
+ import type { Logger } from '@aztec/foundation/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,
@@ -79,7 +80,7 @@ export class SequencerTimetable {
79
80
  enforce: boolean;
80
81
  },
81
82
  private readonly metrics?: SequencerMetrics,
82
- private readonly log = createLogger('sequencer:timetable'),
83
+ private readonly log?: Logger,
83
84
  ) {
84
85
  this.ethereumSlotDuration = opts.ethereumSlotDuration;
85
86
  this.aztecSlotDuration = opts.aztecSlotDuration;
@@ -131,7 +132,7 @@ export class SequencerTimetable {
131
132
  const initializeDeadline = this.aztecSlotDuration - minWorkToDo;
132
133
  this.initializeDeadline = initializeDeadline;
133
134
 
134
- this.log.verbose(
135
+ this.log?.info(
135
136
  `Sequencer timetable initialized with ${this.maxNumberOfBlocks} blocks per slot (${this.enforce ? 'enforced' : 'not enforced'})`,
136
137
  {
137
138
  ethereumSlotDuration: this.ethereumSlotDuration,
@@ -205,7 +206,7 @@ export class SequencerTimetable {
205
206
  }
206
207
 
207
208
  this.metrics?.recordStateTransitionBufferMs(Math.floor(bufferSeconds * 1000), newState);
208
- this.log.trace(`Enough time to transition to ${newState}`, { maxAllowedTime, secondsIntoSlot });
209
+ this.log?.trace(`Enough time to transition to ${newState}`, { maxAllowedTime, secondsIntoSlot });
209
210
  }
210
211
 
211
212
  /**
@@ -241,7 +242,7 @@ export class SequencerTimetable {
241
242
  const canStart = available >= this.minExecutionTime;
242
243
  const deadline = secondsIntoSlot + available;
243
244
 
244
- this.log.verbose(
245
+ this.log?.verbose(
245
246
  `${canStart ? 'Can' : 'Cannot'} start single-block checkpoint at ${secondsIntoSlot}s into slot`,
246
247
  { secondsIntoSlot, maxAllowed, available, deadline },
247
248
  );
@@ -261,7 +262,7 @@ export class SequencerTimetable {
261
262
  // Found an available sub-slot! Is this the last one?
262
263
  const isLastBlock = subSlot === this.maxNumberOfBlocks;
263
264
 
264
- this.log.verbose(
265
+ this.log?.verbose(
265
266
  `Can start ${isLastBlock ? 'last block' : 'block'} in sub-slot ${subSlot} with deadline ${deadline}s`,
266
267
  { secondsIntoSlot, deadline, timeUntilDeadline, subSlot, maxBlocks: this.maxNumberOfBlocks },
267
268
  );
@@ -271,7 +272,7 @@ export class SequencerTimetable {
271
272
  }
272
273
 
273
274
  // No sub-slots available with enough time
274
- this.log.verbose(`No time left to start any more blocks`, {
275
+ this.log?.verbose(`No time left to start any more blocks`, {
275
276
  secondsIntoSlot,
276
277
  maxBlocks: this.maxNumberOfBlocks,
277
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,8 +1,8 @@
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
7
  FullNodeBlockBuilderConfig,
8
8
  ICheckpointBlockBuilder,
@@ -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
 
@@ -205,6 +205,7 @@ export class MockCheckpointsBuilder implements ICheckpointsBuilder {
205
205
  constants: CheckpointGlobalVariables;
206
206
  l1ToL2Messages: Fr[];
207
207
  previousCheckpointOutHashes: Fr[];
208
+ feeAssetPriceModifier: bigint;
208
209
  }> = [];
209
210
  public openCheckpointCalls: Array<{
210
211
  checkpointNumber: CheckpointNumber;
@@ -212,6 +213,7 @@ export class MockCheckpointsBuilder implements ICheckpointsBuilder {
212
213
  l1ToL2Messages: Fr[];
213
214
  previousCheckpointOutHashes: Fr[];
214
215
  existingBlocks: L2Block[];
216
+ feeAssetPriceModifier: bigint;
215
217
  }> = [];
216
218
  public updateConfigCalls: Array<Partial<FullNodeBlockBuilderConfig>> = [];
217
219
 
@@ -247,6 +249,7 @@ export class MockCheckpointsBuilder implements ICheckpointsBuilder {
247
249
  slotDuration: 24,
248
250
  l1ChainId: 1,
249
251
  rollupVersion: 1,
252
+ rollupManaLimit: 200_000_000,
250
253
  };
251
254
  }
252
255
 
@@ -257,15 +260,24 @@ export class MockCheckpointsBuilder implements ICheckpointsBuilder {
257
260
  startCheckpoint(
258
261
  checkpointNumber: CheckpointNumber,
259
262
  constants: CheckpointGlobalVariables,
263
+ feeAssetPriceModifier: bigint,
260
264
  l1ToL2Messages: Fr[],
261
265
  previousCheckpointOutHashes: Fr[],
262
266
  _fork: MerkleTreeWriteOperations,
263
267
  ): Promise<ICheckpointBlockBuilder> {
264
- this.startCheckpointCalls.push({ checkpointNumber, constants, l1ToL2Messages, previousCheckpointOutHashes });
268
+ this.startCheckpointCalls.push({
269
+ checkpointNumber,
270
+ constants,
271
+ l1ToL2Messages,
272
+ previousCheckpointOutHashes,
273
+ feeAssetPriceModifier,
274
+ });
265
275
 
266
276
  if (!this.checkpointBuilder) {
267
277
  // Auto-create a builder if none was set
268
278
  this.checkpointBuilder = new MockCheckpointBuilder(constants, checkpointNumber);
279
+ } else {
280
+ this.checkpointBuilder.resetCheckpointState();
269
281
  }
270
282
 
271
283
  return Promise.resolve(this.checkpointBuilder);
@@ -274,6 +286,7 @@ export class MockCheckpointsBuilder implements ICheckpointsBuilder {
274
286
  openCheckpoint(
275
287
  checkpointNumber: CheckpointNumber,
276
288
  constants: CheckpointGlobalVariables,
289
+ feeAssetPriceModifier: bigint,
277
290
  l1ToL2Messages: Fr[],
278
291
  previousCheckpointOutHashes: Fr[],
279
292
  _fork: MerkleTreeWriteOperations,
@@ -285,6 +298,7 @@ export class MockCheckpointsBuilder implements ICheckpointsBuilder {
285
298
  l1ToL2Messages,
286
299
  previousCheckpointOutHashes,
287
300
  existingBlocks,
301
+ feeAssetPriceModifier,
288
302
  });
289
303
 
290
304
  if (!this.checkpointBuilder) {
package/src/test/utils.ts CHANGED
@@ -56,6 +56,7 @@ export async function makeBlock(txs: Tx[], globalVariables: GlobalVariables): Pr
56
56
  export function mockPendingTxs(p2p: MockProxy<P2P>, txs: Tx[]): void {
57
57
  p2p.getPendingTxCount.mockResolvedValue(txs.length);
58
58
  p2p.iteratePendingTxs.mockImplementation(() => mockTxIterator(Promise.resolve(txs)));
59
+ p2p.iterateEligiblePendingTxs.mockImplementation(() => mockTxIterator(Promise.resolve(txs)));
59
60
  }
60
61
 
61
62
  /**
@@ -118,10 +119,11 @@ export function createCheckpointProposal(
118
119
  block: L2Block,
119
120
  checkpointSignature: Signature,
120
121
  blockSignature?: Signature,
122
+ feeAssetPriceModifier: bigint = 0n,
121
123
  ): CheckpointProposal {
122
124
  const txHashes = block.body.txEffects.map(tx => tx.txHash);
123
125
  const checkpointHeader = createCheckpointHeaderFromBlock(block);
124
- return new CheckpointProposal(checkpointHeader, block.archive.root, checkpointSignature, {
126
+ return new CheckpointProposal(checkpointHeader, block.archive.root, feeAssetPriceModifier, checkpointSignature, {
125
127
  blockHeader: block.header,
126
128
  indexWithinCheckpoint: block.indexWithinCheckpoint,
127
129
  txHashes,
@@ -138,9 +140,10 @@ export function createCheckpointAttestation(
138
140
  block: L2Block,
139
141
  signature: Signature,
140
142
  sender: EthAddress,
143
+ feeAssetPriceModifier: bigint = 0n,
141
144
  ): CheckpointAttestation {
142
145
  const checkpointHeader = createCheckpointHeaderFromBlock(block);
143
- const payload = new ConsensusPayload(checkpointHeader, block.archive.root);
146
+ const payload = new ConsensusPayload(checkpointHeader, block.archive.root, feeAssetPriceModifier);
144
147
  const attestation = new CheckpointAttestation(payload, signature, signature);
145
148
  // Set sender directly for testing (bypasses signature recovery)
146
149
  (attestation as any).sender = sender;