@aztec/sequencer-client 0.0.1-commit.181e2d196 → 0.0.1-commit.1a421b1a1
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 +22 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +14 -12
- 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 +33 -26
- package/dest/sequencer/sequencer.d.ts +7 -6
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +11 -13
- 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 +4 -6
- package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.js +39 -30
- package/package.json +28 -28
- package/src/client/sequencer-client.ts +111 -12
- package/src/config.ts +17 -14
- package/src/sequencer/checkpoint_proposal_job.ts +36 -38
- package/src/sequencer/sequencer.ts +12 -14
- package/src/sequencer/timetable.ts +7 -7
- package/src/sequencer/types.ts +1 -1
- package/src/test/mock_checkpoint_builder.ts +48 -45
package/src/config.ts
CHANGED
|
@@ -13,7 +13,6 @@ import { type P2PConfig, p2pConfigMappings } from '@aztec/p2p/config';
|
|
|
13
13
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
14
14
|
import {
|
|
15
15
|
type ChainConfig,
|
|
16
|
-
DEFAULT_MAX_TXS_PER_BLOCK,
|
|
17
16
|
type SequencerConfig,
|
|
18
17
|
chainConfigMappings,
|
|
19
18
|
sharedSequencerConfigMappings,
|
|
@@ -36,15 +35,12 @@ export type { SequencerConfig };
|
|
|
36
35
|
* Default values for SequencerConfig.
|
|
37
36
|
* Centralized location for all sequencer configuration defaults.
|
|
38
37
|
*/
|
|
39
|
-
export const DefaultSequencerConfig
|
|
38
|
+
export const DefaultSequencerConfig = {
|
|
40
39
|
sequencerPollingIntervalMS: 500,
|
|
41
|
-
maxTxsPerBlock: DEFAULT_MAX_TXS_PER_BLOCK,
|
|
42
40
|
minTxsPerBlock: 1,
|
|
43
41
|
buildCheckpointIfEmpty: false,
|
|
44
42
|
publishTxsWithProposals: false,
|
|
45
|
-
|
|
46
|
-
maxDABlockGas: 10e9,
|
|
47
|
-
maxBlockSizeInBytes: 1024 * 1024,
|
|
43
|
+
perBlockAllocationMultiplier: 2,
|
|
48
44
|
enforceTimeTable: true,
|
|
49
45
|
attestationPropagationTime: DEFAULT_P2P_PROPAGATION_TIME,
|
|
50
46
|
secondsBeforeInvalidatingBlockAsCommitteeMember: 144, // 12 L1 blocks
|
|
@@ -59,7 +55,7 @@ export const DefaultSequencerConfig: ResolvedSequencerConfig = {
|
|
|
59
55
|
shuffleAttestationOrdering: false,
|
|
60
56
|
skipPushProposedBlocksToArchiver: false,
|
|
61
57
|
skipPublishingCheckpointsPercent: 0,
|
|
62
|
-
};
|
|
58
|
+
} satisfies ResolvedSequencerConfig;
|
|
63
59
|
|
|
64
60
|
/**
|
|
65
61
|
* Configuration settings for the SequencerClient.
|
|
@@ -80,6 +76,11 @@ export const sequencerConfigMappings: ConfigMappingsType<SequencerConfig> = {
|
|
|
80
76
|
description: 'The number of ms to wait between polling for checking to build on the next slot.',
|
|
81
77
|
...numberConfigHelper(DefaultSequencerConfig.sequencerPollingIntervalMS),
|
|
82
78
|
},
|
|
79
|
+
maxTxsPerCheckpoint: {
|
|
80
|
+
env: 'SEQ_MAX_TX_PER_CHECKPOINT',
|
|
81
|
+
description: 'The maximum number of txs across all blocks in a checkpoint.',
|
|
82
|
+
parseEnv: (val: string) => (val ? parseInt(val, 10) : undefined),
|
|
83
|
+
},
|
|
83
84
|
minTxsPerBlock: {
|
|
84
85
|
env: 'SEQ_MIN_TX_PER_BLOCK',
|
|
85
86
|
description: 'The minimum number of txs to include in a block.',
|
|
@@ -97,12 +98,19 @@ export const sequencerConfigMappings: ConfigMappingsType<SequencerConfig> = {
|
|
|
97
98
|
maxL2BlockGas: {
|
|
98
99
|
env: 'SEQ_MAX_L2_BLOCK_GAS',
|
|
99
100
|
description: 'The maximum L2 block gas.',
|
|
100
|
-
|
|
101
|
+
parseEnv: (val: string) => (val ? parseInt(val, 10) : undefined),
|
|
101
102
|
},
|
|
102
103
|
maxDABlockGas: {
|
|
103
104
|
env: 'SEQ_MAX_DA_BLOCK_GAS',
|
|
104
105
|
description: 'The maximum DA block gas.',
|
|
105
|
-
|
|
106
|
+
parseEnv: (val: string) => (val ? parseInt(val, 10) : undefined),
|
|
107
|
+
},
|
|
108
|
+
perBlockAllocationMultiplier: {
|
|
109
|
+
env: 'SEQ_PER_BLOCK_ALLOCATION_MULTIPLIER',
|
|
110
|
+
description:
|
|
111
|
+
'Per-block gas budget multiplier for both L2 and DA gas. Budget per block is (checkpointLimit / maxBlocks) * multiplier.' +
|
|
112
|
+
' Values greater than one allow early blocks to use more than their even share, relying on checkpoint-level capping for later blocks.',
|
|
113
|
+
...numberConfigHelper(DefaultSequencerConfig.perBlockAllocationMultiplier),
|
|
106
114
|
},
|
|
107
115
|
coinbase: {
|
|
108
116
|
env: 'COINBASE',
|
|
@@ -122,11 +130,6 @@ export const sequencerConfigMappings: ConfigMappingsType<SequencerConfig> = {
|
|
|
122
130
|
env: 'ACVM_BINARY_PATH',
|
|
123
131
|
description: 'The path to the ACVM binary',
|
|
124
132
|
},
|
|
125
|
-
maxBlockSizeInBytes: {
|
|
126
|
-
env: 'SEQ_MAX_BLOCK_SIZE_IN_BYTES',
|
|
127
|
-
description: 'Max block size',
|
|
128
|
-
...numberConfigHelper(DefaultSequencerConfig.maxBlockSizeInBytes),
|
|
129
|
-
},
|
|
130
133
|
enforceTimeTable: {
|
|
131
134
|
env: 'SEQ_ENFORCE_TIME_TABLE',
|
|
132
135
|
description: 'Whether to enforce the time table when building blocks',
|
|
@@ -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,
|
|
@@ -32,7 +30,7 @@ import {
|
|
|
32
30
|
type L2BlockSource,
|
|
33
31
|
MaliciousCommitteeAttestationsAndSigners,
|
|
34
32
|
} from '@aztec/stdlib/block';
|
|
35
|
-
import type
|
|
33
|
+
import { type Checkpoint, validateCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
36
34
|
import { getSlotStartBuildTimestamp } from '@aztec/stdlib/epoch-helpers';
|
|
37
35
|
import { Gas } from '@aztec/stdlib/gas';
|
|
38
36
|
import {
|
|
@@ -267,6 +265,22 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
267
265
|
this.setStateFn(SequencerState.ASSEMBLING_CHECKPOINT, this.slot);
|
|
268
266
|
const checkpoint = await checkpointBuilder.completeCheckpoint();
|
|
269
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
|
+
|
|
270
284
|
// Record checkpoint-level build metrics
|
|
271
285
|
this.metrics.recordCheckpointBuild(
|
|
272
286
|
checkpointBuildTimer.ms(),
|
|
@@ -389,9 +403,6 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
389
403
|
const txHashesAlreadyIncluded = new Set<string>();
|
|
390
404
|
const initialBlockNumber = BlockNumber(this.syncedToBlockNumber + 1);
|
|
391
405
|
|
|
392
|
-
// Remaining blob fields available for blocks (checkpoint end marker already subtracted)
|
|
393
|
-
let remainingBlobFields = BLOBS_PER_CHECKPOINT * FIELDS_PER_BLOB - NUM_CHECKPOINT_END_MARKER_FIELDS;
|
|
394
|
-
|
|
395
406
|
// Last block in the checkpoint will usually be flagged as pending broadcast, so we send it along with the checkpoint proposal
|
|
396
407
|
let blockPendingBroadcast: { block: L2Block; txs: Tx[] } | undefined = undefined;
|
|
397
408
|
|
|
@@ -424,7 +435,6 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
424
435
|
blockNumber,
|
|
425
436
|
indexWithinCheckpoint,
|
|
426
437
|
txHashesAlreadyIncluded,
|
|
427
|
-
remainingBlobFields,
|
|
428
438
|
});
|
|
429
439
|
|
|
430
440
|
// TODO(palla/mbps): Review these conditions. We may want to keep trying in some scenarios.
|
|
@@ -450,12 +460,9 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
450
460
|
break;
|
|
451
461
|
}
|
|
452
462
|
|
|
453
|
-
const { block, usedTxs
|
|
463
|
+
const { block, usedTxs } = buildResult;
|
|
454
464
|
blocksInCheckpoint.push(block);
|
|
455
465
|
|
|
456
|
-
// Update remaining blob fields for the next block
|
|
457
|
-
remainingBlobFields = newRemainingBlobFields;
|
|
458
|
-
|
|
459
466
|
// Sync the proposed block to the archiver to make it available
|
|
460
467
|
// Note that the checkpoint builder uses its own fork so it should not need to wait for this syncing
|
|
461
468
|
// Eventually we should refactor the checkpoint builder to not need a separate long-lived fork
|
|
@@ -523,18 +530,10 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
523
530
|
indexWithinCheckpoint: IndexWithinCheckpoint;
|
|
524
531
|
buildDeadline: Date | undefined;
|
|
525
532
|
txHashesAlreadyIncluded: Set<string>;
|
|
526
|
-
remainingBlobFields: number;
|
|
527
533
|
},
|
|
528
|
-
): Promise<{ block: L2Block; usedTxs: Tx[]
|
|
529
|
-
const {
|
|
530
|
-
|
|
531
|
-
forceCreate,
|
|
532
|
-
blockNumber,
|
|
533
|
-
indexWithinCheckpoint,
|
|
534
|
-
buildDeadline,
|
|
535
|
-
txHashesAlreadyIncluded,
|
|
536
|
-
remainingBlobFields,
|
|
537
|
-
} = opts;
|
|
534
|
+
): Promise<{ block: L2Block; usedTxs: Tx[] } | { error: Error } | undefined> {
|
|
535
|
+
const { blockTimestamp, forceCreate, blockNumber, indexWithinCheckpoint, buildDeadline, txHashesAlreadyIncluded } =
|
|
536
|
+
opts;
|
|
538
537
|
|
|
539
538
|
this.log.verbose(
|
|
540
539
|
`Preparing block ${blockNumber} index ${indexWithinCheckpoint} at checkpoint ${this.checkpointNumber} for slot ${this.slot}`,
|
|
@@ -543,8 +542,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
543
542
|
|
|
544
543
|
try {
|
|
545
544
|
// Wait until we have enough txs to build the block
|
|
546
|
-
const minTxs = this.
|
|
547
|
-
const { availableTxs, canStartBuilding } = await this.waitForMinTxs(opts);
|
|
545
|
+
const { availableTxs, canStartBuilding, minTxs } = await this.waitForMinTxs(opts);
|
|
548
546
|
if (!canStartBuilding) {
|
|
549
547
|
this.log.warn(
|
|
550
548
|
`Not enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.slot} (got ${availableTxs} txs but needs ${minTxs})`,
|
|
@@ -568,16 +566,16 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
568
566
|
);
|
|
569
567
|
this.setStateFn(SequencerState.CREATING_BLOCK, this.slot);
|
|
570
568
|
|
|
571
|
-
//
|
|
572
|
-
|
|
573
|
-
const maxBlobFieldsForTxs = remainingBlobFields - blockEndOverhead;
|
|
574
|
-
|
|
569
|
+
// Per-block limits derived at startup by computeBlockLimits(), further capped
|
|
570
|
+
// by remaining checkpoint-level budgets inside CheckpointBuilder before each block is built.
|
|
575
571
|
const blockBuilderOptions: PublicProcessorLimits = {
|
|
576
572
|
maxTransactions: this.config.maxTxsPerBlock,
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
573
|
+
maxBlockGas:
|
|
574
|
+
this.config.maxL2BlockGas !== undefined || this.config.maxDABlockGas !== undefined
|
|
575
|
+
? new Gas(this.config.maxDABlockGas ?? Infinity, this.config.maxL2BlockGas ?? Infinity)
|
|
576
|
+
: undefined,
|
|
580
577
|
deadline: buildDeadline,
|
|
578
|
+
isBuildingProposal: true,
|
|
581
579
|
};
|
|
582
580
|
|
|
583
581
|
// Actually build the block by executing txs
|
|
@@ -607,7 +605,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
607
605
|
}
|
|
608
606
|
|
|
609
607
|
// Block creation succeeded, emit stats and metrics
|
|
610
|
-
const {
|
|
608
|
+
const { block, publicProcessorDuration, usedTxs, blockBuildDuration } = buildResult;
|
|
611
609
|
|
|
612
610
|
const blockStats = {
|
|
613
611
|
eventName: 'l2-block-built',
|
|
@@ -618,7 +616,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
618
616
|
|
|
619
617
|
const blockHash = await block.hash();
|
|
620
618
|
const txHashes = block.body.txEffects.map(tx => tx.txHash);
|
|
621
|
-
const manaPerSec =
|
|
619
|
+
const manaPerSec = block.header.totalManaUsed.toNumberUnsafe() / (blockBuildDuration / 1000);
|
|
622
620
|
|
|
623
621
|
this.log.info(
|
|
624
622
|
`Built block ${block.number} at checkpoint ${this.checkpointNumber} for slot ${this.slot} with ${numTxs} txs`,
|
|
@@ -626,9 +624,9 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
626
624
|
);
|
|
627
625
|
|
|
628
626
|
this.eventEmitter.emit('block-proposed', { blockNumber: block.number, slot: this.slot });
|
|
629
|
-
this.metrics.recordBuiltBlock(blockBuildDuration,
|
|
627
|
+
this.metrics.recordBuiltBlock(blockBuildDuration, block.header.totalManaUsed.toNumberUnsafe());
|
|
630
628
|
|
|
631
|
-
return { block, usedTxs
|
|
629
|
+
return { block, usedTxs };
|
|
632
630
|
} catch (err: any) {
|
|
633
631
|
this.eventEmitter.emit('block-build-failed', { reason: err.message, slot: this.slot });
|
|
634
632
|
this.log.error(`Error building block`, err, { blockNumber, slot: this.slot });
|
|
@@ -666,7 +664,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
666
664
|
blockNumber: BlockNumber;
|
|
667
665
|
indexWithinCheckpoint: IndexWithinCheckpoint;
|
|
668
666
|
buildDeadline: Date | undefined;
|
|
669
|
-
}): Promise<{ canStartBuilding: boolean; availableTxs: number }> {
|
|
667
|
+
}): Promise<{ canStartBuilding: boolean; availableTxs: number; minTxs: number }> {
|
|
670
668
|
const { indexWithinCheckpoint, blockNumber, buildDeadline, forceCreate } = opts;
|
|
671
669
|
|
|
672
670
|
// We only allow a block with 0 txs in the first block of the checkpoint
|
|
@@ -683,7 +681,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
683
681
|
// If we're past deadline, or we have no deadline, give up
|
|
684
682
|
const now = this.dateProvider.nowAsDate();
|
|
685
683
|
if (startBuildingDeadline === undefined || now >= startBuildingDeadline) {
|
|
686
|
-
return { canStartBuilding: false, availableTxs
|
|
684
|
+
return { canStartBuilding: false, availableTxs, minTxs };
|
|
687
685
|
}
|
|
688
686
|
|
|
689
687
|
// Wait a bit before checking again
|
|
@@ -696,7 +694,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
696
694
|
availableTxs = await this.p2pClient.getPendingTxCount();
|
|
697
695
|
}
|
|
698
696
|
|
|
699
|
-
return { canStartBuilding: true, availableTxs };
|
|
697
|
+
return { canStartBuilding: true, availableTxs, minTxs };
|
|
700
698
|
}
|
|
701
699
|
|
|
702
700
|
/**
|
|
@@ -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,
|
|
@@ -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,
|
|
@@ -475,16 +474,15 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
475
474
|
* We don't check against the previous block submitted since it may have been reorg'd out.
|
|
476
475
|
*/
|
|
477
476
|
protected async checkSync(args: { ts: bigint; slot: SlotNumber }): Promise<SequencerSyncCheckResult | undefined> {
|
|
478
|
-
// Check that the archiver
|
|
477
|
+
// Check that the archiver has fully synced the L2 slot before the one we want to propose in.
|
|
479
478
|
// TODO(#14766): Archiver reports L1 timestamp based on L1 blocks seen, which means that a missed L1 block will
|
|
480
479
|
// cause the archiver L1 timestamp to fall behind, and cause this sequencer to start processing one L1 slot later.
|
|
481
|
-
const
|
|
482
|
-
const { slot
|
|
483
|
-
if (
|
|
480
|
+
const syncedL2Slot = await this.l2BlockSource.getSyncedL2SlotNumber();
|
|
481
|
+
const { slot } = args;
|
|
482
|
+
if (syncedL2Slot === undefined || syncedL2Slot + 1 < slot) {
|
|
484
483
|
this.log.debug(`Cannot propose block at next L2 slot ${slot} due to pending sync from L1`, {
|
|
485
484
|
slot,
|
|
486
|
-
|
|
487
|
-
l1Timestamp,
|
|
485
|
+
syncedL2Slot,
|
|
488
486
|
});
|
|
489
487
|
return undefined;
|
|
490
488
|
}
|
|
@@ -524,7 +522,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
524
522
|
checkpointNumber: CheckpointNumber.ZERO,
|
|
525
523
|
blockNumber: BlockNumber.ZERO,
|
|
526
524
|
archive,
|
|
527
|
-
|
|
525
|
+
syncedL2Slot,
|
|
528
526
|
pendingChainValidationStatus,
|
|
529
527
|
};
|
|
530
528
|
}
|
|
@@ -541,7 +539,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
541
539
|
blockNumber: blockData.header.getBlockNumber(),
|
|
542
540
|
checkpointNumber: blockData.checkpointNumber,
|
|
543
541
|
archive: blockData.archive.root,
|
|
544
|
-
|
|
542
|
+
syncedL2Slot,
|
|
545
543
|
pendingChainValidationStatus,
|
|
546
544
|
};
|
|
547
545
|
}
|
|
@@ -720,7 +718,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
720
718
|
syncedTo: SequencerSyncCheckResult,
|
|
721
719
|
currentSlot: SlotNumber,
|
|
722
720
|
): Promise<void> {
|
|
723
|
-
const { pendingChainValidationStatus,
|
|
721
|
+
const { pendingChainValidationStatus, syncedL2Slot } = syncedTo;
|
|
724
722
|
if (pendingChainValidationStatus.valid) {
|
|
725
723
|
return;
|
|
726
724
|
}
|
|
@@ -735,7 +733,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
735
733
|
|
|
736
734
|
const logData = {
|
|
737
735
|
invalidL1Timestamp: invalidCheckpointTimestamp,
|
|
738
|
-
|
|
736
|
+
syncedL2Slot,
|
|
739
737
|
invalidCheckpoint: pendingChainValidationStatus.checkpoint,
|
|
740
738
|
secondsBeforeInvalidatingBlockAsCommitteeMember,
|
|
741
739
|
secondsBeforeInvalidatingBlockAsNonCommitteeMember,
|
|
@@ -882,6 +880,6 @@ type SequencerSyncCheckResult = {
|
|
|
882
880
|
checkpointNumber: CheckpointNumber;
|
|
883
881
|
blockNumber: BlockNumber;
|
|
884
882
|
archive: Fr;
|
|
885
|
-
|
|
883
|
+
syncedL2Slot: SlotNumber;
|
|
886
884
|
pendingChainValidationStatus: ValidateCheckpointResult;
|
|
887
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
|
>;
|
|
@@ -1,8 +1,8 @@
|
|
|
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
7
|
FullNodeBlockBuilderConfig,
|
|
8
8
|
ICheckpointBlockBuilder,
|
|
@@ -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);
|