@aztec/archiver 0.26.6 → 0.27.1

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 (49) hide show
  1. package/README.md +2 -3
  2. package/dest/archiver/archiver.d.ts +12 -16
  3. package/dest/archiver/archiver.d.ts.map +1 -1
  4. package/dest/archiver/archiver.js +38 -36
  5. package/dest/archiver/archiver_store.d.ts +18 -21
  6. package/dest/archiver/archiver_store.d.ts.map +1 -1
  7. package/dest/archiver/archiver_store_test_suite.d.ts.map +1 -1
  8. package/dest/archiver/archiver_store_test_suite.js +46 -90
  9. package/dest/archiver/config.d.ts.map +1 -1
  10. package/dest/archiver/config.js +2 -5
  11. package/dest/archiver/data_retrieval.d.ts +10 -12
  12. package/dest/archiver/data_retrieval.d.ts.map +1 -1
  13. package/dest/archiver/data_retrieval.js +23 -22
  14. package/dest/archiver/eth_log_handlers.d.ts +17 -20
  15. package/dest/archiver/eth_log_handlers.d.ts.map +1 -1
  16. package/dest/archiver/eth_log_handlers.js +35 -52
  17. package/dest/archiver/kv_archiver_store/block_store.d.ts.map +1 -1
  18. package/dest/archiver/kv_archiver_store/block_store.js +1 -9
  19. package/dest/archiver/kv_archiver_store/contract_store.d.ts +1 -21
  20. package/dest/archiver/kv_archiver_store/contract_store.d.ts.map +1 -1
  21. package/dest/archiver/kv_archiver_store/contract_store.js +1 -36
  22. package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts +14 -21
  23. package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts.map +1 -1
  24. package/dest/archiver/kv_archiver_store/kv_archiver_store.js +25 -28
  25. package/dest/archiver/kv_archiver_store/message_store.d.ts +11 -1
  26. package/dest/archiver/kv_archiver_store/message_store.d.ts.map +1 -1
  27. package/dest/archiver/kv_archiver_store/message_store.js +57 -5
  28. package/dest/archiver/memory_archiver_store/l1_to_l2_message_store.d.ts +18 -1
  29. package/dest/archiver/memory_archiver_store/l1_to_l2_message_store.d.ts.map +1 -1
  30. package/dest/archiver/memory_archiver_store/l1_to_l2_message_store.js +48 -1
  31. package/dest/archiver/memory_archiver_store/memory_archiver_store.d.ts +18 -21
  32. package/dest/archiver/memory_archiver_store/memory_archiver_store.d.ts.map +1 -1
  33. package/dest/archiver/memory_archiver_store/memory_archiver_store.js +32 -45
  34. package/dest/index.d.ts.map +1 -1
  35. package/dest/index.js +15 -3
  36. package/package.json +9 -9
  37. package/src/archiver/archiver.ts +46 -46
  38. package/src/archiver/archiver_store.ts +21 -24
  39. package/src/archiver/archiver_store_test_suite.ts +54 -115
  40. package/src/archiver/config.ts +0 -4
  41. package/src/archiver/data_retrieval.ts +30 -35
  42. package/src/archiver/eth_log_handlers.ts +42 -74
  43. package/src/archiver/kv_archiver_store/block_store.ts +0 -10
  44. package/src/archiver/kv_archiver_store/contract_store.ts +1 -44
  45. package/src/archiver/kv_archiver_store/kv_archiver_store.ts +26 -31
  46. package/src/archiver/kv_archiver_store/message_store.ts +60 -3
  47. package/src/archiver/memory_archiver_store/l1_to_l2_message_store.ts +48 -1
  48. package/src/archiver/memory_archiver_store/memory_archiver_store.ts +36 -48
  49. package/src/index.ts +15 -2
