@aztec/archiver 0.0.1-commit.d3ec352c → 0.0.1-commit.f295ac2

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 +147 -22
  2. package/dest/archiver.d.ts +135 -0
  3. package/dest/archiver.d.ts.map +1 -0
  4. package/dest/archiver.js +769 -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 +36 -0
  9. package/dest/errors.d.ts.map +1 -0
  10. package/dest/errors.js +54 -0
  11. package/dest/factory.d.ts +5 -6
  12. package/dest/factory.d.ts.map +1 -1
  13. package/dest/factory.js +82 -5
  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 +75 -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 +85 -0
  45. package/dest/modules/data_source_base.d.ts.map +1 -0
  46. package/dest/modules/data_source_base.js +291 -0
  47. package/dest/modules/data_store_updater.d.ts +69 -0
  48. package/dest/modules/data_store_updater.d.ts.map +1 -0
  49. package/dest/modules/data_store_updater.js +304 -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 +178 -0
  60. package/dest/store/block_store.d.ts.map +1 -0
  61. package/dest/store/block_store.js +680 -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 +331 -0
  69. package/dest/store/kv_archiver_store.d.ts.map +1 -0
  70. package/dest/store/kv_archiver_store.js +438 -0
  71. package/dest/store/log_store.d.ts +45 -0
  72. package/dest/store/log_store.d.ts.map +1 -0
  73. package/dest/store/log_store.js +422 -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 -6
  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 +5 -6
  91. package/dest/test/mock_archiver.d.ts.map +1 -1
  92. package/dest/test/mock_archiver.js +6 -11
  93. package/dest/test/mock_l1_to_l2_message_source.d.ts +6 -7
  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 +19 -14
  96. package/dest/test/mock_l2_block_source.d.ts +28 -14
  97. package/dest/test/mock_l2_block_source.d.ts.map +1 -1
  98. package/dest/test/mock_l2_block_source.js +160 -52
  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 -10
  102. package/package.json +17 -18
  103. package/src/archiver.ts +525 -0
  104. package/src/{archiver/config.ts → config.ts} +28 -12
  105. package/src/errors.ts +90 -0
  106. package/src/factory.ts +118 -6
  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 +182 -0
  111. package/src/l1/calldata_retriever.ts +641 -0
  112. package/src/{archiver → l1}/data_retrieval.ts +136 -218
  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 +414 -0
  119. package/src/modules/data_store_updater.ts +419 -0
  120. package/src/{archiver → modules}/instrumentation.ts +24 -59
  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 +919 -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 +622 -0
  127. package/src/store/log_store.ts +552 -0
  128. package/src/{archiver/kv_archiver_store → store}/message_store.ts +21 -18
  129. package/src/{archiver/structs → structs}/inbox_message.ts +7 -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 +8 -13
  141. package/src/test/mock_l1_to_l2_message_source.ts +16 -15
  142. package/src/test/mock_l2_block_source.ts +184 -64
  143. package/src/test/mock_structs.ts +256 -11
  144. package/dest/archiver/archiver.d.ts +0 -290
  145. package/dest/archiver/archiver.d.ts.map +0 -1
  146. package/dest/archiver/archiver.js +0 -1434
  147. package/dest/archiver/archiver_store.d.ts +0 -256
  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 -80
  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 -125
  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 -371
  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 -169
  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 -337
  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 -1880
  191. package/src/archiver/archiver_store.ts +0 -310
  192. package/src/archiver/archiver_store_test_suite.ts +0 -1295
  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 -482
  196. package/src/archiver/kv_archiver_store/kv_archiver_store.ts +0 -423
  197. package/src/archiver/kv_archiver_store/log_store.ts +0 -407
  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,438 @@
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){
28
+ this.db = db;
29
+ this.functionNames = new Map();
30
+ this.#log = createLogger('archiver:data-store');
31
+ this.#blockStore = new BlockStore(db);
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
+ /** Looks up a public function name given a selector. */ getDebugFunctionName(_address, selector) {
56
+ return Promise.resolve(this.functionNames.get(selector.toString()));
57
+ }
58
+ /** Register a public function signature, so it can be looked up by selector. */ async registerContractFunctionSignatures(signatures) {
59
+ for (const sig of signatures){
60
+ if (this.functionNames.size > MAX_FUNCTION_SIGNATURES) {
61
+ return;
62
+ }
63
+ try {
64
+ const selector = await FunctionSelector.fromSignature(sig);
65
+ this.functionNames.set(selector.toString(), sig.slice(0, sig.indexOf('(')).slice(0, MAX_FUNCTION_NAME_LEN));
66
+ } catch {
67
+ this.#log.warn(`Failed to parse signature: ${sig}. Ignoring`);
68
+ }
69
+ }
70
+ }
71
+ /**
72
+ * Returns a contract class given its id, or undefined if not exists.
73
+ * @param id - Id of the contract class.
74
+ */ getContractClass(id) {
75
+ return this.#contractClassStore.getContractClass(id);
76
+ }
77
+ /** Returns the list of all class ids known by the archiver. */ getContractClassIds() {
78
+ return this.#contractClassStore.getContractClassIds();
79
+ }
80
+ /**
81
+ * Returns a contract instance given its address and the given timestamp, or undefined if not exists.
82
+ * @param address - Address of the contract.
83
+ * @param timestamp - Timestamp to get the contract instance at. Contract updates might change the instance.
84
+ * @returns The contract instance or undefined if not found.
85
+ */ getContractInstance(address, timestamp) {
86
+ return this.#contractInstanceStore.getContractInstance(address, timestamp);
87
+ }
88
+ getContractInstanceDeploymentBlockNumber(address) {
89
+ return this.#contractInstanceStore.getContractInstanceDeploymentBlockNumber(address);
90
+ }
91
+ /**
92
+ * Add new contract classes from an L2 block to the store's list.
93
+ * @param data - List of contract classes to be added.
94
+ * @param bytecodeCommitments - Bytecode commitments for the contract classes.
95
+ * @param blockNumber - Number of the L2 block the contracts were registered in.
96
+ * @returns True if the operation is successful.
97
+ */ async addContractClasses(data, bytecodeCommitments, blockNumber) {
98
+ return (await Promise.all(data.map((c, i)=>this.#contractClassStore.addContractClass(c, bytecodeCommitments[i], blockNumber)))).every(Boolean);
99
+ }
100
+ async deleteContractClasses(data, blockNumber) {
101
+ return (await Promise.all(data.map((c)=>this.#contractClassStore.deleteContractClasses(c, blockNumber)))).every(Boolean);
102
+ }
103
+ getBytecodeCommitment(contractClassId) {
104
+ return this.#contractClassStore.getBytecodeCommitment(contractClassId);
105
+ }
106
+ /** Adds private functions to a contract class. */ addFunctions(contractClassId, privateFunctions, utilityFunctions) {
107
+ return this.#contractClassStore.addFunctions(contractClassId, privateFunctions, utilityFunctions);
108
+ }
109
+ /**
110
+ * Add new contract instances from an L2 block to the store's list.
111
+ * @param data - List of contract instances to be added.
112
+ * @param blockNumber - Number of the L2 block the instances were deployed in.
113
+ * @returns True if the operation is successful.
114
+ */ async addContractInstances(data, blockNumber) {
115
+ return (await Promise.all(data.map((c)=>this.#contractInstanceStore.addContractInstance(c, blockNumber)))).every(Boolean);
116
+ }
117
+ async deleteContractInstances(data, _blockNumber) {
118
+ return (await Promise.all(data.map((c)=>this.#contractInstanceStore.deleteContractInstance(c)))).every(Boolean);
119
+ }
120
+ /**
121
+ * Add new contract instance updates
122
+ * @param data - List of contract updates to be added.
123
+ * @param timestamp - Timestamp at which the updates were scheduled.
124
+ * @returns True if the operation is successful.
125
+ */ async addContractInstanceUpdates(data, timestamp) {
126
+ return (await Promise.all(data.map((update, logIndex)=>this.#contractInstanceStore.addContractInstanceUpdate(update, timestamp, logIndex)))).every(Boolean);
127
+ }
128
+ async deleteContractInstanceUpdates(data, timestamp) {
129
+ return (await Promise.all(data.map((update, logIndex)=>this.#contractInstanceStore.deleteContractInstanceUpdate(update, timestamp, logIndex)))).every(Boolean);
130
+ }
131
+ /**
132
+ * Append new blocks to the store's list.
133
+ * @param blocks - The L2 blocks to be added to the store and the last processed L1 block.
134
+ * @returns True if the operation is successful.
135
+ */ addBlocks(blocks, opts = {}) {
136
+ return this.#blockStore.addBlocks(blocks, opts);
137
+ }
138
+ /**
139
+ * Returns an array of checkpoint objects
140
+ * @param from The first checkpoint number to be retrieved
141
+ * @param limit The maximum number of checkpoints to retrieve
142
+ * @returns The array of requested checkpoint data objects
143
+ */ getRangeOfCheckpoints(from, limit) {
144
+ return this.#blockStore.getRangeOfCheckpoints(from, limit);
145
+ }
146
+ /**
147
+ * Returns the number of the latest block
148
+ * @returns The number of the latest block
149
+ */ getLatestBlockNumber() {
150
+ return this.#blockStore.getLatestBlockNumber();
151
+ }
152
+ /**
153
+ * Unwinds checkpoints from the database
154
+ * @param from - The tip of the chain, passed for verification purposes,
155
+ * ensuring that we don't end up deleting something we did not intend
156
+ * @param checkpointsToUnwind - The number of checkpoints we are to unwind
157
+ * @returns True if the operation is successful
158
+ */ unwindCheckpoints(from, checkpointsToUnwind) {
159
+ return this.#blockStore.unwindCheckpoints(from, checkpointsToUnwind);
160
+ }
161
+ /**
162
+ * Appends new checkpoints, and their blocks to the store's collection
163
+ * @param checkpoints The collection of checkpoints to be added
164
+ * @returns True if the operation is successful
165
+ */ addCheckpoints(checkpoints) {
166
+ return this.#blockStore.addCheckpoints(checkpoints);
167
+ }
168
+ /**
169
+ * Returns the block for the given number, or undefined if not exists.
170
+ * @param number - The block number to return.
171
+ */ getCheckpointedBlock(number) {
172
+ return this.#blockStore.getCheckpointedBlock(number);
173
+ }
174
+ /**
175
+ * Returns the block for the given hash, or undefined if not exists.
176
+ * @param blockHash - The block hash to return.
177
+ */ getCheckpointedBlockByHash(blockHash) {
178
+ return this.#blockStore.getCheckpointedBlockByHash(blockHash);
179
+ }
180
+ /**
181
+ * Returns the block for the given archive root, or undefined if not exists.
182
+ * @param archive - The archive root to return.
183
+ */ getCheckpointedBlockByArchive(archive) {
184
+ return this.#blockStore.getCheckpointedBlockByArchive(archive);
185
+ }
186
+ /**
187
+ * Returns the block for the given number, or undefined if not exists.
188
+ * @param number - The block number to return.
189
+ */ getBlock(number) {
190
+ return this.#blockStore.getBlock(number);
191
+ }
192
+ /**
193
+ * Returns the block for the given hash, or undefined if not exists.
194
+ * @param blockHash - The block hash to return.
195
+ */ getBlockByHash(blockHash) {
196
+ return this.#blockStore.getBlockByHash(L2BlockHash.fromField(blockHash));
197
+ }
198
+ /**
199
+ * Returns the block for the given archive root, or undefined if not exists.
200
+ * @param archive - The archive root to return.
201
+ */ getBlockByArchive(archive) {
202
+ return this.#blockStore.getBlockByArchive(archive);
203
+ }
204
+ /**
205
+ * Gets up to `limit` amount of published L2 blocks starting from `from`.
206
+ * @param from - Number of the first block to return (inclusive).
207
+ * @param limit - The number of blocks to return.
208
+ * @returns The requested L2 blocks.
209
+ */ getBlocks(from, limit) {
210
+ return toArray(this.#blockStore.getBlocks(from, limit));
211
+ }
212
+ /**
213
+ * Gets up to `limit` amount of checkpointed L2 blocks starting from `from`.
214
+ * @param from - Number of the first block to return (inclusive).
215
+ * @param limit - The number of blocks to return.
216
+ * @returns The requested checkpointed L2 blocks.
217
+ */ getCheckpointedBlocks(from, limit) {
218
+ return toArray(this.#blockStore.getCheckpointedBlocks(from, limit));
219
+ }
220
+ /**
221
+ * Gets up to `limit` amount of L2 block headers starting from `from`.
222
+ * @param start - Number of the first block to return (inclusive).
223
+ * @param limit - The number of blocks to return.
224
+ * @returns The requested L2 block headers.
225
+ */ getBlockHeaders(start, limit) {
226
+ return toArray(this.#blockStore.getBlockHeaders(start, limit));
227
+ }
228
+ /**
229
+ * Returns the block header for the given hash, or undefined if not exists.
230
+ * @param blockHash - The block hash to return.
231
+ */ getBlockHeaderByHash(blockHash) {
232
+ return this.#blockStore.getBlockHeaderByHash(L2BlockHash.fromField(blockHash));
233
+ }
234
+ /**
235
+ * Returns the block header for the given archive root, or undefined if not exists.
236
+ * @param archive - The archive root to return.
237
+ */ getBlockHeaderByArchive(archive) {
238
+ return this.#blockStore.getBlockHeaderByArchive(archive);
239
+ }
240
+ /**
241
+ * Gets a tx effect.
242
+ * @param txHash - The hash of the tx corresponding to the tx effect.
243
+ * @returns The requested tx effect with block info (or undefined if not found).
244
+ */ getTxEffect(txHash) {
245
+ return this.#blockStore.getTxEffect(txHash);
246
+ }
247
+ /**
248
+ * Gets a receipt of a settled tx.
249
+ * @param txHash - The hash of a tx we try to get the receipt for.
250
+ * @returns The requested tx receipt (or undefined if not found).
251
+ */ getSettledTxReceipt(txHash) {
252
+ return this.#blockStore.getSettledTxReceipt(txHash);
253
+ }
254
+ /**
255
+ * Append new logs to the store's list.
256
+ * @param blocks - The blocks for which to add the logs.
257
+ * @returns True if the operation is successful.
258
+ */ addLogs(blocks) {
259
+ return this.#logStore.addLogs(blocks);
260
+ }
261
+ deleteLogs(blocks) {
262
+ return this.#logStore.deleteLogs(blocks);
263
+ }
264
+ /**
265
+ * Get the total number of L1 to L2 messages
266
+ * @returns The number of L1 to L2 messages in the store
267
+ */ getTotalL1ToL2MessageCount() {
268
+ return this.#messageStore.getTotalL1ToL2MessageCount();
269
+ }
270
+ /** Returns the last L1 to L2 message stored. */ getLastL1ToL2Message() {
271
+ return this.#messageStore.getLastMessage();
272
+ }
273
+ /**
274
+ * Append L1 to L2 messages to the store.
275
+ * @param messages - The L1 to L2 messages to be added to the store.
276
+ * @returns True if the operation is successful.
277
+ */ addL1ToL2Messages(messages) {
278
+ return this.#messageStore.addL1ToL2Messages(messages);
279
+ }
280
+ /**
281
+ * Gets the L1 to L2 message index in the L1 to L2 message tree.
282
+ * @param l1ToL2Message - The L1 to L2 message.
283
+ * @returns The index of the L1 to L2 message in the L1 to L2 message tree (undefined if not found).
284
+ */ getL1ToL2MessageIndex(l1ToL2Message) {
285
+ return this.#messageStore.getL1ToL2MessageIndex(l1ToL2Message);
286
+ }
287
+ /**
288
+ * Gets L1 to L2 message (to be) included in a given checkpoint.
289
+ * @param checkpointNumber - Checkpoint number to get messages for.
290
+ * @returns The L1 to L2 messages/leaves of the messages subtree (throws if not found).
291
+ */ getL1ToL2Messages(checkpointNumber) {
292
+ return this.#messageStore.getL1ToL2Messages(checkpointNumber);
293
+ }
294
+ /**
295
+ * Gets all private logs that match any of the `tags`. For each tag, an array of matching logs is returned. An empty
296
+ * array implies no logs match that tag.
297
+ */ getPrivateLogsByTags(tags) {
298
+ try {
299
+ return this.#logStore.getPrivateLogsByTags(tags);
300
+ } catch (err) {
301
+ return Promise.reject(err);
302
+ }
303
+ }
304
+ /**
305
+ * Gets all public logs that match any of the `tags` from the specified contract. For each tag, an array of matching
306
+ * logs is returned. An empty array implies no logs match that tag.
307
+ */ getPublicLogsByTagsFromContract(contractAddress, tags) {
308
+ try {
309
+ return this.#logStore.getPublicLogsByTagsFromContract(contractAddress, tags);
310
+ } catch (err) {
311
+ return Promise.reject(err);
312
+ }
313
+ }
314
+ /**
315
+ * Gets public logs based on the provided filter.
316
+ * @param filter - The filter to apply to the logs.
317
+ * @returns The requested logs.
318
+ */ getPublicLogs(filter) {
319
+ try {
320
+ return this.#logStore.getPublicLogs(filter);
321
+ } catch (err) {
322
+ return Promise.reject(err);
323
+ }
324
+ }
325
+ /**
326
+ * Gets contract class logs based on the provided filter.
327
+ * @param filter - The filter to apply to the logs.
328
+ * @returns The requested logs.
329
+ */ getContractClassLogs(filter) {
330
+ try {
331
+ return this.#logStore.getContractClassLogs(filter);
332
+ } catch (err) {
333
+ return Promise.reject(err);
334
+ }
335
+ }
336
+ /**
337
+ * Gets the number of the latest proven checkpoint processed.
338
+ * @returns The number of the latest proven checkpoint processed.
339
+ */ getProvenCheckpointNumber() {
340
+ return this.#blockStore.getProvenCheckpointNumber();
341
+ }
342
+ /**
343
+ * Stores the number of the latest proven checkpoint processed.
344
+ * @param checkpointNumber - The number of the latest proven checkpoint processed.
345
+ */ async setProvenCheckpointNumber(checkpointNumber) {
346
+ await this.#blockStore.setProvenCheckpointNumber(checkpointNumber);
347
+ }
348
+ async setBlockSynchedL1BlockNumber(l1BlockNumber) {
349
+ await this.#blockStore.setSynchedL1BlockNumber(l1BlockNumber);
350
+ }
351
+ /**
352
+ * Stores the l1 block that messages have been synched until
353
+ */ async setMessageSynchedL1Block(l1Block) {
354
+ await this.#messageStore.setSynchedL1Block(l1Block);
355
+ }
356
+ /**
357
+ * Returns the number of the most recent proven block
358
+ * @returns The number of the most recent proven block
359
+ */ getProvenBlockNumber() {
360
+ return this.#blockStore.getProvenBlockNumber();
361
+ }
362
+ /**
363
+ * Gets the synch point of the archiver
364
+ */ async getSynchPoint() {
365
+ const [blocksSynchedTo, messagesSynchedTo] = await Promise.all([
366
+ this.#blockStore.getSynchedL1BlockNumber(),
367
+ this.#messageStore.getSynchedL1Block()
368
+ ]);
369
+ return {
370
+ blocksSynchedTo,
371
+ messagesSynchedTo
372
+ };
373
+ }
374
+ /** Estimates the size of the store in bytes. */ estimateSize() {
375
+ return this.db.estimateSize();
376
+ }
377
+ /** Deletes all L1 to L2 messages up until (excluding) the target checkpoint number. */ rollbackL1ToL2MessagesToCheckpoint(targetCheckpointNumber) {
378
+ return this.#messageStore.rollbackL1ToL2MessagesToCheckpoint(targetCheckpointNumber);
379
+ }
380
+ /** Returns an async iterator to all L1 to L2 messages on the range. */ iterateL1ToL2Messages(range = {}) {
381
+ return this.#messageStore.iterateL1ToL2Messages(range);
382
+ }
383
+ /** Removes all L1 to L2 messages starting from the given index (inclusive). */ removeL1ToL2Messages(startIndex) {
384
+ return this.#messageStore.removeL1ToL2Messages(startIndex);
385
+ }
386
+ /** Returns the last synced validation status of the pending chain. */ getPendingChainValidationStatus() {
387
+ return this.#blockStore.getPendingChainValidationStatus();
388
+ }
389
+ /** Sets the last synced validation status of the pending chain. */ setPendingChainValidationStatus(status) {
390
+ return this.#blockStore.setPendingChainValidationStatus(status);
391
+ }
392
+ /**
393
+ * Gets the number of the latest L2 block processed.
394
+ * @returns The number of the latest L2 block processed.
395
+ */ getCheckpointedL2BlockNumber() {
396
+ return this.#blockStore.getCheckpointedL2BlockNumber();
397
+ }
398
+ /**
399
+ * Gets the number of the latest published checkpoint processed.
400
+ * @returns The number of the latest published checkpoint processed
401
+ */ getSynchedCheckpointNumber() {
402
+ return this.#blockStore.getLatestCheckpointNumber();
403
+ }
404
+ /**
405
+ * Stores the l1 block number that checkpoints have been synched until
406
+ * @param l1BlockNumber - The l1 block number
407
+ */ async setCheckpointSynchedL1BlockNumber(l1BlockNumber) {
408
+ await this.#blockStore.setSynchedL1BlockNumber(l1BlockNumber);
409
+ }
410
+ /**
411
+ * Retrieves all blocks for the requested checkpoint
412
+ * @param checkpointNumber Retrieves all blocks for the given checkpoint
413
+ * @returns The collection of blocks for the requested checkpoint if available (undefined otherwise)
414
+ */ getBlocksForCheckpoint(checkpointNumber) {
415
+ return this.#blockStore.getBlocksForCheckpoint(checkpointNumber);
416
+ }
417
+ /**
418
+ * Returns checkpoint data for the requested checkpoint number
419
+ * @param checkpointNumber - The checkpoint requested
420
+ * @returns The checkpoint data or undefined if not found
421
+ */ getCheckpointData(checkpointNumber) {
422
+ return this.#blockStore.getCheckpointData(checkpointNumber);
423
+ }
424
+ /**
425
+ * Gets all blocks that have the given slot number.
426
+ * @param slotNumber - The slot number to search for.
427
+ * @returns All blocks with the given slot number.
428
+ */ getBlocksForSlot(slotNumber) {
429
+ return this.#blockStore.getBlocksForSlot(slotNumber);
430
+ }
431
+ /**
432
+ * Removes all blocks with block number > blockNumber.
433
+ * @param blockNumber - The block number to remove after.
434
+ * @returns The removed blocks (for event emission).
435
+ */ removeBlocksAfter(blockNumber) {
436
+ return this.#blockStore.unwindBlocksAfter(blockNumber);
437
+ }
438
+ }
@@ -0,0 +1,45 @@
1
+ import type { AztecAsyncKVStore } from '@aztec/kv-store';
2
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
3
+ import { L2BlockNew } 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: L2BlockNew[]): Promise<boolean>;
21
+ deleteLogs(blocks: L2BlockNew[]): Promise<boolean>;
22
+ /**
23
+ * Gets all 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
+ */
26
+ getPrivateLogsByTags(tags: SiloedTag[]): Promise<TxScopedL2Log[][]>;
27
+ /**
28
+ * Gets all public logs that match any of the `tags` from the specified contract. For each tag, an array of matching
29
+ * logs is returned. An empty array implies no logs match that tag.
30
+ */
31
+ getPublicLogsByTagsFromContract(contractAddress: AztecAddress, tags: Tag[]): Promise<TxScopedL2Log[][]>;
32
+ /**
33
+ * Gets public logs based on the provided filter.
34
+ * @param filter - The filter to apply to the logs.
35
+ * @returns The requested logs.
36
+ */
37
+ getPublicLogs(filter: LogFilter): Promise<GetPublicLogsResponse>;
38
+ /**
39
+ * Gets contract class logs based on the provided filter.
40
+ * @param filter - The filter to apply to the logs.
41
+ * @returns The requested logs.
42
+ */
43
+ getContractClassLogs(filter: LogFilter): Promise<GetContractClassLogsResponse>;
44
+ }
45
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibG9nX3N0b3JlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvc3RvcmUvbG9nX3N0b3JlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQU1BLE9BQU8sS0FBSyxFQUFFLGlCQUFpQixFQUFpQixNQUFNLGlCQUFpQixDQUFDO0FBQ3hFLE9BQU8sS0FBSyxFQUFFLFlBQVksRUFBRSxNQUFNLDZCQUE2QixDQUFDO0FBQ2hFLE9BQU8sRUFBZSxVQUFVLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQztBQUM5RCxPQUFPLEtBQUssRUFBRSw0QkFBNEIsRUFBRSxxQkFBcUIsRUFBRSxNQUFNLGlDQUFpQyxDQUFDO0FBQzNHLE9BQU8sRUFJTCxLQUFLLFNBQVMsRUFHZCxLQUFLLFNBQVMsRUFDZCxHQUFHLEVBQ0gsYUFBYSxFQUNkLE1BQU0sb0JBQW9CLENBQUM7QUFFNUIsT0FBTyxLQUFLLEVBQUUsVUFBVSxFQUFFLE1BQU0sa0JBQWtCLENBQUM7QUFFbkQ7O0dBRUc7QUFDSCxxQkFBYSxRQUFROztJQWFqQixPQUFPLENBQUMsRUFBRTtJQUNWLE9BQU8sQ0FBQyxVQUFVO0lBRnBCLFlBQ1UsRUFBRSxFQUFFLGlCQUFpQixFQUNyQixVQUFVLEVBQUUsVUFBVSxFQUM5QixlQUFlLEdBQUUsTUFBYSxFQVUvQjtJQTRNRDs7OztPQUlHO0lBQ0gsT0FBTyxDQUFDLE1BQU0sRUFBRSxVQUFVLEVBQUUsR0FBRyxPQUFPLENBQUMsT0FBTyxDQUFDLENBUzlDO0lBZ0JELFVBQVUsQ0FBQyxNQUFNLEVBQUUsVUFBVSxFQUFFLEdBQUcsT0FBTyxDQUFDLE9BQU8sQ0FBQyxDQTJCakQ7SUFFRDs7O09BR0c7SUFDRyxvQkFBb0IsQ0FBQyxJQUFJLEVBQUUsU0FBUyxFQUFFLEdBQUcsT0FBTyxDQUFDLGFBQWEsRUFBRSxFQUFFLENBQUMsQ0FJeEU7SUFFRDs7O09BR0c7SUFDRywrQkFBK0IsQ0FBQyxlQUFlLEVBQUUsWUFBWSxFQUFFLElBQUksRUFBRSxHQUFHLEVBQUUsR0FBRyxPQUFPLENBQUMsYUFBYSxFQUFFLEVBQUUsQ0FBQyxDQVE1RztJQUVEOzs7O09BSUc7SUFDSCxhQUFhLENBQUMsTUFBTSxFQUFFLFNBQVMsR0FBRyxPQUFPLENBQUMscUJBQXFCLENBQUMsQ0FRL0Q7SUE2RUQ7Ozs7T0FJRztJQUNILG9CQUFvQixDQUFDLE1BQU0sRUFBRSxTQUFTLEdBQUcsT0FBTyxDQUFDLDRCQUE0QixDQUFDLENBUTdFO0NBNkdGIn0=
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log_store.d.ts","sourceRoot":"","sources":["../../src/store/log_store.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,iBAAiB,EAAiB,MAAM,iBAAiB,CAAC;AACxE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAe,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,KAAK,EAAE,4BAA4B,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAC3G,OAAO,EAIL,KAAK,SAAS,EAGd,KAAK,SAAS,EACd,GAAG,EACH,aAAa,EACd,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD;;GAEG;AACH,qBAAa,QAAQ;;IAajB,OAAO,CAAC,EAAE;IACV,OAAO,CAAC,UAAU;IAFpB,YACU,EAAE,EAAE,iBAAiB,EACrB,UAAU,EAAE,UAAU,EAC9B,eAAe,GAAE,MAAa,EAU/B;IA4MD;;;;OAIG;IACH,OAAO,CAAC,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAS9C;IAgBD,UAAU,CAAC,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CA2BjD;IAED;;;OAGG;IACG,oBAAoB,CAAC,IAAI,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC,CAIxE;IAED;;;OAGG;IACG,+BAA+B,CAAC,eAAe,EAAE,YAAY,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC,CAQ5G;IAED;;;;OAIG;IACH,aAAa,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAQ/D;IA6ED;;;;OAIG;IACH,oBAAoB,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,4BAA4B,CAAC,CAQ7E;CA6GF"}