@aztec/archiver 0.0.1-commit.fce3e4f → 0.0.1-commit.fffb133c

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 (201) hide show
  1. package/README.md +156 -22
  2. package/dest/archiver.d.ts +135 -0
  3. package/dest/archiver.d.ts.map +1 -0
  4. package/dest/archiver.js +768 -0
  5. package/dest/config.d.ts +30 -0
  6. package/dest/config.d.ts.map +1 -0
  7. package/dest/{archiver/config.js → config.js} +21 -5
  8. package/dest/errors.d.ts +41 -0
  9. package/dest/errors.d.ts.map +1 -0
  10. package/dest/errors.js +62 -0
  11. package/dest/factory.d.ts +7 -7
  12. package/dest/factory.d.ts.map +1 -1
  13. package/dest/factory.js +90 -10
  14. package/dest/index.d.ts +10 -4
  15. package/dest/index.d.ts.map +1 -1
  16. package/dest/index.js +8 -3
  17. package/dest/interfaces.d.ts +9 -0
  18. package/dest/interfaces.d.ts.map +1 -0
  19. package/dest/interfaces.js +3 -0
  20. package/dest/l1/bin/retrieve-calldata.d.ts +3 -0
  21. package/dest/l1/bin/retrieve-calldata.d.ts.map +1 -0
  22. package/dest/l1/bin/retrieve-calldata.js +149 -0
  23. package/dest/l1/calldata_retriever.d.ts +112 -0
  24. package/dest/l1/calldata_retriever.d.ts.map +1 -0
  25. package/dest/l1/calldata_retriever.js +471 -0
  26. package/dest/l1/data_retrieval.d.ts +88 -0
  27. package/dest/l1/data_retrieval.d.ts.map +1 -0
  28. package/dest/{archiver → l1}/data_retrieval.js +76 -150
  29. package/dest/l1/debug_tx.d.ts +19 -0
  30. package/dest/l1/debug_tx.d.ts.map +1 -0
  31. package/dest/l1/debug_tx.js +73 -0
  32. package/dest/l1/spire_proposer.d.ts +70 -0
  33. package/dest/l1/spire_proposer.d.ts.map +1 -0
  34. package/dest/l1/spire_proposer.js +157 -0
  35. package/dest/l1/trace_tx.d.ts +97 -0
  36. package/dest/l1/trace_tx.d.ts.map +1 -0
  37. package/dest/l1/trace_tx.js +91 -0
  38. package/dest/l1/types.d.ts +12 -0
  39. package/dest/l1/types.d.ts.map +1 -0
  40. package/dest/l1/types.js +3 -0
  41. package/dest/l1/validate_trace.d.ts +29 -0
  42. package/dest/l1/validate_trace.d.ts.map +1 -0
  43. package/dest/l1/validate_trace.js +150 -0
  44. package/dest/modules/data_source_base.d.ts +84 -0
  45. package/dest/modules/data_source_base.d.ts.map +1 -0
  46. package/dest/modules/data_source_base.js +260 -0
  47. package/dest/modules/data_store_updater.d.ts +73 -0
  48. package/dest/modules/data_store_updater.d.ts.map +1 -0
  49. package/dest/modules/data_store_updater.js +302 -0
  50. package/dest/modules/instrumentation.d.ts +37 -0
  51. package/dest/modules/instrumentation.d.ts.map +1 -0
  52. package/dest/{archiver → modules}/instrumentation.js +22 -59
  53. package/dest/modules/l1_synchronizer.d.ts +75 -0
  54. package/dest/modules/l1_synchronizer.d.ts.map +1 -0
  55. package/dest/modules/l1_synchronizer.js +1113 -0
  56. package/dest/modules/validation.d.ts +17 -0
  57. package/dest/modules/validation.d.ts.map +1 -0
  58. package/dest/{archiver → modules}/validation.js +7 -1
  59. package/dest/store/block_store.d.ts +192 -0
  60. package/dest/store/block_store.d.ts.map +1 -0
  61. package/dest/store/block_store.js +721 -0
  62. package/dest/store/contract_class_store.d.ts +18 -0
  63. package/dest/store/contract_class_store.d.ts.map +1 -0
  64. package/dest/{archiver/kv_archiver_store → store}/contract_class_store.js +2 -2
  65. package/dest/store/contract_instance_store.d.ts +24 -0
  66. package/dest/store/contract_instance_store.d.ts.map +1 -0
  67. package/dest/{archiver/kv_archiver_store → store}/contract_instance_store.js +1 -1
  68. package/dest/store/kv_archiver_store.d.ts +340 -0
  69. package/dest/store/kv_archiver_store.d.ts.map +1 -0
  70. package/dest/store/kv_archiver_store.js +447 -0
  71. package/dest/store/log_store.d.ts +54 -0
  72. package/dest/store/log_store.d.ts.map +1 -0
  73. package/dest/store/log_store.js +436 -0
  74. package/dest/store/message_store.d.ts +40 -0
  75. package/dest/store/message_store.d.ts.map +1 -0
  76. package/dest/{archiver/kv_archiver_store → store}/message_store.js +15 -14
  77. package/dest/{archiver/structs → structs}/data_retrieval.d.ts +1 -1
  78. package/dest/structs/data_retrieval.d.ts.map +1 -0
  79. package/dest/structs/inbox_message.d.ts +15 -0
  80. package/dest/structs/inbox_message.d.ts.map +1 -0
  81. package/dest/{archiver/structs → structs}/inbox_message.js +6 -5
  82. package/dest/structs/published.d.ts +2 -0
  83. package/dest/structs/published.d.ts.map +1 -0
  84. package/dest/test/fake_l1_state.d.ts +190 -0
  85. package/dest/test/fake_l1_state.d.ts.map +1 -0
  86. package/dest/test/fake_l1_state.js +383 -0
  87. package/dest/test/index.d.ts +2 -1
  88. package/dest/test/index.d.ts.map +1 -1
  89. package/dest/test/index.js +1 -0
  90. package/dest/test/mock_archiver.d.ts +16 -8
  91. package/dest/test/mock_archiver.d.ts.map +1 -1
  92. package/dest/test/mock_archiver.js +18 -14
  93. package/dest/test/mock_l1_to_l2_message_source.d.ts +7 -6
  94. package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
  95. package/dest/test/mock_l1_to_l2_message_source.js +21 -11
  96. package/dest/test/mock_l2_block_source.d.ts +34 -16
  97. package/dest/test/mock_l2_block_source.d.ts.map +1 -1
  98. package/dest/test/mock_l2_block_source.js +179 -59
  99. package/dest/test/mock_structs.d.ts +78 -3
  100. package/dest/test/mock_structs.d.ts.map +1 -1
  101. package/dest/test/mock_structs.js +141 -9
  102. package/package.json +19 -20
  103. package/src/archiver.ts +523 -0
  104. package/src/{archiver/config.ts → config.ts} +28 -12
  105. package/src/errors.ts +102 -0
  106. package/src/factory.ts +125 -10
  107. package/src/index.ts +10 -3
  108. package/src/interfaces.ts +9 -0
  109. package/src/l1/README.md +98 -0
  110. package/src/l1/bin/retrieve-calldata.ts +187 -0
  111. package/src/l1/calldata_retriever.ts +641 -0
  112. package/src/{archiver → l1}/data_retrieval.ts +142 -223
  113. package/src/l1/debug_tx.ts +99 -0
  114. package/src/l1/spire_proposer.ts +160 -0
  115. package/src/l1/trace_tx.ts +128 -0
  116. package/src/l1/types.ts +13 -0
  117. package/src/l1/validate_trace.ts +211 -0
  118. package/src/modules/data_source_base.ts +367 -0
  119. package/src/modules/data_store_updater.ts +423 -0
  120. package/src/{archiver → modules}/instrumentation.ts +26 -61
  121. package/src/modules/l1_synchronizer.ts +931 -0
  122. package/src/{archiver → modules}/validation.ts +11 -6
  123. package/src/store/block_store.ts +966 -0
  124. package/src/{archiver/kv_archiver_store → store}/contract_class_store.ts +2 -2
  125. package/src/{archiver/kv_archiver_store → store}/contract_instance_store.ts +2 -2
  126. package/src/store/kv_archiver_store.ts +639 -0
  127. package/src/store/log_store.ts +575 -0
  128. package/src/{archiver/kv_archiver_store → store}/message_store.ts +21 -18
  129. package/src/{archiver/structs → structs}/inbox_message.ts +8 -8
  130. package/src/{archiver/structs → structs}/published.ts +0 -1
  131. package/src/test/fake_l1_state.ts +599 -0
  132. package/src/test/fixtures/debug_traceTransaction-multicall3.json +88 -0
  133. package/src/test/fixtures/debug_traceTransaction-multiplePropose.json +153 -0
  134. package/src/test/fixtures/debug_traceTransaction-proxied.json +122 -0
  135. package/src/test/fixtures/trace_transaction-multicall3.json +65 -0
  136. package/src/test/fixtures/trace_transaction-multiplePropose.json +319 -0
  137. package/src/test/fixtures/trace_transaction-proxied.json +128 -0
  138. package/src/test/fixtures/trace_transaction-randomRevert.json +216 -0
  139. package/src/test/index.ts +1 -0
  140. package/src/test/mock_archiver.ts +22 -16
  141. package/src/test/mock_l1_to_l2_message_source.ts +18 -11
  142. package/src/test/mock_l2_block_source.ts +195 -69
  143. package/src/test/mock_structs.ts +256 -10
  144. package/dest/archiver/archiver.d.ts +0 -287
  145. package/dest/archiver/archiver.d.ts.map +0 -1
  146. package/dest/archiver/archiver.js +0 -1408
  147. package/dest/archiver/archiver_store.d.ts +0 -255
  148. package/dest/archiver/archiver_store.d.ts.map +0 -1
  149. package/dest/archiver/archiver_store.js +0 -4
  150. package/dest/archiver/archiver_store_test_suite.d.ts +0 -8
  151. package/dest/archiver/archiver_store_test_suite.d.ts.map +0 -1
  152. package/dest/archiver/archiver_store_test_suite.js +0 -1289
  153. package/dest/archiver/config.d.ts +0 -21
  154. package/dest/archiver/config.d.ts.map +0 -1
  155. package/dest/archiver/data_retrieval.d.ts +0 -79
  156. package/dest/archiver/data_retrieval.d.ts.map +0 -1
  157. package/dest/archiver/errors.d.ts +0 -12
  158. package/dest/archiver/errors.d.ts.map +0 -1
  159. package/dest/archiver/errors.js +0 -17
  160. package/dest/archiver/index.d.ts +0 -7
  161. package/dest/archiver/index.d.ts.map +0 -1
  162. package/dest/archiver/index.js +0 -4
  163. package/dest/archiver/instrumentation.d.ts +0 -35
  164. package/dest/archiver/instrumentation.d.ts.map +0 -1
  165. package/dest/archiver/kv_archiver_store/block_store.d.ts +0 -124
  166. package/dest/archiver/kv_archiver_store/block_store.d.ts.map +0 -1
  167. package/dest/archiver/kv_archiver_store/block_store.js +0 -370
  168. package/dest/archiver/kv_archiver_store/contract_class_store.d.ts +0 -18
  169. package/dest/archiver/kv_archiver_store/contract_class_store.d.ts.map +0 -1
  170. package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts +0 -24
  171. package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts.map +0 -1
  172. package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts +0 -168
  173. package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts.map +0 -1
  174. package/dest/archiver/kv_archiver_store/kv_archiver_store.js +0 -296
  175. package/dest/archiver/kv_archiver_store/log_store.d.ts +0 -49
  176. package/dest/archiver/kv_archiver_store/log_store.d.ts.map +0 -1
  177. package/dest/archiver/kv_archiver_store/log_store.js +0 -336
  178. package/dest/archiver/kv_archiver_store/message_store.d.ts +0 -39
  179. package/dest/archiver/kv_archiver_store/message_store.d.ts.map +0 -1
  180. package/dest/archiver/structs/data_retrieval.d.ts.map +0 -1
  181. package/dest/archiver/structs/inbox_message.d.ts +0 -15
  182. package/dest/archiver/structs/inbox_message.d.ts.map +0 -1
  183. package/dest/archiver/structs/published.d.ts +0 -3
  184. package/dest/archiver/structs/published.d.ts.map +0 -1
  185. package/dest/archiver/validation.d.ts +0 -17
  186. package/dest/archiver/validation.d.ts.map +0 -1
  187. package/dest/rpc/index.d.ts +0 -9
  188. package/dest/rpc/index.d.ts.map +0 -1
  189. package/dest/rpc/index.js +0 -15
  190. package/src/archiver/archiver.ts +0 -1858
  191. package/src/archiver/archiver_store.ts +0 -305
  192. package/src/archiver/archiver_store_test_suite.ts +0 -1264
  193. package/src/archiver/errors.ts +0 -26
  194. package/src/archiver/index.ts +0 -6
  195. package/src/archiver/kv_archiver_store/block_store.ts +0 -481
  196. package/src/archiver/kv_archiver_store/kv_archiver_store.ts +0 -422
  197. package/src/archiver/kv_archiver_store/log_store.ts +0 -406
  198. package/src/rpc/index.ts +0 -16
  199. /package/dest/{archiver/structs → structs}/data_retrieval.js +0 -0
  200. /package/dest/{archiver/structs → structs}/published.js +0 -0
  201. /package/src/{archiver/structs → structs}/data_retrieval.ts +0 -0
