@aztec/archiver 0.0.1-commit.2ed92850 → 0.0.1-commit.343b43af6

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 (96) hide show
  1. package/dest/archiver.d.ts +9 -5
  2. package/dest/archiver.d.ts.map +1 -1
  3. package/dest/archiver.js +76 -111
  4. package/dest/errors.d.ts +7 -9
  5. package/dest/errors.d.ts.map +1 -1
  6. package/dest/errors.js +9 -14
  7. package/dest/factory.d.ts +5 -4
  8. package/dest/factory.d.ts.map +1 -1
  9. package/dest/factory.js +17 -16
  10. package/dest/index.d.ts +2 -1
  11. package/dest/index.d.ts.map +1 -1
  12. package/dest/index.js +1 -0
  13. package/dest/l1/bin/retrieve-calldata.js +36 -33
  14. package/dest/l1/calldata_retriever.d.ts +73 -50
  15. package/dest/l1/calldata_retriever.d.ts.map +1 -1
  16. package/dest/l1/calldata_retriever.js +190 -259
  17. package/dest/l1/data_retrieval.d.ts +9 -9
  18. package/dest/l1/data_retrieval.d.ts.map +1 -1
  19. package/dest/l1/data_retrieval.js +22 -20
  20. package/dest/l1/spire_proposer.d.ts +5 -5
  21. package/dest/l1/spire_proposer.d.ts.map +1 -1
  22. package/dest/l1/spire_proposer.js +9 -17
  23. package/dest/l1/validate_trace.d.ts +6 -3
  24. package/dest/l1/validate_trace.d.ts.map +1 -1
  25. package/dest/l1/validate_trace.js +13 -9
  26. package/dest/modules/data_source_base.d.ts +13 -8
  27. package/dest/modules/data_source_base.d.ts.map +1 -1
  28. package/dest/modules/data_source_base.js +28 -72
  29. package/dest/modules/data_store_updater.d.ts +22 -7
  30. package/dest/modules/data_store_updater.d.ts.map +1 -1
  31. package/dest/modules/data_store_updater.js +69 -29
  32. package/dest/modules/instrumentation.d.ts +15 -2
  33. package/dest/modules/instrumentation.d.ts.map +1 -1
  34. package/dest/modules/instrumentation.js +36 -12
  35. package/dest/modules/l1_synchronizer.d.ts +5 -8
  36. package/dest/modules/l1_synchronizer.d.ts.map +1 -1
  37. package/dest/modules/l1_synchronizer.js +43 -13
  38. package/dest/store/block_store.d.ts +30 -28
  39. package/dest/store/block_store.d.ts.map +1 -1
  40. package/dest/store/block_store.js +125 -76
  41. package/dest/store/contract_class_store.d.ts +1 -1
  42. package/dest/store/contract_class_store.d.ts.map +1 -1
  43. package/dest/store/contract_class_store.js +11 -7
  44. package/dest/store/kv_archiver_store.d.ts +36 -14
  45. package/dest/store/kv_archiver_store.d.ts.map +1 -1
  46. package/dest/store/kv_archiver_store.js +39 -10
  47. package/dest/store/l2_tips_cache.d.ts +19 -0
  48. package/dest/store/l2_tips_cache.d.ts.map +1 -0
  49. package/dest/store/l2_tips_cache.js +89 -0
  50. package/dest/store/log_store.d.ts +1 -1
  51. package/dest/store/log_store.d.ts.map +1 -1
  52. package/dest/store/log_store.js +57 -37
  53. package/dest/store/message_store.js +1 -1
  54. package/dest/test/fake_l1_state.d.ts +13 -1
  55. package/dest/test/fake_l1_state.d.ts.map +1 -1
  56. package/dest/test/fake_l1_state.js +84 -20
  57. package/dest/test/index.js +3 -1
  58. package/dest/test/mock_archiver.d.ts +1 -1
  59. package/dest/test/mock_archiver.d.ts.map +1 -1
  60. package/dest/test/mock_archiver.js +3 -2
  61. package/dest/test/mock_l2_block_source.d.ts +25 -9
  62. package/dest/test/mock_l2_block_source.d.ts.map +1 -1
  63. package/dest/test/mock_l2_block_source.js +132 -86
  64. package/dest/test/mock_structs.d.ts +6 -2
  65. package/dest/test/mock_structs.d.ts.map +1 -1
  66. package/dest/test/mock_structs.js +20 -6
  67. package/dest/test/noop_l1_archiver.d.ts +26 -0
  68. package/dest/test/noop_l1_archiver.d.ts.map +1 -0
  69. package/dest/test/noop_l1_archiver.js +72 -0
  70. package/package.json +14 -13
  71. package/src/archiver.ts +96 -132
  72. package/src/errors.ts +10 -24
  73. package/src/factory.ts +32 -17
  74. package/src/index.ts +1 -0
  75. package/src/l1/README.md +25 -68
  76. package/src/l1/bin/retrieve-calldata.ts +46 -39
  77. package/src/l1/calldata_retriever.ts +249 -379
  78. package/src/l1/data_retrieval.ts +24 -26
  79. package/src/l1/spire_proposer.ts +7 -15
  80. package/src/l1/validate_trace.ts +24 -6
  81. package/src/modules/data_source_base.ts +58 -97
  82. package/src/modules/data_store_updater.ts +71 -30
  83. package/src/modules/instrumentation.ts +44 -12
  84. package/src/modules/l1_synchronizer.ts +48 -17
  85. package/src/store/block_store.ts +151 -108
  86. package/src/store/contract_class_store.ts +11 -7
  87. package/src/store/kv_archiver_store.ts +62 -16
  88. package/src/store/l2_tips_cache.ts +89 -0
  89. package/src/store/log_store.ts +98 -36
  90. package/src/store/message_store.ts +1 -1
  91. package/src/test/fake_l1_state.ts +110 -21
  92. package/src/test/index.ts +3 -0
  93. package/src/test/mock_archiver.ts +3 -2
  94. package/src/test/mock_l2_block_source.ts +172 -86
  95. package/src/test/mock_structs.ts +42 -12
  96. package/src/test/noop_l1_archiver.ts +115 -0
