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

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 (236) hide show
  1. package/README.md +164 -22
  2. package/dest/archiver.d.ts +194 -0
  3. package/dest/archiver.d.ts.map +1 -0
  4. package/dest/archiver.js +949 -0
  5. package/dest/config.d.ts +34 -0
  6. package/dest/config.d.ts.map +1 -0
  7. package/dest/config.js +95 -0
  8. package/dest/errors.d.ts +87 -0
  9. package/dest/errors.d.ts.map +1 -0
  10. package/dest/errors.js +129 -0
  11. package/dest/factory.d.ts +16 -10
  12. package/dest/factory.d.ts.map +1 -1
  13. package/dest/factory.js +117 -20
  14. package/dest/index.d.ts +19 -4
  15. package/dest/index.d.ts.map +1 -1
  16. package/dest/index.js +17 -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 +152 -0
  23. package/dest/l1/calldata_retriever.d.ts +143 -0
  24. package/dest/l1/calldata_retriever.d.ts.map +1 -0
  25. package/dest/l1/calldata_retriever.js +413 -0
  26. package/dest/l1/data_retrieval.d.ts +102 -0
  27. package/dest/l1/data_retrieval.d.ts.map +1 -0
  28. package/dest/{archiver → l1}/data_retrieval.js +85 -165
  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 +149 -0
  35. package/dest/l1/trace_tx.d.ts +43 -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_historical_logs.d.ts +23 -0
  42. package/dest/l1/validate_historical_logs.d.ts.map +1 -0
  43. package/dest/l1/validate_historical_logs.js +108 -0
  44. package/dest/l1/validate_trace.d.ts +32 -0
  45. package/dest/l1/validate_trace.d.ts.map +1 -0
  46. package/dest/l1/validate_trace.js +154 -0
  47. package/dest/modules/contract_data_source_adapter.d.ts +25 -0
  48. package/dest/modules/contract_data_source_adapter.d.ts.map +1 -0
  49. package/dest/modules/contract_data_source_adapter.js +32 -0
  50. package/dest/modules/data_source_base.d.ts +112 -0
  51. package/dest/modules/data_source_base.d.ts.map +1 -0
  52. package/dest/modules/data_source_base.js +322 -0
  53. package/dest/modules/data_store_updater.d.ts +105 -0
  54. package/dest/modules/data_store_updater.d.ts.map +1 -0
  55. package/dest/modules/data_store_updater.js +393 -0
  56. package/dest/modules/instrumentation.d.ts +63 -0
  57. package/dest/modules/instrumentation.d.ts.map +1 -0
  58. package/dest/modules/instrumentation.js +166 -0
  59. package/dest/modules/l1_synchronizer.d.ts +77 -0
  60. package/dest/modules/l1_synchronizer.d.ts.map +1 -0
  61. package/dest/modules/l1_synchronizer.js +1381 -0
  62. package/dest/modules/outbox_trees_resolver.d.ts +62 -0
  63. package/dest/modules/outbox_trees_resolver.d.ts.map +1 -0
  64. package/dest/modules/outbox_trees_resolver.js +162 -0
  65. package/dest/modules/validation.d.ts +40 -0
  66. package/dest/modules/validation.d.ts.map +1 -0
  67. package/dest/{archiver → modules}/validation.js +41 -17
  68. package/dest/store/block_store.d.ts +303 -0
  69. package/dest/store/block_store.d.ts.map +1 -0
  70. package/dest/store/block_store.js +1206 -0
  71. package/dest/store/contract_class_store.d.ts +31 -0
  72. package/dest/store/contract_class_store.d.ts.map +1 -0
  73. package/dest/store/contract_class_store.js +98 -0
  74. package/dest/store/contract_instance_store.d.ts +51 -0
  75. package/dest/store/contract_instance_store.d.ts.map +1 -0
  76. package/dest/{archiver/kv_archiver_store → store}/contract_instance_store.js +55 -3
  77. package/dest/store/data_stores.d.ts +68 -0
  78. package/dest/store/data_stores.d.ts.map +1 -0
  79. package/dest/store/data_stores.js +54 -0
  80. package/dest/store/function_names_cache.d.ts +17 -0
  81. package/dest/store/function_names_cache.d.ts.map +1 -0
  82. package/dest/store/function_names_cache.js +30 -0
  83. package/dest/store/l2_tips_cache.d.ts +25 -0
  84. package/dest/store/l2_tips_cache.d.ts.map +1 -0
  85. package/dest/store/l2_tips_cache.js +26 -0
  86. package/dest/store/log_store.d.ts +59 -0
  87. package/dest/store/log_store.d.ts.map +1 -0
  88. package/dest/store/log_store.js +310 -0
  89. package/dest/store/log_store_codec.d.ts +78 -0
  90. package/dest/store/log_store_codec.d.ts.map +1 -0
  91. package/dest/store/log_store_codec.js +110 -0
  92. package/dest/store/message_store.d.ts +50 -0
  93. package/dest/store/message_store.d.ts.map +1 -0
  94. package/dest/{archiver/kv_archiver_store → store}/message_store.js +66 -23
  95. package/dest/{archiver/structs → structs}/data_retrieval.d.ts +1 -1
  96. package/dest/structs/data_retrieval.d.ts.map +1 -0
  97. package/dest/structs/inbox_message.d.ts +15 -0
  98. package/dest/structs/inbox_message.d.ts.map +1 -0
  99. package/dest/{archiver/structs → structs}/inbox_message.js +6 -6
  100. package/dest/structs/published.d.ts +2 -0
  101. package/dest/structs/published.d.ts.map +1 -0
  102. package/dest/test/fake_l1_state.d.ts +214 -0
  103. package/dest/test/fake_l1_state.d.ts.map +1 -0
  104. package/dest/test/fake_l1_state.js +517 -0
  105. package/dest/test/index.d.ts +2 -1
  106. package/dest/test/index.d.ts.map +1 -1
  107. package/dest/test/index.js +4 -1
  108. package/dest/test/mock_archiver.d.ts +5 -6
  109. package/dest/test/mock_archiver.d.ts.map +1 -1
  110. package/dest/test/mock_archiver.js +8 -12
  111. package/dest/test/mock_l1_to_l2_message_source.d.ts +6 -7
  112. package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
  113. package/dest/test/mock_l1_to_l2_message_source.js +19 -14
  114. package/dest/test/mock_l2_block_source.d.ts +68 -40
  115. package/dest/test/mock_l2_block_source.d.ts.map +1 -1
  116. package/dest/test/mock_l2_block_source.js +347 -145
  117. package/dest/test/mock_structs.d.ts +83 -4
  118. package/dest/test/mock_structs.d.ts.map +1 -1
  119. package/dest/test/mock_structs.js +157 -12
  120. package/dest/test/noop_l1_archiver.d.ts +34 -0
  121. package/dest/test/noop_l1_archiver.d.ts.map +1 -0
  122. package/dest/test/noop_l1_archiver.js +88 -0
  123. package/package.json +18 -18
  124. package/src/archiver.ts +785 -0
  125. package/src/config.ts +125 -0
  126. package/src/errors.ts +203 -0
  127. package/src/factory.ts +185 -22
  128. package/src/index.ts +27 -3
  129. package/src/interfaces.ts +9 -0
  130. package/src/l1/README.md +55 -0
  131. package/src/l1/bin/retrieve-calldata.ts +194 -0
  132. package/src/l1/calldata_retriever.ts +529 -0
  133. package/src/{archiver → l1}/data_retrieval.ts +157 -243
  134. package/src/l1/debug_tx.ts +99 -0
  135. package/src/l1/spire_proposer.ts +152 -0
  136. package/src/l1/trace_tx.ts +128 -0
  137. package/src/l1/types.ts +13 -0
  138. package/src/l1/validate_historical_logs.ts +140 -0
  139. package/src/l1/validate_trace.ts +229 -0
  140. package/src/modules/contract_data_source_adapter.ts +46 -0
  141. package/src/modules/data_source_base.ts +466 -0
  142. package/src/modules/data_store_updater.ts +519 -0
  143. package/src/modules/instrumentation.ts +217 -0
  144. package/src/modules/l1_synchronizer.ts +1320 -0
  145. package/src/modules/outbox_trees_resolver.ts +199 -0
  146. package/src/modules/validation.ts +186 -0
  147. package/src/store/block_store.ts +1551 -0
  148. package/src/store/contract_class_store.ts +126 -0
  149. package/src/{archiver/kv_archiver_store → store}/contract_instance_store.ts +70 -7
  150. package/src/store/data_stores.ts +104 -0
  151. package/src/store/function_names_cache.ts +37 -0
  152. package/src/store/l2_tips_cache.ts +35 -0
  153. package/src/store/log_store.ts +380 -0
  154. package/src/store/log_store_codec.ts +143 -0
  155. package/src/{archiver/kv_archiver_store → store}/message_store.ts +81 -28
  156. package/src/{archiver/structs → structs}/inbox_message.ts +8 -9
  157. package/src/{archiver/structs → structs}/published.ts +0 -1
  158. package/src/test/fake_l1_state.ts +770 -0
  159. package/src/test/fixtures/debug_traceTransaction-multicall3.json +88 -0
  160. package/src/test/fixtures/debug_traceTransaction-multiplePropose.json +153 -0
  161. package/src/test/fixtures/debug_traceTransaction-proxied.json +122 -0
  162. package/src/test/fixtures/trace_transaction-multicall3.json +65 -0
  163. package/src/test/fixtures/trace_transaction-multiplePropose.json +319 -0
  164. package/src/test/fixtures/trace_transaction-proxied.json +128 -0
  165. package/src/test/fixtures/trace_transaction-randomRevert.json +216 -0
  166. package/src/test/index.ts +4 -0
  167. package/src/test/mock_archiver.ts +10 -14
  168. package/src/test/mock_l1_to_l2_message_source.ts +16 -15
  169. package/src/test/mock_l2_block_source.ts +416 -161
  170. package/src/test/mock_structs.ts +292 -14
  171. package/src/test/noop_l1_archiver.ts +158 -0
  172. package/dest/archiver/archiver.d.ts +0 -290
  173. package/dest/archiver/archiver.d.ts.map +0 -1
  174. package/dest/archiver/archiver.js +0 -1434
  175. package/dest/archiver/archiver_store.d.ts +0 -256
  176. package/dest/archiver/archiver_store.d.ts.map +0 -1
  177. package/dest/archiver/archiver_store.js +0 -4
  178. package/dest/archiver/archiver_store_test_suite.d.ts +0 -8
  179. package/dest/archiver/archiver_store_test_suite.d.ts.map +0 -1
  180. package/dest/archiver/archiver_store_test_suite.js +0 -1289
  181. package/dest/archiver/config.d.ts +0 -21
  182. package/dest/archiver/config.d.ts.map +0 -1
  183. package/dest/archiver/config.js +0 -55
  184. package/dest/archiver/data_retrieval.d.ts +0 -80
  185. package/dest/archiver/data_retrieval.d.ts.map +0 -1
  186. package/dest/archiver/errors.d.ts +0 -12
  187. package/dest/archiver/errors.d.ts.map +0 -1
  188. package/dest/archiver/errors.js +0 -17
  189. package/dest/archiver/index.d.ts +0 -7
  190. package/dest/archiver/index.d.ts.map +0 -1
  191. package/dest/archiver/index.js +0 -4
  192. package/dest/archiver/instrumentation.d.ts +0 -35
  193. package/dest/archiver/instrumentation.d.ts.map +0 -1
  194. package/dest/archiver/instrumentation.js +0 -140
  195. package/dest/archiver/kv_archiver_store/block_store.d.ts +0 -125
  196. package/dest/archiver/kv_archiver_store/block_store.d.ts.map +0 -1
  197. package/dest/archiver/kv_archiver_store/block_store.js +0 -371
  198. package/dest/archiver/kv_archiver_store/contract_class_store.d.ts +0 -18
  199. package/dest/archiver/kv_archiver_store/contract_class_store.d.ts.map +0 -1
  200. package/dest/archiver/kv_archiver_store/contract_class_store.js +0 -120
  201. package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts +0 -24
  202. package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts.map +0 -1
  203. package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts +0 -169
  204. package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts.map +0 -1
  205. package/dest/archiver/kv_archiver_store/kv_archiver_store.js +0 -296
  206. package/dest/archiver/kv_archiver_store/log_store.d.ts +0 -49
  207. package/dest/archiver/kv_archiver_store/log_store.d.ts.map +0 -1
  208. package/dest/archiver/kv_archiver_store/log_store.js +0 -337
  209. package/dest/archiver/kv_archiver_store/message_store.d.ts +0 -39
  210. package/dest/archiver/kv_archiver_store/message_store.d.ts.map +0 -1
  211. package/dest/archiver/structs/data_retrieval.d.ts.map +0 -1
  212. package/dest/archiver/structs/inbox_message.d.ts +0 -15
  213. package/dest/archiver/structs/inbox_message.d.ts.map +0 -1
  214. package/dest/archiver/structs/published.d.ts +0 -3
  215. package/dest/archiver/structs/published.d.ts.map +0 -1
  216. package/dest/archiver/validation.d.ts +0 -17
  217. package/dest/archiver/validation.d.ts.map +0 -1
  218. package/dest/rpc/index.d.ts +0 -9
  219. package/dest/rpc/index.d.ts.map +0 -1
  220. package/dest/rpc/index.js +0 -15
  221. package/src/archiver/archiver.ts +0 -1880
  222. package/src/archiver/archiver_store.ts +0 -310
  223. package/src/archiver/archiver_store_test_suite.ts +0 -1295
  224. package/src/archiver/config.ts +0 -79
  225. package/src/archiver/errors.ts +0 -26
  226. package/src/archiver/index.ts +0 -6
  227. package/src/archiver/instrumentation.ts +0 -187
  228. package/src/archiver/kv_archiver_store/block_store.ts +0 -482
  229. package/src/archiver/kv_archiver_store/contract_class_store.ts +0 -176
  230. package/src/archiver/kv_archiver_store/kv_archiver_store.ts +0 -423
  231. package/src/archiver/kv_archiver_store/log_store.ts +0 -407
  232. package/src/archiver/validation.ts +0 -124
  233. package/src/rpc/index.ts +0 -16
  234. /package/dest/{archiver/structs → structs}/data_retrieval.js +0 -0
  235. /package/dest/{archiver/structs → structs}/published.js +0 -0
  236. /package/src/{archiver/structs → structs}/data_retrieval.ts +0 -0
