@aztec/sequencer-client 0.0.1-commit.6d3c34e → 0.0.1-commit.7035c9bd6

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 (97) hide show
  1. package/dest/client/sequencer-client.d.ts +12 -7
  2. package/dest/client/sequencer-client.d.ts.map +1 -1
  3. package/dest/client/sequencer-client.js +56 -17
  4. package/dest/config.d.ts +26 -7
  5. package/dest/config.d.ts.map +1 -1
  6. package/dest/config.js +47 -30
  7. package/dest/global_variable_builder/global_builder.d.ts +2 -4
  8. package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
  9. package/dest/global_variable_builder/global_builder.js +7 -6
  10. package/dest/index.d.ts +2 -2
  11. package/dest/index.d.ts.map +1 -1
  12. package/dest/index.js +1 -1
  13. package/dest/publisher/config.d.ts +35 -17
  14. package/dest/publisher/config.d.ts.map +1 -1
  15. package/dest/publisher/config.js +106 -42
  16. package/dest/publisher/index.d.ts +2 -1
  17. package/dest/publisher/index.d.ts.map +1 -1
  18. package/dest/publisher/l1_tx_failed_store/factory.d.ts +11 -0
  19. package/dest/publisher/l1_tx_failed_store/factory.d.ts.map +1 -0
  20. package/dest/publisher/l1_tx_failed_store/factory.js +22 -0
  21. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts +59 -0
  22. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -0
  23. package/dest/publisher/l1_tx_failed_store/failed_tx_store.js +1 -0
  24. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts +15 -0
  25. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts.map +1 -0
  26. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.js +34 -0
  27. package/dest/publisher/l1_tx_failed_store/index.d.ts +4 -0
  28. package/dest/publisher/l1_tx_failed_store/index.d.ts.map +1 -0
  29. package/dest/publisher/l1_tx_failed_store/index.js +2 -0
  30. package/dest/publisher/sequencer-publisher-factory.d.ts +11 -3
  31. package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
  32. package/dest/publisher/sequencer-publisher-factory.js +27 -2
  33. package/dest/publisher/sequencer-publisher-metrics.d.ts +1 -1
  34. package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
  35. package/dest/publisher/sequencer-publisher-metrics.js +12 -4
  36. package/dest/publisher/sequencer-publisher.d.ts +30 -10
  37. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  38. package/dest/publisher/sequencer-publisher.js +362 -56
  39. package/dest/sequencer/checkpoint_proposal_job.d.ts +42 -11
  40. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
  41. package/dest/sequencer/checkpoint_proposal_job.js +322 -122
  42. package/dest/sequencer/checkpoint_voter.d.ts +3 -2
  43. package/dest/sequencer/checkpoint_voter.d.ts.map +1 -1
  44. package/dest/sequencer/checkpoint_voter.js +34 -10
  45. package/dest/sequencer/events.d.ts +2 -1
  46. package/dest/sequencer/events.d.ts.map +1 -1
  47. package/dest/sequencer/index.d.ts +1 -2
  48. package/dest/sequencer/index.d.ts.map +1 -1
  49. package/dest/sequencer/index.js +0 -1
  50. package/dest/sequencer/metrics.d.ts +21 -5
  51. package/dest/sequencer/metrics.d.ts.map +1 -1
  52. package/dest/sequencer/metrics.js +122 -30
  53. package/dest/sequencer/sequencer.d.ts +43 -20
  54. package/dest/sequencer/sequencer.d.ts.map +1 -1
  55. package/dest/sequencer/sequencer.js +151 -82
  56. package/dest/sequencer/timetable.d.ts +4 -6
  57. package/dest/sequencer/timetable.d.ts.map +1 -1
  58. package/dest/sequencer/timetable.js +7 -11
  59. package/dest/sequencer/types.d.ts +2 -2
  60. package/dest/sequencer/types.d.ts.map +1 -1
  61. package/dest/test/index.d.ts +3 -5
  62. package/dest/test/index.d.ts.map +1 -1
  63. package/dest/test/mock_checkpoint_builder.d.ts +23 -19
  64. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
  65. package/dest/test/mock_checkpoint_builder.js +67 -38
  66. package/dest/test/utils.d.ts +8 -8
  67. package/dest/test/utils.d.ts.map +1 -1
  68. package/dest/test/utils.js +12 -11
  69. package/package.json +29 -28
  70. package/src/client/sequencer-client.ts +77 -18
  71. package/src/config.ts +66 -41
  72. package/src/global_variable_builder/global_builder.ts +6 -5
  73. package/src/index.ts +1 -6
  74. package/src/publisher/config.ts +121 -43
  75. package/src/publisher/index.ts +3 -0
  76. package/src/publisher/l1_tx_failed_store/factory.ts +32 -0
  77. package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +55 -0
  78. package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +46 -0
  79. package/src/publisher/l1_tx_failed_store/index.ts +3 -0
  80. package/src/publisher/sequencer-publisher-factory.ts +38 -6
  81. package/src/publisher/sequencer-publisher-metrics.ts +7 -3
  82. package/src/publisher/sequencer-publisher.ts +360 -69
  83. package/src/sequencer/checkpoint_proposal_job.ts +449 -142
  84. package/src/sequencer/checkpoint_voter.ts +32 -7
  85. package/src/sequencer/events.ts +1 -1
  86. package/src/sequencer/index.ts +0 -1
  87. package/src/sequencer/metrics.ts +138 -32
  88. package/src/sequencer/sequencer.ts +200 -91
  89. package/src/sequencer/timetable.ts +13 -12
  90. package/src/sequencer/types.ts +1 -1
  91. package/src/test/index.ts +2 -4
  92. package/src/test/mock_checkpoint_builder.ts +122 -78
  93. package/src/test/utils.ts +24 -14
  94. package/dest/sequencer/block_builder.d.ts +0 -26
  95. package/dest/sequencer/block_builder.d.ts.map +0 -1
  96. package/dest/sequencer/block_builder.js +0 -129
  97. package/src/sequencer/block_builder.ts +0 -216
