@aztec/sequencer-client 4.0.0-nightly.20250907 → 4.0.0-nightly.20260108

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 (108) hide show
  1. package/dest/client/index.d.ts +1 -1
  2. package/dest/client/sequencer-client.d.ts +10 -8
  3. package/dest/client/sequencer-client.d.ts.map +1 -1
  4. package/dest/client/sequencer-client.js +40 -28
  5. package/dest/config.d.ts +13 -5
  6. package/dest/config.d.ts.map +1 -1
  7. package/dest/config.js +82 -25
  8. package/dest/global_variable_builder/global_builder.d.ts +22 -16
  9. package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
  10. package/dest/global_variable_builder/global_builder.js +52 -39
  11. package/dest/global_variable_builder/index.d.ts +1 -1
  12. package/dest/index.d.ts +2 -2
  13. package/dest/index.d.ts.map +1 -1
  14. package/dest/index.js +1 -1
  15. package/dest/publisher/config.d.ts +11 -8
  16. package/dest/publisher/config.d.ts.map +1 -1
  17. package/dest/publisher/config.js +21 -13
  18. package/dest/publisher/index.d.ts +2 -2
  19. package/dest/publisher/index.d.ts.map +1 -1
  20. package/dest/publisher/index.js +1 -1
  21. package/dest/publisher/sequencer-publisher-factory.d.ts +11 -5
  22. package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
  23. package/dest/publisher/sequencer-publisher-factory.js +9 -2
  24. package/dest/publisher/sequencer-publisher-metrics.d.ts +4 -4
  25. package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
  26. package/dest/publisher/sequencer-publisher-metrics.js +1 -1
  27. package/dest/publisher/sequencer-publisher.d.ts +78 -70
  28. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  29. package/dest/publisher/sequencer-publisher.js +687 -182
  30. package/dest/sequencer/block_builder.d.ts +6 -10
  31. package/dest/sequencer/block_builder.d.ts.map +1 -1
  32. package/dest/sequencer/block_builder.js +21 -10
  33. package/dest/sequencer/checkpoint_builder.d.ts +63 -0
  34. package/dest/sequencer/checkpoint_builder.d.ts.map +1 -0
  35. package/dest/sequencer/checkpoint_builder.js +131 -0
  36. package/dest/sequencer/checkpoint_proposal_job.d.ts +76 -0
  37. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -0
  38. package/dest/sequencer/checkpoint_proposal_job.js +1070 -0
  39. package/dest/sequencer/checkpoint_voter.d.ts +34 -0
  40. package/dest/sequencer/checkpoint_voter.d.ts.map +1 -0
  41. package/dest/sequencer/checkpoint_voter.js +85 -0
  42. package/dest/sequencer/config.d.ts +3 -2
  43. package/dest/sequencer/config.d.ts.map +1 -1
  44. package/dest/sequencer/errors.d.ts +11 -0
  45. package/dest/sequencer/errors.d.ts.map +1 -0
  46. package/dest/sequencer/errors.js +15 -0
  47. package/dest/sequencer/events.d.ts +46 -0
  48. package/dest/sequencer/events.d.ts.map +1 -0
  49. package/dest/sequencer/events.js +1 -0
  50. package/dest/sequencer/index.d.ts +5 -1
  51. package/dest/sequencer/index.d.ts.map +1 -1
  52. package/dest/sequencer/index.js +4 -0
  53. package/dest/sequencer/metrics.d.ts +37 -20
  54. package/dest/sequencer/metrics.d.ts.map +1 -1
  55. package/dest/sequencer/metrics.js +211 -85
  56. package/dest/sequencer/sequencer.d.ts +110 -121
  57. package/dest/sequencer/sequencer.d.ts.map +1 -1
  58. package/dest/sequencer/sequencer.js +809 -524
  59. package/dest/sequencer/timetable.d.ts +57 -21
  60. package/dest/sequencer/timetable.d.ts.map +1 -1
  61. package/dest/sequencer/timetable.js +150 -68
  62. package/dest/sequencer/types.d.ts +3 -0
  63. package/dest/sequencer/types.d.ts.map +1 -0
  64. package/dest/sequencer/types.js +1 -0
  65. package/dest/sequencer/utils.d.ts +20 -28
  66. package/dest/sequencer/utils.d.ts.map +1 -1
  67. package/dest/sequencer/utils.js +12 -24
  68. package/dest/test/index.d.ts +4 -2
  69. package/dest/test/index.d.ts.map +1 -1
  70. package/dest/test/mock_checkpoint_builder.d.ts +83 -0
  71. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -0
  72. package/dest/test/mock_checkpoint_builder.js +179 -0
  73. package/dest/test/utils.d.ts +49 -0
  74. package/dest/test/utils.d.ts.map +1 -0
  75. package/dest/test/utils.js +94 -0
  76. package/dest/tx_validator/nullifier_cache.d.ts +1 -1
  77. package/dest/tx_validator/nullifier_cache.d.ts.map +1 -1
  78. package/dest/tx_validator/tx_validator_factory.d.ts +4 -3
  79. package/dest/tx_validator/tx_validator_factory.d.ts.map +1 -1
  80. package/dest/tx_validator/tx_validator_factory.js +12 -9
  81. package/package.json +32 -31
  82. package/src/client/sequencer-client.ts +34 -40
  83. package/src/config.ts +89 -29
  84. package/src/global_variable_builder/global_builder.ts +67 -59
  85. package/src/index.ts +2 -0
  86. package/src/publisher/config.ts +32 -19
  87. package/src/publisher/index.ts +1 -1
  88. package/src/publisher/sequencer-publisher-factory.ts +19 -6
  89. package/src/publisher/sequencer-publisher-metrics.ts +3 -3
  90. package/src/publisher/sequencer-publisher.ts +418 -242
  91. package/src/sequencer/README.md +531 -0
  92. package/src/sequencer/block_builder.ts +28 -30
  93. package/src/sequencer/checkpoint_builder.ts +217 -0
  94. package/src/sequencer/checkpoint_proposal_job.ts +722 -0
  95. package/src/sequencer/checkpoint_voter.ts +105 -0
  96. package/src/sequencer/config.ts +2 -1
  97. package/src/sequencer/errors.ts +21 -0
  98. package/src/sequencer/events.ts +27 -0
  99. package/src/sequencer/index.ts +4 -0
  100. package/src/sequencer/metrics.ts +269 -94
  101. package/src/sequencer/sequencer.ts +508 -675
  102. package/src/sequencer/timetable.ts +181 -91
  103. package/src/sequencer/types.ts +6 -0
  104. package/src/sequencer/utils.ts +24 -29
  105. package/src/test/index.ts +3 -1
  106. package/src/test/mock_checkpoint_builder.ts +247 -0
  107. package/src/test/utils.ts +137 -0
  108. package/src/tx_validator/tx_validator_factory.ts +13 -7
