@aztec/pxe 0.0.1-commit.f2ce05ee → 0.0.1-commit.f5d02921e
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/access_scopes.d.ts +9 -0
- package/dest/access_scopes.d.ts.map +1 -0
- package/dest/access_scopes.js +6 -0
- package/dest/block_synchronizer/block_synchronizer.d.ts +1 -1
- package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
- package/dest/block_synchronizer/block_synchronizer.js +6 -0
- package/dest/config/index.d.ts +2 -2
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +1 -1
- package/dest/config/package_info.js +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +60 -30
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +199 -72
- package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +7 -7
- package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -1
- package/dest/contract_function_simulator/execution_tagging_index_cache.js +19 -11
- package/dest/contract_function_simulator/index.d.ts +2 -1
- package/dest/contract_function_simulator/index.d.ts.map +1 -1
- package/dest/contract_function_simulator/index.js +1 -0
- package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +3 -5
- package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/event_validation_request.js +7 -9
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +1 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +1 -3
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +3 -6
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/note_validation_request.js +5 -10
- package/dest/contract_function_simulator/oracle/interfaces.d.ts +50 -45
- package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts +9 -0
- package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.js +38 -0
- package/dest/contract_function_simulator/oracle/oracle.d.ts +64 -44
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +187 -97
- package/dest/contract_function_simulator/oracle/private_execution.js +5 -3
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +54 -80
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +98 -85
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +90 -52
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +213 -116
- package/dest/contract_logging.d.ts +27 -0
- package/dest/contract_logging.d.ts.map +1 -0
- package/dest/contract_logging.js +38 -0
- package/dest/contract_sync/contract_sync_service.d.ts +10 -5
- package/dest/contract_sync/contract_sync_service.d.ts.map +1 -1
- package/dest/contract_sync/contract_sync_service.js +72 -30
- package/dest/contract_sync/helpers.d.ts +3 -2
- package/dest/contract_sync/helpers.d.ts.map +1 -1
- package/dest/contract_sync/helpers.js +9 -4
- package/dest/debug/pxe_debug_utils.d.ts +5 -4
- package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
- package/dest/debug/pxe_debug_utils.js +4 -4
- package/dest/entrypoints/client/bundle/index.d.ts +4 -1
- package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/index.js +3 -0
- 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 +9 -1
- package/dest/entrypoints/client/lazy/index.d.ts +4 -1
- package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/index.js +3 -0
- package/dest/entrypoints/client/lazy/utils.d.ts +1 -1
- package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/utils.js +9 -1
- package/dest/entrypoints/server/index.d.ts +3 -1
- package/dest/entrypoints/server/index.d.ts.map +1 -1
- package/dest/entrypoints/server/index.js +2 -0
- package/dest/entrypoints/server/utils.js +9 -1
- package/dest/events/event_service.d.ts +3 -2
- package/dest/events/event_service.d.ts.map +1 -1
- package/dest/events/event_service.js +16 -4
- package/dest/logs/log_service.d.ts +6 -6
- package/dest/logs/log_service.d.ts.map +1 -1
- package/dest/logs/log_service.js +31 -40
- package/dest/messages/message_context_service.d.ts +17 -0
- package/dest/messages/message_context_service.d.ts.map +1 -0
- package/dest/messages/message_context_service.js +36 -0
- package/dest/notes/note_service.d.ts +5 -4
- package/dest/notes/note_service.d.ts.map +1 -1
- package/dest/notes/note_service.js +17 -7
- package/dest/notes_filter.d.ts +25 -0
- package/dest/notes_filter.d.ts.map +1 -0
- package/dest/notes_filter.js +4 -0
- package/dest/oracle_version.d.ts +2 -2
- package/dest/oracle_version.js +3 -3
- package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts +4 -0
- package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts.map +1 -0
- package/dest/private_kernel/hints/{compute_tx_include_by_timestamp.js → compute_tx_expiration_timestamp.js} +12 -12
- package/dest/private_kernel/hints/index.d.ts +1 -1
- package/dest/private_kernel/hints/index.js +1 -1
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +4 -3
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -1
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.js +129 -68
- package/dest/private_kernel/hints/test_utils.d.ts +122 -0
- package/dest/private_kernel/hints/test_utils.d.ts.map +1 -0
- package/dest/private_kernel/hints/test_utils.js +203 -0
- package/dest/private_kernel/private_kernel_execution_prover.d.ts +1 -1
- package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_execution_prover.js +19 -11
- package/dest/private_kernel/private_kernel_oracle.d.ts +6 -2
- package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_oracle.js +7 -3
- package/dest/pxe.d.ts +63 -24
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +105 -74
- package/dest/storage/capsule_store/capsule_service.d.ts +22 -0
- package/dest/storage/capsule_store/capsule_service.d.ts.map +1 -0
- package/dest/storage/capsule_store/capsule_service.js +50 -0
- package/dest/storage/capsule_store/capsule_store.d.ts +9 -9
- package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
- package/dest/storage/capsule_store/capsule_store.js +33 -28
- package/dest/storage/capsule_store/index.d.ts +2 -1
- package/dest/storage/capsule_store/index.d.ts.map +1 -1
- package/dest/storage/capsule_store/index.js +1 -0
- package/dest/storage/contract_store/contract_store.d.ts +42 -15
- package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
- package/dest/storage/contract_store/contract_store.js +140 -64
- package/dest/storage/metadata.d.ts +1 -1
- package/dest/storage/metadata.js +1 -1
- package/dest/storage/note_store/note_store.d.ts +3 -3
- package/dest/storage/note_store/note_store.d.ts.map +1 -1
- package/dest/storage/note_store/note_store.js +3 -4
- package/dest/storage/tagging_store/recipient_tagging_store.d.ts +6 -6
- package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/sender_tagging_store.d.ts +29 -28
- package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/sender_tagging_store.js +141 -115
- package/dest/tagging/get_all_logs_by_tags.d.ts +1 -1
- package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -1
- package/dest/tagging/get_all_logs_by_tags.js +17 -3
- package/dest/tagging/index.d.ts +3 -3
- package/dest/tagging/index.d.ts.map +1 -1
- package/dest/tagging/index.js +1 -1
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +4 -5
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +7 -7
- package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +2 -2
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +6 -7
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +12 -11
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +4 -8
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +13 -7
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +4 -3
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +20 -10
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +5 -7
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +36 -24
- package/package.json +16 -16
- package/src/access_scopes.ts +9 -0
- package/src/block_synchronizer/block_synchronizer.ts +6 -0
- package/src/config/index.ts +1 -1
- package/src/config/package_info.ts +1 -1
- package/src/contract_function_simulator/contract_function_simulator.ts +358 -133
- package/src/contract_function_simulator/execution_tagging_index_cache.ts +19 -14
- package/src/contract_function_simulator/index.ts +1 -0
- package/src/contract_function_simulator/noir-structs/event_validation_request.ts +8 -8
- package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +1 -4
- package/src/contract_function_simulator/noir-structs/note_validation_request.ts +3 -9
- package/src/contract_function_simulator/oracle/interfaces.ts +63 -54
- package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +98 -0
- package/src/contract_function_simulator/oracle/oracle.ts +223 -139
- package/src/contract_function_simulator/oracle/private_execution.ts +4 -4
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +122 -177
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +375 -131
- package/src/contract_logging.ts +52 -0
- package/src/contract_sync/contract_sync_service.ts +108 -45
- package/src/contract_sync/helpers.ts +9 -3
- package/src/debug/pxe_debug_utils.ts +11 -9
- package/src/entrypoints/client/bundle/index.ts +3 -0
- package/src/entrypoints/client/bundle/utils.ts +9 -1
- package/src/entrypoints/client/lazy/index.ts +3 -0
- package/src/entrypoints/client/lazy/utils.ts +9 -1
- package/src/entrypoints/server/index.ts +2 -0
- package/src/entrypoints/server/utils.ts +7 -7
- package/src/events/event_service.ts +17 -4
- package/src/logs/log_service.ts +61 -63
- package/src/messages/message_context_service.ts +44 -0
- package/src/notes/note_service.ts +20 -8
- package/src/notes_filter.ts +26 -0
- package/src/oracle_version.ts +3 -3
- package/src/private_kernel/hints/{compute_tx_include_by_timestamp.ts → compute_tx_expiration_timestamp.ts} +13 -13
- package/src/private_kernel/hints/index.ts +1 -1
- package/src/private_kernel/hints/private_kernel_reset_private_inputs_builder.ts +164 -117
- package/src/private_kernel/hints/test_utils.ts +325 -0
- package/src/private_kernel/private_kernel_execution_prover.ts +19 -12
- package/src/private_kernel/private_kernel_oracle.ts +7 -7
- package/src/pxe.ts +190 -117
- package/src/storage/capsule_store/capsule_service.ts +91 -0
- package/src/storage/capsule_store/capsule_store.ts +34 -26
- package/src/storage/capsule_store/index.ts +1 -0
- package/src/storage/contract_store/contract_store.ts +170 -71
- package/src/storage/metadata.ts +1 -1
- package/src/storage/note_store/note_store.ts +8 -5
- package/src/storage/tagging_store/recipient_tagging_store.ts +9 -5
- package/src/storage/tagging_store/sender_tagging_store.ts +185 -138
- package/src/tagging/get_all_logs_by_tags.ts +28 -4
- package/src/tagging/index.ts +2 -2
- package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +7 -10
- package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +2 -2
- package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +10 -15
- package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +23 -10
- package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +26 -11
- package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +27 -26
- package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +0 -4
- package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +0 -1
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
|
|
2
|
-
import
|
|
3
|
-
import { TxHash } from '@aztec/stdlib/tx';
|
|
2
|
+
import { ExtendedDirectionalAppTaggingSecret, SiloedTag, type TaggingIndexRange } from '@aztec/stdlib/logs';
|
|
3
|
+
import { TxEffect, TxHash } from '@aztec/stdlib/tx';
|
|
4
4
|
|
|
5
5
|
import type { StagedStore } from '../../job_coordinator/job_coordinator.js';
|
|
6
6
|
import { UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN } from '../../tagging/constants.js';
|
|
7
7
|
|
|
8
|
+
/** Internal representation of a pending index range entry. */
|
|
9
|
+
type PendingIndexesEntry = { lowestIndex: number; highestIndex: number; txHash: string };
|
|
10
|
+
|
|
8
11
|
/**
|
|
9
12
|
* Data provider of tagging data used when syncing the sender tagging indexes. The recipient counterpart of this class
|
|
10
13
|
* is called RecipientTaggingStore. We have the data stores separate for sender and recipient because
|
|
@@ -15,20 +18,19 @@ export class SenderTaggingStore implements StagedStore {
|
|
|
15
18
|
|
|
16
19
|
#store: AztecAsyncKVStore;
|
|
17
20
|
|
|
18
|
-
// Stores the pending
|
|
19
|
-
// the private logs with tags corresponding to these indexes has not been finalized yet.
|
|
20
|
-
//
|
|
21
|
-
// We don't store just the highest index because if their transaction is dropped we'd then need the information about
|
|
22
|
-
// the lower pending indexes. For each secret-tx pair however we only store the largest index used in that tx, since
|
|
23
|
-
// the smaller ones are irrelevant due to tx atomicity.
|
|
21
|
+
// Stores the pending index ranges for each directional app tagging secret. Pending here means that the tx that
|
|
22
|
+
// contained the private logs with tags corresponding to these indexes has not been finalized yet.
|
|
24
23
|
//
|
|
25
|
-
//
|
|
24
|
+
// We store the full range (lowestIndex, highestIndex) for each secret-tx pair because transactions can partially
|
|
25
|
+
// revert, in which case only some logs (from the non-revertible phase) survive onchain. By storing the range,
|
|
26
|
+
// we can expand it and check each individual siloed tag against the TxEffect to determine which indexes made it
|
|
27
|
+
// onchain.
|
|
26
28
|
//
|
|
27
|
-
// directional app tagging secret => {
|
|
28
|
-
#pendingIndexes: AztecAsyncMap<string,
|
|
29
|
+
// directional app tagging secret => { lowestIndex, highestIndex, txHash }[]
|
|
30
|
+
#pendingIndexes: AztecAsyncMap<string, PendingIndexesEntry[]>;
|
|
29
31
|
|
|
30
|
-
// jobId => directional app tagging secret => {
|
|
31
|
-
#pendingIndexesForJob: Map<string, Map<string,
|
|
32
|
+
// jobId => directional app tagging secret => { lowestIndex, highestIndex, txHash }[]
|
|
33
|
+
#pendingIndexesForJob: Map<string, Map<string, PendingIndexesEntry[]>>;
|
|
32
34
|
|
|
33
35
|
// Stores the last (highest) finalized index for each directional app tagging secret. We care only about the last
|
|
34
36
|
// index because unlike the pending indexes, it will never happen that a finalized index would be removed and hence
|
|
@@ -50,7 +52,7 @@ export class SenderTaggingStore implements StagedStore {
|
|
|
50
52
|
this.#lastFinalizedIndexesForJob = new Map();
|
|
51
53
|
}
|
|
52
54
|
|
|
53
|
-
#getPendingIndexesForJob(jobId: string): Map<string,
|
|
55
|
+
#getPendingIndexesForJob(jobId: string): Map<string, PendingIndexesEntry[]> {
|
|
54
56
|
let pendingIndexesForJob = this.#pendingIndexesForJob.get(jobId);
|
|
55
57
|
if (!pendingIndexesForJob) {
|
|
56
58
|
pendingIndexesForJob = new Map();
|
|
@@ -68,7 +70,7 @@ export class SenderTaggingStore implements StagedStore {
|
|
|
68
70
|
return jobStagedLastFinalizedIndexes;
|
|
69
71
|
}
|
|
70
72
|
|
|
71
|
-
async #readPendingIndexes(jobId: string, secret: string): Promise<
|
|
73
|
+
async #readPendingIndexes(jobId: string, secret: string): Promise<PendingIndexesEntry[]> {
|
|
72
74
|
// Always issue DB read to keep IndexedDB transaction alive (they auto-commit when a new micro-task starts and there
|
|
73
75
|
// are no pending read requests). The staged value still takes precedence if it exists.
|
|
74
76
|
const dbValue = await this.#pendingIndexes.getAsync(secret);
|
|
@@ -76,7 +78,7 @@ export class SenderTaggingStore implements StagedStore {
|
|
|
76
78
|
return staged !== undefined ? staged : (dbValue ?? []);
|
|
77
79
|
}
|
|
78
80
|
|
|
79
|
-
#writePendingIndexes(jobId: string, secret: string, pendingIndexes:
|
|
81
|
+
#writePendingIndexes(jobId: string, secret: string, pendingIndexes: PendingIndexesEntry[]) {
|
|
80
82
|
this.#getPendingIndexesForJob(jobId).set(secret, pendingIndexes);
|
|
81
83
|
}
|
|
82
84
|
|
|
@@ -126,57 +128,37 @@ export class SenderTaggingStore implements StagedStore {
|
|
|
126
128
|
}
|
|
127
129
|
|
|
128
130
|
/**
|
|
129
|
-
* Stores pending
|
|
130
|
-
* @remarks
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
* @param
|
|
134
|
-
* stored in the db.
|
|
135
|
-
* @param txHash - The tx in which the
|
|
131
|
+
* Stores pending index ranges.
|
|
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
|
+
* 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.
|
|
135
|
+
* @param ranges - The tagging index ranges containing the directional app tagging secrets and the index ranges that are
|
|
136
|
+
* to be stored in the db.
|
|
137
|
+
* @param txHash - The tx in which the tagging indexes were used in private logs.
|
|
136
138
|
* @param jobId - job context for staged writes to this store. See `JobCoordinator` for more details.
|
|
137
|
-
* @throws If
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
* @throws If the newly stored pending index is further than window length from the highest finalized index for the
|
|
141
|
-
* same secret. This is enforced in order to give a guarantee to a recipient that he doesn't need to look further than
|
|
142
|
-
* window length ahead of the highest finalized index.
|
|
143
|
-
* @throws If a secret + txHash pair already exists in the db with a different index value. It should never happen
|
|
144
|
-
* that we would attempt to store a different index for a given secret-txHash pair because we always store just the
|
|
145
|
-
* highest index for a given secret-txHash pair. Hence this is a good way to catch bugs.
|
|
146
|
-
* @throws If the newly stored pending index is lower than or equal to the last finalized index for the same secret.
|
|
147
|
-
* This is enforced because this should never happen if the syncing is done correctly as we look for logs from higher
|
|
148
|
-
* indexes than finalized ones.
|
|
139
|
+
* @throws If the highestIndex is further than window length from the highest finalized index for the same secret.
|
|
140
|
+
* @throws If the lowestIndex is lower than or equal to the last finalized index for the same secret.
|
|
141
|
+
* @throws If a different range already exists for the same (secret, txHash) pair.
|
|
149
142
|
*/
|
|
150
|
-
storePendingIndexes(
|
|
151
|
-
if (
|
|
143
|
+
storePendingIndexes(ranges: TaggingIndexRange[], txHash: TxHash, jobId: string): Promise<void> {
|
|
144
|
+
if (ranges.length === 0) {
|
|
152
145
|
return Promise.resolve();
|
|
153
146
|
}
|
|
154
147
|
|
|
155
|
-
// The secrets in pre-tags should be unique because we always store just the highest index per given secret-txHash
|
|
156
|
-
// pair. Below we check that this is the case.
|
|
157
|
-
const secretsSet = new Set(preTags.map(preTag => preTag.secret.toString()));
|
|
158
|
-
if (secretsSet.size !== preTags.length) {
|
|
159
|
-
return Promise.reject(new Error(`Duplicate secrets found when storing pending indexes`));
|
|
160
|
-
}
|
|
161
|
-
|
|
162
148
|
const txHashStr = txHash.toString();
|
|
163
149
|
|
|
164
150
|
return this.#store.transactionAsync(async () => {
|
|
165
151
|
// Prefetch all data, start reads during iteration to keep IndexedDB transaction alive
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
pending: this.#readPendingIndexes(jobId, secretStr),
|
|
173
|
-
finalized: this.#readLastFinalizedIndex(jobId, secretStr),
|
|
174
|
-
};
|
|
175
|
-
});
|
|
152
|
+
const rangeReadPromises = ranges.map(range => ({
|
|
153
|
+
range,
|
|
154
|
+
secretStr: range.extendedSecret.toString(),
|
|
155
|
+
pending: this.#readPendingIndexes(jobId, range.extendedSecret.toString()),
|
|
156
|
+
finalized: this.#readLastFinalizedIndex(jobId, range.extendedSecret.toString()),
|
|
157
|
+
}));
|
|
176
158
|
|
|
177
159
|
// Await all reads together
|
|
178
|
-
const
|
|
179
|
-
|
|
160
|
+
const rangeData = await Promise.all(
|
|
161
|
+
rangeReadPromises.map(async item => ({
|
|
180
162
|
...item,
|
|
181
163
|
pendingData: await item.pending,
|
|
182
164
|
finalizedIndex: await item.finalized,
|
|
@@ -184,48 +166,51 @@ export class SenderTaggingStore implements StagedStore {
|
|
|
184
166
|
);
|
|
185
167
|
|
|
186
168
|
// Process in memory and validate
|
|
187
|
-
for (const {
|
|
188
|
-
//
|
|
189
|
-
|
|
190
|
-
if (index > (finalizedIndex ?? 0) + UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN) {
|
|
169
|
+
for (const { range, secretStr, pendingData, finalizedIndex } of rangeData) {
|
|
170
|
+
// Check that the highest index is not further than window length from the highest finalized index.
|
|
171
|
+
if (range.highestIndex > (finalizedIndex ?? 0) + UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN) {
|
|
191
172
|
throw new Error(
|
|
192
|
-
`Highest used index ${
|
|
173
|
+
`Highest used index ${range.highestIndex} is further than window length from the highest finalized index ${finalizedIndex ?? 0}.
|
|
193
174
|
Tagging window length ${UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN} is configured too low. Contact the Aztec team
|
|
194
175
|
to increase it!`,
|
|
195
176
|
);
|
|
196
177
|
}
|
|
197
178
|
|
|
198
|
-
// Throw if the
|
|
199
|
-
if (finalizedIndex !== undefined &&
|
|
179
|
+
// Throw if the lowest index is lower than or equal to the last finalized index
|
|
180
|
+
if (finalizedIndex !== undefined && range.lowestIndex <= finalizedIndex) {
|
|
200
181
|
throw new Error(
|
|
201
|
-
`Cannot store pending index ${
|
|
202
|
-
`
|
|
182
|
+
`Cannot store pending index range [${range.lowestIndex}, ${range.highestIndex}] for secret ${secretStr}: ` +
|
|
183
|
+
`lowestIndex is lower than or equal to the last finalized index ${finalizedIndex}`,
|
|
203
184
|
);
|
|
204
185
|
}
|
|
205
186
|
|
|
206
|
-
// Check if
|
|
207
|
-
const
|
|
187
|
+
// Check if an entry with the same txHash already exists
|
|
188
|
+
const existingEntry = pendingData.find(entry => entry.txHash === txHashStr);
|
|
208
189
|
|
|
209
|
-
if (
|
|
210
|
-
//
|
|
211
|
-
if (
|
|
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) {
|
|
212
193
|
throw new Error(
|
|
213
|
-
`
|
|
214
|
-
`
|
|
194
|
+
`Conflicting range for secret ${secretStr} and txHash ${txHashStr}: ` +
|
|
195
|
+
`existing [${existingEntry.lowestIndex}, ${existingEntry.highestIndex}] vs ` +
|
|
196
|
+
`new [${range.lowestIndex}, ${range.highestIndex}]`,
|
|
215
197
|
);
|
|
216
198
|
}
|
|
217
|
-
//
|
|
199
|
+
// Exact duplicate — skip
|
|
218
200
|
} else {
|
|
219
|
-
|
|
220
|
-
|
|
201
|
+
this.#writePendingIndexes(jobId, secretStr, [
|
|
202
|
+
...pendingData,
|
|
203
|
+
{ lowestIndex: range.lowestIndex, highestIndex: range.highestIndex, txHash: txHashStr },
|
|
204
|
+
]);
|
|
221
205
|
}
|
|
222
206
|
}
|
|
223
207
|
});
|
|
224
208
|
}
|
|
225
209
|
|
|
226
210
|
/**
|
|
227
|
-
* Returns the transaction hashes of all pending transactions that contain indexes within a specified range
|
|
228
|
-
* for a given directional app tagging secret.
|
|
211
|
+
* Returns the transaction hashes of all pending transactions that contain highest indexes within a specified range
|
|
212
|
+
* for a given directional app tagging secret. We check based on the highest indexes only as that is the relevant
|
|
213
|
+
* information for the caller of this function.
|
|
229
214
|
* @param secret - The directional app tagging secret to query pending indexes for.
|
|
230
215
|
* @param startIndex - The lower bound of the index range (inclusive).
|
|
231
216
|
* @param endIndex - The upper bound of the index range (exclusive).
|
|
@@ -233,7 +218,7 @@ export class SenderTaggingStore implements StagedStore {
|
|
|
233
218
|
* [startIndex, endIndex). Returns an empty array if no pending indexes exist in the range.
|
|
234
219
|
*/
|
|
235
220
|
getTxHashesOfPendingIndexes(
|
|
236
|
-
secret:
|
|
221
|
+
secret: ExtendedDirectionalAppTaggingSecret,
|
|
237
222
|
startIndex: number,
|
|
238
223
|
endIndex: number,
|
|
239
224
|
jobId: string,
|
|
@@ -241,7 +226,7 @@ export class SenderTaggingStore implements StagedStore {
|
|
|
241
226
|
return this.#store.transactionAsync(async () => {
|
|
242
227
|
const existing = await this.#readPendingIndexes(jobId, secret.toString());
|
|
243
228
|
const txHashes = existing
|
|
244
|
-
.filter(entry => entry.
|
|
229
|
+
.filter(entry => entry.highestIndex >= startIndex && entry.highestIndex < endIndex)
|
|
245
230
|
.map(entry => entry.txHash);
|
|
246
231
|
return Array.from(new Set(txHashes)).map(TxHash.fromString);
|
|
247
232
|
});
|
|
@@ -252,7 +237,7 @@ export class SenderTaggingStore implements StagedStore {
|
|
|
252
237
|
* @param secret - The secret to get the last finalized index for.
|
|
253
238
|
* @returns The last (highest) finalized index for the given secret.
|
|
254
239
|
*/
|
|
255
|
-
getLastFinalizedIndex(secret:
|
|
240
|
+
getLastFinalizedIndex(secret: ExtendedDirectionalAppTaggingSecret, jobId: string): Promise<number | undefined> {
|
|
256
241
|
return this.#store.transactionAsync(() => this.#readLastFinalizedIndex(jobId, secret.toString()));
|
|
257
242
|
}
|
|
258
243
|
|
|
@@ -262,23 +247,22 @@ export class SenderTaggingStore implements StagedStore {
|
|
|
262
247
|
* @param secret - The directional app tagging secret to query the last used index for.
|
|
263
248
|
* @returns The last used index.
|
|
264
249
|
*/
|
|
265
|
-
getLastUsedIndex(secret:
|
|
250
|
+
getLastUsedIndex(secret: ExtendedDirectionalAppTaggingSecret, jobId: string): Promise<number | undefined> {
|
|
266
251
|
const secretStr = secret.toString();
|
|
267
252
|
|
|
268
253
|
return this.#store.transactionAsync(async () => {
|
|
269
254
|
const pendingPromise = this.#readPendingIndexes(jobId, secretStr);
|
|
270
255
|
const finalizedPromise = this.#readLastFinalizedIndex(jobId, secretStr);
|
|
271
256
|
|
|
272
|
-
const [
|
|
273
|
-
const pendingIndexes = pendingTxScopedIndexes.map(entry => entry.index);
|
|
257
|
+
const [pendingEntries, lastFinalized] = await Promise.all([pendingPromise, finalizedPromise]);
|
|
274
258
|
|
|
275
|
-
if (
|
|
259
|
+
if (pendingEntries.length === 0) {
|
|
276
260
|
return lastFinalized;
|
|
277
261
|
}
|
|
278
262
|
|
|
279
|
-
// As the last used index we return the highest one from the pending
|
|
280
|
-
// higher than the last finalized index because we prune lower pending indexes when a tx is finalized.
|
|
281
|
-
return Math.max(...
|
|
263
|
+
// As the last used index we return the highest one from the pending index ranges. Note that this value will be
|
|
264
|
+
// always higher than the last finalized index because we prune lower pending indexes when a tx is finalized.
|
|
265
|
+
return Math.max(...pendingEntries.map(entry => entry.highestIndex));
|
|
282
266
|
});
|
|
283
267
|
}
|
|
284
268
|
|
|
@@ -294,7 +278,7 @@ export class SenderTaggingStore implements StagedStore {
|
|
|
294
278
|
|
|
295
279
|
return this.#store.transactionAsync(async () => {
|
|
296
280
|
// Prefetch all data, start reads during iteration to keep IndexedDB transaction alive
|
|
297
|
-
const secretReadPromises: Map<string, Promise<
|
|
281
|
+
const secretReadPromises: Map<string, Promise<PendingIndexesEntry[]>> = new Map();
|
|
298
282
|
|
|
299
283
|
for await (const secret of this.#pendingIndexes.keysAsync()) {
|
|
300
284
|
secretReadPromises.set(secret, this.#readPendingIndexes(jobId, secret));
|
|
@@ -330,22 +314,15 @@ export class SenderTaggingStore implements StagedStore {
|
|
|
330
314
|
});
|
|
331
315
|
}
|
|
332
316
|
|
|
333
|
-
/**
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
finalizePendingIndexes(txHashes: TxHash[], jobId: string): Promise<void> {
|
|
338
|
-
if (txHashes.length === 0) {
|
|
339
|
-
return Promise.resolve();
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
const txHashStrings = new Set(txHashes.map(tx => tx.toString()));
|
|
343
|
-
|
|
317
|
+
/** Prefetches all pending and finalized index data for every secret (from both DB and staged writes). */
|
|
318
|
+
#getSecretsWithPendingData(
|
|
319
|
+
jobId: string,
|
|
320
|
+
): Promise<{ secret: string; pendingData: PendingIndexesEntry[]; lastFinalized: number | undefined }[]> {
|
|
344
321
|
return this.#store.transactionAsync(async () => {
|
|
345
322
|
// Prefetch all data, start reads during iteration to keep IndexedDB transaction alive
|
|
346
323
|
const secretDataPromises: Map<
|
|
347
324
|
string,
|
|
348
|
-
{ pending: Promise<
|
|
325
|
+
{ pending: Promise<PendingIndexesEntry[]>; finalized: Promise<number | undefined> }
|
|
349
326
|
> = new Map();
|
|
350
327
|
|
|
351
328
|
for await (const secret of this.#pendingIndexes.keysAsync()) {
|
|
@@ -375,55 +352,125 @@ export class SenderTaggingStore implements StagedStore {
|
|
|
375
352
|
})),
|
|
376
353
|
);
|
|
377
354
|
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
355
|
+
return dataResults.filter(r => r.pendingData.length > 0);
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Updates pending indexes corresponding to the given transaction hashes to be finalized and prunes any lower pending
|
|
361
|
+
* indexes.
|
|
362
|
+
*/
|
|
363
|
+
async finalizePendingIndexes(txHashes: TxHash[], jobId: string): Promise<void> {
|
|
364
|
+
if (txHashes.length === 0) {
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
const txHashStrings = new Set(txHashes.map(tx => tx.toString()));
|
|
369
|
+
const secretsWithData = await this.#getSecretsWithPendingData(jobId);
|
|
370
|
+
|
|
371
|
+
for (const { secret, pendingData, lastFinalized } of secretsWithData) {
|
|
372
|
+
let currentPending = pendingData;
|
|
373
|
+
let currentFinalized = lastFinalized;
|
|
374
|
+
|
|
375
|
+
// Process all txHashes for this secret
|
|
376
|
+
for (const txHashStr of txHashStrings) {
|
|
377
|
+
const matchingEntries = currentPending.filter(item => item.txHash === txHashStr);
|
|
378
|
+
if (matchingEntries.length === 0) {
|
|
379
|
+
// This is expected as a higher index might have already been finalized which would lead to pruning of
|
|
380
|
+
// pending entries.
|
|
381
381
|
continue;
|
|
382
382
|
}
|
|
383
383
|
|
|
384
|
-
|
|
385
|
-
|
|
384
|
+
if (matchingEntries.length > 1) {
|
|
385
|
+
// We should always just store the highest pending index for a given tx hash and secret because the lower
|
|
386
|
+
// values are irrelevant.
|
|
387
|
+
throw new Error(`Multiple pending entries found for tx hash ${txHashStr} and secret ${secret}`);
|
|
388
|
+
}
|
|
386
389
|
|
|
387
|
-
|
|
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
|
-
}
|
|
390
|
+
const newFinalized = matchingEntries[0].highestIndex;
|
|
393
391
|
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
392
|
+
if (newFinalized < (currentFinalized ?? 0)) {
|
|
393
|
+
// This should never happen because when last finalized index was finalized we should have pruned the lower
|
|
394
|
+
// pending indexes.
|
|
395
|
+
throw new Error(
|
|
396
|
+
`New finalized index ${newFinalized} is smaller than the current last finalized index ${currentFinalized}`,
|
|
397
|
+
);
|
|
398
|
+
}
|
|
399
399
|
|
|
400
|
-
|
|
400
|
+
currentFinalized = newFinalized;
|
|
401
401
|
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
}
|
|
402
|
+
// When we add pending indexes, we ensure they are higher than the last finalized index. However, because we
|
|
403
|
+
// cannot control the order in which transactions are finalized, there may be pending indexes that are now
|
|
404
|
+
// obsolete because they are lower than the most recently finalized index. For this reason, we prune these
|
|
405
|
+
// outdated pending indexes.
|
|
406
|
+
currentPending = currentPending.filter(item => item.highestIndex > currentFinalized!);
|
|
407
|
+
}
|
|
409
408
|
|
|
410
|
-
|
|
409
|
+
// Write final state if changed
|
|
410
|
+
if (currentFinalized !== lastFinalized) {
|
|
411
|
+
this.#writeLastFinalizedIndex(jobId, secret, currentFinalized!);
|
|
412
|
+
}
|
|
413
|
+
if (currentPending !== pendingData) {
|
|
414
|
+
this.#writePendingIndexes(jobId, secret, currentPending);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
411
418
|
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
419
|
+
/**
|
|
420
|
+
* Handles finalization of pending indexes for a transaction whose execution was partially reverted.
|
|
421
|
+
* Recomputes the siloed tags for each pending index of the given tx and checks which ones appear in the
|
|
422
|
+
* TxEffect's private logs (i.e., which ones made it onchain). Those that survived are finalized; those that
|
|
423
|
+
* didn't are dropped.
|
|
424
|
+
* @param txEffect - The tx effect of the partially reverted transaction.
|
|
425
|
+
* @param jobId - job context for staged writes to this store. See `JobCoordinator` for more details.
|
|
426
|
+
*/
|
|
427
|
+
async finalizePendingIndexesOfAPartiallyRevertedTx(txEffect: TxEffect, jobId: string): Promise<void> {
|
|
428
|
+
const txHashStr = txEffect.txHash.toString();
|
|
418
429
|
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
430
|
+
// Build a set of all siloed tag values that made it onchain (first field of each private log).
|
|
431
|
+
const onChainTags = new Set<string>(txEffect.privateLogs.map(log => log.fields[0].toString()));
|
|
432
|
+
|
|
433
|
+
const secretsWithData = await this.#getSecretsWithPendingData(jobId);
|
|
434
|
+
|
|
435
|
+
for (const { secret, pendingData, lastFinalized } of secretsWithData) {
|
|
436
|
+
const matchingEntries = pendingData.filter(item => item.txHash === txHashStr);
|
|
437
|
+
if (matchingEntries.length === 0) {
|
|
438
|
+
// This is expected as a higher index might have already been finalized which would lead to pruning of
|
|
439
|
+
// pending entries.
|
|
440
|
+
continue;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
if (matchingEntries.length > 1) {
|
|
444
|
+
// We should always just store the highest pending index for a given tx hash and secret because the lower
|
|
445
|
+
// values are irrelevant.
|
|
446
|
+
throw new Error(`Multiple pending entries found for tx hash ${txHashStr} and secret ${secret}`);
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
const pendingEntry = matchingEntries[0];
|
|
450
|
+
|
|
451
|
+
// Expand each matching entry's range and recompute siloed tags for each index.
|
|
452
|
+
const extendedSecret = ExtendedDirectionalAppTaggingSecret.fromString(secret);
|
|
453
|
+
let highestSurvivingIndex: number | undefined;
|
|
454
|
+
|
|
455
|
+
for (let index = pendingEntry.lowestIndex; index <= pendingEntry.highestIndex; index++) {
|
|
456
|
+
const siloedTag = await SiloedTag.compute({ extendedSecret, index });
|
|
457
|
+
if (onChainTags.has(siloedTag.value.toString())) {
|
|
458
|
+
highestSurvivingIndex = highestSurvivingIndex !== undefined ? Math.max(highestSurvivingIndex, index) : index;
|
|
425
459
|
}
|
|
426
460
|
}
|
|
427
|
-
|
|
461
|
+
|
|
462
|
+
// Remove all entries for this txHash from pending (both surviving and non-surviving).
|
|
463
|
+
let currentPending = pendingData.filter(item => item.txHash !== txHashStr);
|
|
464
|
+
|
|
465
|
+
if (highestSurvivingIndex !== undefined) {
|
|
466
|
+
const newFinalized = Math.max(lastFinalized ?? 0, highestSurvivingIndex);
|
|
467
|
+
this.#writeLastFinalizedIndex(jobId, secret, newFinalized);
|
|
468
|
+
|
|
469
|
+
// Prune pending indexes that are now <= the finalized index.
|
|
470
|
+
currentPending = currentPending.filter(item => item.highestIndex > newFinalized);
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
this.#writePendingIndexes(jobId, secret, currentPending);
|
|
474
|
+
}
|
|
428
475
|
}
|
|
429
476
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
2
2
|
import type { BlockHash } from '@aztec/stdlib/block';
|
|
3
|
-
import { MAX_LOGS_PER_TAG } from '@aztec/stdlib/interfaces/api-limit';
|
|
3
|
+
import { MAX_LOGS_PER_TAG, MAX_RPC_LEN } 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';
|
|
6
6
|
|
|
@@ -31,6 +31,26 @@ async function getAllPages<T>(numTags: number, fetchPage: (page: number) => Prom
|
|
|
31
31
|
return allResultsPerTag;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Splits tags into chunks of MAX_RPC_LEN, fetches logs for each chunk using getAllPages, then stitches the results
|
|
36
|
+
* back into a single array preserving the original tag order.
|
|
37
|
+
*/
|
|
38
|
+
async function getAllPagesInBatches<Tag, T>(
|
|
39
|
+
tags: Tag[],
|
|
40
|
+
fetchAllPagesForBatch: (batch: Tag[]) => Promise<T[][]>,
|
|
41
|
+
): Promise<T[][]> {
|
|
42
|
+
if (tags.length <= MAX_RPC_LEN) {
|
|
43
|
+
return fetchAllPagesForBatch(tags);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const batches: Tag[][] = [];
|
|
47
|
+
for (let i = 0; i < tags.length; i += MAX_RPC_LEN) {
|
|
48
|
+
batches.push(tags.slice(i, i + MAX_RPC_LEN));
|
|
49
|
+
}
|
|
50
|
+
const batchResults = await Promise.all(batches.map(fetchAllPagesForBatch));
|
|
51
|
+
return batchResults.flat();
|
|
52
|
+
}
|
|
53
|
+
|
|
34
54
|
/**
|
|
35
55
|
* Fetches all private logs for the given tags, automatically paginating through all pages.
|
|
36
56
|
* @param aztecNode - The Aztec node to query.
|
|
@@ -44,7 +64,9 @@ export function getAllPrivateLogsByTags(
|
|
|
44
64
|
tags: SiloedTag[],
|
|
45
65
|
anchorBlockHash: BlockHash,
|
|
46
66
|
): Promise<TxScopedL2Log[][]> {
|
|
47
|
-
return
|
|
67
|
+
return getAllPagesInBatches(tags, batch =>
|
|
68
|
+
getAllPages(batch.length, page => aztecNode.getPrivateLogsByTags(batch, page, anchorBlockHash)),
|
|
69
|
+
);
|
|
48
70
|
}
|
|
49
71
|
|
|
50
72
|
/**
|
|
@@ -62,7 +84,9 @@ export function getAllPublicLogsByTagsFromContract(
|
|
|
62
84
|
tags: Tag[],
|
|
63
85
|
anchorBlockHash: BlockHash,
|
|
64
86
|
): Promise<TxScopedL2Log[][]> {
|
|
65
|
-
return
|
|
66
|
-
|
|
87
|
+
return getAllPagesInBatches(tags, batch =>
|
|
88
|
+
getAllPages(batch.length, page =>
|
|
89
|
+
aztecNode.getPublicLogsByTagsFromContract(contractAddress, batch, page, anchorBlockHash),
|
|
90
|
+
),
|
|
67
91
|
);
|
|
68
92
|
}
|
package/src/tagging/index.ts
CHANGED
|
@@ -15,5 +15,5 @@ export { UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN } from './constants.js';
|
|
|
15
15
|
export { getAllPrivateLogsByTags, getAllPublicLogsByTagsFromContract } from './get_all_logs_by_tags.js';
|
|
16
16
|
|
|
17
17
|
// Re-export tagging-related types from stdlib
|
|
18
|
-
export {
|
|
19
|
-
export { type PreTag } from '@aztec/stdlib/logs';
|
|
18
|
+
export { ExtendedDirectionalAppTaggingSecret, Tag, SiloedTag } from '@aztec/stdlib/logs';
|
|
19
|
+
export { type PreTag, type TaggingIndexRange } from '@aztec/stdlib/logs';
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import type { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
-
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
3
2
|
import type { BlockHash } from '@aztec/stdlib/block';
|
|
4
3
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
5
|
-
import type {
|
|
4
|
+
import type { ExtendedDirectionalAppTaggingSecret, TxScopedL2Log } from '@aztec/stdlib/logs';
|
|
6
5
|
|
|
7
6
|
import type { RecipientTaggingStore } from '../../storage/tagging_store/recipient_tagging_store.js';
|
|
8
7
|
import { UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN } from '../constants.js';
|
|
@@ -10,15 +9,14 @@ import { findHighestIndexes } from './utils/find_highest_indexes.js';
|
|
|
10
9
|
import { loadLogsForRange } from './utils/load_logs_for_range.js';
|
|
11
10
|
|
|
12
11
|
/**
|
|
13
|
-
* Loads private logs for
|
|
12
|
+
* Loads private logs for the app-sender-recipient triplet defined by `secret` and updates the highest aged and
|
|
14
13
|
* finalized indexes in the db. At most load logs from blocks up to and including `anchorBlockNumber`.
|
|
15
14
|
*
|
|
16
15
|
* @dev This function can be safely executed "in parallel" for other sender-recipient pairs because the data in
|
|
17
16
|
* in the tagging data provider is indexed by the secret and hence completely disjoint.
|
|
18
17
|
*/
|
|
19
18
|
export async function loadPrivateLogsForSenderRecipientPair(
|
|
20
|
-
secret:
|
|
21
|
-
app: AztecAddress,
|
|
19
|
+
secret: ExtendedDirectionalAppTaggingSecret,
|
|
22
20
|
aztecNode: AztecNode,
|
|
23
21
|
taggingStore: RecipientTaggingStore,
|
|
24
22
|
anchorBlockNumber: BlockNumber,
|
|
@@ -30,7 +28,7 @@ export async function loadPrivateLogsForSenderRecipientPair(
|
|
|
30
28
|
// (highestAgedIndex, highestFinalizedIndex + WINDOW_LEN]
|
|
31
29
|
//
|
|
32
30
|
// highestAgedIndex is the highest index that was used in a tx that is included in a block at least
|
|
33
|
-
// `
|
|
31
|
+
// `MAX_TX_LIFETIME` seconds ago.
|
|
34
32
|
// highestFinalizedIndex is the highest index that was used in a tx that is included in a finalized block.
|
|
35
33
|
//
|
|
36
34
|
// "(" denotes an open end of the range - the index is not included in the range.
|
|
@@ -42,19 +40,19 @@ export async function loadPrivateLogsForSenderRecipientPair(
|
|
|
42
40
|
// ever appear.
|
|
43
41
|
//
|
|
44
42
|
// This relies on the "maximum inclusion timestamp" rule enforced by the kernel and rollup circuits:
|
|
45
|
-
// - a transaction's maximum inclusion timestamp is at most `
|
|
43
|
+
// - a transaction's maximum inclusion timestamp is at most `MAX_TX_LIFETIME` seconds after
|
|
46
44
|
// the timestamp of its anchor block; and
|
|
47
45
|
// - a rollup only includes transactions whose inclusion timestamp is >= the L2 block's timestamp.
|
|
48
46
|
//
|
|
49
47
|
// Suppose some device used index `I` in a transaction anchored to block `B_N` at time `N`, and that block is now at
|
|
50
|
-
// least `
|
|
48
|
+
// least `MAX_TX_LIFETIME` seconds in the past. Then there is no possibility of any *other* device
|
|
51
49
|
// trying to use an index <= `I` while anchoring to a *newer* block than `B_N` because if we were anchoring to
|
|
52
50
|
// a newer block than `B_N` then we would already have seen the log with index `I` and hence the device would have
|
|
53
51
|
// chosen a larger index.
|
|
54
52
|
// If that *other* device would anchor to a block older than `B_N` then that tx could never be included in a block
|
|
55
53
|
// because it would already have been expired.
|
|
56
54
|
//
|
|
57
|
-
// Therefore, once we see that index `I` has been used in a block that is at least `
|
|
55
|
+
// Therefore, once we see that index `I` has been used in a block that is at least `MAX_TX_LIFETIME`
|
|
58
56
|
// seconds old, we can safely stop syncing logs for all indexes <= `I` and set highestAgedIndex = `I`.
|
|
59
57
|
//
|
|
60
58
|
// ## Explanation of the upper bound `highestFinalizedIndex + WINDOW_LEN`
|
|
@@ -96,7 +94,6 @@ export async function loadPrivateLogsForSenderRecipientPair(
|
|
|
96
94
|
// Get private logs with their block timestamps and corresponding tagging indexes
|
|
97
95
|
const privateLogsWithIndexes = await loadLogsForRange(
|
|
98
96
|
secret,
|
|
99
|
-
app,
|
|
100
97
|
aztecNode,
|
|
101
98
|
start,
|
|
102
99
|
end,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MAX_TX_LIFETIME } from '@aztec/constants';
|
|
2
2
|
import type { TxScopedL2Log } from '@aztec/stdlib/logs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -16,7 +16,7 @@ export function findHighestIndexes(
|
|
|
16
16
|
const ageInSeconds = currentTimestamp - log.blockTimestamp;
|
|
17
17
|
|
|
18
18
|
if (
|
|
19
|
-
ageInSeconds >= BigInt(
|
|
19
|
+
ageInSeconds >= BigInt(MAX_TX_LIFETIME) &&
|
|
20
20
|
(highestAgedIndex === undefined || taggingIndex > highestAgedIndex)
|
|
21
21
|
) {
|
|
22
22
|
highestAgedIndex = taggingIndex;
|