@aztec/archiver 0.30.1 → 0.32.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 (50) hide show
  1. package/dest/archiver/archiver.d.ts +7 -9
  2. package/dest/archiver/archiver.d.ts.map +1 -1
  3. package/dest/archiver/archiver.js +51 -22
  4. package/dest/archiver/archiver_store.d.ts +16 -11
  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 +51 -15
  8. package/dest/archiver/data_retrieval.js +6 -6
  9. package/dest/archiver/eth_log_handlers.d.ts +7 -7
  10. package/dest/archiver/eth_log_handlers.d.ts.map +1 -1
  11. package/dest/archiver/eth_log_handlers.js +11 -11
  12. package/dest/archiver/kv_archiver_store/block_store.d.ts.map +1 -1
  13. package/dest/archiver/kv_archiver_store/block_store.js +3 -2
  14. package/dest/archiver/kv_archiver_store/contract_class_store.d.ts +3 -4
  15. package/dest/archiver/kv_archiver_store/contract_class_store.d.ts.map +1 -1
  16. package/dest/archiver/kv_archiver_store/contract_class_store.js +64 -13
  17. package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts +9 -7
  18. package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts.map +1 -1
  19. package/dest/archiver/kv_archiver_store/kv_archiver_store.js +11 -9
  20. package/dest/archiver/kv_archiver_store/log_store.d.ts +3 -3
  21. package/dest/archiver/kv_archiver_store/log_store.d.ts.map +1 -1
  22. package/dest/archiver/kv_archiver_store/log_store.js +7 -5
  23. package/dest/archiver/kv_archiver_store/message_store.d.ts +3 -2
  24. package/dest/archiver/kv_archiver_store/message_store.d.ts.map +1 -1
  25. package/dest/archiver/kv_archiver_store/message_store.js +10 -6
  26. package/dest/archiver/memory_archiver_store/l1_to_l2_message_store.d.ts +4 -4
  27. package/dest/archiver/memory_archiver_store/l1_to_l2_message_store.d.ts.map +1 -1
  28. package/dest/archiver/memory_archiver_store/l1_to_l2_message_store.js +11 -8
  29. package/dest/archiver/memory_archiver_store/memory_archiver_store.d.ts +11 -7
  30. package/dest/archiver/memory_archiver_store/memory_archiver_store.d.ts.map +1 -1
  31. package/dest/archiver/memory_archiver_store/memory_archiver_store.js +34 -11
  32. package/dest/rpc/archiver_client.d.ts.map +1 -1
  33. package/dest/rpc/archiver_client.js +4 -3
  34. package/dest/rpc/archiver_server.d.ts.map +1 -1
  35. package/dest/rpc/archiver_server.js +4 -3
  36. package/package.json +11 -9
  37. package/src/archiver/archiver.ts +80 -23
  38. package/src/archiver/archiver_store.ts +33 -11
  39. package/src/archiver/archiver_store_test_suite.ts +65 -18
  40. package/src/archiver/data_retrieval.ts +6 -6
  41. package/src/archiver/eth_log_handlers.ts +13 -13
  42. package/src/archiver/kv_archiver_store/block_store.ts +9 -1
  43. package/src/archiver/kv_archiver_store/contract_class_store.ts +106 -18
  44. package/src/archiver/kv_archiver_store/kv_archiver_store.ts +31 -12
  45. package/src/archiver/kv_archiver_store/log_store.ts +23 -10
  46. package/src/archiver/kv_archiver_store/message_store.ts +10 -5
  47. package/src/archiver/memory_archiver_store/l1_to_l2_message_store.ts +10 -7
  48. package/src/archiver/memory_archiver_store/memory_archiver_store.ts +66 -15
  49. package/src/rpc/archiver_client.ts +5 -3
  50. package/src/rpc/archiver_server.ts +4 -2
@@ -11,8 +11,7 @@ import { Fr } from '@aztec/foundation/fields';
11
11
  */
