@aztec/sequencer-client 5.0.0-private.20260319 → 5.0.0-rc.2

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