@aztec/sequencer-client 3.0.0-rc.5 → 4.0.0-nightly.20260107
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.
- package/dest/client/sequencer-client.d.ts +9 -8
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +28 -24
- package/dest/config.d.ts +7 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +63 -26
- package/dest/global_variable_builder/global_builder.d.ts +16 -8
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +37 -28
- package/dest/index.d.ts +2 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -1
- package/dest/publisher/config.d.ts +3 -3
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +2 -2
- package/dest/publisher/sequencer-publisher-factory.d.ts +3 -3
- package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-factory.js +1 -1
- package/dest/publisher/sequencer-publisher-metrics.d.ts +3 -3
- package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.d.ts +27 -23
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +119 -64
- package/dest/sequencer/block_builder.d.ts +1 -3
- package/dest/sequencer/block_builder.d.ts.map +1 -1
- package/dest/sequencer/block_builder.js +4 -2
- package/dest/sequencer/checkpoint_builder.d.ts +63 -0
- package/dest/sequencer/checkpoint_builder.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_builder.js +131 -0
- package/dest/sequencer/checkpoint_proposal_job.d.ts +74 -0
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_proposal_job.js +642 -0
- package/dest/sequencer/checkpoint_voter.d.ts +34 -0
- package/dest/sequencer/checkpoint_voter.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_voter.js +85 -0
- package/dest/sequencer/events.d.ts +46 -0
- package/dest/sequencer/events.d.ts.map +1 -0
- package/dest/sequencer/events.js +1 -0
- package/dest/sequencer/index.d.ts +5 -1
- package/dest/sequencer/index.d.ts.map +1 -1
- package/dest/sequencer/index.js +4 -0
- package/dest/sequencer/metrics.d.ts +21 -1
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +154 -0
- package/dest/sequencer/sequencer.d.ts +91 -125
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +581 -582
- package/dest/sequencer/timetable.d.ts +54 -14
- package/dest/sequencer/timetable.d.ts.map +1 -1
- package/dest/sequencer/timetable.js +148 -59
- package/dest/sequencer/types.d.ts +3 -0
- package/dest/sequencer/types.d.ts.map +1 -0
- package/dest/sequencer/types.js +1 -0
- package/dest/sequencer/utils.d.ts +14 -8
- package/dest/sequencer/utils.d.ts.map +1 -1
- package/dest/sequencer/utils.js +7 -4
- package/dest/test/index.d.ts +3 -1
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.d.ts +83 -0
- package/dest/test/mock_checkpoint_builder.d.ts.map +1 -0
- package/dest/test/mock_checkpoint_builder.js +179 -0
- package/dest/test/utils.d.ts +49 -0
- package/dest/test/utils.d.ts.map +1 -0
- package/dest/test/utils.js +94 -0
- package/package.json +27 -27
- package/src/client/sequencer-client.ts +24 -31
- package/src/config.ts +68 -25
- package/src/global_variable_builder/global_builder.ts +47 -41
- package/src/index.ts +2 -0
- package/src/publisher/config.ts +3 -3
- package/src/publisher/sequencer-publisher-factory.ts +3 -3
- package/src/publisher/sequencer-publisher-metrics.ts +2 -2
- package/src/publisher/sequencer-publisher.ts +170 -74
- package/src/sequencer/README.md +531 -0
- package/src/sequencer/block_builder.ts +4 -1
- package/src/sequencer/checkpoint_builder.ts +217 -0
- package/src/sequencer/checkpoint_proposal_job.ts +706 -0
- package/src/sequencer/checkpoint_voter.ts +105 -0
- package/src/sequencer/events.ts +27 -0
- package/src/sequencer/index.ts +4 -0
- package/src/sequencer/metrics.ts +202 -0
- package/src/sequencer/sequencer.ts +300 -779
- package/src/sequencer/timetable.ts +173 -79
- package/src/sequencer/types.ts +6 -0
- package/src/sequencer/utils.ts +18 -9
- package/src/test/index.ts +2 -0
- package/src/test/mock_checkpoint_builder.ts +247 -0
- package/src/test/utils.ts +137 -0
|
@@ -1,13 +1,13 @@
|
|
|
1
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
4
|
import { SequencerTooSlowError } from './errors.js';
|
|
5
5
|
import type { SequencerMetrics } from './metrics.js';
|
|
6
6
|
import { SequencerState } from './utils.js';
|
|
7
7
|
|
|
8
|
-
const MIN_EXECUTION_TIME =
|
|
9
|
-
const
|
|
10
|
-
const
|
|
8
|
+
export const MIN_EXECUTION_TIME = 2;
|
|
9
|
+
export const CHECKPOINT_INITIALIZATION_TIME = 1;
|
|
10
|
+
export const CHECKPOINT_ASSEMBLE_TIME = 1;
|
|
11
11
|
|
|
12
12
|
export class SequencerTimetable {
|
|
13
13
|
/**
|
|
@@ -17,24 +17,42 @@ export class SequencerTimetable {
|
|
|
17
17
|
*/
|
|
18
18
|
public readonly initializeDeadline: number;
|
|
19
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
|
+
|
|
20
35
|
/**
|
|
21
36
|
* How long it takes to get a published block into L1. L1 builders typically accept txs up to 4 seconds into their slot,
|
|
22
37
|
* but we'll timeout sooner to give it more time to propagate (remember we also have blobs!). Still, when working in anvil,
|
|
23
38
|
* we can just post in the very last second of the L1 slot and still expect the tx to be accepted.
|
|
24
39
|
*/
|
|
25
|
-
public readonly l1PublishingTime;
|
|
40
|
+
public readonly l1PublishingTime: number;
|
|
26
41
|
|
|
27
|
-
/**
|
|
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
|
+
*/
|
|
28
46
|
public readonly minExecutionTime: number = MIN_EXECUTION_TIME;
|
|
29
47
|
|
|
30
48
|
/** How long it takes to get ready to start building */
|
|
31
|
-
public readonly
|
|
49
|
+
public readonly checkpointInitializationTime: number = CHECKPOINT_INITIALIZATION_TIME;
|
|
32
50
|
|
|
33
51
|
/** How long it takes to for proposals and attestations to travel across the p2p layer (one-way) */
|
|
34
|
-
public readonly
|
|
52
|
+
public readonly p2pPropagationTime: number;
|
|
35
53
|
|
|
36
|
-
/** How much time we spend
|
|
37
|
-
public readonly
|
|
54
|
+
/** How much time we spend assembling a checkpoint after building the last block */
|
|
55
|
+
public readonly checkpointAssembleTime: number = CHECKPOINT_ASSEMBLE_TIME;
|
|
38
56
|
|
|
39
57
|
/** Ethereum slot duration in seconds */
|
|
40
58
|
public readonly ethereumSlotDuration: number;
|
|
@@ -42,18 +60,22 @@ export class SequencerTimetable {
|
|
|
42
60
|
/** Aztec slot duration in seconds (must be multiple of ethereum slot duration) */
|
|
43
61
|
public readonly aztecSlotDuration: number;
|
|
44
62
|
|
|
45
|
-
/** 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. */
|
|
46
|
-
public readonly maxL1TxInclusionTimeIntoSlot: number;
|
|
47
|
-
|
|
48
63
|
/** Whether assertTimeLeft will throw if not enough time. */
|
|
49
64
|
public readonly enforce: boolean;
|
|
50
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
|
+
|
|
51
72
|
constructor(
|
|
52
73
|
opts: {
|
|
53
74
|
ethereumSlotDuration: number;
|
|
54
75
|
aztecSlotDuration: number;
|
|
55
|
-
|
|
56
|
-
|
|
76
|
+
l1PublishingTime: number;
|
|
77
|
+
p2pPropagationTime?: number;
|
|
78
|
+
blockDurationMs?: number;
|
|
57
79
|
enforce: boolean;
|
|
58
80
|
},
|
|
59
81
|
private readonly metrics?: SequencerMetrics,
|
|
@@ -61,80 +83,77 @@ export class SequencerTimetable {
|
|
|
61
83
|
) {
|
|
62
84
|
this.ethereumSlotDuration = opts.ethereumSlotDuration;
|
|
63
85
|
this.aztecSlotDuration = opts.aztecSlotDuration;
|
|
64
|
-
this.
|
|
65
|
-
this.
|
|
66
|
-
this.
|
|
86
|
+
this.l1PublishingTime = opts.l1PublishingTime;
|
|
87
|
+
this.p2pPropagationTime = opts.p2pPropagationTime ?? DEFAULT_P2P_PROPAGATION_TIME;
|
|
88
|
+
this.blockDuration = opts.blockDurationMs ? opts.blockDurationMs / 1000 : undefined;
|
|
67
89
|
this.enforce = opts.enforce;
|
|
68
90
|
|
|
69
91
|
// Assume zero-cost propagation time and faster runs in test environments where L1 slot duration is shortened
|
|
70
92
|
if (this.ethereumSlotDuration < 8) {
|
|
71
|
-
this.
|
|
72
|
-
this.
|
|
73
|
-
this.
|
|
93
|
+
this.p2pPropagationTime = 0;
|
|
94
|
+
this.checkpointAssembleTime = 0.5;
|
|
95
|
+
this.checkpointInitializationTime = 0.5;
|
|
96
|
+
this.minExecutionTime = 1;
|
|
74
97
|
}
|
|
75
98
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
this.minExecutionTime
|
|
79
|
-
|
|
80
|
-
this.blockValidationTime +
|
|
81
|
-
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
|
+
}
|
|
82
103
|
|
|
83
|
-
|
|
84
|
-
|
|
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;
|
|
85
107
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
minExecutionTime: this.minExecutionTime,
|
|
92
|
-
blockPrepareTime: this.blockPrepareTime,
|
|
93
|
-
attestationPropagationTime: this.attestationPropagationTime,
|
|
94
|
-
blockValidationTime: this.blockValidationTime,
|
|
95
|
-
initializeDeadline: this.initializeDeadline,
|
|
96
|
-
enforce: this.enforce,
|
|
97
|
-
allWorkToDo,
|
|
98
|
-
});
|
|
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
|
|
99
113
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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);
|
|
104
123
|
}
|
|
105
|
-
}
|
|
106
124
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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;
|
|
110
130
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
// send then split the remaining time between the re-execution and the block building.
|
|
114
|
-
const maxAllowed = this.aztecSlotDuration - this.afterBlockBuildingTimeNeededWithoutReexec;
|
|
115
|
-
const available = maxAllowed - secondsIntoSlot;
|
|
116
|
-
const executionTimeEnd = secondsIntoSlot + available / 2;
|
|
117
|
-
this.log.debug(`Block proposal execution time deadline is ${executionTimeEnd}`, {
|
|
118
|
-
secondsIntoSlot,
|
|
119
|
-
maxAllowed,
|
|
120
|
-
available,
|
|
121
|
-
executionTimeEnd,
|
|
122
|
-
});
|
|
123
|
-
return executionTimeEnd;
|
|
124
|
-
}
|
|
131
|
+
const initializeDeadline = this.aztecSlotDuration - minWorkToDo;
|
|
132
|
+
this.initializeDeadline = initializeDeadline;
|
|
125
133
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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
|
+
);
|
|
129
151
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
validationTimeEnd,
|
|
136
|
-
});
|
|
137
|
-
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
|
+
}
|
|
138
157
|
}
|
|
139
158
|
|
|
140
159
|
public getMaxAllowedTime(
|
|
@@ -152,13 +171,16 @@ export class SequencerTimetable {
|
|
|
152
171
|
case SequencerState.SYNCHRONIZING:
|
|
153
172
|
return; // We don't really care about times for this states
|
|
154
173
|
case SequencerState.PROPOSER_CHECK:
|
|
155
|
-
case SequencerState.
|
|
174
|
+
case SequencerState.INITIALIZING_CHECKPOINT:
|
|
156
175
|
return this.initializeDeadline;
|
|
176
|
+
case SequencerState.WAITING_FOR_TXS:
|
|
157
177
|
case SequencerState.CREATING_BLOCK:
|
|
158
|
-
|
|
178
|
+
case SequencerState.WAITING_UNTIL_NEXT_BLOCK:
|
|
179
|
+
return this.initializeDeadline + this.checkpointInitializationTime;
|
|
180
|
+
case SequencerState.ASSEMBLING_CHECKPOINT:
|
|
159
181
|
case SequencerState.COLLECTING_ATTESTATIONS:
|
|
160
|
-
return this.aztecSlotDuration - this.l1PublishingTime - 2 * this.
|
|
161
|
-
case SequencerState.
|
|
182
|
+
return this.aztecSlotDuration - this.l1PublishingTime - 2 * this.p2pPropagationTime;
|
|
183
|
+
case SequencerState.PUBLISHING_CHECKPOINT:
|
|
162
184
|
return this.aztecSlotDuration - this.l1PublishingTime;
|
|
163
185
|
default: {
|
|
164
186
|
const _exhaustiveCheck: never = state;
|
|
@@ -185,4 +207,76 @@ export class SequencerTimetable {
|
|
|
185
207
|
this.metrics?.recordStateTransitionBufferMs(Math.floor(bufferSeconds * 1000), newState);
|
|
186
208
|
this.log.trace(`Enough time to transition to ${newState}`, { maxAllowedTime, secondsIntoSlot });
|
|
187
209
|
}
|
|
210
|
+
|
|
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 };
|
|
281
|
+
}
|
|
188
282
|
}
|
package/src/sequencer/utils.ts
CHANGED
|
@@ -9,22 +9,31 @@ export enum SequencerState {
|
|
|
9
9
|
SYNCHRONIZING = 'SYNCHRONIZING',
|
|
10
10
|
/** Checking if we are the proposer for the current slot. */
|
|
11
11
|
PROPOSER_CHECK = 'PROPOSER_CHECK',
|
|
12
|
-
/** Initializing the
|
|
13
|
-
|
|
14
|
-
/**
|
|
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. */
|
|
15
17
|
CREATING_BLOCK = 'CREATING_BLOCK',
|
|
16
|
-
/**
|
|
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. */
|
|
17
23
|
COLLECTING_ATTESTATIONS = 'COLLECTING_ATTESTATIONS',
|
|
18
|
-
/** Sending the tx to L1 with the L2
|
|
19
|
-
|
|
24
|
+
/** Sending the tx to L1 with the L2 checkpoint data and awaiting it to be mined.. */
|
|
25
|
+
PUBLISHING_CHECKPOINT = 'PUBLISHING_CHECKPOINT',
|
|
20
26
|
}
|
|
21
27
|
|
|
22
28
|
export type SequencerStateWithSlot =
|
|
23
|
-
| SequencerState.
|
|
29
|
+
| SequencerState.INITIALIZING_CHECKPOINT
|
|
30
|
+
| SequencerState.WAITING_FOR_TXS
|
|
24
31
|
| SequencerState.CREATING_BLOCK
|
|
32
|
+
| SequencerState.WAITING_UNTIL_NEXT_BLOCK
|
|
25
33
|
| SequencerState.COLLECTING_ATTESTATIONS
|
|
26
|
-
| SequencerState.
|
|
27
|
-
| SequencerState.PROPOSER_CHECK
|
|
34
|
+
| SequencerState.PUBLISHING_CHECKPOINT
|
|
35
|
+
| SequencerState.PROPOSER_CHECK
|
|
36
|
+
| SequencerState.ASSEMBLING_CHECKPOINT;
|
|
28
37
|
|
|
29
38
|
export type SequencerStateCallback = () => SequencerState;
|
|
30
39
|
|
package/src/test/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type { ValidatorClient } from '@aztec/validator-client';
|
|
|
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_;
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import { type BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
|
+
import { Timer } from '@aztec/foundation/timer';
|
|
4
|
+
import type { FunctionsOf } from '@aztec/foundation/types';
|
|
5
|
+
import { L2BlockNew } from '@aztec/stdlib/block';
|
|
6
|
+
import { Checkpoint } from '@aztec/stdlib/checkpoint';
|
|
7
|
+
import { Gas } from '@aztec/stdlib/gas';
|
|
8
|
+
import type { FullNodeBlockBuilderConfig, PublicProcessorLimits } from '@aztec/stdlib/interfaces/server';
|
|
9
|
+
import { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
10
|
+
import { makeAppendOnlyTreeSnapshot } from '@aztec/stdlib/testing';
|
|
11
|
+
import type { CheckpointGlobalVariables, Tx } from '@aztec/stdlib/tx';
|
|
12
|
+
|
|
13
|
+
import type {
|
|
14
|
+
BuildBlockInCheckpointResult,
|
|
15
|
+
CheckpointBuilder,
|
|
16
|
+
FullNodeCheckpointsBuilder,
|
|
17
|
+
} from '../sequencer/checkpoint_builder.js';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A fake CheckpointBuilder for testing that implements the same interface as the real one.
|
|
21
|
+
* Can be seeded with blocks to return sequentially on each `buildBlock` call.
|
|
22
|
+
*/
|
|
23
|
+
export class MockCheckpointBuilder implements FunctionsOf<CheckpointBuilder> {
|
|
24
|
+
private blocks: L2BlockNew[] = [];
|
|
25
|
+
private builtBlocks: L2BlockNew[] = [];
|
|
26
|
+
private usedTxsPerBlock: Tx[][] = [];
|
|
27
|
+
private blockIndex = 0;
|
|
28
|
+
|
|
29
|
+
/** Optional function to dynamically provide the block (alternative to seedBlocks) */
|
|
30
|
+
private blockProvider: (() => L2BlockNew) | undefined = undefined;
|
|
31
|
+
|
|
32
|
+
/** Track calls for assertions */
|
|
33
|
+
public buildBlockCalls: Array<{
|
|
34
|
+
blockNumber: BlockNumber;
|
|
35
|
+
timestamp: bigint;
|
|
36
|
+
opts: PublicProcessorLimits;
|
|
37
|
+
}> = [];
|
|
38
|
+
public completeCheckpointCalled = false;
|
|
39
|
+
public getCheckpointCalled = false;
|
|
40
|
+
|
|
41
|
+
/** Set to an error to make buildBlock throw on next call */
|
|
42
|
+
public errorOnBuild: Error | undefined = undefined;
|
|
43
|
+
|
|
44
|
+
constructor(
|
|
45
|
+
private readonly constants: CheckpointGlobalVariables,
|
|
46
|
+
private readonly checkpointNumber: CheckpointNumber,
|
|
47
|
+
) {}
|
|
48
|
+
|
|
49
|
+
/** Seed the builder with blocks to return on successive buildBlock calls */
|
|
50
|
+
seedBlocks(blocks: L2BlockNew[], usedTxsPerBlock?: Tx[][]): this {
|
|
51
|
+
this.blocks = blocks;
|
|
52
|
+
this.usedTxsPerBlock = usedTxsPerBlock ?? blocks.map(() => []);
|
|
53
|
+
this.blockIndex = 0;
|
|
54
|
+
this.blockProvider = undefined;
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Set a function that provides blocks dynamically.
|
|
60
|
+
* Useful for tests where the block is determined at call time (e.g., sequencer tests).
|
|
61
|
+
*/
|
|
62
|
+
setBlockProvider(provider: () => L2BlockNew): this {
|
|
63
|
+
this.blockProvider = provider;
|
|
64
|
+
this.blocks = [];
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
getConstantData(): CheckpointGlobalVariables {
|
|
69
|
+
return this.constants;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
buildBlock(
|
|
73
|
+
_pendingTxs: Iterable<Tx> | AsyncIterable<Tx>,
|
|
74
|
+
blockNumber: BlockNumber,
|
|
75
|
+
timestamp: bigint,
|
|
76
|
+
opts: PublicProcessorLimits,
|
|
77
|
+
): Promise<BuildBlockInCheckpointResult> {
|
|
78
|
+
this.buildBlockCalls.push({ blockNumber, timestamp, opts });
|
|
79
|
+
|
|
80
|
+
if (this.errorOnBuild) {
|
|
81
|
+
return Promise.reject(this.errorOnBuild);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
let block: L2BlockNew;
|
|
85
|
+
let usedTxs: Tx[];
|
|
86
|
+
|
|
87
|
+
if (this.blockProvider) {
|
|
88
|
+
// Dynamic mode: get block from provider
|
|
89
|
+
block = this.blockProvider();
|
|
90
|
+
usedTxs = [];
|
|
91
|
+
this.builtBlocks.push(block);
|
|
92
|
+
} else {
|
|
93
|
+
// Seeded mode: get block from pre-seeded list
|
|
94
|
+
block = this.blocks[this.blockIndex];
|
|
95
|
+
usedTxs = this.usedTxsPerBlock[this.blockIndex] ?? [];
|
|
96
|
+
this.blockIndex++;
|
|
97
|
+
this.builtBlocks.push(block);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return Promise.resolve({
|
|
101
|
+
block,
|
|
102
|
+
publicGas: Gas.empty(),
|
|
103
|
+
publicProcessorDuration: 0,
|
|
104
|
+
numTxs: block?.body?.txEffects?.length ?? usedTxs.length,
|
|
105
|
+
blockBuildingTimer: new Timer(),
|
|
106
|
+
usedTxs,
|
|
107
|
+
failedTxs: [],
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
completeCheckpoint(): Promise<Checkpoint> {
|
|
112
|
+
this.completeCheckpointCalled = true;
|
|
113
|
+
const allBlocks = this.blockProvider ? this.builtBlocks : this.blocks;
|
|
114
|
+
const lastBlock = allBlocks[allBlocks.length - 1];
|
|
115
|
+
// Create a CheckpointHeader from the last block's header for testing
|
|
116
|
+
const checkpointHeader = this.createCheckpointHeader(lastBlock);
|
|
117
|
+
return Promise.resolve(
|
|
118
|
+
new Checkpoint(
|
|
119
|
+
makeAppendOnlyTreeSnapshot(lastBlock.header.globalVariables.blockNumber + 1),
|
|
120
|
+
checkpointHeader,
|
|
121
|
+
allBlocks,
|
|
122
|
+
this.checkpointNumber,
|
|
123
|
+
),
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
getCheckpoint(): Promise<Checkpoint> {
|
|
128
|
+
this.getCheckpointCalled = true;
|
|
129
|
+
const builtBlocks = this.blockProvider ? this.builtBlocks : this.blocks.slice(0, this.blockIndex);
|
|
130
|
+
const lastBlock = builtBlocks[builtBlocks.length - 1];
|
|
131
|
+
if (!lastBlock) {
|
|
132
|
+
throw new Error('No blocks built yet');
|
|
133
|
+
}
|
|
134
|
+
// Create a CheckpointHeader from the last block's header for testing
|
|
135
|
+
const checkpointHeader = this.createCheckpointHeader(lastBlock);
|
|
136
|
+
return Promise.resolve(
|
|
137
|
+
new Checkpoint(
|
|
138
|
+
makeAppendOnlyTreeSnapshot(lastBlock.header.globalVariables.blockNumber + 1),
|
|
139
|
+
checkpointHeader,
|
|
140
|
+
builtBlocks,
|
|
141
|
+
this.checkpointNumber,
|
|
142
|
+
),
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Creates a CheckpointHeader from a block's header for testing.
|
|
148
|
+
* This is a simplified version that creates a minimal CheckpointHeader.
|
|
149
|
+
*/
|
|
150
|
+
private createCheckpointHeader(block: L2BlockNew): CheckpointHeader {
|
|
151
|
+
const header = block.header;
|
|
152
|
+
const gv = header.globalVariables;
|
|
153
|
+
return CheckpointHeader.empty({
|
|
154
|
+
lastArchiveRoot: header.lastArchive.root,
|
|
155
|
+
blockHeadersHash: Fr.random(), // Use random for testing
|
|
156
|
+
slotNumber: gv.slotNumber,
|
|
157
|
+
timestamp: gv.timestamp,
|
|
158
|
+
coinbase: gv.coinbase,
|
|
159
|
+
feeRecipient: gv.feeRecipient,
|
|
160
|
+
gasFees: gv.gasFees,
|
|
161
|
+
totalManaUsed: header.totalManaUsed,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** Reset for reuse in another test */
|
|
166
|
+
reset(): void {
|
|
167
|
+
this.blocks = [];
|
|
168
|
+
this.builtBlocks = [];
|
|
169
|
+
this.usedTxsPerBlock = [];
|
|
170
|
+
this.blockIndex = 0;
|
|
171
|
+
this.buildBlockCalls = [];
|
|
172
|
+
this.completeCheckpointCalled = false;
|
|
173
|
+
this.getCheckpointCalled = false;
|
|
174
|
+
this.errorOnBuild = undefined;
|
|
175
|
+
this.blockProvider = undefined;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* A fake CheckpointsBuilder (factory) for testing that implements the same interface
|
|
181
|
+
* as FullNodeCheckpointsBuilder. Returns MockCheckpointBuilder instances.
|
|
182
|
+
* Does NOT use jest mocks - this is a proper test double.
|
|
183
|
+
*/
|
|
184
|
+
export class MockCheckpointsBuilder implements FunctionsOf<FullNodeCheckpointsBuilder> {
|
|
185
|
+
private checkpointBuilder: MockCheckpointBuilder | undefined;
|
|
186
|
+
|
|
187
|
+
/** Track calls for assertions */
|
|
188
|
+
public startCheckpointCalls: Array<{
|
|
189
|
+
checkpointNumber: CheckpointNumber;
|
|
190
|
+
constants: CheckpointGlobalVariables;
|
|
191
|
+
l1ToL2Messages: Fr[];
|
|
192
|
+
}> = [];
|
|
193
|
+
public updateConfigCalls: Array<Partial<FullNodeBlockBuilderConfig>> = [];
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Set the MockCheckpointBuilder to return from startCheckpoint.
|
|
197
|
+
* Must be called before startCheckpoint is invoked.
|
|
198
|
+
*/
|
|
199
|
+
setCheckpointBuilder(builder: MockCheckpointBuilder): this {
|
|
200
|
+
this.checkpointBuilder = builder;
|
|
201
|
+
return this;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Creates a new MockCheckpointBuilder with the given constants.
|
|
206
|
+
* Convenience method that creates and sets the builder in one call.
|
|
207
|
+
*/
|
|
208
|
+
createCheckpointBuilder(
|
|
209
|
+
constants: CheckpointGlobalVariables,
|
|
210
|
+
checkpointNumber: CheckpointNumber,
|
|
211
|
+
): MockCheckpointBuilder {
|
|
212
|
+
this.checkpointBuilder = new MockCheckpointBuilder(constants, checkpointNumber);
|
|
213
|
+
return this.checkpointBuilder;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** Get the current checkpoint builder (for assertions) */
|
|
217
|
+
getCheckpointBuilder(): MockCheckpointBuilder | undefined {
|
|
218
|
+
return this.checkpointBuilder;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
updateConfig(config: Partial<FullNodeBlockBuilderConfig>): void {
|
|
222
|
+
this.updateConfigCalls.push(config);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
startCheckpoint(
|
|
226
|
+
checkpointNumber: CheckpointNumber,
|
|
227
|
+
constants: CheckpointGlobalVariables,
|
|
228
|
+
l1ToL2Messages: Fr[],
|
|
229
|
+
_fork: unknown,
|
|
230
|
+
): Promise<CheckpointBuilder> {
|
|
231
|
+
this.startCheckpointCalls.push({ checkpointNumber, constants, l1ToL2Messages });
|
|
232
|
+
|
|
233
|
+
if (!this.checkpointBuilder) {
|
|
234
|
+
// Auto-create a builder if none was set
|
|
235
|
+
this.checkpointBuilder = new MockCheckpointBuilder(constants, checkpointNumber);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
return Promise.resolve(this.checkpointBuilder as unknown as CheckpointBuilder);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/** Reset for reuse in another test */
|
|
242
|
+
reset(): void {
|
|
243
|
+
this.checkpointBuilder = undefined;
|
|
244
|
+
this.startCheckpointCalls = [];
|
|
245
|
+
this.updateConfigCalls = [];
|
|
246
|
+
}
|
|
247
|
+
}
|