@@ -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 { L2BlockNew, L2BlockSink, L2BlockSource, ValidateCheckpointResult } from '@aztec/stdlib/block';
15
+ import type { BlockData, L2BlockSink, L2BlockSource, ValidateCheckpointResult } from '@aztec/stdlib/block';
16
16
  import type { Checkpoint } from '@aztec/stdlib/checkpoint';
17
- 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
 
@@ -57,8 +57,11 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
57
57
  private state = SequencerState.STOPPED;
58
58
  private metrics: SequencerMetrics;
59
59
 
60
- /** The last slot for which we attempted to vote when sync failed, to prevent duplicate attempts. */
61
- private lastSlotForVoteWhenSyncFailed: SlotNumber | undefined;
60
+ /** The last slot for which we attempted to perform our voting duties with degraded block production */
61
+ private lastSlotForFallbackVote: SlotNumber | undefined;
62
+
63
+ /** The last slot for which we logged "no committee" warning, to avoid spam */
64
+ private lastSlotForNoCommitteeWarning: SlotNumber | undefined;
62
65
 
63
66
  /** The last slot for which we triggered a checkpoint proposal job, to prevent duplicate attempts. */
64
67
  private lastSlotForCheckpointProposalJob: SlotNumber | undefined;
@@ -72,14 +75,6 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
72
75
  /** The maximum number of seconds that the sequencer can be into a slot to transition to a particular state. */
73
76
  protected timetable!: SequencerTimetable;
74
77
 
75
- // This shouldn't be here as this gets re-created each time we build/propose a block.
76
- // But we have a number of tests that abuse/rely on this class having a permanent publisher.
77
- // As long as those tests only configure a single publisher they will continue to work.
78
- // This will get re-assigned every time the sequencer goes to build a new block to a publisher that is valid
79
- // for the block proposer.
80
- // TODO(palla/mbps): Remove this field and fix tests
81
- protected publisher: SequencerPublisher | undefined;
82
-
83
78
  /** Config for the sequencer */
84
79
  protected config: ResolvedSequencerConfig = DefaultSequencerConfig;
85
80
 
@@ -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
+ this.publisherFactory.interruptAll();
157
151
  await this.runningPromise?.stop();
158
152
  this.setState(SequencerState.STOPPED, undefined, { force: true });
159
153
  this.log.info('Stopped sequencer');
