@aztec/archiver 0.0.1-commit.358457c → 0.0.1-commit.381b1a9

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.
Files changed (55) hide show
  1. package/dest/archiver.d.ts +3 -3
  2. package/dest/archiver.d.ts.map +1 -1
  3. package/dest/archiver.js +49 -18
  4. package/dest/factory.d.ts +2 -3
  5. package/dest/factory.d.ts.map +1 -1
  6. package/dest/factory.js +8 -8
  7. package/dest/modules/data_source_base.d.ts +3 -3
  8. package/dest/modules/data_source_base.d.ts.map +1 -1
  9. package/dest/modules/data_source_base.js +1 -1
  10. package/dest/modules/data_store_updater.d.ts +11 -3
  11. package/dest/modules/data_store_updater.d.ts.map +1 -1
  12. package/dest/modules/data_store_updater.js +36 -5
  13. package/dest/modules/instrumentation.d.ts +1 -12
  14. package/dest/modules/instrumentation.d.ts.map +1 -1
  15. package/dest/modules/instrumentation.js +0 -10
  16. package/dest/modules/l1_synchronizer.d.ts +2 -1
  17. package/dest/modules/l1_synchronizer.d.ts.map +1 -1
  18. package/dest/modules/l1_synchronizer.js +31 -9
  19. package/dest/store/block_store.d.ts +8 -9
  20. package/dest/store/block_store.d.ts.map +1 -1
  21. package/dest/store/block_store.js +31 -13
  22. package/dest/store/kv_archiver_store.d.ts +13 -3
  23. package/dest/store/kv_archiver_store.d.ts.map +1 -1
  24. package/dest/store/kv_archiver_store.js +16 -4
  25. package/dest/store/log_store.d.ts +1 -1
  26. package/dest/store/log_store.d.ts.map +1 -1
  27. package/dest/store/log_store.js +48 -10
  28. package/dest/store/message_store.js +1 -1
  29. package/dest/test/fake_l1_state.d.ts +8 -1
  30. package/dest/test/fake_l1_state.d.ts.map +1 -1
  31. package/dest/test/fake_l1_state.js +28 -2
  32. package/dest/test/mock_l2_block_source.d.ts +4 -3
  33. package/dest/test/mock_l2_block_source.d.ts.map +1 -1
  34. package/dest/test/mock_l2_block_source.js +7 -4
  35. package/dest/test/mock_structs.d.ts +4 -1
  36. package/dest/test/mock_structs.d.ts.map +1 -1
  37. package/dest/test/mock_structs.js +13 -1
  38. package/dest/test/noop_l1_archiver.d.ts +4 -1
  39. package/dest/test/noop_l1_archiver.d.ts.map +1 -1
  40. package/dest/test/noop_l1_archiver.js +5 -1
  41. package/package.json +13 -13
  42. package/src/archiver.ts +59 -20
  43. package/src/factory.ts +5 -4
  44. package/src/modules/data_source_base.ts +3 -3
  45. package/src/modules/data_store_updater.ts +39 -4
  46. package/src/modules/instrumentation.ts +0 -20
  47. package/src/modules/l1_synchronizer.ts +38 -11
  48. package/src/store/block_store.ts +41 -13
  49. package/src/store/kv_archiver_store.ts +22 -4
  50. package/src/store/log_store.ts +66 -12
  51. package/src/store/message_store.ts +1 -1
  52. package/src/test/fake_l1_state.ts +35 -4
  53. package/src/test/mock_l2_block_source.ts +15 -3
  54. package/src/test/mock_structs.ts +20 -6
  55. package/src/test/noop_l1_archiver.ts +7 -1
