@aztec/pxe 3.0.0-rc.5 → 4.0.0-nightly.20260107
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/block_synchronizer/block_synchronizer.d.ts +39 -0
- package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -0
- package/dest/{synchronizer/synchronizer.js → block_synchronizer/block_synchronizer.js} +22 -22
- package/dest/block_synchronizer/index.d.ts +2 -0
- package/dest/block_synchronizer/index.d.ts.map +1 -0
- package/dest/block_synchronizer/index.js +1 -0
- package/dest/config/index.d.ts +4 -4
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/package_info.js +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +40 -11
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +47 -17
- package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +1 -1
- package/dest/contract_function_simulator/execution_tagging_index_cache.js +1 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts +4 -3
- package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_request.js +7 -6
- package/dest/contract_function_simulator/oracle/interfaces.d.ts +3 -4
- package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.d.ts +1 -1
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +3 -3
- package/dest/contract_function_simulator/oracle/private_execution.d.ts +7 -9
- package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution.js +11 -11
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +22 -8
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +24 -12
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +47 -8
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +143 -37
- package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +4 -4
- package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +1 -1
- package/dest/contract_function_simulator/proxied_contract_data_source.js +23 -5
- package/dest/debug/pxe_debug_utils.d.ts +31 -0
- package/dest/debug/pxe_debug_utils.d.ts.map +1 -0
- package/dest/debug/pxe_debug_utils.js +37 -0
- package/dest/entrypoints/client/bundle/index.d.ts +1 -2
- package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/index.js +0 -1
- 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 -1
- package/dest/entrypoints/client/lazy/index.d.ts +1 -2
- package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/index.js +0 -1
- 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 -1
- package/dest/entrypoints/pxe_creation_options.d.ts +3 -2
- package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
- package/dest/entrypoints/server/index.d.ts +2 -2
- package/dest/entrypoints/server/index.d.ts.map +1 -1
- package/dest/entrypoints/server/index.js +1 -1
- package/dest/entrypoints/server/utils.d.ts +1 -1
- package/dest/entrypoints/server/utils.d.ts.map +1 -1
- package/dest/entrypoints/server/utils.js +11 -7
- package/dest/error_enriching.d.ts +4 -4
- package/dest/error_enriching.d.ts.map +1 -1
- package/dest/error_enriching.js +6 -6
- package/dest/events/event_service.d.ts +15 -0
- package/dest/events/event_service.d.ts.map +1 -0
- package/dest/events/event_service.js +47 -0
- package/dest/events/private_event_filter_validator.d.ts +6 -5
- package/dest/events/private_event_filter_validator.d.ts.map +1 -1
- package/dest/events/private_event_filter_validator.js +4 -4
- package/dest/logs/log_service.d.ts +26 -0
- package/dest/logs/log_service.d.ts.map +1 -0
- package/dest/logs/log_service.js +120 -0
- package/dest/notes/index.d.ts +2 -0
- package/dest/notes/index.d.ts.map +1 -0
- package/dest/notes/index.js +1 -0
- package/dest/notes/note_service.d.ts +48 -0
- package/dest/notes/note_service.d.ts.map +1 -0
- package/dest/notes/note_service.js +152 -0
- package/dest/private_kernel/private_kernel_oracle_impl.d.ts +4 -4
- package/dest/private_kernel/private_kernel_oracle_impl.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_oracle_impl.js +7 -7
- package/dest/public_storage/public_storage_service.d.ts +24 -0
- package/dest/public_storage/public_storage_service.d.ts.map +1 -0
- package/dest/public_storage/public_storage_service.js +26 -0
- package/dest/pxe.d.ts +25 -33
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +125 -136
- package/dest/storage/address_store/address_store.d.ts +11 -0
- package/dest/storage/address_store/address_store.d.ts.map +1 -0
- package/dest/storage/{address_data_provider/address_data_provider.js → address_store/address_store.js} +1 -1
- package/dest/storage/address_store/index.d.ts +2 -0
- package/dest/storage/address_store/index.d.ts.map +1 -0
- package/dest/storage/address_store/index.js +1 -0
- package/dest/storage/{sync_data_provider/sync_data_provider.d.ts → anchor_block_store/anchor_block_store.d.ts} +2 -4
- package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -0
- package/dest/storage/{sync_data_provider/sync_data_provider.js → anchor_block_store/anchor_block_store.js} +2 -9
- package/dest/storage/{sync_data_provider → anchor_block_store}/index.d.ts +2 -2
- package/dest/storage/anchor_block_store/index.d.ts.map +1 -0
- package/dest/storage/anchor_block_store/index.js +1 -0
- package/dest/storage/capsule_store/capsule_store.d.ts +57 -0
- package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -0
- package/dest/storage/{capsule_data_provider/capsule_data_provider.js → capsule_store/capsule_store.js} +33 -5
- package/dest/storage/capsule_store/index.d.ts +2 -0
- package/dest/storage/capsule_store/index.d.ts.map +1 -0
- package/dest/storage/capsule_store/index.js +1 -0
- package/dest/storage/{contract_data_provider/contract_data_provider.d.ts → contract_store/contract_store.d.ts} +7 -4
- package/dest/storage/contract_store/contract_store.d.ts.map +1 -0
- package/dest/storage/{contract_data_provider/contract_data_provider.js → contract_store/contract_store.js} +46 -3
- package/dest/storage/contract_store/index.d.ts +2 -0
- package/dest/storage/contract_store/index.d.ts.map +1 -0
- package/dest/storage/contract_store/index.js +1 -0
- package/dest/storage/{contract_data_provider → contract_store}/private_functions_tree.d.ts +1 -1
- package/dest/storage/contract_store/private_functions_tree.d.ts.map +1 -0
- package/dest/storage/index.d.ts +8 -8
- package/dest/storage/index.d.ts.map +1 -1
- package/dest/storage/index.js +7 -7
- package/dest/storage/note_store/index.d.ts +3 -0
- package/dest/storage/note_store/index.d.ts.map +1 -0
- package/dest/storage/note_store/index.js +2 -0
- package/dest/storage/{note_data_provider/note_data_provider.d.ts → note_store/note_store.d.ts} +7 -7
- package/dest/storage/note_store/note_store.d.ts.map +1 -0
- package/dest/storage/{note_data_provider/note_data_provider.js → note_store/note_store.js} +6 -6
- package/dest/storage/{private_event_data_provider/private_event_data_provider.d.ts → private_event_store/private_event_store.d.ts} +9 -4
- package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -0
- package/dest/storage/{private_event_data_provider/private_event_data_provider.js → private_event_store/private_event_store.js} +57 -15
- package/dest/storage/tagging_store/index.d.ts +4 -0
- package/dest/storage/tagging_store/index.d.ts.map +1 -0
- package/dest/storage/tagging_store/index.js +3 -0
- package/dest/storage/tagging_store/recipient_tagging_store.d.ts +21 -0
- package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -0
- package/dest/storage/tagging_store/recipient_tagging_store.js +42 -0
- package/dest/storage/tagging_store/sender_address_book_store.d.ts +14 -0
- package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +1 -0
- package/dest/storage/tagging_store/sender_address_book_store.js +30 -0
- package/dest/storage/tagging_store/sender_tagging_store.d.ts +67 -0
- package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -0
- package/dest/storage/tagging_store/sender_tagging_store.js +196 -0
- package/dest/tagging/index.d.ts +15 -6
- package/dest/tagging/index.d.ts.map +1 -1
- package/dest/tagging/index.js +23 -5
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +14 -0
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -0
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +99 -0
- package/dest/tagging/recipient_sync/utils/find_highest_indexes.d.ts +12 -0
- package/dest/tagging/recipient_sync/utils/find_highest_indexes.d.ts.map +1 -0
- package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +20 -0
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +14 -0
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -0
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +29 -0
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +20 -0
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -0
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +74 -0
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +11 -0
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -0
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +32 -0
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +18 -0
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -0
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +55 -0
- package/dest/tree_membership/tree_membership_service.d.ts +52 -0
- package/dest/tree_membership/tree_membership_service.d.ts.map +1 -0
- package/dest/tree_membership/tree_membership_service.js +84 -0
- package/package.json +16 -16
- package/src/{synchronizer/synchronizer.ts → block_synchronizer/block_synchronizer.ts} +21 -22
- package/src/block_synchronizer/index.ts +1 -0
- package/src/config/index.ts +3 -3
- package/src/config/package_info.ts +1 -1
- package/src/contract_function_simulator/contract_function_simulator.ts +84 -15
- package/src/contract_function_simulator/execution_tagging_index_cache.ts +1 -1
- package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +5 -4
- package/src/contract_function_simulator/oracle/interfaces.ts +2 -3
- package/src/contract_function_simulator/oracle/oracle.ts +3 -3
- package/src/contract_function_simulator/oracle/private_execution.ts +14 -13
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +89 -19
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +208 -45
- package/src/contract_function_simulator/proxied_contract_data_source.ts +24 -7
- package/src/debug/pxe_debug_utils.ts +48 -0
- package/src/entrypoints/client/bundle/index.ts +0 -1
- package/src/entrypoints/client/bundle/utils.ts +7 -1
- package/src/entrypoints/client/lazy/index.ts +0 -1
- package/src/entrypoints/client/lazy/utils.ts +7 -2
- package/src/entrypoints/pxe_creation_options.ts +2 -1
- package/src/entrypoints/server/index.ts +1 -1
- package/src/entrypoints/server/utils.ts +11 -15
- package/src/error_enriching.ts +7 -15
- package/src/events/event_service.ts +77 -0
- package/src/events/private_event_filter_validator.ts +5 -4
- package/src/logs/log_service.ts +202 -0
- package/src/notes/index.ts +1 -0
- package/src/notes/note_service.ts +200 -0
- package/src/private_kernel/private_kernel_oracle_impl.ts +6 -6
- package/src/public_storage/public_storage_service.ts +33 -0
- package/src/pxe.ts +153 -162
- package/src/storage/{address_data_provider/address_data_provider.ts → address_store/address_store.ts} +1 -1
- package/src/storage/address_store/index.ts +1 -0
- package/src/storage/{sync_data_provider/sync_data_provider.ts → anchor_block_store/anchor_block_store.ts} +2 -12
- package/src/storage/anchor_block_store/index.ts +1 -0
- package/src/storage/{capsule_data_provider/capsule_data_provider.ts → capsule_store/capsule_store.ts} +33 -1
- package/src/storage/capsule_store/index.ts +1 -0
- package/src/storage/{contract_data_provider/contract_data_provider.ts → contract_store/contract_store.ts} +64 -2
- package/src/storage/contract_store/index.ts +1 -0
- package/src/storage/index.ts +7 -7
- package/src/storage/note_store/index.ts +2 -0
- package/src/storage/{note_data_provider/note_data_provider.ts → note_store/note_store.ts} +7 -7
- package/src/storage/{private_event_data_provider/private_event_data_provider.ts → private_event_store/private_event_store.ts} +69 -18
- package/src/storage/tagging_store/index.ts +3 -0
- package/src/storage/tagging_store/recipient_tagging_store.ts +53 -0
- package/src/storage/tagging_store/sender_address_book_store.ts +42 -0
- package/src/storage/tagging_store/sender_tagging_store.ts +244 -0
- package/src/tagging/index.ts +27 -5
- package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +129 -0
- package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +34 -0
- package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +43 -0
- package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +96 -0
- package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +44 -0
- package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +72 -0
- package/src/tree_membership/tree_membership_service.ts +112 -0
- package/dest/contract_function_simulator/execution_data_provider.d.ts +0 -268
- package/dest/contract_function_simulator/execution_data_provider.d.ts.map +0 -1
- package/dest/contract_function_simulator/execution_data_provider.js +0 -14
- package/dest/contract_function_simulator/pxe_oracle_interface.d.ts +0 -124
- package/dest/contract_function_simulator/pxe_oracle_interface.d.ts.map +0 -1
- package/dest/contract_function_simulator/pxe_oracle_interface.js +0 -713
- package/dest/storage/address_data_provider/address_data_provider.d.ts +0 -11
- package/dest/storage/address_data_provider/address_data_provider.d.ts.map +0 -1
- package/dest/storage/address_data_provider/index.d.ts +0 -2
- package/dest/storage/address_data_provider/index.d.ts.map +0 -1
- package/dest/storage/address_data_provider/index.js +0 -1
- package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts +0 -25
- package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts.map +0 -1
- package/dest/storage/capsule_data_provider/index.d.ts +0 -2
- package/dest/storage/capsule_data_provider/index.d.ts.map +0 -1
- package/dest/storage/capsule_data_provider/index.js +0 -1
- package/dest/storage/contract_data_provider/contract_data_provider.d.ts.map +0 -1
- package/dest/storage/contract_data_provider/index.d.ts +0 -2
- package/dest/storage/contract_data_provider/index.d.ts.map +0 -1
- package/dest/storage/contract_data_provider/index.js +0 -1
- package/dest/storage/contract_data_provider/private_functions_tree.d.ts.map +0 -1
- package/dest/storage/note_data_provider/index.d.ts +0 -3
- package/dest/storage/note_data_provider/index.d.ts.map +0 -1
- package/dest/storage/note_data_provider/index.js +0 -2
- package/dest/storage/note_data_provider/note_data_provider.d.ts.map +0 -1
- package/dest/storage/private_event_data_provider/private_event_data_provider.d.ts.map +0 -1
- package/dest/storage/sync_data_provider/index.d.ts.map +0 -1
- package/dest/storage/sync_data_provider/index.js +0 -1
- package/dest/storage/sync_data_provider/sync_data_provider.d.ts.map +0 -1
- package/dest/storage/tagging_data_provider/index.d.ts +0 -2
- package/dest/storage/tagging_data_provider/index.d.ts.map +0 -1
- package/dest/storage/tagging_data_provider/index.js +0 -1
- package/dest/storage/tagging_data_provider/tagging_data_provider.d.ts +0 -40
- package/dest/storage/tagging_data_provider/tagging_data_provider.d.ts.map +0 -1
- package/dest/storage/tagging_data_provider/tagging_data_provider.js +0 -89
- package/dest/synchronizer/index.d.ts +0 -2
- package/dest/synchronizer/index.d.ts.map +0 -1
- package/dest/synchronizer/index.js +0 -1
- package/dest/synchronizer/synchronizer.d.ts +0 -36
- package/dest/synchronizer/synchronizer.d.ts.map +0 -1
- package/dest/tagging/constants.d.ts +0 -2
- package/dest/tagging/constants.d.ts.map +0 -1
- package/dest/tagging/constants.js +0 -2
- package/dest/tagging/siloed_tag.d.ts +0 -14
- package/dest/tagging/siloed_tag.d.ts.map +0 -1
- package/dest/tagging/siloed_tag.js +0 -20
- package/dest/tagging/tag.d.ts +0 -12
- package/dest/tagging/tag.d.ts.map +0 -1
- package/dest/tagging/tag.js +0 -17
- package/dest/tagging/utils.d.ts +0 -18
- package/dest/tagging/utils.d.ts.map +0 -1
- package/dest/tagging/utils.js +0 -24
- package/src/contract_function_simulator/execution_data_provider.ts +0 -343
- package/src/contract_function_simulator/pxe_oracle_interface.ts +0 -1040
- package/src/storage/address_data_provider/index.ts +0 -1
- package/src/storage/capsule_data_provider/index.ts +0 -1
- package/src/storage/contract_data_provider/index.ts +0 -1
- package/src/storage/note_data_provider/index.ts +0 -2
- package/src/storage/sync_data_provider/index.ts +0 -1
- package/src/storage/tagging_data_provider/index.ts +0 -1
- package/src/storage/tagging_data_provider/tagging_data_provider.ts +0 -120
- package/src/synchronizer/index.ts +0 -1
- package/src/tagging/constants.ts +0 -2
- package/src/tagging/siloed_tag.ts +0 -22
- package/src/tagging/tag.ts +0 -16
- package/src/tagging/utils.ts +0 -31
- /package/dest/storage/{contract_data_provider → contract_store}/private_functions_tree.js +0 -0
- /package/src/storage/{contract_data_provider → contract_store}/private_functions_tree.ts +0 -0
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { toArray } from '@aztec/foundation/iterable';
|
|
2
|
+
import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
|
|
3
|
+
import type { DirectionalAppTaggingSecret, PreTag } from '@aztec/stdlib/logs';
|
|
4
|
+
import { TxHash } from '@aztec/stdlib/tx';
|
|
5
|
+
|
|
6
|
+
import { UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN } from '../../tagging/index.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Data provider of tagging data used when syncing the sender tagging indexes. The recipient counterpart of this class
|
|
10
|
+
* is called RecipientTaggingStore. We have the providers separate for the sender and recipient because
|
|
11
|
+
* the algorithms are completely disjoint and there is not data reuse between the two.
|
|
12
|
+
*/
|
|
13
|
+
export class SenderTaggingStore {
|
|
14
|
+
#store: AztecAsyncKVStore;
|
|
15
|
+
|
|
16
|
+
// Stores the pending indexes for each directional app tagging secret. Pending here means that the tx that contained
|
|
17
|
+
// the private logs with tags corresponding to these indexes has not been finalized yet.
|
|
18
|
+
//
|
|
19
|
+
// We don't store just the highest index because if their transaction is dropped we'd then need the information about
|
|
20
|
+
// the lower pending indexes. For each secret-tx pair however we only store the largest index used in that tx, since
|
|
21
|
+
// the smaller ones are irrelevant due to tx atomicity.
|
|
22
|
+
//
|
|
23
|
+
// TODO(#17615): This assumes no logs are used in the non-revertible phase.
|
|
24
|
+
#pendingIndexes: AztecAsyncMap<string, { index: number; txHash: string }[]>;
|
|
25
|
+
|
|
26
|
+
// Stores the last (highest) finalized index for each directional app tagging secret. We care only about the last
|
|
27
|
+
// index because unlike the pending indexes, it will never happen that a finalized index would be removed and hence
|
|
28
|
+
// we don't need to store the history.
|
|
29
|
+
#lastFinalizedIndexes: AztecAsyncMap<string, number>;
|
|
30
|
+
|
|
31
|
+
constructor(store: AztecAsyncKVStore) {
|
|
32
|
+
this.#store = store;
|
|
33
|
+
|
|
34
|
+
this.#pendingIndexes = this.#store.openMap('pending_indexes');
|
|
35
|
+
this.#lastFinalizedIndexes = this.#store.openMap('last_finalized_indexes');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Stores pending indexes.
|
|
40
|
+
* @remarks Ignores the index if the same preTag + txHash combination already exists in the db with the same index.
|
|
41
|
+
* This is expected to happen because whenever we start sync we start from the last finalized index and we can have
|
|
42
|
+
* pending indexes already stored from previous syncs.
|
|
43
|
+
* @param preTags - The pre-tags containing the directional app tagging secrets and the indexes that are to be
|
|
44
|
+
* stored in the db.
|
|
45
|
+
* @param txHash - The tx in which the pretags were used in private logs.
|
|
46
|
+
* @throws If any two pre-tags contain the same directional app tagging secret. This is enforced because we care
|
|
47
|
+
* only about the highest index for a given secret that was used in the tx. Hence this check is a good way to catch
|
|
48
|
+
* bugs.
|
|
49
|
+
* @throws If the newly stored pending index is further than window length from the highest finalized index for the
|
|
50
|
+
* same secret. This is enforced in order to give a guarantee to a recipient that he doesn't need to look further than
|
|
51
|
+
* window length ahead of the highest finalized index.
|
|
52
|
+
* @throws If a secret + txHash pair already exists in the db with a different index value. It should never happen
|
|
53
|
+
* that we would attempt to store a different index for a given secret-txHash pair because we always store just the
|
|
54
|
+
* highest index for a given secret-txHash pair. Hence this is a good way to catch bugs.
|
|
55
|
+
* @throws If the newly stored pending index is lower than or equal to the last finalized index for the same secret.
|
|
56
|
+
* This is enforced because this should never happen if the syncing is done correctly as we look for logs from higher
|
|
57
|
+
* indexes than finalized ones.
|
|
58
|
+
*/
|
|
59
|
+
async storePendingIndexes(preTags: PreTag[], txHash: TxHash) {
|
|
60
|
+
// The secrets in pre-tags should be unique because we always store just the highest index per given secret-txHash
|
|
61
|
+
// pair. Below we check that this is the case.
|
|
62
|
+
const secretsSet = new Set(preTags.map(preTag => preTag.secret.toString()));
|
|
63
|
+
if (secretsSet.size !== preTags.length) {
|
|
64
|
+
throw new Error(`Duplicate secrets found when storing pending indexes`);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
for (const { secret, index } of preTags) {
|
|
68
|
+
// First we check that for any secret the highest used index in tx is not further than window length from
|
|
69
|
+
// the highest finalized index.
|
|
70
|
+
const finalizedIndex = (await this.getLastFinalizedIndex(secret)) ?? 0;
|
|
71
|
+
if (index > finalizedIndex + UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN) {
|
|
72
|
+
throw new Error(
|
|
73
|
+
`Highest used index ${index} is further than window length from the highest finalized index ${finalizedIndex}.
|
|
74
|
+
Tagging window length ${UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN} is configured too low. Contact the Aztec team
|
|
75
|
+
to increase it!`,
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Throw if the new pending index is lower than or equal to the last finalized index
|
|
80
|
+
const secretStr = secret.toString();
|
|
81
|
+
const lastFinalizedIndex = await this.#lastFinalizedIndexes.getAsync(secretStr);
|
|
82
|
+
if (lastFinalizedIndex !== undefined && index <= lastFinalizedIndex) {
|
|
83
|
+
throw new Error(
|
|
84
|
+
`Cannot store pending index ${index} for secret ${secretStr}: ` +
|
|
85
|
+
`it is lower than or equal to the last finalized index ${lastFinalizedIndex}`,
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Check if this secret + txHash combination already exists
|
|
90
|
+
const txHashStr = txHash.toString();
|
|
91
|
+
const existingForSecret = (await this.#pendingIndexes.getAsync(secretStr)) ?? [];
|
|
92
|
+
const existingForSecretAndTx = existingForSecret.find(entry => entry.txHash === txHashStr);
|
|
93
|
+
|
|
94
|
+
if (existingForSecretAndTx) {
|
|
95
|
+
// If it exists with a different index, throw an error
|
|
96
|
+
if (existingForSecretAndTx.index !== index) {
|
|
97
|
+
throw new Error(
|
|
98
|
+
`Cannot store index ${index} for secret ${secretStr} and txHash ${txHashStr}: ` +
|
|
99
|
+
`a different index ${existingForSecretAndTx.index} already exists for this secret-txHash pair`,
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
// If it exists with the same index, ignore the update (no-op)
|
|
103
|
+
} else {
|
|
104
|
+
// If it doesn't exist, add it
|
|
105
|
+
await this.#pendingIndexes.set(secretStr, [...existingForSecret, { index, txHash: txHashStr }]);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Returns the transaction hashes of all pending transactions that contain indexes within a specified range
|
|
112
|
+
* for a given directional app tagging secret.
|
|
113
|
+
* @param secret - The directional app tagging secret to query pending indexes for.
|
|
114
|
+
* @param startIndex - The lower bound of the index range (inclusive).
|
|
115
|
+
* @param endIndex - The upper bound of the index range (exclusive).
|
|
116
|
+
* @returns An array of unique transaction hashes for pending transactions that contain indexes in the range
|
|
117
|
+
* [startIndex, endIndex). Returns an empty array if no pending indexes exist in the range.
|
|
118
|
+
*/
|
|
119
|
+
async getTxHashesOfPendingIndexes(
|
|
120
|
+
secret: DirectionalAppTaggingSecret,
|
|
121
|
+
startIndex: number,
|
|
122
|
+
endIndex: number,
|
|
123
|
+
): Promise<TxHash[]> {
|
|
124
|
+
const existing = (await this.#pendingIndexes.getAsync(secret.toString())) ?? [];
|
|
125
|
+
const txHashes = existing
|
|
126
|
+
.filter(entry => entry.index >= startIndex && entry.index < endIndex)
|
|
127
|
+
.map(entry => entry.txHash);
|
|
128
|
+
return Array.from(new Set(txHashes)).map(TxHash.fromString);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Returns the last (highest) finalized index for a given secret.
|
|
133
|
+
* @param secret - The secret to get the last finalized index for.
|
|
134
|
+
* @returns The last (highest) finalized index for the given secret.
|
|
135
|
+
*/
|
|
136
|
+
getLastFinalizedIndex(secret: DirectionalAppTaggingSecret): Promise<number | undefined> {
|
|
137
|
+
return this.#lastFinalizedIndexes.getAsync(secret.toString());
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Returns the last used index for a given directional app tagging secret, considering both finalized and pending
|
|
142
|
+
* indexes.
|
|
143
|
+
* @param secret - The directional app tagging secret to query the last used index for.
|
|
144
|
+
* @returns The last used index.
|
|
145
|
+
*/
|
|
146
|
+
async getLastUsedIndex(secret: DirectionalAppTaggingSecret): Promise<number | undefined> {
|
|
147
|
+
const secretStr = secret.toString();
|
|
148
|
+
const pendingTxScopedIndexes = (await this.#pendingIndexes.getAsync(secretStr)) ?? [];
|
|
149
|
+
const pendingIndexes = pendingTxScopedIndexes.map(entry => entry.index);
|
|
150
|
+
|
|
151
|
+
if (pendingTxScopedIndexes.length === 0) {
|
|
152
|
+
return this.#lastFinalizedIndexes.getAsync(secretStr);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// As the last used index we return the highest one from the pending indexes. Note that this value will be always
|
|
156
|
+
// higher than the last finalized index because we prune lower pending indexes when a tx is finalized.
|
|
157
|
+
return Math.max(...pendingIndexes);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Drops all pending indexes corresponding to the given transaction hashes.
|
|
162
|
+
*/
|
|
163
|
+
async dropPendingIndexes(txHashes: TxHash[]) {
|
|
164
|
+
if (txHashes.length === 0) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const txHashStrs = new Set<string>(txHashes.map(txHash => txHash.toString()));
|
|
169
|
+
const allSecrets = await toArray(this.#pendingIndexes.keysAsync());
|
|
170
|
+
|
|
171
|
+
for (const secret of allSecrets) {
|
|
172
|
+
const pendingData = await this.#pendingIndexes.getAsync(secret);
|
|
173
|
+
if (pendingData) {
|
|
174
|
+
const filtered = pendingData.filter(item => !txHashStrs.has(item.txHash));
|
|
175
|
+
if (filtered.length === 0) {
|
|
176
|
+
await this.#pendingIndexes.delete(secret);
|
|
177
|
+
} else if (filtered.length !== pendingData.length) {
|
|
178
|
+
// Some items were filtered out, so update the pending data
|
|
179
|
+
await this.#pendingIndexes.set(secret, filtered);
|
|
180
|
+
}
|
|
181
|
+
// else: No items were filtered out (txHashes not found for this secret) --> no-op
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Updates pending indexes corresponding to the given transaction hashes to be finalized and prunes any lower pending
|
|
188
|
+
* indexes.
|
|
189
|
+
*/
|
|
190
|
+
async finalizePendingIndexes(txHashes: TxHash[]) {
|
|
191
|
+
if (txHashes.length === 0) {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
for (const txHash of txHashes) {
|
|
196
|
+
const txHashStr = txHash.toString();
|
|
197
|
+
|
|
198
|
+
const allSecrets = await toArray(this.#pendingIndexes.keysAsync());
|
|
199
|
+
|
|
200
|
+
for (const secret of allSecrets) {
|
|
201
|
+
const pendingData = await this.#pendingIndexes.getAsync(secret);
|
|
202
|
+
if (!pendingData) {
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const matchingIndexes = pendingData.filter(item => item.txHash === txHashStr).map(item => item.index);
|
|
207
|
+
if (matchingIndexes.length === 0) {
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (matchingIndexes.length > 1) {
|
|
212
|
+
// We should always just store the highest pending index for a given tx hash and secret because the lower
|
|
213
|
+
// values are irrelevant.
|
|
214
|
+
throw new Error(`Multiple pending indexes found for tx hash ${txHashStr} and secret ${secret}`);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
let lastFinalized = await this.#lastFinalizedIndexes.getAsync(secret);
|
|
218
|
+
const newFinalized = matchingIndexes[0];
|
|
219
|
+
|
|
220
|
+
if (newFinalized < (lastFinalized ?? 0)) {
|
|
221
|
+
// This should never happen because when last finalized index was finalized we should have pruned the lower
|
|
222
|
+
// pending indexes.
|
|
223
|
+
throw new Error(
|
|
224
|
+
`New finalized index ${newFinalized} is smaller than the current last finalized index ${lastFinalized}`,
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
await this.#lastFinalizedIndexes.set(secret, newFinalized);
|
|
229
|
+
lastFinalized = newFinalized;
|
|
230
|
+
|
|
231
|
+
// When we add pending indexes, we ensure they are higher than the last finalized index. However, because we
|
|
232
|
+
// cannot control the order in which transactions are finalized, there may be pending indexes that are now
|
|
233
|
+
// obsolete because they are lower than the most recently finalized index. For this reason, we prune these
|
|
234
|
+
// outdated pending indexes.
|
|
235
|
+
const remainingItemsOfHigherIndex = pendingData.filter(item => item.index > (lastFinalized ?? 0));
|
|
236
|
+
if (remainingItemsOfHigherIndex.length === 0) {
|
|
237
|
+
await this.#pendingIndexes.delete(secret);
|
|
238
|
+
} else {
|
|
239
|
+
await this.#pendingIndexes.set(secret, remainingItemsOfHigherIndex);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
package/src/tagging/index.ts
CHANGED
|
@@ -1,6 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
/**
|
|
2
|
+
* This directory contains the sender and recipient synchronization algorithms that use tagging.
|
|
3
|
+
*
|
|
4
|
+
* The objective of the sender sync algorithm is to determine which tags have already been used by a sender, thereby
|
|
5
|
+
* deciding which tag should be used next.
|
|
6
|
+
*
|
|
7
|
+
* The objective of the recipient sync algorithm is to load and process the corresponding logs.
|
|
8
|
+
*
|
|
9
|
+
* @module tagging
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export { loadPrivateLogsForSenderRecipientPair } from './recipient_sync/load_private_logs_for_sender_recipient_pair.js';
|
|
13
|
+
export { syncSenderTaggingIndexes } from './sender_sync/sync_sender_tagging_indexes.js';
|
|
14
|
+
|
|
15
|
+
// This window has to be as large as the largest expected number of logs emitted in a tx for a given directional app
|
|
16
|
+
// tagging secret. If we get more tag indexes consumed than this window, an error is thrown in `PXE::proveTx` function.
|
|
17
|
+
// This is set to a larger value than MAX_PRIVATE_LOGS_PER_TX (currently 64) because there could be more than
|
|
18
|
+
// MAX_PRIVATE_LOGS_PER_TX indexes consumed in case the logs are squashed. This happens when the log contains a note
|
|
19
|
+
// and the note is nullified in the same tx.
|
|
20
|
+
//
|
|
21
|
+
// Having a large window significantly slowed down `e2e_l1_with_wall_time` test as there we perform sync for more than
|
|
22
|
+
// 1000 secrets. For this reason we set it to a relatively low value of 20. 20 should be sufficient for all the use
|
|
23
|
+
// cases.
|
|
24
|
+
export const UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN = 20;
|
|
25
|
+
|
|
26
|
+
// Re-export tagging-related types from stdlib
|
|
27
|
+
export { DirectionalAppTaggingSecret, Tag, SiloedTag } from '@aztec/stdlib/logs';
|
|
6
28
|
export { type PreTag } from '@aztec/stdlib/logs';
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import type { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
3
|
+
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
4
|
+
import type { DirectionalAppTaggingSecret, TxScopedL2Log } from '@aztec/stdlib/logs';
|
|
5
|
+
|
|
6
|
+
import type { RecipientTaggingStore } from '../../storage/tagging_store/recipient_tagging_store.js';
|
|
7
|
+
import { UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN } from '../index.js';
|
|
8
|
+
import { findHighestIndexes } from './utils/find_highest_indexes.js';
|
|
9
|
+
import { loadLogsForRange } from './utils/load_logs_for_range.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Loads private logs for `app` and sender-recipient pair defined by `secret` and updates the highest aged and
|
|
13
|
+
* finalized indexes in the db. At most load logs from blocks up to and including `anchorBlockNumber`.
|
|
14
|
+
*
|
|
15
|
+
* @dev This function can be safely executed "in parallel" for other sender-recipient pairs because the data in
|
|
16
|
+
* in the tagging data provider is indexed by the secret and hence completely disjoint.
|
|
17
|
+
*/
|
|
18
|
+
export async function loadPrivateLogsForSenderRecipientPair(
|
|
19
|
+
secret: DirectionalAppTaggingSecret,
|
|
20
|
+
app: AztecAddress,
|
|
21
|
+
aztecNode: AztecNode,
|
|
22
|
+
taggingStore: RecipientTaggingStore,
|
|
23
|
+
anchorBlockNumber: BlockNumber,
|
|
24
|
+
): Promise<TxScopedL2Log[]> {
|
|
25
|
+
// # Explanation of how the algorithm works
|
|
26
|
+
// When we perform the sync we will look at logs that correspond to the tagging index range
|
|
27
|
+
// (highestAgedIndex, highestFinalizedIndex + WINDOW_LEN]
|
|
28
|
+
//
|
|
29
|
+
// highestAgedIndex is the highest index that was used in a tx that is included in a block at least
|
|
30
|
+
// `MAX_INCLUDE_BY_TIMESTAMP_DURATION` seconds ago.
|
|
31
|
+
// highestFinalizedIndex is the highest index that was used in a tx that is included in a finalized block.
|
|
32
|
+
//
|
|
33
|
+
// "(" denotes an open end of the range - the index is not included in the range.
|
|
34
|
+
// "]" denotes a closed end of the range - the index is included in the range.
|
|
35
|
+
//
|
|
36
|
+
// ## Explanation of highestAgedIndex
|
|
37
|
+
//
|
|
38
|
+
// highestAgedIndex is chosen such that for all tagging indexes `i <= highestAgedIndex` we know that no new logs can
|
|
39
|
+
// ever appear.
|
|
40
|
+
//
|
|
41
|
+
// This relies on the "maximum inclusion timestamp" rule enforced by the kernel and rollup circuits:
|
|
42
|
+
// - a transaction's maximum inclusion timestamp is at most `MAX_INCLUDE_BY_TIMESTAMP_DURATION` seconds after
|
|
43
|
+
// the timestamp of its anchor block; and
|
|
44
|
+
// - a rollup only includes transactions whose inclusion timestamp is >= the L2 block's timestamp.
|
|
45
|
+
//
|
|
46
|
+
// Suppose some device used index `I` in a transaction anchored to block `B_N` at time `N`, and that block is now at
|
|
47
|
+
// least `MAX_INCLUDE_BY_TIMESTAMP_DURATION` seconds in the past. Then there is no possibility of any *other* device
|
|
48
|
+
// trying to use an index <= `I` while anchoring to a *newer* block than `B_N` because if we were anchoring to
|
|
49
|
+
// a newer block than `B_N` then we would already have seen the log with index `I` and hence the device would have
|
|
50
|
+
// chosen a larger index.
|
|
51
|
+
// If that *other* device would anchor to a block older than `B_N` then that tx could never be included in a block
|
|
52
|
+
// because it would already have been expired.
|
|
53
|
+
//
|
|
54
|
+
// Therefore, once we see that index `I` has been used in a block that is at least `MAX_INCLUDE_BY_TIMESTAMP_DURATION`
|
|
55
|
+
// seconds old, we can safely stop syncing logs for all indexes <= `I` and set highestAgedIndex = `I`.
|
|
56
|
+
//
|
|
57
|
+
// ## Explanation of the upper bound `highestFinalizedIndex + WINDOW_LEN`
|
|
58
|
+
//
|
|
59
|
+
// When a sender chooses a tagging index, they will select an index that is at most `WINDOW_LEN` greater than
|
|
60
|
+
// the highest finalized index. If that index was already used, they will throw an error. For this reason we
|
|
61
|
+
// don't have to look further than `highestFinalizedIndex + WINDOW_LEN`.
|
|
62
|
+
|
|
63
|
+
let finalizedBlockNumber: number, currentTimestamp: bigint;
|
|
64
|
+
{
|
|
65
|
+
const [l2Tips, latestBlockHeader] = await Promise.all([aztecNode.getL2Tips(), aztecNode.getBlockHeader('latest')]);
|
|
66
|
+
|
|
67
|
+
if (!latestBlockHeader) {
|
|
68
|
+
throw new Error('Node failed to return latest block header when syncing logs');
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
[finalizedBlockNumber, currentTimestamp] = [l2Tips.finalized.number, latestBlockHeader.globalVariables.timestamp];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
let start: number, end: number;
|
|
75
|
+
{
|
|
76
|
+
const currentHighestAgedIndex = await taggingStore.getHighestAgedIndex(secret);
|
|
77
|
+
const currentHighestFinalizedIndex = await taggingStore.getHighestFinalizedIndex(secret);
|
|
78
|
+
|
|
79
|
+
// We don't want to include the highest aged index so we start from `currentHighestAgedIndex + 1` (or 0 if not set)
|
|
80
|
+
start = currentHighestAgedIndex === undefined ? 0 : currentHighestAgedIndex + 1;
|
|
81
|
+
|
|
82
|
+
// The highest index a sender can choose is "highest finalized index + window length" but given that
|
|
83
|
+
// `loadLogsForRange` expects an exclusive `end` we add 1.
|
|
84
|
+
end = (currentHighestFinalizedIndex ?? 0) + UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN + 1;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const logs: TxScopedL2Log[] = [];
|
|
88
|
+
|
|
89
|
+
while (true) {
|
|
90
|
+
// Get private logs with their block timestamps and corresponding tagging indexes
|
|
91
|
+
const privateLogsWithIndexes = await loadLogsForRange(secret, app, aztecNode, start, end, anchorBlockNumber);
|
|
92
|
+
|
|
93
|
+
if (privateLogsWithIndexes.length === 0) {
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
logs.push(...privateLogsWithIndexes.map(({ log }) => log));
|
|
98
|
+
|
|
99
|
+
const { highestAgedIndex, highestFinalizedIndex } = findHighestIndexes(
|
|
100
|
+
privateLogsWithIndexes,
|
|
101
|
+
currentTimestamp,
|
|
102
|
+
finalizedBlockNumber,
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
// Store updates in data provider and update local variables
|
|
106
|
+
if (highestAgedIndex !== undefined) {
|
|
107
|
+
await taggingStore.updateHighestAgedIndex(secret, highestAgedIndex);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (highestFinalizedIndex === undefined) {
|
|
111
|
+
// We have not found a new highest finalized index, so there is no need to move the window forward.
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (highestAgedIndex !== undefined && highestAgedIndex > highestFinalizedIndex) {
|
|
116
|
+
// This is just a sanity check as this should never happen.
|
|
117
|
+
throw new Error('Highest aged index lower than highest finalized index invariant violated');
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
await taggingStore.updateHighestFinalizedIndex(secret, highestFinalizedIndex);
|
|
121
|
+
|
|
122
|
+
// For the next iteration we want to look only at indexes for which we have not attempted to load logs yet while
|
|
123
|
+
// ensuring that we do not look further than WINDOW_LEN ahead of the highest finalized index.
|
|
124
|
+
start = end;
|
|
125
|
+
end = highestFinalizedIndex + UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN + 1; // `end` is exclusive so we add 1.
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return logs;
|
|
129
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { MAX_INCLUDE_BY_TIMESTAMP_DURATION } from '@aztec/constants';
|
|
2
|
+
import type { TxScopedL2Log } from '@aztec/stdlib/logs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Finds the highest aged and the highest finalized tagging indexes.
|
|
6
|
+
*/
|
|
7
|
+
export function findHighestIndexes(
|
|
8
|
+
privateLogsWithIndexes: Array<{ log: TxScopedL2Log; taggingIndex: number }>,
|
|
9
|
+
currentTimestamp: bigint,
|
|
10
|
+
finalizedBlockNumber: number,
|
|
11
|
+
): { highestAgedIndex: number | undefined; highestFinalizedIndex: number | undefined } {
|
|
12
|
+
let highestAgedIndex = undefined;
|
|
13
|
+
let highestFinalizedIndex = undefined;
|
|
14
|
+
|
|
15
|
+
for (const { log, taggingIndex } of privateLogsWithIndexes) {
|
|
16
|
+
const ageInSeconds = currentTimestamp - log.blockTimestamp;
|
|
17
|
+
|
|
18
|
+
if (
|
|
19
|
+
ageInSeconds >= BigInt(MAX_INCLUDE_BY_TIMESTAMP_DURATION) &&
|
|
20
|
+
(highestAgedIndex === undefined || taggingIndex > highestAgedIndex)
|
|
21
|
+
) {
|
|
22
|
+
highestAgedIndex = taggingIndex;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (
|
|
26
|
+
log.blockNumber <= finalizedBlockNumber &&
|
|
27
|
+
(highestFinalizedIndex === undefined || taggingIndex > highestFinalizedIndex)
|
|
28
|
+
) {
|
|
29
|
+
highestFinalizedIndex = taggingIndex;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return { highestAgedIndex, highestFinalizedIndex };
|
|
34
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
3
|
+
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
4
|
+
import type { DirectionalAppTaggingSecret, PreTag, TxScopedL2Log } from '@aztec/stdlib/logs';
|
|
5
|
+
import { SiloedTag, Tag } from '@aztec/stdlib/logs';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Gets private logs with their corresponding block timestamps and tagging indexes for the given index range, `app` and
|
|
9
|
+
* `secret`. At most load logs from blocks up to and including `anchorBlockNumber`. `start` is inclusive and `end` is
|
|
10
|
+
* exclusive.
|
|
11
|
+
*/
|
|
12
|
+
export async function loadLogsForRange(
|
|
13
|
+
secret: DirectionalAppTaggingSecret,
|
|
14
|
+
app: AztecAddress,
|
|
15
|
+
aztecNode: AztecNode,
|
|
16
|
+
start: number,
|
|
17
|
+
end: number,
|
|
18
|
+
anchorBlockNumber: BlockNumber,
|
|
19
|
+
): Promise<Array<{ log: TxScopedL2Log; taggingIndex: number }>> {
|
|
20
|
+
// Derive tags for the window
|
|
21
|
+
const preTags: PreTag[] = Array(end - start)
|
|
22
|
+
.fill(0)
|
|
23
|
+
.map((_, i) => ({ secret, index: start + i }));
|
|
24
|
+
const siloedTags = await Promise.all(preTags.map(preTag => Tag.compute(preTag))).then(tags =>
|
|
25
|
+
Promise.all(tags.map(tag => SiloedTag.compute(tag, app))),
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
const logs = await aztecNode.getPrivateLogsByTags(siloedTags);
|
|
29
|
+
|
|
30
|
+
// Pair logs with their corresponding tagging indexes
|
|
31
|
+
const logsWithIndexes: Array<{ log: TxScopedL2Log; taggingIndex: number }> = [];
|
|
32
|
+
for (let i = 0; i < logs.length; i++) {
|
|
33
|
+
const logsForTag = logs[i];
|
|
34
|
+
const taggingIndex = preTags[i].index;
|
|
35
|
+
for (const log of logsForTag) {
|
|
36
|
+
if (log.blockNumber <= anchorBlockNumber) {
|
|
37
|
+
logsWithIndexes.push({ log, taggingIndex });
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return logsWithIndexes;
|
|
43
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
2
|
+
import type { AztecNode } from '@aztec/stdlib/interfaces/server';
|
|
3
|
+
import type { DirectionalAppTaggingSecret } from '@aztec/stdlib/logs';
|
|
4
|
+
|
|
5
|
+
import type { SenderTaggingStore } from '../../storage/tagging_store/sender_tagging_store.js';
|
|
6
|
+
import { UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN } from '../index.js';
|
|
7
|
+
import { getStatusChangeOfPending } from './utils/get_status_change_of_pending.js';
|
|
8
|
+
import { loadAndStoreNewTaggingIndexes } from './utils/load_and_store_new_tagging_indexes.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Syncs tagging indexes. This function needs to be called whenever a private log is being sent.
|
|
12
|
+
*
|
|
13
|
+
* @param secret - The secret that's unique for (sender, recipient, contract) tuple while the direction of
|
|
14
|
+
* sender -> recipient matters.
|
|
15
|
+
* @param app - The address of the contract that the logs are tagged for. Needs to be provided because we perform
|
|
16
|
+
* second round of siloing in this function which is necessary because kernels do it as well (they silo first field
|
|
17
|
+
* of the private log which corresponds to the tag).
|
|
18
|
+
* @remarks When syncing the indexes as sender we don't care about the log contents - we only care about the highest
|
|
19
|
+
* pending and highest finalized indexes as that guides the next index choice when sending a log. The next index choice
|
|
20
|
+
* is simply the highest pending index plus one (or finalized if pending is undefined).
|
|
21
|
+
* @dev This function looks for new indexes, adds them to pending, then it checks status of each pending index and
|
|
22
|
+
* updates its status accordingly.
|
|
23
|
+
*/
|
|
24
|
+
export async function syncSenderTaggingIndexes(
|
|
25
|
+
secret: DirectionalAppTaggingSecret,
|
|
26
|
+
app: AztecAddress,
|
|
27
|
+
aztecNode: AztecNode,
|
|
28
|
+
taggingStore: SenderTaggingStore,
|
|
29
|
+
): Promise<void> {
|
|
30
|
+
// # Explanation of how syncing works
|
|
31
|
+
//
|
|
32
|
+
// When choosing an index, we select: highest pending index + 1 (or highest finalized index + 1 if no pending).
|
|
33
|
+
// If the chosen index is more than WINDOW_LEN from the highest finalized index, we throw an error. By having this
|
|
34
|
+
// hard limit we give a guarantee to a recipient that he doesn't need to look further than WINDOW_LEN ahead of the
|
|
35
|
+
// highest finalized index.
|
|
36
|
+
//
|
|
37
|
+
// This function synchronizes the finalized and pending indexes by iteratively querying the node for a window of
|
|
38
|
+
// indexes at a time, storing all those indexes as pending, and then checking the status of each pending index to
|
|
39
|
+
// update its finalization status accordingly. If we stumble upon a window with no indexes, we stop the loop.
|
|
40
|
+
//
|
|
41
|
+
// Stopping at that point is safe because of the limit described above - there can never be an index that is more
|
|
42
|
+
// than WINDOW_LEN from the highest finalized index.
|
|
43
|
+
//
|
|
44
|
+
// # Note on performance
|
|
45
|
+
// Each window advance requires two queries (logs + tx status). For example, syncing indexes 0–500 with a window of
|
|
46
|
+
// 100 takes at least 10 round trips (5 windows × 2 queries).
|
|
47
|
+
|
|
48
|
+
const finalizedIndex = await taggingStore.getLastFinalizedIndex(secret);
|
|
49
|
+
|
|
50
|
+
let start = finalizedIndex === undefined ? 0 : finalizedIndex + 1;
|
|
51
|
+
let end = start + UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN;
|
|
52
|
+
|
|
53
|
+
let previousFinalizedIndex = finalizedIndex;
|
|
54
|
+
let newFinalizedIndex = undefined;
|
|
55
|
+
|
|
56
|
+
while (true) {
|
|
57
|
+
// Load and store indexes for the current window. These indexes may already exist in the database if txs using
|
|
58
|
+
// them were previously sent from this PXE. Any duplicates are handled by the tagging data provider.
|
|
59
|
+
await loadAndStoreNewTaggingIndexes(secret, app, start, end, aztecNode, taggingStore);
|
|
60
|
+
|
|
61
|
+
// Retrieve all indexes within the current window from storage and update their status accordingly.
|
|
62
|
+
const pendingTxHashes = await taggingStore.getTxHashesOfPendingIndexes(secret, start, end);
|
|
63
|
+
if (pendingTxHashes.length === 0) {
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const { txHashesToFinalize, txHashesToDrop } = await getStatusChangeOfPending(pendingTxHashes, aztecNode);
|
|
68
|
+
|
|
69
|
+
await taggingStore.dropPendingIndexes(txHashesToDrop);
|
|
70
|
+
await taggingStore.finalizePendingIndexes(txHashesToFinalize);
|
|
71
|
+
|
|
72
|
+
// We check if the finalized index has been updated.
|
|
73
|
+
newFinalizedIndex = await taggingStore.getLastFinalizedIndex(secret);
|
|
74
|
+
if (previousFinalizedIndex !== newFinalizedIndex) {
|
|
75
|
+
// A new finalized index was found, so we'll run the loop again. For example:
|
|
76
|
+
// - Previous finalized index: 10
|
|
77
|
+
// - New finalized index: 13
|
|
78
|
+
// - Window length: 10
|
|
79
|
+
//
|
|
80
|
+
// In the last iteration, we processed indexes 11-20. To avoid reprocessing the same logs,
|
|
81
|
+
// we'll only look at the new indexes 21-23:
|
|
82
|
+
//
|
|
83
|
+
// Previous window: [11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
|
|
84
|
+
// New window: [21, 22, 23]
|
|
85
|
+
|
|
86
|
+
const previousEnd = end;
|
|
87
|
+
// Add 1 because `end` is exclusive and the known finalized index is not included in the window.
|
|
88
|
+
end = newFinalizedIndex! + UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN + 1;
|
|
89
|
+
start = previousEnd;
|
|
90
|
+
previousFinalizedIndex = newFinalizedIndex;
|
|
91
|
+
} else {
|
|
92
|
+
// No new finalized index was found, so we don't need to process the next window.
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { AztecNode } from '@aztec/stdlib/interfaces/server';
|
|
2
|
+
import { TxHash, TxStatus } from '@aztec/stdlib/tx';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Based on receipts obtained from `aztecNode` returns which pending transactions changed their status to finalized or
|
|
6
|
+
* dropped.
|
|
7
|
+
*/
|
|
8
|
+
export async function getStatusChangeOfPending(
|
|
9
|
+
pending: TxHash[],
|
|
10
|
+
aztecNode: AztecNode,
|
|
11
|
+
): Promise<{ txHashesToFinalize: TxHash[]; txHashesToDrop: TxHash[] }> {
|
|
12
|
+
// Get receipts for all pending tx hashes and the finalized block number.
|
|
13
|
+
const [receipts, { finalized }] = await Promise.all([
|
|
14
|
+
Promise.all(pending.map(pendingTxHash => aztecNode.getTxReceipt(pendingTxHash))),
|
|
15
|
+
aztecNode.getL2Tips(),
|
|
16
|
+
]);
|
|
17
|
+
|
|
18
|
+
const txHashesToFinalize: TxHash[] = [];
|
|
19
|
+
const txHashesToDrop: TxHash[] = [];
|
|
20
|
+
|
|
21
|
+
for (let i = 0; i < receipts.length; i++) {
|
|
22
|
+
const receipt = receipts[i];
|
|
23
|
+
const txHash = pending[i];
|
|
24
|
+
|
|
25
|
+
if (receipt.status === TxStatus.SUCCESS && receipt.blockNumber && receipt.blockNumber <= finalized.number) {
|
|
26
|
+
// Tx has been included in a block and the corresponding block is finalized --> we mark the indexes as
|
|
27
|
+
// finalized.
|
|
28
|
+
txHashesToFinalize.push(txHash);
|
|
29
|
+
} else if (
|
|
30
|
+
receipt.status === TxStatus.DROPPED ||
|
|
31
|
+
receipt.status === TxStatus.APP_LOGIC_REVERTED ||
|
|
32
|
+
receipt.status === TxStatus.TEARDOWN_REVERTED ||
|
|
33
|
+
receipt.status === TxStatus.BOTH_REVERTED
|
|
34
|
+
) {
|
|
35
|
+
// Tx was dropped or reverted --> we drop the corresponding pending indexes.
|
|
36
|
+
// TODO(#17615): Don't drop pending indexes corresponding to non-revertible phases.
|
|
37
|
+
txHashesToDrop.push(txHash);
|
|
38
|
+
} else {
|
|
39
|
+
// Tx is still pending or the corresponding block is not yet finalized --> we don't do anything.
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return { txHashesToFinalize, txHashesToDrop };
|
|
44
|
+
}
|