@@ -166,7 +160,6 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
166
160
  } catch (err) {
167
161
  this.emit('checkpoint-error', { error: err as Error });
168
162
  if (err instanceof SequencerTooSlowError) {
169
- // TODO(palla/mbps): Add missing states
170
163
  // Log as warn only if we had to abort halfway through the block proposal
171
164
  const logLvl = [SequencerState.INITIALIZING_CHECKPOINT, SequencerState.PROPOSER_CHECK].includes(
172
165
  err.proposedState,
@@ -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(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;
@@ -235,31 +236,56 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
235
236
  @trackSpan('Sequencer.prepareCheckpointProposal')
236
237
  private async prepareCheckpointProposal(
237
238
  slot: SlotNumber,
239
+ targetSlot: SlotNumber,
240
+ epoch: EpochNumber,
241
+ targetEpoch: EpochNumber,
238
242
  ts: bigint,
239
- now: bigint,
243
+ nowSeconds: bigint,
240
244
  ): Promise<CheckpointProposalJob | undefined> {
241
- // Check we have not already processed this slot (cheapest check)
245
+ // Check we have not already processed this target slot (cheapest check)
242
246
  // We only check this if enforce timetable is set, since we want to keep processing the same slot if we are not
243
247
  // running against actual time (eg when we use sandbox-style automining)
244
248
  if (
245
249
  this.lastSlotForCheckpointProposalJob &&
246
- this.lastSlotForCheckpointProposalJob >= slot &&
250
+ this.lastSlotForCheckpointProposalJob >= targetSlot &&
247
251
  this.config.enforceTimeTable
248
252
  ) {
249
- this.log.trace(`Slot ${slot} has already been processed`);
253
+ this.log.trace(`Target slot ${targetSlot} has already been processed`);
250
254
  return undefined;
251
255
  }
252
256
 
253
- // But if we have already proposed for this slot, the we definitely have to skip it, automining or not
254
- if (this.lastCheckpointProposed && this.lastCheckpointProposed.header.slotNumber >= slot) {
255
- 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
+ );
256
262
  return undefined;
257
263
  }
258
264
 
259
265
  // Check all components are synced to latest as seen by the archiver (queries all subsystems)
260
266
  const syncedTo = await this.checkSync({ ts, slot });
261
267
  if (!syncedTo) {
262
- await this.tryVoteWhenSyncFails({ slot, ts });
268
+ await this.tryVoteWhenSyncFails({ slot, targetSlot, ts });
269
+ return undefined;
270
+ }
271
+
272
+ // If escape hatch is open for the target epoch, do not start checkpoint proposal work and do not attempt invalidations.
273
+ // Still perform governance/slashing voting (as proposer) once per slot.
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);
276
+
277
+ if (isEscapeHatchOpen) {
278
+ this.setState(SequencerState.PROPOSER_CHECK, slot);
279
+ const [canPropose, proposer] = await this.checkCanPropose(targetSlot);
280
+ if (canPropose) {
281
+ await this.tryVoteWhenEscapeHatchOpen({ slot, proposer });
282
+ } else {
283
+ this.log.trace(`Escape hatch open but we are not proposer, skipping vote-only actions`, {
284
+ slot,
285
+ epoch,
286
+ proposer,
287
+ });
288
+ }
263
289
  return undefined;
264
290
  }
265
291
 
@@ -267,18 +293,18 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
267
293
  const checkpointNumber = CheckpointNumber(syncedTo.checkpointNumber + 1);
268
294
 
269
295
  const logCtx = {
270
- now,
271
- syncedToL1Ts: syncedTo.l1Timestamp,
272
- syncedToL2Slot: getSlotAtTimestamp(syncedTo.l1Timestamp, this.l1Constants),
296
+ nowSeconds,
297
+ syncedToL2Slot: syncedTo.syncedL2Slot,
273
298
  slot,
299
+ targetSlot,
274
300
  slotTs: ts,
275
301
  checkpointNumber,
276
302
  isPendingChainValid: pick(syncedTo.pendingChainValidationStatus, 'valid', 'reason', 'invalidIndex'),
277
303
  };
278
304
 
279
- // Check that we are a proposer for the next slot
305
+ // Check that we are a proposer for the target slot.
280
306
  this.setState(SequencerState.PROPOSER_CHECK, slot);
281
- const [canPropose, proposer] = await this.checkCanPropose(slot);
307
+ const [canPropose, proposer] = await this.checkCanPropose(targetSlot);
282
308
 
283
309
  // If we are not a proposer check if we should invalidate an invalid checkpoint, and bail
284
310
  if (!canPropose) {
@@ -286,13 +312,13 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
286
312
  return undefined;
287
313
  }
288
314
 
289
- // Check that the slot is not taken by a block already (should never happen, since only us can propose for this slot)
290
- if (syncedTo.block && syncedTo.block.header.getSlot() >= slot) {
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) {
291
317
  this.log.warn(
292
- `Cannot propose block at next L2 slot ${slot} since that slot was taken by block ${syncedTo.blockNumber}`,
293
- { ...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() },
294
320
  );
295
- this.metrics.recordBlockProposalPrecheckFailed('slot_already_taken');
321
+ this.metrics.recordCheckpointPrecheckFailed('slot_already_taken');
296
322
  return undefined;
297
323
  }
298
324
 
@@ -303,7 +329,6 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
303
329
  const proposerForPublisher = this.config.fishermanMode ? undefined : proposer;
304
330
  const { attestorAddress, publisher } = await this.publisherFactory.create(proposerForPublisher);
305
331
  this.log.verbose(`Created publisher at address ${publisher.getSenderAddress()} for attestor ${attestorAddress}`);
306
- this.publisher = publisher;
307
332
 
308
333
  // In fisherman mode, set the actual proposer's address for simulations
309
334
  if (this.config.fishermanMode && proposer) {
@@ -314,13 +339,11 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
314
339
  // Prepare invalidation request if the pending chain is invalid (returns undefined if no need)
315
340
  const invalidateCheckpoint = await publisher.simulateInvalidateCheckpoint(syncedTo.pendingChainValidationStatus);
316
341
 
317
- // 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
318
343
  // if all the previous checks are good, but we do it just in case.
319
- const canProposeCheck = await publisher.canProposeAtNextEthBlock(
320
- syncedTo.archive,
321
- proposer ?? EthAddress.ZERO,
322
- invalidateCheckpoint,
323
- );
344
+ const canProposeCheck = await publisher.canProposeAt(syncedTo.archive, proposer ?? EthAddress.ZERO, {
345
+ ...invalidateCheckpoint,
346
+ });
324
347
 
325
348
  if (canProposeCheck === undefined) {
326
349
  this.log.warn(
@@ -328,17 +351,17 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
328
351
  logCtx,
329
352
  );
330
353
  this.emit('proposer-rollup-check-failed', { reason: 'Rollup contract check failed', slot });
331
- this.metrics.recordBlockProposalPrecheckFailed('rollup_contract_check_failed');
354
+ this.metrics.recordCheckpointPrecheckFailed('rollup_contract_check_failed');
332
355
  return undefined;
333
356
  }
334
357
 
335
- if (canProposeCheck.slot !== slot) {
358
+ if (canProposeCheck.slot !== targetSlot) {
336
359
  this.log.warn(
337
- `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}.`,
338
- { ...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 },
339
362
  );
340
363
  this.emit('proposer-rollup-check-failed', { reason: 'Slot mismatch', slot });
341
- this.metrics.recordBlockProposalPrecheckFailed('slot_mismatch');
364
+ this.metrics.recordCheckpointPrecheckFailed('slot_mismatch');
342
365
  return undefined;
343
366
  }
344
367
 
@@ -348,16 +371,28 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
348
371
  { ...logCtx, rollup: canProposeCheck, expectedSlot: slot },
349
372
  );
350
373
  this.emit('proposer-rollup-check-failed', { reason: 'Block mismatch', slot });
351
- this.metrics.recordBlockProposalPrecheckFailed('block_number_mismatch');
374
+ this.metrics.recordCheckpointPrecheckFailed('block_number_mismatch');
352
375
  return undefined;
353
376
  }
354
377
 
355
- this.lastSlotForCheckpointProposalJob = slot;
356
- 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
+ );
357
389
 
358
390
  // Create and return the checkpoint proposal job
359
391
  return this.createCheckpointProposalJob(
360
392
  slot,
393
+ targetSlot,
394
+ epoch,
395
+ targetEpoch,
361
396
  checkpointNumber,
362
397
  syncedTo.blockNumber,
363
398
  proposer,
@@ -369,6 +404,9 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
369
404
 
370
405
  protected createCheckpointProposalJob(
371
406
  slot: SlotNumber,
407
+ targetSlot: SlotNumber,
408
+ epoch: EpochNumber,
409
+ targetEpoch: EpochNumber,
372
410
  checkpointNumber: CheckpointNumber,
373
411
  syncedToBlockNumber: BlockNumber,
374
412
  proposer: EthAddress | undefined,
@@ -378,6 +416,9 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
378
416
  ): CheckpointProposalJob {
379
417
  return new CheckpointProposalJob(
380
418
  slot,
419
+ targetSlot,
420
+ epoch,
421
+ targetEpoch,
381
422
  checkpointNumber,
382
423
  syncedToBlockNumber,
383
424
  proposer,
@@ -389,6 +430,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
389
430
  this.p2pClient,
390
431
  this.worldState,
391
432
  this.l1ToL2MessageSource,
433
+ this.l2BlockSource,
392
434
  this.checkpointsBuilder,
393
435
  this.l2BlockSource,
394
436
  this.l1Constants,
@@ -400,11 +442,18 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
400
442
  this.metrics,
401
443
  this,
402
444
  this.setState.bind(this),
403
- this.log,
404
445
  this.tracer,
446
+ this.log.getBindings(),
405
447
  );
406
448
  }
407
449
 
450
+ /**
451
+ * Returns the current sequencer state.
452
+ */
453
+ public getState(): SequencerState {
454
+ return this.state;
455
+ }
456
+
408
457
  /**
409
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.
410
459
  * @param proposedState - The new state to transition to.
@@ -451,16 +500,15 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
451
500
  * We don't check against the previous block submitted since it may have been reorg'd out.
452
501
  */
453
502
  protected async checkSync(args: { ts: bigint; slot: SlotNumber }): Promise<SequencerSyncCheckResult | undefined> {
454
- // Check that the archiver and dependencies have synced to the previous L1 slot at least
503
+ // Check that the archiver has fully synced the L2 slot before the one we want to propose in.
455
504
  // TODO(#14766): Archiver reports L1 timestamp based on L1 blocks seen, which means that a missed L1 block will
456
505
  // cause the archiver L1 timestamp to fall behind, and cause this sequencer to start processing one L1 slot later.
457
- const l1Timestamp = await this.l2BlockSource.getL1Timestamp();
458
- const { slot, ts } = args;
459
- if (l1Timestamp === undefined || l1Timestamp + BigInt(this.l1Constants.ethereumSlotDuration) < ts) {
506
+ const syncedL2Slot = await this.l2BlockSource.getSyncedL2SlotNumber();
507
+ const { slot } = args;
508
+ if (syncedL2Slot === undefined || syncedL2Slot + 1 < slot) {
460
509
  this.log.debug(`Cannot propose block at next L2 slot ${slot} due to pending sync from L1`, {
461
510
  slot,
462
- ts,
463
- l1Timestamp,
511
+ syncedL2Slot,
464
512
  });
465
513
  return undefined;
466
514
  }
@@ -500,24 +548,24 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
500
548
  checkpointNumber: CheckpointNumber.ZERO,
501
549
  blockNumber: BlockNumber.ZERO,
502
550
  archive,
503
- l1Timestamp,
551
+ syncedL2Slot,
504
552
  pendingChainValidationStatus,
505
553
  };
506
554
  }
507
555
 
508
- const block = await this.l2BlockSource.getL2BlockNew(blockNumber);
509
- if (!block) {
556
+ const blockData = await this.l2BlockSource.getBlockData(blockNumber);
557
+ if (!blockData) {
510
558
  // this shouldn't really happen because a moment ago we checked that all components were in sync
511
- this.log.error(`Failed to get L2 block ${blockNumber} from the archiver with all components in sync`);
559
+ this.log.error(`Failed to get L2 block data ${blockNumber} from the archiver with all components in sync`);
512
560
  return undefined;
513
561
  }
514
562
 
515
563
  return {
516
- block,
517
- blockNumber: block.number,
518
- checkpointNumber: block.checkpointNumber,
519
- archive: block.archive.root,
520
- l1Timestamp,
564
+ blockData,
565
+ blockNumber: blockData.header.getBlockNumber(),
566
+ checkpointNumber: blockData.checkpointNumber,
567
+ archive: blockData.archive.root,
568
+ syncedL2Slot,
521
569
  pendingChainValidationStatus,
522
570
  };
523
571
  }
@@ -526,17 +574,20 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
526
574
  * Checks if we are the proposer for the next slot.
527
575
  * @returns True if we can propose, and the proposer address (undefined if anyone can propose)
528
576
  */
529
- protected async checkCanPropose(slot: SlotNumber): Promise<[boolean, EthAddress | undefined]> {
577
+ protected async checkCanPropose(targetSlot: SlotNumber): Promise<[boolean, EthAddress | undefined]> {
530
578
  let proposer: EthAddress | undefined;
531
579
 
532
580
  try {
533
- proposer = await this.epochCache.getProposerAttesterAddressInSlot(slot);
581
+ proposer = await this.epochCache.getProposerAttesterAddressInSlot(targetSlot);
534
582
  } catch (e) {
535
583
  if (e instanceof NoCommitteeError) {
536
- 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
+ }
537
588
  return [false, undefined];
538
589
  }
539
- this.log.error(`Error getting proposer for slot ${slot}`, e);
590
+ this.log.error(`Error getting proposer for target slot ${targetSlot}`, e);
540
591
  return [false, undefined];
541
592
  }
542
593
 
@@ -553,10 +604,15 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
553
604
  const weAreProposer = validatorAddresses.some(addr => addr.equals(proposer));
554
605
 
555
606
  if (!weAreProposer) {
556
- 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
+ });
557
612
  return [false, proposer];
558
613
  }
559
614
 
615
+ this.log.debug(`We are the proposer for target slot ${targetSlot}`, { targetSlot, proposer });
560
616
  return [true, proposer];
561
617
  }
562
618
 
@@ -565,11 +621,11 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
565
621
  * This allows the sequencer to participate in governance/slashing votes even when it cannot build blocks.
566
622
  */
567
623
  @trackSpan('Seqeuencer.tryVoteWhenSyncFails', ({ slot }) => ({ [Attributes.SLOT_NUMBER]: slot }))
568
- protected async tryVoteWhenSyncFails(args: { slot: SlotNumber; ts: bigint }): Promise<void> {
569
- const { slot } = args;
624
+ protected async tryVoteWhenSyncFails(args: { slot: SlotNumber; targetSlot: SlotNumber; ts: bigint }): Promise<void> {
625
+ const { slot, targetSlot } = args;
570
626
 
571
627
  // Prevent duplicate attempts in the same slot
572
- if (this.lastSlotForVoteWhenSyncFailed === slot) {
628
+ if (this.lastSlotForFallbackVote === slot) {
573
629
  this.log.trace(`Already attempted to vote in slot ${slot} (skipping)`);
574
630
  return;
575
631
  }
@@ -594,14 +650,14 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
594
650
  });
595
651
 
596
652
  // Check if we're a proposer or proposal is open
597
- const [canPropose, proposer] = await this.checkCanPropose(slot);
653
+ const [canPropose, proposer] = await this.checkCanPropose(targetSlot);
598
654
  if (!canPropose) {
599
655
  this.log.trace(`Cannot vote in slot ${slot} since we are not a proposer`, { slot, proposer });
600
656
  return;
601
657
  }
602
658
 
603
659
  // Mark this slot as attempted
604
- this.lastSlotForVoteWhenSyncFailed = slot;
660
+ this.lastSlotForFallbackVote = slot;
605
661
 
606
662
  // Get a publisher for voting
607
663
  const { attestorAddress, publisher } = await this.publisherFactory.create(proposer);
@@ -611,9 +667,9 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
611
667
  slot,
612
668
  });
