@aztec/pxe 5.0.0 → 5.0.1

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 (69) hide show
  1. package/dest/contract_function_simulator/oracle/oracle_registry.d.ts +2 -1
  2. package/dest/contract_function_simulator/oracle/oracle_registry.d.ts.map +1 -1
  3. package/dest/contract_function_simulator/oracle/oracle_registry.js +9 -0
  4. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +5 -2
  5. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  6. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +39 -15
  7. package/dest/entrypoints/client/bundle/index.d.ts +2 -1
  8. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  9. package/dest/entrypoints/client/bundle/index.js +1 -0
  10. package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
  11. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  12. package/dest/entrypoints/client/bundle/utils.js +10 -4
  13. package/dest/entrypoints/client/lazy/index.d.ts +2 -1
  14. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  15. package/dest/entrypoints/client/lazy/index.js +1 -0
  16. package/dest/entrypoints/client/lazy/utils.d.ts +1 -1
  17. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  18. package/dest/entrypoints/client/lazy/utils.js +10 -4
  19. package/dest/entrypoints/client/store.d.ts +14 -0
  20. package/dest/entrypoints/client/store.d.ts.map +1 -0
  21. package/dest/entrypoints/client/store.js +28 -0
  22. package/dest/entrypoints/server/index.d.ts +2 -1
  23. package/dest/entrypoints/server/index.d.ts.map +1 -1
  24. package/dest/entrypoints/server/index.js +1 -0
  25. package/dest/entrypoints/server/store.d.ts +18 -0
  26. package/dest/entrypoints/server/store.d.ts.map +1 -0
  27. package/dest/entrypoints/server/store.js +28 -0
  28. package/dest/entrypoints/server/utils.d.ts +1 -1
  29. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  30. package/dest/entrypoints/server/utils.js +8 -2
  31. package/dest/logs/log_service.d.ts +3 -2
  32. package/dest/logs/log_service.d.ts.map +1 -1
  33. package/dest/logs/log_service.js +5 -1
  34. package/dest/notes/note_service.d.ts +1 -1
  35. package/dest/notes/note_service.js +1 -1
  36. package/dest/oracle_version.d.ts +2 -2
  37. package/dest/oracle_version.js +2 -2
  38. package/dest/pxe.d.ts +1 -1
  39. package/dest/pxe.d.ts.map +1 -1
  40. package/dest/pxe.js +8 -5
  41. package/dest/storage/store_identity.d.ts +35 -0
  42. package/dest/storage/store_identity.d.ts.map +1 -0
  43. package/dest/storage/store_identity.js +44 -0
  44. package/dest/storage/tagging_store/sender_tagging_store.d.ts +19 -3
  45. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  46. package/dest/storage/tagging_store/sender_tagging_store.js +48 -11
  47. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +1 -1
  48. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +1 -1
  49. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  50. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +6 -2
  51. package/package.json +17 -17
  52. package/src/contract_function_simulator/oracle/oracle_registry.ts +5 -0
  53. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +47 -14
  54. package/src/entrypoints/client/bundle/index.ts +1 -0
  55. package/src/entrypoints/client/bundle/utils.ts +15 -3
  56. package/src/entrypoints/client/lazy/index.ts +1 -0
  57. package/src/entrypoints/client/lazy/utils.ts +15 -3
  58. package/src/entrypoints/client/store.ts +38 -0
  59. package/src/entrypoints/server/index.ts +1 -0
  60. package/src/entrypoints/server/store.ts +47 -0
  61. package/src/entrypoints/server/utils.ts +21 -7
  62. package/src/logs/log_service.ts +4 -0
  63. package/src/notes/note_service.ts +1 -1
  64. package/src/oracle_version.ts +2 -2
  65. package/src/pxe.ts +8 -5
  66. package/src/storage/store_identity.ts +72 -0
  67. package/src/storage/tagging_store/sender_tagging_store.ts +62 -15
  68. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +1 -1
  69. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +6 -2
@@ -128,10 +128,11 @@ export class SenderTaggingStore implements StagedStore {
128
128
  }
129
129
 
