@aztec/sequencer-client 0.0.1-commit.cd76b27 → 0.0.1-commit.d0fcfb7f
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 +12 -1
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +85 -13
- package/dest/config.d.ts +23 -4
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +23 -16
- package/dest/sequencer/checkpoint_proposal_job.d.ts +2 -4
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_proposal_job.js +68 -46
- package/dest/sequencer/sequencer.d.ts +14 -7
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +17 -14
- 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 +10 -8
- package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.js +41 -30
- package/package.json +28 -28
- package/src/client/sequencer-client.ts +111 -12
- package/src/config.ts +28 -19
- package/src/sequencer/checkpoint_proposal_job.ts +104 -57
- package/src/sequencer/sequencer.ts +20 -15
- package/src/sequencer/timetable.ts +7 -7
- package/src/sequencer/types.ts +1 -1
- package/src/test/mock_checkpoint_builder.ts +52 -47
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { NUM_CHECKPOINT_END_MARKER_FIELDS, getNumBlockEndBlobFields } from '@aztec/blob-lib/encoding';
|
|
2
|
-
import { BLOBS_PER_CHECKPOINT, FIELDS_PER_BLOB } from '@aztec/constants';
|
|
3
1
|
import type { EpochCache } from '@aztec/epoch-cache';
|
|
4
2
|
import {
|
|
5
3
|
BlockNumber,
|
|
@@ -9,6 +7,11 @@ import {
|
|
|
9
7
|
SlotNumber,
|
|
10
8
|
} from '@aztec/foundation/branded-types';
|
|
11
9
|
import { randomInt } from '@aztec/foundation/crypto/random';
|
|
10
|
+
import {
|
|
11
|
+
flipSignature,
|
|
12
|
+
generateRecoverableSignature,
|
|
13
|
+
generateUnrecoverableSignature,
|
|
14
|
+
} from '@aztec/foundation/crypto/secp256k1-signer';
|
|
12
15
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
13
16
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
14
17
|
import { Signature } from '@aztec/foundation/eth-signature';
|
|
@@ -27,18 +30,18 @@ import {
|
|
|
27
30
|
type L2BlockSource,
|
|
28
31
|
MaliciousCommitteeAttestationsAndSigners,
|
|
29
32
|
} from '@aztec/stdlib/block';
|
|
30
|
-
import type
|
|
33
|
+
import { type Checkpoint, validateCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
31
34
|
import { getSlotStartBuildTimestamp } from '@aztec/stdlib/epoch-helpers';
|
|
32
35
|
import { Gas } from '@aztec/stdlib/gas';
|
|
33
36
|
import {
|
|
34
|
-
|
|
37
|
+
InsufficientValidTxsError,
|
|
35
38
|
type PublicProcessorLimits,
|
|
36
39
|
type ResolvedSequencerConfig,
|
|
37
40
|
type WorldStateSynchronizer,
|
|
38
41
|
} from '@aztec/stdlib/interfaces/server';
|
|
39
42
|
import { type L1ToL2MessageSource, computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
|
|
40
43
|
import type { BlockProposalOptions, CheckpointProposal, CheckpointProposalOptions } from '@aztec/stdlib/p2p';
|
|
41
|
-
import { orderAttestations } from '@aztec/stdlib/p2p';
|
|
44
|
+
import { orderAttestations, trimAttestations } from '@aztec/stdlib/p2p';
|
|
42
45
|
import type { L2BlockBuiltStats } from '@aztec/stdlib/stats';
|
|
43
46
|
import { type FailedTx, Tx } from '@aztec/stdlib/tx';
|
|
44
47
|
import { AttestationTimeoutError } from '@aztec/stdlib/validators';
|
|
@@ -262,6 +265,22 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
262
265
|
this.setStateFn(SequencerState.ASSEMBLING_CHECKPOINT, this.slot);
|
|
263
266
|
const checkpoint = await checkpointBuilder.completeCheckpoint();
|
|
264
267
|
|
|
268
|
+
// Final validation round for the checkpoint before we propose it, just for safety
|
|
269
|
+
try {
|
|
270
|
+
validateCheckpoint(checkpoint, {
|
|
271
|
+
rollupManaLimit: this.l1Constants.rollupManaLimit,
|
|
272
|
+
maxL2BlockGas: this.config.maxL2BlockGas,
|
|
273
|
+
maxDABlockGas: this.config.maxDABlockGas,
|
|
274
|
+
maxTxsPerBlock: this.config.maxTxsPerBlock,
|
|
275
|
+
maxTxsPerCheckpoint: this.config.maxTxsPerCheckpoint,
|
|
276
|
+
});
|
|
277
|
+
} catch (err) {
|
|
278
|
+
this.log.error(`Built an invalid checkpoint at slot ${this.slot} (skipping proposal)`, err, {
|
|
279
|
+
checkpoint: checkpoint.header.toInspect(),
|
|
280
|
+
});
|
|
281
|
+
return undefined;
|
|
282
|
+
}
|
|
283
|
+
|
|
265
284
|
// Record checkpoint-level build metrics
|
|
266
285
|
this.metrics.recordCheckpointBuild(
|
|
267
286
|
checkpointBuildTimer.ms(),
|
|
@@ -384,9 +403,6 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
384
403
|
const txHashesAlreadyIncluded = new Set<string>();
|
|
385
404
|
const initialBlockNumber = BlockNumber(this.syncedToBlockNumber + 1);
|
|
386
405
|
|
|
387
|
-
// Remaining blob fields available for blocks (checkpoint end marker already subtracted)
|
|
388
|
-
let remainingBlobFields = BLOBS_PER_CHECKPOINT * FIELDS_PER_BLOB - NUM_CHECKPOINT_END_MARKER_FIELDS;
|
|
389
|
-
|
|
390
406
|
// Last block in the checkpoint will usually be flagged as pending broadcast, so we send it along with the checkpoint proposal
|
|
391
407
|
let blockPendingBroadcast: { block: L2Block; txs: Tx[] } | undefined = undefined;
|
|
392
408
|
|
|
@@ -419,7 +435,6 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
419
435
|
blockNumber,
|
|
420
436
|
indexWithinCheckpoint,
|
|
421
437
|
txHashesAlreadyIncluded,
|
|
422
|
-
remainingBlobFields,
|
|
423
438
|
});
|
|
424
439
|
|
|
425
440
|
// TODO(palla/mbps): Review these conditions. We may want to keep trying in some scenarios.
|
|
@@ -445,12 +460,9 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
445
460
|
break;
|
|
446
461
|
}
|
|
447
462
|
|
|
448
|
-
const { block, usedTxs
|
|
463
|
+
const { block, usedTxs } = buildResult;
|
|
449
464
|
blocksInCheckpoint.push(block);
|
|
450
465
|
|
|
451
|
-
// Update remaining blob fields for the next block
|
|
452
|
-
remainingBlobFields = newRemainingBlobFields;
|
|
453
|
-
|
|
454
466
|
// Sync the proposed block to the archiver to make it available
|
|
455
467
|
// Note that the checkpoint builder uses its own fork so it should not need to wait for this syncing
|
|
456
468
|
// Eventually we should refactor the checkpoint builder to not need a separate long-lived fork
|
|
@@ -518,18 +530,10 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
518
530
|
indexWithinCheckpoint: IndexWithinCheckpoint;
|
|
519
531
|
buildDeadline: Date | undefined;
|
|
520
532
|
txHashesAlreadyIncluded: Set<string>;
|
|
521
|
-
remainingBlobFields: number;
|
|
522
533
|
},
|
|
523
|
-
): Promise<{ block: L2Block; usedTxs: Tx[]
|
|
524
|
-
const {
|
|
525
|
-
|
|
526
|
-
forceCreate,
|
|
527
|
-
blockNumber,
|
|
528
|
-
indexWithinCheckpoint,
|
|
529
|
-
buildDeadline,
|
|
530
|
-
txHashesAlreadyIncluded,
|
|
531
|
-
remainingBlobFields,
|
|
532
|
-
} = opts;
|
|
534
|
+
): Promise<{ block: L2Block; usedTxs: Tx[] } | { error: Error } | undefined> {
|
|
535
|
+
const { blockTimestamp, forceCreate, blockNumber, indexWithinCheckpoint, buildDeadline, txHashesAlreadyIncluded } =
|
|
536
|
+
opts;
|
|
533
537
|
|
|
534
538
|
this.log.verbose(
|
|
535
539
|
`Preparing block ${blockNumber} index ${indexWithinCheckpoint} at checkpoint ${this.checkpointNumber} for slot ${this.slot}`,
|
|
@@ -538,8 +542,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
538
542
|
|
|
539
543
|
try {
|
|
540
544
|
// Wait until we have enough txs to build the block
|
|
541
|
-
const minTxs = this.
|
|
542
|
-
const { availableTxs, canStartBuilding } = await this.waitForMinTxs(opts);
|
|
545
|
+
const { availableTxs, canStartBuilding, minTxs } = await this.waitForMinTxs(opts);
|
|
543
546
|
if (!canStartBuilding) {
|
|
544
547
|
this.log.warn(
|
|
545
548
|
`Not enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.slot} (got ${availableTxs} txs but needs ${minTxs})`,
|
|
@@ -563,19 +566,24 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
563
566
|
);
|
|
564
567
|
this.setStateFn(SequencerState.CREATING_BLOCK, this.slot);
|
|
565
568
|
|
|
566
|
-
//
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
const blockBuilderOptions: PublicProcessorLimits = {
|
|
569
|
+
// Per-block limits derived at startup by computeBlockLimits(), further capped
|
|
570
|
+
// by remaining checkpoint-level budgets inside CheckpointBuilder before each block is built.
|
|
571
|
+
// minValidTxs is passed into the builder so it can reject the block *before* updating state.
|
|
572
|
+
const minValidTxs = forceCreate ? 0 : (this.config.minValidTxsPerBlock ?? minTxs);
|
|
573
|
+
const blockBuilderOptions: PublicProcessorLimits & { minValidTxs?: number } = {
|
|
571
574
|
maxTransactions: this.config.maxTxsPerBlock,
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
+
maxBlockGas:
|
|
576
|
+
this.config.maxL2BlockGas !== undefined || this.config.maxDABlockGas !== undefined
|
|
577
|
+
? new Gas(this.config.maxDABlockGas ?? Infinity, this.config.maxL2BlockGas ?? Infinity)
|
|
578
|
+
: undefined,
|
|
575
579
|
deadline: buildDeadline,
|
|
580
|
+
isBuildingProposal: true,
|
|
581
|
+
minValidTxs,
|
|
576
582
|
};
|
|
577
583
|
|
|
578
|
-
// Actually build the block by executing txs
|
|
584
|
+
// Actually build the block by executing txs. The builder throws InsufficientValidTxsError
|
|
585
|
+
// if the number of successfully processed txs is below minValidTxs, ensuring state is not
|
|
586
|
+
// updated for blocks that will be discarded.
|
|
579
587
|
const buildResult = await this.buildSingleBlockWithCheckpointBuilder(
|
|
580
588
|
checkpointBuilder,
|
|
581
589
|
pendingTxs,
|
|
@@ -587,14 +595,16 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
587
595
|
// If any txs failed during execution, drop them from the mempool so we don't pick them up again
|
|
588
596
|
await this.dropFailedTxsFromP2P(buildResult.failedTxs);
|
|
589
597
|
|
|
590
|
-
|
|
591
|
-
// too long, then we may not get to minTxsPerBlock after executing public functions.
|
|
592
|
-
const minValidTxs = this.config.minValidTxsPerBlock ?? minTxs;
|
|
593
|
-
const numTxs = buildResult.status === 'no-valid-txs' ? 0 : buildResult.numTxs;
|
|
594
|
-
if (buildResult.status === 'no-valid-txs' || (!forceCreate && numTxs < minValidTxs)) {
|
|
598
|
+
if (buildResult.status === 'insufficient-valid-txs') {
|
|
595
599
|
this.log.warn(
|
|
596
600
|
`Block ${blockNumber} at index ${indexWithinCheckpoint} on slot ${this.slot} has too few valid txs to be proposed`,
|
|
597
|
-
{
|
|
601
|
+
{
|
|
602
|
+
slot: this.slot,
|
|
603
|
+
blockNumber,
|
|
604
|
+
numTxs: buildResult.processedCount,
|
|
605
|
+
indexWithinCheckpoint,
|
|
606
|
+
minValidTxs,
|
|
607
|
+
},
|
|
598
608
|
);
|
|
599
609
|
this.eventEmitter.emit('block-build-failed', { reason: `Insufficient valid txs`, slot: this.slot });
|
|
600
610
|
this.metrics.recordBlockProposalFailed('insufficient_valid_txs');
|
|
@@ -602,7 +612,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
602
612
|
}
|
|
603
613
|
|
|
604
614
|
// Block creation succeeded, emit stats and metrics
|
|
605
|
-
const {
|
|
615
|
+
const { block, publicProcessorDuration, usedTxs, blockBuildDuration, numTxs } = buildResult;
|
|
606
616
|
|
|
607
617
|
const blockStats = {
|
|
608
618
|
eventName: 'l2-block-built',
|
|
@@ -613,7 +623,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
613
623
|
|
|
614
624
|
const blockHash = await block.hash();
|
|
615
625
|
const txHashes = block.body.txEffects.map(tx => tx.txHash);
|
|
616
|
-
const manaPerSec =
|
|
626
|
+
const manaPerSec = block.header.totalManaUsed.toNumberUnsafe() / (blockBuildDuration / 1000);
|
|
617
627
|
|
|
618
628
|
this.log.info(
|
|
619
629
|
`Built block ${block.number} at checkpoint ${this.checkpointNumber} for slot ${this.slot} with ${numTxs} txs`,
|
|
@@ -621,9 +631,9 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
621
631
|
);
|
|
622
632
|
|
|
623
633
|
this.eventEmitter.emit('block-proposed', { blockNumber: block.number, slot: this.slot });
|
|
624
|
-
this.metrics.recordBuiltBlock(blockBuildDuration,
|
|
634
|
+
this.metrics.recordBuiltBlock(blockBuildDuration, block.header.totalManaUsed.toNumberUnsafe());
|
|
625
635
|
|
|
626
|
-
return { block, usedTxs
|
|
636
|
+
return { block, usedTxs };
|
|
627
637
|
} catch (err: any) {
|
|
628
638
|
this.eventEmitter.emit('block-build-failed', { reason: err.message, slot: this.slot });
|
|
629
639
|
this.log.error(`Error building block`, err, { blockNumber, slot: this.slot });
|
|
@@ -633,13 +643,13 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
633
643
|
}
|
|
634
644
|
}
|
|
635
645
|
|
|
636
|
-
/** Uses the checkpoint builder to build a block, catching
|
|
646
|
+
/** Uses the checkpoint builder to build a block, catching InsufficientValidTxsError. */
|
|
637
647
|
private async buildSingleBlockWithCheckpointBuilder(
|
|
638
648
|
checkpointBuilder: CheckpointBuilder,
|
|
639
649
|
pendingTxs: AsyncIterable<Tx>,
|
|
640
650
|
blockNumber: BlockNumber,
|
|
641
651
|
blockTimestamp: bigint,
|
|
642
|
-
blockBuilderOptions: PublicProcessorLimits,
|
|
652
|
+
blockBuilderOptions: PublicProcessorLimits & { minValidTxs?: number },
|
|
643
653
|
) {
|
|
644
654
|
try {
|
|
645
655
|
const workTimer = new Timer();
|
|
@@ -647,8 +657,12 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
647
657
|
const blockBuildDuration = workTimer.ms();
|
|
648
658
|
return { ...result, blockBuildDuration, status: 'success' as const };
|
|
649
659
|
} catch (err: unknown) {
|
|
650
|
-
if (isErrorClass(err,
|
|
651
|
-
return {
|
|
660
|
+
if (isErrorClass(err, InsufficientValidTxsError)) {
|
|
661
|
+
return {
|
|
662
|
+
failedTxs: err.failedTxs,
|
|
663
|
+
processedCount: err.processedCount,
|
|
664
|
+
status: 'insufficient-valid-txs' as const,
|
|
665
|
+
};
|
|
652
666
|
}
|
|
653
667
|
throw err;
|
|
654
668
|
}
|
|
@@ -661,7 +675,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
661
675
|
blockNumber: BlockNumber;
|
|
662
676
|
indexWithinCheckpoint: IndexWithinCheckpoint;
|
|
663
677
|
buildDeadline: Date | undefined;
|
|
664
|
-
}): Promise<{ canStartBuilding: boolean; availableTxs: number }> {
|
|
678
|
+
}): Promise<{ canStartBuilding: boolean; availableTxs: number; minTxs: number }> {
|
|
665
679
|
const { indexWithinCheckpoint, blockNumber, buildDeadline, forceCreate } = opts;
|
|
666
680
|
|
|
667
681
|
// We only allow a block with 0 txs in the first block of the checkpoint
|
|
@@ -678,7 +692,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
678
692
|
// If we're past deadline, or we have no deadline, give up
|
|
679
693
|
const now = this.dateProvider.nowAsDate();
|
|
680
694
|
if (startBuildingDeadline === undefined || now >= startBuildingDeadline) {
|
|
681
|
-
return { canStartBuilding: false, availableTxs
|
|
695
|
+
return { canStartBuilding: false, availableTxs, minTxs };
|
|
682
696
|
}
|
|
683
697
|
|
|
684
698
|
// Wait a bit before checking again
|
|
@@ -691,7 +705,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
691
705
|
availableTxs = await this.p2pClient.getPendingTxCount();
|
|
692
706
|
}
|
|
693
707
|
|
|
694
|
-
return { canStartBuilding: true, availableTxs };
|
|
708
|
+
return { canStartBuilding: true, availableTxs, minTxs };
|
|
695
709
|
}
|
|
696
710
|
|
|
697
711
|
/**
|
|
@@ -743,11 +757,28 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
743
757
|
|
|
744
758
|
collectedAttestationsCount = attestations.length;
|
|
745
759
|
|
|
760
|
+
// Trim attestations to minimum required to save L1 calldata gas
|
|
761
|
+
const localAddresses = this.validatorClient.getValidatorAddresses();
|
|
762
|
+
const trimmed = trimAttestations(
|
|
763
|
+
attestations,
|
|
764
|
+
numberOfRequiredAttestations,
|
|
765
|
+
this.attestorAddress,
|
|
766
|
+
localAddresses,
|
|
767
|
+
);
|
|
768
|
+
if (trimmed.length < attestations.length) {
|
|
769
|
+
this.log.debug(`Trimmed attestations from ${attestations.length} to ${trimmed.length} for L1 submission`);
|
|
770
|
+
}
|
|
771
|
+
|
|
746
772
|
// Rollup contract requires that the signatures are provided in the order of the committee
|
|
747
|
-
const sorted = orderAttestations(
|
|
773
|
+
const sorted = orderAttestations(trimmed, committee);
|
|
748
774
|
|
|
749
775
|
// Manipulate the attestations if we've been configured to do so
|
|
750
|
-
if (
|
|
776
|
+
if (
|
|
777
|
+
this.config.injectFakeAttestation ||
|
|
778
|
+
this.config.injectHighSValueAttestation ||
|
|
779
|
+
this.config.injectUnrecoverableSignatureAttestation ||
|
|
780
|
+
this.config.shuffleAttestationOrdering
|
|
781
|
+
) {
|
|
751
782
|
return this.manipulateAttestations(proposal.slotNumber, epoch, seed, committee, sorted);
|
|
752
783
|
}
|
|
753
784
|
|
|
@@ -776,7 +807,11 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
776
807
|
this.epochCache.computeProposerIndex(slotNumber, epoch, seed, BigInt(committee.length)),
|
|
777
808
|
);
|
|
778
809
|
|
|
779
|
-
if (
|
|
810
|
+
if (
|
|
811
|
+
this.config.injectFakeAttestation ||
|
|
812
|
+
this.config.injectHighSValueAttestation ||
|
|
813
|
+
this.config.injectUnrecoverableSignatureAttestation
|
|
814
|
+
) {
|
|
780
815
|
// Find non-empty attestations that are not from the proposer
|
|
781
816
|
const nonProposerIndices: number[] = [];
|
|
782
817
|
for (let i = 0; i < attestations.length; i++) {
|
|
@@ -786,8 +821,20 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
786
821
|
}
|
|
787
822
|
if (nonProposerIndices.length > 0) {
|
|
788
823
|
const targetIndex = nonProposerIndices[randomInt(nonProposerIndices.length)];
|
|
789
|
-
this.
|
|
790
|
-
|
|
824
|
+
if (this.config.injectHighSValueAttestation) {
|
|
825
|
+
this.log.warn(
|
|
826
|
+
`Injecting high-s value attestation in checkpoint for slot ${slotNumber} at index ${targetIndex}`,
|
|
827
|
+
);
|
|
828
|
+
unfreeze(attestations[targetIndex]).signature = flipSignature(attestations[targetIndex].signature);
|
|
829
|
+
} else if (this.config.injectUnrecoverableSignatureAttestation) {
|
|
830
|
+
this.log.warn(
|
|
831
|
+
`Injecting unrecoverable signature attestation in checkpoint for slot ${slotNumber} at index ${targetIndex}`,
|
|
832
|
+
);
|
|
833
|
+
unfreeze(attestations[targetIndex]).signature = generateUnrecoverableSignature();
|
|
834
|
+
} else {
|
|
835
|
+
this.log.warn(`Injecting fake attestation in checkpoint for slot ${slotNumber} at index ${targetIndex}`);
|
|
836
|
+
unfreeze(attestations[targetIndex]).signature = generateRecoverableSignature();
|
|
837
|
+
}
|
|
791
838
|
}
|
|
792
839
|
return new CommitteeAttestationsAndSigners(attestations);
|
|
793
840
|
}
|
|
@@ -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,
|
|
@@ -110,7 +110,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
110
110
|
/** Updates sequencer config by the defined values and updates the timetable */
|
|
111
111
|
public updateConfig(config: Partial<SequencerConfig>) {
|
|
112
112
|
const filteredConfig = pickFromSchema(config, SequencerConfigSchema);
|
|
113
|
-
this.log.info(`Updated sequencer config`, omit(filteredConfig, '
|
|
113
|
+
this.log.info(`Updated sequencer config`, omit(filteredConfig, 'txPublicSetupAllowListExtend'));
|
|
114
114
|
this.config = merge(this.config, filteredConfig);
|
|
115
115
|
this.timetable = new SequencerTimetable(
|
|
116
116
|
{
|
|
@@ -281,8 +281,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
281
281
|
|
|
282
282
|
const logCtx = {
|
|
283
283
|
now,
|
|
284
|
-
|
|
285
|
-
syncedToL2Slot: getSlotAtTimestamp(syncedTo.l1Timestamp, this.l1Constants),
|
|
284
|
+
syncedToL2Slot: syncedTo.syncedL2Slot,
|
|
286
285
|
slot,
|
|
287
286
|
slotTs: ts,
|
|
288
287
|
checkpointNumber,
|
|
@@ -422,6 +421,13 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
422
421
|
);
|
|
423
422
|
}
|
|
424
423
|
|
|
424
|
+
/**
|
|
425
|
+
* Returns the current sequencer state.
|
|
426
|
+
*/
|
|
427
|
+
public getState(): SequencerState {
|
|
428
|
+
return this.state;
|
|
429
|
+
}
|
|
430
|
+
|
|
425
431
|
/**
|
|
426
432
|
* Internal helper for setting the sequencer state and checks if we have enough time left in the slot to transition to the new state.
|
|
427
433
|
* @param proposedState - The new state to transition to.
|
|
@@ -468,16 +474,15 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
468
474
|
* We don't check against the previous block submitted since it may have been reorg'd out.
|
|
469
475
|
*/
|
|
470
476
|
protected async checkSync(args: { ts: bigint; slot: SlotNumber }): Promise<SequencerSyncCheckResult | undefined> {
|
|
471
|
-
// Check that the archiver
|
|
477
|
+
// Check that the archiver has fully synced the L2 slot before the one we want to propose in.
|
|
472
478
|
// TODO(#14766): Archiver reports L1 timestamp based on L1 blocks seen, which means that a missed L1 block will
|
|
473
479
|
// cause the archiver L1 timestamp to fall behind, and cause this sequencer to start processing one L1 slot later.
|
|
474
|
-
const
|
|
475
|
-
const { slot
|
|
476
|
-
if (
|
|
480
|
+
const syncedL2Slot = await this.l2BlockSource.getSyncedL2SlotNumber();
|
|
481
|
+
const { slot } = args;
|
|
482
|
+
if (syncedL2Slot === undefined || syncedL2Slot + 1 < slot) {
|
|
477
483
|
this.log.debug(`Cannot propose block at next L2 slot ${slot} due to pending sync from L1`, {
|
|
478
484
|
slot,
|
|
479
|
-
|
|
480
|
-
l1Timestamp,
|
|
485
|
+
syncedL2Slot,
|
|
481
486
|
});
|
|
482
487
|
return undefined;
|
|
483
488
|
}
|
|
@@ -517,7 +522,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
517
522
|
checkpointNumber: CheckpointNumber.ZERO,
|
|
518
523
|
blockNumber: BlockNumber.ZERO,
|
|
519
524
|
archive,
|
|
520
|
-
|
|
525
|
+
syncedL2Slot,
|
|
521
526
|
pendingChainValidationStatus,
|
|
522
527
|
};
|
|
523
528
|
}
|
|
@@ -534,7 +539,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
534
539
|
blockNumber: blockData.header.getBlockNumber(),
|
|
535
540
|
checkpointNumber: blockData.checkpointNumber,
|
|
536
541
|
archive: blockData.archive.root,
|
|
537
|
-
|
|
542
|
+
syncedL2Slot,
|
|
538
543
|
pendingChainValidationStatus,
|
|
539
544
|
};
|
|
540
545
|
}
|
|
@@ -713,7 +718,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
713
718
|
syncedTo: SequencerSyncCheckResult,
|
|
714
719
|
currentSlot: SlotNumber,
|
|
715
720
|
): Promise<void> {
|
|
716
|
-
const { pendingChainValidationStatus,
|
|
721
|
+
const { pendingChainValidationStatus, syncedL2Slot } = syncedTo;
|
|
717
722
|
if (pendingChainValidationStatus.valid) {
|
|
718
723
|
return;
|
|
719
724
|
}
|
|
@@ -728,7 +733,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
728
733
|
|
|
729
734
|
const logData = {
|
|
730
735
|
invalidL1Timestamp: invalidCheckpointTimestamp,
|
|
731
|
-
|
|
736
|
+
syncedL2Slot,
|
|
732
737
|
invalidCheckpoint: pendingChainValidationStatus.checkpoint,
|
|
733
738
|
secondsBeforeInvalidatingBlockAsCommitteeMember,
|
|
734
739
|
secondsBeforeInvalidatingBlockAsNonCommitteeMember,
|
|
@@ -875,6 +880,6 @@ type SequencerSyncCheckResult = {
|
|
|
875
880
|
checkpointNumber: CheckpointNumber;
|
|
876
881
|
blockNumber: BlockNumber;
|
|
877
882
|
archive: Fr;
|
|
878
|
-
|
|
883
|
+
syncedL2Slot: SlotNumber;
|
|
879
884
|
pendingChainValidationStatus: ValidateCheckpointResult;
|
|
880
885
|
};
|
|
@@ -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
|
>;
|