@aztec/archiver 4.0.0-nightly.20260113 → 4.0.0-nightly.20260114

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 (47) hide show
  1. package/README.md +139 -22
  2. package/dest/archiver/archive_source_base.d.ts +75 -0
  3. package/dest/archiver/archive_source_base.d.ts.map +1 -0
  4. package/dest/archiver/archive_source_base.js +202 -0
  5. package/dest/archiver/archiver.d.ts +28 -167
  6. package/dest/archiver/archiver.d.ts.map +1 -1
  7. package/dest/archiver/archiver.js +46 -601
  8. package/dest/archiver/archiver_store_updates.d.ts +38 -0
  9. package/dest/archiver/archiver_store_updates.d.ts.map +1 -0
  10. package/dest/archiver/archiver_store_updates.js +212 -0
  11. package/dest/archiver/index.d.ts +3 -2
  12. package/dest/archiver/index.d.ts.map +1 -1
  13. package/dest/archiver/index.js +2 -0
  14. package/dest/archiver/kv_archiver_store/block_store.d.ts +1 -1
  15. package/dest/archiver/kv_archiver_store/block_store.js +1 -1
  16. package/dest/archiver/kv_archiver_store/contract_class_store.d.ts +1 -1
  17. package/dest/archiver/kv_archiver_store/contract_class_store.js +1 -1
  18. package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts +1 -1
  19. package/dest/archiver/kv_archiver_store/contract_instance_store.js +1 -1
  20. package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts +169 -9
  21. package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts.map +1 -1
  22. package/dest/archiver/kv_archiver_store/kv_archiver_store.js +157 -49
  23. package/dest/archiver/l1/data_retrieval.d.ts +9 -11
  24. package/dest/archiver/l1/data_retrieval.d.ts.map +1 -1
  25. package/dest/archiver/l1/data_retrieval.js +32 -51
  26. package/dest/archiver/test/fake_l1_state.d.ts +173 -0
  27. package/dest/archiver/test/fake_l1_state.d.ts.map +1 -0
  28. package/dest/archiver/test/fake_l1_state.js +364 -0
  29. package/package.json +13 -13
  30. package/src/archiver/archive_source_base.ts +339 -0
  31. package/src/archiver/archiver.ts +62 -808
  32. package/src/archiver/archiver_store_updates.ts +321 -0
  33. package/src/archiver/index.ts +2 -1
  34. package/src/archiver/kv_archiver_store/block_store.ts +1 -1
  35. package/src/archiver/kv_archiver_store/contract_class_store.ts +1 -1
  36. package/src/archiver/kv_archiver_store/contract_instance_store.ts +1 -1
  37. package/src/archiver/kv_archiver_store/kv_archiver_store.ts +170 -8
  38. package/src/archiver/l1/data_retrieval.ts +51 -68
  39. package/src/archiver/test/fake_l1_state.ts +561 -0
  40. package/dest/archiver/archiver_store.d.ts +0 -315
  41. package/dest/archiver/archiver_store.d.ts.map +0 -1
  42. package/dest/archiver/archiver_store.js +0 -4
  43. package/dest/archiver/archiver_store_test_suite.d.ts +0 -8
  44. package/dest/archiver/archiver_store_test_suite.d.ts.map +0 -1
  45. package/dest/archiver/archiver_store_test_suite.js +0 -2770
  46. package/src/archiver/archiver_store.ts +0 -380
  47. package/src/archiver/archiver_store_test_suite.ts +0 -2842
