@aztec/sequencer-client 0.0.0-test.1 → 0.0.1-commit.0b941701

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 (135) hide show
  1. package/dest/client/index.d.ts +1 -1
  2. package/dest/client/sequencer-client.d.ts +31 -31
  3. package/dest/client/sequencer-client.d.ts.map +1 -1
  4. package/dest/client/sequencer-client.js +82 -60
  5. package/dest/config.d.ts +15 -16
  6. package/dest/config.d.ts.map +1 -1
  7. package/dest/config.js +118 -70
  8. package/dest/global_variable_builder/global_builder.d.ts +26 -15
  9. package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
  10. package/dest/global_variable_builder/global_builder.js +62 -44
  11. package/dest/global_variable_builder/index.d.ts +1 -1
  12. package/dest/index.d.ts +2 -4
  13. package/dest/index.d.ts.map +1 -1
  14. package/dest/index.js +1 -3
  15. package/dest/publisher/config.d.ts +15 -12
  16. package/dest/publisher/config.d.ts.map +1 -1
  17. package/dest/publisher/config.js +32 -19
  18. package/dest/publisher/index.d.ts +3 -1
  19. package/dest/publisher/index.d.ts.map +1 -1
  20. package/dest/publisher/index.js +3 -0
  21. package/dest/publisher/sequencer-publisher-factory.d.ts +44 -0
  22. package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -0
  23. package/dest/publisher/sequencer-publisher-factory.js +51 -0
  24. package/dest/publisher/sequencer-publisher-metrics.d.ts +5 -4
  25. package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
  26. package/dest/publisher/sequencer-publisher-metrics.js +26 -62
  27. package/dest/publisher/sequencer-publisher.d.ts +134 -87
  28. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  29. package/dest/publisher/sequencer-publisher.js +1146 -249
  30. package/dest/sequencer/checkpoint_proposal_job.d.ts +79 -0
  31. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -0
  32. package/dest/sequencer/checkpoint_proposal_job.js +1165 -0
  33. package/dest/sequencer/checkpoint_voter.d.ts +35 -0
  34. package/dest/sequencer/checkpoint_voter.d.ts.map +1 -0
  35. package/dest/sequencer/checkpoint_voter.js +109 -0
  36. package/dest/sequencer/config.d.ts +7 -1
  37. package/dest/sequencer/config.d.ts.map +1 -1
  38. package/dest/sequencer/errors.d.ts +11 -0
  39. package/dest/sequencer/errors.d.ts.map +1 -0
  40. package/dest/sequencer/errors.js +15 -0
  41. package/dest/sequencer/events.d.ts +46 -0
  42. package/dest/sequencer/events.d.ts.map +1 -0
  43. package/dest/sequencer/events.js +1 -0
  44. package/dest/sequencer/index.d.ts +4 -2
  45. package/dest/sequencer/index.d.ts.map +1 -1
  46. package/dest/sequencer/index.js +3 -1
  47. package/dest/sequencer/metrics.d.ts +48 -12
  48. package/dest/sequencer/metrics.d.ts.map +1 -1
  49. package/dest/sequencer/metrics.js +204 -69
  50. package/dest/sequencer/sequencer.d.ts +144 -137
  51. package/dest/sequencer/sequencer.d.ts.map +1 -1
  52. package/dest/sequencer/sequencer.js +967 -525
  53. package/dest/sequencer/timetable.d.ts +76 -24
  54. package/dest/sequencer/timetable.d.ts.map +1 -1
  55. package/dest/sequencer/timetable.js +177 -61
  56. package/dest/sequencer/types.d.ts +3 -0
  57. package/dest/sequencer/types.d.ts.map +1 -0
  58. package/dest/sequencer/types.js +1 -0
  59. package/dest/sequencer/utils.d.ts +20 -38
  60. package/dest/sequencer/utils.d.ts.map +1 -1
  61. package/dest/sequencer/utils.js +12 -47
  62. package/dest/test/index.d.ts +9 -1
  63. package/dest/test/index.d.ts.map +1 -1
  64. package/dest/test/index.js +0 -4
  65. package/dest/test/mock_checkpoint_builder.d.ts +95 -0
  66. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -0
  67. package/dest/test/mock_checkpoint_builder.js +222 -0
  68. package/dest/test/utils.d.ts +53 -0
  69. package/dest/test/utils.d.ts.map +1 -0
  70. package/dest/test/utils.js +103 -0
  71. package/package.json +47 -45
  72. package/src/client/sequencer-client.ts +106 -107
  73. package/src/config.ts +131 -81
  74. package/src/global_variable_builder/global_builder.ts +84 -55
  75. package/src/index.ts +1 -3
  76. package/src/publisher/config.ts +45 -32
  77. package/src/publisher/index.ts +4 -0
  78. package/src/publisher/sequencer-publisher-factory.ts +92 -0
  79. package/src/publisher/sequencer-publisher-metrics.ts +30 -64
  80. package/src/publisher/sequencer-publisher.ts +967 -295
  81. package/src/sequencer/README.md +531 -0
  82. package/src/sequencer/checkpoint_proposal_job.ts +845 -0
  83. package/src/sequencer/checkpoint_voter.ts +130 -0
  84. package/src/sequencer/config.ts +8 -0
  85. package/src/sequencer/errors.ts +21 -0
  86. package/src/sequencer/events.ts +27 -0
  87. package/src/sequencer/index.ts +3 -1
  88. package/src/sequencer/metrics.ts +269 -72
  89. package/src/sequencer/sequencer.ts +708 -588
  90. package/src/sequencer/timetable.ts +221 -62
  91. package/src/sequencer/types.ts +6 -0
  92. package/src/sequencer/utils.ts +28 -60
  93. package/src/test/index.ts +12 -4
  94. package/src/test/mock_checkpoint_builder.ts +311 -0
  95. package/src/test/utils.ts +164 -0
  96. package/dest/sequencer/allowed.d.ts +0 -3
  97. package/dest/sequencer/allowed.d.ts.map +0 -1
  98. package/dest/sequencer/allowed.js +0 -27
  99. package/dest/slasher/factory.d.ts +0 -7
  100. package/dest/slasher/factory.d.ts.map +0 -1
  101. package/dest/slasher/factory.js +0 -8
  102. package/dest/slasher/index.d.ts +0 -3
  103. package/dest/slasher/index.d.ts.map +0 -1
  104. package/dest/slasher/index.js +0 -2
  105. package/dest/slasher/slasher_client.d.ts +0 -75
  106. package/dest/slasher/slasher_client.d.ts.map +0 -1
  107. package/dest/slasher/slasher_client.js +0 -132
  108. package/dest/tx_validator/archive_cache.d.ts +0 -14
  109. package/dest/tx_validator/archive_cache.d.ts.map +0 -1
  110. package/dest/tx_validator/archive_cache.js +0 -22
  111. package/dest/tx_validator/gas_validator.d.ts +0 -14
  112. package/dest/tx_validator/gas_validator.d.ts.map +0 -1
  113. package/dest/tx_validator/gas_validator.js +0 -78
  114. package/dest/tx_validator/nullifier_cache.d.ts +0 -16
  115. package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
  116. package/dest/tx_validator/nullifier_cache.js +0 -24
  117. package/dest/tx_validator/phases_validator.d.ts +0 -12
  118. package/dest/tx_validator/phases_validator.d.ts.map +0 -1
  119. package/dest/tx_validator/phases_validator.js +0 -80
  120. package/dest/tx_validator/test_utils.d.ts +0 -23
  121. package/dest/tx_validator/test_utils.d.ts.map +0 -1
  122. package/dest/tx_validator/test_utils.js +0 -26
  123. package/dest/tx_validator/tx_validator_factory.d.ts +0 -18
  124. package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
  125. package/dest/tx_validator/tx_validator_factory.js +0 -50
  126. package/src/sequencer/allowed.ts +0 -36
  127. package/src/slasher/factory.ts +0 -15
  128. package/src/slasher/index.ts +0 -2
  129. package/src/slasher/slasher_client.ts +0 -193
  130. package/src/tx_validator/archive_cache.ts +0 -28
  131. package/src/tx_validator/gas_validator.ts +0 -101
  132. package/src/tx_validator/nullifier_cache.ts +0 -30
  133. package/src/tx_validator/phases_validator.ts +0 -98
  134. package/src/tx_validator/test_utils.ts +0 -48
  135. package/src/tx_validator/tx_validator_factory.ts +0 -120