@@ -0,0 +1,447 @@
1
+ import { toArray } from '@aztec/foundation/iterable';
2
+ import { createLogger } from '@aztec/foundation/log';
3
+ import { FunctionSelector } from '@aztec/stdlib/abi';
4
+ import { L2BlockHash } from '@aztec/stdlib/block';
5
+ import { join } from 'path';
6
+ import { BlockStore } from './block_store.js';
7
+ import { ContractClassStore } from './contract_class_store.js';
8
+ import { ContractInstanceStore } from './contract_instance_store.js';
9
+ import { LogStore } from './log_store.js';
10
+ import { MessageStore } from './message_store.js';
11
+ export const ARCHIVER_DB_VERSION = 5;
12
+ export const MAX_FUNCTION_SIGNATURES = 1000;
13
+ export const MAX_FUNCTION_NAME_LEN = 256;
14
+ /**
15
+ * LMDB-based data store for the archiver.
16
+ * Stores all archiver data including blocks, logs, contract classes/instances, and L1 to L2 messages.
17
+ */ export class KVArchiverDataStore {
18
+ db;
19
+ static SCHEMA_VERSION = ARCHIVER_DB_VERSION;
20
+ #blockStore;
21
+ #logStore;
22
+ #messageStore;
23
+ #contractClassStore;
24
+ #contractInstanceStore;
25
+ functionNames;
26
+ #log;
27
+ constructor(db, logsMaxPageSize = 1000, l1Constants){
28
+ this.db = db;
29
+ this.functionNames = new Map();
30
+ this.#log = createLogger('archiver:data-store');
31
+ this.#blockStore = new BlockStore(db, l1Constants);
32
+ this.#logStore = new LogStore(db, this.#blockStore, logsMaxPageSize);
33
+ this.#messageStore = new MessageStore(db);
34
+ this.#contractClassStore = new ContractClassStore(db);
35
+ this.#contractInstanceStore = new ContractInstanceStore(db);
36
+ }
37
+ /** Opens a new transaction to the underlying store and runs all operations within it. */ transactionAsync(callback) {
38
+ return this.db.transactionAsync(callback);
39
+ }
40
+ getBlockNumber() {
41
+ return this.#blockStore.getLatestL2BlockNumber();
42
+ }
43
+ async getContract(address, maybeTimestamp) {
44
+ const [header] = await this.getBlockHeaders(await this.getBlockNumber(), 1);
45
+ const timestamp = maybeTimestamp ?? header.globalVariables.timestamp;
46
+ return this.getContractInstance(address, timestamp);
47
+ }
48
+ /** Backups the archiver db to the target folder. Returns the path to the db file. */ async backupTo(path, compress = true) {
49
+ await this.db.backupTo(path, compress);
50
+ return join(path, 'data.mdb');
51
+ }
52
+ /** Closes the underlying data store. */ close() {
53
+ return this.db.close();
54
+ }
55
+ /** Computes the finalized block number based on the proven block number. */ getFinalizedL2BlockNumber() {
56
+ return this.#blockStore.getFinalizedL2BlockNumber();
57
+ }
58
+ /** Looks up a public function name given a selector. */ getDebugFunctionName(_address, selector) {
59
+ return Promise.resolve(this.functionNames.get(selector.toString()));
60
+ }
61
+ /** Register a public function signature, so it can be looked up by selector. */ async registerContractFunctionSignatures(signatures) {
62
+ for (const sig of signatures){
63
+ if (this.functionNames.size > MAX_FUNCTION_SIGNATURES) {
64
+ return;
65
+ }
66
+ try {
67
+ const selector = await FunctionSelector.fromSignature(sig);
68
+ this.functionNames.set(selector.toString(), sig.slice(0, sig.indexOf('(')).slice(0, MAX_FUNCTION_NAME_LEN));
69
+ } catch {
70
+ this.#log.warn(`Failed to parse signature: ${sig}. Ignoring`);
71
+ }
72
+ }
73
+ }
74
+ /**
75
+ * Returns a contract class given its id, or undefined if not exists.
76
+ * @param id - Id of the contract class.
77
+ */ getContractClass(id) {
78
+ return this.#contractClassStore.getContractClass(id);
79
+ }
80
+ /** Returns the list of all class ids known by the archiver. */ getContractClassIds() {
81
+ return this.#contractClassStore.getContractClassIds();
82
+ }
83
+ /**
84
+ * Returns a contract instance given its address and the given timestamp, or undefined if not exists.
85
+ * @param address - Address of the contract.
86
+ * @param timestamp - Timestamp to get the contract instance at. Contract updates might change the instance.
87
+ * @returns The contract instance or undefined if not found.
88
+ */ getContractInstance(address, timestamp) {
89
+ return this.#contractInstanceStore.getContractInstance(address, timestamp);
90
+ }
91
+ getContractInstanceDeploymentBlockNumber(address) {
92
+ return this.#contractInstanceStore.getContractInstanceDeploymentBlockNumber(address);
93
+ }
94
+ /**
95
+ * Add new contract classes from an L2 block to the store's list.
96
+ * @param data - List of contract classes to be added.
97
+ * @param bytecodeCommitments - Bytecode commitments for the contract classes.
98
+ * @param blockNumber - Number of the L2 block the contracts were registered in.
99
+ * @returns True if the operation is successful.
100
+ */ async addContractClasses(data, bytecodeCommitments, blockNumber) {
101
+ return (await Promise.all(data.map((c, i)=>this.#contractClassStore.addContractClass(c, bytecodeCommitments[i], blockNumber)))).every(Boolean);
102
+ }
103
+ async deleteContractClasses(data, blockNumber) {
104
+ return (await Promise.all(data.map((c)=>this.#contractClassStore.deleteContractClasses(c, blockNumber)))).every(Boolean);
105
+ }
106
+ getBytecodeCommitment(contractClassId) {
107
+ return this.#contractClassStore.getBytecodeCommitment(contractClassId);
108
+ }
109
+ /** Adds private functions to a contract class. */ addFunctions(contractClassId, privateFunctions, utilityFunctions) {
110
+ return this.#contractClassStore.addFunctions(contractClassId, privateFunctions, utilityFunctions);
111
+ }
112
+ /**
113
+ * Add new contract instances from an L2 block to the store's list.
114
+ * @param data - List of contract instances to be added.
115
+ * @param blockNumber - Number of the L2 block the instances were deployed in.
116
+ * @returns True if the operation is successful.
117
+ */ async addContractInstances(data, blockNumber) {
118
+ return (await Promise.all(data.map((c)=>this.#contractInstanceStore.addContractInstance(c, blockNumber)))).every(Boolean);
119
+ }
120
+ async deleteContractInstances(data, _blockNumber) {
121
+ return (await Promise.all(data.map((c)=>this.#contractInstanceStore.deleteContractInstance(c)))).every(Boolean);
122
+ }
123
+ /**
124
+ * Add new contract instance updates
125
+ * @param data - List of contract updates to be added.
126
+ * @param timestamp - Timestamp at which the updates were scheduled.
127
+ * @returns True if the operation is successful.
128
+ */ async addContractInstanceUpdates(data, timestamp) {
129
+ return (await Promise.all(data.map((update, logIndex)=>this.#contractInstanceStore.addContractInstanceUpdate(update, timestamp, logIndex)))).every(Boolean);
130
+ }
131
+ async deleteContractInstanceUpdates(data, timestamp) {
132
+ return (await Promise.all(data.map((update, logIndex)=>this.#contractInstanceStore.deleteContractInstanceUpdate(update, timestamp, logIndex)))).every(Boolean);
133
+ }
134
+ /**
135
+ * Append new proposed blocks to the store's list.
136
+ * These are uncheckpointed blocks that have been proposed by the sequencer but not yet included in a checkpoint on L1.
137
+ * For checkpointed blocks (already published to L1), use addCheckpoints() instead.
138
+ * @param blocks - The proposed L2 blocks to be added to the store.
139
+ * @returns True if the operation is successful.
140
+ */ addProposedBlocks(blocks, opts = {}) {
141
+ return this.#blockStore.addProposedBlocks(blocks, opts);
142
+ }
143
+ /**
144
+ * Returns an array of checkpoint objects
145
+ * @param from The first checkpoint number to be retrieved
146
+ * @param limit The maximum number of checkpoints to retrieve
147
+ * @returns The array of requested checkpoint data objects
148
+ */ getRangeOfCheckpoints(from, limit) {
149
+ return this.#blockStore.getRangeOfCheckpoints(from, limit);
150
+ }
151
+ /**
152
+ * Returns the number of the latest block
153
+ * @returns The number of the latest block
154
+ */ getLatestBlockNumber() {
155
+ return this.#blockStore.getLatestBlockNumber();
156
+ }
157
+ /**
158
+ * Removes all checkpoints with checkpoint number > checkpointNumber.
159
+ * Also removes ALL blocks (both checkpointed and uncheckpointed) after the last block of the given checkpoint.
160
+ * @param checkpointNumber - Remove all checkpoints strictly after this one.
161
+ */ removeCheckpointsAfter(checkpointNumber) {
162
+ return this.#blockStore.removeCheckpointsAfter(checkpointNumber);
163
+ }
164
+ /**
165
+ * Appends new checkpoints, and their blocks to the store's collection
166
+ * @param checkpoints The collection of checkpoints to be added
167
+ * @returns True if the operation is successful
168
+ */ addCheckpoints(checkpoints) {
169
+ return this.#blockStore.addCheckpoints(checkpoints);
170
+ }
171
+ /**
172
+ * Returns the block for the given number, or undefined if not exists.
173
+ * @param number - The block number to return.
174
+ */ getCheckpointedBlock(number) {
175
+ return this.#blockStore.getCheckpointedBlock(number);
176
+ }
177
+ /**
178
+ * Returns the block for the given hash, or undefined if not exists.
179
+ * @param blockHash - The block hash to return.
180
+ */ getCheckpointedBlockByHash(blockHash) {
181
+ return this.#blockStore.getCheckpointedBlockByHash(blockHash);
182
+ }
183
+ /**
184
+ * Returns the block for the given archive root, or undefined if not exists.
185
+ * @param archive - The archive root to return.
186
+ */ getCheckpointedBlockByArchive(archive) {
187
+ return this.#blockStore.getCheckpointedBlockByArchive(archive);
188
+ }
189
+ /**
190
+ * Returns the block for the given number, or undefined if not exists.
191
+ * @param number - The block number to return.
192
+ */ getBlock(number) {
193
+ return this.#blockStore.getBlock(number);
194
+ }
195
+ /**
196
+ * Returns the block for the given hash, or undefined if not exists.
197
+ * @param blockHash - The block hash to return.
198
+ */ getBlockByHash(blockHash) {
199
+ return this.#blockStore.getBlockByHash(L2BlockHash.fromField(blockHash));
200
+ }
201
+ /**
202
+ * Returns the block for the given archive root, or undefined if not exists.
203
+ * @param archive - The archive root to return.
204
+ */ getBlockByArchive(archive) {
205
+ return this.#blockStore.getBlockByArchive(archive);
206
+ }
207
+ /**
208
+ * Gets up to `limit` amount of published L2 blocks starting from `from`.
209
+ * @param from - Number of the first block to return (inclusive).
210
+ * @param limit - The number of blocks to return.
211
+ * @returns The requested L2 blocks.
212
+ */ getBlocks(from, limit) {
213
+ return toArray(this.#blockStore.getBlocks(from, limit));
214
+ }
215
+ /**
216
+ * Gets up to `limit` amount of checkpointed L2 blocks starting from `from`.
217
+ * @param from - Number of the first block to return (inclusive).
218
+ * @param limit - The number of blocks to return.
219
+ * @returns The requested checkpointed L2 blocks.
220
+ */ getCheckpointedBlocks(from, limit) {
221
+ return toArray(this.#blockStore.getCheckpointedBlocks(from, limit));
222
+ }
223
+ /**
224
+ * Gets up to `limit` amount of L2 block headers starting from `from`.
225
+ * @param start - Number of the first block to return (inclusive).
226
+ * @param limit - The number of blocks to return.
227
+ * @returns The requested L2 block headers.
228
+ */ getBlockHeaders(start, limit) {
229
+ return toArray(this.#blockStore.getBlockHeaders(start, limit));
230
+ }
231
+ /**
232
+ * Returns the block header for the given hash, or undefined if not exists.
233
+ * @param blockHash - The block hash to return.
234
+ */ getBlockHeaderByHash(blockHash) {
235
+ return this.#blockStore.getBlockHeaderByHash(L2BlockHash.fromField(blockHash));
236
+ }
237
+ /**
238
+ * Returns the block header for the given archive root, or undefined if not exists.
239
+ * @param archive - The archive root to return.
240
+ */ getBlockHeaderByArchive(archive) {
241
+ return this.#blockStore.getBlockHeaderByArchive(archive);
242
+ }
243
+ /**
244
+ * Gets a tx effect.
245
+ * @param txHash - The hash of the tx corresponding to the tx effect.
246
+ * @returns The requested tx effect with block info (or undefined if not found).
247
+ */ getTxEffect(txHash) {
248
+ return this.#blockStore.getTxEffect(txHash);
249
+ }
250
+ /**
251
+ * Gets a receipt of a settled tx.
252
+ * @param txHash - The hash of a tx we try to get the receipt for.
253
+ * @returns The requested tx receipt (or undefined if not found).
254
+ */ getSettledTxReceipt(txHash) {
255
+ return this.#blockStore.getSettledTxReceipt(txHash);
256
+ }
257
+ /**
258
+ * Append new logs to the store's list.
259
+ * @param blocks - The blocks for which to add the logs.
260
+ * @returns True if the operation is successful.
261
+ */ addLogs(blocks) {
262
+ return this.#logStore.addLogs(blocks);
263
+ }
264
+ deleteLogs(blocks) {
265
+ return this.#logStore.deleteLogs(blocks);
266
+ }
267
+ /**
268
+ * Get the total number of L1 to L2 messages
269
+ * @returns The number of L1 to L2 messages in the store
270
+ */ getTotalL1ToL2MessageCount() {
271
+ return this.#messageStore.getTotalL1ToL2MessageCount();
272
+ }
273
+ /** Returns the last L1 to L2 message stored. */ getLastL1ToL2Message() {
274
+ return this.#messageStore.getLastMessage();
275
+ }
276
+ /**
277
+ * Append L1 to L2 messages to the store.
278
+ * @param messages - The L1 to L2 messages to be added to the store.
279
+ * @returns True if the operation is successful.
280
+ */ addL1ToL2Messages(messages) {
281
+ return this.#messageStore.addL1ToL2Messages(messages);
282
+ }
283
+ /**
284
+ * Gets the L1 to L2 message index in the L1 to L2 message tree.
285
+ * @param l1ToL2Message - The L1 to L2 message.
286
+ * @returns The index of the L1 to L2 message in the L1 to L2 message tree (undefined if not found).
287
+ */ getL1ToL2MessageIndex(l1ToL2Message) {
288
+ return this.#messageStore.getL1ToL2MessageIndex(l1ToL2Message);
289
+ }
290
+ /**
291
+ * Gets L1 to L2 message (to be) included in a given checkpoint.
292
+ * @param checkpointNumber - Checkpoint number to get messages for.
293
+ * @returns The L1 to L2 messages/leaves of the messages subtree (throws if not found).
294
+ */ getL1ToL2Messages(checkpointNumber) {
295
+ return this.#messageStore.getL1ToL2Messages(checkpointNumber);
296
+ }
297
+ /**
298
+ * Gets private logs that match any of the `tags`. For each tag, an array of matching logs is returned. An empty
299
+ * array implies no logs match that tag.
300
+ * @param tags - The tags to search for.
301
+ * @param page - The page number (0-indexed) for pagination. Returns at most 10 logs per tag per page.
302
+ */ getPrivateLogsByTags(tags, page) {
303
+ try {
304
+ return this.#logStore.getPrivateLogsByTags(tags, page);
305
+ } catch (err) {
306
+ return Promise.reject(err);
307
+ }
308
+ }
309
+ /**
310
+ * Gets public logs that match any of the `tags` from the specified contract. For each tag, an array of matching
311
+ * logs is returned. An empty array implies no logs match that tag.
312
+ * @param contractAddress - The contract address to search logs for.
313
+ * @param tags - The tags to search for.
314
+ * @param page - The page number (0-indexed) for pagination. Returns at most 10 logs per tag per page.
315
+ */ getPublicLogsByTagsFromContract(contractAddress, tags, page) {
316
+ try {
317
+ return this.#logStore.getPublicLogsByTagsFromContract(contractAddress, tags, page);
318
+ } catch (err) {
319
+ return Promise.reject(err);
320
+ }
321
+ }
322
+ /**
323
+ * Gets public logs based on the provided filter.
324
+ * @param filter - The filter to apply to the logs.
325
+ * @returns The requested logs.
326
+ */ getPublicLogs(filter) {
327
+ try {
328
+ return this.#logStore.getPublicLogs(filter);
329
+ } catch (err) {
330
+ return Promise.reject(err);
331
+ }
332
+ }
333
+ /**
334
+ * Gets contract class logs based on the provided filter.
335
+ * @param filter - The filter to apply to the logs.
336
+ * @returns The requested logs.
337
+ */ getContractClassLogs(filter) {
338
+ try {
339
+ return this.#logStore.getContractClassLogs(filter);
340
+ } catch (err) {
341
+ return Promise.reject(err);
342
+ }
343
+ }
344
+ /**
345
+ * Gets the number of the latest proven checkpoint processed.
346
+ * @returns The number of the latest proven checkpoint processed.
347
+ */ getProvenCheckpointNumber() {
348
+ return this.#blockStore.getProvenCheckpointNumber();
349
+ }
350
+ /**
351
+ * Stores the number of the latest proven checkpoint processed.
352
+ * @param checkpointNumber - The number of the latest proven checkpoint processed.
353
+ */ async setProvenCheckpointNumber(checkpointNumber) {
354
+ await this.#blockStore.setProvenCheckpointNumber(checkpointNumber);
355
+ }
356
+ async setBlockSynchedL1BlockNumber(l1BlockNumber) {
357
+ await this.#blockStore.setSynchedL1BlockNumber(l1BlockNumber);
358
+ }
359
+ /**
360
+ * Stores the l1 block that messages have been synched until
361
+ */ async setMessageSynchedL1Block(l1Block) {
362
+ await this.#messageStore.setSynchedL1Block(l1Block);
363
+ }
364
+ /**
365
+ * Returns the number of the most recent proven block
366
+ * @returns The number of the most recent proven block
367
+ */ getProvenBlockNumber() {
368
+ return this.#blockStore.getProvenBlockNumber();
369
+ }
370
+ /**
371
+ * Gets the synch point of the archiver
372
+ */ async getSynchPoint() {
373
+ const [blocksSynchedTo, messagesSynchedTo] = await Promise.all([
374
+ this.#blockStore.getSynchedL1BlockNumber(),
375
+ this.#messageStore.getSynchedL1Block()
376
+ ]);
377
+ return {
378
+ blocksSynchedTo,
379
+ messagesSynchedTo
380
+ };
381
+ }
382
+ /** Estimates the size of the store in bytes. */ estimateSize() {
383
+ return this.db.estimateSize();
384
+ }
385
+ /** Deletes all L1 to L2 messages up until (excluding) the target checkpoint number. */ rollbackL1ToL2MessagesToCheckpoint(targetCheckpointNumber) {
386
+ return this.#messageStore.rollbackL1ToL2MessagesToCheckpoint(targetCheckpointNumber);
387
+ }
388
+ /** Returns an async iterator to all L1 to L2 messages on the range. */ iterateL1ToL2Messages(range = {}) {
389
+ return this.#messageStore.iterateL1ToL2Messages(range);
390
+ }
391
+ /** Removes all L1 to L2 messages starting from the given index (inclusive). */ removeL1ToL2Messages(startIndex) {
392
+ return this.#messageStore.removeL1ToL2Messages(startIndex);
393
+ }
394
+ /** Returns the last synced validation status of the pending chain. */ getPendingChainValidationStatus() {
395
+ return this.#blockStore.getPendingChainValidationStatus();
396
+ }
397
+ /** Sets the last synced validation status of the pending chain. */ setPendingChainValidationStatus(status) {
398
+ return this.#blockStore.setPendingChainValidationStatus(status);
399
+ }
400
+ /**
401
+ * Gets the number of the latest L2 block processed.
402
+ * @returns The number of the latest L2 block processed.
403
+ */ getCheckpointedL2BlockNumber() {
404
+ return this.#blockStore.getCheckpointedL2BlockNumber();
405
+ }
406
+ /**
407
+ * Gets the number of the latest published checkpoint processed.
408
+ * @returns The number of the latest published checkpoint processed
409
+ */ getSynchedCheckpointNumber() {
410
+ return this.#blockStore.getLatestCheckpointNumber();
411
+ }
412
+ /**
413
+ * Stores the l1 block number that checkpoints have been synched until
414
+ * @param l1BlockNumber - The l1 block number
415
+ */ async setCheckpointSynchedL1BlockNumber(l1BlockNumber) {
416
+ await this.#blockStore.setSynchedL1BlockNumber(l1BlockNumber);
417
+ }
418
+ /**
419
+ * Retrieves all blocks for the requested checkpoint
420
+ * @param checkpointNumber Retrieves all blocks for the given checkpoint
421
+ * @returns The collection of blocks for the requested checkpoint if available (undefined otherwise)
422
+ */ getBlocksForCheckpoint(checkpointNumber) {
423
+ return this.#blockStore.getBlocksForCheckpoint(checkpointNumber);
424
+ }
425
+ /**
426
+ * Returns checkpoint data for the requested checkpoint number
427
+ * @param checkpointNumber - The checkpoint requested
428
+ * @returns The checkpoint data or undefined if not found
429
+ */ getCheckpointData(checkpointNumber) {
430
+ return this.#blockStore.getCheckpointData(checkpointNumber);
431
+ }
432
+ /**
433
+ * Gets all blocks that have the given slot number.
434
+ * @param slotNumber - The slot number to search for.
435
+ * @returns All blocks with the given slot number.
436
+ */ getBlocksForSlot(slotNumber) {
437
+ return this.#blockStore.getBlocksForSlot(slotNumber);
438
+ }
439
+ /**
440
+ * Removes all blocks with block number > blockNumber.
441
+ * Does not remove any associated checkpoints.
442
+ * @param blockNumber - The block number to remove after.
443
+ * @returns The removed blocks (for event emission).
444
+ */ removeBlocksAfter(blockNumber) {
445
+ return this.#blockStore.removeBlocksAfter(blockNumber);
446
+ }
447
+ }
@@ -0,0 +1,54 @@
1
+ import type { AztecAsyncKVStore } from '@aztec/kv-store';
2
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
3
+ import { L2Block } from '@aztec/stdlib/block';
4
+ import type { GetContractClassLogsResponse, GetPublicLogsResponse } from '@aztec/stdlib/interfaces/client';
5
+ import { type LogFilter, type SiloedTag, Tag, TxScopedL2Log } from '@aztec/stdlib/logs';
6
+ import type { BlockStore } from './block_store.js';
7
+ /**
8
+ * A store for logs
9
+ */
10
+ export declare class LogStore {
11
+ #private;
12
+ private db;
13
+ private blockStore;
14
+ constructor(db: AztecAsyncKVStore, blockStore: BlockStore, logsMaxPageSize?: number);
15
+ /**
16
+ * Append new logs to the store's list.
17
+ * @param blocks - The blocks for which to add the logs.
18
+ * @returns True if the operation is successful.
19
+ */
20
+ addLogs(blocks: L2Block[]): Promise<boolean>;
21
+ deleteLogs(blocks: L2Block[]): Promise<boolean>;
22
+ /**
23
+ * Gets private logs that match any of the `tags`. For each tag, an array of matching logs is returned. An empty
24
+ * array implies no logs match that tag.
25
+ * @param tags - The tags to search for.
26
+ * @param page - The page number (0-indexed) for pagination.
27
+ * @returns An array of log arrays, one per tag. Returns at most MAX_LOGS_PER_TAG logs per tag per page. If
28
+ * MAX_LOGS_PER_TAG logs are returned for a tag, the caller should fetch the next page to check for more logs.
29
+ */
30
+ getPrivateLogsByTags(tags: SiloedTag[], page?: number): Promise<TxScopedL2Log[][]>;
31
+ /**
32
+ * Gets public logs that match any of the `tags` from the specified contract. For each tag, an array of matching
33
+ * logs is returned. An empty array implies no logs match that tag.
34
+ * @param contractAddress - The contract address to search logs for.
35
+ * @param tags - The tags to search for.
36
+ * @param page - The page number (0-indexed) for pagination.
37
+ * @returns An array of log arrays, one per tag. Returns at most MAX_LOGS_PER_TAG logs per tag per page. If
38
+ * MAX_LOGS_PER_TAG logs are returned for a tag, the caller should fetch the next page to check for more logs.
39
+ */
40
+ getPublicLogsByTagsFromContract(contractAddress: AztecAddress, tags: Tag[], page?: number): Promise<TxScopedL2Log[][]>;
41
+ /**
42
+ * Gets public logs based on the provided filter.
43
+ * @param filter - The filter to apply to the logs.
44
+ * @returns The requested logs.
45
+ */
46
+ getPublicLogs(filter: LogFilter): Promise<GetPublicLogsResponse>;
47
+ /**
48
+ * Gets contract class logs based on the provided filter.
49
+ * @param filter - The filter to apply to the logs.
50
+ * @returns The requested logs.
51
+ */
52
+ getContractClassLogs(filter: LogFilter): Promise<GetContractClassLogsResponse>;
53
+ }
54
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibG9nX3N0b3JlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvc3RvcmUvbG9nX3N0b3JlLnRzIl0sIm5hbW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