@@ -1,407 +0,0 @@
1
- import { INITIAL_L2_BLOCK_NUM, MAX_NOTE_HASHES_PER_TX } from '@aztec/constants';
2
- import { BlockNumber } from '@aztec/foundation/branded-types';
3
- import type { Fr } from '@aztec/foundation/fields';
4
- import { createLogger } from '@aztec/foundation/log';
5
- import { BufferReader, numToUInt32BE } from '@aztec/foundation/serialize';
6
- import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
7
- import type { L2Block } from '@aztec/stdlib/block';
8
- import type { GetContractClassLogsResponse, GetPublicLogsResponse } from '@aztec/stdlib/interfaces/client';
9
- import {
10
- ContractClassLog,
11
- ExtendedContractClassLog,
12
- ExtendedPublicLog,
13
- type LogFilter,
14
- LogId,
15
- PrivateLog,
16
- PublicLog,
17
- TxScopedL2Log,
18
- } from '@aztec/stdlib/logs';
19
-
20
- import type { BlockStore } from './block_store.js';
21
-
22
- /**
23
- * A store for logs
24
- */
25
- export class LogStore {
26
- #logsByTag: AztecAsyncMap<string, Buffer[]>;
27
- #logTagsByBlock: AztecAsyncMap<number, string[]>;
28
- #privateLogsByBlock: AztecAsyncMap<number, Buffer>;
29
- #publicLogsByBlock: AztecAsyncMap<number, Buffer>;
30
- #contractClassLogsByBlock: AztecAsyncMap<number, Buffer>;
31
- #logsMaxPageSize: number;
32
- #log = createLogger('archiver:log_store');
33
-
34
- constructor(
35
- private db: AztecAsyncKVStore,
36
- private blockStore: BlockStore,
37
- logsMaxPageSize: number = 1000,
38
- ) {
39
- this.#logsByTag = db.openMap('archiver_tagged_logs_by_tag');
40
- this.#logTagsByBlock = db.openMap('archiver_log_tags_by_block');
41
- this.#privateLogsByBlock = db.openMap('archiver_private_logs_by_block');
42
- this.#publicLogsByBlock = db.openMap('archiver_public_logs_by_block');
43
- this.#contractClassLogsByBlock = db.openMap('archiver_contract_class_logs_by_block');
44
-
45
- this.#logsMaxPageSize = logsMaxPageSize;
46
- }
47
-
48
- #extractTaggedLogs(block: L2Block) {
49
- const taggedLogs = new Map<string, Buffer[]>();
50
- const dataStartIndexForBlock =
51
- block.header.state.partial.noteHashTree.nextAvailableLeafIndex -
52
- block.body.txEffects.length * MAX_NOTE_HASHES_PER_TX;
53
- block.body.txEffects.forEach((txEffect, txIndex) => {
54
- const txHash = txEffect.txHash;
55
- const dataStartIndexForTx = dataStartIndexForBlock + txIndex * MAX_NOTE_HASHES_PER_TX;
56
-
57
- txEffect.privateLogs.forEach((log, logIndex) => {
58
- const tag = log.fields[0];
59
- this.#log.debug(`Found private log with tag ${tag.toString()} in block ${block.number}`);
60
-
61
- const currentLogs = taggedLogs.get(tag.toString()) ?? [];
62
- currentLogs.push(new TxScopedL2Log(txHash, dataStartIndexForTx, logIndex, block.number, log).toBuffer());
63
- taggedLogs.set(tag.toString(), currentLogs);
64
- });
65
-
66
- txEffect.publicLogs.forEach((log, logIndex) => {
67
- const tag = log.fields[0];
68
- this.#log.debug(`Found public log with tag ${tag.toString()} in block ${block.number}`);
69
-
70
- const currentLogs = taggedLogs.get(tag.toString()) ?? [];
71
- currentLogs.push(new TxScopedL2Log(txHash, dataStartIndexForTx, logIndex, block.number, log).toBuffer());
72
- taggedLogs.set(tag.toString(), currentLogs);
73
- });
74
- });
75
- return taggedLogs;
76
- }
77
-
78
- /**
79
- * Append new logs to the store's list.
80
- * @param blocks - The blocks for which to add the logs.
81
- * @returns True if the operation is successful.
82
- */
83
- addLogs(blocks: L2Block[]): Promise<boolean> {
84
- const taggedLogsToAdd = blocks
85
- .map(block => this.#extractTaggedLogs(block))
86
- .reduce((acc, val) => {
87
- for (const [tag, logs] of val.entries()) {
88
- const currentLogs = acc.get(tag) ?? [];
89
- acc.set(tag, currentLogs.concat(logs));
90
- }
91
- return acc;
92
- }, new Map());
93
- const tagsToUpdate = Array.from(taggedLogsToAdd.keys());
94
-
95
- return this.db.transactionAsync(async () => {
96
- const currentTaggedLogs = await Promise.all(
97
- tagsToUpdate.map(async tag => ({ tag, logBuffers: await this.#logsByTag.getAsync(tag) })),
98
- );
99
- currentTaggedLogs.forEach(taggedLogBuffer => {
100
- if (taggedLogBuffer.logBuffers && taggedLogBuffer.logBuffers.length > 0) {
101
- taggedLogsToAdd.set(
102
- taggedLogBuffer.tag,
103
- taggedLogBuffer.logBuffers!.concat(taggedLogsToAdd.get(taggedLogBuffer.tag)!),
104
- );
105
- }
106
- });
107
- for (const block of blocks) {
108
- const tagsInBlock = [];
109
- for (const [tag, logs] of taggedLogsToAdd.entries()) {
110
- await this.#logsByTag.set(tag, logs);
111
- tagsInBlock.push(tag);
112
- }
113
- await this.#logTagsByBlock.set(block.number, tagsInBlock);
114
-
115
- const privateLogsInBlock = block.body.txEffects
116
- .map(txEffect => txEffect.privateLogs)
117
- .flat()
118
- .map(log => log.toBuffer());
119
- await this.#privateLogsByBlock.set(block.number, Buffer.concat(privateLogsInBlock));
120
-
121
- const publicLogsInBlock = block.body.txEffects
122
- .map((txEffect, txIndex) =>
123
- [
124
- numToUInt32BE(txIndex),
125
- numToUInt32BE(txEffect.publicLogs.length),
126
- txEffect.publicLogs.map(log => log.toBuffer()),
127
- ].flat(),
128
- )
129
- .flat();
130
-
131
- const contractClassLogsInBlock = block.body.txEffects
132
- .map((txEffect, txIndex) =>
133
- [
134
- numToUInt32BE(txIndex),
135
- numToUInt32BE(txEffect.contractClassLogs.length),
136
- txEffect.contractClassLogs.map(log => log.toBuffer()),
137
- ].flat(),
138
- )
139
- .flat();
140
-
141
- await this.#publicLogsByBlock.set(block.number, Buffer.concat(publicLogsInBlock));
142
- await this.#contractClassLogsByBlock.set(block.number, Buffer.concat(contractClassLogsInBlock));
143
- }
144
-
145
- return true;
146
- });
147
- }
148
-
149
- deleteLogs(blocks: L2Block[]): Promise<boolean> {
150
- return this.db.transactionAsync(async () => {
151
- const tagsToDelete = (
152
- await Promise.all(
153
- blocks.map(async block => {
154
- const tags = await this.#logTagsByBlock.getAsync(block.number);
155
- return tags ?? [];
156
- }),
157
- )
158
- ).flat();
159
-
160
- await Promise.all(
161
- blocks.map(block =>
162
- Promise.all([
163
- this.#privateLogsByBlock.delete(block.number),
164
- this.#publicLogsByBlock.delete(block.number),
165
- this.#logTagsByBlock.delete(block.number),
166
- this.#contractClassLogsByBlock.delete(block.number),
167
- ]),
168
- ),
169
- );
170
-
171
- await Promise.all(tagsToDelete.map(tag => this.#logsByTag.delete(tag.toString())));
172
- return true;
173
- });
174
- }
175
-
176
- /**
177
- * Retrieves all private logs from up to `limit` blocks, starting from the block number `start`.
178
- * @param start - The block number from which to begin retrieving logs.
179
- * @param limit - The maximum number of blocks to retrieve logs from.
180
- * @returns An array of private logs from the specified range of blocks.
181
- */
182
- async getPrivateLogs(start: number, limit: number): Promise<PrivateLog[]> {
183
- const logs = [];
184
- for await (const buffer of this.#privateLogsByBlock.valuesAsync({ start, limit })) {
185
- const reader = new BufferReader(buffer);
186
- while (reader.remainingBytes() > 0) {
187
- logs.push(reader.readObject(PrivateLog));
188
- }
189
- }
190
- return logs;
191
- }
192
-
193
- /**
194
- * Gets all logs that match any of the received tags (i.e. logs with their first field equal to a tag).
195
- * @param tags - The tags to filter the logs by.
196
- * @returns For each received tag, an array of matching logs is returned. An empty array implies no logs match
197
- * that tag.
198
- */
199
- async getLogsByTags(tags: Fr[], limitPerTag?: number): Promise<TxScopedL2Log[][]> {
200
- if (limitPerTag !== undefined && limitPerTag <= 0) {
201
- throw new TypeError('limitPerTag needs to be greater than 0');
202
- }
203
- const logs = await Promise.all(tags.map(tag => this.#logsByTag.getAsync(tag.toString())));
204
- return logs.map(
205
- logBuffers => logBuffers?.slice(0, limitPerTag).map(logBuffer => TxScopedL2Log.fromBuffer(logBuffer)) ?? [],
206
- );
207
- }
208
-
209
- /**
210
- * Gets public logs based on the provided filter.
211
- * @param filter - The filter to apply to the logs.
212
- * @returns The requested logs.
213
- */
214
- getPublicLogs(filter: LogFilter): Promise<GetPublicLogsResponse> {
215
- if (filter.afterLog) {
216
- return this.#filterPublicLogsBetweenBlocks(filter);
217
- } else if (filter.txHash) {
218
- return this.#filterPublicLogsOfTx(filter);
219
- } else {
220
- return this.#filterPublicLogsBetweenBlocks(filter);
221
- }
222
- }
223
-
224
- async #filterPublicLogsOfTx(filter: LogFilter): Promise<GetPublicLogsResponse> {
225
- if (!filter.txHash) {
226
- throw new Error('Missing txHash');
227
- }
228
-
229
- const [blockNumber, txIndex] = (await this.blockStore.getTxLocation(filter.txHash)) ?? [];
230
- if (typeof blockNumber !== 'number' || typeof txIndex !== 'number') {
231
- return { logs: [], maxLogsHit: false };
232
- }
233
-
234
- const buffer = (await this.#publicLogsByBlock.getAsync(blockNumber)) ?? Buffer.alloc(0);
235
- const publicLogsInBlock: [PublicLog[]] = [[]];
236
- const reader = new BufferReader(buffer);
237
- while (reader.remainingBytes() > 0) {
238
- const indexOfTx = reader.readNumber();
239
- const numLogsInTx = reader.readNumber();
240
- publicLogsInBlock[indexOfTx] = [];
241
- for (let i = 0; i < numLogsInTx; i++) {
242
- publicLogsInBlock[indexOfTx].push(reader.readObject(PublicLog));
243
- }
244
- }
245
-
246
- const txLogs = publicLogsInBlock[txIndex];
247
-
248
- const logs: ExtendedPublicLog[] = [];
249
- const maxLogsHit = this.#accumulateLogs(logs, blockNumber, txIndex, txLogs, filter);
250
-
251
- return { logs, maxLogsHit };
252
- }
253
-
254
- async #filterPublicLogsBetweenBlocks(filter: LogFilter): Promise<GetPublicLogsResponse> {
255
- const start =
256
- filter.afterLog?.blockNumber ?? Math.max(filter.fromBlock ?? INITIAL_L2_BLOCK_NUM, INITIAL_L2_BLOCK_NUM);
257
- const end = filter.toBlock;
258
-
259
- if (typeof end === 'number' && end < start) {
260
- return {
261
- logs: [],
262
- maxLogsHit: true,
263
- };
264
- }
265
-
266
- const logs: ExtendedPublicLog[] = [];
267
-
268
- let maxLogsHit = false;
269
- loopOverBlocks: for await (const [blockNumber, logBuffer] of this.#publicLogsByBlock.entriesAsync({ start, end })) {
270
- const publicLogsInBlock: [PublicLog[]] = [[]];
271
- const reader = new BufferReader(logBuffer);
272
- while (reader.remainingBytes() > 0) {
273
- const indexOfTx = reader.readNumber();
274
- const numLogsInTx = reader.readNumber();
275
- publicLogsInBlock[indexOfTx] = [];
276
- for (let i = 0; i < numLogsInTx; i++) {
277
- publicLogsInBlock[indexOfTx].push(reader.readObject(PublicLog));
278
- }
279
- }
280
- for (let txIndex = filter.afterLog?.txIndex ?? 0; txIndex < publicLogsInBlock.length; txIndex++) {
281
- const txLogs = publicLogsInBlock[txIndex];
282
- maxLogsHit = this.#accumulateLogs(logs, blockNumber, txIndex, txLogs, filter);
283
- if (maxLogsHit) {
284
- this.#log.debug(`Max logs hit at block ${blockNumber}`);
285
- break loopOverBlocks;
286
- }
287
- }
288
- }
289
-
290
- return { logs, maxLogsHit };
291
- }
292
-
293
- /**
294
- * Gets contract class logs based on the provided filter.
295
- * @param filter - The filter to apply to the logs.
296
- * @returns The requested logs.
297
- */
298
- getContractClassLogs(filter: LogFilter): Promise<GetContractClassLogsResponse> {
299
- if (filter.afterLog) {
300
- return this.#filterContractClassLogsBetweenBlocks(filter);
301
- } else if (filter.txHash) {
302
- return this.#filterContractClassLogsOfTx(filter);
303
- } else {
304
- return this.#filterContractClassLogsBetweenBlocks(filter);
305
- }
306
- }
307
-
308
- async #filterContractClassLogsOfTx(filter: LogFilter): Promise<GetContractClassLogsResponse> {
309
- if (!filter.txHash) {
310
- throw new Error('Missing txHash');
311
- }
312
-
313
- const [blockNumber, txIndex] = (await this.blockStore.getTxLocation(filter.txHash)) ?? [];
314
- if (typeof blockNumber !== 'number' || typeof txIndex !== 'number') {
315
- return { logs: [], maxLogsHit: false };
316
- }
317
- const contractClassLogsBuffer = (await this.#contractClassLogsByBlock.getAsync(blockNumber)) ?? Buffer.alloc(0);
318
- const contractClassLogsInBlock: [ContractClassLog[]] = [[]];
319
-
320
- const reader = new BufferReader(contractClassLogsBuffer);
321
- while (reader.remainingBytes() > 0) {
322
- const indexOfTx = reader.readNumber();
323
- const numLogsInTx = reader.readNumber();
324
- contractClassLogsInBlock[indexOfTx] = [];
325
- for (let i = 0; i < numLogsInTx; i++) {
326
- contractClassLogsInBlock[indexOfTx].push(reader.readObject(ContractClassLog));
327
- }
328
- }
329
-
330
- const txLogs = contractClassLogsInBlock[txIndex];
331
-
332
- const logs: ExtendedContractClassLog[] = [];
333
- const maxLogsHit = this.#accumulateLogs(logs, blockNumber, txIndex, txLogs, filter);
334
-
335
- return { logs, maxLogsHit };
336
- }
337
-
338
- async #filterContractClassLogsBetweenBlocks(filter: LogFilter): Promise<GetContractClassLogsResponse> {
339
- const start =
340
- filter.afterLog?.blockNumber ?? Math.max(filter.fromBlock ?? INITIAL_L2_BLOCK_NUM, INITIAL_L2_BLOCK_NUM);
341
- const end = filter.toBlock;
342
-
343
- if (typeof end === 'number' && end < start) {
344
- return {
345
- logs: [],
346
- maxLogsHit: true,
347
- };
348
- }
349
-
350
- const logs: ExtendedContractClassLog[] = [];
351
-
352
- let maxLogsHit = false;
353
- loopOverBlocks: for await (const [blockNumber, logBuffer] of this.#contractClassLogsByBlock.entriesAsync({
354
- start,
355
- end,
356
- })) {
357
- const contractClassLogsInBlock: [ContractClassLog[]] = [[]];
358
- const reader = new BufferReader(logBuffer);
359
- while (reader.remainingBytes() > 0) {
360
- const indexOfTx = reader.readNumber();
361
- const numLogsInTx = reader.readNumber();
362
- contractClassLogsInBlock[indexOfTx] = [];
363
- for (let i = 0; i < numLogsInTx; i++) {
364
- contractClassLogsInBlock[indexOfTx].push(reader.readObject(ContractClassLog));
365
- }
366
- }
367
- for (let txIndex = filter.afterLog?.txIndex ?? 0; txIndex < contractClassLogsInBlock.length; txIndex++) {
368
- const txLogs = contractClassLogsInBlock[txIndex];
369
- maxLogsHit = this.#accumulateLogs(logs, blockNumber, txIndex, txLogs, filter);
370
- if (maxLogsHit) {
371
- this.#log.debug(`Max logs hit at block ${blockNumber}`);
372
- break loopOverBlocks;
373
- }
374
- }
375
- }
376
-
377
- return { logs, maxLogsHit };
378
- }
379
-
380
- #accumulateLogs(
381
- results: (ExtendedContractClassLog | ExtendedPublicLog)[],
382
- blockNumber: number,
383
- txIndex: number,
384
- txLogs: (ContractClassLog | PublicLog)[],
385
- filter: LogFilter,
386
- ): boolean {
387
- let maxLogsHit = false;
388
- let logIndex = typeof filter.afterLog?.logIndex === 'number' ? filter.afterLog.logIndex + 1 : 0;
389
- for (; logIndex < txLogs.length; logIndex++) {
390
- const log = txLogs[logIndex];
391
- if (!filter.contractAddress || log.contractAddress.equals(filter.contractAddress)) {
392
- if (log instanceof ContractClassLog) {
393
- results.push(new ExtendedContractClassLog(new LogId(BlockNumber(blockNumber), txIndex, logIndex), log));
394
- } else {
395
- results.push(new ExtendedPublicLog(new LogId(BlockNumber(blockNumber), txIndex, logIndex), log));
396
- }
397
-
398
- if (results.length >= this.#logsMaxPageSize) {
399
- maxLogsHit = true;
400
- break;
401
- }
402
- }
403
- }
404
-
405
- return maxLogsHit;
406
- }
407
- }
@@ -1,124 +0,0 @@
1
- import type { EpochCache } from '@aztec/epoch-cache';
2
- import { EpochNumber } from '@aztec/foundation/branded-types';
3
- import { compactArray } from '@aztec/foundation/collection';
4
- import type { Logger } from '@aztec/foundation/log';
5
- import {
6
- type AttestationInfo,
7
- type ValidateBlockNegativeResult,
8
- type ValidateBlockResult,
9
- getAttestationInfoFromPayload,
10
- } from '@aztec/stdlib/block';
11
- import type { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
12
- import { type L1RollupConstants, getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
13
- import { ConsensusPayload } from '@aztec/stdlib/p2p';
14
-
15
- export type { ValidateBlockResult };
16
-
17
- /**
18
- * Extracts attestation information from a published checkpoint.
19
- * Returns info for each attestation, preserving array indices.
20
- */
21
- export function getAttestationInfoFromPublishedCheckpoint({
22
- checkpoint,
23
- attestations,
24
- }: PublishedCheckpoint): AttestationInfo[] {
25
- const payload = ConsensusPayload.fromCheckpoint(checkpoint);
26
- return getAttestationInfoFromPayload(payload, attestations);
27
- }
28
-
29
- /**
30
- * Validates the attestations submitted for the given checkpoint.
31
- * Returns true if the attestations are valid and sufficient, false otherwise.
32
- */
33
- export async function validateCheckpointAttestations(
34
- publishedCheckpoint: PublishedCheckpoint,
35
- epochCache: EpochCache,
36
- constants: Pick<L1RollupConstants, 'epochDuration'>,
37
- logger?: Logger,
38
- ): Promise<ValidateBlockResult> {
39
- const attestorInfos = getAttestationInfoFromPublishedCheckpoint(publishedCheckpoint);
40
- const attestors = compactArray(attestorInfos.map(info => ('address' in info ? info.address : undefined)));
41
- const { checkpoint, attestations } = publishedCheckpoint;
42
- const headerHash = checkpoint.header.hash();
43
- const archiveRoot = checkpoint.archive.root.toString();
44
- const slot = checkpoint.header.slotNumber;
45
- const epoch: EpochNumber = getEpochAtSlot(slot, constants);
46
- const { committee, seed } = await epochCache.getCommitteeForEpoch(epoch);
47
- const logData = { checkpointNumber: checkpoint.number, slot, epoch, headerHash, archiveRoot };
48
-
49
- logger?.debug(`Validating attestations for checkpoint ${checkpoint.number} at slot ${slot} in epoch ${epoch}`, {
50
- committee: (committee ?? []).map(member => member.toString()),
51
- recoveredAttestors: attestorInfos,
52
- postedAttestations: attestations.map(a => (a.address.isZero() ? a.signature : a.address).toString()),
53
- ...logData,
54
- });
55
-
56
- if (!committee || committee.length === 0) {
57
- logger?.warn(
58
- `No committee found for epoch ${epoch} at slot ${slot}. Accepting checkpoint without validation.`,
59
- logData,
60
- );
61
- return { valid: true };
62
- }
63
-
64
- const requiredAttestationCount = Math.floor((committee.length * 2) / 3) + 1;
65
-
66
- const failedValidationResult = <TReason extends ValidateBlockNegativeResult['reason']>(reason: TReason) => ({
67
- valid: false as const,
68
- reason,
69
- block: checkpoint.blocks[0].toBlockInfo(),
70
- committee,
71
- seed,
72
- epoch,
73
- attestors,
74
- attestations,
75
- });
76
-
77
- for (let i = 0; i < attestorInfos.length; i++) {
78
- const info = attestorInfos[i];
79
-
80
- // Fail on invalid signatures (no address recovered)
81
- if (info.status === 'invalid-signature' || info.status === 'empty') {
82
- logger?.warn(`Attestation with empty or invalid signature at slot ${slot}`, {
83
- committee,
84
- invalidIndex: i,
85
- ...logData,
86
- });
87
- return { ...failedValidationResult('invalid-attestation'), invalidIndex: i };
88
- }
89
-
90
- // Check if the attestor at this index matches the committee member at the same index
91
- if (info.status === 'recovered-from-signature' || info.status === 'provided-as-address') {
92
- const signer = info.address.toString();
93
- const expectedCommitteeMember = committee[i]?.toString();
94
-
95
- if (!expectedCommitteeMember || signer !== expectedCommitteeMember) {
96
- logger?.warn(
97
- `Attestation at index ${i} from ${signer} does not match expected committee member ${expectedCommitteeMember} at slot ${slot}`,
98
- {
99
- committee,
100
- invalidIndex: i,
101
- ...logData,
102
- },
103
- );
104
- return { ...failedValidationResult('invalid-attestation'), invalidIndex: i };
105
- }
106
- }
107
- }
108
-
109
- const validAttestationCount = attestorInfos.filter(info => info.status === 'recovered-from-signature').length;
110
- if (validAttestationCount < requiredAttestationCount) {
111
- logger?.warn(`Insufficient attestations for checkpoint at slot ${slot}`, {
112
- requiredAttestations: requiredAttestationCount,
113
- actualAttestations: validAttestationCount,
114
- ...logData,
115
- });
116
- return failedValidationResult('insufficient-attestations');
117
- }
118
-
119
- logger?.debug(
120
- `Checkpoint attestations validated successfully for checkpoint ${checkpoint.number} at slot ${slot}`,
121
- logData,
122
- );
123
- return { valid: true };
124
- }
package/src/rpc/index.ts DELETED
@@ -1,16 +0,0 @@
1
- import { createSafeJsonRpcClient } from '@aztec/foundation/json-rpc/client';
2
- import { type ArchiverApi, ArchiverApiSchema } from '@aztec/stdlib/interfaces/server';
3
- import { type ComponentsVersions, getVersioningResponseHandler } from '@aztec/stdlib/versioning';
4
- import { makeTracedFetch } from '@aztec/telemetry-client';
5
-
6
- export function createArchiverClient(
7
- url: string,
8
- versions: Partial<ComponentsVersions>,
9
- fetch = makeTracedFetch([1, 2, 3], true),
10
- ): ArchiverApi {
11
- return createSafeJsonRpcClient<ArchiverApi>(url, ArchiverApiSchema, {
12
- namespaceMethods: 'archiver',
13
- fetch,
14
- onResponse: getVersioningResponseHandler(versions),
15
- });
16
- }
File without changes