@aztec/pxe 0.0.1-commit.e6bd8901 → 0.0.1-commit.f146247c
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.
- package/dest/block_synchronizer/block_synchronizer.d.ts +3 -3
- package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
- package/dest/block_synchronizer/block_synchronizer.js +5 -5
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +2 -4
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +7 -9
- package/dest/contract_function_simulator/oracle/interfaces.d.ts +8 -8
- package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.d.ts +3 -3
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +15 -15
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +2 -3
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +5 -7
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +20 -16
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +23 -19
- package/dest/contract_sync/index.d.ts +1 -1
- package/dest/contract_sync/index.d.ts.map +1 -1
- package/dest/contract_sync/index.js +1 -3
- package/dest/debug/pxe_debug_utils.d.ts +16 -6
- package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
- package/dest/debug/pxe_debug_utils.js +17 -8
- package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
- package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/utils.js +12 -6
- package/dest/entrypoints/client/lazy/utils.d.ts +2 -2
- package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/utils.js +13 -7
- package/dest/entrypoints/pxe_creation_options.d.ts +3 -2
- package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
- package/dest/entrypoints/server/utils.d.ts +1 -1
- package/dest/entrypoints/server/utils.d.ts.map +1 -1
- package/dest/entrypoints/server/utils.js +19 -8
- package/dest/events/event_service.d.ts +4 -5
- package/dest/events/event_service.d.ts.map +1 -1
- package/dest/events/event_service.js +5 -6
- package/dest/job_coordinator/job_coordinator.d.ts +3 -2
- package/dest/job_coordinator/job_coordinator.d.ts.map +1 -1
- package/dest/job_coordinator/job_coordinator.js +3 -2
- package/dest/logs/log_service.d.ts +5 -4
- package/dest/logs/log_service.d.ts.map +1 -1
- package/dest/logs/log_service.js +8 -12
- package/dest/notes/note_service.d.ts +4 -5
- package/dest/notes/note_service.d.ts.map +1 -1
- package/dest/notes/note_service.js +6 -8
- package/dest/oracle_version.d.ts +3 -3
- package/dest/oracle_version.d.ts.map +1 -1
- package/dest/oracle_version.js +2 -2
- package/dest/private_kernel/private_kernel_execution_prover.d.ts +3 -2
- package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_execution_prover.js +2 -2
- package/dest/private_kernel/private_kernel_oracle.d.ts +3 -3
- package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
- package/dest/pxe.d.ts +1 -1
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +9 -8
- package/dest/storage/address_store/address_store.d.ts +1 -1
- package/dest/storage/address_store/address_store.d.ts.map +1 -1
- package/dest/storage/address_store/address_store.js +12 -11
- package/dest/storage/anchor_block_store/anchor_block_store.d.ts +9 -1
- package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -1
- package/dest/storage/anchor_block_store/anchor_block_store.js +8 -1
- package/dest/storage/capsule_store/capsule_store.js +6 -8
- package/dest/storage/contract_store/contract_store.d.ts +1 -1
- package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
- package/dest/storage/contract_store/contract_store.js +22 -13
- package/dest/storage/metadata.d.ts +1 -1
- package/dest/storage/metadata.js +1 -1
- package/dest/storage/note_store/note_store.d.ts +11 -1
- package/dest/storage/note_store/note_store.d.ts.map +1 -1
- package/dest/storage/note_store/note_store.js +143 -105
- package/dest/storage/private_event_store/private_event_store.d.ts +1 -1
- package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
- package/dest/storage/private_event_store/private_event_store.js +84 -61
- package/dest/storage/private_event_store/stored_private_event.d.ts +4 -4
- package/dest/storage/private_event_store/stored_private_event.d.ts.map +1 -1
- package/dest/storage/private_event_store/stored_private_event.js +2 -2
- package/dest/storage/tagging_store/recipient_tagging_store.d.ts +1 -1
- package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/recipient_tagging_store.js +31 -19
- package/dest/storage/tagging_store/sender_address_book_store.d.ts +1 -1
- package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/sender_address_book_store.js +20 -14
- package/dest/storage/tagging_store/sender_tagging_store.d.ts +1 -1
- package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/sender_tagging_store.js +183 -113
- package/dest/tagging/get_all_logs_by_tags.d.ts +4 -4
- package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -1
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +3 -3
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +3 -3
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +3 -3
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +3 -3
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
- package/package.json +16 -16
- package/src/block_synchronizer/block_synchronizer.ts +17 -19
- package/src/contract_function_simulator/contract_function_simulator.ts +6 -6
- package/src/contract_function_simulator/oracle/interfaces.ts +10 -10
- package/src/contract_function_simulator/oracle/oracle.ts +27 -17
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +2 -8
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +32 -26
- package/src/contract_sync/index.ts +1 -3
- package/src/debug/pxe_debug_utils.ts +23 -9
- package/src/entrypoints/client/bundle/utils.ts +7 -14
- package/src/entrypoints/client/lazy/utils.ts +8 -14
- package/src/entrypoints/pxe_creation_options.ts +2 -1
- package/src/entrypoints/server/utils.ts +15 -19
- package/src/events/event_service.ts +4 -6
- package/src/job_coordinator/job_coordinator.ts +4 -3
- package/src/logs/log_service.ts +12 -13
- package/src/notes/note_service.ts +5 -8
- package/src/oracle_version.ts +2 -2
- package/src/private_kernel/private_kernel_execution_prover.ts +6 -3
- package/src/private_kernel/private_kernel_oracle.ts +2 -2
- package/src/pxe.ts +16 -9
- package/src/storage/address_store/address_store.ts +15 -15
- package/src/storage/anchor_block_store/anchor_block_store.ts +8 -0
- package/src/storage/capsule_store/capsule_store.ts +8 -8
- package/src/storage/contract_store/contract_store.ts +22 -11
- package/src/storage/metadata.ts +1 -1
- package/src/storage/note_store/note_store.ts +159 -129
- package/src/storage/private_event_store/private_event_store.ts +102 -81
- package/src/storage/private_event_store/stored_private_event.ts +3 -3
- package/src/storage/tagging_store/recipient_tagging_store.ts +31 -21
- package/src/storage/tagging_store/sender_address_book_store.ts +20 -14
- package/src/storage/tagging_store/sender_tagging_store.ts +210 -126
- package/src/tagging/get_all_logs_by_tags.ts +3 -3
- package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +2 -2
- package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +2 -2
- package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +2 -2
- package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +3 -3
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { toArray } from '@aztec/foundation/iterable';
|
|
2
1
|
import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
|
|
3
2
|
import type { DirectionalAppTaggingSecret, PreTag } from '@aztec/stdlib/logs';
|
|
4
3
|
import { TxHash } from '@aztec/stdlib/tx';
|
|
@@ -70,31 +69,23 @@ export class SenderTaggingStore implements StagedStore {
|
|
|
70
69
|
}
|
|
71
70
|
|
|
72
71
|
async #readPendingIndexes(jobId: string, secret: string): Promise<{ index: number; txHash: string }[]> {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
return
|
|
72
|
+
// Always issue DB read to keep IndexedDB transaction alive (they auto-commit when a new micro-task starts and there
|
|
73
|
+
// are no pending read requests). The staged value still takes precedence if it exists.
|
|
74
|
+
const dbValue = await this.#pendingIndexes.getAsync(secret);
|
|
75
|
+
const staged = this.#getPendingIndexesForJob(jobId).get(secret);
|
|
76
|
+
return staged !== undefined ? staged : (dbValue ?? []);
|
|
78
77
|
}
|
|
79
78
|
|
|
80
79
|
#writePendingIndexes(jobId: string, secret: string, pendingIndexes: { index: number; txHash: string }[]) {
|
|
81
80
|
this.#getPendingIndexesForJob(jobId).set(secret, pendingIndexes);
|
|
82
81
|
}
|
|
83
82
|
|
|
84
|
-
/**
|
|
85
|
-
* Returns a job view of all the secrets that have a corresponding list of pending indexes either in persistent
|
|
86
|
-
* storage or the current job.
|
|
87
|
-
*/
|
|
88
|
-
async #readSecretsWithPendingIndexes(jobId: string): Promise<string[]> {
|
|
89
|
-
const storedSecrets = new Set(await toArray(this.#pendingIndexes.keysAsync()));
|
|
90
|
-
const stagedSecrets = this.#getPendingIndexesForJob(jobId).keys();
|
|
91
|
-
return [...storedSecrets.union(new Set(stagedSecrets))];
|
|
92
|
-
}
|
|
93
|
-
|
|
94
83
|
async #readLastFinalizedIndex(jobId: string, secret: string): Promise<number | undefined> {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
);
|
|
84
|
+
// Always issue DB read to keep IndexedDB transaction alive (they auto-commit when a new micro-task starts and there
|
|
85
|
+
// are no pending read requests). The staged value still takes precedence if it exists.
|
|
86
|
+
const dbValue = await this.#lastFinalizedIndexes.getAsync(secret);
|
|
87
|
+
const staged = this.#getLastFinalizedIndexesForJob(jobId).get(secret);
|
|
88
|
+
return staged ?? dbValue;
|
|
98
89
|
}
|
|
99
90
|
|
|
100
91
|
#writeLastFinalizedIndex(jobId: string, secret: string, lastFinalizedIndex: number) {
|
|
@@ -156,55 +147,80 @@ export class SenderTaggingStore implements StagedStore {
|
|
|
156
147
|
* This is enforced because this should never happen if the syncing is done correctly as we look for logs from higher
|
|
157
148
|
* indexes than finalized ones.
|
|
158
149
|
*/
|
|
159
|
-
|
|
150
|
+
storePendingIndexes(preTags: PreTag[], txHash: TxHash, jobId: string): Promise<void> {
|
|
151
|
+
if (preTags.length === 0) {
|
|
152
|
+
return Promise.resolve();
|
|
153
|
+
}
|
|
154
|
+
|
|
160
155
|
// The secrets in pre-tags should be unique because we always store just the highest index per given secret-txHash
|
|
161
156
|
// pair. Below we check that this is the case.
|
|
162
157
|
const secretsSet = new Set(preTags.map(preTag => preTag.secret.toString()));
|
|
163
158
|
if (secretsSet.size !== preTags.length) {
|
|
164
|
-
|
|
159
|
+
return Promise.reject(new Error(`Duplicate secrets found when storing pending indexes`));
|
|
165
160
|
}
|
|
166
161
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
const
|
|
162
|
+
const txHashStr = txHash.toString();
|
|
163
|
+
|
|
164
|
+
return this.#store.transactionAsync(async () => {
|
|
165
|
+
// Prefetch all data, start reads during iteration to keep IndexedDB transaction alive
|
|
166
|
+
const preTagReadPromises = preTags.map(({ secret, index }) => {
|
|
167
|
+
const secretStr = secret.toString();
|
|
168
|
+
return {
|
|
169
|
+
secret,
|
|
170
|
+
secretStr,
|
|
171
|
+
index,
|
|
172
|
+
pending: this.#readPendingIndexes(jobId, secretStr),
|
|
173
|
+
finalized: this.#readLastFinalizedIndex(jobId, secretStr),
|
|
174
|
+
};
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
// Await all reads together
|
|
178
|
+
const preTagData = await Promise.all(
|
|
179
|
+
preTagReadPromises.map(async item => ({
|
|
180
|
+
...item,
|
|
181
|
+
pendingData: await item.pending,
|
|
182
|
+
finalizedIndex: await item.finalized,
|
|
183
|
+
})),
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
// Process in memory and validate
|
|
187
|
+
for (const { secretStr, index, pendingData, finalizedIndex } of preTagData) {
|
|
188
|
+
// First we check that for any secret the highest used index in tx is not further than window length from
|
|
189
|
+
// the highest finalized index.
|
|
190
|
+
if (index > (finalizedIndex ?? 0) + UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN) {
|
|
191
|
+
throw new Error(
|
|
192
|
+
`Highest used index ${index} is further than window length from the highest finalized index ${finalizedIndex ?? 0}.
|
|
193
|
+
Tagging window length ${UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN} is configured too low. Contact the Aztec team
|
|
194
|
+
to increase it!`,
|
|
195
|
+
);
|
|
196
|
+
}
|
|
193
197
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
if (existingForSecretAndTx.index !== index) {
|
|
198
|
+
// Throw if the new pending index is lower than or equal to the last finalized index
|
|
199
|
+
if (finalizedIndex !== undefined && index <= finalizedIndex) {
|
|
197
200
|
throw new Error(
|
|
198
|
-
`Cannot store index ${index} for secret ${secretStr}
|
|
199
|
-
`
|
|
201
|
+
`Cannot store pending index ${index} for secret ${secretStr}: ` +
|
|
202
|
+
`it is lower than or equal to the last finalized index ${finalizedIndex}`,
|
|
200
203
|
);
|
|
201
204
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
205
|
+
|
|
206
|
+
// Check if this secret + txHash combination already exists
|
|
207
|
+
const existingForSecretAndTx = pendingData.find(entry => entry.txHash === txHashStr);
|
|
208
|
+
|
|
209
|
+
if (existingForSecretAndTx) {
|
|
210
|
+
// If it exists with a different index, throw an error
|
|
211
|
+
if (existingForSecretAndTx.index !== index) {
|
|
212
|
+
throw new Error(
|
|
213
|
+
`Cannot store index ${index} for secret ${secretStr} and txHash ${txHashStr}: ` +
|
|
214
|
+
`a different index ${existingForSecretAndTx.index} already exists for this secret-txHash pair`,
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
// If it exists with the same index, ignore the update (no-op)
|
|
218
|
+
} else {
|
|
219
|
+
// If it doesn't exist, add it
|
|
220
|
+
this.#writePendingIndexes(jobId, secretStr, [...pendingData, { index, txHash: txHashStr }]);
|
|
221
|
+
}
|
|
206
222
|
}
|
|
207
|
-
}
|
|
223
|
+
});
|
|
208
224
|
}
|
|
209
225
|
|
|
210
226
|
/**
|
|
@@ -216,17 +232,19 @@ export class SenderTaggingStore implements StagedStore {
|
|
|
216
232
|
* @returns An array of unique transaction hashes for pending transactions that contain indexes in the range
|
|
217
233
|
* [startIndex, endIndex). Returns an empty array if no pending indexes exist in the range.
|
|
218
234
|
*/
|
|
219
|
-
|
|
235
|
+
getTxHashesOfPendingIndexes(
|
|
220
236
|
secret: DirectionalAppTaggingSecret,
|
|
221
237
|
startIndex: number,
|
|
222
238
|
endIndex: number,
|
|
223
239
|
jobId: string,
|
|
224
240
|
): Promise<TxHash[]> {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
241
|
+
return this.#store.transactionAsync(async () => {
|
|
242
|
+
const existing = await this.#readPendingIndexes(jobId, secret.toString());
|
|
243
|
+
const txHashes = existing
|
|
244
|
+
.filter(entry => entry.index >= startIndex && entry.index < endIndex)
|
|
245
|
+
.map(entry => entry.txHash);
|
|
246
|
+
return Array.from(new Set(txHashes)).map(TxHash.fromString);
|
|
247
|
+
});
|
|
230
248
|
}
|
|
231
249
|
|
|
232
250
|
/**
|
|
@@ -235,7 +253,7 @@ export class SenderTaggingStore implements StagedStore {
|
|
|
235
253
|
* @returns The last (highest) finalized index for the given secret.
|
|
236
254
|
*/
|
|
237
255
|
getLastFinalizedIndex(secret: DirectionalAppTaggingSecret, jobId: string): Promise<number | undefined> {
|
|
238
|
-
return this.#readLastFinalizedIndex(jobId, secret.toString());
|
|
256
|
+
return this.#store.transactionAsync(() => this.#readLastFinalizedIndex(jobId, secret.toString()));
|
|
239
257
|
}
|
|
240
258
|
|
|
241
259
|
/**
|
|
@@ -244,102 +262,168 @@ export class SenderTaggingStore implements StagedStore {
|
|
|
244
262
|
* @param secret - The directional app tagging secret to query the last used index for.
|
|
245
263
|
* @returns The last used index.
|
|
246
264
|
*/
|
|
247
|
-
|
|
265
|
+
getLastUsedIndex(secret: DirectionalAppTaggingSecret, jobId: string): Promise<number | undefined> {
|
|
248
266
|
const secretStr = secret.toString();
|
|
249
|
-
const pendingTxScopedIndexes = await this.#readPendingIndexes(jobId, secretStr);
|
|
250
|
-
const pendingIndexes = pendingTxScopedIndexes.map(entry => entry.index);
|
|
251
267
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
268
|
+
return this.#store.transactionAsync(async () => {
|
|
269
|
+
const pendingPromise = this.#readPendingIndexes(jobId, secretStr);
|
|
270
|
+
const finalizedPromise = this.#readLastFinalizedIndex(jobId, secretStr);
|
|
271
|
+
|
|
272
|
+
const [pendingTxScopedIndexes, lastFinalized] = await Promise.all([pendingPromise, finalizedPromise]);
|
|
273
|
+
const pendingIndexes = pendingTxScopedIndexes.map(entry => entry.index);
|
|
274
|
+
|
|
275
|
+
if (pendingTxScopedIndexes.length === 0) {
|
|
276
|
+
return lastFinalized;
|
|
277
|
+
}
|
|
255
278
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
279
|
+
// As the last used index we return the highest one from the pending indexes. Note that this value will be always
|
|
280
|
+
// higher than the last finalized index because we prune lower pending indexes when a tx is finalized.
|
|
281
|
+
return Math.max(...pendingIndexes);
|
|
282
|
+
});
|
|
259
283
|
}
|
|
260
284
|
|
|
261
285
|
/**
|
|
262
286
|
* Drops all pending indexes corresponding to the given transaction hashes.
|
|
263
287
|
*/
|
|
264
|
-
|
|
288
|
+
dropPendingIndexes(txHashes: TxHash[], jobId: string): Promise<void> {
|
|
265
289
|
if (txHashes.length === 0) {
|
|
266
|
-
return;
|
|
290
|
+
return Promise.resolve();
|
|
267
291
|
}
|
|
268
292
|
|
|
269
293
|
const txHashStrings = new Set<string>(txHashes.map(txHash => txHash.toString()));
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
const
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
294
|
+
|
|
295
|
+
return this.#store.transactionAsync(async () => {
|
|
296
|
+
// Prefetch all data, start reads during iteration to keep IndexedDB transaction alive
|
|
297
|
+
const secretReadPromises: Map<string, Promise<{ index: number; txHash: string }[]>> = new Map();
|
|
298
|
+
|
|
299
|
+
for await (const secret of this.#pendingIndexes.keysAsync()) {
|
|
300
|
+
secretReadPromises.set(secret, this.#readPendingIndexes(jobId, secret));
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// Add staged-only secrets (sync, no DB)
|
|
304
|
+
for (const secret of this.#getPendingIndexesForJob(jobId).keys()) {
|
|
305
|
+
if (!secretReadPromises.has(secret)) {
|
|
306
|
+
secretReadPromises.set(secret, Promise.resolve(this.#getPendingIndexesForJob(jobId).get(secret) ?? []));
|
|
281
307
|
}
|
|
282
|
-
// else: No items were filtered out (txHashes not found for this secret) --> no-op
|
|
283
308
|
}
|
|
284
|
-
|
|
309
|
+
|
|
310
|
+
// Await all reads together
|
|
311
|
+
const secrets = [...secretReadPromises.keys()];
|
|
312
|
+
const pendingDataResults = await Promise.all(secretReadPromises.values());
|
|
313
|
+
|
|
314
|
+
// Process in memory
|
|
315
|
+
for (let i = 0; i < secrets.length; i++) {
|
|
316
|
+
const secret = secrets[i];
|
|
317
|
+
const pendingData = pendingDataResults[i];
|
|
318
|
+
|
|
319
|
+
if (pendingData && pendingData.length > 0) {
|
|
320
|
+
const filtered = pendingData.filter(item => !txHashStrings.has(item.txHash));
|
|
321
|
+
if (filtered.length === 0) {
|
|
322
|
+
this.#writePendingIndexes(jobId, secret, []);
|
|
323
|
+
} else if (filtered.length !== pendingData.length) {
|
|
324
|
+
// Some items were filtered out, so update the pending data
|
|
325
|
+
this.#writePendingIndexes(jobId, secret, filtered);
|
|
326
|
+
}
|
|
327
|
+
// else: No items were filtered out (txHashes not found for this secret) --> no-op
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
});
|
|
285
331
|
}
|
|
286
332
|
|
|
287
333
|
/**
|
|
288
334
|
* Updates pending indexes corresponding to the given transaction hashes to be finalized and prunes any lower pending
|
|
289
335
|
* indexes.
|
|
290
336
|
*/
|
|
291
|
-
|
|
337
|
+
finalizePendingIndexes(txHashes: TxHash[], jobId: string): Promise<void> {
|
|
292
338
|
if (txHashes.length === 0) {
|
|
293
|
-
return;
|
|
339
|
+
return Promise.resolve();
|
|
294
340
|
}
|
|
295
341
|
|
|
296
|
-
|
|
297
|
-
const txHashStr = txHash.toString();
|
|
342
|
+
const txHashStrings = new Set(txHashes.map(tx => tx.toString()));
|
|
298
343
|
|
|
299
|
-
|
|
344
|
+
return this.#store.transactionAsync(async () => {
|
|
345
|
+
// Prefetch all data, start reads during iteration to keep IndexedDB transaction alive
|
|
346
|
+
const secretDataPromises: Map<
|
|
347
|
+
string,
|
|
348
|
+
{ pending: Promise<{ index: number; txHash: string }[]>; finalized: Promise<number | undefined> }
|
|
349
|
+
> = new Map();
|
|
300
350
|
|
|
301
|
-
for (const secret of
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
351
|
+
for await (const secret of this.#pendingIndexes.keysAsync()) {
|
|
352
|
+
secretDataPromises.set(secret, {
|
|
353
|
+
pending: this.#readPendingIndexes(jobId, secret),
|
|
354
|
+
finalized: this.#readLastFinalizedIndex(jobId, secret),
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// Add staged-only secrets (sync, no DB)
|
|
359
|
+
for (const secret of this.#getPendingIndexesForJob(jobId).keys()) {
|
|
360
|
+
if (!secretDataPromises.has(secret)) {
|
|
361
|
+
secretDataPromises.set(secret, {
|
|
362
|
+
pending: Promise.resolve(this.#getPendingIndexesForJob(jobId).get(secret) ?? []),
|
|
363
|
+
finalized: Promise.resolve(this.#getLastFinalizedIndexesForJob(jobId).get(secret)),
|
|
364
|
+
});
|
|
305
365
|
}
|
|
366
|
+
}
|
|
306
367
|
|
|
307
|
-
|
|
308
|
-
|
|
368
|
+
// Await all reads together
|
|
369
|
+
const secrets = [...secretDataPromises.keys()];
|
|
370
|
+
const dataResults = await Promise.all(
|
|
371
|
+
secrets.map(async secret => ({
|
|
372
|
+
secret,
|
|
373
|
+
pendingData: await secretDataPromises.get(secret)!.pending,
|
|
374
|
+
lastFinalized: await secretDataPromises.get(secret)!.finalized,
|
|
375
|
+
})),
|
|
376
|
+
);
|
|
377
|
+
|
|
378
|
+
// Process all txHashes for each secret in memory
|
|
379
|
+
for (const { secret, pendingData, lastFinalized } of dataResults) {
|
|
380
|
+
if (!pendingData || pendingData.length === 0) {
|
|
309
381
|
continue;
|
|
310
382
|
}
|
|
311
383
|
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
384
|
+
let currentPending = pendingData;
|
|
385
|
+
let currentFinalized = lastFinalized;
|
|
386
|
+
|
|
387
|
+
// Process all txHashes for this secret
|
|
388
|
+
for (const txHashStr of txHashStrings) {
|
|
389
|
+
const matchingIndexes = currentPending.filter(item => item.txHash === txHashStr).map(item => item.index);
|
|
390
|
+
if (matchingIndexes.length === 0) {
|
|
391
|
+
continue;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
if (matchingIndexes.length > 1) {
|
|
395
|
+
// We should always just store the highest pending index for a given tx hash and secret because the lower
|
|
396
|
+
// values are irrelevant.
|
|
397
|
+
throw new Error(`Multiple pending indexes found for tx hash ${txHashStr} and secret ${secret}`);
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
const newFinalized = matchingIndexes[0];
|
|
401
|
+
|
|
402
|
+
if (newFinalized < (currentFinalized ?? 0)) {
|
|
403
|
+
// This should never happen because when last finalized index was finalized we should have pruned the lower
|
|
404
|
+
// pending indexes.
|
|
405
|
+
throw new Error(
|
|
406
|
+
`New finalized index ${newFinalized} is smaller than the current last finalized index ${currentFinalized}`,
|
|
407
|
+
);
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
currentFinalized = newFinalized;
|
|
411
|
+
|
|
412
|
+
// When we add pending indexes, we ensure they are higher than the last finalized index. However, because we
|
|
413
|
+
// cannot control the order in which transactions are finalized, there may be pending indexes that are now
|
|
414
|
+
// obsolete because they are lower than the most recently finalized index. For this reason, we prune these
|
|
415
|
+
// outdated pending indexes.
|
|
416
|
+
currentPending = currentPending.filter(item => item.index > currentFinalized!);
|
|
316
417
|
}
|
|
317
418
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
if (newFinalized < (lastFinalized ?? 0)) {
|
|
322
|
-
// This should never happen because when last finalized index was finalized we should have pruned the lower
|
|
323
|
-
// pending indexes.
|
|
324
|
-
throw new Error(
|
|
325
|
-
`New finalized index ${newFinalized} is smaller than the current last finalized index ${lastFinalized}`,
|
|
326
|
-
);
|
|
419
|
+
// Write final state if changed
|
|
420
|
+
if (currentFinalized !== lastFinalized) {
|
|
421
|
+
this.#writeLastFinalizedIndex(jobId, secret, currentFinalized!);
|
|
327
422
|
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
lastFinalized = newFinalized;
|
|
331
|
-
|
|
332
|
-
// When we add pending indexes, we ensure they are higher than the last finalized index. However, because we
|
|
333
|
-
// cannot control the order in which transactions are finalized, there may be pending indexes that are now
|
|
334
|
-
// obsolete because they are lower than the most recently finalized index. For this reason, we prune these
|
|
335
|
-
// outdated pending indexes.
|
|
336
|
-
const remainingItemsOfHigherIndex = pendingData.filter(item => item.index > (lastFinalized ?? 0));
|
|
337
|
-
if (remainingItemsOfHigherIndex.length === 0) {
|
|
338
|
-
this.#writePendingIndexes(jobId, secret, []);
|
|
339
|
-
} else {
|
|
340
|
-
this.#writePendingIndexes(jobId, secret, remainingItemsOfHigherIndex);
|
|
423
|
+
if (currentPending !== pendingData) {
|
|
424
|
+
this.#writePendingIndexes(jobId, secret, currentPending);
|
|
341
425
|
}
|
|
342
426
|
}
|
|
343
|
-
}
|
|
427
|
+
});
|
|
344
428
|
}
|
|
345
429
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
2
|
-
import type {
|
|
2
|
+
import type { BlockHash } from '@aztec/stdlib/block';
|
|
3
3
|
import { MAX_LOGS_PER_TAG } from '@aztec/stdlib/interfaces/api-limit';
|
|
4
4
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
5
5
|
import type { SiloedTag, Tag, TxScopedL2Log } from '@aztec/stdlib/logs';
|
|
@@ -42,7 +42,7 @@ async function getAllPages<T>(numTags: number, fetchPage: (page: number) => Prom
|
|
|
42
42
|
export function getAllPrivateLogsByTags(
|
|
43
43
|
aztecNode: AztecNode,
|
|
44
44
|
tags: SiloedTag[],
|
|
45
|
-
anchorBlockHash:
|
|
45
|
+
anchorBlockHash: BlockHash,
|
|
46
46
|
): Promise<TxScopedL2Log[][]> {
|
|
47
47
|
return getAllPages(tags.length, page => aztecNode.getPrivateLogsByTags(tags, page, anchorBlockHash));
|
|
48
48
|
}
|
|
@@ -60,7 +60,7 @@ export function getAllPublicLogsByTagsFromContract(
|
|
|
60
60
|
aztecNode: AztecNode,
|
|
61
61
|
contractAddress: AztecAddress,
|
|
62
62
|
tags: Tag[],
|
|
63
|
-
anchorBlockHash:
|
|
63
|
+
anchorBlockHash: BlockHash,
|
|
64
64
|
): Promise<TxScopedL2Log[][]> {
|
|
65
65
|
return getAllPages(tags.length, page =>
|
|
66
66
|
aztecNode.getPublicLogsByTagsFromContract(contractAddress, tags, page, anchorBlockHash),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
2
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
3
|
-
import type {
|
|
3
|
+
import type { BlockHash } from '@aztec/stdlib/block';
|
|
4
4
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
5
5
|
import type { DirectionalAppTaggingSecret, TxScopedL2Log } from '@aztec/stdlib/logs';
|
|
6
6
|
|
|
@@ -22,7 +22,7 @@ export async function loadPrivateLogsForSenderRecipientPair(
|
|
|
22
22
|
aztecNode: AztecNode,
|
|
23
23
|
taggingStore: RecipientTaggingStore,
|
|
24
24
|
anchorBlockNumber: BlockNumber,
|
|
25
|
-
anchorBlockHash:
|
|
25
|
+
anchorBlockHash: BlockHash,
|
|
26
26
|
jobId: string,
|
|
27
27
|
): Promise<TxScopedL2Log[]> {
|
|
28
28
|
// # Explanation of how the algorithm works
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
2
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
3
|
-
import type {
|
|
3
|
+
import type { BlockHash } from '@aztec/stdlib/block';
|
|
4
4
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
5
5
|
import type { DirectionalAppTaggingSecret, PreTag, TxScopedL2Log } from '@aztec/stdlib/logs';
|
|
6
6
|
import { SiloedTag, Tag } from '@aztec/stdlib/logs';
|
|
@@ -19,7 +19,7 @@ export async function loadLogsForRange(
|
|
|
19
19
|
start: number,
|
|
20
20
|
end: number,
|
|
21
21
|
anchorBlockNumber: BlockNumber,
|
|
22
|
-
anchorBlockHash:
|
|
22
|
+
anchorBlockHash: BlockHash,
|
|
23
23
|
): Promise<Array<{ log: TxScopedL2Log; taggingIndex: number }>> {
|
|
24
24
|
// Derive tags for the window
|
|
25
25
|
const preTags: PreTag[] = Array(end - start)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
2
|
-
import type {
|
|
2
|
+
import type { BlockHash } from '@aztec/stdlib/block';
|
|
3
3
|
import type { AztecNode } from '@aztec/stdlib/interfaces/server';
|
|
4
4
|
import type { DirectionalAppTaggingSecret } from '@aztec/stdlib/logs';
|
|
5
5
|
|
|
@@ -27,7 +27,7 @@ export async function syncSenderTaggingIndexes(
|
|
|
27
27
|
app: AztecAddress,
|
|
28
28
|
aztecNode: AztecNode,
|
|
29
29
|
taggingStore: SenderTaggingStore,
|
|
30
|
-
anchorBlockHash:
|
|
30
|
+
anchorBlockHash: BlockHash,
|
|
31
31
|
jobId: string,
|
|
32
32
|
): Promise<void> {
|
|
33
33
|
// # Explanation of how syncing works
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
2
|
-
import type {
|
|
2
|
+
import type { BlockHash } from '@aztec/stdlib/block';
|
|
3
3
|
import type { AztecNode } from '@aztec/stdlib/interfaces/server';
|
|
4
4
|
import type { DirectionalAppTaggingSecret, PreTag } from '@aztec/stdlib/logs';
|
|
5
5
|
import { SiloedTag, Tag } from '@aztec/stdlib/logs';
|
|
@@ -29,7 +29,7 @@ export async function loadAndStoreNewTaggingIndexes(
|
|
|
29
29
|
end: number,
|
|
30
30
|
aztecNode: AztecNode,
|
|
31
31
|
taggingStore: SenderTaggingStore,
|
|
32
|
-
anchorBlockHash:
|
|
32
|
+
anchorBlockHash: BlockHash,
|
|
33
33
|
jobId: string,
|
|
34
34
|
) {
|
|
35
35
|
// We compute the tags for the current window of indexes
|
|
@@ -55,7 +55,7 @@ export async function loadAndStoreNewTaggingIndexes(
|
|
|
55
55
|
async function getTxsContainingTags(
|
|
56
56
|
tags: SiloedTag[],
|
|
57
57
|
aztecNode: AztecNode,
|
|
58
|
-
anchorBlockHash:
|
|
58
|
+
anchorBlockHash: BlockHash,
|
|
59
59
|
): Promise<TxHash[][]> {
|
|
60
60
|
// We use the utility function below to retrieve all logs for the tags across all pages, so we don't need to handle
|
|
61
61
|
// pagination here.
|