130
130
  /**
131
- * Stores pending index ranges.
131
+ * Stores pending index ranges, rejecting any range that disagrees with an already-stored one.
132
132
  * @remarks If the same (secret, txHash) pair already exists in the db with an equal range, it's a no-op. This is
133
133
  * expected to happen because whenever we start sync we start from the last finalized index and we can have pending
134
- * ranges already stored from previous syncs. If the ranges differ, it throws an error as that indicates a bug.
134
+ * ranges already stored from previous syncs. If the ranges differ, it throws an error as that indicates a bug in
135
+ * callers that record indexes at prove time. Discovery from onchain logs must use `mergePendingIndexes` instead.
135
136
  * @param ranges - The tagging index ranges containing the directional app tagging secrets and the index ranges that are
136
137
  * to be stored in the db.
137
138
  * @param txHash - The tx in which the tagging indexes were used in private logs.
@@ -141,6 +142,33 @@ export class SenderTaggingStore implements StagedStore {
141
142
  * @throws If a different range already exists for the same (secret, txHash) pair.
142
143
  */
143
144
  storePendingIndexes(ranges: TaggingIndexRange[], txHash: TxHash, jobId: string): Promise<void> {
145
+ return this.#storePendingIndexes(ranges, txHash, jobId, false);
146
+ }
147
+
148
+ /**
149
+ * Stores pending index ranges, widening an existing entry for the same (secret, txHash) pair to the union of the
150
+ * stored and incoming ranges instead of throwing on a mismatch. Discovery from onchain logs needs this: it may see
151
+ * only the surviving (non-revertible phase) sub-range of a partially reverted tx recorded at prove time (the
152
+ * finalized receipt step of the sync resolves that difference), or indexes beyond a partially discovered entry
153
+ * when a tx from another PXE straddles a sync window boundary. Callers that record indexes at prove time must use
154
+ * `storePendingIndexes` instead, so that a range disagreement surfaces as a bug rather than being absorbed.
155
+ * @param ranges - The tagging index ranges containing the directional app tagging secrets and the index ranges that are
156
+ * to be stored in the db.
157
+ * @param txHash - The tx in which the tagging indexes were used in private logs.
158
+ * @param jobId - job context for staged writes to this store. See `JobCoordinator` for more details.
159
+ * @throws If the highestIndex is further than window length from the highest finalized index for the same secret.
160
+ * @throws If the lowestIndex is lower than or equal to the last finalized index for the same secret.
161
+ */
162
+ mergePendingIndexes(ranges: TaggingIndexRange[], txHash: TxHash, jobId: string): Promise<void> {
163
+ return this.#storePendingIndexes(ranges, txHash, jobId, true);
164
+ }
165
+
166
+ #storePendingIndexes(
167
+ ranges: TaggingIndexRange[],
168
+ txHash: TxHash,
169
+ jobId: string,
170
+ mergeExisting: boolean,
171
+ ): Promise<void> {
144
172
  if (ranges.length === 0) {
145
173
  return Promise.resolve();
146
174
  }
@@ -187,21 +215,40 @@ export class SenderTaggingStore implements StagedStore {
187
215
  // Check if an entry with the same txHash already exists
188
216
  const existingEntry = pendingData.find(entry => entry.txHash === txHashStr);
189
217
 
190
- if (existingEntry) {
191
- // Assert that the ranges are equal — different ranges for the same (secret, txHash) indicates a bug
192
- if (existingEntry.lowestIndex !== range.lowestIndex || existingEntry.highestIndex !== range.highestIndex) {
193
- throw new Error(
194
- `Conflicting range for secret ${secretStr} and txHash ${txHashStr}: ` +
195
- `existing [${existingEntry.lowestIndex}, ${existingEntry.highestIndex}] vs ` +
196
- `new [${range.lowestIndex}, ${range.highestIndex}]`,
197
- );
198
- }
199
- // Exact duplicate — skip
200
- } else {
201
- this.#writePendingIndexes(jobId, secretStr, [
218
+ let updatedPending: PendingIndexesEntry[] | undefined;
219
+ if (!existingEntry) {
220
+ updatedPending = [
202
221
  ...pendingData,
203
222
  { lowestIndex: range.lowestIndex, highestIndex: range.highestIndex, txHash: txHashStr },
204
- ]);
223
+ ];
224
+ } else if (mergeExisting) {
225
+ // Widen the entry to the union of both ranges, never shrink it: replacing would drop prove-time
226
+ // indexes the chain doesn't show (partially reverted tx), and skipping would drop onchain indexes
227
+ // discovered in a later sync window (tx straddling the window boundary).
228
+ const lowestIndex = Math.min(existingEntry.lowestIndex, range.lowestIndex);
229
+ const highestIndex = Math.max(existingEntry.highestIndex, range.highestIndex);
230
+ if (lowestIndex !== existingEntry.lowestIndex || highestIndex !== existingEntry.highestIndex) {
231
+ updatedPending = pendingData.map(entry =>
232
+ entry === existingEntry ? { lowestIndex, highestIndex, txHash: entry.txHash } : entry,
233
+ );
234
+ }
235
+ } else if (
236
+ existingEntry.lowestIndex !== range.lowestIndex ||
237
+ existingEntry.highestIndex !== range.highestIndex
238
+ ) {
239
+ // Different ranges for the same (secret, txHash) indicate a bug in callers that record indexes at prove
240
+ // time.
241
+ throw new Error(
242
+ `Conflicting range for secret ${secretStr} and txHash ${txHashStr}: ` +
243
+ `existing [${existingEntry.lowestIndex}, ${existingEntry.highestIndex}] vs ` +
244
+ `new [${range.lowestIndex}, ${range.highestIndex}]`,
245
+ );
246
+ }
247
+ // Remaining cases (a merge whose union equals the stored range, or an identical range without
248
+ // mergeExisting): duplicate evidence, nothing to write.
249
+
250
+ if (updatedPending) {
251
+ this.#writePendingIndexes(jobId, secretStr, updatedPending);
205
252
  }
206
253
  }