12
12
  export class L1ToL2MessageStore {
13
13
  /**
14
- * A map containing the entry key to the corresponding L1 to L2
15
- * messages (and the number of times the message has been seen).
14
+ * A map pointing from a key in a "blockNum-messageIndex" format to the corresponding L1 to L2 message hash.
16
15
  */
17
16
  protected store: Map<string, Fr> = new Map();
18
17
 
@@ -50,17 +49,21 @@ export class L1ToL2MessageStore {
50
49
  }
51
50
 
52
51
  /**
53
- * Gets the L1 to L2 message index in the L1 to L2 message tree.
52
+ * Gets the first L1 to L2 message index in the L1 to L2 message tree which is greater than or equal to `startIndex`.
54
53
  * @param l1ToL2Message - The L1 to L2 message.
54
+ * @param startIndex - The index to start searching from.
55
55
  * @returns The index of the L1 to L2 message in the L1 to L2 message tree (undefined if not found).
56
56
  */
57
- getMessageIndex(l1ToL2Message: Fr): bigint | undefined {
57
+ getMessageIndex(l1ToL2Message: Fr, startIndex: bigint): bigint | undefined {
58
58
  for (const [key, message] of this.store.entries()) {
59
59
  if (message.equals(l1ToL2Message)) {
60
- const [blockNumber, messageIndex] = key.split('-');
60
+ const keyParts = key.split('-');
61
+ const [blockNumber, messageIndex] = [BigInt(keyParts[0]), BigInt(keyParts[1])];
61
62
  const indexInTheWholeTree =
62
- (BigInt(blockNumber) - BigInt(INITIAL_L2_BLOCK_NUM)) * BigInt(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP) +
63
- BigInt(messageIndex);
63
+ (blockNumber - BigInt(INITIAL_L2_BLOCK_NUM)) * BigInt(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP) + messageIndex;
64
+ if (indexInTheWholeTree < startIndex) {
65
+ continue;
66
+ }
64
67
  return indexInTheWholeTree;
65
68
  }
66
69
  }
@@ -1,6 +1,8 @@
1
1
  import {
2
2
  Body,
3
+ EncryptedL2BlockL2Logs,
3
4
  ExtendedUnencryptedL2Log,
5
+ FromLogType,
4
6
  GetUnencryptedLogsResponse,
5
7
  InboxLeaf,
6
8
  L2Block,
@@ -13,11 +15,16 @@ import {
13
15
  TxHash,
14
16
  TxReceipt,
15
17
  TxStatus,
16
- UnencryptedL2Log,
18
+ UnencryptedL2BlockL2Logs,
17
19
  } from '@aztec/circuit-types';
18
20
  import { Fr, INITIAL_L2_BLOCK_NUM } from '@aztec/circuits.js';
19
21
  import { AztecAddress } from '@aztec/foundation/aztec-address';
20
- import { ContractClassPublic, ContractInstanceWithAddress } from '@aztec/types/contracts';
22
+ import {
23
+ ContractClassPublic,
24
+ ContractInstanceWithAddress,
25
+ ExecutablePrivateFunctionWithMembershipProof,
26
+ UnconstrainedFunctionWithMembershipProof,
27
+ } from '@aztec/types/contracts';
21
28
 
22
29
  import { ArchiverDataStore, ArchiverL1SynchPoint } from '../archiver_store.js';
23
30
  import { DataRetrieval } from '../data_retrieval.js';
@@ -46,13 +53,13 @@ export class MemoryArchiverStore implements ArchiverDataStore {
46
53
  * An array containing all the encrypted logs that have been fetched so far.
47
54
  * Note: Index in the "outer" array equals to (corresponding L2 block's number - INITIAL_L2_BLOCK_NUM).
48
55
  */
49
- private encryptedLogsPerBlock: L2BlockL2Logs[] = [];
56
+ private encryptedLogsPerBlock: EncryptedL2BlockL2Logs[] = [];
50
57
 
51
58
  /**
52
59
  * An array containing all the unencrypted logs that have been fetched so far.
53
60
  * Note: Index in the "outer" array equals to (corresponding L2 block's number - INITIAL_L2_BLOCK_NUM).
54
61
  */
55
- private unencryptedLogsPerBlock: L2BlockL2Logs[] = [];
62
+ private unencryptedLogsPerBlock: UnencryptedL2BlockL2Logs[] = [];
56
63
 
57
64
  /**
58
65
  * Contains all L1 to L2 messages.
@@ -61,6 +68,10 @@ export class MemoryArchiverStore implements ArchiverDataStore {
61
68
 
62
69
  private contractClasses: Map<string, ContractClassPublic> = new Map();
63
70
 
71
+ private privateFunctions: Map<string, ExecutablePrivateFunctionWithMembershipProof[]> = new Map();
72
+
73
+ private unconstrainedFunctions: Map<string, UnconstrainedFunctionWithMembershipProof[]> = new Map();
74
+
64
75
  private contractInstances: Map<string, ContractInstanceWithAddress> = new Map();
65
76
 
66
77
  private lastL1BlockNewBlocks: bigint = 0n;
@@ -72,7 +83,14 @@ export class MemoryArchiverStore implements ArchiverDataStore {
72
83
  ) {}
73
84
 
74
85
  public getContractClass(id: Fr): Promise<ContractClassPublic | undefined> {
75
- return Promise.resolve(this.contractClasses.get(id.toString()));
86
+ const contractClass = this.contractClasses.get(id.toString());
87
+ return Promise.resolve(
88
+ contractClass && {
89
+ ...contractClass,
90
+ privateFunctions: this.privateFunctions.get(id.toString()) ?? [],
91
+ unconstrainedFunctions: this.unconstrainedFunctions.get(id.toString()) ?? [],
92
+ },
93
+ );
76
94
  }
77
95
 
78
96
  public getContractClassIds(): Promise<Fr[]> {
@@ -83,6 +101,28 @@ export class MemoryArchiverStore implements ArchiverDataStore {
83
101
  return Promise.resolve(this.contractInstances.get(address.toString()));
84
102
  }
85
103
 
104
+ public addFunctions(
105
+ contractClassId: Fr,
106
+ newPrivateFunctions: ExecutablePrivateFunctionWithMembershipProof[],
107
+ newUnconstrainedFunctions: UnconstrainedFunctionWithMembershipProof[],
108
+ ): Promise<boolean> {
109
+ const privateFunctions = this.privateFunctions.get(contractClassId.toString()) ?? [];
110
+ const unconstrainedFunctions = this.unconstrainedFunctions.get(contractClassId.toString()) ?? [];
111
+ const updatedPrivateFunctions = [
112
+ ...privateFunctions,
113
+ ...newPrivateFunctions.filter(newFn => !privateFunctions.find(f => f.selector.equals(newFn.selector))),
114
+ ];
115
+ const updatedUnconstrainedFunctions = [
116
+ ...unconstrainedFunctions,
117
+ ...newUnconstrainedFunctions.filter(
118
+ newFn => !unconstrainedFunctions.find(f => f.selector.equals(newFn.selector)),
119
+ ),
120
+ ];
121
+ this.privateFunctions.set(contractClassId.toString(), updatedPrivateFunctions);
122
+ this.unconstrainedFunctions.set(contractClassId.toString(), updatedUnconstrainedFunctions);
123
+ return Promise.resolve(true);
124
+ }
125
+
86
126
  public addContractClasses(data: ContractClassPublic[], _blockNumber: number): Promise<boolean> {
87
127
  for (const contractClass of data) {
88
128
  this.contractClasses.set(contractClass.id.toString(), contractClass);
@@ -145,7 +185,11 @@ export class MemoryArchiverStore implements ArchiverDataStore {
145
185
  * @param blockNumber - The block for which to add the logs.
146
186
  * @returns True if the operation is successful.
147
187
  */
148
- addLogs(encryptedLogs: L2BlockL2Logs, unencryptedLogs: L2BlockL2Logs, blockNumber: number): Promise<boolean> {
188
+ addLogs(
189
+ encryptedLogs: EncryptedL2BlockL2Logs,
190
+ unencryptedLogs: UnencryptedL2BlockL2Logs,
191
+ blockNumber: number,
192
+ ): Promise<boolean> {
149
193
  if (encryptedLogs) {
150
194
  this.encryptedLogsPerBlock[blockNumber - INITIAL_L2_BLOCK_NUM] = encryptedLogs;
151
195
  }
@@ -175,12 +219,13 @@ export class MemoryArchiverStore implements ArchiverDataStore {
175
219
  }
176
220
 
177
221
  /**
178
- * Gets the L1 to L2 message index in the L1 to L2 message tree.
222
+ * Gets the first L1 to L2 message index in the L1 to L2 message tree which is greater than or equal to `startIndex`.
179
223
  * @param l1ToL2Message - The L1 to L2 message.
224
+ * @param startIndex - The index to start searching from.
180
225
  * @returns The index of the L1 to L2 message in the L1 to L2 message tree (undefined if not found).
181
226
  */
182
- public getL1ToL2MessageIndex(l1ToL2Message: Fr): Promise<bigint | undefined> {
183
- return Promise.resolve(this.l1ToL2Messages.getMessageIndex(l1ToL2Message));
227
+ getL1ToL2MessageIndex(l1ToL2Message: Fr, startIndex: bigint): Promise<bigint | undefined> {
228
+ return Promise.resolve(this.l1ToL2Messages.getMessageIndex(l1ToL2Message, startIndex));
184
229
  }
185
230
 
186
231
  /**
@@ -249,11 +294,17 @@ export class MemoryArchiverStore implements ArchiverDataStore {
249
294
  * @param logType - Specifies whether to return encrypted or unencrypted logs.
250
295
  * @returns The requested logs.
251
296
  */
252
- getLogs(from: number, limit: number, logType: LogType): Promise<L2BlockL2Logs[]> {
297
+ getLogs<TLogType extends LogType>(
298
+ from: number,
299
+ limit: number,
300
+ logType: TLogType,
301
+ ): Promise<L2BlockL2Logs<FromLogType<TLogType>>[]> {
253
302
  if (from < INITIAL_L2_BLOCK_NUM || limit < 1) {
254
303
  throw new Error(`Invalid limit: ${limit}`);
255
304
  }
256
- const logs = logType === LogType.ENCRYPTED ? this.encryptedLogsPerBlock : this.unencryptedLogsPerBlock;
305
+ const logs = (
306
+ logType === LogType.ENCRYPTED ? this.encryptedLogsPerBlock : this.unencryptedLogsPerBlock
307
+ ) as L2BlockL2Logs<FromLogType<TLogType>>[];
257
308
  if (from > logs.length) {
258
309
  return Promise.resolve([]);
259
310
  }
@@ -316,7 +367,7 @@ export class MemoryArchiverStore implements ArchiverDataStore {
316
367
  const blockContext = this.l2BlockContexts[fromBlockIndex];
317
368
  const blockLogs = this.unencryptedLogsPerBlock[fromBlockIndex];
318
369
  for (; txIndexInBlock < blockLogs.txLogs.length; txIndexInBlock++) {
319
- const txLogs = blockLogs.txLogs[txIndexInBlock].unrollLogs().map(log => UnencryptedL2Log.fromBuffer(log));
370
+ const txLogs = blockLogs.txLogs[txIndexInBlock].unrollLogs();
320
371
  for (; logIndexInTx < txLogs.length; logIndexInTx++) {
321
372
  const log = txLogs[logIndexInTx];
322
373
  if (
@@ -357,10 +408,10 @@ export class MemoryArchiverStore implements ArchiverDataStore {
357
408
  return Promise.resolve(this.l2BlockContexts[this.l2BlockContexts.length - 1].block.number);
358
409
  }
359
410
 
360
- public getSynchedL1BlockNumbers(): Promise<ArchiverL1SynchPoint> {
411
+ public getSynchPoint(): Promise<ArchiverL1SynchPoint> {
361
412
  return Promise.resolve({
362
- blocks: this.lastL1BlockNewBlocks,
363
- messages: this.lastL1BlockNewMessages,
413
+ blocksSynchedTo: this.lastL1BlockNewBlocks,
414
+ messagesSynchedTo: this.lastL1BlockNewMessages,
364
415
  });
365
416
  }
366
417
  }
@@ -1,9 +1,10 @@
1
1
  import {
2
+ EncryptedL2BlockL2Logs,
2
3
  ExtendedUnencryptedL2Log,
3
4
  L2Block,
4
- L2BlockL2Logs,
5
5
  NullifierMembershipWitness,
6
6
  TxReceipt,
7
+ UnencryptedL2BlockL2Logs,
7
8
  } from '@aztec/circuit-types';
8
9
  import { EthAddress, Fr } from '@aztec/circuits.js';
9
10
  import { createJsonRpcClient, makeFetch } from '@aztec/foundation/json-rpc/client';
@@ -18,10 +19,11 @@ export const createArchiverClient = (url: string, fetch = makeFetch([1, 2, 3], t
18
19
  ExtendedUnencryptedL2Log,
19
20
  Fr,
20
21
  L2Block,
21
- L2BlockL2Logs,
22
+ EncryptedL2BlockL2Logs,
23
+ UnencryptedL2BlockL2Logs,
22
24
  },
23
25
  { TxReceipt, NullifierMembershipWitness },
24
26
  false,
25
27
  'archiver',
26
28
  fetch,
27
- );
29
+ ) as ArchiveSource;
@@ -1,10 +1,11 @@
1
1
  import {
2
+ EncryptedL2BlockL2Logs,
2
3
  ExtendedUnencryptedL2Log,
3
4
  L2Block,
4
- L2BlockL2Logs,
5
5
  NullifierMembershipWitness,
6
6
  TxEffect,
7
7
  TxReceipt,
8
+ UnencryptedL2BlockL2Logs,
8
9
  } from '@aztec/circuit-types';
9
10
  import { EthAddress, Fr } from '@aztec/circuits.js';
10
11
  import { JsonRpcServer } from '@aztec/foundation/json-rpc/server';
@@ -24,7 +25,8 @@ export function createArchiverRpcServer(archiverService: Archiver): JsonRpcServe
24
25
  ExtendedUnencryptedL2Log,
25
26
  Fr,
26
27
  L2Block,
27
- L2BlockL2Logs,
28
+ EncryptedL2BlockL2Logs,
29
+ UnencryptedL2BlockL2Logs,
28
30
  TxEffect,
29
31
  },
30
32
  { TxReceipt, NullifierMembershipWitness },