@aztec/pxe 0.0.1-commit.3100065 → 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.
- package/dest/bin/check_oracle_version.js +5 -46
- package/dest/bin/index.d.ts +2 -2
- package/dest/bin/index.d.ts.map +1 -1
- package/dest/bin/index.js +1 -1
- package/dest/bin/oracle_version_helpers.d.ts +8 -39
- package/dest/bin/oracle_version_helpers.d.ts.map +1 -1
- package/dest/bin/oracle_version_helpers.js +10 -239
- package/dest/block_synchronizer/block_synchronizer.d.ts +3 -5
- package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
- package/dest/block_synchronizer/block_synchronizer.js +5 -18
- package/dest/config/package_info.js +1 -1
- package/dest/contract/contract_class_service.d.ts +1 -8
- package/dest/contract/contract_class_service.d.ts.map +1 -1
- package/dest/contract/contract_class_service.js +8 -40
- package/dest/contract/helpers.d.ts +1 -1
- package/dest/contract/helpers.d.ts.map +1 -1
- package/dest/contract/helpers.js +3 -3
- package/dest/contract/skip_sync_contracts.d.ts +11 -0
- package/dest/contract/skip_sync_contracts.d.ts.map +1 -0
- package/dest/contract/skip_sync_contracts.js +18 -0
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +1 -8
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +5 -20
- package/dest/contract_function_simulator/index.d.ts +3 -3
- package/dest/contract_function_simulator/index.d.ts.map +1 -1
- package/dest/contract_function_simulator/index.js +1 -2
- package/dest/contract_function_simulator/noir-structs/resolved_tx.d.ts +7 -9
- package/dest/contract_function_simulator/noir-structs/resolved_tx.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/resolved_tx.js +3 -44
- package/dest/contract_function_simulator/noir-structs/tx_effect_data.d.ts +5 -4
- package/dest/contract_function_simulator/noir-structs/tx_effect_data.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/tx_effect_data.js +2 -2
- package/dest/contract_function_simulator/oracle/oracle_registry.d.ts +4 -3
- package/dest/contract_function_simulator/oracle/oracle_registry.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle_registry.js +15 -6
- package/dest/contract_function_simulator/oracle/oracle_type_mappings.d.ts +87 -35
- package/dest/contract_function_simulator/oracle/oracle_type_mappings.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle_type_mappings.js +297 -287
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +11 -8
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +15 -4
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +168 -53
- package/dest/entrypoints/client/bundle/index.d.ts +2 -1
- package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/index.js +1 -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 +10 -4
- package/dest/entrypoints/client/lazy/index.d.ts +2 -1
- package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/index.js +1 -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 +10 -4
- package/dest/entrypoints/client/store.d.ts +14 -0
- package/dest/entrypoints/client/store.d.ts.map +1 -0
- package/dest/entrypoints/client/store.js +42 -0
- package/dest/entrypoints/server/index.d.ts +2 -1
- package/dest/entrypoints/server/index.d.ts.map +1 -1
- package/dest/entrypoints/server/index.js +1 -0
- package/dest/entrypoints/server/store.d.ts +18 -0
- package/dest/entrypoints/server/store.d.ts.map +1 -0
- package/dest/entrypoints/server/store.js +28 -0
- 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 +8 -2
- package/dest/events/event_service.d.ts +13 -6
- package/dest/events/event_service.d.ts.map +1 -1
- package/dest/events/event_service.js +13 -13
- package/dest/logs/log_service.d.ts +15 -6
- package/dest/logs/log_service.d.ts.map +1 -1
- package/dest/logs/log_service.js +25 -32
- package/dest/messages/tx_resolver_service.d.ts +18 -7
- package/dest/messages/tx_resolver_service.d.ts.map +1 -1
- package/dest/messages/tx_resolver_service.js +13 -7
- package/dest/node/benchmarked_node.d.ts +20 -0
- package/dest/node/benchmarked_node.d.ts.map +1 -0
- package/dest/node/benchmarked_node.js +94 -0
- package/dest/node/caching_aztec_node.d.ts +24 -0
- package/dest/node/caching_aztec_node.d.ts.map +1 -0
- package/dest/node/caching_aztec_node.js +267 -0
- package/dest/notes/note_service.d.ts +13 -7
- package/dest/notes/note_service.d.ts.map +1 -1
- package/dest/notes/note_service.js +10 -10
- package/dest/oracle_version.d.ts +2 -2
- package/dest/oracle_version.js +5 -5
- package/dest/private_kernel/batch_planner.d.ts +1 -1
- package/dest/private_kernel/batch_planner.d.ts.map +1 -1
- package/dest/private_kernel/batch_planner.js +1 -1
- 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 +45 -5
- package/dest/pxe.d.ts +1 -1
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +39 -19
- 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 +2 -2
- package/dest/storage/fact_store/fact_store.d.ts +1 -1
- package/dest/storage/fact_store/fact_store.js +1 -1
- package/dest/storage/fact_store/index.d.ts +2 -2
- package/dest/storage/fact_store/index.d.ts.map +1 -1
- package/dest/storage/fact_store/index.js +1 -1
- package/dest/storage/fact_store/origin_state.d.ts +4 -2
- package/dest/storage/fact_store/origin_state.d.ts.map +1 -1
- package/dest/storage/fact_store/origin_state.js +8 -1
- package/dest/storage/store_identity.d.ts +35 -0
- package/dest/storage/store_identity.d.ts.map +1 -0
- package/dest/storage/store_identity.js +44 -0
- package/dest/storage/tagging_store/sender_tagging_store.d.ts +41 -10
- package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/sender_tagging_store.js +81 -29
- package/dest/tagging/constants.d.ts +10 -1
- package/dest/tagging/constants.d.ts.map +1 -1
- package/dest/tagging/constants.js +19 -0
- package/dest/tagging/get_all_logs_by_tags.d.ts +29 -8
- package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -1
- package/dest/tagging/get_all_logs_by_tags.js +29 -10
- package/dest/tagging/index.d.ts +3 -3
- package/dest/tagging/index.d.ts.map +1 -1
- package/dest/tagging/index.js +2 -2
- package/dest/tagging/recipient_sync/sync_tagged_private_logs.d.ts +10 -5
- package/dest/tagging/recipient_sync/sync_tagged_private_logs.d.ts.map +1 -1
- package/dest/tagging/recipient_sync/sync_tagged_private_logs.js +69 -38
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +6 -3
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +23 -38
- package/dest/tagging/sender_sync/utils/classify_pending_txs.d.ts +22 -0
- package/dest/tagging/sender_sync/utils/classify_pending_txs.d.ts.map +1 -0
- package/dest/tagging/sender_sync/utils/classify_pending_txs.js +61 -0
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +15 -5
- 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 -35
- package/dest/tagging/sender_sync/utils/resolve_pending_txs.d.ts +29 -0
- package/dest/tagging/sender_sync/utils/resolve_pending_txs.d.ts.map +1 -0
- package/dest/tagging/sender_sync/utils/resolve_pending_txs.js +41 -0
- package/dest/tagging/sender_sync/utils/test_utils.d.ts +16 -0
- package/dest/tagging/sender_sync/utils/test_utils.d.ts.map +1 -0
- package/dest/tagging/sender_sync/utils/test_utils.js +24 -0
- package/dest/tagging/testing/tag_query_test_utils.d.ts +6 -0
- package/dest/tagging/testing/tag_query_test_utils.d.ts.map +1 -0
- package/dest/tagging/testing/tag_query_test_utils.js +10 -0
- package/package.json +17 -17
- package/src/bin/check_oracle_version.ts +5 -56
- package/src/bin/index.ts +1 -5
- package/src/bin/oracle_version_helpers.ts +11 -292
- package/src/block_synchronizer/block_synchronizer.ts +6 -23
- package/src/config/package_info.ts +1 -1
- package/src/contract/contract_class_service.ts +8 -46
- package/src/contract/helpers.ts +3 -3
- package/src/contract/skip_sync_contracts.ts +23 -0
- package/src/contract_function_simulator/contract_function_simulator.ts +5 -20
- package/src/contract_function_simulator/index.ts +23 -3
- package/src/contract_function_simulator/noir-structs/resolved_tx.ts +11 -45
- package/src/contract_function_simulator/noir-structs/tx_effect_data.ts +4 -3
- package/src/contract_function_simulator/oracle/oracle_registry.ts +12 -8
- package/src/contract_function_simulator/oracle/oracle_type_mappings.ts +301 -198
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +19 -9
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +184 -56
- package/src/entrypoints/client/bundle/index.ts +1 -0
- package/src/entrypoints/client/bundle/utils.ts +15 -3
- package/src/entrypoints/client/lazy/index.ts +1 -0
- package/src/entrypoints/client/lazy/utils.ts +15 -3
- package/src/entrypoints/client/store.ts +54 -0
- package/src/entrypoints/server/index.ts +1 -0
- package/src/entrypoints/server/store.ts +47 -0
- package/src/entrypoints/server/utils.ts +21 -7
- package/src/events/event_service.ts +24 -14
- package/src/logs/log_service.ts +41 -39
- package/src/messages/tx_resolver_service.ts +26 -15
- package/src/node/benchmarked_node.ts +140 -0
- package/src/node/caching_aztec_node.ts +406 -0
- package/src/notes/note_service.ts +20 -14
- package/src/oracle_version.ts +5 -5
- package/src/private_kernel/batch_planner.ts +0 -1
- package/src/private_kernel/private_kernel_execution_prover.ts +90 -4
- package/src/pxe.ts +40 -21
- package/src/storage/contract_store/contract_store.ts +2 -1
- package/src/storage/fact_store/fact_store.ts +1 -1
- package/src/storage/fact_store/index.ts +1 -0
- package/src/storage/fact_store/origin_state.ts +10 -1
- package/src/storage/store_identity.ts +72 -0
- package/src/storage/tagging_store/sender_tagging_store.ts +113 -41
- package/src/tagging/constants.ts +22 -0
- package/src/tagging/get_all_logs_by_tags.ts +47 -11
- package/src/tagging/index.ts +7 -2
- package/src/tagging/recipient_sync/sync_tagged_private_logs.ts +116 -62
- package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +27 -57
- package/src/tagging/sender_sync/utils/classify_pending_txs.ts +91 -0
- package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +46 -40
- package/src/tagging/sender_sync/utils/resolve_pending_txs.ts +64 -0
- package/src/tagging/sender_sync/utils/test_utils.ts +46 -0
- package/src/tagging/testing/tag_query_test_utils.ts +11 -0
- package/dest/contract_function_simulator/aztec_node_read_cache.d.ts +0 -39
- package/dest/contract_function_simulator/aztec_node_read_cache.d.ts.map +0 -1
- package/dest/contract_function_simulator/aztec_node_read_cache.js +0 -60
- package/dest/contract_function_simulator/benchmarked_node.d.ts +0 -9
- package/dest/contract_function_simulator/benchmarked_node.d.ts.map +0 -1
- package/dest/contract_function_simulator/benchmarked_node.js +0 -77
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +0 -17
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +0 -1
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +0 -60
- package/src/contract_function_simulator/aztec_node_read_cache.ts +0 -89
- package/src/contract_function_simulator/benchmarked_node.ts +0 -103
- package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +0 -66
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
1
|
+
import type { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
2
|
import { isDefined } from '@aztec/foundation/types';
|
|
3
|
-
import type { BlockHash } from '@aztec/stdlib/block';
|
|
4
3
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
5
4
|
import type { AppTaggingSecret, LogResult } from '@aztec/stdlib/logs';
|
|
6
5
|
import { AppTaggingSecretKind, SiloedTag } from '@aztec/stdlib/logs';
|
|
7
6
|
import type { BlockHeader } from '@aztec/stdlib/tx';
|
|
8
7
|
|
|
9
8
|
import type { RecipientTaggingStore } from '../../storage/tagging_store/recipient_tagging_store.js';
|
|
10
|
-
import {
|
|
11
|
-
|
|
9
|
+
import {
|
|
10
|
+
INITIAL_CONSTRAINED_PROBE_LEN,
|
|
11
|
+
UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN,
|
|
12
|
+
unfinalizedTaggingIndexesWindowEnd,
|
|
13
|
+
} from '../constants.js';
|
|
14
|
+
import { type LogQueryAnchor, getAllPrivateLogsByTags, logQueryAnchorOf } from '../get_all_logs_by_tags.js';
|
|
12
15
|
import { findHighestIndexes } from './utils/find_highest_indexes.js';
|
|
13
16
|
|
|
14
17
|
/**
|
|
@@ -62,9 +65,14 @@ import { findHighestIndexes } from './utils/find_highest_indexes.js';
|
|
|
62
65
|
* - The lower bound is `highestFinalizedIndex + 1`. The `highestAgedIndex` mechanism is unnecessary because
|
|
63
66
|
* the nullifier chain prevents out-of-order index usage: no device can fill in a lower index after a higher
|
|
64
67
|
* one is already on-chain.
|
|
65
|
-
* -
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
+
* - Because the sequence is gapless, the scan stops at the first missing index: that gap proves the sequence has
|
|
69
|
+
* ended and no further logs exist. We exploit this with a doubling first-miss probe (see
|
|
70
|
+
* `INITIAL_CONSTRAINED_PROBE_LEN` in ../constants.ts), so a
|
|
71
|
+
* steady-state sync with no new logs costs two tags instead of the whole window. The probe length is in-memory
|
|
72
|
+
* state scoped to one sync call, so every sync restarts at the initial probe.
|
|
73
|
+
* - The upper bound is the same as unconstrained: `highestFinalizedIndex + WINDOW_LEN`. Advancing the probe is
|
|
74
|
+
* decoupled from persisting the finalized index, so unfinalized logs at the top of the run are still fetched
|
|
75
|
+
* while only the finalized prefix is persisted.
|
|
68
76
|
*
|
|
69
77
|
* # Batching across secrets
|
|
70
78
|
*
|
|
@@ -85,8 +93,7 @@ export async function syncTaggedPrivateLogs(
|
|
|
85
93
|
return [];
|
|
86
94
|
}
|
|
87
95
|
|
|
88
|
-
const
|
|
89
|
-
const anchorBlockHash = await anchorBlockHeader.hash();
|
|
96
|
+
const anchor = await logQueryAnchorOf(anchorBlockHeader);
|
|
90
97
|
const currentTimestamp = anchorBlockHeader.globalVariables.timestamp;
|
|
91
98
|
|
|
92
99
|
// Read stored indexes from the db and compute the initial [start, end) range for each secret
|
|
@@ -95,7 +102,7 @@ export async function syncTaggedPrivateLogs(
|
|
|
95
102
|
|
|
96
103
|
while (pending.length > 0) {
|
|
97
104
|
// Compute tags for all pending secrets and fetch logs in batched RPC calls
|
|
98
|
-
const logsPerSecret = await fetchLogsForSecrets(pending, aztecNode,
|
|
105
|
+
const logsPerSecret = await fetchLogsForSecrets(pending, aztecNode, anchor);
|
|
99
106
|
|
|
100
107
|
const nextRound = await Promise.all(
|
|
101
108
|
pending.map(async (pendingSecret, i) => {
|
|
@@ -109,19 +116,23 @@ export async function syncTaggedPrivateLogs(
|
|
|
109
116
|
|
|
110
117
|
// Persist new indexes. If the finalized index moved forward, the window advances
|
|
111
118
|
// and we need another round for this secret.
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
119
|
+
return pendingSecret.kind === AppTaggingSecretKind.CONSTRAINED
|
|
120
|
+
? await processConstrainedResults(
|
|
121
|
+
pendingSecret,
|
|
122
|
+
logsFoundWithSecret,
|
|
123
|
+
taggingStore,
|
|
124
|
+
currentTimestamp,
|
|
125
|
+
finalizedBlockNumber,
|
|
126
|
+
jobId,
|
|
127
|
+
)
|
|
128
|
+
: await processUnconstrainedResults(
|
|
129
|
+
pendingSecret,
|
|
130
|
+
logsFoundWithSecret,
|
|
131
|
+
taggingStore,
|
|
132
|
+
currentTimestamp,
|
|
133
|
+
finalizedBlockNumber,
|
|
134
|
+
jobId,
|
|
135
|
+
);
|
|
125
136
|
}),
|
|
126
137
|
);
|
|
127
138
|
|
|
@@ -138,18 +149,29 @@ function getIndexRangesForSecrets(
|
|
|
138
149
|
jobId: string,
|
|
139
150
|
): Promise<PendingSecret[]> {
|
|
140
151
|
return Promise.all(
|
|
141
|
-
secrets.map(async secret => {
|
|
152
|
+
secrets.map(async (secret): Promise<PendingSecret> => {
|
|
142
153
|
const currentHighestFinalizedIndex = await taggingStore.getHighestFinalizedIndex(secret, jobId);
|
|
154
|
+
const boundEnd = unfinalizedTaggingIndexesWindowEnd(currentHighestFinalizedIndex);
|
|
155
|
+
|
|
156
|
+
if (secret.kind === AppTaggingSecretKind.CONSTRAINED) {
|
|
157
|
+
// Constrained streams are gapless and resume at the finalized index, so probe a small initial window and stop
|
|
158
|
+
// at the first missing tag instead of always fetching the full window. The probe grows each round up to the
|
|
159
|
+
// window cap.
|
|
160
|
+
const start = currentHighestFinalizedIndex === undefined ? 0 : currentHighestFinalizedIndex + 1;
|
|
161
|
+
return {
|
|
162
|
+
kind: AppTaggingSecretKind.CONSTRAINED,
|
|
163
|
+
secret,
|
|
164
|
+
start,
|
|
165
|
+
end: Math.min(boundEnd, start + INITIAL_CONSTRAINED_PROBE_LEN),
|
|
166
|
+
boundEnd,
|
|
167
|
+
probeLen: INITIAL_CONSTRAINED_PROBE_LEN,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
143
170
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
const start = highestIndexBeforeStart === undefined ? 0 : highestIndexBeforeStart + 1;
|
|
149
|
-
|
|
150
|
-
const end = (currentHighestFinalizedIndex ?? 0) + UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN + 1;
|
|
151
|
-
|
|
152
|
-
return { secret, start, end };
|
|
171
|
+
// Unconstrained secrets can have gaps, so they scan the whole window starting past the highest aged index.
|
|
172
|
+
const highestAgedIndex = await taggingStore.getHighestAgedIndex(secret, jobId);
|
|
173
|
+
const start = highestAgedIndex === undefined ? 0 : highestAgedIndex + 1;
|
|
174
|
+
return { kind: AppTaggingSecretKind.UNCONSTRAINED, secret, start, end: boundEnd };
|
|
153
175
|
}),
|
|
154
176
|
);
|
|
155
177
|
}
|
|
@@ -161,8 +183,7 @@ function getIndexRangesForSecrets(
|
|
|
161
183
|
async function fetchLogsForSecrets(
|
|
162
184
|
pending: PendingSecret[],
|
|
163
185
|
aztecNode: AztecNode,
|
|
164
|
-
|
|
165
|
-
anchorBlockHash: BlockHash,
|
|
186
|
+
anchor: LogQueryAnchor,
|
|
166
187
|
): Promise<LogWithIndex[][]> {
|
|
167
188
|
// Determine the index range for each secret
|
|
168
189
|
const indexesPerSecret = pending.map(({ start, end }) => Array.from({ length: end - start }, (_, i) => start + i));
|
|
@@ -176,14 +197,10 @@ async function fetchLogsForSecrets(
|
|
|
176
197
|
|
|
177
198
|
const allTags = tagsPerSecret.flat();
|
|
178
199
|
|
|
179
|
-
// getAllPrivateLogsByTags handles MAX_RPC_LEN chunking internally
|
|
180
|
-
//
|
|
181
|
-
//
|
|
182
|
-
|
|
183
|
-
const allResults = await getAllPrivateLogsByTags(aztecNode, allTags, anchorBlockHash, {
|
|
184
|
-
includeEffects: true,
|
|
185
|
-
toBlock: BlockNumber(anchorBlockNumber + 1),
|
|
186
|
-
});
|
|
200
|
+
// getAllPrivateLogsByTags handles MAX_RPC_LEN chunking internally, and bounds the query at the anchor block so
|
|
201
|
+
// logs from later blocks are never returned. Recipient sync builds `PendingTaggedLog` from each log's note hashes
|
|
202
|
+
// and first nullifier, so we opt into effects.
|
|
203
|
+
const allResults = await getAllPrivateLogsByTags(aztecNode, allTags, anchor, { includeEffects: true });
|
|
187
204
|
|
|
188
205
|
// Split flat results back per secret using the known lengths
|
|
189
206
|
const logsPerSecret: LogWithIndex[][] = [];
|
|
@@ -203,41 +220,58 @@ async function fetchLogsForSecrets(
|
|
|
203
220
|
}
|
|
204
221
|
|
|
205
222
|
/**
|
|
206
|
-
* Processes fetched logs for a constrained secret
|
|
207
|
-
*
|
|
223
|
+
* Processes fetched logs for a constrained secret: persists the finalized index and advances the probe. See the
|
|
224
|
+
* "# Constrained secrets" section above for why the scan stops at the first missing index. Only `highestFinalizedIndex`
|
|
208
225
|
* is tracked (no aged index).
|
|
209
226
|
*/
|
|
210
227
|
async function processConstrainedResults(
|
|
211
|
-
pending:
|
|
228
|
+
pending: PendingConstrained,
|
|
212
229
|
logsWithIndexes: LogWithIndex[],
|
|
213
230
|
taggingStore: RecipientTaggingStore,
|
|
214
231
|
currentTimestamp: bigint,
|
|
215
232
|
finalizedBlockNumber: BlockNumber,
|
|
216
233
|
jobId: string,
|
|
217
234
|
): Promise<PendingSecret | undefined> {
|
|
218
|
-
// Find where the contiguous run of indexes ends
|
|
219
|
-
// first gap, so all logs in the batch are within this prefix.
|
|
235
|
+
// Find where the contiguous run of indexes ends; all logs in the batch fall within this prefix.
|
|
220
236
|
const indexesWithLogs = new Set(logsWithIndexes.map(l => l.taggingIndex));
|
|
221
237
|
let firstMissingIndex = pending.start;
|
|
222
238
|
while (firstMissingIndex < pending.end && indexesWithLogs.has(firstMissingIndex)) {
|
|
223
239
|
firstMissingIndex++;
|
|
224
240
|
}
|
|
225
241
|
|
|
226
|
-
//
|
|
227
|
-
// transaction, guaranteeing the log cannot disappear once included, so we persist the
|
|
228
|
-
//
|
|
242
|
+
// Persist the highest finalized index found. The nullifier for a constrained-delivery log is emitted in the same
|
|
243
|
+
// transaction, guaranteeing the log cannot disappear once included, so we persist even when a gap stops the scan.
|
|
244
|
+
// This lets the next sync round skip already-finalized indexes.
|
|
229
245
|
const { highestFinalizedIndex } = findHighestIndexes(logsWithIndexes, currentTimestamp, finalizedBlockNumber);
|
|
230
|
-
|
|
231
246
|
if (highestFinalizedIndex !== undefined) {
|
|
232
247
|
await taggingStore.updateHighestFinalizedIndex(pending.secret, highestFinalizedIndex, jobId);
|
|
248
|
+
}
|
|
233
249
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
250
|
+
// Advancing the probe is decoupled from persisting the finalized index: keep scanning as long as the probe was
|
|
251
|
+
// entirely hits (no gap) and there is room before the protocol bound, even if none of those hits is finalized yet.
|
|
252
|
+
// Gating this on finalization would drop logs in unfinalized blocks, which sit at the top of the contiguous run.
|
|
253
|
+
// The bound re-anchors to any finalized index found this round.
|
|
254
|
+
const probeFullyConsumed = firstMissingIndex >= pending.end;
|
|
255
|
+
const boundEnd =
|
|
256
|
+
highestFinalizedIndex !== undefined
|
|
257
|
+
? Math.max(pending.boundEnd, unfinalizedTaggingIndexesWindowEnd(highestFinalizedIndex))
|
|
258
|
+
: pending.boundEnd;
|
|
259
|
+
|
|
260
|
+
// Double the probe each round, capped at the window (see INITIAL_CONSTRAINED_PROBE_LEN in ../constants.ts).
|
|
261
|
+
// The queried range is already bounded by boundEnd (a probe can never reach
|
|
262
|
+
// more than WINDOW_LEN past the finalized frontier); this cap just keeps the stored length from growing unbounded
|
|
263
|
+
// once the probe saturates the window.
|
|
264
|
+
const nextProbeLen = Math.min(pending.probeLen * 2, UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN);
|
|
265
|
+
|
|
266
|
+
if (probeFullyConsumed && pending.end < boundEnd) {
|
|
267
|
+
return {
|
|
268
|
+
kind: AppTaggingSecretKind.CONSTRAINED,
|
|
269
|
+
secret: pending.secret,
|
|
270
|
+
start: pending.end,
|
|
271
|
+
end: Math.min(boundEnd, pending.end + nextProbeLen),
|
|
272
|
+
boundEnd,
|
|
273
|
+
probeLen: nextProbeLen,
|
|
274
|
+
};
|
|
241
275
|
}
|
|
242
276
|
|
|
243
277
|
return undefined;
|
|
@@ -248,7 +282,7 @@ async function processConstrainedResults(
|
|
|
248
282
|
* if the window needs to advance, or undefined if this secret is done.
|
|
249
283
|
*/
|
|
250
284
|
async function processUnconstrainedResults(
|
|
251
|
-
pending:
|
|
285
|
+
pending: PendingUnconstrained,
|
|
252
286
|
logsWithIndexes: LogWithIndex[],
|
|
253
287
|
taggingStore: RecipientTaggingStore,
|
|
254
288
|
currentTimestamp: bigint,
|
|
@@ -282,19 +316,39 @@ async function processUnconstrainedResults(
|
|
|
282
316
|
|
|
283
317
|
// For the next iteration we want to look only at indexes for which we have not yet fetched logs while
|
|
284
318
|
// ensuring that we do not look further than WINDOW_LEN ahead of the highest finalized index.
|
|
319
|
+
const end = unfinalizedTaggingIndexesWindowEnd(highestFinalizedIndex);
|
|
285
320
|
return {
|
|
321
|
+
kind: AppTaggingSecretKind.UNCONSTRAINED,
|
|
286
322
|
secret: pending.secret,
|
|
287
323
|
start: pending.end,
|
|
288
|
-
end
|
|
324
|
+
end,
|
|
289
325
|
};
|
|
290
326
|
}
|
|
291
327
|
|
|
292
|
-
|
|
328
|
+
/** Working scan state common to both secret kinds: the half-open [start, end) tag-index range to query this round. */
|
|
329
|
+
type PendingSecretBase = {
|
|
293
330
|
secret: AppTaggingSecret;
|
|
294
331
|
start: number;
|
|
295
332
|
end: number;
|
|
296
333
|
};
|
|
297
334
|
|
|
335
|
+
/** Constrained scan state, carrying the doubling-probe bookkeeping that only the gapless constrained scan uses. */
|
|
336
|
+
type PendingConstrained = PendingSecretBase & {
|
|
337
|
+
kind: typeof AppTaggingSecretKind.CONSTRAINED;
|
|
338
|
+
// Exclusive upper bound on the indexes this secret may probe this sync, from `unfinalizedTaggingIndexesWindowEnd`:
|
|
339
|
+
// the protocol bound on how far ahead of finalized a log can sit. `end` grows toward it each round.
|
|
340
|
+
boundEnd: number;
|
|
341
|
+
// Intended probe length for the round that produced `end`. The queried span can be smaller when boundEnd caps it.
|
|
342
|
+
probeLen: number;
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
/** Unconstrained scan state: a plain window with no probe bookkeeping, since the scan always covers the full window. */
|
|
346
|
+
type PendingUnconstrained = PendingSecretBase & {
|
|
347
|
+
kind: typeof AppTaggingSecretKind.UNCONSTRAINED;
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
type PendingSecret = PendingConstrained | PendingUnconstrained;
|
|
351
|
+
|
|
298
352
|
type LogWithIndex = {
|
|
299
353
|
log: LogResult;
|
|
300
354
|
taggingIndex: number;
|
|
@@ -1,20 +1,19 @@
|
|
|
1
|
-
import type {
|
|
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
|
|
|
5
5
|
import type { SenderTaggingStore } from '../../storage/tagging_store/sender_tagging_store.js';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
EMPTY_STATUS_CHANGE,
|
|
9
|
-
getStatusChangeOfPending,
|
|
10
|
-
mergeStatusChanges,
|
|
11
|
-
} from './utils/get_status_change_of_pending.js';
|
|
6
|
+
import { unfinalizedTaggingIndexesWindowEnd } from '../constants.js';
|
|
7
|
+
import type { LogQueryAnchor } from '../get_all_logs_by_tags.js';
|
|
12
8
|
import { loadAndStoreNewTaggingIndexes } from './utils/load_and_store_new_tagging_indexes.js';
|
|
9
|
+
import { resolvePendingTxs } from './utils/resolve_pending_txs.js';
|
|
13
10
|
|
|
14
11
|
/**
|
|
15
12
|
* Syncs tagging indexes. This function needs to be called whenever a private log is being sent.
|
|
16
13
|
*
|
|
17
14
|
* @param secret - The sender-side tagging `AppTaggingSecret`.
|
|
15
|
+
* @param finalizedBlockNumber - The locally-synced finalized tip, used to tell whether the block a discovered log
|
|
16
|
+
* sits in is finalized.
|
|
18
17
|
* @remarks When syncing the indexes as sender we don't care about the log contents - we only care about the highest
|
|
19
18
|
* pending and highest finalized indexes as that guides the next index choice when sending a log. The next index choice
|
|
20
19
|
* is simply the highest pending index plus one (or finalized if pending is undefined).
|
|
@@ -25,7 +24,8 @@ export async function syncSenderTaggingIndexes(
|
|
|
25
24
|
secret: AppTaggingSecret,
|
|
26
25
|
aztecNode: AztecNode,
|
|
27
26
|
taggingStore: SenderTaggingStore,
|
|
28
|
-
|
|
27
|
+
finalizedBlockNumber: BlockNumber,
|
|
28
|
+
anchor: LogQueryAnchor,
|
|
29
29
|
jobId: string,
|
|
30
30
|
): Promise<void> {
|
|
31
31
|
// # Explanation of how syncing works
|
|
@@ -43,68 +43,39 @@ export async function syncSenderTaggingIndexes(
|
|
|
43
43
|
// than WINDOW_LEN from the highest finalized index.
|
|
44
44
|
//
|
|
45
45
|
// # Note on performance
|
|
46
|
-
//
|
|
47
|
-
//
|
|
46
|
+
// A window advance usually takes a single logs query: the finalization status of most txs the logs surface is
|
|
47
|
+
// derived from the log block numbers and the locally-synced finalized tip, without a per-tx node call. See
|
|
48
|
+
// `resolvePendingTxs` for the txs that the logs cannot settle and what they cost.
|
|
48
49
|
|
|
49
50
|
const finalizedIndex = await taggingStore.getLastFinalizedIndex(secret, jobId);
|
|
50
51
|
|
|
51
52
|
let start = finalizedIndex === undefined ? 0 : finalizedIndex + 1;
|
|
52
|
-
|
|
53
|
+
// The loop only extends the window when the finalized index moves,
|
|
54
|
+
// so this first window must cover the entire permitted range on its own.
|
|
55
|
+
let end = unfinalizedTaggingIndexesWindowEnd(finalizedIndex);
|
|
53
56
|
|
|
54
57
|
let previousFinalizedIndex = finalizedIndex;
|
|
55
58
|
let newFinalizedIndex = undefined;
|
|
56
59
|
|
|
57
60
|
while (true) {
|
|
58
|
-
|
|
59
|
-
// Reading these before issuing any RPC lets us fetch their receipts in parallel with the logs query below.
|
|
60
|
-
const knownPendingTxHashes = await taggingStore.getTxHashesOfPendingIndexes(secret, start, end, jobId);
|
|
61
|
+
const txsInLogs = await loadAndStoreNewTaggingIndexes(secret, start, end, aztecNode, taggingStore, anchor, jobId);
|
|
61
62
|
|
|
62
|
-
//
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
knownPendingTxHashes.length > 0
|
|
66
|
-
? getStatusChangeOfPending(knownPendingTxHashes, aztecNode)
|
|
67
|
-
: Promise.resolve(EMPTY_STATUS_CHANGE),
|
|
68
|
-
]);
|
|
69
|
-
|
|
70
|
-
// Re-read pending tx hashes after the logs query writes any newly-discovered ones to the store.
|
|
71
|
-
const allPendingTxHashes = await taggingStore.getTxHashesOfPendingIndexes(secret, start, end, jobId);
|
|
72
|
-
if (allPendingTxHashes.length === 0) {
|
|
63
|
+
// Pending txs for this window: prior syncs, txs this PXE itself sent, and what the logs just stored.
|
|
64
|
+
const pendingTxs = await taggingStore.getPendingTxs(secret, start, end, jobId);
|
|
65
|
+
if (pendingTxs.length === 0) {
|
|
73
66
|
break;
|
|
74
67
|
}
|
|
75
68
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
// and is not re-fetched here.
|
|
79
|
-
const knownSet = new Set(knownPendingTxHashes.map(h => h.toString()));
|
|
80
|
-
const newPendingTxHashes = allPendingTxHashes.filter(h => !knownSet.has(h.toString()));
|
|
81
|
-
|
|
82
|
-
const statusOfNew =
|
|
83
|
-
newPendingTxHashes.length > 0
|
|
84
|
-
? await getStatusChangeOfPending(newPendingTxHashes, aztecNode)
|
|
85
|
-
: EMPTY_STATUS_CHANGE;
|
|
86
|
-
|
|
87
|
-
const { txHashesToFinalize, txHashesToDrop, txHashesWithExecutionReverted } = mergeStatusChanges(
|
|
88
|
-
statusOfKnown,
|
|
89
|
-
statusOfNew,
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
await taggingStore.dropPendingIndexes(txHashesToDrop, jobId);
|
|
93
|
-
await taggingStore.finalizePendingIndexes(txHashesToFinalize, jobId);
|
|
69
|
+
const { txHashesFinalizedFromLogs, txHashesFinalizedFromReceipts, txHashesDropped, receiptsWithExecutionReverted } =
|
|
70
|
+
await resolvePendingTxs(pendingTxs, txsInLogs, finalizedBlockNumber, aztecNode);
|
|
94
71
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
for (const receipt of receipts) {
|
|
100
|
-
if (!receipt.isMined() || !receipt.txEffect) {
|
|
101
|
-
throw new Error(
|
|
102
|
-
'TxEffect not found for execution-reverted tx. This is either a bug or a reorg has occurred.',
|
|
103
|
-
);
|
|
104
|
-
}
|
|
72
|
+
await taggingStore.dropPendingIndexes(txHashesDropped, jobId);
|
|
73
|
+
// The logs are queried per secret, so they only evidence this one's indexes. A receipt covers the whole tx.
|
|
74
|
+
await taggingStore.finalizePendingIndexesOfSecret(secret, txHashesFinalizedFromLogs, jobId);
|
|
75
|
+
await taggingStore.finalizePendingIndexes(txHashesFinalizedFromReceipts, jobId);
|
|
105
76
|
|
|
106
|
-
|
|
107
|
-
|
|
77
|
+
for (const receipt of receiptsWithExecutionReverted) {
|
|
78
|
+
await taggingStore.finalizePendingIndexesOfAPartiallyRevertedTx(receipt.txEffect, jobId);
|
|
108
79
|
}
|
|
109
80
|
|
|
110
81
|
// We check if the finalized index has been updated.
|
|
@@ -122,8 +93,7 @@ export async function syncSenderTaggingIndexes(
|
|
|
122
93
|
// New window: [21, 22, 23]
|
|
123
94
|
|
|
124
95
|
const previousEnd = end;
|
|
125
|
-
|
|
126
|
-
end = newFinalizedIndex! + UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN + 1;
|
|
96
|
+
end = unfinalizedTaggingIndexesWindowEnd(newFinalizedIndex);
|
|
127
97
|
start = previousEnd;
|
|
128
98
|
previousFinalizedIndex = newFinalizedIndex;
|
|
129
99
|
} else {
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import type { AztecNode } from '@aztec/stdlib/interfaces/server';
|
|
3
|
+
import { TxHash, TxStatus } from '@aztec/stdlib/tx';
|
|
4
|
+
|
|
5
|
+
import type { PendingTx } from '../../../storage/tagging_store/sender_tagging_store.js';
|
|
6
|
+
import type { TxInLogs } from './load_and_store_new_tagging_indexes.js';
|
|
7
|
+
|
|
8
|
+
/** A sync window's pending txs, grouped by what the window's logs evidence about each of them. */
|
|
9
|
+
export type LogClassification = {
|
|
10
|
+
txHashesFinalized: TxHash[];
|
|
11
|
+
txHashesWithExecutionReverted: TxHash[];
|
|
12
|
+
txHashesAbsent: TxHash[];
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/** Groups a window's pending txs by what its logs say about them. */
|
|
16
|
+
export function classifyPendingTxsFromLogs(
|
|
17
|
+
pendingTxs: PendingTx[],
|
|
18
|
+
txsInLogs: Map<string, TxInLogs>,
|
|
19
|
+
finalizedBlockNumber: BlockNumber,
|
|
20
|
+
): LogClassification {
|
|
21
|
+
const txHashesFinalized: TxHash[] = [];
|
|
22
|
+
const txHashesWithExecutionReverted: TxHash[] = [];
|
|
23
|
+
const txHashesAbsent: TxHash[] = [];
|
|
24
|
+
|
|
25
|
+
for (const pendingTx of pendingTxs) {
|
|
26
|
+
const txHash = TxHash.fromString(pendingTx.txHash);
|
|
27
|
+
const txInLogs = txsInLogs.get(pendingTx.txHash);
|
|
28
|
+
if (!txInLogs) {
|
|
29
|
+
txHashesAbsent.push(txHash);
|
|
30
|
+
} else if (txInLogs.blockNumber > finalizedBlockNumber) {
|
|
31
|
+
// A tx in the logs is mined in the log's block, so it is finalized exactly when that block is at or below the
|
|
32
|
+
// finalized tip. This one is not, so it belongs to no group until the tip catches up.
|
|
33
|
+
} else if (txInLogs.taggingIndexes.includes(pendingTx.highestIndex)) {
|
|
34
|
+
txHashesFinalized.push(txHash);
|
|
35
|
+
} else {
|
|
36
|
+
// A partially reverted tx: the revert dropped the logs carrying its higher indexes.
|
|
37
|
+
txHashesWithExecutionReverted.push(txHash);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return { txHashesFinalized, txHashesWithExecutionReverted, txHashesAbsent };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** A batch of pending txs grouped by what their receipts report about them. */
|
|
45
|
+
export type ReceiptClassification = {
|
|
46
|
+
txHashesFinalized: TxHash[];
|
|
47
|
+
txHashesDropped: TxHash[];
|
|
48
|
+
txHashesWithExecutionReverted: TxHash[];
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/** Groups pending txs by what their receipts say, for the txs the logs could not resolve. */
|
|
52
|
+
export async function classifyPendingTxsFromReceipts(
|
|
53
|
+
pending: TxHash[],
|
|
54
|
+
aztecNode: AztecNode,
|
|
55
|
+
): Promise<ReceiptClassification> {
|
|
56
|
+
const receipts = await Promise.all(pending.map(pendingTxHash => aztecNode.getTxReceipt(pendingTxHash)));
|
|
57
|
+
|
|
58
|
+
const txHashesFinalized: TxHash[] = [];
|
|
59
|
+
const txHashesDropped: TxHash[] = [];
|
|
60
|
+
const txHashesWithExecutionReverted: TxHash[] = [];
|
|
61
|
+
|
|
62
|
+
for (let i = 0; i < receipts.length; i++) {
|
|
63
|
+
const receipt = receipts[i];
|
|
64
|
+
const txHash = pending[i];
|
|
65
|
+
|
|
66
|
+
if (receipt.status === TxStatus.FINALIZED) {
|
|
67
|
+
// Tx has been included in a block and the corresponding block is finalized
|
|
68
|
+
if (receipt.hasExecutionSucceeded()) {
|
|
69
|
+
// No part of execution reverted - we just finalize all the indexes.
|
|
70
|
+
txHashesFinalized.push(txHash);
|
|
71
|
+
} else if (receipt.hasExecutionReverted()) {
|
|
72
|
+
// Tx was mined but execution reverted (app logic, teardown, or both). Some logs from the non-revertible
|
|
73
|
+
// phase may still be onchain. We check which tags made it onchain and finalize those; drop the rest.
|
|
74
|
+
txHashesWithExecutionReverted.push(txHash);
|
|
75
|
+
} else {
|
|
76
|
+
// Defensive check - this branch should never be triggered
|
|
77
|
+
throw new Error(
|
|
78
|
+
'Both hasExecutionSucceeded and hasExecutionReverted on the receipt returned false. This should never happen and it implies a bug. Please open an issue.',
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
} else if (receipt.isDropped()) {
|
|
82
|
+
// Tx was dropped from the mempool --> we drop the corresponding pending indexes.
|
|
83
|
+
txHashesDropped.push(txHash);
|
|
84
|
+
} else {
|
|
85
|
+
// Tx is still pending, not yet finalized, or was mined successfully but not yet finalized --> we don't do
|
|
86
|
+
// anything.
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return { txHashesFinalized, txHashesDropped, txHashesWithExecutionReverted };
|
|
91
|
+
}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
2
|
import type { AztecNode } from '@aztec/stdlib/interfaces/server';
|
|
3
|
-
import { type AppTaggingSecret, SiloedTag } from '@aztec/stdlib/logs';
|
|
3
|
+
import { type AppTaggingSecret, type LogResult, SiloedTag } from '@aztec/stdlib/logs';
|
|
4
4
|
import { TxHash } from '@aztec/stdlib/tx';
|
|
5
5
|
|
|
6
6
|
import type { SenderTaggingStore } from '../../../storage/tagging_store/sender_tagging_store.js';
|
|
7
|
-
import { getAllPrivateLogsByTags } from '../../get_all_logs_by_tags.js';
|
|
7
|
+
import { type LogQueryAnchor, getAllPrivateLogsByTags } from '../../get_all_logs_by_tags.js';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* Loads tagging indexes from the Aztec node and stores them in the tagging data provider.
|
|
10
|
+
* Loads tagging indexes from the Aztec node and stores them in the tagging data provider. Returns the txs the
|
|
11
|
+
* window's logs carried, keyed by tx hash string, with the block each was mined in and the window indexes it used,
|
|
12
|
+
* so the caller can classify their finalization status without further node queries.
|
|
11
13
|
* @remarks This function is one of two places by which a pending index can get to the tagging data provider. The other
|
|
12
14
|
* place is when a tx is being sent from this PXE.
|
|
13
15
|
* @param extendedSecret - The app tagging secret whose indexes are being synced.
|
|
@@ -15,7 +17,7 @@ import { getAllPrivateLogsByTags } from '../../get_all_logs_by_tags.js';
|
|
|
15
17
|
* @param end - The ending index (exclusive) of the window to process.
|
|
16
18
|
* @param aztecNode - The Aztec node instance to query for logs.
|
|
17
19
|
* @param taggingStore - The data provider to store pending indexes.
|
|
18
|
-
* @param
|
|
20
|
+
* @param anchor - Block the log query is anchored to.
|
|
19
21
|
* @param jobId - Job identifier, used to keep writes in-memory until they can be persisted in a data integrity
|
|
20
22
|
* preserving way.
|
|
21
23
|
*/
|
|
@@ -25,60 +27,64 @@ export async function loadAndStoreNewTaggingIndexes(
|
|
|
25
27
|
end: number,
|
|
26
28
|
aztecNode: AztecNode,
|
|
27
29
|
taggingStore: SenderTaggingStore,
|
|
28
|
-
|
|
30
|
+
anchor: LogQueryAnchor,
|
|
29
31
|
jobId: string,
|
|
30
|
-
) {
|
|
32
|
+
): Promise<Map<string, TxInLogs>> {
|
|
31
33
|
// We compute the tags for the current window of indexes
|
|
32
34
|
const siloedTagsForWindow = await Promise.all(
|
|
33
35
|
Array.from({ length: end - start }, (_, i) => SiloedTag.compute({ extendedSecret, index: start + i })),
|
|
34
36
|
);
|
|
35
37
|
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
+
const allLogs = await getAllPrivateLogsByTags(aztecNode, siloedTagsForWindow, anchor);
|
|
39
|
+
if (allLogs.length !== siloedTagsForWindow.length) {
|
|
40
|
+
throw new Error(
|
|
41
|
+
`Number of log arrays does not match number of tags. ${allLogs.length} !== ${siloedTagsForWindow.length}`,
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const txsInLogs = getTxsInLogs(allLogs, start);
|
|
38
46
|
|
|
39
|
-
// Now we iterate over the map, construct the tagging index ranges and store them in the db.
|
|
40
|
-
|
|
47
|
+
// Now we iterate over the map, construct the tagging index ranges and store them in the db. A tx already tracked
|
|
48
|
+
// in the store is merged rather than range-checked: if this PXE sent the tx and it partially reverted, the chain
|
|
49
|
+
// only shows the surviving sub-range of the prove-time entry (the finalized receipt step of the sync owns
|
|
50
|
+
// resolving that difference), and a tx from another PXE may straddle a sync window boundary, in which case the
|
|
51
|
+
// entry is widened so the next index choice covers the full onchain range.
|
|
52
|
+
for (const [txHashStr, { taggingIndexes }] of txsInLogs.entries()) {
|
|
41
53
|
const txHash = TxHash.fromString(txHashStr);
|
|
42
|
-
const ranges = [
|
|
43
|
-
|
|
54
|
+
const ranges = [
|
|
55
|
+
{ extendedSecret, lowestIndex: Math.min(...taggingIndexes), highestIndex: Math.max(...taggingIndexes) },
|
|
56
|
+
];
|
|
57
|
+
await taggingStore.mergePendingIndexes(ranges, txHash, jobId);
|
|
44
58
|
}
|
|
45
|
-
}
|
|
46
59
|
|
|
47
|
-
|
|
48
|
-
// an array for each tag.
|
|
49
|
-
async function getTxsContainingTags(
|
|
50
|
-
tags: SiloedTag[],
|
|
51
|
-
aztecNode: AztecNode,
|
|
52
|
-
anchorBlockHash: BlockHash,
|
|
53
|
-
): Promise<TxHash[][]> {
|
|
54
|
-
// We use the utility function below to retrieve all logs for the tags across all pages, so we don't need to handle
|
|
55
|
-
// pagination here. Sender sync only needs `txHash` from each log, so we leave `includeEffects` off.
|
|
56
|
-
const allLogs = await getAllPrivateLogsByTags(aztecNode, tags, anchorBlockHash);
|
|
57
|
-
return allLogs.map(logs => logs.map(log => log.txHash));
|
|
60
|
+
return txsInLogs;
|
|
58
61
|
}
|
|
59
62
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
/** A tx that a sync window's logs carried. */
|
|
64
|
+
export type TxInLogs = {
|
|
65
|
+
/** The block the tx was mined in, which decides whether it is finalized. */
|
|
66
|
+
blockNumber: BlockNumber;
|
|
67
|
+
/** The window's tagging indexes whose siloed tags this tx's logs carried. */
|
|
68
|
+
taggingIndexes: number[];
|
|
69
|
+
};
|
|
65
70
|
|
|
66
|
-
|
|
71
|
+
// Returns a map of txHash to the block it was mined in and all window indexes used by it.
|
|
72
|
+
function getTxsInLogs(logsForTags: LogResult[][], start: number): Map<string, TxInLogs> {
|
|
73
|
+
const txsInLogs = new Map<string, TxInLogs>();
|
|
67
74
|
// Iterate over indexes
|
|
68
|
-
for (let i = 0; i <
|
|
75
|
+
for (let i = 0; i < logsForTags.length; i++) {
|
|
69
76
|
const taggingIndex = start + i;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const
|
|
74
|
-
const existing = indexesMap.get(key);
|
|
77
|
+
// iterate over logs that used that index (tag)
|
|
78
|
+
for (const log of logsForTags[i]) {
|
|
79
|
+
const key = log.txHash.toString();
|
|
80
|
+
const existing = txsInLogs.get(key);
|
|
75
81
|
// Add the index to the tx's indexes
|
|
76
82
|
if (existing) {
|
|
77
|
-
existing.push(taggingIndex);
|
|
83
|
+
existing.taggingIndexes.push(taggingIndex);
|
|
78
84
|
} else {
|
|
79
|
-
|
|
85
|
+
txsInLogs.set(key, { blockNumber: log.blockNumber, taggingIndexes: [taggingIndex] });
|
|
80
86
|
}
|
|
81
87
|
}
|
|
82
88
|
}
|
|
83
|
-
return
|
|
89
|
+
return txsInLogs;
|
|
84
90
|
}
|