@@ -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
 
@@ -111,6 +127,25 @@ export function makeL1PublishedData(l1BlockNumber: number): L1PublishedData {
111
127
  return new L1PublishedData(BigInt(l1BlockNumber), BigInt(l1BlockNumber * 1000), makeBlockHash(l1BlockNumber));
112
128
  }
113
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
+
114
149
  /** Wraps a Checkpoint with L1 published data and random attestations. */
115
150
  export function makePublishedCheckpoint(
116
151
  checkpoint: Checkpoint,
@@ -285,11 +320,6 @@ export async function makeCheckpointWithLogs(
285
320
  return txEffect;
286
321
  });
287
322
 
288
- const checkpoint = new Checkpoint(
289
- AppendOnlyTreeSnapshot.random(),
290
- CheckpointHeader.random(),
291
- [block],
292
- CheckpointNumber.fromBlockNumber(BlockNumber(blockNumber)),
293
- );
323
+ const checkpoint = makeCheckpoint([block], CheckpointNumber.fromBlockNumber(BlockNumber(blockNumber)));
294
324
  return makePublishedCheckpoint(checkpoint, blockNumber);
295
325
  }
@@ -0,0 +1,115 @@
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 { SlotNumber } from '@aztec/foundation/branded-types';
5
+ import { Buffer32 } from '@aztec/foundation/buffer';
6
+ import { Fr } from '@aztec/foundation/curves/bn254';
7
+ import { EthAddress } from '@aztec/foundation/eth-address';
8
+ import type { FunctionsOf } from '@aztec/foundation/types';
9
+ import type { ArchiverEmitter } from '@aztec/stdlib/block';
10
+ import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
11
+ import { type TelemetryClient, type Tracer, getTelemetryClient } from '@aztec/telemetry-client';
12
+
13
+ import { mock } from 'jest-mock-extended';
14
+ import { EventEmitter } from 'node:events';
15
+
16
+ import { Archiver } from '../archiver.js';
17
+ import { ArchiverInstrumentation } from '../modules/instrumentation.js';
18
+ import type { ArchiverL1Synchronizer } from '../modules/l1_synchronizer.js';
19
+ import type { KVArchiverDataStore } from '../store/kv_archiver_store.js';
20
+
21
+ /** Noop L1 synchronizer for testing without L1 connectivity. */
22
+ class NoopL1Synchronizer implements FunctionsOf<ArchiverL1Synchronizer> {
23
+ public readonly tracer: Tracer;
24
+
25
+ constructor(tracer: Tracer) {
26
+ this.tracer = tracer;
27
+ }
28
+
29
+ setConfig(_config: unknown) {}
30
+ getL1BlockNumber(): bigint | undefined {
31
+ return 0n;
32
+ }
33
+ getL1Timestamp(): bigint | undefined {
34
+ return undefined;
35
+ }
36
+ testEthereumNodeSynced(): Promise<void> {
37
+ return Promise.resolve();
38
+ }
39
+ syncFromL1(_initialSyncComplete: boolean): Promise<void> {
40
+ return Promise.resolve();
41
+ }
42
+ }
43
+
44
+ /**
45
+ * Archiver with mocked L1 connectivity for testing.
46
+ * Uses mock L1 clients and a noop synchronizer, enabling tests that
47
+ * don't require real Ethereum connectivity.
48
+ */
49
+ export class NoopL1Archiver extends Archiver {
50
+ constructor(
51
+ dataStore: KVArchiverDataStore,
52
+ l1Constants: L1RollupConstants & { genesisArchiveRoot: Fr },
53
+ instrumentation: ArchiverInstrumentation,
54
+ ) {
55
+ // Create mocks for L1 clients
56
+ const publicClient = mock<ViemPublicClient>();
57
+ const debugClient = mock<ViemPublicDebugClient>();
58
+ const rollup = mock<RollupContract>();
59
+ const blobClient = mock<BlobClientInterface>();
60
+
61
+ // Mock methods called during start()
62
+ blobClient.testSources.mockResolvedValue();
63
+ publicClient.getBlockNumber.mockResolvedValue(1n);
64
+
65
+ const events = new EventEmitter() as ArchiverEmitter;
66
+ const synchronizer = new NoopL1Synchronizer(instrumentation.tracer);
67
+
68
+ super(
69
+ publicClient,
70
+ debugClient,
71
+ rollup,
72
+ {
73
+ registryAddress: EthAddress.ZERO,
74
+ governanceProposerAddress: EthAddress.ZERO,
75
+ slashFactoryAddress: EthAddress.ZERO,
76
+ slashingProposerAddress: EthAddress.ZERO,
77
+ },
78
+ dataStore,
79
+ {
80
+ pollingIntervalMs: 1000,
81
+ batchSize: 100,
82
+ skipValidateCheckpointAttestations: true,
83
+ maxAllowedEthClientDriftSeconds: 300,
84
+ ethereumAllowNoDebugHosts: true, // Skip trace validation
85
+ },
86
+ blobClient,
87
+ instrumentation,
88
+ { ...l1Constants, l1StartBlockHash: Buffer32.random() },
89
+ synchronizer as ArchiverL1Synchronizer,
90
+ events,
91
+ );
92
+ }
93
+
94
+ /** Override start to skip L1 validation checks. */
95
+ public override start(_blockUntilSynced?: boolean): Promise<void> {
96
+ // Just start the running promise without L1 checks
97
+ this.runningPromise.start();
98
+ return Promise.resolve();
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
+ }
105
+ }
106
+
107
+ /** Creates an archiver with mocked L1 connectivity for testing. */
108
+ export async function createNoopL1Archiver(
109
+ dataStore: KVArchiverDataStore,
110
+ l1Constants: L1RollupConstants & { genesisArchiveRoot: Fr },
111
+ telemetry: TelemetryClient = getTelemetryClient(),
112
+ ): Promise<NoopL1Archiver> {
113
+ const instrumentation = await ArchiverInstrumentation.new(telemetry, () => dataStore.estimateSize());
114
+ return new NoopL1Archiver(dataStore, l1Constants, instrumentation);
115
+ }