@aztec/archiver 0.80.0 → 0.81.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 (41) hide show
  1. package/dest/archiver/archiver.d.ts +5 -9
  2. package/dest/archiver/archiver.d.ts.map +1 -1
  3. package/dest/archiver/archiver.js +36 -49
  4. package/dest/archiver/archiver_store.d.ts +5 -4
  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 +104 -91
  8. package/dest/archiver/data_retrieval.d.ts +3 -4
  9. package/dest/archiver/data_retrieval.d.ts.map +1 -1
  10. package/dest/archiver/data_retrieval.js +8 -3
  11. package/dest/archiver/index.d.ts +1 -1
  12. package/dest/archiver/index.d.ts.map +1 -1
  13. package/dest/archiver/kv_archiver_store/block_store.d.ts +6 -6
  14. package/dest/archiver/kv_archiver_store/block_store.d.ts.map +1 -1
  15. package/dest/archiver/kv_archiver_store/block_store.js +24 -21
  16. package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts +4 -4
  17. package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts.map +1 -1
  18. package/dest/archiver/kv_archiver_store/kv_archiver_store.js +2 -3
  19. package/dest/archiver/kv_archiver_store/log_store.d.ts.map +1 -1
  20. package/dest/archiver/kv_archiver_store/log_store.js +9 -41
  21. package/dest/archiver/memory_archiver_store/memory_archiver_store.d.ts +4 -4
  22. package/dest/archiver/memory_archiver_store/memory_archiver_store.d.ts.map +1 -1
  23. package/dest/archiver/memory_archiver_store/memory_archiver_store.js +25 -54
  24. package/dest/archiver/structs/published.d.ts +1 -10
  25. package/dest/archiver/structs/published.d.ts.map +1 -1
  26. package/dest/archiver/structs/published.js +1 -1
  27. package/dest/test/mock_l2_block_source.d.ts +9 -0
  28. package/dest/test/mock_l2_block_source.d.ts.map +1 -1
  29. package/dest/test/mock_l2_block_source.js +13 -0
  30. package/package.json +13 -13
  31. package/src/archiver/archiver.ts +44 -60
  32. package/src/archiver/archiver_store.ts +5 -4
  33. package/src/archiver/archiver_store_test_suite.ts +116 -93
  34. package/src/archiver/data_retrieval.ts +11 -10
  35. package/src/archiver/index.ts +1 -1
  36. package/src/archiver/kv_archiver_store/block_store.ts +28 -27
  37. package/src/archiver/kv_archiver_store/kv_archiver_store.ts +5 -6
  38. package/src/archiver/kv_archiver_store/log_store.ts +11 -59
  39. package/src/archiver/memory_archiver_store/memory_archiver_store.ts +35 -66
  40. package/src/archiver/structs/published.ts +1 -11
  41. package/src/test/mock_l2_block_source.ts +14 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/archiver",
3
- "version": "0.80.0",
3
+ "version": "0.81.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./dest/index.js",
@@ -64,18 +64,18 @@
64
64
  ]
65
65
  },