@@ -150,8 +150,12 @@ export class FakeL1State {
150
150
  // Computed from checkpoints based on L1 block visibility
151
151
  private pendingCheckpointNumber: CheckpointNumber = CheckpointNumber(0);
152
152
 
153
+ // The L1 block number reported as "finalized" (defaults to the start block)
154
+ private finalizedL1BlockNumber: bigint;
155
+
153
156
  constructor(private readonly config: FakeL1StateConfig) {
154
157
  this.l1BlockNumber = config.l1StartBlock;
158
+ this.finalizedL1BlockNumber = config.l1StartBlock;
155
159
  this.lastArchive = new AppendOnlyTreeSnapshot(config.genesisArchiveRoot, 1);
156
160
  }
157
161
 
@@ -283,11 +287,30 @@ export class FakeL1State {
283
287
  this.updatePendingCheckpointNumber();
284
288
  }
285
289
 
290
+ /** Sets the L1 block number that will be reported as "finalized". */
291
+ setFinalizedL1BlockNumber(blockNumber: bigint): void {
292
+ this.finalizedL1BlockNumber = blockNumber;
293
+ }
294
+
286
295
  /** Marks a checkpoint as proven. Updates provenCheckpointNumber. */
287
296
  markCheckpointAsProven(checkpointNumber: CheckpointNumber): void {
288
297
  this.provenCheckpointNumber = checkpointNumber;
289
298
  }
290
299
 
300
+ /**
301
+ * Simulates what `rollup.getProvenCheckpointNumber({ blockNumber: atL1Block })` would return.
302
+ */
303
+ getProvenCheckpointNumberAtL1Block(atL1Block: bigint): CheckpointNumber {
304
+ if (this.provenCheckpointNumber === 0) {
305
+ return CheckpointNumber(0);
306
+ }
307
+ const checkpoint = this.checkpoints.find(cp => cp.checkpointNumber === this.provenCheckpointNumber);
308
+ if (checkpoint && checkpoint.l1BlockNumber <= atL1Block) {
309
+ return this.provenCheckpointNumber;
310
+ }
311
+ return CheckpointNumber(0);
312
+ }
313
+
291
314
  /** Sets the target committee size for attestation validation. */
292
315
  setTargetCommitteeSize(size: number): void {
293
316
  this.targetCommitteeSize = size;
@@ -406,6 +429,11 @@ export class FakeL1State {
406
429
  });
407
430
  });
408
431
 
432
+ mockRollup.getProvenCheckpointNumber.mockImplementation((options?: { blockNumber?: bigint }) => {
433
+ const atBlock = options?.blockNumber ?? this.l1BlockNumber;
434
+ return Promise.resolve(this.getProvenCheckpointNumberAtL1Block(atBlock));
435
+ });
436
+
409
437
  mockRollup.canPruneAtTime.mockImplementation(() => Promise.resolve(this.canPruneResult));
410
438
 
411
439
  // Mock the wrapper method for fetching checkpoint events
