@aztec/archiver 0.0.1-commit.d431d1c → 0.0.1-commit.d6f2b3f94

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 (75) hide show
  1. package/README.md +9 -0
  2. package/dest/archiver.d.ts +6 -5
  3. package/dest/archiver.d.ts.map +1 -1
  4. package/dest/archiver.js +34 -22
  5. package/dest/errors.d.ts +6 -1
  6. package/dest/errors.d.ts.map +1 -1
  7. package/dest/errors.js +8 -0
  8. package/dest/factory.d.ts +5 -2
  9. package/dest/factory.d.ts.map +1 -1
  10. package/dest/factory.js +11 -8
  11. package/dest/l1/bin/retrieve-calldata.js +17 -18
  12. package/dest/l1/data_retrieval.d.ts +1 -1
  13. package/dest/l1/data_retrieval.d.ts.map +1 -1
  14. package/dest/l1/data_retrieval.js +3 -3
  15. package/dest/l1/validate_trace.d.ts +6 -3
  16. package/dest/l1/validate_trace.d.ts.map +1 -1
  17. package/dest/l1/validate_trace.js +13 -9
  18. package/dest/modules/data_source_base.d.ts +17 -18
  19. package/dest/modules/data_source_base.d.ts.map +1 -1
  20. package/dest/modules/data_source_base.js +21 -52
  21. package/dest/modules/data_store_updater.d.ts +23 -19
  22. package/dest/modules/data_store_updater.d.ts.map +1 -1
  23. package/dest/modules/data_store_updater.js +47 -49
  24. package/dest/modules/instrumentation.d.ts +3 -3
  25. package/dest/modules/instrumentation.d.ts.map +1 -1
  26. package/dest/modules/instrumentation.js +17 -10
  27. package/dest/modules/l1_synchronizer.d.ts +1 -1
  28. package/dest/modules/l1_synchronizer.d.ts.map +1 -1
  29. package/dest/modules/l1_synchronizer.js +9 -10
  30. package/dest/store/block_store.d.ts +35 -21
  31. package/dest/store/block_store.d.ts.map +1 -1
  32. package/dest/store/block_store.js +81 -40
  33. package/dest/store/contract_class_store.d.ts +1 -1
  34. package/dest/store/contract_class_store.d.ts.map +1 -1
  35. package/dest/store/contract_class_store.js +11 -7
  36. package/dest/store/kv_archiver_store.d.ts +28 -24
  37. package/dest/store/kv_archiver_store.d.ts.map +1 -1
  38. package/dest/store/kv_archiver_store.js +20 -17
  39. package/dest/store/log_store.d.ts +4 -4
  40. package/dest/store/log_store.d.ts.map +1 -1
  41. package/dest/store/log_store.js +57 -37
  42. package/dest/test/fake_l1_state.d.ts +4 -4
  43. package/dest/test/fake_l1_state.d.ts.map +1 -1
  44. package/dest/test/index.js +3 -1
  45. package/dest/test/mock_archiver.js +1 -1
  46. package/dest/test/mock_l2_block_source.d.ts +20 -20
  47. package/dest/test/mock_l2_block_source.d.ts.map +1 -1
  48. package/dest/test/mock_l2_block_source.js +40 -41
  49. package/dest/test/mock_structs.d.ts +3 -2
  50. package/dest/test/mock_structs.d.ts.map +1 -1
  51. package/dest/test/mock_structs.js +11 -9
  52. package/dest/test/noop_l1_archiver.d.ts +23 -0
  53. package/dest/test/noop_l1_archiver.d.ts.map +1 -0
  54. package/dest/test/noop_l1_archiver.js +68 -0
  55. package/package.json +14 -13
  56. package/src/archiver.ts +46 -28
  57. package/src/errors.ts +12 -0
  58. package/src/factory.ts +23 -13
  59. package/src/l1/bin/retrieve-calldata.ts +16 -17
  60. package/src/l1/data_retrieval.ts +4 -4
  61. package/src/l1/validate_trace.ts +24 -6
  62. package/src/modules/data_source_base.ts +26 -77
  63. package/src/modules/data_store_updater.ts +59 -55
  64. package/src/modules/instrumentation.ts +17 -12
  65. package/src/modules/l1_synchronizer.ts +11 -12
  66. package/src/store/block_store.ts +107 -60
  67. package/src/store/contract_class_store.ts +11 -7
  68. package/src/store/kv_archiver_store.ts +36 -28
  69. package/src/store/log_store.ts +105 -43
  70. package/src/test/fake_l1_state.ts +2 -2
  71. package/src/test/index.ts +3 -0
  72. package/src/test/mock_archiver.ts +1 -1
  73. package/src/test/mock_l2_block_source.ts +54 -64
  74. package/src/test/mock_structs.ts +26 -10
  75. package/src/test/noop_l1_archiver.ts +109 -0