@@ -1,12 +1,13 @@
1
- import { createLogger } from '@aztec/aztec.js';
1
+ import { createLogger } from '@aztec/aztec.js/log';
2
2
 
3
- import { DEFAULT_ATTESTATION_PROPAGATION_TIME } from '../config.js';
3
+ import { DEFAULT_ATTESTATION_PROPAGATION_TIME as DEFAULT_P2P_PROPAGATION_TIME } from '../config.js';
4
+ import { SequencerTooSlowError } from './errors.js';
4
5
  import type { SequencerMetrics } from './metrics.js';
5
6
  import { SequencerState } from './utils.js';
6
7
 
7
- const MIN_EXECUTION_TIME = 1;
8
- const BLOCK_PREPARE_TIME = 1;
9
- const BLOCK_VALIDATION_TIME = 1;
8
+ export const MIN_EXECUTION_TIME = 2;
9
+ export const CHECKPOINT_INITIALIZATION_TIME = 1;
10
+ export const CHECKPOINT_ASSEMBLE_TIME = 1;
10
11
 
11
12
  export class SequencerTimetable {
12
13
  /**
@@ -16,24 +17,42 @@ export class SequencerTimetable {
16
17
  */
17
18
  public readonly initializeDeadline: number;
18
19
 
20
+ /**
21
+ * Fixed time offset (in seconds) when the first sub-slot starts, used as baseline for all block deadlines.
22
+ * This is an estimate of how long initialization (sync + proposer check) typically takes.
23
+ * If actual initialization takes longer/shorter, blocks just get less/more time accordingly.
24
+ */
25
+ public readonly initializationOffset: number;
26
+
27
+ /**
28
+ * Total time needed to finalize and publish a checkpoint, including:
29
+ * - Assembling the checkpoint
30
+ * - Round-trip p2p propagation for the checkpoint proposal and its corresponding attestations
31
+ * - Publishing to L1
32
+ */
33
+ public readonly checkpointFinalizationTime: number;
34
+
19
35
  /**
20
36
  * How long it takes to get a published block into L1. L1 builders typically accept txs up to 4 seconds into their slot,
21
37
  * but we'll timeout sooner to give it more time to propagate (remember we also have blobs!). Still, when working in anvil,
22
38
  * we can just post in the very last second of the L1 slot and still expect the tx to be accepted.
23
39
  */
24
- public readonly l1PublishingTime;
40
+ public readonly l1PublishingTime: number;
25
41
 
26
- /** What's the minimum time we want to leave available for execution and reexecution (used to derive init deadline) */
42
+ /**
43
+ * What's the minimum time we want to leave available for execution and reexecution (used to derive init deadline)
44
+ * Defaults to half of the block duration if set, otherwise a constant.
45
+ */
27
46
  public readonly minExecutionTime: number = MIN_EXECUTION_TIME;
28
47
 
29
48
  /** How long it takes to get ready to start building */
30
- public readonly blockPrepareTime: number = BLOCK_PREPARE_TIME;
49
+ public readonly checkpointInitializationTime: number = CHECKPOINT_INITIALIZATION_TIME;
31
50
 
32
51
  /** How long it takes to for proposals and attestations to travel across the p2p layer (one-way) */
33
- public readonly attestationPropagationTime: number;
52
+ public readonly p2pPropagationTime: number;
34
53
 
35
- /** How much time we spend validating and processing a block after building it, and assembling the proposal to send to attestors */
36
- public readonly blockValidationTime: number = BLOCK_VALIDATION_TIME;
54
+ /** How much time we spend assembling a checkpoint after building the last block */
55
+ public readonly checkpointAssembleTime: number = CHECKPOINT_ASSEMBLE_TIME;
37
56
 
38
57
  /** Ethereum slot duration in seconds */
39
58
  public readonly ethereumSlotDuration: number;
@@ -41,18 +60,22 @@ export class SequencerTimetable {
41
60
  /** Aztec slot duration in seconds (must be multiple of ethereum slot duration) */
42
61
  public readonly aztecSlotDuration: number;
43
62
 
44
- /** How late into an L1 slot we can send a tx to make sure it gets included in the immediate next block. Complement of l1PublishingTime. */
45
- public readonly maxL1TxInclusionTimeIntoSlot: number;
46
-
47
63
  /** Whether assertTimeLeft will throw if not enough time. */
48
64
  public readonly enforce: boolean;
49
65
 
66
+ /** Duration per block when building multiple blocks per slot (undefined = single block per slot) */
67
+ public readonly blockDuration: number | undefined;
68
+
69
+ /** Maximum number of blocks that can be built in this slot configuration */
70
+ public readonly maxNumberOfBlocks: number;
71
+
50
72
  constructor(
51
73
  opts: {
52
74
  ethereumSlotDuration: number;
53
75
  aztecSlotDuration: number;
54
- maxL1TxInclusionTimeIntoSlot: number;
55
- attestationPropagationTime?: number;
76
+ l1PublishingTime: number;
77
+ p2pPropagationTime?: number;
78
+ blockDurationMs?: number;
56
79
  enforce: boolean;
57
80
  },
58
81
  private readonly metrics?: SequencerMetrics,
@@ -60,96 +83,104 @@ export class SequencerTimetable {
60
83
  ) {
61
84
  this.ethereumSlotDuration = opts.ethereumSlotDuration;
62
85
  this.aztecSlotDuration = opts.aztecSlotDuration;
63
- this.maxL1TxInclusionTimeIntoSlot = opts.maxL1TxInclusionTimeIntoSlot;
64
- this.attestationPropagationTime = opts.attestationPropagationTime ?? DEFAULT_ATTESTATION_PROPAGATION_TIME;
65
- this.l1PublishingTime = this.ethereumSlotDuration - this.maxL1TxInclusionTimeIntoSlot;
86
+ this.l1PublishingTime = opts.l1PublishingTime;
87
+ this.p2pPropagationTime = opts.p2pPropagationTime ?? DEFAULT_P2P_PROPAGATION_TIME;
88
+ this.blockDuration = opts.blockDurationMs ? opts.blockDurationMs / 1000 : undefined;
66
89
  this.enforce = opts.enforce;
67
90
 
68
91
  // Assume zero-cost propagation time and faster runs in test environments where L1 slot duration is shortened
69
92
  if (this.ethereumSlotDuration < 8) {
70
- this.attestationPropagationTime = 0;
71
- this.blockValidationTime = 0.5;
72
- this.blockPrepareTime = 0.5;
93
+ this.p2pPropagationTime = 0;
94
+ this.checkpointAssembleTime = 0.5;
95
+ this.checkpointInitializationTime = 0.5;
96
+ this.minExecutionTime = 1;
73
97
  }
74
98
 
75
- const allWorkToDo =
76
- this.blockPrepareTime +
77
- this.minExecutionTime * 2 +
78
- this.attestationPropagationTime * 2 +
79
- this.blockValidationTime +
80
- this.l1PublishingTime;
99
+ // Min execution time cannot be less than the block duration if set
100
+ if (this.blockDuration !== undefined && this.minExecutionTime > this.blockDuration) {
101
+ this.minExecutionTime = this.blockDuration;
102
+ }
81
103
 
82
- const initializeDeadline = this.aztecSlotDuration - allWorkToDo;
83
- this.initializeDeadline = initializeDeadline;
104
+ // Calculate initialization offset - estimate of time needed for sync + proposer check
105
+ // This is the baseline for all sub-slot deadlines
106
+ this.initializationOffset = this.checkpointInitializationTime;
84
107
 
85
- this.log.verbose(`Sequencer timetable initialized (${this.enforce ? 'enforced' : 'not enforced'})`, {
86
- ethereumSlotDuration: this.ethereumSlotDuration,
87
- aztecSlotDuration: this.aztecSlotDuration,
88
- maxL1TxInclusionTimeIntoSlot: this.maxL1TxInclusionTimeIntoSlot,
89
- l1PublishingTime: this.l1PublishingTime,
90
- minExecutionTime: this.minExecutionTime,
91
- blockPrepareTime: this.blockPrepareTime,
92
- attestationPropagationTime: this.attestationPropagationTime,
93
- blockValidationTime: this.blockValidationTime,
94
- initializeDeadline: this.initializeDeadline,
95
- enforce: this.enforce,
96
- allWorkToDo,
97
- });
108
+ // Calculate total checkpoint finalization time (assembly + attestations + L1 publishing)
109
+ this.checkpointFinalizationTime =
110
+ this.checkpointAssembleTime +
111
+ this.p2pPropagationTime * 2 + // Round-trip propagation
112
+ this.l1PublishingTime; // L1 publishing
98
113
 
99
- if (initializeDeadline <= 0) {
100
- throw new Error(
101
- `Block proposal initialize deadline cannot be negative (got ${initializeDeadline} from total time needed ${allWorkToDo} and a slot duration of ${this.aztecSlotDuration}).`,
102
- );
114
+ // Calculate maximum number of blocks that fit in this slot
115
+ if (!this.blockDuration) {
116
+ this.maxNumberOfBlocks = 1; // Single block per slot
117
+ } else {
118
+ const timeReservedAtEnd =
119
+ this.blockDuration + // Last sub-slot for validator re-execution
120
+ this.checkpointFinalizationTime; // Checkpoint finalization
121
+ const timeAvailableForBlocks = this.aztecSlotDuration - this.initializationOffset - timeReservedAtEnd;
122
+ this.maxNumberOfBlocks = Math.floor(timeAvailableForBlocks / this.blockDuration);
103
123
  }
104
- }
105
124
 
106
- private get afterBlockBuildingTimeNeededWithoutReexec() {
107
- return this.blockValidationTime + this.attestationPropagationTime * 2 + this.l1PublishingTime;
108
- }
125
+ // Minimum work to do within a slot for building a block with the minimum time for execution and publishing its checkpoint
126
+ const minWorkToDo =
127
+ this.initializationOffset +
128
+ this.minExecutionTime * 2 + // Execution and reexecution
129
+ this.checkpointFinalizationTime;
109
130
 
110
- public getBlockProposalExecTimeEnd(secondsIntoSlot: number): number {
111
- // We are N seconds into the slot. We need to account for `afterBlockBuildingTimeNeededWithoutReexec` seconds,
112
- // send then split the remaining time between the re-execution and the block building.
113
- const maxAllowed = this.aztecSlotDuration - this.afterBlockBuildingTimeNeededWithoutReexec;
114
- const available = maxAllowed - secondsIntoSlot;
115
- const executionTimeEnd = secondsIntoSlot + available / 2;
116
- this.log.debug(`Block proposal execution time deadline is ${executionTimeEnd}`, {
117
- secondsIntoSlot,
118
- maxAllowed,
119
- available,
120
- executionTimeEnd,
121
- });
122
- return executionTimeEnd;
123
- }
131
+ const initializeDeadline = this.aztecSlotDuration - minWorkToDo;
132
+ this.initializeDeadline = initializeDeadline;
124
133
 
125
- private get afterBlockReexecTimeNeeded() {
126
- return this.attestationPropagationTime + this.l1PublishingTime;
127
- }
134
+ this.log.verbose(
135
+ `Sequencer timetable initialized with ${this.maxNumberOfBlocks} blocks per slot (${this.enforce ? 'enforced' : 'not enforced'})`,
136
+ {
137
+ ethereumSlotDuration: this.ethereumSlotDuration,
138
+ aztecSlotDuration: this.aztecSlotDuration,
139
+ l1PublishingTime: this.l1PublishingTime,
140
+ minExecutionTime: this.minExecutionTime,
141
+ blockPrepareTime: this.checkpointInitializationTime,
142
+ p2pPropagationTime: this.p2pPropagationTime,
143
+ blockAssembleTime: this.checkpointAssembleTime,
144
+ initializeDeadline: this.initializeDeadline,
145
+ enforce: this.enforce,
146
+ minWorkToDo,
147
+ blockDuration: this.blockDuration,
148
+ maxNumberOfBlocks: this.maxNumberOfBlocks,
149
+ },
150
+ );
128
151
 
129
- public getValidatorReexecTimeEnd(secondsIntoSlot?: number): number {
130
- // We need to leave for `afterBlockReexecTimeNeeded` seconds available.
131
- const validationTimeEnd = this.aztecSlotDuration - this.afterBlockReexecTimeNeeded;
132
- this.log.debug(`Validator re-execution time deadline is ${validationTimeEnd}`, {
133
- secondsIntoSlot,
134
- validationTimeEnd,
135
- });
136
- return validationTimeEnd;
152
+ if (initializeDeadline <= 0) {
153
+ throw new Error(
154
+ `Block proposal initialize deadline cannot be negative (got ${initializeDeadline} from total time needed ${minWorkToDo} and a slot duration of ${this.aztecSlotDuration}).`,
155
+ );
156
+ }
137
157
  }
138
158
 
159
+ public getMaxAllowedTime(
160
+ state: Extract<SequencerState, SequencerState.STOPPED | SequencerState.IDLE | SequencerState.SYNCHRONIZING>,
161
+ ): undefined;
162
+ public getMaxAllowedTime(
163
+ state: Exclude<SequencerState, SequencerState.STOPPED | SequencerState.IDLE | SequencerState.SYNCHRONIZING>,
164
+ ): number;
165
+ public getMaxAllowedTime(state: SequencerState): number | undefined;
139
166
  public getMaxAllowedTime(state: SequencerState): number | undefined {
140
167
  switch (state) {
141
168
  case SequencerState.STOPPED:
169
+ case SequencerState.STOPPING:
142
170
  case SequencerState.IDLE:
143
171
  case SequencerState.SYNCHRONIZING:
144
172
  return; // We don't really care about times for this states
145
173
  case SequencerState.PROPOSER_CHECK:
146
- case SequencerState.INITIALIZING_PROPOSAL:
174
+ case SequencerState.INITIALIZING_CHECKPOINT:
147
175
  return this.initializeDeadline;
176
+ case SequencerState.WAITING_FOR_TXS:
148
177
  case SequencerState.CREATING_BLOCK:
149
- return this.initializeDeadline + this.blockPrepareTime;
178
+ case SequencerState.WAITING_UNTIL_NEXT_BLOCK:
179
+ return this.initializeDeadline + this.checkpointInitializationTime;
180
+ case SequencerState.ASSEMBLING_CHECKPOINT:
150
181
  case SequencerState.COLLECTING_ATTESTATIONS:
151
- return this.aztecSlotDuration - this.l1PublishingTime - 2 * this.attestationPropagationTime;
152
- case SequencerState.PUBLISHING_BLOCK:
182
+ return this.aztecSlotDuration - this.l1PublishingTime - 2 * this.p2pPropagationTime;
183
+ case SequencerState.PUBLISHING_CHECKPOINT:
153
184
  return this.aztecSlotDuration - this.l1PublishingTime;
154
185
  default: {
155
186
  const _exhaustiveCheck: never = state;
@@ -176,17 +207,76 @@ export class SequencerTimetable {
176
207
  this.metrics?.recordStateTransitionBufferMs(Math.floor(bufferSeconds * 1000), newState);
177
208
  this.log.trace(`Enough time to transition to ${newState}`, { maxAllowedTime, secondsIntoSlot });
178
209
  }
179
- }
180
210
 
181
- export class SequencerTooSlowError extends Error {
182
- constructor(
183
- public readonly proposedState: SequencerState,
184
- public readonly maxAllowedTime: number,
185
- public readonly currentTime: number,
186
- ) {
187
- super(
188
- `Too far into slot for ${proposedState} (time into slot ${currentTime}s greater than ${maxAllowedTime}s allowance)`,
189
- );
190
- this.name = 'SequencerTooSlowError';
211
+ /**
212
+ * Determines if we can start building the next block and returns its deadline.
213
+ *
214
+ * The timetable divides the slot into fixed sub-slots. This method finds the next
215
+ * available sub-slot that has enough time remaining to build a block.
216
+ *
217
+ * @param secondsIntoSlot - Current time (seconds into the slot)
218
+ * @returns Object with canStart flag, deadline, and whether this is the last block
219
+ */
220
+ public canStartNextBlock(
221
+ secondsIntoSlot: number,
222
+ ):
223
+ | { canStart: true; deadline: undefined; isLastBlock: true }
224
+ | { canStart: false; deadline: undefined; isLastBlock: false }
225
+ | { canStart: boolean; deadline: number; isLastBlock: boolean } {
226
+ // When timetable enforcement is disabled, always allow starting,
227
+ // and build a single block with no deadline. This is here just to
228
+ // satisfy a subset of e2e tests and the sandbox that assume that the
229
+ // sequencer is permanently mining every tx sent.
230
+ if (!this.enforce) {
231
+ return { canStart: true, deadline: undefined, isLastBlock: true };
232
+ }
233
+
234
+ // If no block duration is set, then we're in single-block mode, which
235
+ // is handled for backwards compatibility towards another subset of e2e tests.
236
+ if (this.blockDuration === undefined) {
237
+ // In single block mode, execution and re-execution happen sequentially, so we need to
238
+ // split the available time between them. After building, we need time for attestations and L1.
239
+ const maxAllowed = this.aztecSlotDuration - this.checkpointFinalizationTime;
240
+ const available = (maxAllowed - secondsIntoSlot) / 2; // Split remaining time: half for execution, half for re-execution
241
+ const canStart = available >= this.minExecutionTime;
242
+ const deadline = secondsIntoSlot + available;
243
+
244
+ this.log.verbose(
245
+ `${canStart ? 'Can' : 'Cannot'} start single-block checkpoint at ${secondsIntoSlot}s into slot`,
246
+ { secondsIntoSlot, maxAllowed, available, deadline },
247
+ );
248
+ return { canStart, deadline, isLastBlock: true };
249
+ }
250
+
251
+ // Otherwise, we're in multi-block-per-slot mode, the default when running in production
252
+ // Find the next available sub-slot that has enough time remaining
253
+ for (let subSlot = 1; subSlot <= this.maxNumberOfBlocks; subSlot++) {
254
+ // Calculate end for this sub-slot
255
+ const deadline = this.initializationOffset + subSlot * this.blockDuration;
256
+
257
+ // Check if we have enough time to build a block with this deadline
258
+ const timeUntilDeadline = deadline - secondsIntoSlot;
259
+
260
+ if (timeUntilDeadline >= this.minExecutionTime) {
261
+ // Found an available sub-slot! Is this the last one?
262
+ const isLastBlock = subSlot === this.maxNumberOfBlocks;
263
+
264
+ this.log.verbose(
265
+ `Can start ${isLastBlock ? 'last block' : 'block'} in sub-slot ${subSlot} with deadline ${deadline}s`,
266
+ { secondsIntoSlot, deadline, timeUntilDeadline, subSlot, maxBlocks: this.maxNumberOfBlocks },
267
+ );
268
+
269
+ return { canStart: true, deadline, isLastBlock };
270
+ }
271
+ }
272
+
273
+ // No sub-slots available with enough time
274
+ this.log.verbose(`No time left to start any more blocks`, {
275
+ secondsIntoSlot,
276
+ maxBlocks: this.maxNumberOfBlocks,
277
+ initializationOffset: this.initializationOffset,
278
+ });
279
+
280
+ return { canStart: false, deadline: undefined, isLastBlock: false };
191
281
  }
192
282
  }
@@ -0,0 +1,6 @@
1
+ import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
2
+
3
+ export type SequencerRollupConstants = Pick<
4
+ L1RollupConstants,
5
+ 'ethereumSlotDuration' | 'l1GenesisTime' | 'slotDuration'
6
+ >;
@@ -1,44 +1,39 @@
1
1
  export enum SequencerState {
2
- /**
3
- * Sequencer is stopped and not processing any txs from the pool.
4
- */
2
+ /** Sequencer is stopped and not processing any txs from the pool. */
5
3
  STOPPED = 'STOPPED',
6
- /**
7
- * Sequencer is awaiting the next call to work().
8
- */
4
+ /** Sequencer is being stopped. Will move to STOPPED shortly. */
5
+ STOPPING = 'STOPPING',
6
+ /** Sequencer is awaiting the next call to work(). */
9
7
  IDLE = 'IDLE',
10
- /**
11
- * Synchronizing with the L2 chain.
12
- */
8
+ /** Synchronizing with the L2 chain. */
13
9
  SYNCHRONIZING = 'SYNCHRONIZING',
14
- /**
15
- * Checking if we are the proposer for the current slot.
16
- */
10
+ /** Checking if we are the proposer for the current slot. */
17
11
  PROPOSER_CHECK = 'PROPOSER_CHECK',
18
- /**
19
- * Initializing the block proposal. Will move to CREATING_BLOCK if there are valid txs to include, or back to SYNCHRONIZING otherwise.
20
- */
21
- INITIALIZING_PROPOSAL = 'INITIALIZING_PROPOSAL',
22
- /**
23
- * Creating a new L2 block. Includes processing public function calls and running rollup circuits. Will move to PUBLISHING_CONTRACT_DATA.
24
- */
12
+ /** Initializing the checkpoint proposal. */
13
+ INITIALIZING_CHECKPOINT = 'INITIALIZING_CHECKPOINT',
14
+ /** Waiting for transactions to arrive in the pool. */
15
+ WAITING_FOR_TXS = 'WAITING_FOR_TXS',
16
+ /** Creating a new L2 block. Includes processing public function calls. */
25
17
  CREATING_BLOCK = 'CREATING_BLOCK',
26
- /**
27
- * Collecting attestations from its peers. Will move to PUBLISHING_BLOCK.
28
- */
18
+ /** Waiting until the next block can be created. */
19
+ WAITING_UNTIL_NEXT_BLOCK = 'WAITING_UNTIL_NEXT_BLOCK',
20
+ /** Assembling and broadcasting the checkpoint. */
21
+ ASSEMBLING_CHECKPOINT = 'ASSEMBLING_CHECKPOINT',
22
+ /** Collecting attestations from its peers. */
29
23
  COLLECTING_ATTESTATIONS = 'COLLECTING_ATTESTATIONS',
30
- /**
31
- * Sending the tx to L1 with the L2 block data and awaiting it to be mined. Will move to SYNCHRONIZING.
32
- */
33
- PUBLISHING_BLOCK = 'PUBLISHING_BLOCK',
24
+ /** Sending the tx to L1 with the L2 checkpoint data and awaiting it to be mined.. */
25
+ PUBLISHING_CHECKPOINT = 'PUBLISHING_CHECKPOINT',
34
26
  }
35
27
 
36
28
  export type SequencerStateWithSlot =
37
- | SequencerState.INITIALIZING_PROPOSAL
29
+ | SequencerState.INITIALIZING_CHECKPOINT
30
+ | SequencerState.WAITING_FOR_TXS
38
31
  | SequencerState.CREATING_BLOCK
32
+ | SequencerState.WAITING_UNTIL_NEXT_BLOCK
39
33
  | SequencerState.COLLECTING_ATTESTATIONS
40
- | SequencerState.PUBLISHING_BLOCK
41
- | SequencerState.PROPOSER_CHECK;
34
+ | SequencerState.PUBLISHING_CHECKPOINT
35
+ | SequencerState.PROPOSER_CHECK
36
+ | SequencerState.ASSEMBLING_CHECKPOINT;
42
37
 
43
38
  export type SequencerStateCallback = () => SequencerState;
44
39
 
package/src/test/index.ts CHANGED
@@ -1,11 +1,12 @@
1
- import type { PublisherManager } from '@aztec/ethereum';
2
1
  import type { L1TxUtilsWithBlobs } from '@aztec/ethereum/l1-tx-utils-with-blobs';
2
+ import type { PublisherManager } from '@aztec/ethereum/publisher-manager';
3
3
  import type { PublicProcessorFactory } from '@aztec/simulator/server';
4
4
  import type { 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
8
  import type { SequencerPublisher } from '../publisher/sequencer-publisher.js';
9
+ import type { FullNodeCheckpointsBuilder } from '../sequencer/checkpoint_builder.js';
9
10
  import { Sequencer } from '../sequencer/sequencer.js';
10
11
  import type { SequencerTimetable } from '../sequencer/timetable.js';
11
12
 
@@ -15,6 +16,7 @@ class TestSequencer_ extends Sequencer {
15
16
  declare public publisher: SequencerPublisher;
16
17
  declare public publisherFactory: SequencerPublisherFactory;
17
18
  declare public validatorClient: ValidatorClient;
19
+ declare public checkpointsBuilder: FullNodeCheckpointsBuilder;
18
20
  }
19
21
 
20
22
  export type TestSequencer = TestSequencer_;