@@ -1,86 +1,186 @@
1
- import { createLogger } from '@aztec/aztec.js';
1
+ import { createLogger } from '@aztec/aztec.js/log';
2
2
 
3
+ import { DEFAULT_ATTESTATION_PROPAGATION_TIME as DEFAULT_P2P_PROPAGATION_TIME } from '../config.js';
4
+ import { SequencerTooSlowError } from './errors.js';
3
5
  import type { SequencerMetrics } from './metrics.js';
4
6
  import { SequencerState } from './utils.js';
5
7
 
6
- export class SequencerTimetable {
7
- /** How late into the slot can we be to start working */
8
- public readonly initialTime = 3;
8
+ export const MIN_EXECUTION_TIME = 2;
9
+ export const CHECKPOINT_INITIALIZATION_TIME = 1;
10
+ export const CHECKPOINT_ASSEMBLE_TIME = 1;
9
11
 
10
- /** How long it takes to get ready to start building */
11
- public readonly blockPrepareTime = 1;
12
+ export class SequencerTimetable {
13
+ /**
14
+ * How late into the slot can we be to start working. Computed as the total time needed for assembling and publishing a block,
15
+ * assuming an execution time equal to `minExecutionTime`, subtracted from the slot duration. This means that, if the proposer
16
+ * starts building at this time, and all times hold, it will have at least `minExecutionTime` to execute txs for the block.
17
+ */
18
+ public readonly initializeDeadline: number;
12
19
 
13
- /** How long it takes to for proposals and attestations to travel across the p2p layer (one-way) */
14
- public readonly attestationPropagationTime = 2;
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;
15
26
 
16
- /** How much time we spend validating and processing a block after building it, and assembling the proposal to send to attestors */
17
- public readonly blockValidationTime = 1;
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;
18
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;
41
+
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
+ */
46
+ public readonly minExecutionTime: number = MIN_EXECUTION_TIME;
47
+
48
+ /** How long it takes to get ready to start building */
49
+ public readonly checkpointInitializationTime: number = CHECKPOINT_INITIALIZATION_TIME;
50
+
51
+ /** How long it takes to for proposals and attestations to travel across the p2p layer (one-way) */
52
+ public readonly p2pPropagationTime: number;
53
+
54
+ /** How much time we spend assembling a checkpoint after building the last block */
55
+ public readonly checkpointAssembleTime: number = CHECKPOINT_ASSEMBLE_TIME;
56
+
57
+ /** Ethereum slot duration in seconds */
58
+ public readonly ethereumSlotDuration: number;
59
+
60
+ /** Aztec slot duration in seconds (must be multiple of ethereum slot duration) */
61
+ public readonly aztecSlotDuration: number;
62
+
63
+ /** Whether assertTimeLeft will throw if not enough time. */
64
+ public readonly enforce: boolean;
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;
25
71
 
26
72
  constructor(
27
- private readonly ethereumSlotDuration: number,
28
- private readonly aztecSlotDuration: number,
29
- private readonly maxL1TxInclusionTimeIntoSlot: number,
30
- private readonly enforce: boolean = true,
73
+ opts: {
74
+ ethereumSlotDuration: number;
75
+ aztecSlotDuration: number;
76
+ l1PublishingTime: number;
77
+ p2pPropagationTime?: number;
78
+ blockDurationMs?: number;
79
+ enforce: boolean;
80
+ },
31
81
  private readonly metrics?: SequencerMetrics,
32
82
  private readonly log = createLogger('sequencer:timetable'),
33
83
  ) {
34
- this.l1PublishingTime = this.ethereumSlotDuration - this.maxL1TxInclusionTimeIntoSlot;
35
- }
84
+ this.ethereumSlotDuration = opts.ethereumSlotDuration;
85
+ this.aztecSlotDuration = opts.aztecSlotDuration;
86
+ this.l1PublishingTime = opts.l1PublishingTime;
87
+ this.p2pPropagationTime = opts.p2pPropagationTime ?? DEFAULT_P2P_PROPAGATION_TIME;
88
+ this.blockDuration = opts.blockDurationMs ? opts.blockDurationMs / 1000 : undefined;
89
+ this.enforce = opts.enforce;
36
90
 
37
- private get afterBlockBuildingTimeNeededWithoutReexec() {
38
- return this.blockValidationTime + this.attestationPropagationTime * 2 + this.l1PublishingTime;
39
- }
91
+ // Assume zero-cost propagation time and faster runs in test environments where L1 slot duration is shortened
92
+ if (this.ethereumSlotDuration < 8) {
93
+ this.p2pPropagationTime = 0;
94
+ this.checkpointAssembleTime = 0.5;
95
+ this.checkpointInitializationTime = 0.5;
96
+ this.minExecutionTime = 1;
97
+ }
40
98
 
41
- public getBlockProposalExecTimeEnd(secondsIntoSlot: number): number {
42
- // We are N seconds into the slot. We need to account for `afterBlockBuildingTimeNeededWithoutReexec` seconds,
43
- // send then split the remaining time between the re-execution and the block building.
44
- const maxAllowed = this.aztecSlotDuration - this.afterBlockBuildingTimeNeededWithoutReexec;
45
- const available = maxAllowed - secondsIntoSlot;
46
- const executionTimeEnd = secondsIntoSlot + available / 2;
47
- this.log.debug(`Block proposal execution time deadline is ${executionTimeEnd}`, {
48
- secondsIntoSlot,
49
- maxAllowed,
50
- available,
51
- executionTimeEnd,
52
- });
53
- return executionTimeEnd;
54
- }
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
+ }
55
103
 
56
- private get afterBlockReexecTimeNeeded() {
57
- return this.attestationPropagationTime + this.l1PublishingTime;
58
- }
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;
59
107
 
60
- public getValidatorReexecTimeEnd(secondsIntoSlot: number): number {
61
- // We need to leave for `afterBlockReexecTimeNeeded` seconds available.
62
- const validationTimeEnd = this.aztecSlotDuration - this.afterBlockReexecTimeNeeded;
63
- this.log.debug(`Validator re-execution time deadline is ${validationTimeEnd}`, {
64
- secondsIntoSlot,
65
- validationTimeEnd,
66
- });
67
- return validationTimeEnd;
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
113
+
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);
123
+ }
124
+
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;
130
+
131
+ const initializeDeadline = this.aztecSlotDuration - minWorkToDo;
132
+ this.initializeDeadline = initializeDeadline;
133
+
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
+ );
151
+
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
+ }
68
157
  }
