@aztec/pxe 0.0.1-commit.03f7ef2 → 0.0.1-commit.1142ef1
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 +8 -8
- package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
- package/dest/block_synchronizer/block_synchronizer.js +15 -20
- package/dest/config/package_info.js +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +25 -22
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +34 -28
- package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +3 -2
- package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/event_validation_request.js +5 -2
- package/dest/contract_function_simulator/oracle/private_execution.d.ts +4 -4
- package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution.js +4 -5
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +17 -26
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +14 -39
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +20 -19
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +47 -45
- 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 +5 -5
- package/dest/debug/pxe_debug_utils.d.ts +6 -6
- package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
- package/dest/debug/pxe_debug_utils.js +7 -7
- 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/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/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 +7 -7
- package/dest/events/event_service.d.ts.map +1 -1
- package/dest/events/event_service.js +8 -8
- package/dest/events/private_event_filter_validator.d.ts +6 -6
- package/dest/events/private_event_filter_validator.d.ts.map +1 -1
- package/dest/events/private_event_filter_validator.js +4 -4
- package/dest/job_coordinator/job_coordinator.d.ts +74 -0
- package/dest/job_coordinator/job_coordinator.d.ts.map +1 -0
- package/dest/job_coordinator/job_coordinator.js +93 -0
- package/dest/logs/log_service.d.ts +14 -31
- package/dest/logs/log_service.d.ts.map +1 -1
- package/dest/logs/log_service.js +61 -180
- package/dest/notes/note_service.d.ts +7 -7
- package/dest/notes/note_service.d.ts.map +1 -1
- package/dest/notes/note_service.js +14 -14
- package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts +2 -2
- package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts.map +1 -1
- package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.js +2 -2
- package/dest/private_kernel/private_kernel_execution_prover.d.ts +1 -1
- package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_execution_prover.js +3 -4
- package/dest/private_kernel/private_kernel_oracle.d.ts +3 -2
- package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_oracle_impl.d.ts +5 -5
- package/dest/private_kernel/private_kernel_oracle_impl.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_oracle_impl.js +9 -10
- package/dest/public_storage/public_storage_service.d.ts +4 -4
- package/dest/public_storage/public_storage_service.d.ts.map +1 -1
- package/dest/public_storage/public_storage_service.js +4 -4
- package/dest/pxe.d.ts +11 -9
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +113 -87
- 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/anchor_block_store/anchor_block_store.d.ts +9 -0
- package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -0
- package/dest/storage/{anchor_block_data_provider/anchor_block_data_provider.js → anchor_block_store/anchor_block_store.js} +1 -1
- package/dest/storage/anchor_block_store/index.d.ts +2 -0
- 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_data_provider/capsule_data_provider.d.ts → capsule_store/capsule_store.d.ts} +2 -2
- 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} +1 -1
- 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} +4 -3
- 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} +14 -2
- 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_store/private_event_store.d.ts +56 -0
- 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} +59 -16
- 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/{tagging/recipient_sync/new_recipient_tagging_data_provider.js → storage/tagging_store/recipient_tagging_store.js} +3 -3
- 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_data_provider/sender_tagging_data_provider.d.ts → tagging_store/sender_tagging_store.d.ts} +3 -3
- package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -0
- package/dest/storage/{tagging_data_provider/sender_tagging_data_provider.js → tagging_store/sender_tagging_store.js} +3 -3
- package/dest/tagging/constants.d.ts +2 -2
- package/dest/tagging/constants.d.ts.map +1 -1
- package/dest/tagging/constants.js +10 -3
- package/dest/tagging/index.d.ts +14 -3
- package/dest/tagging/index.d.ts.map +1 -1
- package/dest/tagging/index.js +13 -2
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +3 -3
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +7 -7
- package/dest/tagging/{sync → sender_sync}/sync_sender_tagging_indexes.d.ts +3 -4
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -0
- package/dest/tagging/{sync → sender_sync}/sync_sender_tagging_indexes.js +8 -23
- package/dest/tagging/{sync → sender_sync}/utils/get_status_change_of_pending.d.ts +1 -1
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -0
- package/dest/tagging/{sync → sender_sync}/utils/get_status_change_of_pending.js +2 -2
- package/dest/tagging/{sync → sender_sync}/utils/load_and_store_new_tagging_indexes.d.ts +4 -4
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -0
- package/dest/tagging/{sync → sender_sync}/utils/load_and_store_new_tagging_indexes.js +3 -3
- package/dest/tree_membership/tree_membership_service.d.ts +4 -4
- package/dest/tree_membership/tree_membership_service.d.ts.map +1 -1
- package/dest/tree_membership/tree_membership_service.js +5 -5
- package/package.json +16 -16
- package/src/block_synchronizer/block_synchronizer.ts +14 -19
- package/src/config/package_info.ts +1 -1
- package/src/contract_function_simulator/contract_function_simulator.ts +57 -48
- package/src/contract_function_simulator/noir-structs/event_validation_request.ts +4 -0
- package/src/contract_function_simulator/oracle/private_execution.ts +4 -6
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +52 -80
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +53 -49
- package/src/contract_function_simulator/proxied_contract_data_source.ts +7 -7
- package/src/debug/pxe_debug_utils.ts +6 -6
- package/src/entrypoints/client/bundle/utils.ts +7 -1
- package/src/entrypoints/client/lazy/utils.ts +7 -2
- package/src/entrypoints/pxe_creation_options.ts +2 -1
- package/src/entrypoints/server/utils.ts +11 -15
- package/src/error_enriching.ts +7 -15
- package/src/events/event_service.ts +8 -6
- package/src/events/private_event_filter_validator.ts +5 -5
- package/src/job_coordinator/job_coordinator.ts +149 -0
- package/src/logs/log_service.ts +92 -254
- package/src/notes/note_service.ts +13 -13
- package/src/private_kernel/hints/build_private_kernel_reset_private_inputs.ts +1 -2
- package/src/private_kernel/private_kernel_execution_prover.ts +2 -4
- package/src/private_kernel/private_kernel_oracle.ts +2 -1
- package/src/private_kernel/private_kernel_oracle_impl.ts +8 -14
- package/src/public_storage/public_storage_service.ts +3 -3
- package/src/pxe.ts +154 -106
- 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/{anchor_block_data_provider/anchor_block_data_provider.ts → anchor_block_store/anchor_block_store.ts} +1 -1
- 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} +1 -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} +22 -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} +72 -18
- package/src/storage/tagging_store/index.ts +3 -0
- package/src/{tagging/recipient_sync/new_recipient_tagging_data_provider.ts → storage/tagging_store/recipient_tagging_store.ts} +3 -3
- package/src/storage/tagging_store/sender_address_book_store.ts +42 -0
- package/src/storage/{tagging_data_provider/sender_tagging_data_provider.ts → tagging_store/sender_tagging_store.ts} +3 -3
- package/src/tagging/constants.ts +10 -3
- package/src/tagging/index.ts +16 -2
- package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +11 -8
- package/src/tagging/{sync → sender_sync}/sync_sender_tagging_indexes.ts +9 -25
- package/src/tagging/{sync → sender_sync}/utils/get_status_change_of_pending.ts +6 -2
- package/src/tagging/{sync → sender_sync}/utils/load_and_store_new_tagging_indexes.ts +4 -4
- package/src/tree_membership/tree_membership_service.ts +4 -4
- 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/anchor_block_data_provider/anchor_block_data_provider.d.ts +0 -9
- package/dest/storage/anchor_block_data_provider/anchor_block_data_provider.d.ts.map +0 -1
- package/dest/storage/anchor_block_data_provider/index.d.ts +0 -2
- package/dest/storage/anchor_block_data_provider/index.d.ts.map +0 -1
- package/dest/storage/anchor_block_data_provider/index.js +0 -1
- 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 +0 -51
- package/dest/storage/private_event_data_provider/private_event_data_provider.d.ts.map +0 -1
- package/dest/storage/tagging_data_provider/index.d.ts +0 -3
- package/dest/storage/tagging_data_provider/index.d.ts.map +0 -1
- package/dest/storage/tagging_data_provider/index.js +0 -2
- package/dest/storage/tagging_data_provider/recipient_tagging_data_provider.d.ts +0 -31
- package/dest/storage/tagging_data_provider/recipient_tagging_data_provider.d.ts.map +0 -1
- package/dest/storage/tagging_data_provider/recipient_tagging_data_provider.js +0 -65
- package/dest/storage/tagging_data_provider/sender_tagging_data_provider.d.ts.map +0 -1
- package/dest/tagging/recipient_sync/new_recipient_tagging_data_provider.d.ts +0 -21
- package/dest/tagging/recipient_sync/new_recipient_tagging_data_provider.d.ts.map +0 -1
- package/dest/tagging/sync/sync_sender_tagging_indexes.d.ts.map +0 -1
- package/dest/tagging/sync/utils/get_status_change_of_pending.d.ts.map +0 -1
- package/dest/tagging/sync/utils/load_and_store_new_tagging_indexes.d.ts.map +0 -1
- package/dest/tagging/utils.d.ts +0 -18
- package/dest/tagging/utils.d.ts.map +0 -1
- package/dest/tagging/utils.js +0 -25
- package/src/storage/address_data_provider/index.ts +0 -1
- package/src/storage/anchor_block_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/tagging_data_provider/index.ts +0 -2
- package/src/storage/tagging_data_provider/recipient_tagging_data_provider.ts +0 -86
- package/src/tagging/utils.ts +0 -32
- /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,6 +3,7 @@ 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,
|
|
@@ -28,13 +29,13 @@ import {
|
|
|
28
29
|
import { PrivateFunctionsTree } from './private_functions_tree.js';
|
|
29
30
|
|
|
30
31
|
/**
|
|
31
|
-
*
|
|
32
|
+
* ContractStore serves as a data manager and retriever for Aztec.nr contracts.
|
|
32
33
|
* It provides methods to obtain contract addresses, function ABI, bytecode, and membership witnesses
|
|
33
34
|
* from a given contract address and function selector. The class maintains a cache of ContractTree instances
|
|
34
35
|
* to efficiently serve the requested data. It interacts with the ContractDatabase and AztecNode to fetch
|
|
35
36
|
* the required information and facilitate cryptographic proof generation.
|
|
36
37
|
*/
|
|
37
|
-
export class
|
|
38
|
+
export class ContractStore {
|
|
38
39
|
/** Map from contract class id to private function tree. */
|
|
39
40
|
// TODO: Update it to be LRU cache so that it doesn't keep all the data all the time.
|
|
40
41
|
#privateFunctionTrees: Map<string, PrivateFunctionsTree> = new Map();
|
|
@@ -316,4 +317,23 @@ export class ContractDataProvider {
|
|
|
316
317
|
returnTypes: functionDao.returnTypes,
|
|
317
318
|
};
|
|
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
|
+
}
|
|
319
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;
|
|
@@ -19,11 +19,14 @@ export type PrivateEventDataProviderFilter = {
|
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
type PrivateEventEntry = {
|
|
22
|
+
randomness: Fr; // Note that this value is currently not being returned on queries and is therefore temporarily unused
|
|
22
23
|
msgContent: Buffer;
|
|
23
24
|
eventCommitmentIndex: number;
|
|
24
25
|
l2BlockNumber: number;
|
|
25
26
|
l2BlockHash: Buffer;
|
|
26
27
|
txHash: Buffer;
|
|
28
|
+
/** The lookup key for #eventsByContractScopeSelector, used for cleanup during rollback */
|
|
29
|
+
lookupKey: string;
|
|
27
30
|
};
|
|
28
31
|
|
|
29
32
|
type PrivateEventMetadata = InTx & {
|
|
@@ -34,22 +37,25 @@ type PrivateEventMetadata = InTx & {
|
|
|
34
37
|
/**
|
|
35
38
|
* Stores decrypted private event logs.
|
|
36
39
|
*/
|
|
37
|
-
export class
|
|
40
|
+
export class PrivateEventStore {
|
|
38
41
|
#store: AztecAsyncKVStore;
|
|
39
|
-
/**
|
|
40
|
-
#eventLogs:
|
|
41
|
-
/** Map from
|
|
42
|
-
#
|
|
42
|
+
/** Map storing the actual private event log entries, keyed by eventCommitmentIndex */
|
|
43
|
+
#eventLogs: AztecAsyncMap<number, PrivateEventEntry>;
|
|
44
|
+
/** Map from contractAddress_scope_eventSelector to eventCommitmentIndex[] for efficient lookup */
|
|
45
|
+
#eventsByContractScopeSelector: AztecAsyncMap<string, number[]>;
|
|
46
|
+
/** Map from block number to eventCommitmentIndex[] for rollback support */
|
|
47
|
+
#eventsByBlockNumber: AztecAsyncMap<number, number[]>;
|
|
43
48
|
/** Map from eventCommitmentIndex to boolean indicating if log has been seen. */
|
|
44
49
|
#seenLogs: AztecAsyncMap<number, boolean>;
|
|
45
50
|
|
|
46
|
-
logger = createLogger('
|
|
51
|
+
logger = createLogger('private_event_store');
|
|
47
52
|
|
|
48
53
|
constructor(store: AztecAsyncKVStore) {
|
|
49
54
|
this.#store = store;
|
|
50
|
-
this.#eventLogs = this.#store.
|
|
51
|
-
this.#
|
|
55
|
+
this.#eventLogs = this.#store.openMap('private_event_logs');
|
|
56
|
+
this.#eventsByContractScopeSelector = this.#store.openMap('events_by_contract_scope_selector');
|
|
52
57
|
this.#seenLogs = this.#store.openMap('seen_logs');
|
|
58
|
+
this.#eventsByBlockNumber = this.#store.openMap('events_by_block_number');
|
|
53
59
|
}
|
|
54
60
|
|
|
55
61
|
#keyFor(contractAddress: AztecAddress, scope: AztecAddress, eventSelector: EventSelector): string {
|
|
@@ -69,6 +75,7 @@ export class PrivateEventDataProvider {
|
|
|
69
75
|
*/
|
|
70
76
|
storePrivateEventLog(
|
|
71
77
|
eventSelector: EventSelector,
|
|
78
|
+
randomness: Fr,
|
|
72
79
|
msgContent: Fr[],
|
|
73
80
|
eventCommitmentIndex: number,
|
|
74
81
|
metadata: PrivateEventMetadata,
|
|
@@ -87,17 +94,21 @@ export class PrivateEventDataProvider {
|
|
|
87
94
|
|
|
88
95
|
this.logger.verbose('storing private event log', { contractAddress, scope, msgContent, l2BlockNumber });
|
|
89
96
|
|
|
90
|
-
|
|
91
|
-
|
|
97
|
+
await this.#eventLogs.set(eventCommitmentIndex, {
|
|
98
|
+
randomness,
|
|
92
99
|
msgContent: serializeToBuffer(msgContent),
|
|
93
100
|
l2BlockNumber,
|
|
94
101
|
l2BlockHash: l2BlockHash.toBuffer(),
|
|
95
102
|
eventCommitmentIndex,
|
|
96
103
|
txHash: txHash.toBuffer(),
|
|
104
|
+
lookupKey: key,
|
|
97
105
|
});
|
|
98
106
|
|
|
99
|
-
const existingIndices = (await this.#
|
|
100
|
-
await this.#
|
|
107
|
+
const existingIndices = (await this.#eventsByContractScopeSelector.getAsync(key)) || [];
|
|
108
|
+
await this.#eventsByContractScopeSelector.set(key, [...existingIndices, eventCommitmentIndex]);
|
|
109
|
+
|
|
110
|
+
const existingBlockIndices = (await this.#eventsByBlockNumber.getAsync(l2BlockNumber)) || [];
|
|
111
|
+
await this.#eventsByBlockNumber.set(l2BlockNumber, [...existingBlockIndices, eventCommitmentIndex]);
|
|
101
112
|
|
|
102
113
|
// Mark this log as seen using eventCommitmentIndex
|
|
103
114
|
await this.#seenLogs.set(eventCommitmentIndex, true);
|
|
@@ -117,16 +128,16 @@ export class PrivateEventDataProvider {
|
|
|
117
128
|
*/
|
|
118
129
|
public async getPrivateEvents(
|
|
119
130
|
eventSelector: EventSelector,
|
|
120
|
-
filter:
|
|
131
|
+
filter: PrivateEventStoreFilter,
|
|
121
132
|
): Promise<PackedPrivateEvent[]> {
|
|
122
133
|
const events: Array<{ eventCommitmentIndex: number; event: PackedPrivateEvent }> = [];
|
|
123
134
|
|
|
124
135
|
for (const scope of filter.scopes) {
|
|
125
136
|
const key = this.#keyFor(filter.contractAddress, scope, eventSelector);
|
|
126
|
-
const
|
|
137
|
+
const eventCommitmentIndices = (await this.#eventsByContractScopeSelector.getAsync(key)) || [];
|
|
127
138
|
|
|
128
|
-
for (const
|
|
129
|
-
const entry = await this.#eventLogs.
|
|
139
|
+
for (const eventCommitmentIndex of eventCommitmentIndices) {
|
|
140
|
+
const entry = await this.#eventLogs.getAsync(eventCommitmentIndex);
|
|
130
141
|
if (!entry || entry.l2BlockNumber < filter.fromBlock || entry.l2BlockNumber >= filter.toBlock) {
|
|
131
142
|
continue;
|
|
132
143
|
}
|
|
@@ -159,4 +170,47 @@ export class PrivateEventDataProvider {
|
|
|
159
170
|
events.sort((a, b) => a.eventCommitmentIndex - b.eventCommitmentIndex);
|
|
160
171
|
return events.map(ev => ev.event);
|
|
161
172
|
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Rolls back private events that were stored after a given `blockNumber` and up to `synchedBlockNumber` (the block
|
|
176
|
+
* number up to which PXE managed to sync before the reorg happened).
|
|
177
|
+
*/
|
|
178
|
+
public async rollbackEventsAfterBlock(blockNumber: number, synchedBlockNumber: number): Promise<void> {
|
|
179
|
+
await this.#store.transactionAsync(async () => {
|
|
180
|
+
let removedCount = 0;
|
|
181
|
+
|
|
182
|
+
for (let block = blockNumber + 1; block <= synchedBlockNumber; block++) {
|
|
183
|
+
const indices = await this.#eventsByBlockNumber.getAsync(block);
|
|
184
|
+
if (indices) {
|
|
185
|
+
await this.#eventsByBlockNumber.delete(block);
|
|
186
|
+
|
|
187
|
+
for (const eventCommitmentIndex of indices) {
|
|
188
|
+
const entry = await this.#eventLogs.getAsync(eventCommitmentIndex);
|
|
189
|
+
if (!entry) {
|
|
190
|
+
throw new Error(`Event log not found for eventCommitmentIndex ${eventCommitmentIndex}`);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
await this.#eventLogs.delete(eventCommitmentIndex);
|
|
194
|
+
await this.#seenLogs.delete(eventCommitmentIndex);
|
|
195
|
+
|
|
196
|
+
// Update #eventsByContractScopeSelector using the stored lookupKey
|
|
197
|
+
const existingIndices = await this.#eventsByContractScopeSelector.getAsync(entry.lookupKey);
|
|
198
|
+
if (!existingIndices || existingIndices.length === 0) {
|
|
199
|
+
throw new Error(`No indices found in #eventsByContractScopeSelector for key ${entry.lookupKey}`);
|
|
200
|
+
}
|
|
201
|
+
const filteredIndices = existingIndices.filter(idx => idx !== eventCommitmentIndex);
|
|
202
|
+
if (filteredIndices.length === 0) {
|
|
203
|
+
await this.#eventsByContractScopeSelector.delete(entry.lookupKey);
|
|
204
|
+
} else {
|
|
205
|
+
await this.#eventsByContractScopeSelector.set(entry.lookupKey, filteredIndices);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
removedCount++;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
this.logger.verbose(`Rolled back ${removedCount} private events after block ${blockNumber}`);
|
|
214
|
+
});
|
|
215
|
+
}
|
|
162
216
|
}
|
|
@@ -3,15 +3,15 @@ import type { DirectionalAppTaggingSecret } from '@aztec/stdlib/logs';
|
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Data provider of tagging data used when syncing the logs as a recipient. The sender counterpart of this class
|
|
6
|
-
* is called
|
|
6
|
+
* is called SenderTaggingStore. We have the providers separate for the sender and recipient because
|
|
7
7
|
* the algorithms are completely disjoint and there is not data reuse between the two.
|
|
8
8
|
*
|
|
9
9
|
* @dev Chain reorgs do not need to be handled here because both the finalized and aged indexes refer to finalized
|
|
10
10
|
* blocks, which by definition cannot be affected by reorgs.
|
|
11
11
|
*
|
|
12
|
-
* TODO(benesjan):
|
|
12
|
+
* TODO(benesjan): Relocate to yarn-project/pxe/src/storage/tagging_store
|
|
13
13
|
*/
|
|
14
|
-
export class
|
|
14
|
+
export class RecipientTaggingStore {
|
|
15
15
|
#store: AztecAsyncKVStore;
|
|
16
16
|
|
|
17
17
|
#highestAgedIndex: AztecAsyncMap<string, number>;
|
|
@@ -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
|
+
}
|
|
@@ -3,14 +3,14 @@ import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
|
|
|
3
3
|
import type { DirectionalAppTaggingSecret, PreTag } from '@aztec/stdlib/logs';
|
|
4
4
|
import { TxHash } from '@aztec/stdlib/tx';
|
|
5
5
|
|
|
6
|
-
import { UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN } from '../../tagging/
|
|
6
|
+
import { UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN } from '../../tagging/constants.js';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Data provider of tagging data used when syncing the sender tagging indexes. The recipient counterpart of this class
|
|
10
|
-
* is called
|
|
10
|
+
* is called RecipientTaggingStore. We have the providers separate for the sender and recipient because
|
|
11
11
|
* the algorithms are completely disjoint and there is not data reuse between the two.
|
|
12
12
|
*/
|
|
13
|
-
export class
|
|
13
|
+
export class SenderTaggingStore {
|
|
14
14
|
#store: AztecAsyncKVStore;
|
|
15
15
|
|
|
16
16
|
// Stores the pending indexes for each directional app tagging secret. Pending here means that the tx that contained
|
package/src/tagging/constants.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
|
|
1
|
+
// This window has to be as large as the largest expected number of logs emitted in a tx for a given directional app
|
|
2
|
+
// tagging secret. If we get more tag indexes consumed than this window, an error is thrown in `PXE::proveTx` function.
|
|
3
|
+
// This is set to a larger value than MAX_PRIVATE_LOGS_PER_TX (currently 64) because there could be more than
|
|
4
|
+
// MAX_PRIVATE_LOGS_PER_TX indexes consumed in case the logs are squashed. This happens when the log contains a note
|
|
5
|
+
// and the note is nullified in the same tx.
|
|
6
|
+
//
|
|
7
|
+
// Having a large window significantly slowed down `e2e_l1_with_wall_time` test as there we perform sync for more than
|
|
8
|
+
// 1000 secrets. For this reason we set it to a relatively low value of 20. 20 should be sufficient for all the use
|
|
9
|
+
// cases.
|
|
10
|
+
export const UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN = 20;
|
package/src/tagging/index.ts
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
+
export { UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN } from './constants.js';
|
|
15
|
+
|
|
16
|
+
// Re-export tagging-related types from stdlib
|
|
3
17
|
export { DirectionalAppTaggingSecret, Tag, SiloedTag } from '@aztec/stdlib/logs';
|
|
4
18
|
export { type PreTag } from '@aztec/stdlib/logs';
|
|
@@ -3,8 +3,8 @@ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
|
3
3
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
4
4
|
import type { DirectionalAppTaggingSecret, TxScopedL2Log } from '@aztec/stdlib/logs';
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
6
|
+
import type { RecipientTaggingStore } from '../../storage/tagging_store/recipient_tagging_store.js';
|
|
7
|
+
import { UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN } from '../constants.js';
|
|
8
8
|
import { findHighestIndexes } from './utils/find_highest_indexes.js';
|
|
9
9
|
import { loadLogsForRange } from './utils/load_logs_for_range.js';
|
|
10
10
|
|
|
@@ -19,7 +19,7 @@ export async function loadPrivateLogsForSenderRecipientPair(
|
|
|
19
19
|
secret: DirectionalAppTaggingSecret,
|
|
20
20
|
app: AztecAddress,
|
|
21
21
|
aztecNode: AztecNode,
|
|
22
|
-
|
|
22
|
+
taggingStore: RecipientTaggingStore,
|
|
23
23
|
anchorBlockNumber: BlockNumber,
|
|
24
24
|
): Promise<TxScopedL2Log[]> {
|
|
25
25
|
// # Explanation of how the algorithm works
|
|
@@ -68,13 +68,16 @@ export async function loadPrivateLogsForSenderRecipientPair(
|
|
|
68
68
|
throw new Error('Node failed to return latest block header when syncing logs');
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
[finalizedBlockNumber, currentTimestamp] = [
|
|
71
|
+
[finalizedBlockNumber, currentTimestamp] = [
|
|
72
|
+
l2Tips.finalized.block.number,
|
|
73
|
+
latestBlockHeader.globalVariables.timestamp,
|
|
74
|
+
];
|
|
72
75
|
}
|
|
73
76
|
|
|
74
77
|
let start: number, end: number;
|
|
75
78
|
{
|
|
76
|
-
const currentHighestAgedIndex = await
|
|
77
|
-
const currentHighestFinalizedIndex = await
|
|
79
|
+
const currentHighestAgedIndex = await taggingStore.getHighestAgedIndex(secret);
|
|
80
|
+
const currentHighestFinalizedIndex = await taggingStore.getHighestFinalizedIndex(secret);
|
|
78
81
|
|
|
79
82
|
// We don't want to include the highest aged index so we start from `currentHighestAgedIndex + 1` (or 0 if not set)
|
|
80
83
|
start = currentHighestAgedIndex === undefined ? 0 : currentHighestAgedIndex + 1;
|
|
@@ -104,7 +107,7 @@ export async function loadPrivateLogsForSenderRecipientPair(
|
|
|
104
107
|
|
|
105
108
|
// Store updates in data provider and update local variables
|
|
106
109
|
if (highestAgedIndex !== undefined) {
|
|
107
|
-
await
|
|
110
|
+
await taggingStore.updateHighestAgedIndex(secret, highestAgedIndex);
|
|
108
111
|
}
|
|
109
112
|
|
|
110
113
|
if (highestFinalizedIndex === undefined) {
|
|
@@ -117,7 +120,7 @@ export async function loadPrivateLogsForSenderRecipientPair(
|
|
|
117
120
|
throw new Error('Highest aged index lower than highest finalized index invariant violated');
|
|
118
121
|
}
|
|
119
122
|
|
|
120
|
-
await
|
|
123
|
+
await taggingStore.updateHighestFinalizedIndex(secret, highestFinalizedIndex);
|
|
121
124
|
|
|
122
125
|
// For the next iteration we want to look only at indexes for which we have not attempted to load logs yet while
|
|
123
126
|
// ensuring that we do not look further than WINDOW_LEN ahead of the highest finalized index.
|
|
@@ -2,27 +2,11 @@ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
|
2
2
|
import type { AztecNode } from '@aztec/stdlib/interfaces/server';
|
|
3
3
|
import type { DirectionalAppTaggingSecret } from '@aztec/stdlib/logs';
|
|
4
4
|
|
|
5
|
-
import type {
|
|
5
|
+
import type { SenderTaggingStore } from '../../storage/tagging_store/sender_tagging_store.js';
|
|
6
|
+
import { UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN } from '../constants.js';
|
|
6
7
|
import { getStatusChangeOfPending } from './utils/get_status_change_of_pending.js';
|
|
7
8
|
import { loadAndStoreNewTaggingIndexes } from './utils/load_and_store_new_tagging_indexes.js';
|
|
8
9
|
|
|
9
|
-
// This window has to be as large as the largest expected number of logs emitted in a tx for a given directional app
|
|
10
|
-
// tagging secret. If we get more tag indexes consumed than this window, an error is thrown in `PXE::proveTx` function.
|
|
11
|
-
// This is set to a larger value than MAX_PRIVATE_LOGS_PER_TX (currently 64) because there could be more than
|
|
12
|
-
// MAX_PRIVATE_LOGS_PER_TX indexes consumed in case the logs are squashed. This happens when the log contains a note
|
|
13
|
-
// and the note is nullified in the same tx.
|
|
14
|
-
//
|
|
15
|
-
// Rationale for value 95:
|
|
16
|
-
// - The `e2e_pending_note_hashes_contract` test's "Should handle overflowing the kernel data structures in nested
|
|
17
|
-
// calls" test case hits 95 tagging indexes emitted in a single transaction. This test creates and nullifies many
|
|
18
|
-
// notes recursively to test kernel reset circuit behavior, which causes logs to be squashed but still consume
|
|
19
|
-
// tagging indexes during the sync process. Since this is testing MAX_PRIVATE_LOGS_PER_TX overflow we can be
|
|
20
|
-
// reasonably certain that this value is large enough for standard use cases.
|
|
21
|
-
// - This value is below MAX_RPC_LEN (100) which is the limit for array parameters in the JSON RPC schema for
|
|
22
|
-
// `getLogsByTags`. Any test that would perform sync over JSON RPC (not by having access to the Aztec node instance
|
|
23
|
-
// directly) would error out if that maximum was hit (docs_examples.test.ts is an example of this).
|
|
24
|
-
export const UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN = 95;
|
|
25
|
-
|
|
26
10
|
/**
|
|
27
11
|
* Syncs tagging indexes. This function needs to be called whenever a private log is being sent.
|
|
28
12
|
*
|
|
@@ -41,7 +25,7 @@ export async function syncSenderTaggingIndexes(
|
|
|
41
25
|
secret: DirectionalAppTaggingSecret,
|
|
42
26
|
app: AztecAddress,
|
|
43
27
|
aztecNode: AztecNode,
|
|
44
|
-
|
|
28
|
+
taggingStore: SenderTaggingStore,
|
|
45
29
|
): Promise<void> {
|
|
46
30
|
// # Explanation of how syncing works
|
|
47
31
|
//
|
|
@@ -61,7 +45,7 @@ export async function syncSenderTaggingIndexes(
|
|
|
61
45
|
// Each window advance requires two queries (logs + tx status). For example, syncing indexes 0–500 with a window of
|
|
62
46
|
// 100 takes at least 10 round trips (5 windows × 2 queries).
|
|
63
47
|
|
|
64
|
-
const finalizedIndex = await
|
|
48
|
+
const finalizedIndex = await taggingStore.getLastFinalizedIndex(secret);
|
|
65
49
|
|
|
66
50
|
let start = finalizedIndex === undefined ? 0 : finalizedIndex + 1;
|
|
67
51
|
let end = start + UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN;
|
|
@@ -72,21 +56,21 @@ export async function syncSenderTaggingIndexes(
|
|
|
72
56
|
while (true) {
|
|
73
57
|
// Load and store indexes for the current window. These indexes may already exist in the database if txs using
|
|
74
58
|
// them were previously sent from this PXE. Any duplicates are handled by the tagging data provider.
|
|
75
|
-
await loadAndStoreNewTaggingIndexes(secret, app, start, end, aztecNode,
|
|
59
|
+
await loadAndStoreNewTaggingIndexes(secret, app, start, end, aztecNode, taggingStore);
|
|
76
60
|
|
|
77
61
|
// Retrieve all indexes within the current window from storage and update their status accordingly.
|
|
78
|
-
const pendingTxHashes = await
|
|
62
|
+
const pendingTxHashes = await taggingStore.getTxHashesOfPendingIndexes(secret, start, end);
|
|
79
63
|
if (pendingTxHashes.length === 0) {
|
|
80
64
|
break;
|
|
81
65
|
}
|
|
82
66
|
|
|
83
67
|
const { txHashesToFinalize, txHashesToDrop } = await getStatusChangeOfPending(pendingTxHashes, aztecNode);
|
|
84
68
|
|
|
85
|
-
await
|
|
86
|
-
await
|
|
69
|
+
await taggingStore.dropPendingIndexes(txHashesToDrop);
|
|
70
|
+
await taggingStore.finalizePendingIndexes(txHashesToFinalize);
|
|
87
71
|
|
|
88
72
|
// We check if the finalized index has been updated.
|
|
89
|
-
newFinalizedIndex = await
|
|
73
|
+
newFinalizedIndex = await taggingStore.getLastFinalizedIndex(secret);
|
|
90
74
|
if (previousFinalizedIndex !== newFinalizedIndex) {
|
|
91
75
|
// A new finalized index was found, so we'll run the loop again. For example:
|
|
92
76
|
// - Previous finalized index: 10
|
|
@@ -10,7 +10,7 @@ export async function getStatusChangeOfPending(
|
|
|
10
10
|
aztecNode: AztecNode,
|
|
11
11
|
): Promise<{ txHashesToFinalize: TxHash[]; txHashesToDrop: TxHash[] }> {
|
|
12
12
|
// Get receipts for all pending tx hashes and the finalized block number.
|
|
13
|
-
const [receipts,
|
|
13
|
+
const [receipts, tips] = await Promise.all([
|
|
14
14
|
Promise.all(pending.map(pendingTxHash => aztecNode.getTxReceipt(pendingTxHash))),
|
|
15
15
|
aztecNode.getL2Tips(),
|
|
16
16
|
]);
|
|
@@ -22,7 +22,11 @@ export async function getStatusChangeOfPending(
|
|
|
22
22
|
const receipt = receipts[i];
|
|
23
23
|
const txHash = pending[i];
|
|
24
24
|
|
|
25
|
-
if (
|
|
25
|
+
if (
|
|
26
|
+
receipt.status === TxStatus.SUCCESS &&
|
|
27
|
+
receipt.blockNumber &&
|
|
28
|
+
receipt.blockNumber <= tips.finalized.block.number
|
|
29
|
+
) {
|
|
26
30
|
// Tx has been included in a block and the corresponding block is finalized --> we mark the indexes as
|
|
27
31
|
// finalized.
|
|
28
32
|
txHashesToFinalize.push(txHash);
|
|
@@ -4,7 +4,7 @@ import type { DirectionalAppTaggingSecret, PreTag } from '@aztec/stdlib/logs';
|
|
|
4
4
|
import { SiloedTag, Tag } from '@aztec/stdlib/logs';
|
|
5
5
|
import { TxHash } from '@aztec/stdlib/tx';
|
|
6
6
|
|
|
7
|
-
import type {
|
|
7
|
+
import type { SenderTaggingStore } from '../../../storage/tagging_store/sender_tagging_store.js';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Loads tagging indexes from the Aztec node and stores them in the tagging data provider.
|
|
@@ -16,7 +16,7 @@ import type { SenderTaggingDataProvider } from '../../../storage/tagging_data_pr
|
|
|
16
16
|
* @param start - The starting index (inclusive) of the window to process.
|
|
17
17
|
* @param end - The ending index (exclusive) of the window to process.
|
|
18
18
|
* @param aztecNode - The Aztec node instance to query for logs.
|
|
19
|
-
* @param
|
|
19
|
+
* @param taggingStore - The data provider to store pending indexes.
|
|
20
20
|
*/
|
|
21
21
|
export async function loadAndStoreNewTaggingIndexes(
|
|
22
22
|
secret: DirectionalAppTaggingSecret,
|
|
@@ -24,7 +24,7 @@ export async function loadAndStoreNewTaggingIndexes(
|
|
|
24
24
|
start: number,
|
|
25
25
|
end: number,
|
|
26
26
|
aztecNode: AztecNode,
|
|
27
|
-
|
|
27
|
+
taggingStore: SenderTaggingStore,
|
|
28
28
|
) {
|
|
29
29
|
// We compute the tags for the current window of indexes
|
|
30
30
|
const preTagsForWindow: PreTag[] = Array(end - start)
|
|
@@ -40,7 +40,7 @@ export async function loadAndStoreNewTaggingIndexes(
|
|
|
40
40
|
// Now we iterate over the map, reconstruct the preTags and tx hash and store them in the db.
|
|
41
41
|
for (const [txHashStr, highestIndex] of highestIndexMap.entries()) {
|
|
42
42
|
const txHash = TxHash.fromString(txHashStr);
|
|
43
|
-
await
|
|
43
|
+
await taggingStore.storePendingIndexes([{ secret, index: highestIndex }], txHash);
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
|
|
@@ -7,12 +7,12 @@ import type { AztecNode } from '@aztec/stdlib/interfaces/server';
|
|
|
7
7
|
import { getNonNullifiedL1ToL2MessageWitness } from '@aztec/stdlib/messaging';
|
|
8
8
|
import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
|
|
9
9
|
|
|
10
|
-
import type {
|
|
10
|
+
import type { AnchorBlockStore } from '../storage/anchor_block_store/anchor_block_store.js';
|
|
11
11
|
|
|
12
12
|
export class TreeMembershipService {
|
|
13
13
|
constructor(
|
|
14
14
|
private readonly aztecNode: AztecNode,
|
|
15
|
-
private readonly
|
|
15
|
+
private readonly anchorBlockStore: AnchorBlockStore,
|
|
16
16
|
) {}
|
|
17
17
|
|
|
18
18
|
/**
|
|
@@ -51,7 +51,7 @@ export class TreeMembershipService {
|
|
|
51
51
|
blockNumber: BlockParameter,
|
|
52
52
|
nullifier: Fr,
|
|
53
53
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
54
|
-
const anchorBlockNumber = (await this.
|
|
54
|
+
const anchorBlockNumber = (await this.anchorBlockStore.getBlockHeader()).getBlockNumber();
|
|
55
55
|
if (blockNumber !== 'latest' && blockNumber > anchorBlockNumber) {
|
|
56
56
|
throw new Error(`Block number ${blockNumber} is higher than current block ${anchorBlockNumber}`);
|
|
57
57
|
}
|
|
@@ -64,7 +64,7 @@ export class TreeMembershipService {
|
|
|
64
64
|
* @param leafSlot - The slot of the public data in the public data tree.
|
|
65
65
|
*/
|
|
66
66
|
public async getPublicDataWitness(blockNumber: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
|
|
67
|
-
const anchorBlockNumber = (await this.
|
|
67
|
+
const anchorBlockNumber = (await this.anchorBlockStore.getBlockHeader()).getBlockNumber();
|
|
68
68
|
if (blockNumber !== 'latest' && blockNumber > anchorBlockNumber) {
|
|
69
69
|
throw new Error(`Block number ${blockNumber} is higher than current block ${anchorBlockNumber}`);
|
|
70
70
|
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
2
|
-
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
3
|
-
import { CompleteAddress } from '@aztec/stdlib/contract';
|
|
4
|
-
export declare class AddressDataProvider {
|
|
5
|
-
#private;
|
|
6
|
-
constructor(store: AztecAsyncKVStore);
|
|
7
|
-
addCompleteAddress(completeAddress: CompleteAddress): Promise<boolean>;
|
|
8
|
-
getCompleteAddress(account: AztecAddress): Promise<CompleteAddress | undefined>;
|
|
9
|
-
getCompleteAddresses(): Promise<CompleteAddress[]>;
|
|
10
|
-
}
|
|
11
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWRkcmVzc19kYXRhX3Byb3ZpZGVyLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvc3RvcmFnZS9hZGRyZXNzX2RhdGFfcHJvdmlkZXIvYWRkcmVzc19kYXRhX3Byb3ZpZGVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLE9BQU8sS0FBSyxFQUFtQixpQkFBaUIsRUFBaUIsTUFBTSxpQkFBaUIsQ0FBQztBQUN6RixPQUFPLEtBQUssRUFBRSxZQUFZLEVBQUUsTUFBTSw2QkFBNkIsQ0FBQztBQUNoRSxPQUFPLEVBQUUsZUFBZSxFQUFFLE1BQU0sd0JBQXdCLENBQUM7QUFFekQscUJBQWEsbUJBQW1COztJQUs5QixZQUFZLEtBQUssRUFBRSxpQkFBaUIsRUFLbkM7SUFFRCxrQkFBa0IsQ0FBQyxlQUFlLEVBQUUsZUFBZSxHQUFHLE9BQU8sQ0FBQyxPQUFPLENBQUMsQ0EwQnJFO0lBWUQsa0JBQWtCLENBQUMsT0FBTyxFQUFFLFlBQVksR0FBRyxPQUFPLENBQUMsZUFBZSxHQUFHLFNBQVMsQ0FBQyxDQUU5RTtJQUVLLG9CQUFvQixJQUFJLE9BQU8sQ0FBQyxlQUFlLEVBQUUsQ0FBQyxDQUl2RDtDQUNGIn0=
|