613
669
 
614
- // Enqueue governance and slashing votes
670
+ // Enqueue governance and slashing votes (voter uses the target slot for L1 submission)
615
671
  const voter = new CheckpointVoter(
616
- slot,
672
+ targetSlot,
617
673
  publisher,
618
674
  attestorAddress,
619
675
  this.validatorClient,
@@ -636,7 +692,55 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
636
692
  }
637
693
 
638
694
  /**
639
- * Considers invalidating a checkpoint if the pending chain is invalid. Depends on how long the invalid checkpoint
695
+ * Tries to vote on slashing actions and governance proposals when escape hatch is open.
696
+ * This allows the sequencer to participate in voting without performing checkpoint proposal work.
697
+ */
698
+ @trackSpan('Sequencer.tryVoteWhenEscapeHatchOpen', ({ slot }) => ({ [Attributes.SLOT_NUMBER]: slot }))
699
+ protected async tryVoteWhenEscapeHatchOpen(args: {
700
+ slot: SlotNumber;
701
+ proposer: EthAddress | undefined;
702
+ }): Promise<void> {
703
+ const { slot, proposer } = args;
704
+
705
+ // Prevent duplicate attempts in the same slot
706
+ if (this.lastSlotForFallbackVote === slot) {
707
+ this.log.trace(`Already attempted to vote in slot ${slot} (escape hatch open, skipping)`);
708
+ return;
709
+ }
710
+
711
+ // Mark this slot as attempted
712
+ this.lastSlotForFallbackVote = slot;
713
+
714
+ const { attestorAddress, publisher } = await this.publisherFactory.create(proposer);
715
+
716
+ this.log.debug(`Escape hatch open for slot ${slot}, attempting vote-only actions`, { slot, attestorAddress });
717
+
718
+ const voter = new CheckpointVoter(
719
+ slot,
720
+ publisher,
721
+ attestorAddress,
722
+ this.validatorClient,
723
+ this.slasherClient,
724
+ this.l1Constants,
725
+ this.config,
726
+ this.metrics,
727
+ this.log,
728
+ );
729
+
730
+ const votesPromises = voter.enqueueVotes();
731
+ const votes = await Promise.all(votesPromises);
732
+
733
+ if (votes.every(p => !p)) {
734
+ this.log.debug(`No votes to enqueue for slot ${slot} (escape hatch open)`);
735
+ return;
736
+ }
737
+
738
+ this.log.info(`Voting in slot ${slot} (escape hatch open)`, { slot });
739
+ await publisher.sendRequests();
740
+ }
741
+
742
+ /**
743
+ * Considers invalidating a block if the pending chain is invalid. Depends on how long the invalid block
640
744
  * has been there without being invalidated and whether the sequencer is in the committee or not. We always
641
745
  * have the proposer try to invalidate, but if they fail, the sequencers in the committee are expected to try,
642
746
  * and if they fail, any sequencer will try as well.
@@ -645,7 +749,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
645
749
  syncedTo: SequencerSyncCheckResult,
646
750
  currentSlot: SlotNumber,
647
751
  ): Promise<void> {
648
- const { pendingChainValidationStatus, l1Timestamp } = syncedTo;
752
+ const { pendingChainValidationStatus, syncedL2Slot } = syncedTo;
649
753
  if (pendingChainValidationStatus.valid) {
650
754
  return;
651
755
  }
@@ -660,7 +764,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
660
764
 
661
765
  const logData = {
662
766
  invalidL1Timestamp: invalidCheckpointTimestamp,
663
- l1Timestamp,
767
+ syncedL2Slot,
664
768
  invalidCheckpoint: pendingChainValidationStatus.checkpoint,
665
769
  secondsBeforeInvalidatingBlockAsCommitteeMember,
666
770
  secondsBeforeInvalidatingBlockAsNonCommitteeMember,
@@ -788,6 +892,11 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
788
892
  return this.validatorClient?.getValidatorAddresses();
789
893
  }
790
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
+
791
900
  public getConfig() {
792
901
  return this.config;
793
902
  }
@@ -798,10 +907,10 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
798
907
  }
799
908
 
800
909
  type SequencerSyncCheckResult = {
801
- block?: L2BlockNew;
910
+ blockData?: BlockData;
802
911
  checkpointNumber: CheckpointNumber;
803
912
  blockNumber: BlockNumber;
804
913
  archive: Fr;
805
- l1Timestamp: bigint;
914
+ syncedL2Slot: SlotNumber;
806
915
  pendingChainValidationStatus: ValidateCheckpointResult;
807
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,