@aztec/sequencer-client 0.0.1-commit.c2595eba → 0.0.1-commit.c2eed6949

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 (80) hide show
  1. package/dest/client/sequencer-client.d.ts +15 -7
  2. package/dest/client/sequencer-client.d.ts.map +1 -1
  3. package/dest/client/sequencer-client.js +60 -26
  4. package/dest/config.d.ts +26 -7
  5. package/dest/config.d.ts.map +1 -1
  6. package/dest/config.js +47 -28
  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 +47 -17
  13. package/dest/publisher/config.d.ts.map +1 -1
  14. package/dest/publisher/config.js +121 -42
  15. package/dest/publisher/index.d.ts +2 -1
  16. package/dest/publisher/index.d.ts.map +1 -1
  17. package/dest/publisher/l1_tx_failed_store/factory.d.ts +11 -0
  18. package/dest/publisher/l1_tx_failed_store/factory.d.ts.map +1 -0
  19. package/dest/publisher/l1_tx_failed_store/factory.js +22 -0
  20. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts +59 -0
  21. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -0
  22. package/dest/publisher/l1_tx_failed_store/failed_tx_store.js +1 -0
  23. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts +15 -0
  24. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts.map +1 -0
  25. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.js +34 -0
  26. package/dest/publisher/l1_tx_failed_store/index.d.ts +4 -0
  27. package/dest/publisher/l1_tx_failed_store/index.d.ts.map +1 -0
  28. package/dest/publisher/l1_tx_failed_store/index.js +2 -0
  29. package/dest/publisher/sequencer-publisher-factory.d.ts +11 -3
  30. package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
  31. package/dest/publisher/sequencer-publisher-factory.js +27 -2
  32. package/dest/publisher/sequencer-publisher.d.ts +33 -10
  33. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  34. package/dest/publisher/sequencer-publisher.js +371 -57
  35. package/dest/sequencer/checkpoint_proposal_job.d.ts +39 -10
  36. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
  37. package/dest/sequencer/checkpoint_proposal_job.js +287 -167
  38. package/dest/sequencer/events.d.ts +2 -1
  39. package/dest/sequencer/events.d.ts.map +1 -1
  40. package/dest/sequencer/metrics.d.ts +21 -5
  41. package/dest/sequencer/metrics.d.ts.map +1 -1
  42. package/dest/sequencer/metrics.js +97 -15
  43. package/dest/sequencer/sequencer.d.ts +30 -15
  44. package/dest/sequencer/sequencer.d.ts.map +1 -1
  45. package/dest/sequencer/sequencer.js +95 -82
  46. package/dest/sequencer/timetable.d.ts +4 -6
  47. package/dest/sequencer/timetable.d.ts.map +1 -1
  48. package/dest/sequencer/timetable.js +7 -11
  49. package/dest/sequencer/types.d.ts +2 -2
  50. package/dest/sequencer/types.d.ts.map +1 -1
  51. package/dest/test/index.d.ts +3 -5
  52. package/dest/test/index.d.ts.map +1 -1
  53. package/dest/test/mock_checkpoint_builder.d.ts +12 -12
  54. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
  55. package/dest/test/mock_checkpoint_builder.js +45 -36
  56. package/dest/test/utils.d.ts +3 -3
  57. package/dest/test/utils.d.ts.map +1 -1
  58. package/dest/test/utils.js +5 -4
  59. package/package.json +27 -28
  60. package/src/client/sequencer-client.ts +76 -23
  61. package/src/config.ts +65 -38
  62. package/src/global_variable_builder/global_builder.ts +23 -24
  63. package/src/global_variable_builder/index.ts +1 -1
  64. package/src/publisher/config.ts +153 -43
  65. package/src/publisher/index.ts +3 -0
  66. package/src/publisher/l1_tx_failed_store/factory.ts +32 -0
  67. package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +55 -0
  68. package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +46 -0
  69. package/src/publisher/l1_tx_failed_store/index.ts +3 -0
  70. package/src/publisher/sequencer-publisher-factory.ts +38 -6
  71. package/src/publisher/sequencer-publisher.ts +371 -70
  72. package/src/sequencer/checkpoint_proposal_job.ts +392 -193
  73. package/src/sequencer/events.ts +1 -1
  74. package/src/sequencer/metrics.ts +106 -18
  75. package/src/sequencer/sequencer.ts +131 -94
  76. package/src/sequencer/timetable.ts +13 -12
  77. package/src/sequencer/types.ts +1 -1
  78. package/src/test/index.ts +2 -4
  79. package/src/test/mock_checkpoint_builder.ts +65 -53
  80. 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
 
