@aztec/archiver 0.0.1-commit.f5d02921e → 0.0.1-commit.f650c0a5c
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 -3
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +3 -3
- package/dest/l1/data_retrieval.d.ts +3 -3
- package/dest/l1/data_retrieval.d.ts.map +1 -1
- package/dest/l1/data_retrieval.js +14 -15
- 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 +105 -105
- package/dest/store/block_store.d.ts +2 -1
- package/dest/store/block_store.d.ts.map +1 -1
- package/dest/store/block_store.js +47 -3
- package/dest/store/kv_archiver_store.d.ts +3 -7
- package/dest/store/kv_archiver_store.d.ts.map +1 -1
- package/dest/store/kv_archiver_store.js +2 -7
- 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 +9 -1
- package/dest/test/fake_l1_state.d.ts.map +1 -1
- package/dest/test/fake_l1_state.js +41 -6
- package/dest/test/noop_l1_archiver.d.ts +1 -1
- package/dest/test/noop_l1_archiver.d.ts.map +1 -1
- package/dest/test/noop_l1_archiver.js +0 -1
- package/package.json +13 -13
- package/src/archiver.ts +8 -6
- package/src/l1/data_retrieval.ts +8 -12
- package/src/modules/l1_synchronizer.ts +112 -127
- package/src/store/block_store.ts +59 -3
- package/src/store/kv_archiver_store.ts +3 -10
- package/src/store/message_store.ts +10 -12
- package/src/structs/inbox_message.ts +1 -1
- package/src/test/fake_l1_state.ts +56 -7
- package/src/test/noop_l1_archiver.ts +0 -1
|
@@ -332,6 +332,21 @@ export class FakeL1State {
|
|
|
332
332
|
this.updatePendingCheckpointNumber();
|
|
333
333
|
}
|
|
334
334
|
|
|
335
|
+
/**
|
|
336
|
+
* Moves a checkpoint to a different L1 block number (simulates L1 reorg that
|
|
337
|
+
* re-includes the same checkpoint transaction in a different block).
|
|
338
|
+
* The checkpoint content stays the same — only the L1 metadata changes.
|
|
339
|
+
* Auto-updates pending status.
|
|
340
|
+
*/
|
|
341
|
+
moveCheckpointToL1Block(checkpointNumber: CheckpointNumber, newL1BlockNumber: bigint): void {
|
|
342
|
+
for (const cpData of this.checkpoints) {
|
|
343
|
+
if (cpData.checkpointNumber === checkpointNumber) {
|
|
344
|
+
cpData.l1BlockNumber = newL1BlockNumber;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
this.updatePendingCheckpointNumber();
|
|
348
|
+
}
|
|
349
|
+
|
|
335
350
|
/**
|
|
336
351
|
* Removes messages after a given total index (simulates L1 reorg).
|
|
337
352
|
* Auto-updates rolling hash.
|
|
@@ -451,19 +466,33 @@ export class FakeL1State {
|
|
|
451
466
|
createMockInboxContract(_publicClient: MockProxy<ViemPublicClient>): MockProxy<InboxContract> {
|
|
452
467
|
const mockInbox = mock<InboxContract>();
|
|
453
468
|
|
|
454
|
-
mockInbox.getState.mockImplementation(() => {
|
|
469
|
+
mockInbox.getState.mockImplementation((opts: { blockTag?: string; blockNumber?: bigint } = {}) => {
|
|
470
|
+
// Filter messages visible at the given block number (or all if not specified)
|
|
471
|
+
const blockNumber = opts.blockNumber ?? this.l1BlockNumber;
|
|
472
|
+
const visibleMessages = this.messages.filter(m => m.l1BlockNumber <= blockNumber);
|
|
473
|
+
|
|
455
474
|
// treeInProgress must be > any sealed checkpoint. On L1, a checkpoint can only be proposed
|
|
456
475
|
// after its messages are sealed, so treeInProgress > checkpointNumber for all published checkpoints.
|
|
457
476
|
const maxFromMessages =
|
|
458
|
-
|
|
477
|
+
visibleMessages.length > 0 ? Math.max(...visibleMessages.map(m => Number(m.checkpointNumber))) + 1 : 0;
|
|
459
478
|
const maxFromCheckpoints =
|
|
460
479
|
this.checkpoints.length > 0
|
|
461
|
-
? Math.max(
|
|
480
|
+
? Math.max(
|
|
481
|
+
...this.checkpoints
|
|
482
|
+
.filter(cp => !cp.pruned && cp.l1BlockNumber <= blockNumber)
|
|
483
|
+
.map(cp => Number(cp.checkpointNumber)),
|
|
484
|
+
0,
|
|
485
|
+
) + 1
|
|
462
486
|
: 0;
|
|
463
487
|
const treeInProgress = Math.max(maxFromMessages, maxFromCheckpoints, INITIAL_CHECKPOINT_NUMBER);
|
|
488
|
+
|
|
489
|
+
// Compute rolling hash only for visible messages
|
|
490
|
+
const rollingHash =
|
|
491
|
+
visibleMessages.length > 0 ? visibleMessages[visibleMessages.length - 1].rollingHash : Buffer16.ZERO;
|
|
492
|
+
|
|
464
493
|
return Promise.resolve({
|
|
465
|
-
messagesRollingHash:
|
|
466
|
-
totalMessagesInserted: BigInt(
|
|
494
|
+
messagesRollingHash: rollingHash,
|
|
495
|
+
totalMessagesInserted: BigInt(visibleMessages.length),
|
|
467
496
|
treeInProgress: BigInt(treeInProgress),
|
|
468
497
|
});
|
|
469
498
|
});
|
|
@@ -473,8 +502,8 @@ export class FakeL1State {
|
|
|
473
502
|
Promise.resolve(this.getMessageSentLogs(fromBlock, toBlock)),
|
|
474
503
|
);
|
|
475
504
|
|
|
476
|
-
mockInbox.getMessageSentEventByHash.mockImplementation((
|
|
477
|
-
Promise.resolve(this.
|
|
505
|
+
mockInbox.getMessageSentEventByHash.mockImplementation((msgHash: string, l1BlockHash: string) =>
|
|
506
|
+
Promise.resolve(this.getMessageSentLogByHash(msgHash, l1BlockHash) as MessageSentLog),
|
|
478
507
|
);
|
|
479
508
|
|
|
480
509
|
return mockInbox;
|
|
@@ -594,6 +623,26 @@ export class FakeL1State {
|
|
|
594
623
|
}));
|
|
595
624
|
}
|
|
596
625
|
|
|
626
|
+
private getMessageSentLogByHash(msgHash: string, l1BlockHash: string): MessageSentLog | undefined {
|
|
627
|
+
const msg = this.messages.find(
|
|
628
|
+
msg => msg.leaf.toString() === msgHash && Buffer32.fromBigInt(msg.l1BlockNumber).toString() === l1BlockHash,
|
|
629
|
+
);
|
|
630
|
+
if (!msg) {
|
|
631
|
+
return undefined;
|
|
632
|
+
}
|
|
633
|
+
return {
|
|
634
|
+
l1BlockNumber: msg.l1BlockNumber,
|
|
635
|
+
l1BlockHash: Buffer32.fromBigInt(msg.l1BlockNumber),
|
|
636
|
+
l1TransactionHash: `0x${msg.l1BlockNumber.toString(16)}` as `0x${string}`,
|
|
637
|
+
args: {
|
|
638
|
+
checkpointNumber: msg.checkpointNumber,
|
|
639
|
+
index: msg.index,
|
|
640
|
+
leaf: msg.leaf,
|
|
641
|
+
rollingHash: msg.rollingHash,
|
|
642
|
+
},
|
|
643
|
+
};
|
|
644
|
+
}
|
|
645
|
+
|
|
597
646
|
private async makeRollupTx(
|
|
598
647
|
checkpoint: Checkpoint,
|
|
599
648
|
signers: Secp256k1Signer[],
|