@aztec-labs/archiver 6.0.0-nightly.20260829

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 (174) hide show
  1. package/README.md +178 -0
  2. package/dest/archiver.d.ts +194 -0
  3. package/dest/archiver.d.ts.map +1 -0
  4. package/dest/archiver.js +948 -0
  5. package/dest/config.d.ts +34 -0
  6. package/dest/config.d.ts.map +1 -0
  7. package/dest/config.js +100 -0
  8. package/dest/errors.d.ts +97 -0
  9. package/dest/errors.d.ts.map +1 -0
  10. package/dest/errors.js +141 -0
  11. package/dest/factory.d.ts +32 -0
  12. package/dest/factory.d.ts.map +1 -0
  13. package/dest/factory.js +183 -0
  14. package/dest/index.d.ts +20 -0
  15. package/dest/index.d.ts.map +1 -0
  16. package/dest/index.js +18 -0
  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/l1/data_retrieval.js +308 -0
  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 +116 -0
  51. package/dest/modules/data_source_base.d.ts.map +1 -0
  52. package/dest/modules/data_source_base.js +334 -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 +392 -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 +1369 -0
  62. package/dest/modules/outbox_trees_resolver.d.ts +64 -0
  63. package/dest/modules/outbox_trees_resolver.d.ts.map +1 -0
  64. package/dest/modules/outbox_trees_resolver.js +184 -0
  65. package/dest/modules/validation.d.ts +40 -0
  66. package/dest/modules/validation.d.ts.map +1 -0
  67. package/dest/modules/validation.js +122 -0
  68. package/dest/store/block_store.d.ts +304 -0
  69. package/dest/store/block_store.d.ts.map +1 -0
  70. package/dest/store/block_store.js +1252 -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/store/contract_instance_store.js +129 -0
  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 +111 -0
  93. package/dest/store/message_store.d.ts.map +1 -0
  94. package/dest/store/message_store.js +522 -0
  95. package/dest/structs/data_retrieval.d.ts +27 -0
  96. package/dest/structs/data_retrieval.d.ts.map +1 -0
  97. package/dest/structs/data_retrieval.js +5 -0
  98. package/dest/structs/inbox_message.d.ts +17 -0
  99. package/dest/structs/inbox_message.d.ts.map +1 -0
  100. package/dest/structs/inbox_message.js +33 -0
  101. package/dest/structs/published.d.ts +2 -0
  102. package/dest/structs/published.d.ts.map +1 -0
  103. package/dest/structs/published.js +1 -0
  104. package/dest/test/fake_l1_state.d.ts +220 -0
  105. package/dest/test/fake_l1_state.d.ts.map +1 -0
  106. package/dest/test/fake_l1_state.js +565 -0
  107. package/dest/test/index.d.ts +5 -0
  108. package/dest/test/index.d.ts.map +1 -0
  109. package/dest/test/index.js +6 -0
  110. package/dest/test/mock_archiver.d.ts +35 -0
  111. package/dest/test/mock_archiver.d.ts.map +1 -0
  112. package/dest/test/mock_archiver.js +93 -0
  113. package/dest/test/mock_l1_to_l2_message_source.d.ts +24 -0
  114. package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -0
  115. package/dest/test/mock_l1_to_l2_message_source.js +79 -0
  116. package/dest/test/mock_l2_block_source.d.ts +139 -0
  117. package/dest/test/mock_l2_block_source.d.ts.map +1 -0
  118. package/dest/test/mock_l2_block_source.js +489 -0
  119. package/dest/test/mock_structs.d.ts +92 -0
  120. package/dest/test/mock_structs.d.ts.map +1 -0
  121. package/dest/test/mock_structs.js +188 -0
  122. package/dest/test/noop_l1_archiver.d.ts +34 -0
  123. package/dest/test/noop_l1_archiver.d.ts.map +1 -0
  124. package/dest/test/noop_l1_archiver.js +88 -0
  125. package/package.json +108 -0
  126. package/src/archiver.ts +785 -0
  127. package/src/config.ts +133 -0
  128. package/src/errors.ts +211 -0
  129. package/src/factory.ts +262 -0
  130. package/src/index.ts +29 -0
  131. package/src/interfaces.ts +9 -0
  132. package/src/l1/README.md +55 -0
  133. package/src/l1/bin/retrieve-calldata.ts +194 -0
  134. package/src/l1/calldata_retriever.ts +529 -0
  135. package/src/l1/data_retrieval.ts +498 -0
  136. package/src/l1/debug_tx.ts +98 -0
  137. package/src/l1/spire_proposer.ts +151 -0
  138. package/src/l1/trace_tx.ts +127 -0
  139. package/src/l1/types.ts +12 -0
  140. package/src/l1/validate_historical_logs.ts +140 -0
  141. package/src/l1/validate_trace.ts +228 -0
  142. package/src/modules/contract_data_source_adapter.ts +46 -0
  143. package/src/modules/data_source_base.ts +482 -0
  144. package/src/modules/data_store_updater.ts +520 -0
  145. package/src/modules/instrumentation.ts +217 -0
  146. package/src/modules/l1_synchronizer.ts +1296 -0
  147. package/src/modules/outbox_trees_resolver.ts +220 -0
  148. package/src/modules/validation.ts +186 -0
  149. package/src/store/block_store.ts +1604 -0
  150. package/src/store/contract_class_store.ts +126 -0
  151. package/src/store/contract_instance_store.ts +178 -0
  152. package/src/store/data_stores.ts +103 -0
  153. package/src/store/function_names_cache.ts +37 -0
  154. package/src/store/l2_tips_cache.ts +35 -0
  155. package/src/store/log_store.ts +380 -0
  156. package/src/store/log_store_codec.ts +143 -0
  157. package/src/store/message_store.ts +621 -0
  158. package/src/structs/data_retrieval.ts +27 -0
  159. package/src/structs/inbox_message.ts +48 -0
  160. package/src/structs/published.ts +1 -0
  161. package/src/test/fake_l1_state.ts +807 -0
  162. package/src/test/fixtures/debug_traceTransaction-multicall3.json +88 -0
  163. package/src/test/fixtures/debug_traceTransaction-multiplePropose.json +153 -0
  164. package/src/test/fixtures/debug_traceTransaction-proxied.json +122 -0
  165. package/src/test/fixtures/trace_transaction-multicall3.json +65 -0
  166. package/src/test/fixtures/trace_transaction-multiplePropose.json +319 -0
  167. package/src/test/fixtures/trace_transaction-proxied.json +128 -0
  168. package/src/test/fixtures/trace_transaction-randomRevert.json +216 -0
  169. package/src/test/index.ts +7 -0
  170. package/src/test/mock_archiver.ts +122 -0
  171. package/src/test/mock_l1_to_l2_message_source.ts +81 -0
  172. package/src/test/mock_l2_block_source.ts +620 -0
  173. package/src/test/mock_structs.ts +317 -0
  174. package/src/test/noop_l1_archiver.ts +157 -0