@@ -449,10 +477,13 @@ export class FakeL1State {
449
477
  publicClient.getChainId.mockResolvedValue(1);
450
478
  publicClient.getBlockNumber.mockImplementation(() => Promise.resolve(this.l1BlockNumber));
451
479
 
452
- // Use async function pattern that existing test uses for getBlock
453
-
454
- publicClient.getBlock.mockImplementation((async (args: { blockNumber?: bigint } = {}) => {
455
- const blockNum = args.blockNumber ?? (await publicClient.getBlockNumber());
480
+ publicClient.getBlock.mockImplementation((async (args: { blockNumber?: bigint; blockTag?: string } = {}) => {
481
+ let blockNum: bigint;
482
+ if (args.blockTag === 'finalized') {
483
+ blockNum = this.finalizedL1BlockNumber;
484
+ } else {
485
+ blockNum = args.blockNumber ?? (await publicClient.getBlockNumber());
486
+ }
456
487
  return {
457
488
  number: blockNum,
458
489
  timestamp: BigInt(blockNum) * BigInt(this.config.ethereumSlotDuration) + this.config.l1GenesisTime,
@@ -18,7 +18,12 @@ import {
18
18
  } from '@aztec/stdlib/block';
19
19
  import { Checkpoint, type CheckpointData, L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
20
20
  import type { ContractClassPublic, ContractDataSource, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
21
- import { EmptyL1RollupConstants, type L1RollupConstants, getSlotRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
21
+ import {
22
+ EmptyL1RollupConstants,
23
+ type L1RollupConstants,
24
+ getEpochAtSlot,
25
+ getSlotRangeForEpoch,
26
+ } from '@aztec/stdlib/epoch-helpers';
22
27
  import { computeCheckpointOutHash } from '@aztec/stdlib/messaging';
23
28
  import { CheckpointHeader } from '@aztec/stdlib/rollup';
24
29
  import { type BlockHeader, TxExecutionResult, TxHash, TxReceipt, TxStatus } from '@aztec/stdlib/tx';
@@ -42,6 +47,12 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
42
47
  await this.createCheckpoints(numBlocks, 1);
43
48
  }
44
49
 
50
+ public getCheckpointNumber(): Promise<CheckpointNumber> {
51
+ return Promise.resolve(
52
+ this.checkpointList.length === 0 ? CheckpointNumber.ZERO : CheckpointNumber(this.checkpointList.length),
53
+ );
54
+ }
55
+
45
56
  /** Creates checkpoints, each containing `blocksPerCheckpoint` blocks. */
46
57
  public async createCheckpoints(numCheckpoints: number, blocksPerCheckpoint: number = 1) {
47
58
  for (let c = 0; c < numCheckpoints; c++) {
@@ -388,6 +399,7 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
388
399
  txEffect.transactionFee.toBigInt(),
389
400
  await block.hash(),
390
401
  block.number,
402
+ getEpochAtSlot(block.slot, EmptyL1RollupConstants),
391
403
  );
392
404
  }
393
405
  }
@@ -441,11 +453,11 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
441
453
  };
442
454
  }
443
455
 
444
- getL2EpochNumber(): Promise<EpochNumber> {
456
+ getSyncedL2EpochNumber(): Promise<EpochNumber> {
445
457
  throw new Error('Method not implemented.');
446
458
  }
447
459
 
448
- getL2SlotNumber(): Promise<SlotNumber> {
460
+ getSyncedL2SlotNumber(): Promise<SlotNumber> {
449
461
  throw new Error('Method not implemented.');
450
462
  }
451
463
 
@@ -127,6 +127,25 @@ export function makeL1PublishedData(l1BlockNumber: number): L1PublishedData {
127
127
  return new L1PublishedData(BigInt(l1BlockNumber), BigInt(l1BlockNumber * 1000), makeBlockHash(l1BlockNumber));
128
128
  }
129
129
 
130
+ /** Creates a Checkpoint from a list of blocks with a header that matches the blocks' structure. */
131
+ export function makeCheckpoint(blocks: L2Block[], checkpointNumber = CheckpointNumber(1)): Checkpoint {
132
+ const firstBlock = blocks[0];
133
+ const { slotNumber, timestamp, coinbase, feeRecipient, gasFees } = firstBlock.header.globalVariables;
134
+ return new Checkpoint(
135
+ blocks.at(-1)!.archive,
136
+ CheckpointHeader.random({
137
+ lastArchiveRoot: firstBlock.header.lastArchive.root,
138
+ slotNumber,
139
+ timestamp,
140
+ coinbase,
141
+ feeRecipient,
142
+ gasFees,
143
+ }),
144
+ blocks,
145
+ checkpointNumber,
146
+ );
147
+ }
148
+
130
149
  /** Wraps a Checkpoint with L1 published data and random attestations. */
131
150
  export function makePublishedCheckpoint(
132
151
  checkpoint: Checkpoint,
@@ -301,11 +320,6 @@ export async function makeCheckpointWithLogs(
301
320
  return txEffect;
302
321
  });
303
322
 
304
- const checkpoint = new Checkpoint(
305
- AppendOnlyTreeSnapshot.random(),
306
- CheckpointHeader.random(),
307
- [block],
308
- CheckpointNumber.fromBlockNumber(BlockNumber(blockNumber)),
309
- );
323
+ const checkpoint = makeCheckpoint([block], CheckpointNumber.fromBlockNumber(BlockNumber(blockNumber)));
310
324
  return makePublishedCheckpoint(checkpoint, blockNumber);
311
325
  }
@@ -1,6 +1,7 @@
1
1
  import type { BlobClientInterface } from '@aztec/blob-client/client';
2
2
  import type { RollupContract } from '@aztec/ethereum/contracts';
3
3
  import type { ViemPublicClient, ViemPublicDebugClient } from '@aztec/ethereum/types';
4
+ import { SlotNumber } from '@aztec/foundation/branded-types';
4
5
  import { Buffer32 } from '@aztec/foundation/buffer';
5
6
  import { Fr } from '@aztec/foundation/curves/bn254';
6
7
  import { EthAddress } from '@aztec/foundation/eth-address';
@@ -30,7 +31,7 @@ class NoopL1Synchronizer implements FunctionsOf<ArchiverL1Synchronizer> {
30
31
  return 0n;
31
32
  }
32
33
  getL1Timestamp(): bigint | undefined {
33
- return 0n;
34
+ return undefined;
34
35
  }
35
36
  testEthereumNodeSynced(): Promise<void> {
36
37
  return Promise.resolve();
@@ -96,6 +97,11 @@ export class NoopL1Archiver extends Archiver {
96
97
  this.runningPromise.start();
97
98
  return Promise.resolve();
98
99
  }
100
+
101
+ /** Always reports as fully synced since there is no real L1 to sync from. */
102
+ public override getSyncedL2SlotNumber(): Promise<SlotNumber | undefined> {
103
+ return Promise.resolve(SlotNumber(Number.MAX_SAFE_INTEGER));
104
+ }
99
105
  }
100
106
 
101
107
  /** Creates an archiver with mocked L1 connectivity for testing. */