@aztec/pxe 0.0.1-commit.321f6a9 → 0.0.1-commit.330febf

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 (124) hide show
  1. package/dest/bin/check_oracle_version.js +2 -38
  2. package/dest/bin/index.d.ts +2 -2
  3. package/dest/bin/index.d.ts.map +1 -1
  4. package/dest/bin/index.js +1 -1
  5. package/dest/bin/oracle_version_helpers.d.ts +1 -15
  6. package/dest/bin/oracle_version_helpers.d.ts.map +1 -1
  7. package/dest/bin/oracle_version_helpers.js +0 -21
  8. package/dest/block_synchronizer/block_synchronizer.d.ts +3 -5
  9. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
  10. package/dest/block_synchronizer/block_synchronizer.js +5 -18
  11. package/dest/contract/contract_class_service.d.ts +1 -8
  12. package/dest/contract/contract_class_service.d.ts.map +1 -1
  13. package/dest/contract/contract_class_service.js +8 -40
  14. package/dest/contract_function_simulator/contract_function_simulator.d.ts +1 -8
  15. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  16. package/dest/contract_function_simulator/contract_function_simulator.js +0 -17
  17. package/dest/contract_function_simulator/oracle/oracle_type_mappings.d.ts +1 -1
  18. package/dest/contract_function_simulator/oracle/oracle_type_mappings.d.ts.map +1 -1
  19. package/dest/contract_function_simulator/oracle/oracle_type_mappings.js +11 -1
  20. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +1 -1
  21. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  22. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +6 -2
  23. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +10 -2
  24. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  25. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +128 -38
  26. package/dest/events/event_service.d.ts +13 -6
  27. package/dest/events/event_service.d.ts.map +1 -1
  28. package/dest/events/event_service.js +13 -13
  29. package/dest/logs/log_service.d.ts +13 -5
  30. package/dest/logs/log_service.d.ts.map +1 -1
  31. package/dest/logs/log_service.js +20 -36
  32. package/dest/messages/tx_resolver_service.d.ts +18 -7
  33. package/dest/messages/tx_resolver_service.d.ts.map +1 -1
  34. package/dest/messages/tx_resolver_service.js +9 -8
  35. package/dest/node/benchmarked_node.d.ts +20 -0
  36. package/dest/node/benchmarked_node.d.ts.map +1 -0
  37. package/dest/node/benchmarked_node.js +94 -0
  38. package/dest/node/caching_aztec_node.d.ts +24 -0
  39. package/dest/node/caching_aztec_node.d.ts.map +1 -0
  40. package/dest/node/caching_aztec_node.js +267 -0
  41. package/dest/notes/note_service.d.ts +12 -6
  42. package/dest/notes/note_service.d.ts.map +1 -1
  43. package/dest/notes/note_service.js +9 -9
  44. package/dest/oracle_version.js +2 -2
  45. package/dest/pxe.d.ts +1 -1
  46. package/dest/pxe.d.ts.map +1 -1
  47. package/dest/pxe.js +31 -14
  48. package/dest/storage/contract_store/contract_store.d.ts +1 -1
  49. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  50. package/dest/storage/contract_store/contract_store.js +2 -2
  51. package/dest/storage/fact_store/origin_state.d.ts +1 -1
  52. package/dest/storage/fact_store/origin_state.js +1 -1
  53. package/dest/storage/tagging_store/sender_tagging_store.d.ts +23 -8
  54. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  55. package/dest/storage/tagging_store/sender_tagging_store.js +33 -18
  56. package/dest/tagging/constants.d.ts +9 -1
  57. package/dest/tagging/constants.d.ts.map +1 -1
  58. package/dest/tagging/constants.js +10 -0
  59. package/dest/tagging/get_all_logs_by_tags.d.ts +29 -8
  60. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -1
  61. package/dest/tagging/get_all_logs_by_tags.js +29 -10
  62. package/dest/tagging/index.d.ts +2 -2
  63. package/dest/tagging/index.d.ts.map +1 -1
  64. package/dest/tagging/index.js +1 -1
  65. package/dest/tagging/recipient_sync/sync_tagged_private_logs.d.ts +2 -2
  66. package/dest/tagging/recipient_sync/sync_tagged_private_logs.d.ts.map +1 -1
  67. package/dest/tagging/recipient_sync/sync_tagged_private_logs.js +13 -17
  68. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +6 -3
  69. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  70. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +23 -38
  71. package/dest/tagging/sender_sync/utils/classify_pending_txs.d.ts +22 -0
  72. package/dest/tagging/sender_sync/utils/classify_pending_txs.d.ts.map +1 -0
  73. package/dest/tagging/sender_sync/utils/classify_pending_txs.js +61 -0
  74. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +15 -5
  75. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  76. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +30 -33
  77. package/dest/tagging/sender_sync/utils/resolve_pending_txs.d.ts +29 -0
  78. package/dest/tagging/sender_sync/utils/resolve_pending_txs.d.ts.map +1 -0
  79. package/dest/tagging/sender_sync/utils/resolve_pending_txs.js +41 -0
  80. package/dest/tagging/sender_sync/utils/test_utils.d.ts +16 -0
  81. package/dest/tagging/sender_sync/utils/test_utils.d.ts.map +1 -0
  82. package/dest/tagging/sender_sync/utils/test_utils.js +24 -0
  83. package/package.json +17 -17
  84. package/src/bin/check_oracle_version.ts +2 -46
  85. package/src/bin/index.ts +1 -1
  86. package/src/bin/oracle_version_helpers.ts +0 -24
  87. package/src/block_synchronizer/block_synchronizer.ts +6 -23
  88. package/src/contract/contract_class_service.ts +8 -46
  89. package/src/contract_function_simulator/contract_function_simulator.ts +0 -17
  90. package/src/contract_function_simulator/oracle/oracle_type_mappings.ts +16 -1
  91. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +7 -2
  92. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +130 -40
  93. package/src/events/event_service.ts +24 -14
  94. package/src/logs/log_service.ts +37 -44
  95. package/src/messages/tx_resolver_service.ts +22 -11
  96. package/src/node/benchmarked_node.ts +140 -0
  97. package/src/node/caching_aztec_node.ts +406 -0
  98. package/src/notes/note_service.ts +19 -13
  99. package/src/oracle_version.ts +2 -2
  100. package/src/pxe.ts +32 -16
  101. package/src/storage/contract_store/contract_store.ts +2 -1
  102. package/src/storage/fact_store/origin_state.ts +1 -1
  103. package/src/storage/tagging_store/sender_tagging_store.ts +51 -26
  104. package/src/tagging/constants.ts +12 -0
  105. package/src/tagging/get_all_logs_by_tags.ts +47 -11
  106. package/src/tagging/index.ts +6 -1
  107. package/src/tagging/recipient_sync/sync_tagged_private_logs.ts +19 -22
  108. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +27 -57
  109. package/src/tagging/sender_sync/utils/classify_pending_txs.ts +91 -0
  110. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +40 -38
  111. package/src/tagging/sender_sync/utils/resolve_pending_txs.ts +64 -0
  112. package/src/tagging/sender_sync/utils/test_utils.ts +46 -0
  113. package/dest/contract_function_simulator/aztec_node_read_cache.d.ts +0 -39
  114. package/dest/contract_function_simulator/aztec_node_read_cache.d.ts.map +0 -1
  115. package/dest/contract_function_simulator/aztec_node_read_cache.js +0 -60
  116. package/dest/contract_function_simulator/benchmarked_node.d.ts +0 -9
  117. package/dest/contract_function_simulator/benchmarked_node.d.ts.map +0 -1
  118. package/dest/contract_function_simulator/benchmarked_node.js +0 -77
  119. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +0 -17
  120. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +0 -1
  121. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +0 -60
  122. package/src/contract_function_simulator/aztec_node_read_cache.ts +0 -89
  123. package/src/contract_function_simulator/benchmarked_node.ts +0 -103
  124. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +0 -66
@@ -1,6 +1,5 @@
1
1
  import { AppTaggingSecret, SiloedTag } from '@aztec/stdlib/logs';