@@ -12,7 +12,7 @@ import type { Secp256k1Signer } from '@aztec/foundation/crypto/secp256k1-signer'
12
12
  import { Fr } from '@aztec/foundation/curves/bn254';
13
13
  import { EthAddress } from '@aztec/foundation/eth-address';
14
14
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
15
- import { CommitteeAttestation, L2BlockNew } from '@aztec/stdlib/block';
15
+ import { CommitteeAttestation, L2Block } from '@aztec/stdlib/block';
16
16
  import { Checkpoint, L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
17
17
  import { PrivateLog, PublicLog, SiloedTag, Tag } from '@aztec/stdlib/logs';
18
18
  import { InboxLeaf } from '@aztec/stdlib/messaging';
@@ -46,24 +46,40 @@ export function makeInboxMessage(
46
46
  }
47
47
 
48
48
  export function makeInboxMessages(
49
- count: number,
49
+ totalCount: number,
50
50
  opts: {
51
51
  initialHash?: Buffer16;
52
52
  initialCheckpointNumber?: CheckpointNumber;
53
+ messagesPerCheckpoint?: number;
53
54
  overrideFn?: (msg: InboxMessage, index: number) => InboxMessage;
54
55
  } = {},
55
56
  ): InboxMessage[] {
56
- const { initialHash = Buffer16.ZERO, overrideFn = msg => msg, initialCheckpointNumber = 1 } = opts;
57
+ const {
58
+ initialHash = Buffer16.ZERO,
59
+ overrideFn = msg => msg,
60
+ initialCheckpointNumber = CheckpointNumber(1),
61
+ messagesPerCheckpoint = 1,
62
+ } = opts;
63
+
57
64
  const messages: InboxMessage[] = [];
58
65
  let rollingHash = initialHash;
59
- for (let i = 0; i < count; i++) {
66
+ for (let i = 0; i < totalCount; i++) {
67
+ const msgIndex = i % messagesPerCheckpoint;
68
+ const checkpointNumber = CheckpointNumber.fromBigInt(
69
+ BigInt(initialCheckpointNumber) + BigInt(i) / BigInt(messagesPerCheckpoint),
70
+ );
60
71
  const leaf = Fr.random();
61
- const checkpointNumber = CheckpointNumber(i + initialCheckpointNumber);
62
- const message = overrideFn(makeInboxMessage(rollingHash, { leaf, checkpointNumber }), i);
72
+ const message = overrideFn(
73
+ makeInboxMessage(rollingHash, {
74
+ leaf,
75
+ checkpointNumber,
76
+ index: InboxLeaf.smallestIndexForCheckpoint(checkpointNumber) + BigInt(msgIndex),
77
+ }),
78
+ i,
79
+ );
63
80
  rollingHash = message.rollingHash;
64
81
  messages.push(message);
65
82
  }
66
-
67
83
  return messages;
68
84
  }
69
85
 
@@ -268,8 +284,8 @@ export async function makeCheckpointWithLogs(
268
284
  ): Promise<PublishedCheckpoint> {
269
285
  const { previousArchive, numTxsPerBlock = 4, privateLogs, publicLogs } = options;
270
286
 
271
- const block = await L2BlockNew.random(BlockNumber(blockNumber), {
272
- checkpointNumber: CheckpointNumber(blockNumber),
287
+ const block = await L2Block.random(BlockNumber(blockNumber), {
288
+ checkpointNumber: CheckpointNumber.fromBlockNumber(BlockNumber(blockNumber)),
273
289
  indexWithinCheckpoint: IndexWithinCheckpoint(0),
274
290
  state: makeStateForBlock(blockNumber, numTxsPerBlock),
275
291
  ...(previousArchive ? { lastArchive: previousArchive } : {}),
@@ -289,7 +305,7 @@ export async function makeCheckpointWithLogs(
289
305
  AppendOnlyTreeSnapshot.random(),
290
306
  CheckpointHeader.random(),
291
307
  [block],
292
- CheckpointNumber(blockNumber),
308
+ CheckpointNumber.fromBlockNumber(BlockNumber(blockNumber)),
293
309
  );
294
310
  return makePublishedCheckpoint(checkpoint, blockNumber);
295
311
  }
@@ -0,0 +1,109 @@
1
+ import type { BlobClientInterface } from '@aztec/blob-client/client';
2
+ import type { RollupContract } from '@aztec/ethereum/contracts';
3
+ import type { ViemPublicClient, ViemPublicDebugClient } from '@aztec/ethereum/types';
4
+ import { Buffer32 } from '@aztec/foundation/buffer';
5
+ import { Fr } from '@aztec/foundation/curves/bn254';
6
+ import { EthAddress } from '@aztec/foundation/eth-address';
7
+ import type { FunctionsOf } from '@aztec/foundation/types';
8
+ import type { ArchiverEmitter } from '@aztec/stdlib/block';
9
+ import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
10
+ import { type TelemetryClient, type Tracer, getTelemetryClient } from '@aztec/telemetry-client';
11
+
12
+ import { mock } from 'jest-mock-extended';
13
+ import { EventEmitter } from 'node:events';
14
+
15
+ import { Archiver } from '../archiver.js';
16
+ import { ArchiverInstrumentation } from '../modules/instrumentation.js';
17
+ import type { ArchiverL1Synchronizer } from '../modules/l1_synchronizer.js';
18
+ import type { KVArchiverDataStore } from '../store/kv_archiver_store.js';
19
+
20
+ /** Noop L1 synchronizer for testing without L1 connectivity. */
21
+ class NoopL1Synchronizer implements FunctionsOf<ArchiverL1Synchronizer> {
22
+ public readonly tracer: Tracer;
23
+
24
+ constructor(tracer: Tracer) {
25
+ this.tracer = tracer;
26
+ }
27
+
28
+ setConfig(_config: unknown) {}
29
+ getL1BlockNumber(): bigint | undefined {
30
+ return 0n;
31
+ }
32
+ getL1Timestamp(): bigint | undefined {
33
+ return 0n;
34
+ }
35
+ testEthereumNodeSynced(): Promise<void> {
36
+ return Promise.resolve();
37
+ }
38
+ syncFromL1(_initialSyncComplete: boolean): Promise<void> {
39
+ return Promise.resolve();
40
+ }
41
+ }
42
+
43
+ /**
44
+ * Archiver with mocked L1 connectivity for testing.
45
+ * Uses mock L1 clients and a noop synchronizer, enabling tests that
46
+ * don't require real Ethereum connectivity.
47
+ */
48
+ export class NoopL1Archiver extends Archiver {
49
+ constructor(
50
+ dataStore: KVArchiverDataStore,
51
+ l1Constants: L1RollupConstants & { genesisArchiveRoot: Fr },
52
+ instrumentation: ArchiverInstrumentation,
53
+ ) {
54
+ // Create mocks for L1 clients
55
+ const publicClient = mock<ViemPublicClient>();
56
+ const debugClient = mock<ViemPublicDebugClient>();
57
+ const rollup = mock<RollupContract>();
58
+ const blobClient = mock<BlobClientInterface>();
59
+
60
+ // Mock methods called during start()
61
+ blobClient.testSources.mockResolvedValue();
62
+ publicClient.getBlockNumber.mockResolvedValue(1n);
63
+
64
+ const events = new EventEmitter() as ArchiverEmitter;
65
+ const synchronizer = new NoopL1Synchronizer(instrumentation.tracer);
66
+
67
+ super(
68
+ publicClient,
69
+ debugClient,
70
+ rollup,
71
+ {
72
+ registryAddress: EthAddress.ZERO,
73
+ governanceProposerAddress: EthAddress.ZERO,
74
+ slashFactoryAddress: EthAddress.ZERO,
75
+ slashingProposerAddress: EthAddress.ZERO,
76
+ },
77
+ dataStore,
78
+ {
79
+ pollingIntervalMs: 1000,
80
+ batchSize: 100,
81
+ skipValidateCheckpointAttestations: true,
82
+ maxAllowedEthClientDriftSeconds: 300,
83
+ ethereumAllowNoDebugHosts: true, // Skip trace validation
84
+ },
85
+ blobClient,
86
+ instrumentation,
87
+ { ...l1Constants, l1StartBlockHash: Buffer32.random() },
88
+ synchronizer as ArchiverL1Synchronizer,
89
+ events,
90
+ );
91
+ }
92
+
93
+ /** Override start to skip L1 validation checks. */
94
+ public override start(_blockUntilSynced?: boolean): Promise<void> {
95
+ // Just start the running promise without L1 checks
96
+ this.runningPromise.start();
97
+ return Promise.resolve();
98
+ }
99
+ }
100
+
101
+ /** Creates an archiver with mocked L1 connectivity for testing. */
102
+ export async function createNoopL1Archiver(
103
+ dataStore: KVArchiverDataStore,
104
+ l1Constants: L1RollupConstants & { genesisArchiveRoot: Fr },
105
+ telemetry: TelemetryClient = getTelemetryClient(),
106
+ ): Promise<NoopL1Archiver> {
107
+ const instrumentation = await ArchiverInstrumentation.new(telemetry, () => dataStore.estimateSize());
108
+ return new NoopL1Archiver(dataStore, l1Constants, instrumentation);
109
+ }