@aztec/sequencer-client 0.0.1-commit.358457c → 0.0.1-commit.3895657bc
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/publisher/sequencer-publisher-factory.d.ts +1 -1
- package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-factory.js +14 -0
- package/dest/publisher/sequencer-publisher.d.ts +5 -1
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +45 -5
- 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 +60 -35
- package/dest/sequencer/sequencer.d.ts +9 -6
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +1 -1
- 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 +5 -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 +28 -19
- package/src/publisher/sequencer-publisher-factory.ts +15 -0
- package/src/publisher/sequencer-publisher.ts +61 -9
- package/src/sequencer/checkpoint_proposal_job.ts +76 -42
- package/src/sequencer/sequencer.ts +1 -1
- package/src/sequencer/timetable.ts +7 -7
- package/src/sequencer/types.ts +4 -1
- package/src/test/mock_checkpoint_builder.ts +48 -45
|
@@ -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,7 +30,7 @@ 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 {
|
|
@@ -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}`,
|
|
@@ -563,16 +567,16 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
563
567
|
);
|
|
564
568
|
this.setStateFn(SequencerState.CREATING_BLOCK, this.slot);
|
|
565
569
|
|
|
566
|
-
//
|
|
567
|
-
|
|
568
|
-
const maxBlobFieldsForTxs = remainingBlobFields - blockEndOverhead;
|
|
569
|
-
|
|
570
|
+
// Per-block limits derived at startup by computeBlockLimits(), further capped
|
|
571
|
+
// by remaining checkpoint-level budgets inside CheckpointBuilder before each block is built.
|
|
570
572
|
const blockBuilderOptions: PublicProcessorLimits = {
|
|
571
573
|
maxTransactions: this.config.maxTxsPerBlock,
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
574
|
+
maxBlockGas:
|
|
575
|
+
this.config.maxL2BlockGas !== undefined || this.config.maxDABlockGas !== undefined
|
|
576
|
+
? new Gas(this.config.maxDABlockGas ?? Infinity, this.config.maxL2BlockGas ?? Infinity)
|
|
577
|
+
: undefined,
|
|
575
578
|
deadline: buildDeadline,
|
|
579
|
+
isBuildingProposal: true,
|
|
576
580
|
};
|
|
577
581
|
|
|
578
582
|
// Actually build the block by executing txs
|
|
@@ -602,7 +606,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
602
606
|
}
|
|
603
607
|
|
|
604
608
|
// Block creation succeeded, emit stats and metrics
|
|
605
|
-
const {
|
|
609
|
+
const { block, publicProcessorDuration, usedTxs, blockBuildDuration } = buildResult;
|
|
606
610
|
|
|
607
611
|
const blockStats = {
|
|
608
612
|
eventName: 'l2-block-built',
|
|
@@ -613,7 +617,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
613
617
|
|
|
614
618
|
const blockHash = await block.hash();
|
|
615
619
|
const txHashes = block.body.txEffects.map(tx => tx.txHash);
|
|
616
|
-
const manaPerSec =
|
|
620
|
+
const manaPerSec = block.header.totalManaUsed.toNumberUnsafe() / (blockBuildDuration / 1000);
|
|
617
621
|
|
|
618
622
|
this.log.info(
|
|
619
623
|
`Built block ${block.number} at checkpoint ${this.checkpointNumber} for slot ${this.slot} with ${numTxs} txs`,
|
|
@@ -621,9 +625,9 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
621
625
|
);
|
|
622
626
|
|
|
623
627
|
this.eventEmitter.emit('block-proposed', { blockNumber: block.number, slot: this.slot });
|
|
624
|
-
this.metrics.recordBuiltBlock(blockBuildDuration,
|
|
628
|
+
this.metrics.recordBuiltBlock(blockBuildDuration, block.header.totalManaUsed.toNumberUnsafe());
|
|
625
629
|
|
|
626
|
-
return { block, usedTxs
|
|
630
|
+
return { block, usedTxs };
|
|
627
631
|
} catch (err: any) {
|
|
628
632
|
this.eventEmitter.emit('block-build-failed', { reason: err.message, slot: this.slot });
|
|
629
633
|
this.log.error(`Error building block`, err, { blockNumber, slot: this.slot });
|
|
@@ -759,7 +763,12 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
759
763
|
const sorted = orderAttestations(trimmed, committee);
|
|
760
764
|
|
|
761
765
|
// Manipulate the attestations if we've been configured to do so
|
|
762
|
-
if (
|
|
766
|
+
if (
|
|
767
|
+
this.config.injectFakeAttestation ||
|
|
768
|
+
this.config.injectHighSValueAttestation ||
|
|
769
|
+
this.config.injectUnrecoverableSignatureAttestation ||
|
|
770
|
+
this.config.shuffleAttestationOrdering
|
|
771
|
+
) {
|
|
763
772
|
return this.manipulateAttestations(proposal.slotNumber, epoch, seed, committee, sorted);
|
|
764
773
|
}
|
|
765
774
|
|
|
@@ -788,7 +797,11 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
788
797
|
this.epochCache.computeProposerIndex(slotNumber, epoch, seed, BigInt(committee.length)),
|
|
789
798
|
);
|
|
790
799
|
|
|
791
|
-
if (
|
|
800
|
+
if (
|
|
801
|
+
this.config.injectFakeAttestation ||
|
|
802
|
+
this.config.injectHighSValueAttestation ||
|
|
803
|
+
this.config.injectUnrecoverableSignatureAttestation
|
|
804
|
+
) {
|
|
792
805
|
// Find non-empty attestations that are not from the proposer
|
|
793
806
|
const nonProposerIndices: number[] = [];
|
|
794
807
|
for (let i = 0; i < attestations.length; i++) {
|
|
@@ -798,8 +811,20 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
798
811
|
}
|
|
799
812
|
if (nonProposerIndices.length > 0) {
|
|
800
813
|
const targetIndex = nonProposerIndices[randomInt(nonProposerIndices.length)];
|
|
801
|
-
this.
|
|
802
|
-
|
|
814
|
+
if (this.config.injectHighSValueAttestation) {
|
|
815
|
+
this.log.warn(
|
|
816
|
+
`Injecting high-s value attestation in checkpoint for slot ${slotNumber} at index ${targetIndex}`,
|
|
817
|
+
);
|
|
818
|
+
unfreeze(attestations[targetIndex]).signature = flipSignature(attestations[targetIndex].signature);
|
|
819
|
+
} else if (this.config.injectUnrecoverableSignatureAttestation) {
|
|
820
|
+
this.log.warn(
|
|
821
|
+
`Injecting unrecoverable signature attestation in checkpoint for slot ${slotNumber} at index ${targetIndex}`,
|
|
822
|
+
);
|
|
823
|
+
unfreeze(attestations[targetIndex]).signature = generateUnrecoverableSignature();
|
|
824
|
+
} else {
|
|
825
|
+
this.log.warn(`Injecting fake attestation in checkpoint for slot ${slotNumber} at index ${targetIndex}`);
|
|
826
|
+
unfreeze(attestations[targetIndex]).signature = generateRecoverableSignature();
|
|
827
|
+
}
|
|
803
828
|
}
|
|
804
829
|
return new CommitteeAttestationsAndSigners(attestations);
|
|
805
830
|
}
|
|
@@ -808,11 +833,20 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
808
833
|
this.log.warn(`Shuffling attestation ordering in checkpoint for slot ${slotNumber} (proposer #${proposerIndex})`);
|
|
809
834
|
|
|
810
835
|
const shuffled = [...attestations];
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
836
|
+
|
|
837
|
+
// Find two non-proposer positions that both have non-empty signatures to swap.
|
|
838
|
+
// This ensures the bitmap doesn't change, so the MaliciousCommitteeAttestationsAndSigners
|
|
839
|
+
// signers array stays correctly aligned with L1's committee reconstruction.
|
|
840
|
+
const swappable: number[] = [];
|
|
841
|
+
for (let k = 0; k < shuffled.length; k++) {
|
|
842
|
+
if (!shuffled[k].signature.isEmpty() && k !== proposerIndex) {
|
|
843
|
+
swappable.push(k);
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
if (swappable.length >= 2) {
|
|
847
|
+
const [i, j] = [swappable[0], swappable[1]];
|
|
848
|
+
[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
|
|
849
|
+
}
|
|
816
850
|
|
|
817
851
|
const signers = new CommitteeAttestationsAndSigners(attestations).getSigners();
|
|
818
852
|
return new MaliciousCommitteeAttestationsAndSigners(shuffled, signers);
|
|
@@ -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
|
{
|
|
@@ -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
|
@@ -3,4 +3,7 @@ import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
|
3
3
|
export type SequencerRollupConstants = Pick<
|
|
4
4
|
L1RollupConstants,
|
|
5
5
|
'ethereumSlotDuration' | 'l1GenesisTime' | 'slotDuration'
|
|
6
|
-
|
|
6
|
+
> & {
|
|
7
|
+
/** Total L2 gas (mana) allowed per checkpoint. Fetched from L1 getManaLimit(). */
|
|
8
|
+
rollupManaLimit: number;
|
|
9
|
+
};
|
|
@@ -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);
|