@@ -1,6 +1,5 @@
1
1
  import {
2
2
  Body,
3
- ContractData,
4
3
  ExtendedContractData,
5
4
  ExtendedUnencryptedL2Log,
6
5
  GetUnencryptedLogsResponse,
@@ -11,6 +10,7 @@ import {
11
10
  LogFilter,
12
11
  LogId,
13
12
  LogType,
13
+ NewInboxLeaf,
14
14
  TxEffect,
15
15
  TxHash,
16
16
  TxReceipt,
@@ -22,7 +22,7 @@ import { AztecAddress } from '@aztec/foundation/aztec-address';
22
22
  import { ContractClassPublic, ContractInstanceWithAddress } from '@aztec/types/contracts';
23
23
 
24
24
  import { ArchiverDataStore } from '../archiver_store.js';
25
- import { L1ToL2MessageStore, PendingL1ToL2MessageStore } from './l1_to_l2_message_store.js';
25
+ import { L1ToL2MessageStore, NewL1ToL2MessageStore, PendingL1ToL2MessageStore } from './l1_to_l2_message_store.js';
26
26
 
27
27
  /**
28
28
  * Simple, in-memory implementation of an archiver data store.
@@ -65,6 +65,9 @@ export class MemoryArchiverStore implements ArchiverDataStore {
65
65
  */
66
66
  private extendedContractData: Map<string, ExtendedContractData> = new Map();
67
67
 
68
+ // TODO(#4492): Nuke the other message stores
69
+ private newL1ToL2Messages = new NewL1ToL2MessageStore();
70
+
68
71
  /**
69
72
  * Contains all the confirmed L1 to L2 messages (i.e. messages that were consumed in an L2 block)
70
73
  * It is a map of entryKey to the corresponding L1 to L2 message and the number of times it has appeared
@@ -80,6 +83,7 @@ export class MemoryArchiverStore implements ArchiverDataStore {
80
83
 
81
84
  private contractInstances: Map<string, ContractInstanceWithAddress> = new Map();
82
85
 
86
+ private lastL1BlockNewMessages: bigint = 0n;
83
87
  private lastL1BlockAddedMessages: bigint = 0n;
84
88
  private lastL1BlockCancelledMessages: bigint = 0n;
85
89
 
@@ -173,6 +177,24 @@ export class MemoryArchiverStore implements ArchiverDataStore {
173
177
  return Promise.resolve(true);
174
178
  }
175
179
 
180
+ /**
181
+ * Append new L1 to L2 messages to the store.
182
+ * @param messages - The L1 to L2 messages to be added to the store.
183
+ * @param lastMessageL1BlockNumber - The L1 block number in which the last message was emitted.
184
+ * @returns True if the operation is successful.
185
+ */
186
+ public addNewL1ToL2Messages(messages: NewInboxLeaf[], lastMessageL1BlockNumber: bigint): Promise<boolean> {
187
+ if (lastMessageL1BlockNumber <= this.lastL1BlockNewMessages) {
188
+ return Promise.resolve(false);
189
+ }
190
+
191
+ this.lastL1BlockNewMessages = lastMessageL1BlockNumber;
192
+ for (const message of messages) {
193
+ this.newL1ToL2Messages.addMessage(message);
194
+ }
195
+ return Promise.resolve(true);
196
+ }
197
+
176
198
  /**
177
199
  * Append new pending L1 to L2 messages to the store.
178
200
  * @param messages - The L1 to L2 messages to be added to the store.
@@ -321,6 +343,15 @@ export class MemoryArchiverStore implements ArchiverDataStore {
321
343
  return Promise.resolve(message);
322
344
  }
323
345
 
346
+ /**
347
+ * Gets new L1 to L2 message (to be) included in a given block.
348
+ * @param blockNumber - L2 block number to get messages for.
349
+ * @returns The L1 to L2 messages/leaves of the messages subtree (throws if not found).
350
+ */
351
+ getNewL1ToL2Messages(blockNumber: bigint): Promise<Buffer[]> {
352
+ return Promise.resolve(this.newL1ToL2Messages.getMessages(blockNumber));
353
+ }
354
+
324
355
  /**
325
356
  * Gets up to `limit` amount of logs starting from `from`.
326
357
  * @param from - Number of the L2 block to which corresponds the first logs to be returned.
@@ -427,6 +458,7 @@ export class MemoryArchiverStore implements ArchiverDataStore {
427
458
 
428
459
  /**
429
460
  * Get the extended contract data for this contract.
461
+ * TODO(palla/purge-old-contract-deploy): Delete me?
430
462
  * @param contractAddress - The contract data address.
431
463
  * @returns The extended contract data or undefined if not found.
432
464
  */
@@ -435,52 +467,6 @@ export class MemoryArchiverStore implements ArchiverDataStore {
435
467
  return Promise.resolve(result);
436
468
  }
437
469
 
438
- /**
439
- * Lookup all contract data in an L2 block.
440
- * @param blockNum - The block number to get all contract data from.
441
- * @returns All extended contract data in the block (if found).
442
- */
443
- public getExtendedContractDataInBlock(blockNum: number): Promise<ExtendedContractData[]> {
444
- if (blockNum > this.l2BlockContexts.length) {
445
- return Promise.resolve([]);
446
- }
447
- return Promise.resolve(this.extendedContractDataByBlock[blockNum] || []);
448
- }
449
-
450
- /**
451
- * Get basic info for an L2 contract.
452
- * Contains contract address & the ethereum portal address.
453
- * @param contractAddress - The contract data address.
454
- * @returns ContractData with the portal address (if we didn't throw an error).
455
- */
456
- public getContractData(contractAddress: AztecAddress): Promise<ContractData | undefined> {
457
- if (contractAddress.isZero()) {
458
- return Promise.resolve(undefined);
459
- }
460
- for (const blockContext of this.l2BlockContexts) {
461
- for (const contractData of blockContext.block.body.txEffects.flatMap(txEffect => txEffect.contractData)) {
462
- if (contractData.contractAddress.equals(contractAddress)) {
463
- return Promise.resolve(contractData);
464
- }
465
- }
466
- }
467
- return Promise.resolve(undefined);
468
- }
469
-
470
- /**
471
- * Get basic info for an all L2 contracts deployed in a block.
472
- * Contains contract address & the ethereum portal address.
473
- * @param l2BlockNum - Number of the L2 block where contracts were deployed.
474
- * @returns ContractData with the portal address (if we didn't throw an error).
475
- */
476
- public getContractDataInBlock(l2BlockNum: number): Promise<ContractData[] | undefined> {
477
- if (l2BlockNum > this.l2BlockContexts.length) {
478
- return Promise.resolve([]);
479
- }
480
- const block: L2Block | undefined = this.l2BlockContexts[l2BlockNum - INITIAL_L2_BLOCK_NUM]?.block;
481
- return Promise.resolve(block?.body.txEffects.flatMap(txEffect => txEffect.contractData));
482
- }
483
-
484
470
  /**
485
471
  * Gets the number of the latest L2 block processed.
486
472
  * @returns The number of the latest L2 block processed.
@@ -494,11 +480,13 @@ export class MemoryArchiverStore implements ArchiverDataStore {
494
480
 
495
481
  public getL1BlockNumber() {
496
482
  const addedBlock = this.l2BlockContexts[this.l2BlockContexts.length - 1]?.block?.getL1BlockNumber() ?? 0n;
483
+ const newMessages = this.lastL1BlockNewMessages;
497
484
  const addedMessages = this.lastL1BlockAddedMessages;
498
485
  const cancelledMessages = this.lastL1BlockCancelledMessages;
499
486
 
500
487
  return Promise.resolve({
501
488
  addedBlock,
489
+ newMessages,
502
490
  addedMessages,
503
491
  cancelledMessages,
504
492
  });
package/src/index.ts CHANGED
@@ -1,7 +1,9 @@
1
+ import { EthAddress } from '@aztec/foundation/eth-address';
1
2
  import { createDebugLogger } from '@aztec/foundation/log';
2
3
  import { fileURLToPath } from '@aztec/foundation/url';
4
+ import { RollupAbi } from '@aztec/l1-artifacts';
3
5
 
4
- import { createPublicClient, http } from 'viem';
6
+ import { createPublicClient, getAddress, getContract, http } from 'viem';
5
7
  import { localhost } from 'viem/chains';
6
8
 
7
9
  import { Archiver, getConfigEnvVars } from './archiver/index.js';
@@ -27,13 +29,24 @@ async function main() {
27
29
 
28
30
  const archiverStore = new MemoryArchiverStore(1000);
29
31
 
32
+ // TODO(#4492): Nuke this once the old inbox is purged
33
+ let newInboxAddress!: EthAddress;
34
+ {
35
+ const rollup = getContract({
36
+ address: getAddress(l1Contracts.rollupAddress.toString()),
37
+ abi: RollupAbi,
38
+ client: publicClient,
39
+ });
40
+ newInboxAddress = EthAddress.fromString(await rollup.read.NEW_INBOX());
41
+ }
42
+
30
43
  const archiver = new Archiver(
31
44
  publicClient,
32
45
  l1Contracts.rollupAddress,
33
46
  l1Contracts.availabilityOracleAddress,
34
47
  l1Contracts.inboxAddress,
48
+ newInboxAddress,
35
49
  l1Contracts.registryAddress,
36
- l1Contracts.contractDeploymentEmitterAddress,
37
50
  archiverStore,
38
51
  );
39
52