@aztec/archiver 0.0.0-test.1 → 0.0.1-commit.5476d83

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 (110) hide show
  1. package/README.md +27 -6
  2. package/dest/archiver/archiver.d.ts +147 -57
  3. package/dest/archiver/archiver.d.ts.map +1 -1
  4. package/dest/archiver/archiver.js +841 -333
  5. package/dest/archiver/archiver_store.d.ts +85 -50
  6. package/dest/archiver/archiver_store.d.ts.map +1 -1
  7. package/dest/archiver/archiver_store_test_suite.d.ts +1 -1
  8. package/dest/archiver/archiver_store_test_suite.d.ts.map +1 -1
  9. package/dest/archiver/archiver_store_test_suite.js +708 -213
  10. package/dest/archiver/config.d.ts +5 -21
  11. package/dest/archiver/config.d.ts.map +1 -1
  12. package/dest/archiver/config.js +21 -12
  13. package/dest/archiver/data_retrieval.d.ts +32 -27
  14. package/dest/archiver/data_retrieval.d.ts.map +1 -1
  15. package/dest/archiver/data_retrieval.js +197 -94
  16. package/dest/archiver/errors.d.ts +9 -1
  17. package/dest/archiver/errors.d.ts.map +1 -1
  18. package/dest/archiver/errors.js +12 -0
  19. package/dest/archiver/index.d.ts +3 -4
  20. package/dest/archiver/index.d.ts.map +1 -1
  21. package/dest/archiver/index.js +1 -2
  22. package/dest/archiver/instrumentation.d.ts +12 -6
  23. package/dest/archiver/instrumentation.d.ts.map +1 -1
  24. package/dest/archiver/instrumentation.js +58 -17
  25. package/dest/archiver/kv_archiver_store/block_store.d.ts +48 -11
  26. package/dest/archiver/kv_archiver_store/block_store.d.ts.map +1 -1
  27. package/dest/archiver/kv_archiver_store/block_store.js +216 -63
  28. package/dest/archiver/kv_archiver_store/contract_class_store.d.ts +3 -3
  29. package/dest/archiver/kv_archiver_store/contract_class_store.d.ts.map +1 -1
  30. package/dest/archiver/kv_archiver_store/contract_class_store.js +12 -18
  31. package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts +11 -8
  32. package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts.map +1 -1
  33. package/dest/archiver/kv_archiver_store/contract_instance_store.js +30 -16
  34. package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts +50 -35
  35. package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts.map +1 -1
  36. package/dest/archiver/kv_archiver_store/kv_archiver_store.js +88 -46
  37. package/dest/archiver/kv_archiver_store/log_store.d.ts +2 -2
  38. package/dest/archiver/kv_archiver_store/log_store.d.ts.map +1 -1
  39. package/dest/archiver/kv_archiver_store/log_store.js +18 -46
  40. package/dest/archiver/kv_archiver_store/message_store.d.ts +23 -17
  41. package/dest/archiver/kv_archiver_store/message_store.d.ts.map +1 -1
  42. package/dest/archiver/kv_archiver_store/message_store.js +150 -48
  43. package/dest/archiver/structs/data_retrieval.d.ts +1 -1
  44. package/dest/archiver/structs/inbox_message.d.ts +15 -0
  45. package/dest/archiver/structs/inbox_message.d.ts.map +1 -0
  46. package/dest/archiver/structs/inbox_message.js +38 -0
  47. package/dest/archiver/structs/published.d.ts +3 -11
  48. package/dest/archiver/structs/published.d.ts.map +1 -1
  49. package/dest/archiver/structs/published.js +1 -1
  50. package/dest/archiver/validation.d.ts +17 -0
  51. package/dest/archiver/validation.d.ts.map +1 -0
  52. package/dest/archiver/validation.js +98 -0
  53. package/dest/factory.d.ts +8 -13
  54. package/dest/factory.d.ts.map +1 -1
  55. package/dest/factory.js +18 -49
  56. package/dest/index.d.ts +2 -2
  57. package/dest/index.d.ts.map +1 -1
  58. package/dest/index.js +1 -1
  59. package/dest/rpc/index.d.ts +2 -3
  60. package/dest/rpc/index.d.ts.map +1 -1
  61. package/dest/rpc/index.js +1 -4
  62. package/dest/test/index.d.ts +1 -1
  63. package/dest/test/mock_archiver.d.ts +2 -2
  64. package/dest/test/mock_archiver.d.ts.map +1 -1
  65. package/dest/test/mock_l1_to_l2_message_source.d.ts +5 -3
  66. package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
  67. package/dest/test/mock_l1_to_l2_message_source.js +14 -1
  68. package/dest/test/mock_l2_block_source.d.ts +38 -10
  69. package/dest/test/mock_l2_block_source.d.ts.map +1 -1
  70. package/dest/test/mock_l2_block_source.js +119 -8
  71. package/dest/test/mock_structs.d.ts +9 -0
  72. package/dest/test/mock_structs.d.ts.map +1 -0
  73. package/dest/test/mock_structs.js +37 -0
  74. package/package.json +28 -30
  75. package/src/archiver/archiver.ts +1087 -410
  76. package/src/archiver/archiver_store.ts +97 -55
  77. package/src/archiver/archiver_store_test_suite.ts +664 -210
  78. package/src/archiver/config.ts +28 -41
  79. package/src/archiver/data_retrieval.ts +279 -125
  80. package/src/archiver/errors.ts +21 -0
  81. package/src/archiver/index.ts +2 -3
  82. package/src/archiver/instrumentation.ts +77 -22
  83. package/src/archiver/kv_archiver_store/block_store.ts +270 -72
  84. package/src/archiver/kv_archiver_store/contract_class_store.ts +13 -23
  85. package/src/archiver/kv_archiver_store/contract_instance_store.ts +35 -27
  86. package/src/archiver/kv_archiver_store/kv_archiver_store.ts +127 -63
  87. package/src/archiver/kv_archiver_store/log_store.ts +24 -62
  88. package/src/archiver/kv_archiver_store/message_store.ts +209 -53
  89. package/src/archiver/structs/inbox_message.ts +41 -0
  90. package/src/archiver/structs/published.ts +2 -11
  91. package/src/archiver/validation.ts +124 -0
  92. package/src/factory.ts +24 -66
  93. package/src/index.ts +1 -1
  94. package/src/rpc/index.ts +1 -5
  95. package/src/test/mock_archiver.ts +1 -1
  96. package/src/test/mock_l1_to_l2_message_source.ts +14 -3
  97. package/src/test/mock_l2_block_source.ts +158 -13
  98. package/src/test/mock_structs.ts +49 -0
  99. package/dest/archiver/kv_archiver_store/nullifier_store.d.ts +0 -12
  100. package/dest/archiver/kv_archiver_store/nullifier_store.d.ts.map +0 -1
  101. package/dest/archiver/kv_archiver_store/nullifier_store.js +0 -73
  102. package/dest/archiver/memory_archiver_store/l1_to_l2_message_store.d.ts +0 -23
  103. package/dest/archiver/memory_archiver_store/l1_to_l2_message_store.d.ts.map +0 -1
  104. package/dest/archiver/memory_archiver_store/l1_to_l2_message_store.js +0 -49
  105. package/dest/archiver/memory_archiver_store/memory_archiver_store.d.ts +0 -175
  106. package/dest/archiver/memory_archiver_store/memory_archiver_store.d.ts.map +0 -1
  107. package/dest/archiver/memory_archiver_store/memory_archiver_store.js +0 -636
  108. package/src/archiver/kv_archiver_store/nullifier_store.ts +0 -97
  109. package/src/archiver/memory_archiver_store/l1_to_l2_message_store.ts +0 -61
  110. package/src/archiver/memory_archiver_store/memory_archiver_store.ts +0 -801