69
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;
70
166
  public getMaxAllowedTime(state: SequencerState): number | undefined {
71
167
  switch (state) {
72
168
  case SequencerState.STOPPED:
169
+ case SequencerState.STOPPING:
73
170
  case SequencerState.IDLE:
74
171
  case SequencerState.SYNCHRONIZING:
75
- case SequencerState.PROPOSER_CHECK:
76
172
  return; // We don't really care about times for this states
77
- case SequencerState.INITIALIZING_PROPOSAL:
78
- return this.initialTime;
173
+ case SequencerState.PROPOSER_CHECK:
174
+ case SequencerState.INITIALIZING_CHECKPOINT:
175
+ return this.initializeDeadline;
176
+ case SequencerState.WAITING_FOR_TXS:
79
177
  case SequencerState.CREATING_BLOCK:
80
- return this.initialTime + this.blockPrepareTime;
178
+ case SequencerState.WAITING_UNTIL_NEXT_BLOCK:
179
+ return this.initializeDeadline + this.checkpointInitializationTime;
180
+ case SequencerState.ASSEMBLING_CHECKPOINT:
81
181
  case SequencerState.COLLECTING_ATTESTATIONS:
82
- return this.aztecSlotDuration - this.l1PublishingTime - 2 * this.attestationPropagationTime;
83
- case SequencerState.PUBLISHING_BLOCK:
182
+ return this.aztecSlotDuration - this.l1PublishingTime - 2 * this.p2pPropagationTime;
183
+ case SequencerState.PUBLISHING_CHECKPOINT:
84
184
  return this.aztecSlotDuration - this.l1PublishingTime;
85
185
  default: {
86
186
  const _exhaustiveCheck: never = state;
@@ -107,17 +207,76 @@ export class SequencerTimetable {
107
207
  this.metrics?.recordStateTransitionBufferMs(Math.floor(bufferSeconds * 1000), newState);
108
208
  this.log.trace(`Enough time to transition to ${newState}`, { maxAllowedTime, secondsIntoSlot });
109
209
  }
110
- }
111
210
 
112
- export class SequencerTooSlowError extends Error {
113
- constructor(
114
- public readonly proposedState: SequencerState,
115
- public readonly maxAllowedTime: number,
116
- public readonly currentTime: number,
117
- ) {
118
- super(
119
- `Too far into slot for ${proposedState} (time into slot ${currentTime}s greater than ${maxAllowedTime}s allowance)`,
120
- );
121
- 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 };
122
281
  }
123
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,74 +1,42 @@
1
- import type { EthAddress } from '@aztec/foundation/eth-address';
2
- import { Signature } from '@aztec/foundation/eth-signature';
3
- import type { BlockAttestation } from '@aztec/stdlib/p2p';
4
-
5
1
  export enum SequencerState {
6
- /**
7
- * Sequencer is stopped and not processing any txs from the pool.
8
- */
2
+ /** Sequencer is stopped and not processing any txs from the pool. */
9
3
  STOPPED = 'STOPPED',
10
- /**
11
- * Sequencer is awaiting the next call to work().
12
- */
4
+ /** Sequencer is being stopped. Will move to STOPPED shortly. */
5
+ STOPPING = 'STOPPING',
6
+ /** Sequencer is awaiting the next call to work(). */
13
7
  IDLE = 'IDLE',
14
- /**
15
- * Synchronizing with the L2 chain.
16
- */
8
+ /** Synchronizing with the L2 chain. */
17
9
  SYNCHRONIZING = 'SYNCHRONIZING',
18
- /**
19
- * Checking if we are the proposer for the current slot.
20
- */
10
+ /** Checking if we are the proposer for the current slot. */
21
11
  PROPOSER_CHECK = 'PROPOSER_CHECK',
22
- /**
23
- * Initializing the block proposal. Will move to CREATING_BLOCK if there are valid txs to include, or back to SYNCHRONIZING otherwise.
24
- */
25
- INITIALIZING_PROPOSAL = 'INITIALIZING_PROPOSAL',
26
- /**
27
- * Creating a new L2 block. Includes processing public function calls and running rollup circuits. Will move to PUBLISHING_CONTRACT_DATA.
28
- */
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. */
29
17
  CREATING_BLOCK = 'CREATING_BLOCK',
30
- /**
31
- * Collecting attestations from its peers. Will move to PUBLISHING_BLOCK.
32
- */
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. */
33
23
  COLLECTING_ATTESTATIONS = 'COLLECTING_ATTESTATIONS',
34
- /**
35
- * Sending the tx to L1 with the L2 block data and awaiting it to be mined. Will move to SYNCHRONIZING.
36
- */
37
- 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',
38
26
  }
39
27
 
28
+ export type SequencerStateWithSlot =
29
+ | SequencerState.INITIALIZING_CHECKPOINT
30
+ | SequencerState.WAITING_FOR_TXS
31
+ | SequencerState.CREATING_BLOCK
32
+ | SequencerState.WAITING_UNTIL_NEXT_BLOCK
33
+ | SequencerState.COLLECTING_ATTESTATIONS
34
+ | SequencerState.PUBLISHING_CHECKPOINT
35
+ | SequencerState.PROPOSER_CHECK
36
+ | SequencerState.ASSEMBLING_CHECKPOINT;
37
+
40
38
  export type SequencerStateCallback = () => SequencerState;
41
39
 
42
40
  export function sequencerStateToNumber(state: SequencerState): number {
43
41
  return Object.values(SequencerState).indexOf(state);
44
42
  }
45
-
46
- /** Order Attestations
47
- *
48
- * Returns attestation signatures in the order of a series of provided ethereum addresses
49
- * The rollup smart contract expects attestations to appear in the order of the committee
50
- *
51
- * @todo: perform this logic within the memory attestation store instead?
52
- */
53
- export async function orderAttestations(
54
- attestations: BlockAttestation[],
55
- orderAddresses: EthAddress[],
56
- ): Promise<Signature[]> {
57
- // Create a map of sender addresses to BlockAttestations
58
- const attestationMap = new Map<string, BlockAttestation>();
59
-
60
- for (const attestation of attestations) {
61
- const sender = await attestation.getSender();
62
- if (sender) {
63
- attestationMap.set(sender.toString(), attestation);
64
- }
65
- }
66
-
67
- // Create the ordered array based on the orderAddresses, else return an empty signature
68
- const orderedAttestations = orderAddresses.map(address => {
69
- const addressString = address.toString();
70
- return attestationMap.get(addressString)?.signature || Signature.empty();
71
- });
72
-
73
- return orderedAttestations;
74
- }
package/src/test/index.ts CHANGED
@@ -1,20 +1,28 @@
1
+ import type { L1TxUtilsWithBlobs } from '@aztec/ethereum/l1-tx-utils-with-blobs';
2
+ import type { PublisherManager } from '@aztec/ethereum/publisher-manager';
1
3
  import type { PublicProcessorFactory } from '@aztec/simulator/server';
4
+ import type { FullNodeCheckpointsBuilder, ValidatorClient } from '@aztec/validator-client';
2
5
 
3
6
  import { SequencerClient } from '../client/sequencer-client.js';
7
+ import type { SequencerPublisherFactory } from '../publisher/sequencer-publisher-factory.js';
4
8
  import type { SequencerPublisher } from '../publisher/sequencer-publisher.js';
5
9
  import { Sequencer } from '../sequencer/sequencer.js';
6
10
  import type { SequencerTimetable } from '../sequencer/timetable.js';
7
11
 
8
12
  class TestSequencer_ extends Sequencer {
9
- public override publicProcessorFactory!: PublicProcessorFactory;
10
- public override timetable!: SequencerTimetable;
11
- public override publisher!: SequencerPublisher;
13
+ declare public publicProcessorFactory: PublicProcessorFactory;
14
+ declare public timetable: SequencerTimetable;
15
+ declare public publisher: SequencerPublisher;
16
+ declare public publisherFactory: SequencerPublisherFactory;
17
+ declare public validatorClient: ValidatorClient;
18
+ declare public checkpointsBuilder: FullNodeCheckpointsBuilder;
12
19
  }
13
20
 
14
21
  export type TestSequencer = TestSequencer_;
15
22
 
16
23
  class TestSequencerClient_ extends SequencerClient {
17
- public override sequencer!: TestSequencer;
24
+ declare public sequencer: TestSequencer;
25
+ declare public publisherManager: PublisherManager<L1TxUtilsWithBlobs>;
18
26
  }
19
27
 
20
28
  export type TestSequencerClient = TestSequencerClient_;