@aztec/archiver 0.28.1 → 0.30.0

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/archiver.d.ts +13 -53
  2. package/dest/archiver/archiver.d.ts.map +1 -1
  3. package/dest/archiver/archiver.js +60 -199
  4. package/dest/archiver/archiver_store.d.ts +21 -67
  5. package/dest/archiver/archiver_store.d.ts.map +1 -1
  6. package/dest/archiver/archiver_store_test_suite.d.ts.map +1 -1
  7. package/dest/archiver/archiver_store_test_suite.js +60 -199
  8. package/dest/archiver/config.d.ts.map +1 -1
  9. package/dest/archiver/config.js +6 -2
  10. package/dest/archiver/data_retrieval.d.ts +10 -32
  11. package/dest/archiver/data_retrieval.d.ts.map +1 -1
  12. package/dest/archiver/data_retrieval.js +13 -67
  13. package/dest/archiver/eth_log_handlers.d.ts +7 -38
  14. package/dest/archiver/eth_log_handlers.d.ts.map +1 -1
  15. package/dest/archiver/eth_log_handlers.js +9 -77
  16. package/dest/archiver/kv_archiver_store/block_store.d.ts +5 -4
  17. package/dest/archiver/kv_archiver_store/block_store.d.ts.map +1 -1
  18. package/dest/archiver/kv_archiver_store/block_store.js +12 -15
  19. package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts +15 -56
  20. package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts.map +1 -1
  21. package/dest/archiver/kv_archiver_store/kv_archiver_store.js +23 -87
  22. package/dest/archiver/kv_archiver_store/message_store.d.ts +12 -43
  23. package/dest/archiver/kv_archiver_store/message_store.d.ts.map +1 -1
  24. package/dest/archiver/kv_archiver_store/message_store.js +32 -141
  25. package/dest/archiver/memory_archiver_store/l1_to_l2_message_store.d.ts +8 -41
  26. package/dest/archiver/memory_archiver_store/l1_to_l2_message_store.d.ts.map +1 -1
  27. package/dest/archiver/memory_archiver_store/l1_to_l2_message_store.js +22 -79
  28. package/dest/archiver/memory_archiver_store/memory_archiver_store.d.ts +20 -81
  29. package/dest/archiver/memory_archiver_store/memory_archiver_store.d.ts.map +1 -1
  30. package/dest/archiver/memory_archiver_store/memory_archiver_store.js +30 -143
  31. package/dest/index.d.ts.map +1 -1
  32. package/dest/index.js +3 -15
  33. package/dest/rpc/archiver_client.d.ts.map +1 -1
  34. package/dest/rpc/archiver_client.js +2 -6
  35. package/dest/rpc/archiver_server.d.ts.map +1 -1
  36. package/dest/rpc/archiver_server.js +2 -6
  37. package/package.json +9 -9
  38. package/src/archiver/archiver.ts +80 -267
  39. package/src/archiver/archiver_store.ts +22 -76
  40. package/src/archiver/archiver_store_test_suite.ts +78 -243
  41. package/src/archiver/config.ts +6 -0
  42. package/src/archiver/data_retrieval.ts +19 -101
  43. package/src/archiver/eth_log_handlers.ts +14 -108
  44. package/src/archiver/kv_archiver_store/block_store.ts +13 -14
  45. package/src/archiver/kv_archiver_store/kv_archiver_store.ts +23 -93
  46. package/src/archiver/kv_archiver_store/message_store.ts +38 -169
  47. package/src/archiver/memory_archiver_store/l1_to_l2_message_store.ts +21 -90
  48. package/src/archiver/memory_archiver_store/memory_archiver_store.ts +33 -161
  49. package/src/index.ts +1 -15
  50. package/src/rpc/archiver_client.ts +0 -8
  51. package/src/rpc/archiver_server.ts +0 -8
  52. package/dest/archiver/kv_archiver_store/contract_store.d.ts +0 -26
  53. package/dest/archiver/kv_archiver_store/contract_store.d.ts.map +0 -1
  54. package/dest/archiver/kv_archiver_store/contract_store.js +0 -49
  55. package/src/archiver/kv_archiver_store/contract_store.ts +0 -55