@@ -0,0 +1,310 @@
1
+ import { INITIAL_L2_BLOCK_NUM } from '@aztec-labs/constants';
2
+ import { createLogger } from '@aztec-labs/foundation/log';
3
+ import { MAX_LOGS_PER_TAG } from '@aztec-labs/stdlib/interfaces/api-limit';
4
+ import { decodeKeyTail, decodeValue, encodeKey, encodePublicPrefix, encodeValue, endOfTagRange, endOfTxRange, fieldHex, incKey, tagHexForLog } from './log_store_codec.js';
5
+ /**
6
+ * Indexes every emitted private and public log under a composite hex-string key
7
+ * `[contractAddress (public only)]-tag-blockNumber-txIndexWithinBlock-logIndexWithinTx`,
8
+ * where each numeric segment is zero-padded to 8 lowercase hex digits (4 bytes BE) and
9
+ * `contractAddress` / `tag` are the bare 64-hex-char field representations (no `0x` prefix). The
10
+ * fixed-width zero-padded hex segments sort lexicographically in the same order as the canonical
11
+ * `(contract, tag, blockNumber, txIndexWithinBlock, logIndexWithinTx)` tuple, so a single ordered
12
+ * range scan answers every {@link PrivateLogsQuery} / {@link PublicLogsQuery}.
13
+ *
14
+ * Per-block secondary indices (`#privateKeysByBlock`, `#publicKeysByBlock`) record the exact primary
15
+ * keys written for each block so {@link deleteLogs} can drop them on reorg without having to range
16
+ * scan by block (block isn't the leading key segment).
17
+ *
18
+ * Contract-class logs are no longer stored or served by the log store.
19
+ */ export class LogStore {
20
+ db;
21
+ blockStore;
22
+ genesisBlockHash;
23
+ /** Primary map: composite private key (tag + tail = 96 hex chars + separators) -> serialized {@link StoredLogValue}. */ #privateLogs;
24
+ /** Primary map: composite public key (contract + tag + tail) -> serialized {@link StoredLogValue}. */ #publicLogs;
25
+ /** Secondary deletion index: blockNumber -> the exact primary keys written for that block. */ #privateKeysByBlock;
26
+ #publicKeysByBlock;
27
+ #log;
28
+ /**
29
+ * @param genesisBlockHash - Hash of the synthetic genesis block. During early sync the PXE anchors to
30
+ * genesis and passes its hash as a query `referenceBlock`; since the archiver never indexes the
31
+ * genesis block, the store recognizes this hash directly and resolves it to the genesis block number
32
+ * rather than mistaking it for a reorg.
33
+ */ constructor(db, blockStore, genesisBlockHash){
34
+ this.db = db;
35
+ this.blockStore = blockStore;
36
+ this.genesisBlockHash = genesisBlockHash;
37
+ this.#log = createLogger('archiver:log_store');
38
+ this.#privateLogs = db.openMap('archiver_private_logs');
39
+ this.#publicLogs = db.openMap('archiver_public_logs');
40
+ this.#privateKeysByBlock = db.openMap('archiver_private_log_keys_by_block');
41
+ this.#publicKeysByBlock = db.openMap('archiver_public_log_keys_by_block');
42
+ }
43
+ /**
44
+ * Indexes every emitted private and public log from the given blocks. Wraps the write in a single
45
+ * `db.transactionAsync` so the primary entries and the per-block secondary indices stay consistent.
46
+ *
47
+ * A block is only ever added once; on reorg the archiver calls {@link deleteLogs} first, so we write
48
+ * the secondary index entries with a plain `set` (overwrite) rather than read-modify-append.
49
+ */ addLogs(blocks) {
50
+ return this.db.transactionAsync(async ()=>{
51
+ for (const block of blocks){
52
+ const blockHash = await block.hash();
53
+ const blockNumber = block.number;
54
+ const blockTimestamp = block.timestamp;
55
+ const privateKeys = [];
56
+ const privateValues = [];
57
+ const publicKeys = [];
58
+ const publicValues = [];
59
+ for(let txIndexWithinBlock = 0; txIndexWithinBlock < block.body.txEffects.length; txIndexWithinBlock++){
60
+ const txEffect = block.body.txEffects[txIndexWithinBlock];
61
+ const txHash = txEffect.txHash;
62
+ // Private and public log indices are counted independently per tx, each starting at 0.
63
+ let privateLogIndexWithinTx = 0;
64
+ let publicLogIndexWithinTx = 0;
65
+ for (const log of txEffect.privateLogs){
66
+ const tagHex = tagHexForLog(log.fields);
67
+ const key = encodeKey(tagHex, blockNumber, txIndexWithinBlock, privateLogIndexWithinTx);
68
+ const value = encodeValue({
69
+ txHash,
70
+ blockHash,
71
+ blockTimestamp,
72
+ logData: log.getEmittedFields()
73
+ });
74
+ privateKeys.push(key);
75
+ privateValues.push(value);
76
+ privateLogIndexWithinTx++;
77
+ }
78
+ for (const log of txEffect.publicLogs){
79
+ const contractHex = fieldHex(log.contractAddress);
80
+ const tagHex = tagHexForLog(log.fields);
81
+ const key = encodeKey(encodePublicPrefix(contractHex, tagHex), blockNumber, txIndexWithinBlock, publicLogIndexWithinTx);
82
+ const value = encodeValue({
83
+ txHash,
84
+ blockHash,
85
+ blockTimestamp,
86
+ logData: log.getEmittedFields()
87
+ });
88
+ publicKeys.push(key);
89
+ publicValues.push(value);
90
+ publicLogIndexWithinTx++;
91
+ }
92
+ }
93
+ for(let i = 0; i < privateKeys.length; i++){
94
+ await this.#privateLogs.set(privateKeys[i], privateValues[i]);
95
+ }
96
+ for(let i = 0; i < publicKeys.length; i++){
97
+ await this.#publicLogs.set(publicKeys[i], publicValues[i]);
98
+ }
99
+ await this.#privateKeysByBlock.set(blockNumber, privateKeys);
100
+ await this.#publicKeysByBlock.set(blockNumber, publicKeys);
101
+ this.#log.debug(`Indexed logs for block ${blockNumber}`, {
102
+ blockNumber,
103
+ privateCount: privateKeys.length,
104
+ publicCount: publicKeys.length
105
+ });
106
+ }
107
+ return true;
108
+ });
109
+ }
110
+ /**
111
+ * Deletes every log indexed under any of the given blocks. Secondary-index driven, so it doesn't
112
+ * have to range-scan the primary maps.
113
+ */ deleteLogs(blocks) {
114
+ return this.db.transactionAsync(async ()=>{
115
+ for (const block of blocks){
116
+ const blockNumber = block.number;
117
+ const [privateKeys, publicKeys] = await Promise.all([
118
+ this.#privateKeysByBlock.getAsync(blockNumber),
119
+ this.#publicKeysByBlock.getAsync(blockNumber)
120
+ ]);
121
+ if (privateKeys) {
122
+ for (const key of privateKeys){
123
+ await this.#privateLogs.delete(key);
124
+ }
125
+ await this.#privateKeysByBlock.delete(blockNumber);
126
+ }
127
+ if (publicKeys) {
128
+ for (const key of publicKeys){
129
+ await this.#publicLogs.delete(key);
130
+ }
131
+ await this.#publicKeysByBlock.delete(blockNumber);
132
+ }
133
+ }
134
+ return true;
135
+ });
136
+ }
137
+ /** Returns one inner array per element of `query.tags`, in input order. */ getPrivateLogsByTags(query) {
138
+ LogStore.#validateQuery(query);
139
+ return this.db.transactionAsync(()=>this.#runQuery(query, /* contractHex */ undefined));
140
+ }
141
+ /** Returns one inner array per element of `query.tags`, in input order. */ getPublicLogsByTags(query) {
142
+ LogStore.#validateQuery(query);
143
+ return this.db.transactionAsync(()=>this.#runQuery(query, fieldHex(query.contractAddress)));
144
+ }
145
+ static #validateQuery(query) {
146
+ if (query.txHash !== undefined && (query.fromBlock !== undefined || query.toBlock !== undefined)) {
147
+ throw new Error('`txHash` is mutually exclusive with `fromBlock`/`toBlock`');
148
+ }
149
+ }
150
+ async #runQuery(query, contractHex) {
151
+ const isPublic = contractHex !== undefined;
152
+ const tags = query.tags ?? [];
153
+ const primaryMap = isPublic ? this.#publicLogs : this.#privateLogs;
154
+ // referenceBlock reorg check, in-transaction, against the same db the log primary maps live on. The
155
+ // genesis block is a valid anchor during early sync but is synthetic and never indexed in the block
156
+ // store, so resolve it directly to the genesis block number rather than mistaking it for a reorg.
157
+ let referenceBlockNumber;
158
+ if (query.referenceBlock) {
159
+ if (query.referenceBlock.equals(this.genesisBlockHash)) {
160
+ referenceBlockNumber = INITIAL_L2_BLOCK_NUM - 1;
161
+ } else {
162
+ const refBlk = await this.blockStore.getBlockData({
163
+ hash: query.referenceBlock
164
+ });
165
+ if (!refBlk) {
166
+ throw new Error(`Reference block ${query.referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`);
167
+ }
168
+ referenceBlockNumber = refBlk.header.globalVariables.blockNumber;
169
+ }
170
+ }
171
+ // Compute the exclusive upper-block bound across `toBlock` and `referenceBlock`.
172
+ // `toBlock` is already exclusive; `referenceBlock` caps inclusively, so its exclusive form is +1.
173
+ let upperExclusive;
174
+ if (query.toBlock !== undefined) {
175
+ upperExclusive = query.toBlock;
176
+ }
177
+ if (referenceBlockNumber !== undefined) {
178
+ const refExclusive = referenceBlockNumber + 1;
179
+ upperExclusive = upperExclusive === undefined ? refExclusive : Math.min(upperExclusive, refExclusive);
180
+ }
181
+ // Resolve txHash -> (blockNumber, txIndexInBlock) once for the whole query.
182
+ let txLocation;
183
+ if (query.txHash) {
184
+ const loc = await this.blockStore.getTxLocation(query.txHash);
185
+ if (!loc) {
186
+ return tags.map(()=>[]);
187
+ }
188
+ txLocation = loc;
189
+ if (upperExclusive !== undefined && txLocation[0] >= upperExclusive) {
190
+ return tags.map(()=>[]);
191
+ }
192
+ }
193
+ const fromBlock = query.fromBlock ?? INITIAL_L2_BLOCK_NUM;
194
+ const includeEffects = query.includeEffects === true;
195
+ const perTagResults = [];
196
+ for (const tagEntry of tags){
197
+ const { tagHex, afterLog } = normalizeTagEntry(tagEntry);
198
+ const prefix = contractHex !== undefined ? encodePublicPrefix(contractHex, tagHex) : tagHex;
199
+ const end = txLocation ? endOfTxRange(prefix, txLocation[0], txLocation[1]) : endOfTagRange(prefix, upperExclusive);
200
+ let start;
201
+ if (afterLog) {
202
+ // Cursor wins as the start; `fromBlock` is ignored (fine if the cursor sits below it). The cursor
203
+ // carries `(blockNumber, txIndexWithinBlock, logIndexWithinTx)`, which slot directly into the
204
+ // composite key — no tx-hash lookup needed.
205
+ start = incKey(encodeKey(prefix, afterLog.blockNumber, afterLog.txIndexWithinBlock, afterLog.logIndexWithinTx));
206
+ } else if (txLocation) {
207
+ start = encodeKey(prefix, txLocation[0], txLocation[1], 0);
208
+ } else {
209
+ start = encodeKey(prefix, fromBlock, 0, 0);
210
+ }
211
+ const limit = query.limitPerTag ?? MAX_LOGS_PER_TAG;
212
+ const out = [];
213
+ for await (const [rawKey, rawVal] of primaryMap.entriesAsync({
214
+ start,
215
+ end,
216
+ limit
217
+ })){
218
+ const tail = decodeKeyTail(rawKey);
219
+ const value = decodeValue(rawVal);
220
+ out.push({
221
+ logData: value.logData,
222
+ blockNumber: tail.blockNumber,
223
+ blockHash: value.blockHash,
224
+ blockTimestamp: value.blockTimestamp,
225
+ txHash: value.txHash,
226
+ txIndexWithinBlock: tail.txIndexWithinBlock,
227
+ logIndexWithinTx: tail.logIndexWithinTx
228
+ });
229
+ }
230
+ perTagResults.push(out);
231
+ }
232
+ if (includeEffects) {
233
+ // Dedupe by txHash across the entire page so a tx with many tagged logs costs one fetch.
234
+ const txHashByKey = new Map();
235
+ for (const arr of perTagResults){
236
+ for (const log of arr){
237
+ txHashByKey.set(log.txHash.toString(), log.txHash);
238
+ }
239
+ }
240
+ const uniqueTxs = Array.from(txHashByKey.values());
241
+ if (uniqueTxs.length > 0) {
242
+ const effects = await this.blockStore.getNoteHashesAndNullifiers(uniqueTxs);
243
+ const byTxHash = new Map();
244
+ uniqueTxs.forEach((tx, i)=>byTxHash.set(tx.toString(), effects[i]));
245
+ for(let i = 0; i < perTagResults.length; i++){
246
+ perTagResults[i] = perTagResults[i].map((log)=>{
247
+ const [noteHashes, nullifiers] = byTxHash.get(log.txHash.toString()) ?? [
248
+ [],
249
+ []
250
+ ];
251
+ return {
252
+ ...log,
253
+ noteHashes,
254
+ nullifiers
255
+ };
256
+ });
257
+ }
258
+ }
259
+ }
260
+ return perTagResults;
261
+ }
262
+ /**
263
+ * Reads back every private log indexed for the given block via the per-block secondary index. Order
264
+ * matches the canonical composite-key order (`tag`, `blockNumber`, `txIndexWithinBlock`,
265
+ * `logIndexWithinTx`). Used by the data-store-updater test suite to verify the indexed-vs-block-body
266
+ * counts without depending on the removed `getPublicLogs(LogFilter)` API.
267
+ */ getPrivateLogsForBlock(blockNumber) {
268
+ return this.db.transactionAsync(()=>this.#readBlockLogs(this.#privateKeysByBlock, this.#privateLogs, blockNumber));
269
+ }
270
+ /** {@inheritDoc LogStore.getPrivateLogsForBlock} */ getPublicLogsForBlock(blockNumber) {
271
+ return this.db.transactionAsync(()=>this.#readBlockLogs(this.#publicKeysByBlock, this.#publicLogs, blockNumber));
272
+ }
273
+ async #readBlockLogs(keysByBlock, primaryMap, blockNumber) {
274
+ const keys = await keysByBlock.getAsync(blockNumber);
275
+ if (!keys || keys.length === 0) {
276
+ return [];
277
+ }
278
+ const results = [];
279
+ for (const key of keys){
280
+ const raw = await primaryMap.getAsync(key);
281
+ if (!raw) {
282
+ continue;
283
+ }
284
+ const tail = decodeKeyTail(key);
285
+ const value = decodeValue(raw);
286
+ results.push({
287
+ logData: value.logData,
288
+ blockNumber: tail.blockNumber,
289
+ blockHash: value.blockHash,
290
+ blockTimestamp: value.blockTimestamp,
291
+ txHash: value.txHash,
292
+ txIndexWithinBlock: tail.txIndexWithinBlock,
293
+ logIndexWithinTx: tail.logIndexWithinTx
294
+ });
295
+ }
296
+ return results;
297
+ }
298
+ }
299
+ /** Pulls `{ tagHex, afterLog }` out of a {@link TagQuery}, normalizing the bare-tag form. */ function normalizeTagEntry(entry) {
300
+ if (typeof entry === 'object' && entry !== null && 'tag' in entry) {
301
+ return {
302
+ tagHex: fieldHex(entry.tag.value),
303
+ afterLog: entry.afterLog
304
+ };
305
+ }
306
+ return {
307
+ tagHex: fieldHex(entry.value),
308
+ afterLog: undefined
309
+ };
310
+ }
@@ -0,0 +1,78 @@
1
+ import { BlockNumber } from '@aztec-labs/foundation/branded-types';
2
+ import { Fr } from '@aztec-labs/foundation/curves/bn254';
3
+ import { BlockHash } from '@aztec-labs/stdlib/block';
4
+ import { TxHash } from '@aztec-labs/stdlib/tx';
5
+ export declare const NUMERIC_HEX_LEN = 8;
6
+ export declare const SEP = "-";
7
+ /**
8
+ * Sentinel appended after a numeric hex segment to build an end bound strictly greater than any
9
+ * real key for that namespace. `'g'` sorts lexicographically after every hex digit (`0`-`9`, `a`-`f`),
10
+ * so `prefix + '-g'` is a clean exclusive upper bound.
11
+ */
12
+ export declare const HEX_SENTINEL = "g";
13
+ export type ParsedKeyTail = {
14
+ blockNumber: BlockNumber;
15
+ txIndexWithinBlock: number;
16
+ logIndexWithinTx: number;
17
+ };
18
+ /**
19
+ * Per-kind stored value layout (no msgpackr):
20
+ * txHash(32) ++ blockHash(32) ++ blockTimestamp(u64 BE = 8) ++ logDataLen(u32 BE = 4) ++ logData[i].toBuffer()...
21
+ * `blockNumber`, `txIndexWithinBlock`, and `logIndexWithinTx` are decoded from the composite key.
22
+ */
23
+ export type StoredLogValue = {
24
+ txHash: TxHash;
25
+ blockHash: BlockHash;
26
+ blockTimestamp: bigint;
27
+ logData: Fr[];
28
+ };
29
+ /** Returns the 64-char lowercase hex representation of a field, stripping the `0x` prefix. */
30
+ export declare function fieldHex(value: Fr | {
31
+ toString: () => string;
32
+ }): string;
33
+ /**
34
+ * Tag prefix for a log: the hex of its first field, or the empty string when the log carries no fields.
35
+ * A protocol-valid public log can have zero fields (e.g. a raw AVM `EMITPUBLICLOG` with `logSize = 0`),
36
+ * which has no tag to index by. Encoding it under the empty tag keeps it retrievable via the per-block
37
+ * read (and droppable on reorg) while never matching a real 64-hex-char tag query — instead of reading
38
+ * `fields[0]` off an empty array and aborting the whole block-ingestion transaction.
39
+ */
40
+ export declare function tagHexForLog(fields: Fr[]): string;
41
+ /** Encodes a number as 8-char zero-padded lowercase hex (matches a u32 big-endian byte buffer's lex order). */
42
+ export declare function u32Hex(n: number): string;
43
+ /**
44
+ * Encodes the composite primary key as `prefix-block-txIdx-logIdx` where `prefix` is the leading
45
+ * segment (`tag` for private; `contract-tag` for public) and the trailing triple is fixed-width
46
+ * 8-char zero-padded hex so byte-order matches `(blockNumber, txIndexWithinBlock, logIndexWithinTx)`.
47
+ */
48
+ export declare function encodeKey(prefix: string, blockNumber: number, txIndex: number, logIndex: number): string;
49
+ /**
50
+ * Decodes the trailing `(blockNumber, txIndexWithinBlock, logIndexWithinTx)` triple from a composite
51
+ * key. The leading prefix segments are ignored — we only ever read them off the input query, never
52
+ * back off the key.
53
+ */
54
+ export declare function decodeKeyTail(key: string): ParsedKeyTail;
55
+ /**
56
+ * Exclusive end bound for a `(contract, tag)`-prefix scan. With an `upperBlockExclusive` we cut at
57
+ * `(prefix, upper, 0, 0)`. With no bound we use `prefix + '-' + HEX_SENTINEL`, which sorts strictly
58
+ * after every real key under `prefix` (`g` is greater than any hex digit).
59
+ */
60
+ export declare function endOfTagRange(prefix: string, upperBlockExclusive: number | undefined): string;
61
+ /**
62
+ * Exclusive end bound for a tx-strict scan: every key strictly inside `(prefix, txBlk, txIdx, *)`.
63
+ * `prefix-block-txIdx-` followed by the hex sentinel is the first key past every real logIndex for
64
+ * this tx and strictly less than the next tx's first key.
65
+ */
66
+ export declare function endOfTxRange(prefix: string, txBlk: number, txIdx: number): string;
67
+ /**
68
+ * Returns the smallest string strictly greater than a fully-encoded composite key. The encoded key
69
+ * ends in a hex digit, and `'g'` sorts strictly after any hex digit, so appending `'g'` is the
70
+ * smallest possible successor in our key alphabet. Used to turn an inclusive cursor into an
71
+ * exclusive `start`.
72
+ */
73
+ export declare function incKey(key: string): string;
74
+ export declare function encodeValue(value: StoredLogValue): Buffer;
75
+ export declare function decodeValue(buffer: Buffer | Uint8Array): StoredLogValue;
76
+ /** Encodes the public-log key prefix as `contractHex-tagHex`. */
77
+ export declare function encodePublicPrefix(contractHex: string, tagHex: string): string;
78
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibG9nX3N0b3JlX2Nv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B,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa,CAQxD;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,mBAAmB,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAK7F;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAEjF;AAED;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE1C;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,cAAc,GAAG,MAAM,CAQzD;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,GAAG,cAAc,CAiBvE;AAED,iEAAiE;AACjE,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAE9E"}
@@ -0,0 +1,110 @@
1
+ import { BlockNumber } from '@aztec-labs/foundation/branded-types';
2
+ import { Fr } from '@aztec-labs/foundation/curves/bn254';
3
+ import { BlockHash } from '@aztec-labs/stdlib/block';
4
+ import { TxHash } from '@aztec-labs/stdlib/tx';
5
+ export const NUMERIC_HEX_LEN = 8;
6
+ export const SEP = '-';
7
+ /**
8
+ * Sentinel appended after a numeric hex segment to build an end bound strictly greater than any
9
+ * real key for that namespace. `'g'` sorts lexicographically after every hex digit (`0`-`9`, `a`-`f`),
10
+ * so `prefix + '-g'` is a clean exclusive upper bound.
11
+ */ export const HEX_SENTINEL = 'g';
12
+ /** Returns the 64-char lowercase hex representation of a field, stripping the `0x` prefix. */ export function fieldHex(value) {
13
+ // Fr.toString() and AztecAddress.toString() both return `0x` + 64 lowercase hex chars.
14
+ return value.toString().slice(2);
15
+ }
16
+ /**
17
+ * Tag prefix for a log: the hex of its first field, or the empty string when the log carries no fields.
18
+ * A protocol-valid public log can have zero fields (e.g. a raw AVM `EMITPUBLICLOG` with `logSize = 0`),
19
+ * which has no tag to index by. Encoding it under the empty tag keeps it retrievable via the per-block
20
+ * read (and droppable on reorg) while never matching a real 64-hex-char tag query — instead of reading
21
+ * `fields[0]` off an empty array and aborting the whole block-ingestion transaction.
22
+ */ export function tagHexForLog(fields) {
23
+ return fields.length > 0 ? fieldHex(fields[0]) : '';
24
+ }
25
+ /** Encodes a number as 8-char zero-padded lowercase hex (matches a u32 big-endian byte buffer's lex order). */ export function u32Hex(n) {
26
+ return n.toString(16).padStart(NUMERIC_HEX_LEN, '0');
27
+ }
28
+ /**
29
+ * Encodes the composite primary key as `prefix-block-txIdx-logIdx` where `prefix` is the leading
30
+ * segment (`tag` for private; `contract-tag` for public) and the trailing triple is fixed-width
31
+ * 8-char zero-padded hex so byte-order matches `(blockNumber, txIndexWithinBlock, logIndexWithinTx)`.
32
+ */ export function encodeKey(prefix, blockNumber, txIndex, logIndex) {
33
+ return `${prefix}${SEP}${u32Hex(blockNumber)}${SEP}${u32Hex(txIndex)}${SEP}${u32Hex(logIndex)}`;
34
+ }
35
+ /**
36
+ * Decodes the trailing `(blockNumber, txIndexWithinBlock, logIndexWithinTx)` triple from a composite
37
+ * key. The leading prefix segments are ignored — we only ever read them off the input query, never
38
+ * back off the key.
39
+ */ export function decodeKeyTail(key) {
40
+ const parts = key.split(SEP);
41
+ const len = parts.length;
42
+ return {
43
+ blockNumber: BlockNumber(parseInt(parts[len - 3], 16)),
44
+ txIndexWithinBlock: parseInt(parts[len - 2], 16),
45
+ logIndexWithinTx: parseInt(parts[len - 1], 16)
46
+ };
47
+ }
48
+ /**
49
+ * Exclusive end bound for a `(contract, tag)`-prefix scan. With an `upperBlockExclusive` we cut at
50
+ * `(prefix, upper, 0, 0)`. With no bound we use `prefix + '-' + HEX_SENTINEL`, which sorts strictly
51
+ * after every real key under `prefix` (`g` is greater than any hex digit).
52
+ */ export function endOfTagRange(prefix, upperBlockExclusive) {
53
+ if (upperBlockExclusive === undefined) {
54
+ return `${prefix}${SEP}${HEX_SENTINEL}`;
55
+ }
56
+ return encodeKey(prefix, upperBlockExclusive, 0, 0);
57
+ }
58
+ /**
59
+ * Exclusive end bound for a tx-strict scan: every key strictly inside `(prefix, txBlk, txIdx, *)`.
60
+ * `prefix-block-txIdx-` followed by the hex sentinel is the first key past every real logIndex for
61
+ * this tx and strictly less than the next tx's first key.
62
+ */ export function endOfTxRange(prefix, txBlk, txIdx) {
63
+ return `${prefix}${SEP}${u32Hex(txBlk)}${SEP}${u32Hex(txIdx)}${SEP}${HEX_SENTINEL}`;
64
+ }
65
+ /**
66
+ * Returns the smallest string strictly greater than a fully-encoded composite key. The encoded key
67
+ * ends in a hex digit, and `'g'` sorts strictly after any hex digit, so appending `'g'` is the
68
+ * smallest possible successor in our key alphabet. Used to turn an inclusive cursor into an
69
+ * exclusive `start`.
70
+ */ export function incKey(key) {
71
+ return key + HEX_SENTINEL;
72
+ }
73
+ export function encodeValue(value) {
74
+ const head = Buffer.allocUnsafe(32 + 32 + 8 + 4);
75
+ value.txHash.toBuffer().copy(head, 0);
76
+ value.blockHash.toBuffer().copy(head, 32);
77
+ head.writeBigUInt64BE(value.blockTimestamp, 64);
78
+ head.writeUInt32BE(value.logData.length, 72);
79
+ const fieldBufs = value.logData.map((f)=>f.toBuffer());
80
+ return Buffer.concat([
81
+ head,
82
+ ...fieldBufs
83
+ ]);
84
+ }
85
+ export function decodeValue(buffer) {
86
+ const buf = Buffer.isBuffer(buffer) ? buffer : Buffer.from(buffer.buffer, buffer.byteOffset, buffer.byteLength);
87
+ let off = 0;
88
+ const txHash = TxHash.fromBuffer(buf.subarray(off, off + 32));
89
+ off += 32;
90
+ const blockHash = BlockHash.fromBuffer(buf.subarray(off, off + 32));
91
+ off += 32;
92
+ const blockTimestamp = buf.readBigUInt64BE(off);
93
+ off += 8;
94
+ const logDataLen = buf.readUInt32BE(off);
95
+ off += 4;
96
+ const logData = new Array(logDataLen);
97
+ for(let i = 0; i < logDataLen; i++){
98
+ logData[i] = Fr.fromBuffer(buf.subarray(off, off + 32));
99
+ off += 32;
100
+ }
101
+ return {
102
+ txHash,
103
+ blockHash,
104
+ blockTimestamp,
105
+ logData
106
+ };
107
+ }
108
+ /** Encodes the public-log key prefix as `contractHex-tagHex`. */ export function encodePublicPrefix(contractHex, tagHex) {
109
+ return `${contractHex}${SEP}${tagHex}`;
110
+ }
@@ -0,0 +1,111 @@
1
+ import type { L1BlockId } from '@aztec-labs/ethereum/l1-types';
2
+ import { Fr } from '@aztec-labs/foundation/curves/bn254';
3
+ import { type AztecAsyncKVStore, type CustomRange } from '@aztec-labs/kv-store';
4
+ import { type InboxBucket } from '@aztec-labs/stdlib/messaging';
5
+ import { type InboxMessage } from '../structs/inbox_message.js';
6
+ export declare class MessageStoreError extends Error {
7
+ readonly inboxMessage: InboxMessage;
8
+ constructor(message: string, inboxMessage: InboxMessage);
9
+ }
10
+ export declare class MessageStore {
11
+ #private;
12
+ private db;
13
+ constructor(db: AztecAsyncKVStore);
14
+ getTotalL1ToL2MessageCount(): Promise<bigint>;
15
+ /** Gets the last L1 block synced. */
16
+ getSynchedL1Block(): Promise<L1BlockId | undefined>;
17
+ /** Sets the last L1 block synced */
18
+ setSynchedL1Block(l1Block: L1BlockId): Promise<void>;
19
+ /** Gets the L1 finalized block as of the last successful message sync. */
20
+ getMessagesFinalizedL1Block(): Promise<L1BlockId | undefined>;
21
+ private maybeAdvanceFinalizedL1Block;
22
+ /**
23
+ * Appends L1 to L2 messages to the store, one whole Inbox bucket at a time.
24
+ *
25
+ * A bucket is opened and closed within a single L1 block, and callers retrieve Inbox logs in whole-L1-block ranges,
26
+ * so every message of a bucket reaches this method in the same call — including the rollover buckets a full block
27
+ * spills into. The bucket snapshots are derived from that: the batch is split per bucket sequence and each bucket
28
+ * gets a single snapshot built from its complete message set. Delivering only part of a bucket already held in the
29
+ * store is rejected, since the snapshot would then undercount the bucket. Delivering a stored bucket again from its
30
+ * first message is allowed: an L1 reorg can replace a bucket's tail, and the re-sync that follows replays the whole
31
+ * L1 block it lives in.
32
+ *
33
+ * Requires messages to be ordered by index and to continue the stored chain. Throws a `MessageStoreError` if
34
+ * messages arrive out of order, if the rolling hash chain breaks, or if a bucket arrives incomplete.
35
+ */
36
+ addL1ToL2MessageBuckets(messages: InboxMessage[]): Promise<void>;
37
+ private assertIncomingBucketsAreComplete;
38
+ private writeIncomingBucketSnapshots;
39
+ /**
40
+ * Gets the L1 to L2 message index in the L1 to L2 message tree.
41
+ * @param l1ToL2Message - The L1 to L2 message.
42
+ * @returns The index of the L1 to L2 message in the L1 to L2 message tree (undefined if not found).
43
+ */
44
+ getL1ToL2MessageIndex(l1ToL2Message: Fr): Promise<bigint | undefined>;
45
+ getLastMessage(): Promise<InboxMessage | undefined>;
46
+ /**
47
+ * Atomically updates the message sync state: the L1 sync point and (optionally) the L1 finalized block as of this
48
+ * sync. The finalized block is advanced monotonically.
49
+ */
50
+ setMessageSyncState(l1Block: L1BlockId, finalizedL1Block?: L1BlockId): Promise<void>;
51
+ iterateL1ToL2Messages(range?: CustomRange<bigint>): AsyncIterableIterator<InboxMessage>;
52
+ removeL1ToL2Messages(startIndex: bigint): Promise<void>;
53
+ private rewindBucketsAfterRemoval;
54
+ /**
55
+ * Returns the Inbox bucket with the given sequence number, or undefined if it has not been synced. Sequence 0 is
56
+ * the genesis sentinel: the on-chain Inbox reserves it as the "consumed nothing" base case
57
+ * and never absorbs a message into it, so the archiver ingests no snapshot for it; it is synthesized here (rolling
58
+ * hash 0, total 0) so streaming consumers can resolve a genesis parent or an empty checkpoint's last-consumed bucket.
59
+ */
60
+ getInboxBucket(seq: bigint): Promise<InboxBucket | undefined>;
61
+ /**
62
+ * Returns the Inbox bucket whose cumulative message total equals `totalMsgCount`, or undefined if no synced bucket
63
+ * sits on that boundary. Sequence 0 (total 0) is the genesis sentinel base case; otherwise the
64
+ * message at global index `totalMsgCount - 1` is the last message of the bucket with that cumulative total, so its
65
+ * `bucketSeq` resolves the bucket. A total that does not land on a bucket boundary returns undefined.
66
+ */
67
+ getInboxBucketByTotalMsgCount(totalMsgCount: bigint): Promise<InboxBucket | undefined>;
68
+ /**
69
+ * Returns the message leaves in the cumulative Inbox message-count range `[startLeafCount, endLeafCount)`, in
70
+ * insertion order. The bounds are compact L1-to-L2 tree leaf counts, which every block header
71
+ * carries, so consumers can ask for the messages a block or checkpoint consumed without resolving buckets
72
+ * themselves. Both bounds must land on a bucket boundary this archiver has synced; it throws otherwise, since a
73
+ * caller asking for a range always expects the messages in it.
74
+ */
75
+ getL1ToL2MessagesBetweenLeafCounts(startLeafCount: bigint, endLeafCount: bigint): Promise<Fr[]>;
76
+ private getBucketAtBoundary;
77
+ /**
78
+ * Returns the latest Inbox bucket opened at or before the given L1 timestamp, or undefined if every synced bucket
79
+ * was opened strictly after it.
80
+ */
81
+ getLatestInboxBucketAtOrBefore(timestamp: bigint): Promise<InboxBucket | undefined>;
82
+ /**
83
+ * Returns the message leaves absorbed into buckets in the range `(fromExclusive, toInclusive]`, in insertion order.
84
+ * Both bounds must name buckets this archiver has synced, so that an empty result means the
85
+ * range holds no messages rather than hiding an unsynced bound; callers route the
86
+ * `InboxBucketNotSyncedError` to their own catch-up handling. Sequence 0 is the genesis base case and always
87
+ * resolves: the range then starts at the first message of the Inbox.
88
+ */
89
+ getL1ToL2MessagesBetweenBuckets(fromExclusive: bigint, toInclusive: bigint): Promise<Fr[]>;
90
+ private getMessageLeavesInIndexRange;
91
+ private getBucketSnapshotBySeq;
92
+ private getSyncedBucketSnapshot;
93
+ private writeBucketSnapshot;
94
+ private getNewestBucketSeq;
95
+ private getTotalMsgCountBeforeBucket;
96
+ private toInboxBucket;
97
+ private bucketSeqToKey;
98
+ private timestampToKey;
99
+ /**
100
+ * Removes every L1 to L2 message inserted after the given L1 block, so the message store matches the L1 Inbox state
101
+ * as of that block. Used when rolling the archiver back to an earlier checkpoint, whose L1 block is passed here.
102
+ *
103
+ * A bucket lives entirely within one L1 block, so the cut always falls on a bucket boundary and can be found from
104
+ * the bucket snapshots alone, without reading the messages being removed.
105
+ */
106
+ rollbackL1ToL2MessagesAfterL1Block(l1BlockNumber: bigint): Promise<void>;
107
+ private indexToKey;
108
+ private leafToIndexKey;
109
+ private increaseTotalMessageCount;
110
+ }
111
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWVzc2FnZV9zdG9yZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3N0b3JlL21lc3NhZ2Vfc3RvcmUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLEVBQUUsU0FBUyxFQUFFLE1BQU0sK0JBQStCLENBQUM7QUFFL0QsT0FBTyxFQUFFLEVBQUUsRUFBRSxNQUFNLHFDQUFxQyxDQUFDO0FBSXpELE9BQU8sRUFDTCxLQUFLLGlCQUFpQixFQUl0QixLQUFLLFdBQVcsRUFFakIsTUFBTSxzQkFBc0IsQ0FBQztBQUM5QixPQUFPLEVBQUUsS0FBSyxXQUFXLEVBQTBCLE1BQU0sOEJBQThCLENBQUM7QUFHeEYsT0FBTyxFQUFFLEtBQUssWUFBWSxFQUFrRCxNQUFNLDZCQUE2QixDQUFDO0FBNkVoSCxxQkFBYSxpQkFBa0IsU0FBUSxLQUFLO2FBR3hCLFlBQVksRUFBRSxZQUFZO0lBRjVDLFlBQ0UsT0FBTyxFQUFFLE1BQU0sRUFDQyxZQUFZLEVBQUUsWUFBWSxFQUkzQztDQUNGO0FBRUQscUJBQWEsWUFBWTs7SUFzQlgsT0FBTyxDQUFDLEVBQUU7SUFBdEIsWUFBb0IsRUFBRSxFQUFFLGlCQUFpQixFQVF4QztJQUVZLDBCQUEwQixJQUFJLE9BQU8sQ0FBQyxNQUFNLENBQUMsQ0FFekQ7SUFFRCxxQ0FBcUM7SUFDeEIsaUJBQWlCLElBQUksT0FBTyxDQUFDLFNBQVMsR0FBRyxTQUFTLENBQUM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