@@ -1,21 +1,23 @@
1
+ import type { L1BlockId } from '@aztec/ethereum';
1
2
  import type { Fr } from '@aztec/foundation/fields';
3
+ import type { CustomRange } from '@aztec/kv-store';
2
4
  import type { FunctionSelector } from '@aztec/stdlib/abi';
3
5
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
- import type { InBlock, L2Block } from '@aztec/stdlib/block';
6
+ import type { L2Block, ValidateBlockResult } from '@aztec/stdlib/block';
5
7
  import type {
6
8
  ContractClassPublic,
7
9
  ContractInstanceUpdateWithAddress,
8
10
  ContractInstanceWithAddress,
9
11
  ExecutablePrivateFunctionWithMembershipProof,
10
- UnconstrainedFunctionWithMembershipProof,
12
+ UtilityFunctionWithMembershipProof,
11
13
  } from '@aztec/stdlib/contract';
12
14
  import type { GetContractClassLogsResponse, GetPublicLogsResponse } from '@aztec/stdlib/interfaces/client';
13
15
  import type { LogFilter, PrivateLog, TxScopedL2Log } from '@aztec/stdlib/logs';
14
- import type { InboxLeaf } from '@aztec/stdlib/messaging';
15
- import { BlockHeader, type TxEffect, type TxHash, type TxReceipt } from '@aztec/stdlib/tx';
16
+ import { BlockHeader, type IndexedTxEffect, type TxHash, type TxReceipt } from '@aztec/stdlib/tx';
17
+ import type { UInt64 } from '@aztec/stdlib/types';
16
18
 