@@ -60,6 +60,9 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
60
60
  /** The last slot for which we attempted to perform our voting duties with degraded block production */
61
61
  private lastSlotForFallbackVote: SlotNumber | undefined;
62
62
 
63
+ /** The last slot for which we logged "no committee" warning, to avoid spam */
64
+ private lastSlotForNoCommitteeWarning: SlotNumber | undefined;
65
+
63
66
  /** The last slot for which we triggered a checkpoint proposal job, to prevent duplicate attempts. */
64
67
  private lastSlotForCheckpointProposalJob: SlotNumber | undefined;
65
68
 
@@ -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
 
@@ -115,7 +110,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
115
110
  /** Updates sequencer config by the defined values and updates the timetable */
116
111
  public updateConfig(config: Partial<SequencerConfig>) {
117
112
  const filteredConfig = pickFromSchema(config, SequencerConfigSchema);
118
- this.log.info(`Updated sequencer config`, omit(filteredConfig, 'txPublicSetupAllowList'));
113
+ this.log.info(`Updated sequencer config`, omit(filteredConfig, 'txPublicSetupAllowListExtend'));
119
114
  this.config = merge(this.config, filteredConfig);
120
115
  this.timetable = new SequencerTimetable(
121
116
  {
@@ -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
+ await this.publisherFactory.stopAll();
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,
@@ -199,10 +192,18 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
199
192
  @trackSpan('Sequencer.work')
200
193
  protected async work() {
201
194
  this.setState(SequencerState.SYNCHRONIZING, undefined);
202
- const { slot, ts, now, epoch } = this.epochCache.getEpochAndSlotInNextL1Slot();
195
+ const { slot, ts, nowSeconds, epoch } = this.epochCache.getEpochAndSlotInNextL1Slot();
196
+ const { slot: targetSlot, epoch: targetEpoch } = this.epochCache.getTargetEpochAndSlotInNextL1Slot();
203
197
 
204
198
  // Check if we are synced and it's our slot, grab a publisher, check previous block invalidation, etc
205
- const checkpointProposalJob = await this.prepareCheckpointProposal(epoch, slot, ts, now);
199
+ const checkpointProposalJob = await this.prepareCheckpointProposal(
200
+ slot,
201
+ targetSlot,
202
+ epoch,
203
+ targetEpoch,
204
+ ts,
205
+ nowSeconds,
206
+ );
206
207
  if (!checkpointProposalJob) {
207
208
  return;
208
209
  }
@@ -215,13 +216,13 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
215
216
  this.lastCheckpointProposed = checkpoint;
216
217
  }
217
218
 
218
- // Log fee strategy comparison if on fisherman
219
+ // Log fee strategy comparison if on fisherman (uses target epoch since we mirror the proposer's perspective)
219
220
  if (
220
221
  this.config.fishermanMode &&
221
- (this.lastEpochForStrategyComparison === undefined || epoch > this.lastEpochForStrategyComparison)
222
+ (this.lastEpochForStrategyComparison === undefined || targetEpoch > this.lastEpochForStrategyComparison)
222
223
  ) {
223
- this.logStrategyComparison(epoch, checkpointProposalJob.getPublisher());
224
- this.lastEpochForStrategyComparison = epoch;
224
+ this.logStrategyComparison(targetEpoch, checkpointProposalJob.getPublisher());
225
+ this.lastEpochForStrategyComparison = targetEpoch;
225
226
  }
226
227
 
227
228
  return checkpoint;
@@ -234,43 +235,48 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
234
235
  */
235
236
  @trackSpan('Sequencer.prepareCheckpointProposal')
236
237
  private async prepareCheckpointProposal(
237
- epoch: EpochNumber,
238
238
  slot: SlotNumber,
239
+ targetSlot: SlotNumber,
240
+ epoch: EpochNumber,
241
+ targetEpoch: EpochNumber,
239
242
  ts: bigint,
240
- now: bigint,
243
+ nowSeconds: bigint,
241
244
  ): Promise<CheckpointProposalJob | undefined> {
242
- // Check we have not already processed this slot (cheapest check)
245
+ // Check we have not already processed this target slot (cheapest check)
243
246
  // We only check this if enforce timetable is set, since we want to keep processing the same slot if we are not
244
247
  // running against actual time (eg when we use sandbox-style automining)
245
248
  if (
246
249
  this.lastSlotForCheckpointProposalJob &&
247
- this.lastSlotForCheckpointProposalJob >= slot &&
250
+ this.lastSlotForCheckpointProposalJob >= targetSlot &&
248
251
  this.config.enforceTimeTable
249
252
  ) {
250
- this.log.trace(`Slot ${slot} has already been processed`);
253
+ this.log.trace(`Target slot ${targetSlot} has already been processed`);
251
254
  return undefined;
252
255
  }
253
256
 
254
- // But if we have already proposed for this slot, the we definitely have to skip it, automining or not
255
- if (this.lastCheckpointProposed && this.lastCheckpointProposed.header.slotNumber >= slot) {
256
- this.log.trace(`Slot ${slot} has already been published as checkpoint ${this.lastCheckpointProposed.number}`);
257
+ // But if we have already proposed for this slot, then we definitely have to skip it, automining or not
258
+ if (this.lastCheckpointProposed && this.lastCheckpointProposed.header.slotNumber >= targetSlot) {
259
+ this.log.trace(
260
+ `Slot ${targetSlot} has already been published as checkpoint ${this.lastCheckpointProposed.number}`,
261
+ );
257
262
  return undefined;
258
263
  }
259
264
 
260
265
  // Check all components are synced to latest as seen by the archiver (queries all subsystems)
261
266
  const syncedTo = await this.checkSync({ ts, slot });
262
267
  if (!syncedTo) {
263
- await this.tryVoteWhenSyncFails({ slot, ts });
268
+ await this.tryVoteWhenSyncFails({ slot, targetSlot, ts });
264
269
  return undefined;
265
270
  }
266
271
 
267
- // If escape hatch is open for this epoch, do not start checkpoint proposal work and do not attempt invalidations.
272
+ // If escape hatch is open for the target epoch, do not start checkpoint proposal work and do not attempt invalidations.
268
273
  // Still perform governance/slashing voting (as proposer) once per slot.
269
- const isEscapeHatchOpen = await this.epochCache.isEscapeHatchOpen(epoch);
274
+ // When pipelining, we check the target epoch (slot+1's epoch) since that's the epoch we're building for.
275
+ const isEscapeHatchOpen = await this.epochCache.isEscapeHatchOpen(targetEpoch);
270
276
 
271
277
  if (isEscapeHatchOpen) {
272
278
  this.setState(SequencerState.PROPOSER_CHECK, slot);
273
- const [canPropose, proposer] = await this.checkCanPropose(slot);
279
+ const [canPropose, proposer] = await this.checkCanPropose(targetSlot);
274
280
  if (canPropose) {
275
281
  await this.tryVoteWhenEscapeHatchOpen({ slot, proposer });
276
282
  } else {
@@ -287,18 +293,18 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
287
293
  const checkpointNumber = CheckpointNumber(syncedTo.checkpointNumber + 1);
288
294
 
289
295
  const logCtx = {
290
- now,
291
- syncedToL1Ts: syncedTo.l1Timestamp,
292
- syncedToL2Slot: getSlotAtTimestamp(syncedTo.l1Timestamp, this.l1Constants),
296
+ nowSeconds,
297
+ syncedToL2Slot: syncedTo.syncedL2Slot,
293
298
  slot,
299
+ targetSlot,
294
300
  slotTs: ts,
295
301
  checkpointNumber,
296
302
  isPendingChainValid: pick(syncedTo.pendingChainValidationStatus, 'valid', 'reason', 'invalidIndex'),
297
303
  };
298
304
 
299
- // Check that we are a proposer for the next slot
305
+ // Check that we are a proposer for the target slot.
300
306
  this.setState(SequencerState.PROPOSER_CHECK, slot);
301
- const [canPropose, proposer] = await this.checkCanPropose(slot);
307
+ const [canPropose, proposer] = await this.checkCanPropose(targetSlot);
302
308
 
303
309
  // If we are not a proposer check if we should invalidate an invalid checkpoint, and bail
304
310
  if (!canPropose) {
@@ -306,13 +312,13 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
306
312
  return undefined;
307
313
  }
308
314
 
309
- // Check that the slot is not taken by a block already (should never happen, since only us can propose for this slot)
310
- if (syncedTo.block && syncedTo.block.header.getSlot() >= slot) {
315
+ // Check that the target slot is not taken by a block already (should never happen, since only us can propose for this slot)
316
+ if (syncedTo.blockData && syncedTo.blockData.header.getSlot() >= targetSlot) {
311
317
  this.log.warn(
312
- `Cannot propose block at next L2 slot ${slot} since that slot was taken by block ${syncedTo.blockNumber}`,
313
- { ...logCtx, block: syncedTo.block.header.toInspect() },
318
+ `Cannot propose block at target slot ${targetSlot} since that slot was taken by block ${syncedTo.blockNumber}`,
319
+ { ...logCtx, block: syncedTo.blockData.header.toInspect() },
314
320
  );
315
- this.metrics.recordBlockProposalPrecheckFailed('slot_already_taken');
321
+ this.metrics.recordCheckpointPrecheckFailed('slot_already_taken');
316
322
  return undefined;
317
323
  }
318
324
 
@@ -323,7 +329,6 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
323
329
  const proposerForPublisher = this.config.fishermanMode ? undefined : proposer;
324
330
  const { attestorAddress, publisher } = await this.publisherFactory.create(proposerForPublisher);
325
331
  this.log.verbose(`Created publisher at address ${publisher.getSenderAddress()} for attestor ${attestorAddress}`);
326
- this.publisher = publisher;
327
332
 
328
333
  // In fisherman mode, set the actual proposer's address for simulations
329
334
  if (this.config.fishermanMode && proposer) {
@@ -334,13 +339,11 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
334
339
  // Prepare invalidation request if the pending chain is invalid (returns undefined if no need)
335
340
  const invalidateCheckpoint = await publisher.simulateInvalidateCheckpoint(syncedTo.pendingChainValidationStatus);
336
341
 
337
- // Check with the rollup contract if we can indeed propose at the next L2 slot. This check should not fail
342
+ // Check with the rollup contract if we can indeed propose at the target slot. This check should not fail
338
343
  // if all the previous checks are good, but we do it just in case.
339
- const canProposeCheck = await publisher.canProposeAtNextEthBlock(
340
- syncedTo.archive,
341
- proposer ?? EthAddress.ZERO,
342
- invalidateCheckpoint,
343
- );
344
+ const canProposeCheck = await publisher.canProposeAt(syncedTo.archive, proposer ?? EthAddress.ZERO, {
345
+ ...invalidateCheckpoint,
346
+ });
344
347
 
345
348
  if (canProposeCheck === undefined) {
346
349
  this.log.warn(
@@ -348,17 +351,17 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
348
351
  logCtx,
349
352
  );
350
353
  this.emit('proposer-rollup-check-failed', { reason: 'Rollup contract check failed', slot });
351
- this.metrics.recordBlockProposalPrecheckFailed('rollup_contract_check_failed');
354
+ this.metrics.recordCheckpointPrecheckFailed('rollup_contract_check_failed');
352
355
  return undefined;
353
356
  }
354
357
 
355
- if (canProposeCheck.slot !== slot) {
358
+ if (canProposeCheck.slot !== targetSlot) {
356
359
  this.log.warn(
357
- `Cannot propose block due to slot mismatch with rollup contract (this can be caused by a clock out of sync). Expected slot ${slot} but got ${canProposeCheck.slot}.`,
358
- { ...logCtx, rollup: canProposeCheck, expectedSlot: slot },
360
+ `Cannot propose block due to slot mismatch with rollup contract (this can be caused by a clock out of sync). Expected slot ${targetSlot} but got ${canProposeCheck.slot}.`,
361
+ { ...logCtx, rollup: canProposeCheck, expectedSlot: targetSlot },
359
362
  );
360
363
  this.emit('proposer-rollup-check-failed', { reason: 'Slot mismatch', slot });
361
- this.metrics.recordBlockProposalPrecheckFailed('slot_mismatch');
364
+ this.metrics.recordCheckpointPrecheckFailed('slot_mismatch');
362
365
  return undefined;
363
366
  }
364
367
 
@@ -368,17 +371,28 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
368
371
  { ...logCtx, rollup: canProposeCheck, expectedSlot: slot },
369
372
  );
370
373
  this.emit('proposer-rollup-check-failed', { reason: 'Block mismatch', slot });
371
- this.metrics.recordBlockProposalPrecheckFailed('block_number_mismatch');
374
+ this.metrics.recordCheckpointPrecheckFailed('block_number_mismatch');
372
375
  return undefined;
373
376
  }
374
377
 
375
- this.lastSlotForCheckpointProposalJob = slot;
376
- this.log.info(`Preparing checkpoint proposal ${checkpointNumber} at slot ${slot}`, { ...logCtx, proposer });
378
+ this.lastSlotForCheckpointProposalJob = targetSlot;
379
+
380
+ await this.p2pClient.prepareForSlot(targetSlot);
381
+ this.log.info(
382
+ `Preparing checkpoint proposal ${checkpointNumber} for target slot ${targetSlot} during wall-clock slot ${slot}`,
383
+ {
384
+ ...logCtx,
385
+ proposer,
386
+ pipeliningEnabled: this.epochCache.isProposerPipeliningEnabled(),
387
+ },
388
+ );
377
389
 
378
390
  // Create and return the checkpoint proposal job
379
391
  return this.createCheckpointProposalJob(
380
- epoch,
381
392
  slot,
393
+ targetSlot,
394
+ epoch,
395
+ targetEpoch,
382
396
  checkpointNumber,
383
397
  syncedTo.blockNumber,
384
398
  proposer,
@@ -389,8 +403,10 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
389
403
  }
390
404
 
391
405
  protected createCheckpointProposalJob(
392
- epoch: EpochNumber,
393
406
  slot: SlotNumber,
407
+ targetSlot: SlotNumber,
408
+ epoch: EpochNumber,
409
+ targetEpoch: EpochNumber,
394
410
  checkpointNumber: CheckpointNumber,
395
411
  syncedToBlockNumber: BlockNumber,
396
412
  proposer: EthAddress | undefined,
@@ -399,8 +415,10 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
399
415
  invalidateCheckpoint: InvalidateCheckpointRequest | undefined,
400
416
  ): CheckpointProposalJob {
401
417
  return new CheckpointProposalJob(
402
- epoch,
403
418
  slot,
419
+ targetSlot,
420
+ epoch,
421
+ targetEpoch,
404
422
  checkpointNumber,
405
423
  syncedToBlockNumber,
406
424
  proposer,
@@ -429,6 +447,13 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
429
447
  );
430
448
  }
431
449
 
450
+ /**
451
+ * Returns the current sequencer state.
452
+ */
453
+ public getState(): SequencerState {
454
+ return this.state;
455
+ }
456
+
432
457
  /**
433
458
  * Internal helper for setting the sequencer state and checks if we have enough time left in the slot to transition to the new state.
434
459
  * @param proposedState - The new state to transition to.
@@ -475,16 +500,15 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
475
500
  * We don't check against the previous block submitted since it may have been reorg'd out.
476
501
  */
477
502
  protected async checkSync(args: { ts: bigint; slot: SlotNumber }): Promise<SequencerSyncCheckResult | undefined> {
478
- // Check that the archiver and dependencies have synced to the previous L1 slot at least
479
- // TODO(#14766): Archiver reports L1 timestamp based on L1 blocks seen, which means that a missed L1 block will
480
- // cause the archiver L1 timestamp to fall behind, and cause this sequencer to start processing one L1 slot later.
481
- const l1Timestamp = await this.l2BlockSource.getL1Timestamp();
482
- const { slot, ts } = args;
483
- if (l1Timestamp === undefined || l1Timestamp + BigInt(this.l1Constants.ethereumSlotDuration) < ts) {
503
+ // Check that the archiver has fully synced the L2 slot before the one we want to propose in.
504
+ // The archiver reports sync progress via L1 block timestamps and synced checkpoint slots.
505
+ // See getSyncedL2SlotNumber for how missed L1 blocks are handled.
506
+ const syncedL2Slot = await this.l2BlockSource.getSyncedL2SlotNumber();
507
+ const { slot } = args;
508
+ if (syncedL2Slot === undefined || syncedL2Slot + 1 < slot) {
484
509
  this.log.debug(`Cannot propose block at next L2 slot ${slot} due to pending sync from L1`, {
485
510
  slot,
486
- ts,
487
- l1Timestamp,
511
+ syncedL2Slot,
488
512
  });
489
513
  return undefined;
490
514
  }
@@ -524,24 +548,24 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
524
548
  checkpointNumber: CheckpointNumber.ZERO,
525
549
  blockNumber: BlockNumber.ZERO,
526
550
  archive,
527
- l1Timestamp,
551
+ syncedL2Slot,
528
552
  pendingChainValidationStatus,
529
553
  };
530
554
  }
531
555
 
532
- const block = await this.l2BlockSource.getL2Block(blockNumber);
533
- if (!block) {
556
+ const blockData = await this.l2BlockSource.getBlockData(blockNumber);
557
+ if (!blockData) {
534
558
  // this shouldn't really happen because a moment ago we checked that all components were in sync
535
- this.log.error(`Failed to get L2 block ${blockNumber} from the archiver with all components in sync`);
559
+ this.log.error(`Failed to get L2 block data ${blockNumber} from the archiver with all components in sync`);
536
560
  return undefined;
537
561
  }
538
562
 
539
563
  return {
540
- block,
541
- blockNumber: block.number,
542
- checkpointNumber: block.checkpointNumber,
543
- archive: block.archive.root,
544
- l1Timestamp,
564
+ blockData,
565
+ blockNumber: blockData.header.getBlockNumber(),
566
+ checkpointNumber: blockData.checkpointNumber,
567
+ archive: blockData.archive.root,
568
+ syncedL2Slot,
545
569
  pendingChainValidationStatus,
546
570
  };
547
571
  }
@@ -550,17 +574,20 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
550
574
  * Checks if we are the proposer for the next slot.
551
575
  * @returns True if we can propose, and the proposer address (undefined if anyone can propose)
552
576
  */
553
- protected async checkCanPropose(slot: SlotNumber): Promise<[boolean, EthAddress | undefined]> {
577
+ protected async checkCanPropose(targetSlot: SlotNumber): Promise<[boolean, EthAddress | undefined]> {
554
578
  let proposer: EthAddress | undefined;
555
579
 
556
580
  try {
557
- proposer = await this.epochCache.getProposerAttesterAddressInSlot(slot);
581
+ proposer = await this.epochCache.getProposerAttesterAddressInSlot(targetSlot);
558
582
  } catch (e) {
559
583
  if (e instanceof NoCommitteeError) {
560
- this.log.warn(`Cannot propose at next L2 slot ${slot} since the committee does not exist on L1`);
584
+ if (this.lastSlotForNoCommitteeWarning !== targetSlot) {
585
+ this.lastSlotForNoCommitteeWarning = targetSlot;
586
+ this.log.warn(`Cannot propose at target slot ${targetSlot} since the committee does not exist on L1`);
587
+ }
561
588
  return [false, undefined];
562
589
  }
563
- this.log.error(`Error getting proposer for slot ${slot}`, e);
590
+ this.log.error(`Error getting proposer for target slot ${targetSlot}`, e);
564
591
  return [false, undefined];
565
592
  }
566
593
 
@@ -577,10 +604,15 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
577
604
  const weAreProposer = validatorAddresses.some(addr => addr.equals(proposer));
578
605
 
579
606
  if (!weAreProposer) {
580
- this.log.debug(`Cannot propose at slot ${slot} since we are not a proposer`, { validatorAddresses, proposer });
607
+ this.log.debug(`Cannot propose at target slot ${targetSlot} since we are not a proposer`, {
608
+ targetSlot,
609
+ validatorAddresses,
610
+ proposer,
611
+ });
581
612
  return [false, proposer];
582
613
  }
583
614
 
615
+ this.log.debug(`We are the proposer for target slot ${targetSlot}`, { targetSlot, proposer });
584
616
  return [true, proposer];
585
617
  }
586
618
 
@@ -589,8 +621,8 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
589
621
  * This allows the sequencer to participate in governance/slashing votes even when it cannot build blocks.
590
622
  */
591
623
  @trackSpan('Seqeuencer.tryVoteWhenSyncFails', ({ slot }) => ({ [Attributes.SLOT_NUMBER]: slot }))
592
- protected async tryVoteWhenSyncFails(args: { slot: SlotNumber; ts: bigint }): Promise<void> {
593
- const { slot } = args;
624
+ protected async tryVoteWhenSyncFails(args: { slot: SlotNumber; targetSlot: SlotNumber; ts: bigint }): Promise<void> {
625
+ const { slot, targetSlot } = args;
594
626
 
595
627
  // Prevent duplicate attempts in the same slot
596
628
  if (this.lastSlotForFallbackVote === slot) {
@@ -618,7 +650,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
618
650
  });
619
651
 
620
652
  // Check if we're a proposer or proposal is open
621
- const [canPropose, proposer] = await this.checkCanPropose(slot);
653
+ const [canPropose, proposer] = await this.checkCanPropose(targetSlot);
622
654
  if (!canPropose) {
623
655
  this.log.trace(`Cannot vote in slot ${slot} since we are not a proposer`, { slot, proposer });
624
656
  return;
@@ -635,9 +667,9 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
635
667
  slot,
636
668
  });
637
669
 
638
- // Enqueue governance and slashing votes
670
+ // Enqueue governance and slashing votes (voter uses the target slot for L1 submission)
639
671
  const voter = new CheckpointVoter(
640
- slot,
672
+ targetSlot,
641
673
  publisher,
642
674
  attestorAddress,
643
675
  this.validatorClient,
@@ -717,7 +749,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
717
749
  syncedTo: SequencerSyncCheckResult,
718
750
  currentSlot: SlotNumber,
719
751
  ): Promise<void> {
720
- const { pendingChainValidationStatus, l1Timestamp } = syncedTo;
752
+ const { pendingChainValidationStatus, syncedL2Slot } = syncedTo;
721
753
  if (pendingChainValidationStatus.valid) {
722
754
  return;
723
755
  }
@@ -732,7 +764,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
732
764
 
733
765
  const logData = {
734
766
  invalidL1Timestamp: invalidCheckpointTimestamp,
735
- l1Timestamp,
767
+ syncedL2Slot,
736
768
  invalidCheckpoint: pendingChainValidationStatus.checkpoint,
737
769
  secondsBeforeInvalidatingBlockAsCommitteeMember,
738
770
  secondsBeforeInvalidatingBlockAsNonCommitteeMember,
@@ -860,6 +892,11 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
860
892
  return this.validatorClient?.getValidatorAddresses();
861
893
  }
862
894
 
895
+ /** Updates the publisher factory's node keystore adapter after a keystore reload. */
896
+ public updatePublisherNodeKeyStore(adapter: NodeKeystoreAdapter): void {
897
+ this.publisherFactory.updateNodeKeyStore(adapter);
898
+ }
899
+
863
900
  public getConfig() {
864
901
  return this.config;
865
902
  }
@@ -870,10 +907,10 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
870
907
  }
871
908
 
872
909
  type SequencerSyncCheckResult = {
873
- block?: L2Block;
910
+ blockData?: BlockData;
874
911
  checkpointNumber: CheckpointNumber;
875
912
  blockNumber: BlockNumber;
876
913
  archive: Fr;
877
- l1Timestamp: bigint;
914
+ syncedL2Slot: SlotNumber;
878
915
  pendingChainValidationStatus: ValidateCheckpointResult;
879
916
  };
@@ -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_;