@@ -1,10 +1,5 @@
1
1
  import {
2
- ContractData,
3
- ContractDataSource,
4
- EncodedContractFunction,
5
- ExtendedContractData,
6
2
  GetUnencryptedLogsResponse,
7
- L1ToL2Message,
8
3
  L1ToL2MessageSource,
9
4
  L2Block,
10
5
  L2BlockL2Logs,
@@ -25,26 +20,23 @@ import { EthAddress } from '@aztec/foundation/eth-address';
25
20
  import { Fr } from '@aztec/foundation/fields';
26
21
  import { DebugLogger, createDebugLogger } from '@aztec/foundation/log';
27
22
  import { RunningPromise } from '@aztec/foundation/running-promise';
28
- import { RollupAbi } from '@aztec/l1-artifacts';
29
23
  import { ClassRegistererAddress } from '@aztec/protocol-contracts/class-registerer';
30
- import { InstanceDeployerAddress } from '@aztec/protocol-contracts/instance-deployer';
31
24
  import {
32
- ContractClass,
33
25
  ContractClassPublic,
34
- ContractInstance,
26
+ ContractDataSource,
35
27
  ContractInstanceWithAddress,
28
+ PublicFunction,
36
29
  } from '@aztec/types/contracts';
37
30
 
38
- import { Chain, HttpTransport, PublicClient, createPublicClient, getAddress, getContract, http } from 'viem';
31
+ import { Chain, HttpTransport, PublicClient, createPublicClient, http } from 'viem';
39
32
 
40
33
  import { ArchiverDataStore } from './archiver_store.js';
41
34
  import { ArchiverConfig } from './config.js';
42
35
  import {
36
+ DataRetrieval,
43
37
  retrieveBlockBodiesFromAvailabilityOracle,
44
38
  retrieveBlockMetadataFromRollup,
45
- retrieveNewCancelledL1ToL2Messages,
46
- retrieveNewL1ToL2Messages,
47
- retrieveNewPendingL1ToL2Messages,
39
+ retrieveL1ToL2Messages,
48
40
  } from './data_retrieval.js';
49
41
 
50
42
  /**
@@ -73,7 +65,6 @@ export class Archiver implements ArchiveSource {
73
65
  * @param publicClient - A client for interacting with the Ethereum node.
74
66
  * @param rollupAddress - Ethereum address of the rollup contract.
75
67
  * @param inboxAddress - Ethereum address of the inbox contract.
76
- * @param newInboxAddress - Ethereum address of the new inbox contract.
77
68
  * @param registryAddress - Ethereum address of the registry contract.
78
69
  * @param pollingIntervalMs - The interval for polling for L1 logs (in milliseconds).
79
70
  * @param store - An archiver data store for storage & retrieval of blocks, encrypted logs & contract data.
@@ -84,7 +75,6 @@ export class Archiver implements ArchiveSource {
84
75
  private readonly rollupAddress: EthAddress,
85
76
  private readonly availabilityOracleAddress: EthAddress,
86
77
  private readonly inboxAddress: EthAddress,
87
- private readonly newInboxAddress: EthAddress,
88
78
  private readonly registryAddress: EthAddress,
89
79
  private readonly store: ArchiverDataStore,
90
80
  private readonly pollingIntervalMs = 10_000,
@@ -110,23 +100,11 @@ export class Archiver implements ArchiveSource {
110
100
  pollingInterval: config.viemPollingIntervalMS,
111
101
  });
112
102
 
113
- // TODO(#4492): Nuke this once the old inbox is purged
114
- let newInboxAddress!: EthAddress;
115
- {
116
- const rollup = getContract({
117
- address: getAddress(config.l1Contracts.rollupAddress.toString()),
118
- abi: RollupAbi,
119
- client: publicClient,
120
- });
121
- newInboxAddress = EthAddress.fromString(await rollup.read.NEW_INBOX());
122
- }
123
-
124
103
  const archiver = new Archiver(
125
104
  publicClient,
126
105
  config.l1Contracts.rollupAddress,
127
106
  config.l1Contracts.availabilityOracleAddress,
128
107
  config.l1Contracts.inboxAddress,
129
- newInboxAddress,
130
108
  config.l1Contracts.registryAddress,
131
109
  archiverStore,
132
110
  config.archiverPollingIntervalMS,
@@ -170,15 +148,10 @@ export class Archiver implements ArchiveSource {
170
148
  *
171
149
  * This code does not handle reorgs.
172
150
  */
173
- const lastL1Blocks = await this.store.getL1BlockNumber();
151
+ const lastL1Blocks = await this.store.getSynchedL1BlockNumbers();
174
152
  const currentL1BlockNumber = await this.publicClient.getBlockNumber();
175
153
 
176
- if (
177
- currentL1BlockNumber <= lastL1Blocks.addedBlock &&
178
- currentL1BlockNumber <= lastL1Blocks.newMessages &&
179
- currentL1BlockNumber <= lastL1Blocks.addedMessages &&
180
- currentL1BlockNumber <= lastL1Blocks.cancelledMessages
181
- ) {
154
+ if (currentL1BlockNumber <= lastL1Blocks.blocks && currentL1BlockNumber <= lastL1Blocks.messages) {
182
155
  // chain hasn't moved forward
183
156
  // or it's been rolled back
184
157
  return;
@@ -205,122 +178,82 @@ export class Archiver implements ArchiveSource {
205
178
 
206
179
  // ********** Events that are processed per L1 block **********
207
180
 
208
- // TODO(#4492): Nuke the following when purging the old inbox
209
- // Process l1ToL2Messages, these are consumed as time passes, not each block
210
- const retrievedPendingL1ToL2Messages = await retrieveNewPendingL1ToL2Messages(
211
- this.publicClient,
212
- this.inboxAddress,
213
- blockUntilSynced,
214
- lastL1Blocks.addedMessages + 1n,
215
- currentL1BlockNumber,
216
- );
217
- const retrievedCancelledL1ToL2Messages = await retrieveNewCancelledL1ToL2Messages(
181
+ // ********** Events that are processed per L2 block **********
182
+
183
+ const retrievedL1ToL2Messages = await retrieveL1ToL2Messages(
218
184
  this.publicClient,
219
185
  this.inboxAddress,
220
186
  blockUntilSynced,
221
- lastL1Blocks.cancelledMessages + 1n,
187
+ lastL1Blocks.messages + 1n,
222
188
  currentL1BlockNumber,
223
189
  );
224
190
 
225
- // group pending messages and cancelled messages by their L1 block number
226
- const messagesByBlock = new Map<bigint, [L1ToL2Message[], Fr[]]>();
227
- for (const [message, blockNumber] of retrievedPendingL1ToL2Messages.retrievedData) {
228
- const messages = messagesByBlock.get(blockNumber) || [[], []];
229
- messages[0].push(message);
230
- messagesByBlock.set(blockNumber, messages);
231
- }
232
-
233
- for (const [entryKey, blockNumber] of retrievedCancelledL1ToL2Messages.retrievedData) {
234
- const messages = messagesByBlock.get(blockNumber) || [[], []];
235
- messages[1].push(entryKey);
236
- messagesByBlock.set(blockNumber, messages);
237
- }
238
-
239
- // process messages from each L1 block in sequence
240
- const l1BlocksWithMessages = Array.from(messagesByBlock.keys()).sort((a, b) => (a < b ? -1 : a === b ? 0 : 1));
241
- for (const l1Block of l1BlocksWithMessages) {
242
- const [newMessages, cancelledMessages] = messagesByBlock.get(l1Block)!;
191
+ if (retrievedL1ToL2Messages.retrievedData.length !== 0) {
243
192
  this.log(
244
- `Adding ${newMessages.length} new messages and ${cancelledMessages.length} cancelled messages in L1 block ${l1Block}`,
193
+ `Retrieved ${retrievedL1ToL2Messages.retrievedData.length} new L1 -> L2 messages between L1 blocks ${
194
+ lastL1Blocks.messages + 1n
195
+ } and ${currentL1BlockNumber}.`,
245
196
  );
246
- await this.store.addPendingL1ToL2Messages(newMessages, l1Block);
247
- await this.store.cancelPendingL1ToL2EntryKeys(cancelledMessages, l1Block);
248
197
  }
249
198
 
250
- // ********** Events that are processed per L2 block **********
251
-
252
- const retrievedNewL1ToL2Messages = await retrieveNewL1ToL2Messages(
253
- this.publicClient,
254
- this.newInboxAddress,
255
- blockUntilSynced,
256
- lastL1Blocks.newMessages + 1n,
257
- currentL1BlockNumber,
258
- );
259
- await this.store.addNewL1ToL2Messages(
260
- retrievedNewL1ToL2Messages.retrievedData,
261
- // -1n because the function expects the last block in which the message was emitted and not the one after next
262
- // TODO(#4492): Check whether this could be cleaned up - `nextEthBlockNumber` value doesn't seem to be used much
263
- retrievedNewL1ToL2Messages.nextEthBlockNumber - 1n,
264
- );
199
+ await this.store.addL1ToL2Messages(retrievedL1ToL2Messages);
265
200
 
266
201
  // Read all data from chain and then write to our stores at the end
267
- const nextExpectedL2BlockNum = BigInt((await this.store.getBlockNumber()) + 1);
202
+ const nextExpectedL2BlockNum = BigInt((await this.store.getSynchedL2BlockNumber()) + 1);
268
203
 
269
204
  const retrievedBlockBodies = await retrieveBlockBodiesFromAvailabilityOracle(
270
205
  this.publicClient,
271
206
  this.availabilityOracleAddress,
272
207
  blockUntilSynced,
273
- lastL1Blocks.addedBlock + 1n,
208
+ lastL1Blocks.blocks + 1n,
274
209
  currentL1BlockNumber,
275
210
  );
276
211
 
277
212
  const blockBodies = retrievedBlockBodies.retrievedData.map(([blockBody]) => blockBody);
278
-
279
213
  await this.store.addBlockBodies(blockBodies);
280
214
 
281
- const retrievedBlockMetadata = await retrieveBlockMetadataFromRollup(
282
- this.publicClient,
283
- this.rollupAddress,
284
- blockUntilSynced,
285
- lastL1Blocks.addedBlock + 1n,
286
- currentL1BlockNumber,
287
- nextExpectedL2BlockNum,
288
- );
289
-
290
- const retrievedBodyHashes = retrievedBlockMetadata.retrievedData.map(
291
- ([header]) => header.contentCommitment.txsEffectsHash,
292
- );
215
+ // Now that we have block bodies we will retrieve block metadata and build L2 blocks from the bodies and
216
+ // the metadata
217
+ let retrievedBlocks: DataRetrieval<L2Block>;
218
+ {
219
+ const retrievedBlockMetadata = await retrieveBlockMetadataFromRollup(
220
+ this.publicClient,
221
+ this.rollupAddress,
222
+ blockUntilSynced,
223
+ lastL1Blocks.blocks + 1n,
224
+ currentL1BlockNumber,
225
+ nextExpectedL2BlockNum,
226
+ );
293
227
 
294
- const blockBodiesFromStore = await this.store.getBlockBodies(retrievedBodyHashes);
228
+ const retrievedBodyHashes = retrievedBlockMetadata.retrievedData.map(
229
+ ([header]) => header.contentCommitment.txsEffectsHash,
230
+ );
295
231
 
296
- if (retrievedBlockMetadata.retrievedData.length !== blockBodiesFromStore.length) {
297
- throw new Error('Block headers length does not equal block bodies length');
298
- }
232
+ const blockBodiesFromStore = await this.store.getBlockBodies(retrievedBodyHashes);
299
233
 
300
- const retrievedBlocks = {
301
- retrievedData: retrievedBlockMetadata.retrievedData.map(
302
- (blockMetadata, i) =>
303
- new L2Block(blockMetadata[1], blockMetadata[0], blockBodiesFromStore[i], blockMetadata[2]),
304
- ),
305
- };
234
+ if (retrievedBlockMetadata.retrievedData.length !== blockBodiesFromStore.length) {
235
+ throw new Error('Block headers length does not equal block bodies length');
236
+ }
306
237
 
307
- if (retrievedBlocks.retrievedData.length === 0) {
308
- return;
309
- } else {
310
- this.log(
311
- `Retrieved ${retrievedBlocks.retrievedData.length} new L2 blocks between L1 blocks ${
312
- lastL1Blocks.addedBlock + 1n
313
- } and ${currentL1BlockNumber}.`,
238
+ const blocks = retrievedBlockMetadata.retrievedData.map(
239
+ (blockMetadata, i) => new L2Block(blockMetadata[1], blockMetadata[0], blockBodiesFromStore[i]),
314
240
  );
315
- }
316
241
 
317
- // create the block number -> block hash mapping to ensure we retrieve the appropriate events
318
- const blockNumberToBodyHash: { [key: number]: Buffer | undefined } = {};
319
- retrievedBlocks.retrievedData.forEach((block: L2Block) => {
320
- blockNumberToBodyHash[block.number] = block.header.contentCommitment.txsEffectsHash;
321
- });
322
-
323
- this.log(`Retrieved ${retrievedBlocks.retrievedData.length} block(s) from chain`);
242
+ if (blocks.length === 0) {
243
+ return;
244
+ } else {
245
+ this.log(
246
+ `Retrieved ${blocks.length} new L2 blocks between L1 blocks ${
247
+ lastL1Blocks.blocks + 1n
248
+ } and ${currentL1BlockNumber}.`,
249
+ );
250
+ }
251
+
252
+ retrievedBlocks = {
253
+ lastProcessedL1BlockNumber: retrievedBlockMetadata.lastProcessedL1BlockNumber,
254
+ retrievedData: blocks,
255
+ };
256
+ }
324
257
 
325
258
  await Promise.all(
326
259
  retrievedBlocks.retrievedData.map(block => {
@@ -343,14 +276,7 @@ export class Archiver implements ArchiveSource {
343
276
  }),
344
277
  );
345
278
 
346
- // from retrieved L2Blocks, confirm L1 to L2 messages that have been published
347
- // from each l2block fetch all entryKeys in a flattened array:
348
- this.log(`Confirming l1 to l2 messages in store`);
349
- for (const block of retrievedBlocks.retrievedData) {
350
- await this.store.confirmL1ToL2EntryKeys(block.body.l1ToL2Messages);
351
- }
352
-
353
- await this.store.addBlocks(retrievedBlocks.retrievedData);
279
+ await this.store.addBlocks(retrievedBlocks);
354
280
  }
355
281
 
356
282
  /**
@@ -372,34 +298,13 @@ export class Archiver implements ArchiveSource {
372
298
  * @param allLogs - All logs emitted in a bunch of blocks.
373
299
  */
374
300
  private async storeDeployedContractInstances(allLogs: UnencryptedL2Log[], blockNum: number) {
375
- const contractInstances = ContractInstanceDeployedEvent.fromLogs(allLogs, InstanceDeployerAddress).map(e =>
376
- e.toContractInstance(),
377
- );
301
+ const contractInstances = ContractInstanceDeployedEvent.fromLogs(allLogs).map(e => e.toContractInstance());
378
302
  if (contractInstances.length > 0) {
379
303
  contractInstances.forEach(c => this.log(`Storing contract instance at ${c.address.toString()}`));
380
304
  await this.store.addContractInstances(contractInstances, blockNum);
381
305
  }
382
306
  }
383
307
 
384
- /**
385
- * Stores extended contract data as classes and instances.
386
- * Temporary solution until we source this data from the contract class registerer and instance deployer.
387
- * @param contracts - The extended contract data to be stored.
388
- * @param l2BlockNum - The L2 block number to which the contract data corresponds.
389
- * TODO(palla/purge-old-contract-deploy): Delete this method
390
- */
391
- async storeContractDataAsClassesAndInstances(contracts: ExtendedContractData[], l2BlockNum: number) {
392
- const classesAndInstances = contracts.map(extendedContractDataToContractClassAndInstance);
393
- await this.store.addContractClasses(
394
- classesAndInstances.map(([c, _]) => c),
395
- l2BlockNum,
396
- );
397
- await this.store.addContractInstances(
398
- classesAndInstances.map(([_, i]) => i),
399
- l2BlockNum,
400
- );
401
- }
402
-
403
308
  /**
404
309
  * Stops the archiver.
405
310
  * @returns A promise signalling completion of the stop process.
@@ -438,7 +343,7 @@ export class Archiver implements ArchiveSource {
438
343
  public async getBlock(number: number): Promise<L2Block | undefined> {
439
344
  // If the number provided is -ve, then return the latest block.
440
345
  if (number < 0) {
441
- number = await this.store.getBlockNumber();
346
+ number = await this.store.getSynchedL2BlockNumber();
442
347
  }
443
348
  const blocks = await this.store.getBlocks(number, 1);
444
349
  return blocks.length === 0 ? undefined : blocks[0];
@@ -452,72 +357,25 @@ export class Archiver implements ArchiveSource {
452
357
  return this.store.getSettledTxReceipt(txHash);
453
358
  }
454
359
 
455
- /**
456
- * Get the extended contract data for this contract.
457
- * @param contractAddress - The contract data address.
458
- * @returns The extended contract data or undefined if not found.
459
- */
460
- public async getExtendedContractData(contractAddress: AztecAddress): Promise<ExtendedContractData | undefined> {
461
- return (
462
- (await this.store.getExtendedContractData(contractAddress)) ?? this.makeExtendedContractDataFor(contractAddress)
463
- );
464
- }
465
-
466
- /**
467
- * Temporary method for creating a fake extended contract data out of classes and instances registered in the node.
468
- * Used as a fallback if the extended contract data is not found.
469
- * TODO(palla/purge-old-contract-deploy): Use proper classes
470
- */
471
- private async makeExtendedContractDataFor(address: AztecAddress): Promise<ExtendedContractData | undefined> {
472
- const instance = await this.store.getContractInstance(address);
473
- if (!instance) {
474
- return undefined;
475
- }
476
-
477
- const contractClass = await this.store.getContractClass(instance.contractClassId);
478
- if (!contractClass) {
479
- this.log.warn(`Class ${instance.contractClassId.toString()} for address ${address.toString()} not found`);
480
- return undefined;
481
- }
482
-
483
- return ExtendedContractData.fromClassAndInstance(contractClass, instance);
484
- }
485
-
486
- /**
487
- * Lookup the contract data for this contract.
488
- * Contains contract address & the ethereum portal address.
489
- * @param contractAddress - The contract data address.
490
- * @returns ContractData with the portal address (if we didn't throw an error).
491
- */
492
- public getContractData(contractAddress: AztecAddress): Promise<ContractData | undefined> {
493
- return this.makeContractDataFor(contractAddress);
494
- }
495
-
496
- /**
497
- * Temporary method for creating a fake contract data out of classes and instances registered in the node.
498
- * Used as a fallback if the extended contract data is not found.
499
- */
500
- private async makeContractDataFor(address: AztecAddress): Promise<ContractData | undefined> {
501
- const instance = await this.store.getContractInstance(address);
502
- if (!instance) {
503
- return undefined;
504
- }
505
-
506
- return new ContractData(address, instance.portalContractAddress);
507
- }
508
-
509
360
  /**
510
361
  * Gets the public function data for a contract.
511
- * @param contractAddress - The contract address containing the function to fetch.
362
+ * @param address - The contract address containing the function to fetch.
512
363
  * @param selector - The function selector of the function to fetch.
513
364
  * @returns The public function data (if found).
514
365
  */
515
366
  public async getPublicFunction(
516
- contractAddress: AztecAddress,
367
+ address: AztecAddress,
517
368
  selector: FunctionSelector,
518
- ): Promise<EncodedContractFunction | undefined> {
519
- const contractData = await this.getExtendedContractData(contractAddress);
520
- return contractData?.getPublicFunction(selector);
369
+ ): Promise<PublicFunction | undefined> {
370
+ const instance = await this.getContract(address);
371
+ if (!instance) {
372
+ throw new Error(`Contract ${address.toString()} not found`);
373
+ }
374
+ const contractClass = await this.getContractClass(instance.contractClassId);
375
+ if (!contractClass) {
376
+ throw new Error(`Contract class ${instance.contractClassId.toString()} for ${address.toString()} not found`);
377
+ }
378
+ return contractClass.publicFunctions.find(f => f.selector.equals(selector));
521
379
  }
522
380
 
523
381
  /**
@@ -545,7 +403,7 @@ export class Archiver implements ArchiveSource {
545
403
  * @returns The number of the latest L2 block processed by the block source implementation.
546
404
  */
547
405
  public getBlockNumber(): Promise<number> {
548
- return this.store.getBlockNumber();
406
+ return this.store.getSynchedL2BlockNumber();
549
407
  }
550
408
 
551
409
  public getContractClass(id: Fr): Promise<ContractClassPublic | undefined> {
@@ -557,69 +415,24 @@ export class Archiver implements ArchiveSource {
557
415
  }
558
416
 
559
417
  /**
560
- * Gets up to `limit` amount of pending L1 to L2 messages.
561
- * @param limit - The number of messages to return.
562
- * @returns The requested L1 to L2 messages' keys.
563
- */
564
- getPendingL1ToL2EntryKeys(limit: number): Promise<Fr[]> {
565
- return this.store.getPendingL1ToL2EntryKeys(limit);
566
- }
567
-
568
- /**
569
- * Gets the confirmed/consumed L1 to L2 message associated with the given entry key
570
- * @param entryKey - The entry key.
571
- * @returns The L1 to L2 message (throws if not found).
418
+ * Gets L1 to L2 message (to be) included in a given block.
419
+ * @param blockNumber - L2 block number to get messages for.
420
+ * @returns The L1 to L2 messages/leaves of the messages subtree (throws if not found).
572
421
  */
573
- getConfirmedL1ToL2Message(entryKey: Fr): Promise<L1ToL2Message> {
574
- return this.store.getConfirmedL1ToL2Message(entryKey);
422
+ getL1ToL2Messages(blockNumber: bigint): Promise<Fr[]> {
423
+ return this.store.getL1ToL2Messages(blockNumber);
575
424
  }
576
425
 
577
426
  /**
578
- * Gets new L1 to L2 message (to be) included in a given block.
579
- * @param blockNumber - L2 block number to get messages for.
580
- * @returns The L1 to L2 messages/leaves of the messages subtree (throws if not found).
427
+ * Gets the L1 to L2 message index in the L1 to L2 message tree.
428
+ * @param l1ToL2Message - The L1 to L2 message.
429
+ * @returns The index of the L1 to L2 message in the L1 to L2 message tree (undefined if not found).
581
430
  */
582
- getNewL1ToL2Messages(blockNumber: bigint): Promise<Fr[]> {
583
- return this.store.getNewL1ToL2Messages(blockNumber);
431
+ getL1ToL2MessageIndex(l1ToL2Message: Fr): Promise<bigint | undefined> {
432
+ return this.store.getL1ToL2MessageIndex(l1ToL2Message);
584
433
  }
585
434
 
586
435
  getContractClassIds(): Promise<Fr[]> {
587
436
  return this.store.getContractClassIds();
588
437
  }
589
438
  }
590
-
591
- /**
592
- * Converts ExtendedContractData into contract classes and instances.
593
- * Note that the conversion is not correct, since there is some data missing from the broadcasted ExtendedContractData.
594
- * The archiver will trust the ids broadcasted instead of trying to recompute them.
595
- * Eventually this function and ExtendedContractData altogether will be removed.
596
- */
597
- function extendedContractDataToContractClassAndInstance(
598
- data: ExtendedContractData,
599
- ): [ContractClassPublic, ContractInstanceWithAddress] {
600
- const contractClass: ContractClass = {
601
- version: 1,
602
- artifactHash: Fr.ZERO,
603
- publicFunctions: data.publicFunctions.map(f => ({
604
- selector: f.selector,
605
- bytecode: f.bytecode,
606
- isInternal: f.isInternal,
607
- })),
608
- privateFunctions: [],
609
- packedBytecode: data.bytecode,
610
- };
611
- const contractClassId = data.contractClassId;
612
- const contractInstance: ContractInstance = {
613
- version: 1,
614
- salt: data.saltedInitializationHash,
615
- contractClassId,
616
- initializationHash: data.saltedInitializationHash,
617
- portalContractAddress: data.contractData.portalContractAddress,
618
- publicKeysHash: data.publicKeyHash,
619
- };
620
- const address = data.contractData.contractAddress;
621
- return [
622
- { ...contractClass, id: contractClassId, privateFunctionsRoot: Fr.ZERO },
623
- { ...contractInstance, address },
624
- ];
625
- }
@@ -1,13 +1,11 @@
1
1
  import {
2
2
  Body,
3
- ExtendedContractData,
4
3
  GetUnencryptedLogsResponse,
5
- L1ToL2Message,
4
+ InboxLeaf,
6
5
  L2Block,
7
6
  L2BlockL2Logs,
8
7
  LogFilter,
9
8
  LogType,
10
- NewInboxLeaf,
11
9
  TxEffect,
12
10
  TxHash,
13
11
  TxReceipt,
@@ -16,19 +14,16 @@ import { Fr } from '@aztec/circuits.js';
16
14
  import { AztecAddress } from '@aztec/foundation/aztec-address';
17
15
  import { ContractClassPublic, ContractInstanceWithAddress } from '@aztec/types/contracts';
18
16
 
17
+ import { DataRetrieval } from './data_retrieval.js';
18
+
19
19
  /**
20
20
  * Represents the latest L1 block processed by the archiver for various objects in L2.
21
21
  */
22
22
  export type ArchiverL1SynchPoint = {
23
23
  /** The last L1 block that added a new L2 block. */
24
- addedBlock: bigint;
25
- /** The last L1 block that added messages from the new inbox. */
26
- // TODO(#4492): Clean this up and fix the naming
27
- newMessages: bigint;
28
- /** The last L1 block that added pending messages */
29
- addedMessages: bigint;
30
- /** The last L1 block that cancelled messages */
31
- cancelledMessages: bigint;
24
+ blocks: bigint;
25
+ /** The last L1 block that added L1 -> L2 messages from the Inbox. */
26
+ messages: bigint;
32
27
  };
33
28
 
34
29
  /**
@@ -38,10 +33,10 @@ export type ArchiverL1SynchPoint = {
38
33
  export interface ArchiverDataStore {
39
34
  /**
40
35
  * Append new blocks to the store's list.
41
- * @param blocks - The L2 blocks to be added to the store.
36
+ * @param blocks - The L2 blocks to be added to the store and the last processed L1 block.
42
37
  * @returns True if the operation is successful.
43
38
  */
44
- addBlocks(blocks: L2Block[]): Promise<boolean>;
39
+ addBlocks(blocks: DataRetrieval<L2Block>): Promise<boolean>;
45
40
 
46
41
  /**
47
42
  * Append new block bodies to the store's list.
@@ -94,59 +89,25 @@ export interface ArchiverDataStore {
94
89
  ): Promise<boolean>;
95
90
 
96
91
  /**
97
- * Append new L1 to L2 messages to the store.
98
- * @param messages - The L1 to L2 messages to be added to the store.
99
- * @param lastMessageL1BlockNumber - The L1 block number in which the last message was emitted.
100
- * @returns True if the operation is successful.
101
- */
102
- addNewL1ToL2Messages(messages: NewInboxLeaf[], lastMessageL1BlockNumber: bigint): Promise<boolean>;
103
-
104
- /**
105
- * Append new pending L1 to L2 messages to the store.
106
- * @param messages - The L1 to L2 messages to be added to the store.
107
- * @param l1BlockNumber - The block number of the L1 block that added the messages.
108
- * @returns True if the operation is successful.
109
- * TODO(#4492): Nuke the following when purging the old inbox
110
- */
111
- addPendingL1ToL2Messages(messages: L1ToL2Message[], l1BlockNumber: bigint): Promise<boolean>;
112
-
113
- /**
114
- * Remove pending L1 to L2 messages from the store (if they were cancelled).
115
- * @param entryKeys - The entry keys to be removed from the store.
116
- * @param l1BlockNumber - The block number of the L1 block that cancelled the messages.
92
+ * Append L1 to L2 messages to the store.
93
+ * @param messages - The L1 to L2 messages to be added to the store and the last processed L1 block.
117
94
  * @returns True if the operation is successful.
118
- * TODO(#4492): Nuke the following when purging the old inbox
119
95
  */
120
- cancelPendingL1ToL2EntryKeys(entryKeys: Fr[], l1BlockNumber: bigint): Promise<boolean>;
96
+ addL1ToL2Messages(messages: DataRetrieval<InboxLeaf>): Promise<boolean>;
121
97
 
122
98
  /**
123
- * Messages that have been published in an L2 block are confirmed.
124
- * Add them to the confirmed store, also remove them from the pending store.
125
- * @param entryKeys - The entry keys to be removed from the store.
126
- * @returns True if the operation is successful.
127
- */
128
- confirmL1ToL2EntryKeys(entryKeys: Fr[]): Promise<boolean>;
129
-
130
- /**
131
- * Gets up to `limit` amount of pending L1 to L2 messages, sorted by fee
132
- * @param limit - The number of entries to return (by default NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).
133
- * @returns The requested L1 to L2 entry keys.
134
- */
135
- getPendingL1ToL2EntryKeys(limit: number): Promise<Fr[]>;
136
-
137
- /**
138
- * Gets the confirmed L1 to L2 message corresponding to the given entry key.
139
- * @param entryKey - The entry key to look up.
140
- * @returns The requested L1 to L2 message or throws if not found.
99
+ * Gets L1 to L2 message (to be) included in a given block.
100
+ * @param blockNumber - L2 block number to get messages for.
101
+ * @returns The L1 to L2 messages/leaves of the messages subtree (throws if not found).
141
102
  */
142
- getConfirmedL1ToL2Message(entryKey: Fr): Promise<L1ToL2Message>;
103
+ getL1ToL2Messages(blockNumber: bigint): Promise<Fr[]>;
143
104
 
144
105
  /**
145
- * Gets new L1 to L2 message (to be) included in a given block.
146
- * @param blockNumber - L2 block number to get messages for.
147
- * @returns The L1 to L2 messages/leaves of the messages subtree (throws if not found).
106
+ * Gets the L1 to L2 message index in the L1 to L2 message tree.
107
+ * @param l1ToL2Message - The L1 to L2 message.
108
+ * @returns The index of the L1 to L2 message in the L1 to L2 message tree (undefined if not found).
148
109
  */
149
- getNewL1ToL2Messages(blockNumber: bigint): Promise<Fr[]>;
110
+ getL1ToL2MessageIndex(l1ToL2Message: Fr): Promise<bigint | undefined>;
150
111
 
151
112
  /**
152
113
  * Gets up to `limit` amount of logs starting from `from`.
@@ -164,31 +125,16 @@ export interface ArchiverDataStore {
164
125
  */
165
126
  getUnencryptedLogs(filter: LogFilter): Promise<GetUnencryptedLogsResponse>;
166
127
 
167
- /**
168
- * Add new extended contract data from an L2 block to the store's list.
169
- * @param data - List of contracts' data to be added.
170
- * @param blockNum - Number of the L2 block the contract data was deployed in.
171
- * @returns True if the operation is successful.
172
- */
173
- addExtendedContractData(data: ExtendedContractData[], blockNum: number): Promise<boolean>;
174
-
175
- /**
176
- * Get the extended contract data for this contract.
177
- * @param contractAddress - The contract data address.
178
- * @returns The extended contract data or undefined if not found.
179
- */
180
- getExtendedContractData(contractAddress: AztecAddress): Promise<ExtendedContractData | undefined>;
181
-
182
128
  /**
183
129
  * Gets the number of the latest L2 block processed.
184
130
  * @returns The number of the latest L2 block processed.
185
131
  */
186
- getBlockNumber(): Promise<number>;
132
+ getSynchedL2BlockNumber(): Promise<number>;
187
133
 
188
134
  /**
189
- * Gets the last L1 block number processed by the archiver
135
+ * Gets the synch point of the archiver
190
136
  */
191
- getL1BlockNumber(): Promise<ArchiverL1SynchPoint>;
137
+ getSynchedL1BlockNumbers(): Promise<ArchiverL1SynchPoint>;
192
138
 
193
139
  /**
194
140
  * Add new contract classes from an L2 block to the store's list.