17
- import type { DataRetrieval } from './structs/data_retrieval.js';
18
- import type { L1Published } from './structs/published.js';
19
+ import type { InboxMessage } from './structs/inbox_message.js';
20
+ import type { PublishedL2Block } from './structs/published.js';
19
21
 
20
22
  /**
21
23
  * Represents the latest L1 block processed by the archiver for various objects in L2.
@@ -23,10 +25,8 @@ import type { L1Published } from './structs/published.js';
23
25
  export type ArchiverL1SynchPoint = {
24
26
  /** Number of the last L1 block that added a new L2 block metadata. */
25
27
  blocksSynchedTo?: bigint;
26
- /** Number of the last L1 block that added L1 -> L2 messages from the Inbox. */
27
- messagesSynchedTo?: bigint;
28
- /** Number of the last L1 block that added a new proven block. */
29
- provenLogsSynchedTo?: bigint;
28
+ /** Last L1 block checked for L1 to L2 messages. */
29
+ messagesSynchedTo?: L1BlockId;
30
30
  };
31
31
 
32
32
  /**
@@ -34,12 +34,17 @@ export type ArchiverL1SynchPoint = {
34
34
  * (blocks, encrypted logs, aztec contract data extended contract data).
35
35
  */
36
36
  export interface ArchiverDataStore {
37
+ /** Opens a new transaction to the underlying store and runs all operations within it. */
38
+ transactionAsync<T>(callback: () => Promise<T>): Promise<T>;
39
+
37
40
  /**
38
41
  * Append new blocks to the store's list.
39
42
  * @param blocks - The L2 blocks to be added to the store and the last processed L1 block.
43
+ * @param opts - Options for the operation.
44
+ * @param opts.force - If true, the blocks will be added even if they have gaps.
40
45
  * @returns True if the operation is successful.
41
46
  */
42
- addBlocks(blocks: L1Published<L2Block>[]): Promise<boolean>;
47
+ addBlocks(blocks: PublishedL2Block[], opts?: { force?: boolean }): Promise<boolean>;
43
48
 
44
49
  /**
45
50
  * Unwinds blocks from the database
@@ -51,12 +56,30 @@ export interface ArchiverDataStore {
51
56
  unwindBlocks(from: number, blocksToUnwind: number): Promise<boolean>;
52
57
 
53
58
  /**
54
- * Gets up to `limit` amount of L2 blocks starting from `from`.
59
+ * Returns the block for the given number, or undefined if not exists.
60
+ * @param number - The block number to return.
61
+ */
62
+ getPublishedBlock(number: number): Promise<PublishedL2Block | undefined>;
63
+
64
+ /**
65
+ * Returns the block for the given hash, or undefined if not exists.
66
+ * @param blockHash - The block hash to return.
67
+ */
68
+ getPublishedBlockByHash(blockHash: Fr): Promise<PublishedL2Block | undefined>;
69
+
70
+ /**
71
+ * Returns the block for the given archive root, or undefined if not exists.
72
+ * @param archive - The archive root to return.
73
+ */
74
+ getPublishedBlockByArchive(archive: Fr): Promise<PublishedL2Block | undefined>;
75
+
76
+ /**
77
+ * Gets up to `limit` amount of published L2 blocks starting from `from`.
55
78
  * @param from - Number of the first block to return (inclusive).
56
79
  * @param limit - The number of blocks to return.
57
80
  * @returns The requested L2 blocks.
58
81
  */
59
- getBlocks(from: number, limit: number): Promise<L1Published<L2Block>[]>;
82
+ getPublishedBlocks(from: number, limit: number): Promise<PublishedL2Block[]>;
60
83
 
61
84
  /**
62
85
  * Gets up to `limit` amount of L2 block headers starting from `from`.
@@ -66,12 +89,24 @@ export interface ArchiverDataStore {
66
89
  */
67
90
  getBlockHeaders(from: number, limit: number): Promise<BlockHeader[]>;
68
91
 
92
+ /**
93
+ * Returns the block header for the given hash, or undefined if not exists.
94
+ * @param blockHash - The block hash to return.
95
+ */
96
+ getBlockHeaderByHash(blockHash: Fr): Promise<BlockHeader | undefined>;
97
+
98
+ /**
99
+ * Returns the block header for the given archive root, or undefined if not exists.
100
+ * @param archive - The archive root to return.
101
+ */
102
+ getBlockHeaderByArchive(archive: Fr): Promise<BlockHeader | undefined>;
103
+
69
104
  /**
70
105
  * Gets a tx effect.
71
- * @param txHash - The txHash of the tx corresponding to the tx effect.
72
- * @returns The requested tx effect (or undefined if not found).
106
+ * @param txHash - The hash of the tx corresponding to the tx effect.
107
+ * @returns The requested tx effect with block info (or undefined if not found).
73
108
  */
74
- getTxEffect(txHash: TxHash): Promise<InBlock<TxEffect> | undefined>;
109
+ getTxEffect(txHash: TxHash): Promise<IndexedTxEffect | undefined>;
75
110
 
76
111
  /**
77
112
  * Gets a receipt of a settled tx.
@@ -88,36 +123,19 @@ export interface ArchiverDataStore {
88
123
  addLogs(blocks: L2Block[]): Promise<boolean>;
89
124
  deleteLogs(blocks: L2Block[]): Promise<boolean>;
90
125
 
91
- /**
92
- * Append new nullifiers to the store's list.
93
- * @param blocks - The blocks for which to add the nullifiers.
94
- * @returns True if the operation is successful.
95
- */
96
- addNullifiers(blocks: L2Block[]): Promise<boolean>;
97
- deleteNullifiers(blocks: L2Block[]): Promise<boolean>;
98
-
99
- /**
100
- * Returns the provided nullifier indexes scoped to the block
101
- * they were first included in, or undefined if they're not present in the tree
102
- * @param blockNumber Max block number to search for the nullifiers
103
- * @param nullifiers Nullifiers to get
104
- * @returns The block scoped indexes of the provided nullifiers, or undefined if the nullifier doesn't exist in the tree
105
- */
106
- findNullifiersIndexesWithBlock(blockNumber: number, nullifiers: Fr[]): Promise<(InBlock<bigint> | undefined)[]>;
107
-
108
126
  /**
109
127
  * Append L1 to L2 messages to the store.
110
- * @param messages - The L1 to L2 messages to be added to the store and the last processed L1 block.
128
+ * @param messages - The L1 to L2 messages to be added to the store.
111
129
  * @returns True if the operation is successful.
112
130
  */
113
- addL1ToL2Messages(messages: DataRetrieval<InboxLeaf>): Promise<boolean>;
131
+ addL1ToL2Messages(messages: InboxMessage[]): Promise<void>;
114
132
 
115
133
  /**
116
134
  * Gets L1 to L2 message (to be) included in a given block.
117
135
  * @param blockNumber - L2 block number to get messages for.
118
136
  * @returns The L1 to L2 messages/leaves of the messages subtree (throws if not found).
119
137
  */
120
- getL1ToL2Messages(blockNumber: bigint): Promise<Fr[]>;
138
+ getL1ToL2Messages(blockNumber: number): Promise<Fr[]>;
121
139
 
122
140
  /**
123
141
  * Gets the L1 to L2 message index in the L1 to L2 message tree.
@@ -143,10 +161,11 @@ export interface ArchiverDataStore {
143
161
  /**
144
162
  * Gets all logs that match any of the received tags (i.e. logs with their first field equal to a tag).
145
163
  * @param tags - The tags to filter the logs by.
164
+ * @param logsPerTag - The number of logs to return per tag. Defaults to everything
146
165
  * @returns For each received tag, an array of matching logs is returned. An empty array implies no logs match
147
166
  * that tag.
148
167
  */
149
- getLogsByTags(tags: Fr[]): Promise<TxScopedL2Log[][]>;
168
+ getLogsByTags(tags: Fr[], logsPerTag?: number): Promise<TxScopedL2Log[][]>;
150
169
 
151
170
  /**
152
171
  * Gets public logs based on the provided filter.
@@ -187,10 +206,9 @@ export interface ArchiverDataStore {
187
206
  setBlockSynchedL1BlockNumber(l1BlockNumber: bigint): Promise<void>;
188
207
 
189
208
  /**
190
- * Stores the l1 block number that messages have been synched until
191
- * @param l1BlockNumber - The l1 block number
209
+ * Stores the l1 block that messages have been synched until
192
210
  */
193
- setMessageSynchedL1BlockNumber(l1BlockNumber: bigint): Promise<void>;
211
+ setMessageSynchedL1Block(l1Block: L1BlockId): Promise<void>;
194
212
 
195
213
  /**
196
214
  * Gets the synch point of the archiver
@@ -227,37 +245,61 @@ export interface ArchiverDataStore {
227
245
  /**
228
246
  * Add new contract instance updates
229
247
  * @param data - List of contract updates to be added.
230
- * @param blockNumber - Number of the L2 block the updates were scheduled in.
248
+ * @param timestamp - Timestamp at which the updates were scheduled.
231
249
  * @returns True if the operation is successful.
232
250
  */
233
- addContractInstanceUpdates(data: ContractInstanceUpdateWithAddress[], blockNumber: number): Promise<boolean>;
234
- deleteContractInstanceUpdates(data: ContractInstanceUpdateWithAddress[], blockNumber: number): Promise<boolean>;
251
+ addContractInstanceUpdates(data: ContractInstanceUpdateWithAddress[], timestamp: UInt64): Promise<boolean>;
252
+ deleteContractInstanceUpdates(data: ContractInstanceUpdateWithAddress[], timestamp: UInt64): Promise<boolean>;
235
253
  /**
236
254
  * Adds private functions to a contract class.
237
255
  */
238
256
  addFunctions(
239
257
  contractClassId: Fr,
240
258
  privateFunctions: ExecutablePrivateFunctionWithMembershipProof[],
241
- unconstrainedFunctions: UnconstrainedFunctionWithMembershipProof[],
259
+ utilityFunctions: UtilityFunctionWithMembershipProof[],
242
260
  ): Promise<boolean>;
243
261
 
244
262
  /**
245
- * Returns a contract instance given its address and the given block number, or undefined if not exists.
263
+ * Returns a contract instance given its address and the given timestamp, or undefined if not exists.
246
264
  * @param address - Address of the contract.
265
+ * @param timestamp - Timestamp to get the contract instance at. Contract updates might change the instance.
266
+ * @returns The contract instance or undefined if not found.
247
267
  */
248
- getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined>;
268
+ getContractInstance(address: AztecAddress, timestamp: UInt64): Promise<ContractInstanceWithAddress | undefined>;
249
269
 
250
270
  /** Returns the list of all class ids known by the archiver. */
251
271
  getContractClassIds(): Promise<Fr[]>;
252
272
 
253
- // TODO: These function names are in memory only as they are for development/debugging. They require the full contract
254
- // artifact supplied to the node out of band. This should be reviewed and potentially removed as part of
255
- // the node api cleanup process.
256
- registerContractFunctionSignatures(address: AztecAddress, signatures: string[]): Promise<void>;
257
- getContractFunctionName(address: AztecAddress, selector: FunctionSelector): Promise<string | undefined>;
273
+ /** Register a public function signature, so it can be looked up by selector. */
274
+ registerContractFunctionSignatures(signatures: string[]): Promise<void>;
258
275
 
259
- /**
260
- * Estimates the size of the store in bytes.
261
- */
262
- estimateSize(): Promise<{ mappingSize: number; actualSize: number; numItems: number }>;
276
+ /** Looks up a public function name given a selector. */
277
+ getDebugFunctionName(address: AztecAddress, selector: FunctionSelector): Promise<string | undefined>;
278
+
279
+ /** Estimates the size of the store in bytes. */
280
+ estimateSize(): Promise<{ mappingSize: number; physicalFileSize: number; actualSize: number; numItems: number }>;
281
+
282
+ /** Backups the archiver db to the target folder. Returns the path to the db file. */
283
+ backupTo(path: string): Promise<string>;
284
+
285
+ /** Closes the underlying data store. */
286
+ close(): Promise<void>;
287
+
288
+ /** Deletes all L1 to L2 messages up until (excluding) the target L2 block number. */
289
+ rollbackL1ToL2MessagesToL2Block(targetBlockNumber: number): Promise<void>;
290
+
291
+ /** Returns an async iterator to all L1 to L2 messages on the range. */
292
+ iterateL1ToL2Messages(range?: CustomRange<bigint>): AsyncIterableIterator<InboxMessage>;
293
+
294
+ /** Removes all L1 to L2 messages starting from the given index (inclusive). */
295
+ removeL1ToL2Messages(startIndex: bigint): Promise<void>;
296
+
297
+ /** Returns the last L1 to L2 message stored. */
298
+ getLastL1ToL2Message(): Promise<InboxMessage | undefined>;
299
+
300
+ /** Returns the last synced validation status of the pending chain. */
301
+ getPendingChainValidationStatus(): Promise<ValidateBlockResult | undefined>;
302
+
303
+ /** Sets the last synced validation status of the pending chain. */
304
+ setPendingChainValidationStatus(status: ValidateBlockResult | undefined): Promise<void>;
263
305
  }