66
66
  "dependencies": {
67
- "@aztec/blob-lib": "0.80.0",
68
- "@aztec/blob-sink": "0.80.0",
69
- "@aztec/constants": "0.80.0",
70
- "@aztec/ethereum": "0.80.0",
71
- "@aztec/foundation": "0.80.0",
72
- "@aztec/kv-store": "0.80.0",
73
- "@aztec/l1-artifacts": "0.80.0",
74
- "@aztec/noir-contracts.js": "0.80.0",
75
- "@aztec/noir-protocol-circuits-types": "0.80.0",
76
- "@aztec/protocol-contracts": "0.80.0",
77
- "@aztec/stdlib": "0.80.0",
78
- "@aztec/telemetry-client": "0.80.0",
67
+ "@aztec/blob-lib": "0.81.0",
68
+ "@aztec/blob-sink": "0.81.0",
69
+ "@aztec/constants": "0.81.0",
70
+ "@aztec/ethereum": "0.81.0",
71
+ "@aztec/foundation": "0.81.0",
72
+ "@aztec/kv-store": "0.81.0",
73
+ "@aztec/l1-artifacts": "0.81.0",
74
+ "@aztec/noir-contracts.js": "0.81.0",
75
+ "@aztec/noir-protocol-circuits-types": "0.81.0",
76
+ "@aztec/protocol-contracts": "0.81.0",
77
+ "@aztec/stdlib": "0.81.0",
78
+ "@aztec/telemetry-client": "0.81.0",
79
79
  "debug": "^4.3.4",
80
80
  "lodash.groupby": "^4.6.0",
81
81
  "lodash.omit": "^4.5.0",
@@ -32,7 +32,6 @@ import {
32
32
  type ContractDataSource,
33
33
  type ContractInstanceWithAddress,
34
34
  type ExecutablePrivateFunctionWithMembershipProof,
35
- type PublicFunction,
36
35
  type UnconstrainedFunctionWithMembershipProof,
37
36
  computePublicBytecodeCommitment,
38
37
  isValidPrivateFunctionMembershipProof,
@@ -63,7 +62,7 @@ import { retrieveBlocksFromRollup, retrieveL1ToL2Messages } from './data_retriev
63
62
  import { NoBlobBodiesFoundError } from './errors.js';
64
63
  import { ArchiverInstrumentation } from './instrumentation.js';
65
64
  import type { DataRetrieval } from './structs/data_retrieval.js';
66
- import type { L1Published } from './structs/published.js';
65
+ import type { PublishedL2Block } from './structs/published.js';
67
66
 
68
67
  /**
69
68
  * Helper interface to combine all sources this archiver implementation provides.
@@ -517,26 +516,26 @@ export class Archiver extends EventEmitter implements ArchiveSource, Traceable {
517
516
  );
518
517
 
519
518
  for (const block of retrievedBlocks) {
520
- this.log.debug(`Ingesting new L2 block ${block.data.number} with ${block.data.body.txEffects.length} txs`, {
521
- blockHash: block.data.hash(),
519
+ this.log.debug(`Ingesting new L2 block ${block.block.number} with ${block.block.body.txEffects.length} txs`, {
520
+ blockHash: block.block.hash(),
522
521
  l1BlockNumber: block.l1.blockNumber,
523
- ...block.data.header.globalVariables.toInspect(),
524
- ...block.data.getStats(),
522
+ ...block.block.header.globalVariables.toInspect(),
523
+ ...block.block.getStats(),
525
524
  });
526
525
  }
527
526
 
528
527
  const [processDuration] = await elapsed(() => this.store.addBlocks(retrievedBlocks));
529
528
  this.instrumentation.processNewBlocks(
530
529
  processDuration / retrievedBlocks.length,
531
- retrievedBlocks.map(b => b.data),
530
+ retrievedBlocks.map(b => b.block),
532
531
  );
533
532
 
534
533
  for (const block of retrievedBlocks) {
535
- this.log.info(`Downloaded L2 block ${block.data.number}`, {
536
- blockHash: block.data.hash(),
537
- blockNumber: block.data.number,
538
- txCount: block.data.body.txEffects.length,
539
- globalVariables: block.data.header.globalVariables.toInspect(),
534
+ this.log.info(`Downloaded L2 block ${block.block.number}`, {
535
+ blockHash: block.block.hash(),
536
+ blockNumber: block.block.number,
537
+ txCount: block.block.body.txEffects.length,
538
+ globalVariables: block.block.header.globalVariables.toInspect(),
540
539
  });
541
540
  }
542
541
  } while (searchEndBlock < currentL1BlockNumber);
@@ -648,11 +647,16 @@ export class Archiver extends EventEmitter implements ArchiveSource, Traceable {
648
647
  * @param proven - If true, only return blocks that have been proven.
649
648
  * @returns The requested L2 blocks.
650
649
  */
651
- public async getBlocks(from: number, limit: number, proven?: boolean): Promise<L2Block[]> {
650
+ public getBlocks(from: number, limit: number, proven?: boolean): Promise<L2Block[]> {
651
+ return this.getPublishedBlocks(from, limit, proven).then(blocks => blocks.map(b => b.block));
652
+ }
653
+
654
+ /** Equivalent to getBlocks but includes publish data. */
655
+ public async getPublishedBlocks(from: number, limit: number, proven?: boolean): Promise<PublishedL2Block[]> {
652
656
  const limitWithProven = proven
653
657
  ? Math.min(limit, Math.max((await this.store.getProvenL2BlockNumber()) - from + 1, 0))
654
658
  : limit;
655
- return limitWithProven === 0 ? [] : (await this.store.getBlocks(from, limitWithProven)).map(b => b.data);
659
+ return limitWithProven === 0 ? [] : await this.store.getBlocks(from, limitWithProven);
656
660
  }
657
661
 
658
662
  /**
@@ -669,7 +673,7 @@ export class Archiver extends EventEmitter implements ArchiveSource, Traceable {
669
673
  return undefined;
670
674
  }
671
675
  const blocks = await this.store.getBlocks(number, 1);
672
- return blocks.length === 0 ? undefined : blocks[0].data;
676
+ return blocks.length === 0 ? undefined : blocks[0].block;
673
677
  }
674
678
 
675
679
  public async getBlockHeader(number: number | 'latest'): Promise<BlockHeader | undefined> {
@@ -691,29 +695,6 @@ export class Archiver extends EventEmitter implements ArchiveSource, Traceable {
691
695
  return this.store.getSettledTxReceipt(txHash);
692
696
  }
693
697
 
694
- /**
695
- * Gets the public function data for a contract.
696
- * @param address - The contract address containing the function to fetch.
697
- * @param selector - The function selector of the function to fetch.
698
- * @returns The public function data (if found).
699
- */
700
- public async getPublicFunction(
701
- address: AztecAddress,
702
- selector: FunctionSelector,
703
- ): Promise<PublicFunction | undefined> {
704
- const instance = await this.getContract(address);
705
- if (!instance) {
706
- throw new Error(`Contract ${address.toString()} not found`);
707
- }
708
- const contractClass = await this.getContractClass(instance.currentContractClassId);
709
- if (!contractClass) {
710
- throw new Error(
711
- `Contract class ${instance.currentContractClassId.toString()} for ${address.toString()} not found`,
712
- );
713
- }
714
- return contractClass.publicFunctions.find(f => f.selector.equals(selector));
715
- }
716
-
717
698
  /**
718
699
  * Retrieves all private logs from up to `limit` blocks, starting from the block number `from`.
719
700
  * @param from - The block number from which to begin retrieving logs.
@@ -788,8 +769,11 @@ export class Archiver extends EventEmitter implements ArchiveSource, Traceable {
788
769
  return this.store.getBytecodeCommitment(id);
789
770
  }
790
771
 
791
- public getContract(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
792
- return this.store.getContractInstance(address);
772
+ public async getContract(
773
+ address: AztecAddress,
774
+ blockNumber?: number,
775
+ ): Promise<ContractInstanceWithAddress | undefined> {
776
+ return this.store.getContractInstance(address, blockNumber ?? (await this.getBlockNumber()));
793
777
  }
794
778
 
795
779
  /**
@@ -1048,25 +1032,25 @@ class ArchiverStoreHelper
1048
1032
  return true;
1049
1033
  }
1050
1034
 
1051
- async addBlocks(blocks: L1Published<L2Block>[]): Promise<boolean> {
1035
+ async addBlocks(blocks: PublishedL2Block[]): Promise<boolean> {
1052
1036
  const opResults = await Promise.all([
1053
- this.store.addLogs(blocks.map(block => block.data)),
1037
+ this.store.addLogs(blocks.map(block => block.block)),
1054
1038
  // Unroll all logs emitted during the retrieved blocks and extract any contract classes and instances from them
1055
1039
  ...blocks.map(async block => {
1056
- const contractClassLogs = block.data.body.txEffects.flatMap(txEffect => txEffect.contractClassLogs);
1040
+ const contractClassLogs = block.block.body.txEffects.flatMap(txEffect => txEffect.contractClassLogs);
1057
1041
  // ContractInstanceDeployed event logs are broadcast in privateLogs.
1058
- const privateLogs = block.data.body.txEffects.flatMap(txEffect => txEffect.privateLogs);
1059
- const publicLogs = block.data.body.txEffects.flatMap(txEffect => txEffect.publicLogs);
1042
+ const privateLogs = block.block.body.txEffects.flatMap(txEffect => txEffect.privateLogs);
1043
+ const publicLogs = block.block.body.txEffects.flatMap(txEffect => txEffect.publicLogs);
1060
1044
  return (
1061
1045
  await Promise.all([
1062
- this.#updateRegisteredContractClasses(contractClassLogs, block.data.number, Operation.Store),
1063
- this.#updateDeployedContractInstances(privateLogs, block.data.number, Operation.Store),
1064
- this.#updateUpdatedContractInstances(publicLogs, block.data.number, Operation.Store),
1065
- this.#storeBroadcastedIndividualFunctions(contractClassLogs, block.data.number),
1046
+ this.#updateRegisteredContractClasses(contractClassLogs, block.block.number, Operation.Store),
1047
+ this.#updateDeployedContractInstances(privateLogs, block.block.number, Operation.Store),
1048
+ this.#updateUpdatedContractInstances(publicLogs, block.block.number, Operation.Store),
1049
+ this.#storeBroadcastedIndividualFunctions(contractClassLogs, block.block.number),
1066
1050
  ])
1067
1051
  ).every(Boolean);
1068
1052
  }),
1069
- this.store.addNullifiers(blocks.map(block => block.data)),
1053
+ this.store.addNullifiers(blocks.map(block => block.block)),
1070
1054
  this.store.addBlocks(blocks),
1071
1055
  ]);
1072
1056
 
@@ -1085,28 +1069,28 @@ class ArchiverStoreHelper
1085
1069
  const opResults = await Promise.all([
1086
1070
  // Unroll all logs emitted during the retrieved blocks and extract any contract classes and instances from them
1087
1071
  ...blocks.map(async block => {
1088
- const contractClassLogs = block.data.body.txEffects.flatMap(txEffect => txEffect.contractClassLogs);
1072
+ const contractClassLogs = block.block.body.txEffects.flatMap(txEffect => txEffect.contractClassLogs);
1089
1073
  // ContractInstanceDeployed event logs are broadcast in privateLogs.
1090
- const privateLogs = block.data.body.txEffects.flatMap(txEffect => txEffect.privateLogs);
1091
- const publicLogs = block.data.body.txEffects.flatMap(txEffect => txEffect.publicLogs);
1074
+ const privateLogs = block.block.body.txEffects.flatMap(txEffect => txEffect.privateLogs);
1075
+ const publicLogs = block.block.body.txEffects.flatMap(txEffect => txEffect.publicLogs);
1092
1076
 
1093
1077
  return (
1094
1078
  await Promise.all([
1095
- this.#updateRegisteredContractClasses(contractClassLogs, block.data.number, Operation.Delete),
1096
- this.#updateDeployedContractInstances(privateLogs, block.data.number, Operation.Delete),
1097
- this.#updateUpdatedContractInstances(publicLogs, block.data.number, Operation.Delete),
1079
+ this.#updateRegisteredContractClasses(contractClassLogs, block.block.number, Operation.Delete),
1080
+ this.#updateDeployedContractInstances(privateLogs, block.block.number, Operation.Delete),
1081
+ this.#updateUpdatedContractInstances(publicLogs, block.block.number, Operation.Delete),
1098
1082
  ])
1099
1083
  ).every(Boolean);
1100
1084
  }),
1101
1085
 
1102
- this.store.deleteLogs(blocks.map(b => b.data)),
1086
+ this.store.deleteLogs(blocks.map(b => b.block)),
1103
1087
  this.store.unwindBlocks(from, blocksToUnwind),
1104
1088
  ]);
1105
1089
 
1106
1090
  return opResults.every(Boolean);
1107
1091
  }
1108
1092
 
1109
- getBlocks(from: number, limit: number): Promise<L1Published<L2Block>[]> {
1093
+ getBlocks(from: number, limit: number): Promise<PublishedL2Block[]> {
1110
1094
  return this.store.getBlocks(from, limit);
1111
1095
  }
1112
1096
  getBlockHeaders(from: number, limit: number): Promise<BlockHeader[]> {
@@ -1166,8 +1150,8 @@ class ArchiverStoreHelper
1166
1150
  getBytecodeCommitment(contractClassId: Fr): Promise<Fr | undefined> {
1167
1151
  return this.store.getBytecodeCommitment(contractClassId);
1168
1152
  }
1169
- getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
1170
- return this.store.getContractInstance(address);
1153
+ getContractInstance(address: AztecAddress, blockNumber: number): Promise<ContractInstanceWithAddress | undefined> {
1154
+ return this.store.getContractInstance(address, blockNumber);
1171
1155
  }
1172
1156
  getContractClassIds(): Promise<Fr[]> {
1173
1157
  return this.store.getContractClassIds();
@@ -15,7 +15,7 @@ import type { InboxLeaf } from '@aztec/stdlib/messaging';
15
15
  import { BlockHeader, type TxEffect, type TxHash, type TxReceipt } from '@aztec/stdlib/tx';
16
16
 
17
17
  import type { DataRetrieval } from './structs/data_retrieval.js';
18
- import type { L1Published } from './structs/published.js';
18
+ import type { PublishedL2Block } from './structs/published.js';
19
19
 
20
20
  /**
21
21
  * Represents the latest L1 block processed by the archiver for various objects in L2.
@@ -39,7 +39,7 @@ export interface ArchiverDataStore {
39
39
  * @param blocks - The L2 blocks to be added to the store and the last processed L1 block.
40
40
  * @returns True if the operation is successful.
41
41
  */
42
- addBlocks(blocks: L1Published<L2Block>[]): Promise<boolean>;
42
+ addBlocks(blocks: PublishedL2Block[]): Promise<boolean>;
43
43
 
44
44
  /**
45
45
  * Unwinds blocks from the database
@@ -56,7 +56,7 @@ export interface ArchiverDataStore {
56
56
  * @param limit - The number of blocks to return.
57
57
  * @returns The requested L2 blocks.
58
58
  */
59
- getBlocks(from: number, limit: number): Promise<L1Published<L2Block>[]>;
59
+ getBlocks(from: number, limit: number): Promise<PublishedL2Block[]>;
60
60
 
61
61
  /**
62
62
  * Gets up to `limit` amount of L2 block headers starting from `from`.
@@ -244,8 +244,9 @@ export interface ArchiverDataStore {
244
244
  /**
245
245
  * Returns a contract instance given its address and the given block number, or undefined if not exists.
246
246
  * @param address - Address of the contract.
247
+ * @param blockNumber - Block number to get the contract instance at. Contract updates might change the instance at a given block.
247
248
  */
248
- getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined>;
249
+ getContractInstance(address: AztecAddress, blockNumber: number): Promise<ContractInstanceWithAddress | undefined>;
249
250
 
250
251
  /** Returns the list of all class ids known by the archiver. */
251
252
  getContractClassIds(): Promise<Fr[]>;