2
- import { TxHash } from '@aztec/stdlib/tx';
3
- import { UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN } from '../../tagging/constants.js';
2
+ import { UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN, unfinalizedTaggingIndexesWindowEnd } from '../../tagging/constants.js';
4
3
  /**
5
4
  * Data provider of tagging data used when syncing the sender tagging indexes. The recipient counterpart of this class
6
5
  * is called RecipientTaggingStore. We have the data stores separate for sender and recipient because
@@ -152,11 +151,9 @@ import { UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN } from '../../tagging/constants.
152
151
  })));
153
152
  // Process in memory and validate
154
153
  for (const { range, secretStr, pendingData, finalizedIndex } of rangeData){
155
- // Check that the highest index is not further than window length from the highest finalized index.
156
- if (range.highestIndex > (finalizedIndex ?? 0) + UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN) {
157
- throw new Error(`Highest used index ${range.highestIndex} is further than window length from the highest finalized index ${finalizedIndex ?? 0}.
158
- Tagging window length ${UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN} is configured too low. Contact the Aztec team
159
- to increase it!`);
154
+ const windowEnd = unfinalizedTaggingIndexesWindowEnd(finalizedIndex);
155
+ if (range.highestIndex >= windowEnd) {
156
+ throw windowExceededError(range.highestIndex, windowEnd, finalizedIndex);
160
157
  }
161
158
  // Throw if the lowest index is lower than or equal to the last finalized index
162
159
  if (finalizedIndex !== undefined && range.lowestIndex <= finalizedIndex) {
@@ -201,19 +198,20 @@ import { UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN } from '../../tagging/constants.
201
198
  });
202
199
  }
203
200
  /**
204
- * Returns the transaction hashes of all pending transactions that contain highest indexes within a specified range
205
- * for a given directional app tagging secret. We check based on the highest indexes only as that is the relevant
206
- * information for the caller of this function.
201
+ * Returns the pending txs whose highest index falls within [startIndex, endIndex) for a given directional app
202
+ * tagging secret. The highest index is what decides whether a tx belongs to the window, so it alone is matched
203
+ * against the bounds, and it is also the only index a caller needs: a tx whose highest index is onchain has every
204
+ * lower one onchain too. A secret holds at most one entry per tx hash, so no tx hash appears twice in the result.
207
205
  * @param secret - The directional app tagging secret to query pending indexes for.
208
206
  * @param startIndex - The lower bound of the index range (inclusive).
209
207
  * @param endIndex - The upper bound of the index range (exclusive).
210
- * @returns An array of unique transaction hashes for pending transactions that contain indexes in the range
211
- * [startIndex, endIndex). Returns an empty array if no pending indexes exist in the range.
212
- */ getTxHashesOfPendingIndexes(secret, startIndex, endIndex, jobId) {
208
+ */ getPendingTxs(secret, startIndex, endIndex, jobId) {
213
209
  return this.#store.transactionAsync(async ()=>{
214
210
  const existing = await this.#readPendingIndexes(jobId, secret.toString());
215
- const txHashes = existing.filter((entry)=>entry.highestIndex >= startIndex && entry.highestIndex < endIndex).map((entry)=>entry.txHash);
216
- return Array.from(new Set(txHashes)).map(TxHash.fromString);
211
+ return existing.filter((entry)=>entry.highestIndex >= startIndex && entry.highestIndex < endIndex).map((entry)=>({
212
+ txHash: entry.txHash,
213
+ highestIndex: entry.highestIndex
214
+ }));
217
215
  });
218
216
  }
219
217
  /**
@@ -319,13 +317,26 @@ import { UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN } from '../../tagging/constants.
319
317
  }
320
318
  /**
321
319
  * Updates pending indexes corresponding to the given transaction hashes to be finalized and prunes any lower pending
322
- * indexes.
323
- */ async finalizePendingIndexes(txHashes, jobId) {
320
+ * indexes. Applies to every secret the txs used, so the caller must hold tx-level evidence that the whole tx
321
+ * finalized. Callers holding evidence about a single secret must use {@link finalizePendingIndexesOfSecret} instead.
322
+ */ finalizePendingIndexes(txHashes, jobId) {
323
+ return this.#finalizePendingIndexes(txHashes, jobId);
324
+ }
325
+ /**
326
+ * Same as {@link finalizePendingIndexes}, but restricted to the pending indexes of a single secret.
327
+ *
328
+ * Finalizing every secret off single-secret evidence would be unsound: a tx whose execution partially reverted can
329
+ * have all of one secret's tags onchain and none of another's, and the second secret's indexes must not be recorded
330
+ * as finalized when they never reached the chain.
331
+ */ finalizePendingIndexesOfSecret(secret, txHashes, jobId) {
332
+ return this.#finalizePendingIndexes(txHashes, jobId, secret.toString());
333
+ }
334
+ async #finalizePendingIndexes(txHashes, jobId, onlySecret) {
324
335
  if (txHashes.length === 0) {
325
336
  return;
326
337
  }
327
338
  const txHashStrings = new Set(txHashes.map((tx)=>tx.toString()));
328
- const secretsWithData = await this.#getSecretsWithPendingData(jobId);
339
+ const secretsWithData = (await this.#getSecretsWithPendingData(jobId)).filter(({ secret })=>onlySecret === undefined || secret === onlySecret);
329
340
  for (const { secret, pendingData, lastFinalized } of secretsWithData){
330
341
  let currentPending = pendingData;
331
342
  let currentFinalized = lastFinalized;
@@ -409,3 +420,7 @@ import { UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN } from '../../tagging/constants.
409
420
  }
410
421
  }
411
422
  }
423
+ /** Builds the error thrown when a pending tag index is at or past the unfinalized tagging window end. */ export function windowExceededError(highestIndex, windowEnd, finalizedIndex) {
424
+ const finalizedDescription = finalizedIndex === undefined ? 'no index finalized yet' : `highest finalized index ${finalizedIndex}`;
425
+ return new Error(`Highest used index ${highestIndex} is at or past the window end ${windowEnd} (${finalizedDescription}). ` + `Tagging window length ${UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN} is configured too low. ` + `Contact the Aztec team to increase it!`);
426
+ }
@@ -1,3 +1,11 @@
1
1
  export declare const UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN: number;
2
+ /**
3
+ * Exclusive upper bound of the tag indexes that can exist for a secret whose highest finalized index is
4
+ * `finalizedIndex` (undefined when nothing is finalized yet). The sender store refuses pending indexes at or past it,
5
+ * and both sender and recipient sync scan exactly up to it. Every absolute window bound must come from this helper:
6
+ * a site with a wider or narrower bound lets a tx land at an index the syncs never scan, so two stores sharing the
7
+ * secret could later pick a colliding index.
8
+ */
9
+ export declare function unfinalizedTaggingIndexesWindowEnd(finalizedIndex: number | undefined): number;
2
10
  export declare const INITIAL_CONSTRAINED_PROBE_LEN = 2;
3
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29uc3RhbnRzLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdGFnZ2luZy9jb25zdGFudHMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBbUJBLGVBQU8sTUFBTSxzQ0FBc0MsUUFBK0IsQ0FBQztBQVVuRixlQUFPLE1BQU0sNkJBQTZCLElBQUksQ0FBQyJ9
11
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29uc3RhbnRzLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdGFnZ2luZy9jb25zdGFudHMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBbUJBLGVBQU8sTUFBTSxzQ0FBc0MsUUFBK0IsQ0FBQztBQUVuRjs7Ozs7O0dBTUc7QUFDSCx3QkFBZ0Isa0NBQWtDLENBQUMsY0FBYyxFQUFFLE1BQU0sR0FBRyxTQUFTLEdBQUcsTUFBTSxDQUc3RjtBQVVELGVBQU8sTUFBTSw2QkFBNkIsSUFBSSxDQUFDIn0=
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/tagging/constants.ts"],"names":[],"mappings":"AAmBA,eAAO,MAAM,sCAAsC,QAA+B,CAAC;AAUnF,eAAO,MAAM,6BAA6B,IAAI,CAAC"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/tagging/constants.ts"],"names":[],"mappings":"AAmBA,eAAO,MAAM,sCAAsC,QAA+B,CAAC;AAEnF;;;;;;GAMG;AACH,wBAAgB,kCAAkC,CAAC,cAAc,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAG7F;AAUD,eAAO,MAAM,6BAA6B,IAAI,CAAC"}
@@ -17,6 +17,16 @@ import { MAX_PRIVATE_LOGS_PER_TX } from '@aztec/constants';
17
17
  // reserved at log emission time, before squashing is decided, and the kernel's reset/squash loop is not bounded by
