@aztec/sequencer-client 0.0.1-commit.db765a8 → 0.0.1-commit.df81a97b5
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 +4 -1
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +46 -23
- package/dest/config.d.ts +25 -5
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +21 -12
- package/dest/global_variable_builder/global_builder.d.ts +13 -7
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +22 -21
- package/dest/global_variable_builder/index.d.ts +2 -2
- package/dest/global_variable_builder/index.d.ts.map +1 -1
- package/dest/publisher/config.d.ts +13 -1
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +17 -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 +2 -2
- package/dest/publisher/sequencer-publisher.d.ts +9 -4
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +33 -9
- package/dest/sequencer/checkpoint_proposal_job.d.ts +13 -7
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_proposal_job.js +166 -115
- package/dest/sequencer/events.d.ts +2 -1
- package/dest/sequencer/events.d.ts.map +1 -1
- package/dest/sequencer/metrics.d.ts +5 -1
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +11 -0
- package/dest/sequencer/sequencer.d.ts +11 -8
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +71 -61
- package/dest/sequencer/timetable.d.ts +4 -3
- package/dest/sequencer/timetable.d.ts.map +1 -1
- package/dest/sequencer/timetable.js +6 -7
- package/dest/sequencer/types.d.ts +2 -2
- package/dest/sequencer/types.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.d.ts +7 -9
- package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.js +39 -30
- package/package.json +27 -28
- package/src/client/sequencer-client.ts +56 -21
- package/src/config.ts +28 -14
- package/src/global_variable_builder/global_builder.ts +22 -23
- package/src/global_variable_builder/index.ts +1 -1
- package/src/publisher/config.ts +32 -0
- package/src/publisher/sequencer-publisher-factory.ts +3 -3
- package/src/publisher/sequencer-publisher.ts +39 -11
- package/src/sequencer/checkpoint_proposal_job.ts +219 -131
- package/src/sequencer/events.ts +1 -1
- package/src/sequencer/metrics.ts +14 -0
- package/src/sequencer/sequencer.ts +97 -68
- package/src/sequencer/timetable.ts +7 -7
- package/src/sequencer/types.ts +1 -1
- package/src/test/mock_checkpoint_builder.ts +51 -48
package/src/sequencer/metrics.ts
CHANGED
|
@@ -49,6 +49,8 @@ export class SequencerMetrics {
|
|
|
49
49
|
private checkpointBlockCount: Gauge;
|
|
50
50
|
private checkpointTxCount: Gauge;
|
|
51
51
|
private checkpointTotalMana: Gauge;
|
|
52
|
+
private pipelineDepth: Gauge;
|
|
53
|
+
private pipelineDiscards: UpDownCounter;
|
|
52
54
|
|
|
53
55
|
// Fisherman fee analysis metrics
|
|
54
56
|
private fishermanWouldBeIncluded: UpDownCounter;
|
|
@@ -143,6 +145,10 @@ export class SequencerMetrics {
|
|
|
143
145
|
|
|
144
146
|
this.slashingAttempts = createUpDownCounterWithDefault(this.meter, Metrics.SEQUENCER_SLASHING_ATTEMPTS_COUNT);
|
|
145
147
|
|
|
148
|
+
this.pipelineDepth = this.meter.createGauge(Metrics.SEQUENCER_PIPELINE_DEPTH);
|
|
149
|
+
this.pipelineDiscards = createUpDownCounterWithDefault(this.meter, Metrics.SEQUENCER_PIPELINE_DISCARDS_COUNT);
|
|
150
|
+
this.pipelineDepth.record(0);
|
|
151
|
+
|
|
146
152
|
// Fisherman fee analysis metrics
|
|
147
153
|
this.fishermanWouldBeIncluded = createUpDownCounterWithDefault(
|
|
148
154
|
this.meter,
|
|
@@ -234,6 +240,14 @@ export class SequencerMetrics {
|
|
|
234
240
|
});
|
|
235
241
|
}
|
|
236
242
|
|
|
243
|
+
recordPipelineDepth(depth: number) {
|
|
244
|
+
this.pipelineDepth.record(depth);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
recordPipelineDiscard(count = 1) {
|
|
248
|
+
this.pipelineDiscards.add(count);
|
|
249
|
+
}
|
|
250
|
+
|
|
237
251
|
incOpenSlot(slot: SlotNumber, proposer: string) {
|
|
238
252
|
// sequencer went through the loop a second time. Noop
|
|
239
253
|
if (slot === this.lastSeenSlot) {
|
|
@@ -14,7 +14,7 @@ import type { P2P } from '@aztec/p2p';
|
|
|
14
14
|
import type { SlasherClientInterface } from '@aztec/slasher';
|
|
15
15
|
import type { BlockData, L2BlockSink, L2BlockSource, ValidateCheckpointResult } from '@aztec/stdlib/block';
|
|
16
16
|
import type { Checkpoint } from '@aztec/stdlib/checkpoint';
|
|
17
|
-
import {
|
|
17
|
+
import { getSlotStartBuildTimestamp } from '@aztec/stdlib/epoch-helpers';
|
|
18
18
|
import {
|
|
19
19
|
type ResolvedSequencerConfig,
|
|
20
20
|
type SequencerConfig,
|
|
@@ -147,7 +147,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
147
147
|
public async stop(): Promise<void> {
|
|
148
148
|
this.log.info(`Stopping sequencer`);
|
|
149
149
|
this.setState(SequencerState.STOPPING, undefined, { force: true });
|
|
150
|
-
this.publisherFactory.
|
|
150
|
+
await this.publisherFactory.stopAll();
|
|
151
151
|
await this.runningPromise?.stop();
|
|
152
152
|
this.setState(SequencerState.STOPPED, undefined, { force: true });
|
|
153
153
|
this.log.info('Stopped sequencer');
|
|
@@ -192,10 +192,18 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
192
192
|
@trackSpan('Sequencer.work')
|
|
193
193
|
protected async work() {
|
|
194
194
|
this.setState(SequencerState.SYNCHRONIZING, undefined);
|
|
195
|
-
const { slot, ts,
|
|
195
|
+
const { slot, ts, nowSeconds, epoch } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
196
|
+
const { slot: targetSlot, epoch: targetEpoch } = this.epochCache.getTargetEpochAndSlotInNextL1Slot();
|
|
196
197
|
|
|
197
198
|
// Check if we are synced and it's our slot, grab a publisher, check previous block invalidation, etc
|
|
198
|
-
const checkpointProposalJob = await this.prepareCheckpointProposal(
|
|
199
|
+
const checkpointProposalJob = await this.prepareCheckpointProposal(
|
|
200
|
+
slot,
|
|
201
|
+
targetSlot,
|
|
202
|
+
epoch,
|
|
203
|
+
targetEpoch,
|
|
204
|
+
ts,
|
|
205
|
+
nowSeconds,
|
|
206
|
+
);
|
|
199
207
|
if (!checkpointProposalJob) {
|
|
200
208
|
return;
|
|
201
209
|
}
|
|
@@ -208,13 +216,13 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
208
216
|
this.lastCheckpointProposed = checkpoint;
|
|
209
217
|
}
|
|
210
218
|
|
|
211
|
-
// Log fee strategy comparison if on fisherman
|
|
219
|
+
// Log fee strategy comparison if on fisherman (uses target epoch since we mirror the proposer's perspective)
|
|
212
220
|
if (
|
|
213
221
|
this.config.fishermanMode &&
|
|
214
|
-
(this.lastEpochForStrategyComparison === undefined ||
|
|
222
|
+
(this.lastEpochForStrategyComparison === undefined || targetEpoch > this.lastEpochForStrategyComparison)
|
|
215
223
|
) {
|
|
216
|
-
this.logStrategyComparison(
|
|
217
|
-
this.lastEpochForStrategyComparison =
|
|
224
|
+
this.logStrategyComparison(targetEpoch, checkpointProposalJob.getPublisher());
|
|
225
|
+
this.lastEpochForStrategyComparison = targetEpoch;
|
|
218
226
|
}
|
|
219
227
|
|
|
220
228
|
return checkpoint;
|
|
@@ -227,43 +235,48 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
227
235
|
*/
|
|
228
236
|
@trackSpan('Sequencer.prepareCheckpointProposal')
|
|
229
237
|
private async prepareCheckpointProposal(
|
|
230
|
-
epoch: EpochNumber,
|
|
231
238
|
slot: SlotNumber,
|
|
239
|
+
targetSlot: SlotNumber,
|
|
240
|
+
epoch: EpochNumber,
|
|
241
|
+
targetEpoch: EpochNumber,
|
|
232
242
|
ts: bigint,
|
|
233
|
-
|
|
243
|
+
nowSeconds: bigint,
|
|
234
244
|
): Promise<CheckpointProposalJob | undefined> {
|
|
235
|
-
// Check we have not already processed this slot (cheapest check)
|
|
245
|
+
// Check we have not already processed this target slot (cheapest check)
|
|
236
246
|
// We only check this if enforce timetable is set, since we want to keep processing the same slot if we are not
|
|
237
247
|
// running against actual time (eg when we use sandbox-style automining)
|
|
238
248
|
if (
|
|
239
249
|
this.lastSlotForCheckpointProposalJob &&
|
|
240
|
-
this.lastSlotForCheckpointProposalJob >=
|
|
250
|
+
this.lastSlotForCheckpointProposalJob >= targetSlot &&
|
|
241
251
|
this.config.enforceTimeTable
|
|
242
252
|
) {
|
|
243
|
-
this.log.trace(`
|
|
253
|
+
this.log.trace(`Target slot ${targetSlot} has already been processed`);
|
|
244
254
|
return undefined;
|
|
245
255
|
}
|
|
246
256
|
|
|
247
|
-
// But if we have already proposed for this slot,
|
|
248
|
-
if (this.lastCheckpointProposed && this.lastCheckpointProposed.header.slotNumber >=
|
|
249
|
-
this.log.trace(
|
|
257
|
+
// But if we have already proposed for this slot, then we definitely have to skip it, automining or not
|
|
258
|
+
if (this.lastCheckpointProposed && this.lastCheckpointProposed.header.slotNumber >= targetSlot) {
|
|
259
|
+
this.log.trace(
|
|
260
|
+
`Slot ${targetSlot} has already been published as checkpoint ${this.lastCheckpointProposed.number}`,
|
|
261
|
+
);
|
|
250
262
|
return undefined;
|
|
251
263
|
}
|
|
252
264
|
|
|
253
265
|
// Check all components are synced to latest as seen by the archiver (queries all subsystems)
|
|
254
266
|
const syncedTo = await this.checkSync({ ts, slot });
|
|
255
267
|
if (!syncedTo) {
|
|
256
|
-
await this.tryVoteWhenSyncFails({ slot, ts });
|
|
268
|
+
await this.tryVoteWhenSyncFails({ slot, targetSlot, ts });
|
|
257
269
|
return undefined;
|
|
258
270
|
}
|
|
259
271
|
|
|
260
|
-
// If escape hatch is open for
|
|
272
|
+
// If escape hatch is open for the target epoch, do not start checkpoint proposal work and do not attempt invalidations.
|
|
261
273
|
// Still perform governance/slashing voting (as proposer) once per slot.
|
|
262
|
-
|
|
274
|
+
// When pipelining, we check the target epoch (slot+1's epoch) since that's the epoch we're building for.
|
|
275
|
+
const isEscapeHatchOpen = await this.epochCache.isEscapeHatchOpen(targetEpoch);
|
|
263
276
|
|
|
264
277
|
if (isEscapeHatchOpen) {
|
|
265
278
|
this.setState(SequencerState.PROPOSER_CHECK, slot);
|
|
266
|
-
const [canPropose, proposer] = await this.checkCanPropose(
|
|
279
|
+
const [canPropose, proposer] = await this.checkCanPropose(targetSlot);
|
|
267
280
|
if (canPropose) {
|
|
268
281
|
await this.tryVoteWhenEscapeHatchOpen({ slot, proposer });
|
|
269
282
|
} else {
|
|
@@ -280,18 +293,18 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
280
293
|
const checkpointNumber = CheckpointNumber(syncedTo.checkpointNumber + 1);
|
|
281
294
|
|
|
282
295
|
const logCtx = {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
syncedToL2Slot: getSlotAtTimestamp(syncedTo.l1Timestamp, this.l1Constants),
|
|
296
|
+
nowSeconds,
|
|
297
|
+
syncedToL2Slot: syncedTo.syncedL2Slot,
|
|
286
298
|
slot,
|
|
299
|
+
targetSlot,
|
|
287
300
|
slotTs: ts,
|
|
288
301
|
checkpointNumber,
|
|
289
302
|
isPendingChainValid: pick(syncedTo.pendingChainValidationStatus, 'valid', 'reason', 'invalidIndex'),
|
|
290
303
|
};
|
|
291
304
|
|
|
292
|
-
// Check that we are a proposer for the
|
|
305
|
+
// Check that we are a proposer for the target slot.
|
|
293
306
|
this.setState(SequencerState.PROPOSER_CHECK, slot);
|
|
294
|
-
const [canPropose, proposer] = await this.checkCanPropose(
|
|
307
|
+
const [canPropose, proposer] = await this.checkCanPropose(targetSlot);
|
|
295
308
|
|
|
296
309
|
// If we are not a proposer check if we should invalidate an invalid checkpoint, and bail
|
|
297
310
|
if (!canPropose) {
|
|
@@ -299,10 +312,10 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
299
312
|
return undefined;
|
|
300
313
|
}
|
|
301
314
|
|
|
302
|
-
// Check that the slot is not taken by a block already (should never happen, since only us can propose for this slot)
|
|
303
|
-
if (syncedTo.blockData && syncedTo.blockData.header.getSlot() >=
|
|
315
|
+
// Check that the target slot is not taken by a block already (should never happen, since only us can propose for this slot)
|
|
316
|
+
if (syncedTo.blockData && syncedTo.blockData.header.getSlot() >= targetSlot) {
|
|
304
317
|
this.log.warn(
|
|
305
|
-
`Cannot propose block at
|
|
318
|
+
`Cannot propose block at target slot ${targetSlot} since that slot was taken by block ${syncedTo.blockNumber}`,
|
|
306
319
|
{ ...logCtx, block: syncedTo.blockData.header.toInspect() },
|
|
307
320
|
);
|
|
308
321
|
this.metrics.recordCheckpointPrecheckFailed('slot_already_taken');
|
|
@@ -326,13 +339,11 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
326
339
|
// Prepare invalidation request if the pending chain is invalid (returns undefined if no need)
|
|
327
340
|
const invalidateCheckpoint = await publisher.simulateInvalidateCheckpoint(syncedTo.pendingChainValidationStatus);
|
|
328
341
|
|
|
329
|
-
// Check with the rollup contract if we can indeed propose at the
|
|
342
|
+
// Check with the rollup contract if we can indeed propose at the target slot. This check should not fail
|
|
330
343
|
// if all the previous checks are good, but we do it just in case.
|
|
331
|
-
const canProposeCheck = await publisher.
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
invalidateCheckpoint,
|
|
335
|
-
);
|
|
344
|
+
const canProposeCheck = await publisher.canProposeAt(syncedTo.archive, proposer ?? EthAddress.ZERO, {
|
|
345
|
+
...invalidateCheckpoint,
|
|
346
|
+
});
|
|
336
347
|
|
|
337
348
|
if (canProposeCheck === undefined) {
|
|
338
349
|
this.log.warn(
|
|
@@ -344,10 +355,10 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
344
355
|
return undefined;
|
|
345
356
|
}
|
|
346
357
|
|
|
347
|
-
if (canProposeCheck.slot !==
|
|
358
|
+
if (canProposeCheck.slot !== targetSlot) {
|
|
348
359
|
this.log.warn(
|
|
349
|
-
`Cannot propose block due to slot mismatch with rollup contract (this can be caused by a clock out of sync). Expected slot ${
|
|
350
|
-
{ ...logCtx, rollup: canProposeCheck, expectedSlot:
|
|
360
|
+
`Cannot propose block due to slot mismatch with rollup contract (this can be caused by a clock out of sync). Expected slot ${targetSlot} but got ${canProposeCheck.slot}.`,
|
|
361
|
+
{ ...logCtx, rollup: canProposeCheck, expectedSlot: targetSlot },
|
|
351
362
|
);
|
|
352
363
|
this.emit('proposer-rollup-check-failed', { reason: 'Slot mismatch', slot });
|
|
353
364
|
this.metrics.recordCheckpointPrecheckFailed('slot_mismatch');
|
|
@@ -364,14 +375,24 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
364
375
|
return undefined;
|
|
365
376
|
}
|
|
366
377
|
|
|
367
|
-
this.lastSlotForCheckpointProposalJob =
|
|
368
|
-
|
|
369
|
-
this.
|
|
378
|
+
this.lastSlotForCheckpointProposalJob = targetSlot;
|
|
379
|
+
|
|
380
|
+
await this.p2pClient.prepareForSlot(targetSlot);
|
|
381
|
+
this.log.info(
|
|
382
|
+
`Preparing checkpoint proposal ${checkpointNumber} for target slot ${targetSlot} during wall-clock slot ${slot}`,
|
|
383
|
+
{
|
|
384
|
+
...logCtx,
|
|
385
|
+
proposer,
|
|
386
|
+
pipeliningEnabled: this.epochCache.isProposerPipeliningEnabled(),
|
|
387
|
+
},
|
|
388
|
+
);
|
|
370
389
|
|
|
371
390
|
// Create and return the checkpoint proposal job
|
|
372
391
|
return this.createCheckpointProposalJob(
|
|
373
|
-
epoch,
|
|
374
392
|
slot,
|
|
393
|
+
targetSlot,
|
|
394
|
+
epoch,
|
|
395
|
+
targetEpoch,
|
|
375
396
|
checkpointNumber,
|
|
376
397
|
syncedTo.blockNumber,
|
|
377
398
|
proposer,
|
|
@@ -382,8 +403,10 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
382
403
|
}
|
|
383
404
|
|
|
384
405
|
protected createCheckpointProposalJob(
|
|
385
|
-
epoch: EpochNumber,
|
|
386
406
|
slot: SlotNumber,
|
|
407
|
+
targetSlot: SlotNumber,
|
|
408
|
+
epoch: EpochNumber,
|
|
409
|
+
targetEpoch: EpochNumber,
|
|
387
410
|
checkpointNumber: CheckpointNumber,
|
|
388
411
|
syncedToBlockNumber: BlockNumber,
|
|
389
412
|
proposer: EthAddress | undefined,
|
|
@@ -392,8 +415,10 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
392
415
|
invalidateCheckpoint: InvalidateCheckpointRequest | undefined,
|
|
393
416
|
): CheckpointProposalJob {
|
|
394
417
|
return new CheckpointProposalJob(
|
|
395
|
-
epoch,
|
|
396
418
|
slot,
|
|
419
|
+
targetSlot,
|
|
420
|
+
epoch,
|
|
421
|
+
targetEpoch,
|
|
397
422
|
checkpointNumber,
|
|
398
423
|
syncedToBlockNumber,
|
|
399
424
|
proposer,
|
|
@@ -475,16 +500,15 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
475
500
|
* We don't check against the previous block submitted since it may have been reorg'd out.
|
|
476
501
|
*/
|
|
477
502
|
protected async checkSync(args: { ts: bigint; slot: SlotNumber }): Promise<SequencerSyncCheckResult | undefined> {
|
|
478
|
-
// Check that the archiver
|
|
479
|
-
//
|
|
480
|
-
//
|
|
481
|
-
const
|
|
482
|
-
const { slot
|
|
483
|
-
if (
|
|
503
|
+
// Check that the archiver has fully synced the L2 slot before the one we want to propose in.
|
|
504
|
+
// The archiver reports sync progress via L1 block timestamps and synced checkpoint slots.
|
|
505
|
+
// See getSyncedL2SlotNumber for how missed L1 blocks are handled.
|
|
506
|
+
const syncedL2Slot = await this.l2BlockSource.getSyncedL2SlotNumber();
|
|
507
|
+
const { slot } = args;
|
|
508
|
+
if (syncedL2Slot === undefined || syncedL2Slot + 1 < slot) {
|
|
484
509
|
this.log.debug(`Cannot propose block at next L2 slot ${slot} due to pending sync from L1`, {
|
|
485
510
|
slot,
|
|
486
|
-
|
|
487
|
-
l1Timestamp,
|
|
511
|
+
syncedL2Slot,
|
|
488
512
|
});
|
|
489
513
|
return undefined;
|
|
490
514
|
}
|
|
@@ -524,7 +548,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
524
548
|
checkpointNumber: CheckpointNumber.ZERO,
|
|
525
549
|
blockNumber: BlockNumber.ZERO,
|
|
526
550
|
archive,
|
|
527
|
-
|
|
551
|
+
syncedL2Slot,
|
|
528
552
|
pendingChainValidationStatus,
|
|
529
553
|
};
|
|
530
554
|
}
|
|
@@ -541,7 +565,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
541
565
|
blockNumber: blockData.header.getBlockNumber(),
|
|
542
566
|
checkpointNumber: blockData.checkpointNumber,
|
|
543
567
|
archive: blockData.archive.root,
|
|
544
|
-
|
|
568
|
+
syncedL2Slot,
|
|
545
569
|
pendingChainValidationStatus,
|
|
546
570
|
};
|
|
547
571
|
}
|
|
@@ -550,20 +574,20 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
550
574
|
* Checks if we are the proposer for the next slot.
|
|
551
575
|
* @returns True if we can propose, and the proposer address (undefined if anyone can propose)
|
|
552
576
|
*/
|
|
553
|
-
protected async checkCanPropose(
|
|
577
|
+
protected async checkCanPropose(targetSlot: SlotNumber): Promise<[boolean, EthAddress | undefined]> {
|
|
554
578
|
let proposer: EthAddress | undefined;
|
|
555
579
|
|
|
556
580
|
try {
|
|
557
|
-
proposer = await this.epochCache.getProposerAttesterAddressInSlot(
|
|
581
|
+
proposer = await this.epochCache.getProposerAttesterAddressInSlot(targetSlot);
|
|
558
582
|
} catch (e) {
|
|
559
583
|
if (e instanceof NoCommitteeError) {
|
|
560
|
-
if (this.lastSlotForNoCommitteeWarning !==
|
|
561
|
-
this.lastSlotForNoCommitteeWarning =
|
|
562
|
-
this.log.warn(`Cannot propose at
|
|
584
|
+
if (this.lastSlotForNoCommitteeWarning !== targetSlot) {
|
|
585
|
+
this.lastSlotForNoCommitteeWarning = targetSlot;
|
|
586
|
+
this.log.warn(`Cannot propose at target slot ${targetSlot} since the committee does not exist on L1`);
|
|
563
587
|
}
|
|
564
588
|
return [false, undefined];
|
|
565
589
|
}
|
|
566
|
-
this.log.error(`Error getting proposer for slot ${
|
|
590
|
+
this.log.error(`Error getting proposer for target slot ${targetSlot}`, e);
|
|
567
591
|
return [false, undefined];
|
|
568
592
|
}
|
|
569
593
|
|
|
@@ -580,10 +604,15 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
580
604
|
const weAreProposer = validatorAddresses.some(addr => addr.equals(proposer));
|
|
581
605
|
|
|
582
606
|
if (!weAreProposer) {
|
|
583
|
-
this.log.debug(`Cannot propose at slot ${
|
|
607
|
+
this.log.debug(`Cannot propose at target slot ${targetSlot} since we are not a proposer`, {
|
|
608
|
+
targetSlot,
|
|
609
|
+
validatorAddresses,
|
|
610
|
+
proposer,
|
|
611
|
+
});
|
|
584
612
|
return [false, proposer];
|
|
585
613
|
}
|
|
586
614
|
|
|
615
|
+
this.log.debug(`We are the proposer for target slot ${targetSlot}`, { targetSlot, proposer });
|
|
587
616
|
return [true, proposer];
|
|
588
617
|
}
|
|
589
618
|
|
|
@@ -592,8 +621,8 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
592
621
|
* This allows the sequencer to participate in governance/slashing votes even when it cannot build blocks.
|
|
593
622
|
*/
|
|
594
623
|
@trackSpan('Seqeuencer.tryVoteWhenSyncFails', ({ slot }) => ({ [Attributes.SLOT_NUMBER]: slot }))
|
|
595
|
-
protected async tryVoteWhenSyncFails(args: { slot: SlotNumber; ts: bigint }): Promise<void> {
|
|
596
|
-
const { slot } = args;
|
|
624
|
+
protected async tryVoteWhenSyncFails(args: { slot: SlotNumber; targetSlot: SlotNumber; ts: bigint }): Promise<void> {
|
|
625
|
+
const { slot, targetSlot } = args;
|
|
597
626
|
|
|
598
627
|
// Prevent duplicate attempts in the same slot
|
|
599
628
|
if (this.lastSlotForFallbackVote === slot) {
|
|
@@ -621,7 +650,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
621
650
|
});
|
|
622
651
|
|
|
623
652
|
// Check if we're a proposer or proposal is open
|
|
624
|
-
const [canPropose, proposer] = await this.checkCanPropose(
|
|
653
|
+
const [canPropose, proposer] = await this.checkCanPropose(targetSlot);
|
|
625
654
|
if (!canPropose) {
|
|
626
655
|
this.log.trace(`Cannot vote in slot ${slot} since we are not a proposer`, { slot, proposer });
|
|
627
656
|
return;
|
|
@@ -638,9 +667,9 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
638
667
|
slot,
|
|
639
668
|
});
|
|
640
669
|
|
|
641
|
-
// Enqueue governance and slashing votes
|
|
670
|
+
// Enqueue governance and slashing votes (voter uses the target slot for L1 submission)
|
|
642
671
|
const voter = new CheckpointVoter(
|
|
643
|
-
|
|
672
|
+
targetSlot,
|
|
644
673
|
publisher,
|
|
645
674
|
attestorAddress,
|
|
646
675
|
this.validatorClient,
|
|
@@ -720,7 +749,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
720
749
|
syncedTo: SequencerSyncCheckResult,
|
|
721
750
|
currentSlot: SlotNumber,
|
|
722
751
|
): Promise<void> {
|
|
723
|
-
const { pendingChainValidationStatus,
|
|
752
|
+
const { pendingChainValidationStatus, syncedL2Slot } = syncedTo;
|
|
724
753
|
if (pendingChainValidationStatus.valid) {
|
|
725
754
|
return;
|
|
726
755
|
}
|
|
@@ -735,7 +764,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
735
764
|
|
|
736
765
|
const logData = {
|
|
737
766
|
invalidL1Timestamp: invalidCheckpointTimestamp,
|
|
738
|
-
|
|
767
|
+
syncedL2Slot,
|
|
739
768
|
invalidCheckpoint: pendingChainValidationStatus.checkpoint,
|
|
740
769
|
secondsBeforeInvalidatingBlockAsCommitteeMember,
|
|
741
770
|
secondsBeforeInvalidatingBlockAsNonCommitteeMember,
|
|
@@ -882,6 +911,6 @@ type SequencerSyncCheckResult = {
|
|
|
882
911
|
checkpointNumber: CheckpointNumber;
|
|
883
912
|
blockNumber: BlockNumber;
|
|
884
913
|
archive: Fr;
|
|
885
|
-
|
|
914
|
+
syncedL2Slot: SlotNumber;
|
|
886
915
|
pendingChainValidationStatus: ValidateCheckpointResult;
|
|
887
916
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Logger } from '@aztec/foundation/log';
|
|
2
2
|
import {
|
|
3
3
|
CHECKPOINT_ASSEMBLE_TIME,
|
|
4
4
|
CHECKPOINT_INITIALIZATION_TIME,
|
|
@@ -80,7 +80,7 @@ export class SequencerTimetable {
|
|
|
80
80
|
enforce: boolean;
|
|
81
81
|
},
|
|
82
82
|
private readonly metrics?: SequencerMetrics,
|
|
83
|
-
private readonly log
|
|
83
|
+
private readonly log?: Logger,
|
|
84
84
|
) {
|
|
85
85
|
this.ethereumSlotDuration = opts.ethereumSlotDuration;
|
|
86
86
|
this.aztecSlotDuration = opts.aztecSlotDuration;
|
|
@@ -132,7 +132,7 @@ export class SequencerTimetable {
|
|
|
132
132
|
const initializeDeadline = this.aztecSlotDuration - minWorkToDo;
|
|
133
133
|
this.initializeDeadline = initializeDeadline;
|
|
134
134
|
|
|
135
|
-
this.log
|
|
135
|
+
this.log?.info(
|
|
136
136
|
`Sequencer timetable initialized with ${this.maxNumberOfBlocks} blocks per slot (${this.enforce ? 'enforced' : 'not enforced'})`,
|
|
137
137
|
{
|
|
138
138
|
ethereumSlotDuration: this.ethereumSlotDuration,
|
|
@@ -206,7 +206,7 @@ export class SequencerTimetable {
|
|
|
206
206
|
}
|
|
207
207
|
|
|
208
208
|
this.metrics?.recordStateTransitionBufferMs(Math.floor(bufferSeconds * 1000), newState);
|
|
209
|
-
this.log
|
|
209
|
+
this.log?.trace(`Enough time to transition to ${newState}`, { maxAllowedTime, secondsIntoSlot });
|
|
210
210
|
}
|
|
211
211
|
|
|
212
212
|
/**
|
|
@@ -242,7 +242,7 @@ export class SequencerTimetable {
|
|
|
242
242
|
const canStart = available >= this.minExecutionTime;
|
|
243
243
|
const deadline = secondsIntoSlot + available;
|
|
244
244
|
|
|
245
|
-
this.log
|
|
245
|
+
this.log?.verbose(
|
|
246
246
|
`${canStart ? 'Can' : 'Cannot'} start single-block checkpoint at ${secondsIntoSlot}s into slot`,
|
|
247
247
|
{ secondsIntoSlot, maxAllowed, available, deadline },
|
|
248
248
|
);
|
|
@@ -262,7 +262,7 @@ export class SequencerTimetable {
|
|
|
262
262
|
// Found an available sub-slot! Is this the last one?
|
|
263
263
|
const isLastBlock = subSlot === this.maxNumberOfBlocks;
|
|
264
264
|
|
|
265
|
-
this.log
|
|
265
|
+
this.log?.verbose(
|
|
266
266
|
`Can start ${isLastBlock ? 'last block' : 'block'} in sub-slot ${subSlot} with deadline ${deadline}s`,
|
|
267
267
|
{ secondsIntoSlot, deadline, timeUntilDeadline, subSlot, maxBlocks: this.maxNumberOfBlocks },
|
|
268
268
|
);
|
|
@@ -272,7 +272,7 @@ export class SequencerTimetable {
|
|
|
272
272
|
}
|
|
273
273
|
|
|
274
274
|
// No sub-slots available with enough time
|
|
275
|
-
this.log
|
|
275
|
+
this.log?.verbose(`No time left to start any more blocks`, {
|
|
276
276
|
secondsIntoSlot,
|
|
277
277
|
maxBlocks: this.maxNumberOfBlocks,
|
|
278
278
|
initializationOffset: this.initializationOffset,
|
package/src/sequencer/types.ts
CHANGED
|
@@ -2,5 +2,5 @@ import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
|
2
2
|
|
|
3
3
|
export type SequencerRollupConstants = Pick<
|
|
4
4
|
L1RollupConstants,
|
|
5
|
-
'ethereumSlotDuration' | 'l1GenesisTime' | 'slotDuration'
|
|
5
|
+
'ethereumSlotDuration' | 'l1GenesisTime' | 'slotDuration' | 'rollupManaLimit'
|
|
6
6
|
>;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { type BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
1
|
+
import { type BlockNumber, CheckpointNumber, IndexWithinCheckpoint } from '@aztec/foundation/branded-types';
|
|
2
2
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
|
+
import { unfreeze } from '@aztec/foundation/types';
|
|
3
4
|
import { L2Block } from '@aztec/stdlib/block';
|
|
4
5
|
import { Checkpoint } from '@aztec/stdlib/checkpoint';
|
|
5
|
-
import { Gas } from '@aztec/stdlib/gas';
|
|
6
6
|
import type {
|
|
7
|
+
BlockBuilderOptions,
|
|
7
8
|
FullNodeBlockBuilderConfig,
|
|
8
9
|
ICheckpointBlockBuilder,
|
|
9
10
|
ICheckpointsBuilder,
|
|
10
11
|
MerkleTreeWriteOperations,
|
|
11
|
-
PublicProcessorLimits,
|
|
12
12
|
} from '@aztec/stdlib/interfaces/server';
|
|
13
13
|
import { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
14
14
|
import { makeAppendOnlyTreeSnapshot } from '@aztec/stdlib/testing';
|
|
@@ -32,7 +32,7 @@ export class MockCheckpointBuilder implements ICheckpointBlockBuilder {
|
|
|
32
32
|
public buildBlockCalls: Array<{
|
|
33
33
|
blockNumber: BlockNumber;
|
|
34
34
|
timestamp: bigint;
|
|
35
|
-
opts:
|
|
35
|
+
opts: BlockBuilderOptions;
|
|
36
36
|
}> = [];
|
|
37
37
|
/** Track all consumed transaction hashes across buildBlock calls */
|
|
38
38
|
public consumedTxHashes: Set<string> = new Set();
|
|
@@ -74,7 +74,7 @@ export class MockCheckpointBuilder implements ICheckpointBlockBuilder {
|
|
|
74
74
|
pendingTxs: Iterable<Tx> | AsyncIterable<Tx>,
|
|
75
75
|
blockNumber: BlockNumber,
|
|
76
76
|
timestamp: bigint,
|
|
77
|
-
opts:
|
|
77
|
+
opts: BlockBuilderOptions,
|
|
78
78
|
): Promise<BuildBlockInCheckpointResult> {
|
|
79
79
|
this.buildBlockCalls.push({ blockNumber, timestamp, opts });
|
|
80
80
|
|
|
@@ -86,8 +86,10 @@ export class MockCheckpointBuilder implements ICheckpointBlockBuilder {
|
|
|
86
86
|
let usedTxs: Tx[];
|
|
87
87
|
|
|
88
88
|
if (this.blockProvider) {
|
|
89
|
-
// Dynamic mode: get block from provider
|
|
90
|
-
block = this.blockProvider();
|
|
89
|
+
// Dynamic mode: get block from provider, cloning to avoid shared references across multiple buildBlock calls
|
|
90
|
+
block = L2Block.fromBuffer(this.blockProvider().toBuffer());
|
|
91
|
+
block.header.globalVariables.blockNumber = blockNumber;
|
|
92
|
+
await block.header.recomputeHash();
|
|
91
93
|
usedTxs = [];
|
|
92
94
|
this.builtBlocks.push(block);
|
|
93
95
|
} else {
|
|
@@ -113,81 +115,79 @@ export class MockCheckpointBuilder implements ICheckpointBlockBuilder {
|
|
|
113
115
|
|
|
114
116
|
return {
|
|
115
117
|
block,
|
|
116
|
-
publicGas: Gas.empty(),
|
|
117
118
|
publicProcessorDuration: 0,
|
|
118
119
|
numTxs: block?.body?.txEffects?.length ?? usedTxs.length,
|
|
119
120
|
usedTxs,
|
|
120
121
|
failedTxs: [],
|
|
121
|
-
usedTxBlobFields: block?.body?.txEffects?.reduce((sum, tx) => sum + tx.getNumBlobFields(), 0) ?? 0,
|
|
122
122
|
};
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
completeCheckpoint(): Promise<Checkpoint> {
|
|
126
126
|
this.completeCheckpointCalled = true;
|
|
127
127
|
const allBlocks = this.blockProvider ? this.builtBlocks : this.blocks;
|
|
128
|
-
|
|
129
|
-
// Create a CheckpointHeader from the last block's header for testing
|
|
130
|
-
const checkpointHeader = this.createCheckpointHeader(lastBlock);
|
|
131
|
-
return Promise.resolve(
|
|
132
|
-
new Checkpoint(
|
|
133
|
-
makeAppendOnlyTreeSnapshot(lastBlock.header.globalVariables.blockNumber + 1),
|
|
134
|
-
checkpointHeader,
|
|
135
|
-
allBlocks,
|
|
136
|
-
this.checkpointNumber,
|
|
137
|
-
),
|
|
138
|
-
);
|
|
128
|
+
return this.buildCheckpoint(allBlocks);
|
|
139
129
|
}
|
|
140
130
|
|
|
141
131
|
getCheckpoint(): Promise<Checkpoint> {
|
|
142
132
|
this.getCheckpointCalled = true;
|
|
143
133
|
const builtBlocks = this.blockProvider ? this.builtBlocks : this.blocks.slice(0, this.blockIndex);
|
|
144
|
-
|
|
145
|
-
if (!lastBlock) {
|
|
134
|
+
if (builtBlocks.length === 0) {
|
|
146
135
|
throw new Error('No blocks built yet');
|
|
147
136
|
}
|
|
148
|
-
|
|
149
|
-
const checkpointHeader = this.createCheckpointHeader(lastBlock);
|
|
150
|
-
return Promise.resolve(
|
|
151
|
-
new Checkpoint(
|
|
152
|
-
makeAppendOnlyTreeSnapshot(lastBlock.header.globalVariables.blockNumber + 1),
|
|
153
|
-
checkpointHeader,
|
|
154
|
-
builtBlocks,
|
|
155
|
-
this.checkpointNumber,
|
|
156
|
-
),
|
|
157
|
-
);
|
|
137
|
+
return this.buildCheckpoint(builtBlocks);
|
|
158
138
|
}
|
|
159
139
|
|
|
160
|
-
/**
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
140
|
+
/** Builds a structurally valid Checkpoint from a list of blocks, fixing up indexes and archive chaining. */
|
|
141
|
+
private async buildCheckpoint(blocks: L2Block[]): Promise<Checkpoint> {
|
|
142
|
+
// Fix up indexWithinCheckpoint and archive chaining so the checkpoint passes structural validation.
|
|
143
|
+
for (let i = 0; i < blocks.length; i++) {
|
|
144
|
+
blocks[i].indexWithinCheckpoint = IndexWithinCheckpoint(i);
|
|
145
|
+
if (i > 0) {
|
|
146
|
+
unfreeze(blocks[i].header).lastArchive = blocks[i - 1].archive;
|
|
147
|
+
await blocks[i].header.recomputeHash();
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const firstBlock = blocks[0];
|
|
152
|
+
const lastBlock = blocks[blocks.length - 1];
|
|
153
|
+
const gv = firstBlock.header.globalVariables;
|
|
154
|
+
|
|
155
|
+
const checkpointHeader = CheckpointHeader.empty({
|
|
156
|
+
lastArchiveRoot: firstBlock.header.lastArchive.root,
|
|
157
|
+
blockHeadersHash: Fr.random(),
|
|
170
158
|
slotNumber: gv.slotNumber,
|
|
171
159
|
timestamp: gv.timestamp,
|
|
172
160
|
coinbase: gv.coinbase,
|
|
173
161
|
feeRecipient: gv.feeRecipient,
|
|
174
162
|
gasFees: gv.gasFees,
|
|
175
|
-
totalManaUsed: header.totalManaUsed,
|
|
163
|
+
totalManaUsed: lastBlock.header.totalManaUsed,
|
|
176
164
|
});
|
|
165
|
+
|
|
166
|
+
return new Checkpoint(
|
|
167
|
+
makeAppendOnlyTreeSnapshot(lastBlock.header.globalVariables.blockNumber + 1),
|
|
168
|
+
checkpointHeader,
|
|
169
|
+
blocks,
|
|
170
|
+
this.checkpointNumber,
|
|
171
|
+
);
|
|
177
172
|
}
|
|
178
173
|
|
|
179
|
-
/**
|
|
180
|
-
|
|
181
|
-
this.blocks = [];
|
|
174
|
+
/** Resets per-checkpoint state (built blocks, consumed txs) while preserving config (blockProvider, seeded blocks). */
|
|
175
|
+
resetCheckpointState(): void {
|
|
182
176
|
this.builtBlocks = [];
|
|
183
|
-
this.usedTxsPerBlock = [];
|
|
184
177
|
this.blockIndex = 0;
|
|
185
|
-
this.buildBlockCalls = [];
|
|
186
178
|
this.consumedTxHashes.clear();
|
|
187
179
|
this.completeCheckpointCalled = false;
|
|
188
180
|
this.getCheckpointCalled = false;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** Reset for reuse in another test */
|
|
184
|
+
reset(): void {
|
|
185
|
+
this.blocks = [];
|
|
186
|
+
this.usedTxsPerBlock = [];
|
|
187
|
+
this.buildBlockCalls = [];
|
|
189
188
|
this.errorOnBuild = undefined;
|
|
190
189
|
this.blockProvider = undefined;
|
|
190
|
+
this.resetCheckpointState();
|
|
191
191
|
}
|
|
192
192
|
}
|
|
193
193
|
|
|
@@ -249,6 +249,7 @@ export class MockCheckpointsBuilder implements ICheckpointsBuilder {
|
|
|
249
249
|
slotDuration: 24,
|
|
250
250
|
l1ChainId: 1,
|
|
251
251
|
rollupVersion: 1,
|
|
252
|
+
rollupManaLimit: 200_000_000,
|
|
252
253
|
};
|
|
253
254
|
}
|
|
254
255
|
|
|
@@ -275,6 +276,8 @@ export class MockCheckpointsBuilder implements ICheckpointsBuilder {
|
|
|
275
276
|
if (!this.checkpointBuilder) {
|
|
276
277
|
// Auto-create a builder if none was set
|
|
277
278
|
this.checkpointBuilder = new MockCheckpointBuilder(constants, checkpointNumber);
|
|
279
|
+
} else {
|
|
280
|
+
this.checkpointBuilder.resetCheckpointState();
|
|
278
281
|
}
|
|
279
282
|
|
|
280
283
|
return Promise.resolve(this.checkpointBuilder);
|