207
254
  });
@@ -74,7 +74,7 @@ export async function syncSenderTaggingIndexes(
74
74
  }
75
75
 
76
76
  // Receipts for pending tx hashes that the logs query just surfaced still need a sequential follow-up call.
77
- // `storePendingIndexes` is idempotent on (secret, txHash), so a re-discovered hash stays classified as known
77
+ // `mergePendingIndexes` is idempotent on (secret, txHash), so a re-discovered hash stays classified as known
78
78
  // and is not re-fetched here.
79
79
  const knownSet = new Set(knownPendingTxHashes.map(h => h.toString()));
80
80
  const newPendingTxHashes = allPendingTxHashes.filter(h => !knownSet.has(h.toString()));
@@ -36,11 +36,15 @@ export async function loadAndStoreNewTaggingIndexes(
36
36
  const txsForTags = await getTxsContainingTags(siloedTagsForWindow, aztecNode, anchorBlockHash);
37
37
  const txIndexesMap = getTxIndexesMap(txsForTags, start, siloedTagsForWindow.length);
38
38
 
39
- // Now we iterate over the map, construct the tagging index ranges and store them in the db.
39
+ // Now we iterate over the map, construct the tagging index ranges and store them in the db. A tx already tracked
40
+ // in the store is merged rather than range-checked: if this PXE sent the tx and it partially reverted, the chain
41
+ // only shows the surviving sub-range of the prove-time entry (the finalized receipt step of the sync owns
42
+ // resolving that difference), and a tx from another PXE may straddle a sync window boundary, in which case the
43
+ // entry is widened so the next index choice covers the full onchain range.
40
44
  for (const [txHashStr, indexes] of txIndexesMap.entries()) {
41
45
  const txHash = TxHash.fromString(txHashStr);
42
46
  const ranges = [{ extendedSecret, lowestIndex: Math.min(...indexes), highestIndex: Math.max(...indexes) }];
43
- await taggingStore.storePendingIndexes(ranges, txHash, jobId);
47
+ await taggingStore.mergePendingIndexes(ranges, txHash, jobId);
44
48
  }
45
49
  }
46
50