18
18
  // MAX_PRIVATE_LOGS_PER_TX. No fixed window value closes that gap.
19
19
  export const UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN = MAX_PRIVATE_LOGS_PER_TX + 20;
20
+ /**
21
+ * Exclusive upper bound of the tag indexes that can exist for a secret whose highest finalized index is
22
+ * `finalizedIndex` (undefined when nothing is finalized yet). The sender store refuses pending indexes at or past it,
23
+ * and both sender and recipient sync scan exactly up to it. Every absolute window bound must come from this helper:
24
+ * a site with a wider or narrower bound lets a tx land at an index the syncs never scan, so two stores sharing the
25
+ * secret could later pick a colliding index.
26
+ */ export function unfinalizedTaggingIndexesWindowEnd(finalizedIndex) {
27
+ const windowStart = finalizedIndex === undefined ? 0 : finalizedIndex + 1;
28
+ return windowStart + UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN;
29
+ }
20
30
  // The number of tags probed per constrained secret in the first round.
21
31
  //
22
32
  // The probe doubles each round (2, 4, 8, ..., capped at UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN) while every probed
@@ -1,8 +1,29 @@
1
- import type { BlockNumber } from '@aztec/foundation/branded-types';
1
+ import { BlockNumber } from '@aztec/foundation/branded-types';
2
2
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
3
3
  import type { BlockHash } from '@aztec/stdlib/block';
4
4
  import type { AztecNode } from '@aztec/stdlib/interfaces/client';
5
5
  import { type LogResult, type SiloedTag, type Tag } from '@aztec/stdlib/logs';
6
+ import type { BlockHeader } from '@aztec/stdlib/tx';
7
+ /**
8
+ * The block a tag query is anchored to.
9
+ *
10
+ * Both fields come from one header (see {@link logQueryAnchorOf}), which is what keeps the bound and the reorg check
11
+ * talking about the same block.
12
+ */
13
+ export type LogQueryAnchor = {
14
+ /**
15
+ * Hash of the anchor block, naming the chain the query must be answered on: the node throws if that block is gone,
16
+ * which is how a reorg surfaces.
17
+ */
18
+ hash: BlockHash;
19
+ /** Height of the anchor block, bounding the query to blocks at or below it. */
20
+ number: BlockNumber;
21
+ };
22
+ /**
23
+ * The {@link LogQueryAnchor} naming `anchorBlockHeader`: its hash and its height. Callers build it once and reuse
24
+ * it across every query anchored to that block, so the header is hashed only once.
25
+ */
26
+ export declare function logQueryAnchorOf(anchorBlockHeader: BlockHeader): Promise<LogQueryAnchor>;
6
27
  /** Optional block-range, effects opt-in, and pagination cap shared by both wrappers. */
