@aztec/archiver 0.0.1-commit.3fd054f6 → 0.0.1-commit.42ee6df9b
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/README.md +12 -6
- package/dest/archiver.d.ts +3 -2
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +5 -2
- package/dest/errors.d.ts +14 -2
- package/dest/errors.d.ts.map +1 -1
- package/dest/errors.js +18 -2
- package/dest/l1/calldata_retriever.d.ts +1 -1
- package/dest/l1/calldata_retriever.d.ts.map +1 -1
- package/dest/l1/calldata_retriever.js +2 -1
- package/dest/l1/data_retrieval.d.ts +2 -2
- package/dest/l1/data_retrieval.d.ts.map +1 -1
- package/dest/l1/data_retrieval.js +13 -14
- package/dest/modules/data_source_base.d.ts +4 -2
- package/dest/modules/data_source_base.d.ts.map +1 -1
- package/dest/modules/data_source_base.js +6 -0
- package/dest/modules/data_store_updater.d.ts +3 -2
- package/dest/modules/data_store_updater.d.ts.map +1 -1
- package/dest/modules/data_store_updater.js +9 -0
- package/dest/modules/l1_synchronizer.d.ts +3 -2
- package/dest/modules/l1_synchronizer.d.ts.map +1 -1
- package/dest/modules/l1_synchronizer.js +128 -123
- package/dest/modules/validation.d.ts +1 -1
- package/dest/modules/validation.d.ts.map +1 -1
- package/dest/modules/validation.js +2 -2
- package/dest/store/block_store.d.ts +38 -4
- package/dest/store/block_store.d.ts.map +1 -1
- package/dest/store/block_store.js +185 -60
- package/dest/store/kv_archiver_store.d.ts +21 -8
- package/dest/store/kv_archiver_store.d.ts.map +1 -1
- package/dest/store/kv_archiver_store.js +25 -8
- package/dest/store/l2_tips_cache.d.ts +2 -1
- package/dest/store/l2_tips_cache.d.ts.map +1 -1
- package/dest/store/l2_tips_cache.js +25 -5
- package/dest/store/message_store.d.ts +3 -3
- package/dest/store/message_store.d.ts.map +1 -1
- package/dest/store/message_store.js +9 -10
- package/dest/test/fake_l1_state.d.ts +2 -1
- package/dest/test/fake_l1_state.d.ts.map +1 -1
- package/dest/test/fake_l1_state.js +28 -6
- package/dest/test/mock_l1_to_l2_message_source.d.ts +1 -1
- package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
- package/dest/test/mock_l1_to_l2_message_source.js +2 -1
- package/dest/test/mock_l2_block_source.d.ts +7 -2
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +28 -3
- package/package.json +13 -13
- package/src/archiver.ts +9 -2
- package/src/errors.ts +30 -2
- package/src/l1/calldata_retriever.ts +2 -1
- package/src/l1/data_retrieval.ts +7 -11
- package/src/modules/data_source_base.ts +15 -1
- package/src/modules/data_store_updater.ts +14 -1
- package/src/modules/l1_synchronizer.ts +137 -147
- package/src/modules/validation.ts +2 -2
- package/src/store/block_store.ts +242 -71
- package/src/store/kv_archiver_store.ts +43 -12
- package/src/store/l2_tips_cache.ts +50 -11
- package/src/store/message_store.ts +10 -12
- package/src/structs/inbox_message.ts +1 -1
- package/src/test/fake_l1_state.ts +41 -7
- package/src/test/mock_l1_to_l2_message_source.ts +1 -0
- package/src/test/mock_l2_block_source.ts +37 -2
|
@@ -451,19 +451,33 @@ export class FakeL1State {
|
|
|
451
451
|
createMockInboxContract(_publicClient: MockProxy<ViemPublicClient>): MockProxy<InboxContract> {
|
|
452
452
|
const mockInbox = mock<InboxContract>();
|
|
453
453
|
|
|
454
|
-
mockInbox.getState.mockImplementation(() => {
|
|
454
|
+
mockInbox.getState.mockImplementation((opts: { blockTag?: string; blockNumber?: bigint } = {}) => {
|
|
455
|
+
// Filter messages visible at the given block number (or all if not specified)
|
|
456
|
+
const blockNumber = opts.blockNumber ?? this.l1BlockNumber;
|
|
457
|
+
const visibleMessages = this.messages.filter(m => m.l1BlockNumber <= blockNumber);
|
|
458
|
+
|
|
455
459
|
// treeInProgress must be > any sealed checkpoint. On L1, a checkpoint can only be proposed
|
|
456
460
|
// after its messages are sealed, so treeInProgress > checkpointNumber for all published checkpoints.
|
|
457
461
|
const maxFromMessages =
|
|
458
|
-
|
|
462
|
+
visibleMessages.length > 0 ? Math.max(...visibleMessages.map(m => Number(m.checkpointNumber))) + 1 : 0;
|
|
459
463
|
const maxFromCheckpoints =
|
|
460
464
|
this.checkpoints.length > 0
|
|
461
|
-
? Math.max(
|
|
465
|
+
? Math.max(
|
|
466
|
+
...this.checkpoints
|
|
467
|
+
.filter(cp => !cp.pruned && cp.l1BlockNumber <= blockNumber)
|
|
468
|
+
.map(cp => Number(cp.checkpointNumber)),
|
|
469
|
+
0,
|
|
470
|
+
) + 1
|
|
462
471
|
: 0;
|
|
463
472
|
const treeInProgress = Math.max(maxFromMessages, maxFromCheckpoints, INITIAL_CHECKPOINT_NUMBER);
|
|
473
|
+
|
|
474
|
+
// Compute rolling hash only for visible messages
|
|
475
|
+
const rollingHash =
|
|
476
|
+
visibleMessages.length > 0 ? visibleMessages[visibleMessages.length - 1].rollingHash : Buffer16.ZERO;
|
|
477
|
+
|
|
464
478
|
return Promise.resolve({
|
|
465
|
-
messagesRollingHash:
|
|
466
|
-
totalMessagesInserted: BigInt(
|
|
479
|
+
messagesRollingHash: rollingHash,
|
|
480
|
+
totalMessagesInserted: BigInt(visibleMessages.length),
|
|
467
481
|
treeInProgress: BigInt(treeInProgress),
|
|
468
482
|
});
|
|
469
483
|
});
|
|
@@ -473,8 +487,8 @@ export class FakeL1State {
|
|
|
473
487
|
Promise.resolve(this.getMessageSentLogs(fromBlock, toBlock)),
|
|
474
488
|
);
|
|
475
489
|
|
|
476
|
-
mockInbox.getMessageSentEventByHash.mockImplementation((
|
|
477
|
-
Promise.resolve(this.
|
|
490
|
+
mockInbox.getMessageSentEventByHash.mockImplementation((msgHash: string, l1BlockHash: string) =>
|
|
491
|
+
Promise.resolve(this.getMessageSentLogByHash(msgHash, l1BlockHash) as MessageSentLog),
|
|
478
492
|
);
|
|
479
493
|
|
|
480
494
|
return mockInbox;
|
|
@@ -594,6 +608,26 @@ export class FakeL1State {
|
|
|
594
608
|
}));
|
|
595
609
|
}
|
|
596
610
|
|
|
611
|
+
private getMessageSentLogByHash(msgHash: string, l1BlockHash: string): MessageSentLog | undefined {
|
|
612
|
+
const msg = this.messages.find(
|
|
613
|
+
msg => msg.leaf.toString() === msgHash && Buffer32.fromBigInt(msg.l1BlockNumber).toString() === l1BlockHash,
|
|
614
|
+
);
|
|
615
|
+
if (!msg) {
|
|
616
|
+
return undefined;
|
|
617
|
+
}
|
|
618
|
+
return {
|
|
619
|
+
l1BlockNumber: msg.l1BlockNumber,
|
|
620
|
+
l1BlockHash: Buffer32.fromBigInt(msg.l1BlockNumber),
|
|
621
|
+
l1TransactionHash: `0x${msg.l1BlockNumber.toString(16)}` as `0x${string}`,
|
|
622
|
+
args: {
|
|
623
|
+
checkpointNumber: msg.checkpointNumber,
|
|
624
|
+
index: msg.index,
|
|
625
|
+
leaf: msg.leaf,
|
|
626
|
+
rollingHash: msg.rollingHash,
|
|
627
|
+
},
|
|
628
|
+
};
|
|
629
|
+
}
|
|
630
|
+
|
|
597
631
|
private async makeRollupTx(
|
|
598
632
|
checkpoint: Checkpoint,
|
|
599
633
|
signers: Secp256k1Signer[],
|
|
@@ -16,7 +16,13 @@ import {
|
|
|
16
16
|
type L2Tips,
|
|
17
17
|
type ValidateCheckpointResult,
|
|
18
18
|
} from '@aztec/stdlib/block';
|
|
19
|
-
import {
|
|
19
|
+
import {
|
|
20
|
+
Checkpoint,
|
|
21
|
+
type CheckpointData,
|
|
22
|
+
L1PublishedData,
|
|
23
|
+
type ProposedCheckpointData,
|
|
24
|
+
PublishedCheckpoint,
|
|
25
|
+
} from '@aztec/stdlib/checkpoint';
|
|
20
26
|
import type { ContractClassPublic, ContractDataSource, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
21
27
|
import {
|
|
22
28
|
EmptyL1RollupConstants,
|
|
@@ -39,6 +45,7 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
39
45
|
private provenBlockNumber: number = 0;
|
|
40
46
|
private finalizedBlockNumber: number = 0;
|
|
41
47
|
private checkpointedBlockNumber: number = 0;
|
|
48
|
+
private proposedCheckpointBlockNumber: number = 0;
|
|
42
49
|
|
|
43
50
|
private log = createLogger('archiver:mock_l2_block_source');
|
|
44
51
|
|
|
@@ -89,6 +96,7 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
89
96
|
});
|
|
90
97
|
// Keep tip numbers consistent with remaining blocks.
|
|
91
98
|
this.checkpointedBlockNumber = Math.min(this.checkpointedBlockNumber, maxBlockNum);
|
|
99
|
+
this.proposedCheckpointBlockNumber = Math.min(this.proposedCheckpointBlockNumber, maxBlockNum);
|
|
92
100
|
this.provenBlockNumber = Math.min(this.provenBlockNumber, maxBlockNum);
|
|
93
101
|
this.finalizedBlockNumber = Math.min(this.finalizedBlockNumber, maxBlockNum);
|
|
94
102
|
this.log.verbose(`Removed ${numBlocks} blocks from the mock L2 block source`);
|
|
@@ -105,9 +113,17 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
105
113
|
this.finalizedBlockNumber = finalizedBlockNumber;
|
|
106
114
|
}
|
|
107
115
|
|
|
116
|
+
public setProposedCheckpointBlockNumber(blockNumber: number) {
|
|
117
|
+
this.proposedCheckpointBlockNumber = blockNumber;
|
|
118
|
+
}
|
|
119
|
+
|
|
108
120
|
public setCheckpointedBlockNumber(checkpointedBlockNumber: number) {
|
|
109
121
|
const prevCheckpointed = this.checkpointedBlockNumber;
|
|
110
122
|
this.checkpointedBlockNumber = checkpointedBlockNumber;
|
|
123
|
+
// Proposed checkpoint is always at least as advanced as checkpointed
|
|
124
|
+
if (this.proposedCheckpointBlockNumber < checkpointedBlockNumber) {
|
|
125
|
+
this.proposedCheckpointBlockNumber = checkpointedBlockNumber;
|
|
126
|
+
}
|
|
111
127
|
// Auto-create single-block checkpoints for newly checkpointed blocks that don't have one yet.
|
|
112
128
|
// This handles blocks added via addProposedBlocks that are now being marked as checkpointed.
|
|
113
129
|
const newCheckpoints: Checkpoint[] = [];
|
|
@@ -171,6 +187,10 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
171
187
|
return Promise.resolve(BlockNumber(this.finalizedBlockNumber));
|
|
172
188
|
}
|
|
173
189
|
|
|
190
|
+
public getProposedCheckpointL2BlockNumber() {
|
|
191
|
+
return Promise.resolve(BlockNumber(this.proposedCheckpointBlockNumber));
|
|
192
|
+
}
|
|
193
|
+
|
|
174
194
|
public getCheckpointedBlock(number: BlockNumber): Promise<CheckpointedL2Block | undefined> {
|
|
175
195
|
if (number > this.checkpointedBlockNumber) {
|
|
176
196
|
return Promise.resolve(undefined);
|
|
@@ -408,17 +428,19 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
408
428
|
}
|
|
409
429
|
|
|
410
430
|
async getL2Tips(): Promise<L2Tips> {
|
|
411
|
-
const [latest, proven, finalized, checkpointed] = [
|
|
431
|
+
const [latest, proven, finalized, checkpointed, proposedCheckpoint] = [
|
|
412
432
|
await this.getBlockNumber(),
|
|
413
433
|
await this.getProvenBlockNumber(),
|
|
414
434
|
this.finalizedBlockNumber,
|
|
415
435
|
this.checkpointedBlockNumber,
|
|
436
|
+
await this.getProposedCheckpointL2BlockNumber(),
|
|
416
437
|
] as const;
|
|
417
438
|
|
|
418
439
|
const latestBlock = this.l2Blocks[latest - 1];
|
|
419
440
|
const provenBlock = this.l2Blocks[proven - 1];
|
|
420
441
|
const finalizedBlock = this.l2Blocks[finalized - 1];
|
|
421
442
|
const checkpointedBlock = this.l2Blocks[checkpointed - 1];
|
|
443
|
+
const proposedCheckpointBlock = this.l2Blocks[proposedCheckpoint - 1];
|
|
422
444
|
|
|
423
445
|
const latestBlockId = {
|
|
424
446
|
number: BlockNumber(latest),
|
|
@@ -436,6 +458,10 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
436
458
|
number: BlockNumber(checkpointed),
|
|
437
459
|
hash: (await checkpointedBlock?.hash())?.toString(),
|
|
438
460
|
};
|
|
461
|
+
const proposedCheckpointBlockId = {
|
|
462
|
+
number: BlockNumber(proposedCheckpoint),
|
|
463
|
+
hash: (await proposedCheckpointBlock?.hash())?.toString(),
|
|
464
|
+
};
|
|
439
465
|
|
|
440
466
|
const makeTipId = (blockId: typeof latestBlockId) => ({
|
|
441
467
|
block: blockId,
|
|
@@ -450,6 +476,7 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
450
476
|
checkpointed: makeTipId(checkpointedBlockId),
|
|
451
477
|
proven: makeTipId(provenBlockId),
|
|
452
478
|
finalized: makeTipId(finalizedBlockId),
|
|
479
|
+
proposedCheckpoint: makeTipId(proposedCheckpointBlockId),
|
|
453
480
|
};
|
|
454
481
|
}
|
|
455
482
|
|
|
@@ -531,6 +558,14 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
531
558
|
return Promise.resolve({ valid: true });
|
|
532
559
|
}
|
|
533
560
|
|
|
561
|
+
getProposedCheckpoint(): Promise<ProposedCheckpointData | undefined> {
|
|
562
|
+
return Promise.resolve(undefined);
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
getProposedCheckpointOnly(): Promise<ProposedCheckpointData | undefined> {
|
|
566
|
+
return Promise.resolve(undefined);
|
|
567
|
+
}
|
|
568
|
+
|
|
534
569
|
/** Returns checkpoints whose slot falls within the given epoch. */
|
|
535
570
|
private getCheckpointsInEpoch(epochNumber: EpochNumber): Checkpoint[] {
|
|
536
571
|
const epochDuration = DefaultL1ContractsConfig.aztecEpochDuration;
|