@@ -0,0 +1,339 @@
1
+ import { BlockNumber, CheckpointNumber, type EpochNumber, type SlotNumber } from '@aztec/foundation/branded-types';
2
+ import type { Fr } from '@aztec/foundation/curves/bn254';
3
+ import type { EthAddress } from '@aztec/foundation/eth-address';
4
+ import { isDefined } from '@aztec/foundation/types';
5
+ import type { FunctionSelector } from '@aztec/stdlib/abi';
6
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
7
+ import {
8
+ type CheckpointedL2Block,
9
+ CommitteeAttestation,
10
+ L2Block,
11
+ type L2BlockNew,
12
+ type L2Tips,
13
+ PublishedL2Block,
14
+ } from '@aztec/stdlib/block';
15
+ import { Checkpoint, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
16
+ import type { ContractClassPublic, ContractDataSource, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
17
+ import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
18
+ import type { GetContractClassLogsResponse, GetPublicLogsResponse } from '@aztec/stdlib/interfaces/client';
19
+ import type { L2LogsSource } from '@aztec/stdlib/interfaces/server';
20
+ import type { LogFilter, SiloedTag, Tag, TxScopedL2Log } from '@aztec/stdlib/logs';
21
+ import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
22
+ import type { BlockHeader, IndexedTxEffect, TxHash, TxReceipt } from '@aztec/stdlib/tx';
23
+ import type { UInt64 } from '@aztec/stdlib/types';
24
+
25
+ import type { ArchiveSource } from './archiver.js';
26
+ import type { KVArchiverDataStore } from './kv_archiver_store/kv_archiver_store.js';
27
+ import type { ValidateCheckpointResult } from './validation.js';
28
+
29
+ /**
30
+ * Abstract base class implementing ArchiveSource using a KVArchiverDataStore.
31
+ * Provides implementations for all store-delegating methods and declares abstract methods
32
+ * for L1-dependent functionality that subclasses must implement.
33
+ */
34
+ export abstract class ArchiveSourceBase
35
+ implements ArchiveSource, L2LogsSource, ContractDataSource, L1ToL2MessageSource
36
+ {
37
+ protected readonly store: KVArchiverDataStore;
38
+
39
+ constructor(store: KVArchiverDataStore) {
40
+ this.store = store;
41
+ }
42
+
43
+ // Abstract methods that require L1 dependencies
44
+
45
+ abstract getRollupAddress(): Promise<EthAddress>;
46
+
47
+ abstract getRegistryAddress(): Promise<EthAddress>;
48
+
49
+ abstract getL1Constants(): Promise<L1RollupConstants>;
50
+
51
+ abstract getGenesisValues(): Promise<{ genesisArchiveRoot: Fr }>;
52
+
53
+ abstract getL1Timestamp(): Promise<bigint | undefined>;
54
+
55
+ abstract getL2Tips(): Promise<L2Tips>;
56
+
57
+ abstract getL2SlotNumber(): Promise<SlotNumber | undefined>;
58
+
59
+ abstract getL2EpochNumber(): Promise<EpochNumber | undefined>;
60
+
61
+ abstract getCheckpointsForEpoch(epochNumber: EpochNumber): Promise<Checkpoint[]>;
62
+
63
+ abstract getBlocksForEpoch(epochNumber: EpochNumber): Promise<L2Block[]>;
64
+
65
+ abstract getBlockHeadersForEpoch(epochNumber: EpochNumber): Promise<BlockHeader[]>;
66
+
67
+ abstract isEpochComplete(epochNumber: EpochNumber): Promise<boolean>;
68
+
69
+ abstract syncImmediate(): Promise<void>;
70
+
71
+ // Store-delegating methods
72
+
73
+ public getBlockNumber(): Promise<BlockNumber> {
74
+ return this.store.getLatestBlockNumber();
75
+ }
76
+
77
+ public getProvenBlockNumber(): Promise<BlockNumber> {
78
+ return this.store.getProvenBlockNumber();
79
+ }
80
+
81
+ public async getBlockHeader(number: BlockNumber | 'latest'): Promise<BlockHeader | undefined> {
82
+ const blockNumber = number === 'latest' ? await this.store.getLatestBlockNumber() : number;
83
+ if (blockNumber === 0) {
84
+ return undefined;
85
+ }
86
+ const headers = await this.store.getBlockHeaders(blockNumber, 1);
87
+ return headers.length === 0 ? undefined : headers[0];
88
+ }
89
+
90
+ public getCheckpointedBlock(number: BlockNumber): Promise<CheckpointedL2Block | undefined> {
91
+ return this.store.getCheckpointedBlock(number);
92
+ }
93
+
94
+ public async getCheckpointedBlocks(
95
+ from: BlockNumber,
96
+ limit: number,
97
+ proven?: boolean,
98
+ ): Promise<CheckpointedL2Block[]> {
99
+ const blocks = await this.store.getCheckpointedBlocks(from, limit);
100
+
101
+ if (proven === true) {
102
+ const provenBlockNumber = await this.store.getProvenBlockNumber();
103
+ return blocks.filter(b => b.block.number <= provenBlockNumber);
104
+ }
105
+ return blocks;
106
+ }
107
+
108
+ public getBlockHeaderByHash(blockHash: Fr): Promise<BlockHeader | undefined> {
109
+ return this.store.getBlockHeaderByHash(blockHash);
110
+ }
111
+
112
+ public getBlockHeaderByArchive(archive: Fr): Promise<BlockHeader | undefined> {
113
+ return this.store.getBlockHeaderByArchive(archive);
114
+ }
115
+
116
+ public async getL2BlockNew(number: BlockNumber): Promise<L2BlockNew | undefined> {
117
+ // If the number provided is -ve, then return the latest block.
118
+ if (number < 0) {
119
+ number = await this.store.getLatestBlockNumber();
120
+ }
121
+ if (number === 0) {
122
+ return undefined;
123
+ }
124
+ const publishedBlock = await this.store.getBlock(number);
125
+ return publishedBlock;
126
+ }
127
+
128
+ public getTxEffect(txHash: TxHash): Promise<IndexedTxEffect | undefined> {
129
+ return this.store.getTxEffect(txHash);
130
+ }
131
+
132
+ public getSettledTxReceipt(txHash: TxHash): Promise<TxReceipt | undefined> {
133
+ return this.store.getSettledTxReceipt(txHash);
134
+ }
135
+
136
+ public isPendingChainInvalid(): Promise<boolean> {
137
+ return this.getPendingChainValidationStatus().then(status => !status.valid);
138
+ }
139
+
140
+ public async getPendingChainValidationStatus(): Promise<ValidateCheckpointResult> {
141
+ return (await this.store.getPendingChainValidationStatus()) ?? { valid: true };
142
+ }
143
+
144
+ public async getL2BlocksNew(from: BlockNumber, limit: number, proven?: boolean): Promise<L2BlockNew[]> {
145
+ const blocks = await this.store.getBlocks(from, limit);
146
+
147
+ if (proven === true) {
148
+ const provenBlockNumber = await this.store.getProvenBlockNumber();
149
+ return blocks.filter(b => b.number <= provenBlockNumber);
150
+ }
151
+ return blocks;
152
+ }
153
+
154
+ // L2LogsSource methods
155
+
156
+ public getPrivateLogsByTags(tags: SiloedTag[]): Promise<TxScopedL2Log[][]> {
157
+ return this.store.getPrivateLogsByTags(tags);
158
+ }
159
+
160
+ public getPublicLogsByTagsFromContract(contractAddress: AztecAddress, tags: Tag[]): Promise<TxScopedL2Log[][]> {
161
+ return this.store.getPublicLogsByTagsFromContract(contractAddress, tags);
162
+ }
163
+
164
+ public getPublicLogs(filter: LogFilter): Promise<GetPublicLogsResponse> {
165
+ return this.store.getPublicLogs(filter);
166
+ }
167
+
168
+ public getContractClassLogs(filter: LogFilter): Promise<GetContractClassLogsResponse> {
169
+ return this.store.getContractClassLogs(filter);
170
+ }
171
+
172
+ // ContractDataSource methods
173
+
174
+ public getContractClass(id: Fr): Promise<ContractClassPublic | undefined> {
175
+ return this.store.getContractClass(id);
176
+ }
177
+
178
+ public getBytecodeCommitment(id: Fr): Promise<Fr | undefined> {
179
+ return this.store.getBytecodeCommitment(id);
180
+ }
181
+
182
+ public async getContract(
183
+ address: AztecAddress,
184
+ maybeTimestamp?: UInt64,
185
+ ): Promise<ContractInstanceWithAddress | undefined> {
186
+ let timestamp;
187
+ if (maybeTimestamp === undefined) {
188
+ const latestBlockHeader = await this.getBlockHeader('latest');
189
+ // If we get undefined block header, it means that the archiver has not yet synced any block so we default to 0.
190
+ timestamp = latestBlockHeader ? latestBlockHeader.globalVariables.timestamp : 0n;
191
+ } else {
192
+ timestamp = maybeTimestamp;
193
+ }
194
+
195
+ return this.store.getContractInstance(address, timestamp);
196
+ }
197
+
198
+ public getContractClassIds(): Promise<Fr[]> {
199
+ return this.store.getContractClassIds();
200
+ }
201
+
202
+ public getDebugFunctionName(address: AztecAddress, selector: FunctionSelector): Promise<string | undefined> {
203
+ return this.store.getDebugFunctionName(address, selector);
204
+ }
205
+
206
+ public registerContractFunctionSignatures(signatures: string[]): Promise<void> {
207
+ return this.store.registerContractFunctionSignatures(signatures);
208
+ }
209
+
210
+ // L1ToL2MessageSource methods
211
+
212
+ public getL1ToL2Messages(checkpointNumber: CheckpointNumber): Promise<Fr[]> {
213
+ return this.store.getL1ToL2Messages(checkpointNumber);
214
+ }
215
+
216
+ public getL1ToL2MessageIndex(l1ToL2Message: Fr): Promise<bigint | undefined> {
217
+ return this.store.getL1ToL2MessageIndex(l1ToL2Message);
218
+ }
219
+
220
+ // Published checkpoint methods
221
+
222
+ public async getPublishedCheckpoints(
223
+ checkpointNumber: CheckpointNumber,
224
+ limit: number,
225
+ ): Promise<PublishedCheckpoint[]> {
226
+ const checkpoints = await this.store.getRangeOfCheckpoints(checkpointNumber, limit);
227
+ const blocks = (
228
+ await Promise.all(checkpoints.map(ch => this.store.getBlocksForCheckpoint(ch.checkpointNumber)))
229
+ ).filter(isDefined);
230
+
231
+ const fullCheckpoints: PublishedCheckpoint[] = [];
232
+ for (let i = 0; i < checkpoints.length; i++) {
233
+ const blocksForCheckpoint = blocks[i];
234
+ const checkpoint = checkpoints[i];
235
+ const fullCheckpoint = new Checkpoint(
236
+ checkpoint.archive,
237
+ checkpoint.header,
238
+ blocksForCheckpoint,
239
+ checkpoint.checkpointNumber,
240
+ );
241
+ const publishedCheckpoint = new PublishedCheckpoint(
242
+ fullCheckpoint,
243
+ checkpoint.l1,
244
+ checkpoint.attestations.map(x => CommitteeAttestation.fromBuffer(x)),
245
+ );
246
+ fullCheckpoints.push(publishedCheckpoint);
247
+ }
248
+ return fullCheckpoints;
249
+ }
250
+
251
+ public async getPublishedBlocks(from: BlockNumber, limit: number, proven?: boolean): Promise<PublishedL2Block[]> {
252
+ const checkpoints = await this.store.getRangeOfCheckpoints(CheckpointNumber(from), limit);
253
+ const provenCheckpointNumber = await this.store.getProvenCheckpointNumber();
254
+ const blocks = (
255
+ await Promise.all(checkpoints.map(ch => this.store.getBlocksForCheckpoint(ch.checkpointNumber)))
256
+ ).filter(isDefined);
257
+
258
+ const olbBlocks: PublishedL2Block[] = [];
259
+ for (let i = 0; i < checkpoints.length; i++) {
260
+ const blockForCheckpoint = blocks[i][0];
261
+ const checkpoint = checkpoints[i];
262
+ if (checkpoint.checkpointNumber > provenCheckpointNumber && proven === true) {
263
+ // this checkpointisn't proven and we only want proven
264
+ continue;
265
+ }
266
+ const oldCheckpoint = new Checkpoint(
267
+ blockForCheckpoint.archive,
268
+ checkpoint.header,
269
+ [blockForCheckpoint],
270
+ checkpoint.checkpointNumber,
271
+ );
272
+ const oldBlock = L2Block.fromCheckpoint(oldCheckpoint);
273
+ const publishedBlock = new PublishedL2Block(
274
+ oldBlock,
275
+ checkpoint.l1,
276
+ checkpoint.attestations.map(x => CommitteeAttestation.fromBuffer(x)),
277
+ );
278
+ olbBlocks.push(publishedBlock);
279
+ }
280
+ return olbBlocks;
281
+ }
282
+
283
+ // Legacy APIs
284
+
285
+ public async getBlock(number: BlockNumber): Promise<L2Block | undefined> {
286
+ // If the number provided is -ve, then return the latest block.
287
+ if (number < 0) {
288
+ number = await this.store.getLatestBlockNumber();
289
+ }
290
+ if (number === 0) {
291
+ return undefined;
292
+ }
293
+ const publishedBlocks = await this.getPublishedBlocks(number, 1);
294
+ if (publishedBlocks.length === 0) {
295
+ return undefined;
296
+ }
297
+ return publishedBlocks[0].block;
298
+ }
299
+
300
+ public async getBlocks(from: BlockNumber, limit: number, proven?: boolean): Promise<L2Block[]> {
301
+ const publishedBlocks = await this.getPublishedBlocks(from, limit, proven);
302
+ return publishedBlocks.map(x => x.block);
303
+ }
304
+
305
+ public async getPublishedBlockByHash(blockHash: Fr): Promise<PublishedL2Block | undefined> {
306
+ const checkpointedBlock = await this.store.getCheckpointedBlockByHash(blockHash);
307
+ return this.buildOldBlockFromCheckpointedBlock(checkpointedBlock);
308
+ }
309
+
310
+ public async getPublishedBlockByArchive(archive: Fr): Promise<PublishedL2Block | undefined> {
311
+ const checkpointedBlock = await this.store.getCheckpointedBlockByArchive(archive);
312
+ return this.buildOldBlockFromCheckpointedBlock(checkpointedBlock);
313
+ }
314
+
315
+ private async buildOldBlockFromCheckpointedBlock(
316
+ checkpointedBlock: CheckpointedL2Block | undefined,
317
+ ): Promise<PublishedL2Block | undefined> {
318
+ if (!checkpointedBlock) {
319
+ return undefined;
320
+ }
321
+ const checkpoint = await this.store.getCheckpointData(checkpointedBlock.checkpointNumber);
322
+ if (!checkpoint) {
323
+ return checkpoint;
324
+ }
325
+ const fullCheckpoint = new Checkpoint(
326
+ checkpointedBlock?.block.archive,
327
+ checkpoint?.header,
328
+ [checkpointedBlock.block],
329
+ checkpoint.checkpointNumber,
330
+ );
331
+ const oldBlock = L2Block.fromCheckpoint(fullCheckpoint);
332
+ const published = new PublishedL2Block(
333
+ oldBlock,
334
+ checkpoint.l1,
335
+ checkpoint.attestations.map(x => CommitteeAttestation.fromBuffer(x)),
336
+ );
337
+ return published;
338
+ }
339
+ }