7
28
  export type GetAllLogsByTagsOptions = {
8
29
  /** Lower block bound, inclusive. */
@@ -27,22 +48,22 @@ export type GetAllLogsByTagsOptions = {
27
48
  *
28
49
  * @param aztecNode - The Aztec node to query.
29
50
  * @param tags - The siloed tags to search for.
30
- * @param anchorBlockHash - Reference block for the Aztec node query, throws if block is not found there (typically
31
- * because of reorgs).
51
+ * @param anchor - Block the query is anchored to: results stop there, and the call throws if that block is not found
52
+ * (typically because of reorgs).
32
53
  * @param options - Optional `fromBlock`/`toBlock` range and `includeEffects` opt-in.
33
54
  * @returns An array of log arrays, one per tag, containing all logs across all pages.
34
55
  */
35
- export declare function getAllPrivateLogsByTags<Opts extends GetAllLogsByTagsOptions = GetAllLogsByTagsOptions>(aztecNode: AztecNode, tags: SiloedTag[], anchorBlockHash: BlockHash, options?: Opts): Promise<LogResult<Opts>[][]>;
56
+ export declare function getAllPrivateLogsByTags<Opts extends GetAllLogsByTagsOptions = GetAllLogsByTagsOptions>(aztecNode: AztecNode, tags: SiloedTag[], anchor: LogQueryAnchor, options?: Opts): Promise<LogResult<Opts>[][]>;
36
57
  /**
37
58
  * Fetches all public logs for the given tags from a contract, automatically paginating per-tag via `afterLog` cursors.
38
59
  *
39
60
  * @param aztecNode - The Aztec node to query.
40
61
  * @param contractAddress - The contract address to search logs for.
41
62
  * @param tags - The tags to search for.
42
- * @param anchorBlockHash - Reference block for the Aztec node query, throws if block is not found there (typically
43
- * because of reorgs).
63
+ * @param anchor - Block the query is anchored to: results stop there, and the call throws if that block is not found
64
+ * (typically because of reorgs).
44
65
  * @param options - Optional `fromBlock`/`toBlock` range and `includeEffects` opt-in.
45
66
  * @returns An array of log arrays, one per tag, containing all logs across all pages.
46
67
  */
47
- export declare function getAllPublicLogsByTagsFromContract<Opts extends GetAllLogsByTagsOptions = GetAllLogsByTagsOptions>(aztecNode: AztecNode, contractAddress: AztecAddress, tags: Tag[], anchorBlockHash: BlockHash, options?: Opts): Promise<LogResult<Opts>[][]>;
48
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZ2V0X2FsbF9sb2dzX2J5X3RhZ3MuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy90YWdnaW5nL2dldF9hbGxfbG9nc19ieV90YWdzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLFdBQVcsRUFBRSxNQUFNLGlDQUFpQyxDQUFDO0FBQ25FLE9BQU8sS0FBSyxFQUFFLFlBQVksRUFBRSxNQUFNLDZCQUE2QixDQUFDO0FBQ2hFLE9BQU8sS0FBSyxFQUFFLFNBQVMsRUFBRSxNQUFNLHFCQUFxQixDQUFDO0FBRXJELE9BQU8sS0FBSyxFQUFFLFNBQVMsRUFBRSxNQUFNLGlDQUFpQyxDQUFDO0FBQ2pFLE9BQU8sRUFFTCxLQUFLLFNBQVMsRUFDZCxLQUFLLFNBQVMsRUFDZCxLQUFLLEdBQUcsRUFHVCxNQUFNLG9CQUFvQixDQUFDO0FBRTVCLHdGQUF3RjtBQUN4RixNQUFNLE1BQU0sdUJBQXVCLEdBQUc7SUFDcEMsb0NBQW9DO0lBQ3BDLFNBQVMsQ0FBQyxFQUFFLFdBQVcsQ0FBQztJQUN4QixvQ0FBb0M7SUFDcEMsT0FBTyxDQUFDLEVBQUUsV0FBVyxDQUFDO0lBQ3RCOzs7O09BSUc7SUFDSCxjQUFjLENBQUMsRUFBRSxPQUFPLENBQUM7SUFDekI7Ozs7T0FJRztJQUNILFdBQVcsQ0FBQyxFQUFFLE1BQU0sQ0FBQztDQUN0QixDQUFDO0FBMEJGOzs7Ozs7Ozs7R0FTRztBQUNILHdCQUFnQix1QkFBdUIsQ0FBQyxJQUFJLFNBQVMsdUJBQXVCLEdBQUcsdUJBQXVCLEVBQ3BHLFNBQVMsRUFBRSxTQUFTLEVBQ3BCLElBQUksRUFBRSxTQUFTLEVBQUUsRUFDakIsZUFBZSxFQUFFLFNBQVMsRUFDMUIsT0FBTyxHQUFFLElBQWlCLEdBQ3pCLE9BQU8sQ0FBQyxTQUFTLENBQUMsSUFBSSxDQUFDLEVBQUUsRUFBRSxDQUFDLENBYTlCO0FBRUQ7Ozs7Ozs7Ozs7R0FVRztBQUNILHdCQUFnQixrQ0FBa0MsQ0FBQyxJQUFJLFNBQVMsdUJBQXVCLEdBQUcsdUJBQXVCLEVBQy9HLFNBQVMsRUFBRSxTQUFTLEVBQ3BCLGVBQWUsRUFBRSxZQUFZLEVBQzdCLElBQUksRUFBRSxHQUFHLEVBQUUsRUFDWCxlQUFlLEVBQUUsU0FBUyxFQUMxQixPQUFPLEdBQUUsSUFBaUIsR0FDekIsT0FBTyxDQUFDLFNBQVMsQ0FBQyxJQUFJLENBQUMsRUFBRSxFQUFFLENBQUMsQ0FjOUIifQ==
68
+ export declare function getAllPublicLogsByTagsFromContract<Opts extends GetAllLogsByTagsOptions = GetAllLogsByTagsOptions>(aztecNode: AztecNode, contractAddress: AztecAddress, tags: Tag[], anchor: LogQueryAnchor, options?: Opts): Promise<LogResult<Opts>[][]>;
69
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZ2V0X2FsbF9sb2dzX2J5X3RhZ3MuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy90YWdnaW5nL2dldF9hbGxfbG9nc19ieV90YWdzLnRzIl0sIm5hbWVz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B;;;OAGG;IACH,IAAI,EAAE,SAAS,CAAC;IAChB,+EAA+E;IAC/E,MAAM,EAAE,WAAW,CAAC;CACrB,CAAC;AAEF;;;GAGG;AACH,wBAAsB,gBAAgB,CAAC,iBAAiB,EAAE,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC,CAE9F;AAED,wFAAwF;AACxF,MAAM,MAAM,uBAAuB,GAAG;IACpC,oCAAoC;IACpC,SAAS,CAAC,EAAE,WAAW,CAAC;IACxB,oCAAoC;IACpC,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AA0BF;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,SAAS,uBAAuB,GAAG,uBAAuB,EACpG,SAAS,EAAE,SAAS,EACpB,IAAI,EAAE,SAAS,EAAE,EACjB,MAAM,EAAE,cAAc,EACtB,OAAO,GAAE,IAAiB,GACzB,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAa9B;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,kCAAkC,CAAC,IAAI,SAAS,uBAAuB,GAAG,uBAAuB,EAC/G,SAAS,EAAE,SAAS,EACpB,eAAe,EAAE,YAAY,EAC7B,IAAI,EAAE,GAAG,EAAE,EACX,MAAM,EAAE,cAAc,EACtB,OAAO,GAAE,IAAiB,GACzB,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAc9B"}
@@ -1,5 +1,15 @@
1
+ import { BlockNumber } from '@aztec/foundation/branded-types';
1
2
  import { MAX_RPC_LEN } from '@aztec/stdlib/interfaces/api-limit';
2
3
  import { queryAllPrivateLogsByTags, queryAllPublicLogsByTags } from '@aztec/stdlib/logs';
4
+ /**
5
+ * The {@link LogQueryAnchor} naming `anchorBlockHeader`: its hash and its height. Callers build it once and reuse
6
+ * it across every query anchored to that block, so the header is hashed only once.
7
+ */ export async function logQueryAnchorOf(anchorBlockHeader) {
8
+ return {
9
+ hash: await anchorBlockHeader.hash(),
10
+ number: anchorBlockHeader.getBlockNumber()
11
+ };
12
+ }
3
13
  /**
4
14
  * Splits tags into chunks of MAX_RPC_LEN, paginates each chunk via the stdlib per-tag cursor helper,
5
15
  * then stitches the results back into a single array preserving the original tag order.
@@ -22,16 +32,16 @@ import { queryAllPrivateLogsByTags, queryAllPublicLogsByTags } from '@aztec/stdl
22
32
  *
23
33
  * @param aztecNode - The Aztec node to query.
24
34
  * @param tags - The siloed tags to search for.
25
- * @param anchorBlockHash - Reference block for the Aztec node query, throws if block is not found there (typically
26
- * because of reorgs).
35
+ * @param anchor - Block the query is anchored to: results stop there, and the call throws if that block is not found
36
+ * (typically because of reorgs).
27
37
  * @param options - Optional `fromBlock`/`toBlock` range and `includeEffects` opt-in.
28
38
  * @returns An array of log arrays, one per tag, containing all logs across all pages.
29
- */ export function getAllPrivateLogsByTags(aztecNode, tags, anchorBlockHash, options = {}) {
39
+ */ export function getAllPrivateLogsByTags(aztecNode, tags, anchor, options = {}) {
30
40
  return getAllPagesInBatches(tags, (batch)=>queryAllPrivateLogsByTags(aztecNode, {
31
41
  tags: batch,
32
- referenceBlock: anchorBlockHash,
42
+ referenceBlock: anchor.hash,
33
43
  fromBlock: options.fromBlock,
34
- toBlock: options.toBlock,
44
+ toBlock: exclusiveUpperBound(anchor, options.toBlock),
35
45
  includeEffects: options.includeEffects ?? false,
36
46
  limitPerTag: options.limitPerTag
37
47
  }));
@@ -42,18 +52,27 @@ import { queryAllPrivateLogsByTags, queryAllPublicLogsByTags } from '@aztec/stdl
42
52
  * @param aztecNode - The Aztec node to query.
43
53
  * @param contractAddress - The contract address to search logs for.
44
54
  * @param tags - The tags to search for.
45
- * @param anchorBlockHash - Reference block for the Aztec node query, throws if block is not found there (typically
46
- * because of reorgs).
55
+ * @param anchor - Block the query is anchored to: results stop there, and the call throws if that block is not found
56
+ * (typically because of reorgs).
47
57
  * @param options - Optional `fromBlock`/`toBlock` range and `includeEffects` opt-in.
48
58
  * @returns An array of log arrays, one per tag, containing all logs across all pages.
49
- */ export function getAllPublicLogsByTagsFromContract(aztecNode, contractAddress, tags, anchorBlockHash, options = {}) {
59
+ */ export function getAllPublicLogsByTagsFromContract(aztecNode, contractAddress, tags, anchor, options = {}) {
50
60
  return getAllPagesInBatches(tags, (batch)=>queryAllPublicLogsByTags(aztecNode, {
51
61
  contractAddress,
52
62
  tags: batch,
53
- referenceBlock: anchorBlockHash,
63
+ referenceBlock: anchor.hash,
54
64
  fromBlock: options.fromBlock,
55
- toBlock: options.toBlock,
65
+ toBlock: exclusiveUpperBound(anchor, options.toBlock),
56
66
  includeEffects: options.includeEffects ?? false,
57
67
  limitPerTag: options.limitPerTag
58
68
  }));
59
69
  }
70
+ /**
71
+ * Exclusive upper block bound for a query anchored at `anchor`: one past the anchor block, or the caller's own
72
+ * `toBlock` when that is tighter.
73
+ *
74
+ * The bound is spelled out in the request rather than left implicit in `referenceBlock`, so the request itself
75
+ * names a fixed block range that no later block can widen.
76
+ */ function exclusiveUpperBound(anchor, toBlock) {
77
+ return BlockNumber(Math.min(toBlock ?? Infinity, anchor.number + 1));
78
+ }
@@ -12,7 +12,7 @@ export { syncTaggedPrivateLogs } from './recipient_sync/sync_tagged_private_logs
12
12
  export { syncSenderTaggingIndexes } from './sender_sync/sync_sender_tagging_indexes.js';
13
13
  export { persistSenderTaggingIndexRangesForTx } from './persist_sender_tagging_index_ranges.js';
14
14
  export { UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN, INITIAL_CONSTRAINED_PROBE_LEN } from './constants.js';
15
- export { getAllPrivateLogsByTags, getAllPublicLogsByTagsFromContract } from './get_all_logs_by_tags.js';
15
+ export { type LogQueryAnchor, getAllPrivateLogsByTags, getAllPublicLogsByTagsFromContract, logQueryAnchorOf, } from './get_all_logs_by_tags.js';
16
16
  export { AppTaggingSecret, Tag, SiloedTag } from '@aztec/stdlib/logs';
17
17
  export { type PreTag, type TaggingIndexRange } from '@aztec/stdlib/logs';
18
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy90YWdnaW5nL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7Ozs7Ozs7R0FTRztBQUVILE9BQU8sRUFBRSxxQkFBcUIsRUFBRSxNQUFNLDhDQUE4QyxDQUFDO0FBQ3JGLE9BQU8sRUFBRSx3QkFBd0IsRUFBRSxNQUFNLDhDQUE4QyxDQUFDO0FBQ3hGLE9BQU8sRUFBRSxvQ0FBb0MsRUFBRSxNQUFNLDBDQUEwQyxDQUFDO0FBQ2hHLE9BQU8sRUFBRSxzQ0FBc0MsRUFBRSw2QkFBNkIsRUFBRSxNQUFNLGdCQUFnQixDQUFDO0FBQ3ZHLE9BQU8sRUFBRSx1QkFBdUIsRUFBRSxrQ0FBa0MsRUFBRSxNQUFNLDJCQUEyQixDQUFDO0FBR3hHLE9BQU8sRUFBRSxnQkFBZ0IsRUFBRSxHQUFHLEVBQUUsU0FBUyxFQUFFLE1BQU0sb0JBQW9CLENBQUM7QUFDdEUsT0FBTyxFQUFFLEtBQUssTUFBTSxFQUFFLEtBQUssaUJBQWlCLEVBQUUsTUFBTSxvQkFBb0IsQ0FBQyJ9
18
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy90YWdnaW5nL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7Ozs7Ozs7R0FTRztBQUVILE9BQU8sRUFBRSxxQkFBcUIsRUFBRSxNQUFNLDhDQUE4QyxDQUFDO0FBQ3JGLE9BQU8sRUFBRSx3QkFBd0IsRUFBRSxNQUFNLDhDQUE4QyxDQUFDO0FBQ3hGLE9BQU8sRUFBRSxvQ0FBb0MsRUFBRSxNQUFNLDBDQUEwQyxDQUFDO0FBQ2hHLE9BQU8sRUFBRSxzQ0FBc0MsRUFBRSw2QkFBNkIsRUFBRSxNQUFNLGdCQUFnQixDQUFDO0FBQ3ZHLE9BQU8sRUFDTCxLQUFLLGNBQWMsRUFDbkIsdUJBQXVCLEVBQ3ZCLGtDQUFrQyxFQUNsQyxnQkFBZ0IsR0FDakIsTUFBTSwyQkFBMkIsQ0FBQztBQUduQyxPQUFPLEVBQUUsZ0JBQWdCLEVBQUUsR0FBRyxFQUFFLFNBQVMsRUFBRSxNQUFNLG9CQUFvQixDQUFDO0FBQ3RFLE9BQU8sRUFBRSxLQUFLLE1BQU0sRUFBRSxLQUFLLGlCQUFpQixFQUFFLE1BQU0sb0JBQW9CLENBQUMifQ==
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tagging/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,8CAA8C,CAAC;AACrF,OAAO,EAAE,wBAAwB,EAAE,MAAM,8CAA8C,CAAC;AACxF,OAAO,EAAE,oCAAoC,EAAE,MAAM,0CAA0C,CAAC;AAChG,OAAO,EAAE,sCAAsC,EAAE,6BAA6B,EAAE,MAAM,gBAAgB,CAAC;AACvG,OAAO,EAAE,uBAAuB,EAAE,kCAAkC,EAAE,MAAM,2BAA2B,CAAC;AAGxG,OAAO,EAAE,gBAAgB,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,iBAAiB,EAAE,MAAM,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tagging/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,8CAA8C,CAAC;AACrF,OAAO,EAAE,wBAAwB,EAAE,MAAM,8CAA8C,CAAC;AACxF,OAAO,EAAE,oCAAoC,EAAE,MAAM,0CAA0C,CAAC;AAChG,OAAO,EAAE,sCAAsC,EAAE,6BAA6B,EAAE,MAAM,gBAAgB,CAAC;AACvG,OAAO,EACL,KAAK,cAAc,EACnB,uBAAuB,EACvB,kCAAkC,EAClC,gBAAgB,GACjB,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EAAE,gBAAgB,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,iBAAiB,EAAE,MAAM,oBAAoB,CAAC"}
@@ -11,6 +11,6 @@
11
11
  export { syncSenderTaggingIndexes } from './sender_sync/sync_sender_tagging_indexes.js';
12
12
  export { persistSenderTaggingIndexRangesForTx } from './persist_sender_tagging_index_ranges.js';
13
13
  export { UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN, INITIAL_CONSTRAINED_PROBE_LEN } from './constants.js';
14
- export { getAllPrivateLogsByTags, getAllPublicLogsByTagsFromContract } from './get_all_logs_by_tags.js';
14
+ export { getAllPrivateLogsByTags, getAllPublicLogsByTagsFromContract, logQueryAnchorOf } from './get_all_logs_by_tags.js';
15
15
  // Re-export tagging-related types from stdlib
16
16
  export { AppTaggingSecret, Tag, SiloedTag } from '@aztec/stdlib/logs';
@@ -1,4 +1,4 @@
1
- import { BlockNumber } from '@aztec/foundation/branded-types';
1
+ import type { BlockNumber } from '@aztec/foundation/branded-types';
2
2
  import type { AztecNode } from '@aztec/stdlib/interfaces/client';
3
3
  import type { AppTaggingSecret, LogResult } from '@aztec/stdlib/logs';
4
4
  import type { BlockHeader } from '@aztec/stdlib/tx';
@@ -71,4 +71,4 @@ import type { RecipientTaggingStore } from '../../storage/tagging_store/recipien
71
71
  * advanced are kept for the next iteration.
72
72
  */
73
73
  export declare function syncTaggedPrivateLogs(secrets: AppTaggingSecret[], aztecNode: AztecNode, taggingStore: RecipientTaggingStore, anchorBlockHeader: BlockHeader, finalizedBlockNumber: BlockNumber, jobId: string): Promise<LogResult[]>;
74
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3luY190YWdnZWRfcHJpdmF0ZV9sb2dzLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvdGFnZ2luZy9yZWNpcGllbnRfc3luYy9zeW5jX3RhZ2dlZF9wcml2YXRlX2xvZ3MudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLFdBQVcsRUFBRSxNQUFNLGlDQUFpQyxDQUFDO0FBRzlELE9BQU8sS0FBSyxFQUFFLFNBQVMsRUFBRSxNQUFNLGlDQUFpQyxDQUFDO0FBQ2pFLE9BQU8sS0FBSyxFQUFFLGdCQUFnQixFQUFFLFNBQVMsRUFBRSxNQUFNLG9CQUFvQixDQUFDO0FBRXRFLE9BQU8sS0FBSyxFQUFFLFdBQVcsRUFBRSxNQUFNLGtCQUFrQixDQUFDO0FBRXBELE9BQU8sS0FBSyxFQUFFLHFCQUFxQixFQUFFLE1BQU0sd0RBQXdELENBQUM7QUFLcEc7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OztHQWtFRztBQUNILHdCQUFzQixxQkFBcUIsQ0FDekMsT0FBTyxFQUFFLGdCQUFnQixFQUFFLEVBQzNCLFNBQVMsRUFBRSxTQUFTLEVBQ3BCLFlBQVksRUFBRSxxQkFBcUIsRUFDbkMsaUJBQWlCLEVBQUUsV0FBVyxFQUM5QixvQkFBb0IsRUFBRSxXQUFXLEVBQ2pDLEtBQUssRUFBRSxNQUFNLEdBQ1osT0FBTy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s.d.ts","sourceRoot":"","sources":["../../../src/tagging/recipient_sync/sync_tagged_private_logs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAG9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEtE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,wDAAwD,CAAC;AAKpG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkEG;AACH,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,gBAAgB,EAAE,EAC3B,SAAS,EAAE,SAAS,EACpB,YAAY,EAAE,qBAAqB,EACnC,iBAAiB,EAAE,WAAW,EAC9B,oBAAoB,EAAE,WAAW,EACjC,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,SAAS,EAAE,CAAC,CAqDtB"}
1
+ {"version":3,"file":"sync_tagged_private_logs.d.ts","sourceRoot":"","sources":["../../../src/tagging/recipient_sync/sync_tagged_private_logs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAEnE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEtE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,wDAAwD,CAAC;AASpG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkEG;AACH,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,gBAAgB,EAAE,EAC3B,SAAS,EAAE,SAAS,EACpB,YAAY,EAAE,qBAAqB,EACnC,iBAAiB,EAAE,WAAW,EAC9B,oBAAoB,EAAE,WAAW,EACjC,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,SAAS,EAAE,CAAC,CAoDtB"}
@@ -1,8 +1,7 @@
1
- import { BlockNumber } from '@aztec/foundation/branded-types';
2
1
  import { isDefined } from '@aztec/foundation/types';
3
2
  import { AppTaggingSecretKind, SiloedTag } from '@aztec/stdlib/logs';
4
- import { INITIAL_CONSTRAINED_PROBE_LEN, UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN } from '../constants.js';
5
- import { getAllPrivateLogsByTags } from '../get_all_logs_by_tags.js';
3
+ import { INITIAL_CONSTRAINED_PROBE_LEN, UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN, unfinalizedTaggingIndexesWindowEnd } from '../constants.js';
4
+ import { getAllPrivateLogsByTags, logQueryAnchorOf } from '../get_all_logs_by_tags.js';
6
5
  import { findHighestIndexes } from './utils/find_highest_indexes.js';
7
6
  /**
8
7
  * Fetches and syncs tagged private logs for multiple sender-recipient pairs, batching tag queries across all secrets
@@ -74,15 +73,14 @@ import { findHighestIndexes } from './utils/find_highest_indexes.js';
74
73
  if (secrets.length === 0) {
75
74
  return [];
76
75
  }
77
- const anchorBlockNumber = anchorBlockHeader.getBlockNumber();
78
- const anchorBlockHash = await anchorBlockHeader.hash();
76
+ const anchor = await logQueryAnchorOf(anchorBlockHeader);
79
77
  const currentTimestamp = anchorBlockHeader.globalVariables.timestamp;
80
78
  // Read stored indexes from the db and compute the initial [start, end) range for each secret
81
79
  let pending = await getIndexRangesForSecrets(secrets, taggingStore, jobId);
82
80
  const allLogs = [];
83
81
  while(pending.length > 0){
84
82
  // Compute tags for all pending secrets and fetch logs in batched RPC calls
85
- const logsPerSecret = await fetchLogsForSecrets(pending, aztecNode, anchorBlockNumber, anchorBlockHash);
83
+ const logsPerSecret = await fetchLogsForSecrets(pending, aztecNode, anchor);
86
84
  const nextRound = await Promise.all(pending.map(async (pendingSecret, i)=>{
87
85
  const logsFoundWithSecret = logsPerSecret[i];
88
86
  if (logsFoundWithSecret.length === 0) {
@@ -101,7 +99,7 @@ import { findHighestIndexes } from './utils/find_highest_indexes.js';
101
99
  /** Reads stored indexes for each secret and computes the initial index range to query. */ function getIndexRangesForSecrets(secrets, taggingStore, jobId) {
102
100
  return Promise.all(secrets.map(async (secret)=>{
103
101
  const currentHighestFinalizedIndex = await taggingStore.getHighestFinalizedIndex(secret, jobId);
104
- const boundEnd = (currentHighestFinalizedIndex ?? 0) + UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN + 1;
102
+ const boundEnd = unfinalizedTaggingIndexesWindowEnd(currentHighestFinalizedIndex);
105
103
  if (secret.kind === AppTaggingSecretKind.CONSTRAINED) {
106
104
  // Constrained streams are gapless and resume at the finalized index, so probe a small initial window and stop
107
105
  // at the first missing tag instead of always fetching the full window. The probe grows each round up to the
@@ -130,7 +128,7 @@ import { findHighestIndexes } from './utils/find_highest_indexes.js';
130
128
  /**
131
129
  * Computes siloed tags for all pending secrets' index ranges, fetches logs in one batched RPC call,
132
130
  * and returns the results grouped back per secret.
133
- */ async function fetchLogsForSecrets(pending, aztecNode, anchorBlockNumber, anchorBlockHash) {
131
+ */ async function fetchLogsForSecrets(pending, aztecNode, anchor) {
134
132
  // Determine the index range for each secret
135
133
  const indexesPerSecret = pending.map(({ start, end })=>Array.from({
136
134
  length: end - start
@@ -141,13 +139,11 @@ import { findHighestIndexes } from './utils/find_highest_indexes.js';
141
139
  index
142
140
  })))));
143
141
  const allTags = tagsPerSecret.flat();
144
- // getAllPrivateLogsByTags handles MAX_RPC_LEN chunking internally. Recipient sync builds `PendingTaggedLog` from
145
- // each log's note hashes and first nullifier, so we opt into effects. The `toBlock` cap (anchor block + 1,
146
- // exclusive) tells the node to skip any logs in blocks past the anchor — the same guard previously enforced
147
- // by an in-memory filter on the response.
148
- const allResults = await getAllPrivateLogsByTags(aztecNode, allTags, anchorBlockHash, {
149
- includeEffects: true,
150
- toBlock: BlockNumber(anchorBlockNumber + 1)
142
+ // getAllPrivateLogsByTags handles MAX_RPC_LEN chunking internally, and bounds the query at the anchor block so
143
+ // logs from later blocks are never returned. Recipient sync builds `PendingTaggedLog` from each log's note hashes
144
+ // and first nullifier, so we opt into effects.
145
+ const allResults = await getAllPrivateLogsByTags(aztecNode, allTags, anchor, {
146
+ includeEffects: true
151
147
  });
152
148
  // Split flat results back per secret using the known lengths
153
149
  const logsPerSecret = [];
@@ -190,7 +186,7 @@ import { findHighestIndexes } from './utils/find_highest_indexes.js';
190
186
  // Gating this on finalization would drop logs in unfinalized blocks, which sit at the top of the contiguous run.
191
187
  // The bound re-anchors to any finalized index found this round.
192
188
  const probeFullyConsumed = firstMissingIndex >= pending.end;
193
- const boundEnd = highestFinalizedIndex !== undefined ? Math.max(pending.boundEnd, highestFinalizedIndex + UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN + 1) : pending.boundEnd;
189
+ const boundEnd = highestFinalizedIndex !== undefined ? Math.max(pending.boundEnd, unfinalizedTaggingIndexesWindowEnd(highestFinalizedIndex)) : pending.boundEnd;
194
190
  // Double the probe each round, capped at the window (see INITIAL_CONSTRAINED_PROBE_LEN in ../constants.ts).
195
191
  // The queried range is already bounded by boundEnd (a probe can never reach
196
192
  // more than WINDOW_LEN past the finalized frontier); this cap just keeps the stored length from growing unbounded
@@ -228,7 +224,7 @@ import { findHighestIndexes } from './utils/find_highest_indexes.js';
228
224
  await taggingStore.updateHighestFinalizedIndex(pending.secret, highestFinalizedIndex, jobId);
229
225
  // For the next iteration we want to look only at indexes for which we have not yet fetched logs while
230
226
  // ensuring that we do not look further than WINDOW_LEN ahead of the highest finalized index.
231
- const end = highestFinalizedIndex + UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN + 1;
227
+ const end = unfinalizedTaggingIndexesWindowEnd(highestFinalizedIndex);
232
228
  return {
233
229
  kind: AppTaggingSecretKind.UNCONSTRAINED,
234
230
  secret: pending.secret,
@@ -1,16 +1,19 @@
1
- import type { BlockHash } from '@aztec/stdlib/block';
1
+ import type { BlockNumber } from '@aztec/foundation/branded-types';
2
2
  import type { AztecNode } from '@aztec/stdlib/interfaces/server';
3
3
  import type { AppTaggingSecret } from '@aztec/stdlib/logs';
4
4
  import type { SenderTaggingStore } from '../../storage/tagging_store/sender_tagging_store.js';
5
+ import type { LogQueryAnchor } from '../get_all_logs_by_tags.js';
5
6
  /**
6
7
  * Syncs tagging indexes. This function needs to be called whenever a private log is being sent.
7
8
  *
8
9
  * @param secret - The sender-side tagging `AppTaggingSecret`.
10
+ * @param finalizedBlockNumber - The locally-synced finalized tip, used to tell whether the block a discovered log
11
+ * sits in is finalized.
9
12
  * @remarks When syncing the indexes as sender we don't care about the log contents - we only care about the highest
10
13
  * pending and highest finalized indexes as that guides the next index choice when sending a log. The next index choice
11
14
  * is simply the highest pending index plus one (or finalized if pending is undefined).
12
15
  * @dev This function looks for new indexes, adds them to pending, then it checks status of each pending index and
13
16
  * updates its status accordingly.
14
17
  */
15
- export declare function syncSenderTaggingIndexes(secret: AppTaggingSecret, aztecNode: AztecNode, taggingStore: SenderTaggingStore, anchorBlockHash: BlockHash, jobId: string): Promise<void>;
16
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3luY19zZW5kZXJfdGFnZ2luZ19pbmRleGVzLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvdGFnZ2luZy9zZW5kZXJfc3luYy9zeW5jX3NlbmRlcl90YWdnaW5nX2luZGV4ZXMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLEVBQUUsU0FBUyxFQUFFLE1BQU0scUJBQXFCLENBQUM7QUFDckQsT0FBTyxLQUFLLEVBQUUsU0FBUyxFQUFFLE1BQU0saUNBQWlDLENBQUM7QUFDakUsT0FBTyxLQUFLLEVBQUUsZ0JBQWdCLEVBQUUsTUFBTSxvQkFBb0IsQ0FBQztBQUUzRCxPQUFPLEtBQUssRUFBRSxrQkFBa0IsRUFBRSxNQUFNLHFEQUFxRCxDQUFDO0FBUzlGOzs7Ozs7Ozs7R0FTRztBQUNILHdCQUFzQix3QkFBd0IsQ0FDNUMsTUFBTSxFQUFFLGdCQUFnQixFQUN4QixTQUFTLEVBQUUsU0FBUyxFQUNwQixZQUFZLEVBQUUsa0JBQWtCLEVBQ2hDLGVBQWUsRUFBRSxTQUFTLEVBQzFCLEtBQUssRUFBRSxNQUFNLEdBQ1osT0FBTyxDQUFDLElBQUksQ0FBQyxDQXdHZiJ9
18
+ export declare function syncSenderTaggingIndexes(secret: AppTaggingSecret, aztecNode: AztecNode, taggingStore: SenderTaggingStore, finalizedBlockNumber: BlockNumber, anchor: LogQueryAnchor, jobId: string): Promise<void>;
19
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3luY19zZW5kZXJfdGFnZ2luZ19pbmRleGVzLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvdGFnZ2luZy9zZW5kZXJfc3luYy9zeW5jX3NlbmRlcl90YWdnaW5nX2luZGV4ZXMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLEVBQUUsV0FBVyxFQUFFLE1BQU0saUNBQWlDLENBQUM7QUFDbkUsT0FBTyxLQUFLLEVBQUUsU0FBUyxFQUFFLE1BQU0saUNBQWlDLENBQUM7QUFDakUsT0FBTyxLQUFLLEVBQUUsZ0JBQWdCLEVBQUUsTUFBTSxvQkFBb0IsQ0FBQztBQUUzRCxPQUFPLEtBQUssRUFBRSxrQkFBa0IsRUFBRSxNQUFNLHFEQUFxRCxDQUFDO0FBRTlGLE9BQU8sS0FBSyxFQUFFLGNBQWMsRUFBRSxNQUFNLDRCQUE0QixDQUFDO0FBSWpFOzs7Ozs7Ozs7OztHQVdHO0FBQ0gsd0JBQXNCLHdCQUF3QixDQUM1QyxNQUFNLEVBQUUsZ0JBQWdCLEVBQ3hCLFNBQVMsRUFBRSxTQUFTLEVBQ3BCLFlBQVksRUFBRSxrQkFBa0IsRUFDaEMsb0JBQW9CLEVBQUUsV0FBVyxFQUNqQyxNQUFNLEVBQUUsY0FBYyxFQUN0QixLQUFLLEVBQUUsTUFBTSxHQUNaLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0EwRWYifQ==
@@ -1 +1 @@
1
- {"version":3,"file":"sync_sender_tagging_indexes.d.ts","sourceRoot":"","sources":["../../../src/tagging/sender_sync/sync_sender_tagging_indexes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAE3D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qDAAqD,CAAC;AAS9F;;;;;;;;;GASG;AACH,wBAAsB,wBAAwB,CAC5C,MAAM,EAAE,gBAAgB,EACxB,SAAS,EAAE,SAAS,EACpB,YAAY,EAAE,kBAAkB,EAChC,eAAe,EAAE,SAAS,EAC1B,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,IAAI,CAAC,CAwGf"}
1
+ {"version":3,"file":"sync_sender_tagging_indexes.d.ts","sourceRoot":"","sources":["../../../src/tagging/sender_sync/sync_sender_tagging_indexes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAE3D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qDAAqD,CAAC;AAE9F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAIjE;;;;;;;;;;;GAWG;AACH,wBAAsB,wBAAwB,CAC5C,MAAM,EAAE,gBAAgB,EACxB,SAAS,EAAE,SAAS,EACpB,YAAY,EAAE,kBAAkB,EAChC,oBAAoB,EAAE,WAAW,EACjC,MAAM,EAAE,cAAc,EACtB,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,IAAI,CAAC,CA0Ef"}
@@ -1,16 +1,18 @@
1
- import { UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN } from '../constants.js';
2
- import { EMPTY_STATUS_CHANGE, getStatusChangeOfPending, mergeStatusChanges } from './utils/get_status_change_of_pending.js';
1
+ import { unfinalizedTaggingIndexesWindowEnd } from '../constants.js';
3
2
  import { loadAndStoreNewTaggingIndexes } from './utils/load_and_store_new_tagging_indexes.js';
3
+ import { resolvePendingTxs } from './utils/resolve_pending_txs.js';
4
4
  /**
5
5
  * Syncs tagging indexes. This function needs to be called whenever a private log is being sent.
6
6
  *
7
7
  * @param secret - The sender-side tagging `AppTaggingSecret`.
8
+ * @param finalizedBlockNumber - The locally-synced finalized tip, used to tell whether the block a discovered log
9
+ * sits in is finalized.
8
10
  * @remarks When syncing the indexes as sender we don't care about the log contents - we only care about the highest
9
11
  * pending and highest finalized indexes as that guides the next index choice when sending a log. The next index choice
10
12
  * is simply the highest pending index plus one (or finalized if pending is undefined).
11
13
  * @dev This function looks for new indexes, adds them to pending, then it checks status of each pending index and
12
14
  * updates its status accordingly.
13
- */ export async function syncSenderTaggingIndexes(secret, aztecNode, taggingStore, anchorBlockHash, jobId) {
15
+ */ export async function syncSenderTaggingIndexes(secret, aztecNode, taggingStore, finalizedBlockNumber, anchor, jobId) {
14
16
  // # Explanation of how syncing works
15
17
  //
16
18
  // When choosing an index, we select: highest pending index + 1 (or highest finalized index + 1 if no pending).
@@ -26,46 +28,30 @@ import { loadAndStoreNewTaggingIndexes } from './utils/load_and_store_new_taggin
26
28
  // than WINDOW_LEN from the highest finalized index.
27
29
  //
28
30
  // # Note on performance
29
- // Each window advance requires two queries (logs + tx status). For example, syncing indexes 0–500 with a window of
30
- // 100 takes at least 10 round trips (5 windows × 2 queries).
31
+ // A window advance usually takes a single logs query: the finalization status of most txs the logs surface is
32
+ // derived from the log block numbers and the locally-synced finalized tip, without a per-tx node call. See
33
+ // `resolvePendingTxs` for the txs that the logs cannot settle and what they cost.
31
34
  const finalizedIndex = await taggingStore.getLastFinalizedIndex(secret, jobId);
32
35
  let start = finalizedIndex === undefined ? 0 : finalizedIndex + 1;
33
- let end = start + UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN;
36
+ // The loop only extends the window when the finalized index moves,
37
+ // so this first window must cover the entire permitted range on its own.
38
+ let end = unfinalizedTaggingIndexesWindowEnd(finalizedIndex);
34
39
  let previousFinalizedIndex = finalizedIndex;
35
40
  let newFinalizedIndex = undefined;
36
41
  while(true){
37
- // Pending tx hashes already in the store for this window (from prior syncs or txs this PXE itself sent).
38
- // Reading these before issuing any RPC lets us fetch their receipts in parallel with the logs query below.
39
- const knownPendingTxHashes = await taggingStore.getTxHashesOfPendingIndexes(secret, start, end, jobId);
40
- // Fire the logs query and the known-pending receipts query in parallel
41
- const [, statusOfKnown] = await Promise.all([
42
- loadAndStoreNewTaggingIndexes(secret, start, end, aztecNode, taggingStore, anchorBlockHash, jobId),
43
- knownPendingTxHashes.length > 0 ? getStatusChangeOfPending(knownPendingTxHashes, aztecNode) : Promise.resolve(EMPTY_STATUS_CHANGE)
44
- ]);
45
- // Re-read pending tx hashes after the logs query writes any newly-discovered ones to the store.
46
- const allPendingTxHashes = await taggingStore.getTxHashesOfPendingIndexes(secret, start, end, jobId);
47
- if (allPendingTxHashes.length === 0) {
42
+ const txsInLogs = await loadAndStoreNewTaggingIndexes(secret, start, end, aztecNode, taggingStore, anchor, jobId);
43
+ // Pending txs for this window: prior syncs, txs this PXE itself sent, and what the logs just stored.
44
+ const pendingTxs = await taggingStore.getPendingTxs(secret, start, end, jobId);
45
+ if (pendingTxs.length === 0) {
48
46
  break;
49
47
  }
50
- // Receipts for pending tx hashes that the logs query just surfaced still need a sequential follow-up call.
51
- // `mergePendingIndexes` is idempotent on (secret, txHash), so a re-discovered hash stays classified as known
52
- // and is not re-fetched here.
53
- const knownSet = new Set(knownPendingTxHashes.map((h)=>h.toString()));
54
- const newPendingTxHashes = allPendingTxHashes.filter((h)=>!knownSet.has(h.toString()));
55
- const statusOfNew = newPendingTxHashes.length > 0 ? await getStatusChangeOfPending(newPendingTxHashes, aztecNode) : EMPTY_STATUS_CHANGE;
56
- const { txHashesToFinalize, txHashesToDrop, txHashesWithExecutionReverted } = mergeStatusChanges(statusOfKnown, statusOfNew);
57
- await taggingStore.dropPendingIndexes(txHashesToDrop, jobId);
58
- await taggingStore.finalizePendingIndexes(txHashesToFinalize, jobId);
59
- if (txHashesWithExecutionReverted.length > 0) {
60
- const receipts = await Promise.all(txHashesWithExecutionReverted.map((txHash)=>aztecNode.getTxReceipt(txHash, {
61
- includeTxEffect: true
62
- })));
63
- for (const receipt of receipts){
64
- if (!receipt.isMined() || !receipt.txEffect) {
65
- throw new Error('TxEffect not found for execution-reverted tx. This is either a bug or a reorg has occurred.');
66
- }
67
- await taggingStore.finalizePendingIndexesOfAPartiallyRevertedTx(receipt.txEffect, jobId);
68
- }
48
+ const { txHashesFinalizedFromLogs, txHashesFinalizedFromReceipts, txHashesDropped, receiptsWithExecutionReverted } = await resolvePendingTxs(pendingTxs, txsInLogs, finalizedBlockNumber, aztecNode);
49
+ await taggingStore.dropPendingIndexes(txHashesDropped, jobId);
50
+ // The logs are queried per secret, so they only evidence this one's indexes. A receipt covers the whole tx.
51
+ await taggingStore.finalizePendingIndexesOfSecret(secret, txHashesFinalizedFromLogs, jobId);
52
+ await taggingStore.finalizePendingIndexes(txHashesFinalizedFromReceipts, jobId);
53
+ for (const receipt of receiptsWithExecutionReverted){
54
+ await taggingStore.finalizePendingIndexesOfAPartiallyRevertedTx(receipt.txEffect, jobId);
69
55
  }
70
56
  // We check if the finalized index has been updated.
71
57
  newFinalizedIndex = await taggingStore.getLastFinalizedIndex(secret, jobId);
@@ -81,8 +67,7 @@ import { loadAndStoreNewTaggingIndexes } from './utils/load_and_store_new_taggin
81
67
  // Previous window: [11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
82
68
  // New window: [21, 22, 23]
83
69
  const previousEnd = end;
84
- // Add 1 because `end` is exclusive and the known finalized index is not included in the window.
85
- end = newFinalizedIndex + UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN + 1;
70
+ end = unfinalizedTaggingIndexesWindowEnd(newFinalizedIndex);
86
71
  start = previousEnd;
87
72
  previousFinalizedIndex = newFinalizedIndex;
88
73
  } else {
@@ -0,0 +1,22 @@
1
+ import type { BlockNumber } from '@aztec/foundation/branded-types';
2
+ import type { AztecNode } from '@aztec/stdlib/interfaces/server';
3
+ import { TxHash } from '@aztec/stdlib/tx';
4
+ import type { PendingTx } from '../../../storage/tagging_store/sender_tagging_store.js';
5
+ import type { TxInLogs } from './load_and_store_new_tagging_indexes.js';
6
+ /** A sync window's pending txs, grouped by what the window's logs evidence about each of them. */
7
+ export type LogClassification = {
8
+ txHashesFinalized: TxHash[];
9
+ txHashesWithExecutionReverted: TxHash[];
10
+ txHashesAbsent: TxHash[];
11
+ };
12
+ /** Groups a window's pending txs by what its logs say about them. */
13
+ export declare function classifyPendingTxsFromLogs(pendingTxs: PendingTx[], txsInLogs: Map<string, TxInLogs>, finalizedBlockNumber: BlockNumber): LogClassification;
14
+ /** A batch of pending txs grouped by what their receipts report about them. */
15
+ export type ReceiptClassification = {
16
+ txHashesFinalized: TxHash[];
17
+ txHashesDropped: TxHash[];
18
+ txHashesWithExecutionReverted: TxHash[];
19
+ };
20
+ /** Groups pending txs by what their receipts say, for the txs the logs could not resolve. */
21
+ export declare function classifyPendingTxsFromReceipts(pending: TxHash[], aztecNode: AztecNode): Promise<ReceiptClassification>;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NLEVBQUUsQ0FBQztJQUM1QixlQUFlLEVBQUUsTUFBTSxFQUFFLENBQUM7SUFDMUIsNkJBQTZCLEVBQUUsTUFBTSxFQUFFLENBQUM7Q0FDekMsQ0FBQztBQUVGLDZGQUE2RjtBQUM3Rix3QkFBc0IsOEJBQThCLENBQ2xELE9BQU8sRUFBRSxNQUFNLEVBQUUsRUFDakIsU0FBUyxFQUFFLFNBQVMsR0FDbkIsT0FBTyxDQUFDLHFCQUFxQixDQUFDLENBb0NoQyJ9
@@ -0,0 +1 @@
1
+ {"version":3,"file":"classify_pending_txs.d.ts","sourceRoot":"","sources":["../../../../src/tagging/sender_sync/utils/classify_pending_txs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,MAAM,EAAY,MAAM,kBAAkB,CAAC;AAEpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wDAAwD,CAAC;AACxF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yCAAyC,CAAC;AAExE,kGAAkG;AAClG,MAAM,MAAM,iBAAiB,GAAG;IAC9B,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAC5B,6BAA6B,EAAE,MAAM,EAAE,CAAC;IACxC,cAAc,EAAE,MAAM,EAAE,CAAC;CAC1B,CAAC;AAEF,qEAAqE;AACrE,wBAAgB,0BAA0B,CACxC,UAAU,EAAE,SAAS,EAAE,EACvB,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,EAChC,oBAAoB,EAAE,WAAW,GAChC,iBAAiB,CAsBnB;AAED,+EAA+E;AAC/E,MAAM,MAAM,qBAAqB,GAAG;IAClC,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAC5B,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,6BAA6B,EAAE,MAAM,EAAE,CAAC;CACzC,CAAC;AAEF,6FAA6F;AAC7F,wBAAsB,8BAA8B,CAClD,OAAO,EAAE,MAAM,EAAE,EACjB,SAAS,EAAE,SAAS,GACnB,OAAO,CAAC,qBAAqB,CAAC,CAoChC"}