@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
|
@@ -3,7 +3,7 @@ import type { AztecAsyncArray, AztecAsyncKVStore, AztecAsyncMap } from '@aztec/k
|
|
|
3
3
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
4
|
import { CompleteAddress } from '@aztec/stdlib/contract';
|
|
5
5
|
|
|
6
|
-
export class
|
|
6
|
+
export class AddressStore {
|
|
7
7
|
#store: AztecAsyncKVStore;
|
|
8
8
|
#completeAddresses: AztecAsyncArray<Buffer>;
|
|
9
9
|
#completeAddressIndex: AztecAsyncMap<string, number>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { AddressStore } from './address_store.js';
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
1
|
import type { AztecAsyncKVStore, AztecAsyncSingleton } from '@aztec/kv-store';
|
|
3
2
|
import { BlockHeader } from '@aztec/stdlib/tx';
|
|
4
3
|
|
|
5
|
-
export class
|
|
4
|
+
export class AnchorBlockStore {
|
|
6
5
|
#store: AztecAsyncKVStore;
|
|
7
6
|
#synchronizedHeader: AztecAsyncSingleton<Buffer>;
|
|
8
7
|
|
|
@@ -15,19 +14,10 @@ export class SyncDataProvider {
|
|
|
15
14
|
await this.#synchronizedHeader.set(header.toBuffer());
|
|
16
15
|
}
|
|
17
16
|
|
|
18
|
-
async getBlockNumber(): Promise<BlockNumber> {
|
|
19
|
-
const headerBuffer = await this.#synchronizedHeader.getAsync();
|
|
20
|
-
if (!headerBuffer) {
|
|
21
|
-
throw new Error(`Trying to get block number with a not-yet-synchronized PXE - this should never happen`);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return BlockHeader.fromBuffer(headerBuffer).globalVariables.blockNumber;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
17
|
async getBlockHeader(): Promise<BlockHeader> {
|
|
28
18
|
const headerBuffer = await this.#synchronizedHeader.getAsync();
|
|
29
19
|
if (!headerBuffer) {
|
|
30
|
-
throw new Error(`
|
|
20
|
+
throw new Error(`Trying to get block header with a not-yet-synchronized PXE - this should never happen`);
|
|
31
21
|
}
|
|
32
22
|
|
|
33
23
|
return BlockHeader.fromBuffer(headerBuffer);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { AnchorBlockStore } from './anchor_block_store.js';
|
|
@@ -3,7 +3,7 @@ import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
|
3
3
|
import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
|
|
4
4
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
5
|
|
|
6
|
-
export class
|
|
6
|
+
export class CapsuleStore {
|
|
7
7
|
#store: AztecAsyncKVStore;
|
|
8
8
|
|
|
9
9
|
// Arbitrary data stored by contracts. Key is computed as `${contractAddress}:${key}`
|
|
@@ -19,10 +19,26 @@ export class CapsuleDataProvider {
|
|
|
19
19
|
this.logger = createLogger('pxe:capsule-data-provider');
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Stores arbitrary information in a per-contract non-volatile database, which can later be retrieved with `loadCapsule`.
|
|
24
|
+
* * If data was already stored at this slot, it is overwritten.
|
|
25
|
+
* @param contractAddress - The contract address to scope the data under.
|
|
26
|
+
* @param slot - The slot in the database in which to store the value. Slots need not be contiguous.
|
|
27
|
+
* @param capsule - An array of field elements representing the capsule.
|
|
28
|
+
* @remarks A capsule is a "blob" of data that is passed to the contract through an oracle. It works similarly
|
|
29
|
+
* to public contract storage in that it's indexed by the contract address and storage slot but instead of the global
|
|
30
|
+
* network state it's backed by local PXE db.
|
|
31
|
+
*/
|
|
22
32
|
async storeCapsule(contractAddress: AztecAddress, slot: Fr, capsule: Fr[]): Promise<void> {
|
|
23
33
|
await this.#capsules.set(dbSlotToKey(contractAddress, slot), Buffer.concat(capsule.map(value => value.toBuffer())));
|
|
24
34
|
}
|
|
25
35
|
|
|
36
|
+
/**
|
|
37
|
+
* Returns data previously stored via `storeCapsule` in the per-contract non-volatile database.
|
|
38
|
+
* @param contractAddress - The contract address under which the data is scoped.
|
|
39
|
+
* @param slot - The slot in the database to read.
|
|
40
|
+
* @returns The stored data or `null` if no data is stored under the slot.
|
|
41
|
+
*/
|
|
26
42
|
async loadCapsule(contractAddress: AztecAddress, slot: Fr): Promise<Fr[] | null> {
|
|
27
43
|
const dataBuffer = await this.#capsules.getAsync(dbSlotToKey(contractAddress, slot));
|
|
28
44
|
if (!dataBuffer) {
|
|
@@ -36,10 +52,26 @@ export class CapsuleDataProvider {
|
|
|
36
52
|
return capsule;
|
|
37
53
|
}
|
|
38
54
|
|
|
55
|
+
/**
|
|
56
|
+
* Deletes data in the per-contract non-volatile database. Does nothing if no data was present.
|
|
57
|
+
* @param contractAddress - The contract address under which the data is scoped.
|
|
58
|
+
* @param slot - The slot in the database to delete.
|
|
59
|
+
*/
|
|
39
60
|
async deleteCapsule(contractAddress: AztecAddress, slot: Fr): Promise<void> {
|
|
40
61
|
await this.#capsules.delete(dbSlotToKey(contractAddress, slot));
|
|
41
62
|
}
|
|
42
63
|
|
|
64
|
+
/**
|
|
65
|
+
* Copies a number of contiguous entries in the per-contract non-volatile database. This allows for efficient data
|
|
66
|
+
* structures by avoiding repeated calls to `loadCapsule` and `storeCapsule`.
|
|
67
|
+
* Supports overlapping source and destination regions (which will result in the overlapped source values being
|
|
68
|
+
* overwritten). All copied slots must exist in the database (i.e. have been stored and not deleted)
|
|
69
|
+
*
|
|
70
|
+
* @param contractAddress - The contract address under which the data is scoped.
|
|
71
|
+
* @param srcSlot - The first slot to copy from.
|
|
72
|
+
* @param dstSlot - The first slot to copy to.
|
|
73
|
+
* @param numEntries - The number of entries to copy.
|
|
74
|
+
*/
|
|
43
75
|
copyCapsule(contractAddress: AztecAddress, srcSlot: Fr, dstSlot: Fr, numEntries: number): Promise<void> {
|
|
44
76
|
return this.#store.transactionAsync(async () => {
|
|
45
77
|
// In order to support overlapping source and destination regions, we need to check the relative positions of source
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { CapsuleStore } from './capsule_store.js';
|
|
@@ -3,16 +3,19 @@ import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
|
3
3
|
import { toArray } from '@aztec/foundation/iterable';
|
|
4
4
|
import type { MembershipWitness } from '@aztec/foundation/trees';
|
|
5
5
|
import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
|
|
6
|
+
import { isProtocolContract } from '@aztec/protocol-contracts';
|
|
6
7
|
import {
|
|
7
8
|
type ContractArtifact,
|
|
8
9
|
type FunctionAbi,
|
|
9
10
|
type FunctionArtifact,
|
|
10
11
|
type FunctionArtifactWithContractName,
|
|
12
|
+
FunctionCall,
|
|
11
13
|
type FunctionDebugMetadata,
|
|
12
14
|
FunctionSelector,
|
|
13
15
|
FunctionType,
|
|
14
16
|
contractArtifactFromBuffer,
|
|
15
17
|
contractArtifactToBuffer,
|
|
18
|
+
encodeArguments,
|
|
16
19
|
getFunctionDebugMetadata,
|
|
17
20
|
} from '@aztec/stdlib/abi';
|
|
18
21
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
@@ -26,13 +29,13 @@ import {
|
|
|
26
29
|
import { PrivateFunctionsTree } from './private_functions_tree.js';
|
|
27
30
|
|
|
28
31
|
/**
|
|
29
|
-
*
|
|
32
|
+
* ContractStore serves as a data manager and retriever for Aztec.nr contracts.
|
|
30
33
|
* It provides methods to obtain contract addresses, function ABI, bytecode, and membership witnesses
|
|
31
34
|
* from a given contract address and function selector. The class maintains a cache of ContractTree instances
|
|
32
35
|
* to efficiently serve the requested data. It interacts with the ContractDatabase and AztecNode to fetch
|
|
33
36
|
* the required information and facilitate cryptographic proof generation.
|
|
34
37
|
*/
|
|
35
|
-
export class
|
|
38
|
+
export class ContractStore {
|
|
36
39
|
/** Map from contract class id to private function tree. */
|
|
37
40
|
// TODO: Update it to be LRU cache so that it doesn't keep all the data all the time.
|
|
38
41
|
#privateFunctionTrees: Map<string, PrivateFunctionsTree> = new Map();
|
|
@@ -176,6 +179,21 @@ export class ContractDataProvider {
|
|
|
176
179
|
return fnArtifact && { ...fnArtifact, contractName: artifact.name };
|
|
177
180
|
}
|
|
178
181
|
|
|
182
|
+
public async getFunctionArtifactWithDebugMetadata(
|
|
183
|
+
contractAddress: AztecAddress,
|
|
184
|
+
selector: FunctionSelector,
|
|
185
|
+
): Promise<FunctionArtifactWithContractName> {
|
|
186
|
+
const artifact = await this.getFunctionArtifact(contractAddress, selector);
|
|
187
|
+
if (!artifact) {
|
|
188
|
+
throw new Error(`Function artifact not found for contract ${contractAddress} and selector ${selector}.`);
|
|
189
|
+
}
|
|
190
|
+
const debug = await this.getFunctionDebugMetadata(contractAddress, selector);
|
|
191
|
+
return {
|
|
192
|
+
...artifact,
|
|
193
|
+
debug,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
|
|
179
197
|
public async getPublicFunctionArtifact(
|
|
180
198
|
contractAddress: AztecAddress,
|
|
181
199
|
): Promise<FunctionArtifactWithContractName | undefined> {
|
|
@@ -274,4 +292,48 @@ export class ContractDataProvider {
|
|
|
274
292
|
}
|
|
275
293
|
}
|
|
276
294
|
}
|
|
295
|
+
|
|
296
|
+
public async getFunctionCall(functionName: string, args: any[], to: AztecAddress): Promise<FunctionCall> {
|
|
297
|
+
const contract = await this.getContract(to);
|
|
298
|
+
if (!contract) {
|
|
299
|
+
throw new Error(
|
|
300
|
+
`Unknown contract ${to}: add it to PXE by calling server.addContracts(...).\nSee docs for context: https://docs.aztec.network/developers/resources/debugging/aztecnr-errors#unknown-contract-0x0-add-it-to-pxe-by-calling-serveraddcontracts`,
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
const functionDao = contract.functions.find(f => f.name === functionName);
|
|
305
|
+
if (!functionDao) {
|
|
306
|
+
throw new Error(`Unknown function ${functionName} in contract ${contract.name}.`);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
return {
|
|
310
|
+
name: functionDao.name,
|
|
311
|
+
args: encodeArguments(functionDao, args),
|
|
312
|
+
selector: await FunctionSelector.fromNameAndParameters(functionDao.name, functionDao.parameters),
|
|
313
|
+
type: functionDao.functionType,
|
|
314
|
+
to,
|
|
315
|
+
hideMsgSender: false,
|
|
316
|
+
isStatic: functionDao.isStatic,
|
|
317
|
+
returnTypes: functionDao.returnTypes,
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// Synchronize target contract data
|
|
322
|
+
public async syncPrivateState(
|
|
323
|
+
contractAddress: AztecAddress,
|
|
324
|
+
functionToInvokeAfterSync: FunctionSelector | null,
|
|
325
|
+
utilityExecutor: (privateSyncCall: FunctionCall) => Promise<any>,
|
|
326
|
+
) {
|
|
327
|
+
// Protocol contracts don't have private state to sync
|
|
328
|
+
if (!isProtocolContract(contractAddress)) {
|
|
329
|
+
const syncPrivateStateFunctionCall = await this.getFunctionCall('sync_private_state', [], contractAddress);
|
|
330
|
+
if (functionToInvokeAfterSync && functionToInvokeAfterSync.equals(syncPrivateStateFunctionCall.selector)) {
|
|
331
|
+
throw new Error(
|
|
332
|
+
'Forbidden `sync_private_state` invocation. `sync_private_state` can only be invoked by PXE, manual execution can lead to inconsistencies.',
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
return utilityExecutor(syncPrivateStateFunctionCall);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
277
339
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ContractStore } from './contract_store.js';
|
package/src/storage/index.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './
|
|
6
|
-
export * from './
|
|
1
|
+
export * from './address_store/index.js';
|
|
2
|
+
export * from './capsule_store/index.js';
|
|
3
|
+
export * from './contract_store/index.js';
|
|
4
|
+
export * from './note_store/index.js';
|
|
5
|
+
export * from './anchor_block_store/index.js';
|
|
6
|
+
export * from './tagging_store/index.js';
|
|
7
7
|
export * from './metadata.js';
|
|
8
|
-
export * from './
|
|
8
|
+
export * from './private_event_store/private_event_store.js';
|
|
@@ -8,12 +8,12 @@ import { NoteStatus, type NotesFilter } from '@aztec/stdlib/note';
|
|
|
8
8
|
import { NoteDao } from '@aztec/stdlib/note';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* NoteStore manages the storage and retrieval of notes.
|
|
12
12
|
*
|
|
13
13
|
* Notes can be active or nullified. This class processes new notes, nullifications,
|
|
14
14
|
* and performs rollback handling in the case of a reorg.
|
|
15
15
|
**/
|
|
16
|
-
export class
|
|
16
|
+
export class NoteStore {
|
|
17
17
|
#store: AztecAsyncKVStore;
|
|
18
18
|
#notes: AztecAsyncMap<string, Buffer>;
|
|
19
19
|
#nullifiedNotes: AztecAsyncMap<string, Buffer>;
|
|
@@ -49,16 +49,16 @@ export class NoteDataProvider {
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
/**
|
|
52
|
-
* Creates and initializes a new
|
|
52
|
+
* Creates and initializes a new NoteStore instance.
|
|
53
53
|
*
|
|
54
|
-
* This factory method creates a
|
|
54
|
+
* This factory method creates a NoteStore and restores any existing
|
|
55
55
|
* scope-specific indexes from the database.
|
|
56
56
|
*
|
|
57
57
|
* @param store - The key-value store to use for persistence
|
|
58
|
-
* @returns Promise resolving to a fully initialized
|
|
58
|
+
* @returns Promise resolving to a fully initialized NoteStore instance
|
|
59
59
|
*/
|
|
60
|
-
public static async create(store: AztecAsyncKVStore): Promise<
|
|
61
|
-
const pxeDB = new
|
|
60
|
+
public static async create(store: AztecAsyncKVStore): Promise<NoteStore> {
|
|
61
|
+
const pxeDB = new NoteStore(store);
|
|
62
62
|
for await (const scope of pxeDB.#scopes.keysAsync()) {
|
|
63
63
|
pxeDB.#notesByContractAndScope.set(scope, store.openMultiMap(`${scope}:notes_by_contract`));
|
|
64
64
|
pxeDB.#notesByStorageSlotAndScope.set(scope, store.openMultiMap(`${scope}:notes_by_storage_slot`));
|
|
@@ -2,7 +2,7 @@ import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
|
2
2
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
3
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
4
|
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
5
|
-
import type {
|
|
5
|
+
import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
|
|
6
6
|
import type { EventSelector } from '@aztec/stdlib/abi';
|
|
7
7
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
8
8
|
import { L2BlockHash } from '@aztec/stdlib/block';
|
|
@@ -10,7 +10,7 @@ import { type InTx, TxHash } from '@aztec/stdlib/tx';
|
|
|
10
10
|
|
|
11
11
|
import type { PackedPrivateEvent } from '../../pxe.js';
|
|
12
12
|
|
|
13
|
-
export type
|
|
13
|
+
export type PrivateEventStoreFilter = {
|
|
14
14
|
contractAddress: AztecAddress;
|
|
15
15
|
fromBlock: number;
|
|
16
16
|
toBlock: number;
|
|
@@ -24,6 +24,8 @@ type PrivateEventEntry = {
|
|
|
24
24
|
l2BlockNumber: number;
|
|
25
25
|
l2BlockHash: Buffer;
|
|
26
26
|
txHash: Buffer;
|
|
27
|
+
/** The lookup key for #eventsByContractScopeSelector, used for cleanup during rollback */
|
|
28
|
+
lookupKey: string;
|
|
27
29
|
};
|
|
28
30
|
|
|
29
31
|
type PrivateEventMetadata = InTx & {
|
|
@@ -34,22 +36,25 @@ type PrivateEventMetadata = InTx & {
|
|
|
34
36
|
/**
|
|
35
37
|
* Stores decrypted private event logs.
|
|
36
38
|
*/
|
|
37
|
-
export class
|
|
39
|
+
export class PrivateEventStore {
|
|
38
40
|
#store: AztecAsyncKVStore;
|
|
39
|
-
/**
|
|
40
|
-
#eventLogs:
|
|
41
|
-
/** Map from
|
|
42
|
-
#
|
|
41
|
+
/** Map storing the actual private event log entries, keyed by eventCommitmentIndex */
|
|
42
|
+
#eventLogs: AztecAsyncMap<number, PrivateEventEntry>;
|
|
43
|
+
/** Map from contractAddress_scope_eventSelector to eventCommitmentIndex[] for efficient lookup */
|
|
44
|
+
#eventsByContractScopeSelector: AztecAsyncMap<string, number[]>;
|
|
45
|
+
/** Map from block number to eventCommitmentIndex[] for rollback support */
|
|
46
|
+
#eventsByBlockNumber: AztecAsyncMap<number, number[]>;
|
|
43
47
|
/** Map from eventCommitmentIndex to boolean indicating if log has been seen. */
|
|
44
48
|
#seenLogs: AztecAsyncMap<number, boolean>;
|
|
45
49
|
|
|
46
|
-
logger = createLogger('
|
|
50
|
+
logger = createLogger('private_event_store');
|
|
47
51
|
|
|
48
52
|
constructor(store: AztecAsyncKVStore) {
|
|
49
53
|
this.#store = store;
|
|
50
|
-
this.#eventLogs = this.#store.
|
|
51
|
-
this.#
|
|
54
|
+
this.#eventLogs = this.#store.openMap('private_event_logs');
|
|
55
|
+
this.#eventsByContractScopeSelector = this.#store.openMap('events_by_contract_scope_selector');
|
|
52
56
|
this.#seenLogs = this.#store.openMap('seen_logs');
|
|
57
|
+
this.#eventsByBlockNumber = this.#store.openMap('events_by_block_number');
|
|
53
58
|
}
|
|
54
59
|
|
|
55
60
|
#keyFor(contractAddress: AztecAddress, scope: AztecAddress, eventSelector: EventSelector): string {
|
|
@@ -87,17 +92,20 @@ export class PrivateEventDataProvider {
|
|
|
87
92
|
|
|
88
93
|
this.logger.verbose('storing private event log', { contractAddress, scope, msgContent, l2BlockNumber });
|
|
89
94
|
|
|
90
|
-
|
|
91
|
-
await this.#eventLogs.push({
|
|
95
|
+
await this.#eventLogs.set(eventCommitmentIndex, {
|
|
92
96
|
msgContent: serializeToBuffer(msgContent),
|
|
93
97
|
l2BlockNumber,
|
|
94
98
|
l2BlockHash: l2BlockHash.toBuffer(),
|
|
95
99
|
eventCommitmentIndex,
|
|
96
100
|
txHash: txHash.toBuffer(),
|
|
101
|
+
lookupKey: key,
|
|
97
102
|
});
|
|
98
103
|
|
|
99
|
-
const existingIndices = (await this.#
|
|
100
|
-
await this.#
|
|
104
|
+
const existingIndices = (await this.#eventsByContractScopeSelector.getAsync(key)) || [];
|
|
105
|
+
await this.#eventsByContractScopeSelector.set(key, [...existingIndices, eventCommitmentIndex]);
|
|
106
|
+
|
|
107
|
+
const existingBlockIndices = (await this.#eventsByBlockNumber.getAsync(l2BlockNumber)) || [];
|
|
108
|
+
await this.#eventsByBlockNumber.set(l2BlockNumber, [...existingBlockIndices, eventCommitmentIndex]);
|
|
101
109
|
|
|
102
110
|
// Mark this log as seen using eventCommitmentIndex
|
|
103
111
|
await this.#seenLogs.set(eventCommitmentIndex, true);
|
|
@@ -117,16 +125,16 @@ export class PrivateEventDataProvider {
|
|
|
117
125
|
*/
|
|
118
126
|
public async getPrivateEvents(
|
|
119
127
|
eventSelector: EventSelector,
|
|
120
|
-
filter:
|
|
128
|
+
filter: PrivateEventStoreFilter,
|
|
121
129
|
): Promise<PackedPrivateEvent[]> {
|
|
122
130
|
const events: Array<{ eventCommitmentIndex: number; event: PackedPrivateEvent }> = [];
|
|
123
131
|
|
|
124
132
|
for (const scope of filter.scopes) {
|
|
125
133
|
const key = this.#keyFor(filter.contractAddress, scope, eventSelector);
|
|
126
|
-
const
|
|
134
|
+
const eventCommitmentIndices = (await this.#eventsByContractScopeSelector.getAsync(key)) || [];
|
|
127
135
|
|
|
128
|
-
for (const
|
|
129
|
-
const entry = await this.#eventLogs.
|
|
136
|
+
for (const eventCommitmentIndex of eventCommitmentIndices) {
|
|
137
|
+
const entry = await this.#eventLogs.getAsync(eventCommitmentIndex);
|
|
130
138
|
if (!entry || entry.l2BlockNumber < filter.fromBlock || entry.l2BlockNumber >= filter.toBlock) {
|
|
131
139
|
continue;
|
|
132
140
|
}
|
|
@@ -159,4 +167,47 @@ export class PrivateEventDataProvider {
|
|
|
159
167
|
events.sort((a, b) => a.eventCommitmentIndex - b.eventCommitmentIndex);
|
|
160
168
|
return events.map(ev => ev.event);
|
|
161
169
|
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Rolls back private events that were stored after a given `blockNumber` and up to `synchedBlockNumber` (the block
|
|
173
|
+
* number up to which PXE managed to sync before the reorg happened).
|
|
174
|
+
*/
|
|
175
|
+
public async rollbackEventsAfterBlock(blockNumber: number, synchedBlockNumber: number): Promise<void> {
|
|
176
|
+
await this.#store.transactionAsync(async () => {
|
|
177
|
+
let removedCount = 0;
|
|
178
|
+
|
|
179
|
+
for (let block = blockNumber + 1; block <= synchedBlockNumber; block++) {
|
|
180
|
+
const indices = await this.#eventsByBlockNumber.getAsync(block);
|
|
181
|
+
if (indices) {
|
|
182
|
+
await this.#eventsByBlockNumber.delete(block);
|
|
183
|
+
|
|
184
|
+
for (const eventCommitmentIndex of indices) {
|
|
185
|
+
const entry = await this.#eventLogs.getAsync(eventCommitmentIndex);
|
|
186
|
+
if (!entry) {
|
|
187
|
+
throw new Error(`Event log not found for eventCommitmentIndex ${eventCommitmentIndex}`);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
await this.#eventLogs.delete(eventCommitmentIndex);
|
|
191
|
+
await this.#seenLogs.delete(eventCommitmentIndex);
|
|
192
|
+
|
|
193
|
+
// Update #eventsByContractScopeSelector using the stored lookupKey
|
|
194
|
+
const existingIndices = await this.#eventsByContractScopeSelector.getAsync(entry.lookupKey);
|
|
195
|
+
if (!existingIndices || existingIndices.length === 0) {
|
|
196
|
+
throw new Error(`No indices found in #eventsByContractScopeSelector for key ${entry.lookupKey}`);
|
|
197
|
+
}
|
|
198
|
+
const filteredIndices = existingIndices.filter(idx => idx !== eventCommitmentIndex);
|
|
199
|
+
if (filteredIndices.length === 0) {
|
|
200
|
+
await this.#eventsByContractScopeSelector.delete(entry.lookupKey);
|
|
201
|
+
} else {
|
|
202
|
+
await this.#eventsByContractScopeSelector.set(entry.lookupKey, filteredIndices);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
removedCount++;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
this.logger.verbose(`Rolled back ${removedCount} private events after block ${blockNumber}`);
|
|
211
|
+
});
|
|
212
|
+
}
|
|
162
213
|
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
|
|
2
|
+
import type { DirectionalAppTaggingSecret } from '@aztec/stdlib/logs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Data provider of tagging data used when syncing the logs as a recipient. The sender counterpart of this class
|
|
6
|
+
* is called SenderTaggingStore. We have the providers separate for the sender and recipient because
|
|
7
|
+
* the algorithms are completely disjoint and there is not data reuse between the two.
|
|
8
|
+
*
|
|
9
|
+
* @dev Chain reorgs do not need to be handled here because both the finalized and aged indexes refer to finalized
|
|
10
|
+
* blocks, which by definition cannot be affected by reorgs.
|
|
11
|
+
*
|
|
12
|
+
* TODO(benesjan): Relocate to yarn-project/pxe/src/storage/tagging_store
|
|
13
|
+
*/
|
|
14
|
+
export class RecipientTaggingStore {
|
|
15
|
+
#store: AztecAsyncKVStore;
|
|
16
|
+
|
|
17
|
+
#highestAgedIndex: AztecAsyncMap<string, number>;
|
|
18
|
+
#highestFinalizedIndex: AztecAsyncMap<string, number>;
|
|
19
|
+
|
|
20
|
+
constructor(store: AztecAsyncKVStore) {
|
|
21
|
+
this.#store = store;
|
|
22
|
+
|
|
23
|
+
this.#highestAgedIndex = this.#store.openMap('highest_aged_index');
|
|
24
|
+
this.#highestFinalizedIndex = this.#store.openMap('highest_finalized_index');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
getHighestAgedIndex(secret: DirectionalAppTaggingSecret): Promise<number | undefined> {
|
|
28
|
+
return this.#highestAgedIndex.getAsync(secret.toString());
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async updateHighestAgedIndex(secret: DirectionalAppTaggingSecret, index: number): Promise<void> {
|
|
32
|
+
const currentIndex = await this.#highestAgedIndex.getAsync(secret.toString());
|
|
33
|
+
if (currentIndex !== undefined && index <= currentIndex) {
|
|
34
|
+
// Log sync should never set a lower highest aged index.
|
|
35
|
+
throw new Error(`New highest aged index (${index}) must be higher than the current one (${currentIndex})`);
|
|
36
|
+
}
|
|
37
|
+
await this.#highestAgedIndex.set(secret.toString(), index);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
getHighestFinalizedIndex(secret: DirectionalAppTaggingSecret): Promise<number | undefined> {
|
|
41
|
+
return this.#highestFinalizedIndex.getAsync(secret.toString());
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async updateHighestFinalizedIndex(secret: DirectionalAppTaggingSecret, index: number): Promise<void> {
|
|
45
|
+
const currentIndex = await this.#highestFinalizedIndex.getAsync(secret.toString());
|
|
46
|
+
if (currentIndex !== undefined && index < currentIndex) {
|
|
47
|
+
// Log sync should never set a lower highest finalized index but it can happen that it would try to set the same
|
|
48
|
+
// one because we are loading logs from highest aged index + 1 and not from the highest finalized index.
|
|
49
|
+
throw new Error(`New highest finalized index (${index}) must be higher than the current one (${currentIndex})`);
|
|
50
|
+
}
|
|
51
|
+
await this.#highestFinalizedIndex.set(secret.toString(), index);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { toArray } from '@aztec/foundation/iterable';
|
|
2
|
+
import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
|
|
3
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Stores sender addresses. During recipient log synchronization, these senders are used, along with a given recipient,
|
|
7
|
+
* to derive directional app tagging secrets that are then used to sync the logs.
|
|
8
|
+
*/
|
|
9
|
+
export class SenderAddressBookStore {
|
|
10
|
+
#store: AztecAsyncKVStore;
|
|
11
|
+
#addressBook: AztecAsyncMap<string, true>;
|
|
12
|
+
|
|
13
|
+
constructor(store: AztecAsyncKVStore) {
|
|
14
|
+
this.#store = store;
|
|
15
|
+
|
|
16
|
+
this.#addressBook = this.#store.openMap('address_book');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async addSender(address: AztecAddress): Promise<boolean> {
|
|
20
|
+
if (await this.#addressBook.hasAsync(address.toString())) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
await this.#addressBook.set(address.toString(), true);
|
|
25
|
+
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async getSenders(): Promise<AztecAddress[]> {
|
|
30
|
+
return (await toArray(this.#addressBook.keysAsync())).map(AztecAddress.fromString);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async removeSender(address: AztecAddress): Promise<boolean> {
|
|
34
|
+
if (!(await this.#addressBook.hasAsync(address.toString()))) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
await this.#addressBook.delete(address.toString());
|
|
39
|
+
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
}
|