@aztec/pxe 0.0.1-commit.c7c42ec → 0.0.1-commit.f295ac2
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 +6 -2
- package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
- package/dest/block_synchronizer/block_synchronizer.js +21 -13
- package/dest/config/package_info.js +1 -1
- package/dest/contract_function_simulator/benchmarked_node.d.ts +9 -0
- package/dest/contract_function_simulator/benchmarked_node.d.ts.map +1 -0
- package/dest/contract_function_simulator/benchmarked_node.js +77 -0
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +8 -9
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +33 -16
- package/dest/contract_function_simulator/execution_note_cache.d.ts +18 -9
- package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -1
- package/dest/contract_function_simulator/execution_note_cache.js +45 -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/noir-structs/utility_context.d.ts +4 -10
- package/dest/contract_function_simulator/noir-structs/utility_context.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/utility_context.js +7 -18
- package/dest/contract_function_simulator/oracle/interfaces.d.ts +9 -8
- package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts +3 -1
- package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts +4 -4
- package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/note_packing_utils.js +5 -5
- package/dest/contract_function_simulator/oracle/oracle.d.ts +6 -6
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +20 -19
- package/dest/contract_function_simulator/oracle/private_execution.d.ts +5 -9
- package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution.js +11 -10
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +8 -18
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +10 -35
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +14 -12
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +54 -52
- 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/index.d.ts +2 -1
- package/dest/entrypoints/server/index.d.ts.map +1 -1
- package/dest/entrypoints/server/index.js +1 -0
- package/dest/entrypoints/server/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/events/event_service.d.ts +4 -3
- package/dest/events/event_service.d.ts.map +1 -1
- package/dest/events/event_service.js +17 -19
- package/dest/events/private_event_filter_validator.d.ts +5 -5
- package/dest/events/private_event_filter_validator.d.ts.map +1 -1
- package/dest/events/private_event_filter_validator.js +5 -6
- 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 +3 -2
- package/dest/logs/log_service.d.ts.map +1 -1
- package/dest/logs/log_service.js +5 -3
- package/dest/notes/note_service.d.ts +3 -3
- package/dest/notes/note_service.d.ts.map +1 -1
- package/dest/notes/note_service.js +23 -28
- package/dest/oracle_version.d.ts +2 -2
- package/dest/oracle_version.js +2 -2
- package/dest/private_kernel/hints/index.d.ts +2 -2
- package/dest/private_kernel/hints/index.d.ts.map +1 -1
- package/dest/private_kernel/hints/index.js +1 -1
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +28 -0
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -0
- package/dest/private_kernel/hints/{build_private_kernel_reset_private_inputs.js → private_kernel_reset_private_inputs_builder.js} +13 -7
- 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 +4 -5
- package/dest/private_kernel/private_kernel_oracle.d.ts +24 -28
- package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_oracle.js +90 -2
- package/dest/pxe.d.ts +8 -36
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +65 -87
- package/dest/storage/capsule_store/capsule_store.d.ts +24 -9
- package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
- package/dest/storage/capsule_store/capsule_store.js +132 -23
- package/dest/storage/contract_store/contract_store.d.ts +2 -1
- package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
- package/dest/storage/contract_store/contract_store.js +12 -0
- package/dest/storage/note_store/note_store.d.ts +6 -5
- package/dest/storage/note_store/note_store.d.ts.map +1 -1
- package/dest/storage/note_store/note_store.js +89 -94
- package/dest/storage/private_event_store/private_event_store.d.ts +33 -6
- package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
- package/dest/storage/private_event_store/private_event_store.js +139 -32
- package/dest/storage/tagging_store/recipient_tagging_store.d.ts +15 -8
- package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/recipient_tagging_store.js +69 -12
- package/dest/storage/tagging_store/sender_tagging_store.d.ts +19 -9
- package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/sender_tagging_store.js +110 -28
- package/dest/tagging/constants.d.ts +2 -0
- package/dest/tagging/constants.d.ts.map +1 -0
- package/dest/tagging/constants.js +10 -0
- package/dest/tagging/index.d.ts +2 -2
- package/dest/tagging/index.d.ts.map +1 -1
- package/dest/tagging/index.js +1 -10
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +2 -2
- 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/sender_sync/sync_sender_tagging_indexes.d.ts +2 -2
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +8 -8
- package/dest/tagging/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 -1
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +2 -2
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +4 -2
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +4 -2
- package/dest/tree_membership/tree_membership_service.d.ts +9 -11
- package/dest/tree_membership/tree_membership_service.d.ts.map +1 -1
- package/dest/tree_membership/tree_membership_service.js +25 -34
- package/package.json +18 -18
- package/src/block_synchronizer/block_synchronizer.ts +30 -12
- package/src/config/package_info.ts +1 -1
- package/src/contract_function_simulator/benchmarked_node.ts +103 -0
- package/src/contract_function_simulator/contract_function_simulator.ts +42 -16
- package/src/contract_function_simulator/execution_note_cache.ts +44 -25
- package/src/contract_function_simulator/noir-structs/event_validation_request.ts +4 -0
- package/src/contract_function_simulator/noir-structs/utility_context.ts +6 -25
- package/src/contract_function_simulator/oracle/interfaces.ts +8 -7
- package/src/contract_function_simulator/oracle/note_packing_utils.ts +6 -6
- package/src/contract_function_simulator/oracle/oracle.ts +24 -22
- package/src/contract_function_simulator/oracle/private_execution.ts +10 -19
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +13 -38
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +56 -50
- 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/index.ts +1 -0
- package/src/entrypoints/server/utils.ts +11 -15
- package/src/events/event_service.ts +17 -21
- package/src/events/private_event_filter_validator.ts +3 -5
- package/src/job_coordinator/job_coordinator.ts +149 -0
- package/src/logs/log_service.ts +3 -1
- package/src/notes/note_service.ts +23 -29
- package/src/oracle_version.ts +2 -2
- package/src/private_kernel/hints/index.ts +1 -1
- package/src/private_kernel/hints/{build_private_kernel_reset_private_inputs.ts → private_kernel_reset_private_inputs_builder.ts} +33 -22
- package/src/private_kernel/private_kernel_execution_prover.ts +3 -5
- package/src/private_kernel/private_kernel_oracle.ts +116 -36
- package/src/pxe.ts +98 -116
- package/src/storage/capsule_store/capsule_store.ts +159 -23
- package/src/storage/contract_store/contract_store.ts +20 -0
- package/src/storage/note_store/note_store.ts +98 -95
- package/src/storage/private_event_store/private_event_store.ts +199 -37
- package/src/storage/tagging_store/recipient_tagging_store.ts +89 -13
- package/src/storage/tagging_store/sender_tagging_store.ts +129 -28
- package/src/tagging/constants.ts +10 -0
- package/src/tagging/index.ts +1 -11
- package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +10 -6
- package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +8 -7
- package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +6 -2
- package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +4 -1
- package/src/tree_membership/tree_membership_service.ts +27 -42
- package/dest/contract_function_simulator/proxied_node.d.ts +0 -9
- package/dest/contract_function_simulator/proxied_node.d.ts.map +0 -1
- package/dest/contract_function_simulator/proxied_node.js +0 -27
- package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts +0 -28
- package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts.map +0 -1
- package/dest/private_kernel/private_kernel_oracle_impl.d.ts +0 -46
- package/dest/private_kernel/private_kernel_oracle_impl.d.ts.map +0 -1
- package/dest/private_kernel/private_kernel_oracle_impl.js +0 -86
- package/dest/public_storage/public_storage_service.d.ts +0 -24
- package/dest/public_storage/public_storage_service.d.ts.map +0 -1
- package/dest/public_storage/public_storage_service.js +0 -26
- package/src/contract_function_simulator/proxied_node.ts +0 -33
- package/src/private_kernel/private_kernel_oracle_impl.ts +0 -133
- package/src/public_storage/public_storage_service.ts +0 -33
|
@@ -3,6 +3,7 @@ import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
|
3
3
|
import type { EventSelector } from '@aztec/stdlib/abi';
|
|
4
4
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
5
|
import { type InTx, TxHash } from '@aztec/stdlib/tx';
|
|
6
|
+
import type { StagedStore } from '../../job_coordinator/job_coordinator.js';
|
|
6
7
|
import type { PackedPrivateEvent } from '../../pxe.js';
|
|
7
8
|
export type PrivateEventStoreFilter = {
|
|
8
9
|
contractAddress: AztecAddress;
|
|
@@ -14,26 +15,34 @@ export type PrivateEventStoreFilter = {
|
|
|
14
15
|
type PrivateEventMetadata = InTx & {
|
|
15
16
|
contractAddress: AztecAddress;
|
|
16
17
|
scope: AztecAddress;
|
|
18
|
+
/** The index of the tx within the block */
|
|
19
|
+
txIndexInBlock: number;
|
|
20
|
+
/** The index of the event within the tx (based on nullifier position) */
|
|
21
|
+
eventIndexInTx: number;
|
|
17
22
|
};
|
|
18
23
|
/**
|
|
19
24
|
* Stores decrypted private event logs.
|
|
20
25
|
*/
|
|
21
|
-
export declare class PrivateEventStore {
|
|
26
|
+
export declare class PrivateEventStore implements StagedStore {
|
|
22
27
|
#private;
|
|
28
|
+
readonly storeName: string;
|
|
23
29
|
logger: import("@aztec/foundation/log").Logger;
|
|
24
30
|
constructor(store: AztecAsyncKVStore);
|
|
31
|
+
commit(jobId: string): Promise<void>;
|
|
32
|
+
discardStaged(jobId: string): Promise<void>;
|
|
25
33
|
/**
|
|
26
34
|
* Store a private event log.
|
|
27
35
|
* @param eventSelector - The event selector of the event.
|
|
36
|
+
* @param randomness - The randomness used for the event commitment.
|
|
28
37
|
* @param msgContent - The content of the event.
|
|
29
|
-
* @param
|
|
38
|
+
* @param siloedEventCommitment - The siloed event commitment (used as unique identifier).
|
|
30
39
|
* @param metadata
|
|
31
40
|
* contractAddress - The address of the contract that emitted the event.
|
|
32
41
|
* scope - The address to which the event is scoped.
|
|
33
42
|
* txHash - The transaction hash of the event log.
|
|
34
43
|
* blockNumber - The block number in which the event was emitted.
|
|
35
44
|
*/
|
|
36
|
-
storePrivateEventLog(eventSelector: EventSelector, msgContent: Fr[],
|
|
45
|
+
storePrivateEventLog(eventSelector: EventSelector, randomness: Fr, msgContent: Fr[], siloedEventCommitment: Fr, metadata: PrivateEventMetadata, jobId: string): Promise<void>;
|
|
37
46
|
/**
|
|
38
47
|
* Returns the private events given search parameters.
|
|
39
48
|
* @param eventSelector - The event selector to filter by.
|
|
@@ -42,10 +51,28 @@ export declare class PrivateEventStore {
|
|
|
42
51
|
* fromBlock: The block number to search from (inclusive).
|
|
43
52
|
* toBlock: The block number to search upto (exclusive).
|
|
44
53
|
* scope: - The addresses that decrypted the logs.
|
|
45
|
-
* @returns - The event log contents, augmented with metadata about
|
|
46
|
-
*
|
|
54
|
+
* @returns - The event log contents, augmented with metadata about the transaction and block in which the event was
|
|
55
|
+
* included.
|
|
47
56
|
*/
|
|
48
57
|
getPrivateEvents(eventSelector: EventSelector, filter: PrivateEventStoreFilter): Promise<PackedPrivateEvent[]>;
|
|
58
|
+
/**
|
|
59
|
+
* Rolls back private events that were stored after a given `blockNumber` and up to `synchedBlockNumber` (the block
|
|
60
|
+
* number up to which PXE managed to sync before the reorg happened).
|
|
61
|
+
*
|
|
62
|
+
* We don't need staged writes for a rollback since it's handled in the context of a blockchain rewind.
|
|
63
|
+
*
|
|
64
|
+
* Rollbacks are handled by the BlockSynchronizer, which runs a DB transaction across stores when it detects a
|
|
65
|
+
* re-org, including setting the new anchor block after rolling back.
|
|
66
|
+
*
|
|
67
|
+
* So if anything fails in the process of rolling back any store, all DB changes occurring during rollbacks will be
|
|
68
|
+
* lost and the anchor block will not be updated; which means this code will eventually need to run again
|
|
69
|
+
* (i.e.: PXE will detect it's basing it work on an invalid block hash, then which re-triggers rewind).
|
|
70
|
+
*
|
|
71
|
+
* For further details, refer to `BlockSynchronizer#handleBlockStreamEvent`.
|
|
72
|
+
*
|
|
73
|
+
* IMPORTANT: This method must be called within a transaction to ensure atomicity.
|
|
74
|
+
*/
|
|
75
|
+
rollback(blockNumber: number, synchedBlockNumber: number): Promise<void>;
|
|
49
76
|
}
|
|
50
77
|
export {};
|
|
51
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
78
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHJpdmF0ZV9ldmVudF9zdG9yZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL3N0b3JhZ2UvcHJpdmF0ZV9ldmVudF9zdG9yZS9wcml2YXRlX2V2ZW50X3N0b3JlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLE9BQU8sRUFBRSxFQUFFLEVBQUUsTUFBTSxnQ0FBZ0MsQ0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1LLE1BQU0sQ0FBQyxLQUFLLEVBQUUsTUFBTSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FlekM7SUFFRCxhQUFhLENBQUMsS0FBSyxFQUFFLE1BQU0sR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLENBRzFDO0lBb0REOzs7Ozs7Ozs7OztPQVdHO0lBQ0gsb0JBQW9CLENBQ2xCLGFBQWEsRUFBRSxhQUFhLEVBQzVCLFVBQVUsRUFBRSxFQUFFLEVBQ2QsVUFBVSxFQUFFLEVBQUUsRUFBRSxFQUNoQixxQkFBcUIsRUFBRSxFQUFFLEVBQ3pCLFFBQVEsRUFBRSxvQkFBb0IsRUFDOUIsS0FBSyxFQUFFLE1BQU0sR0FDWixPQUFPLENBQUMsSUFBSSxDQUFDLENBa0NmO0lBRUQ7Ozs7Ozs7Ozs7T0FVRztJQUNVLGdCQUFnQixDQUMzQixhQUFhLEVBQUUsYUFBYSxFQUM1QixNQUFNLEVBQUUsdUJBQXVCLEdBQzlCLE9BQU8sQ0FBQyxrQkFBa0IsRUFBRSxDQUFDLENBdUQvQjtJQUVEOzs7Ozs7Ozs7Ozs7Ozs7O09BZ0JHO0lBQ1UsUUFBUSxDQUFDLFdBQVcsRUFBRSxNQUFNLEVBQUUsa0JBQWtCLEVBQUUsTUFBTSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0E0QnBGO0NBQ0YifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"private_event_store.d.ts","sourceRoot":"","sources":["../../../src/storage/private_event_store/private_event_store.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AAGpD,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"private_event_store.d.ts","sourceRoot":"","sources":["../../../src/storage/private_event_store/private_event_store.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AAGpD,OAAO,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9B,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,IAAI,CAAC,CAkCf;IAED;;;;;;;;;;OAUG;IACU,gBAAgB,CAC3B,aAAa,EAAE,aAAa,EAC5B,MAAM,EAAE,uBAAuB,GAC9B,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAuD/B;IAED;;;;;;;;;;;;;;;;OAgBG;IACU,QAAQ,CAAC,WAAW,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CA4BpF;CACF"}
|
|
@@ -7,64 +7,123 @@ import { TxHash } from '@aztec/stdlib/tx';
|
|
|
7
7
|
/**
|
|
8
8
|
* Stores decrypted private event logs.
|
|
9
9
|
*/ export class PrivateEventStore {
|
|
10
|
+
storeName = 'private_event';
|
|
10
11
|
#store;
|
|
11
|
-
/**
|
|
12
|
-
/**
|
|
13
|
-
/**
|
|
12
|
+
/** Map storing the actual private event log entries, keyed by siloedEventCommitment */ #eventLogs;
|
|
13
|
+
/** Multi-map from contractAddress_scope_eventSelector to siloedEventCommitment for efficient lookup */ #eventsByContractScopeSelector;
|
|
14
|
+
/** Multi-map from block number to siloedEventCommitment for rollback support */ #eventsByBlockNumber;
|
|
15
|
+
/** Map from siloedEventCommitment to boolean indicating if log has been seen. */ #seenLogs;
|
|
16
|
+
/** jobId => eventId (event siloed nullifier) => PrivateEventEntry */ #eventLogsInJobStage;
|
|
14
17
|
logger = createLogger('private_event_store');
|
|
15
18
|
constructor(store){
|
|
16
19
|
this.#store = store;
|
|
17
|
-
this.#eventLogs = this.#store.
|
|
18
|
-
this.#
|
|
20
|
+
this.#eventLogs = this.#store.openMap('private_event_logs');
|
|
21
|
+
this.#eventsByContractScopeSelector = this.#store.openMultiMap('events_by_contract_scope_selector');
|
|
19
22
|
this.#seenLogs = this.#store.openMap('seen_logs');
|
|
23
|
+
this.#eventsByBlockNumber = this.#store.openMultiMap('events_by_block_number');
|
|
24
|
+
this.#eventLogsInJobStage = new Map();
|
|
20
25
|
}
|
|
21
26
|
#keyFor(contractAddress, scope, eventSelector) {
|
|
22
27
|
return `${contractAddress.toString()}_${scope.toString()}_${eventSelector.toString()}`;
|
|
23
28
|
}
|
|
29
|
+
async commit(jobId) {
|
|
30
|
+
await Promise.all([
|
|
31
|
+
...this.#getEventLogsInJobStage(jobId).entries()
|
|
32
|
+
].map(async ([eventId, eventEntry])=>{
|
|
33
|
+
this.logger.verbose('storing private event log (KV store)', eventEntry);
|
|
34
|
+
await Promise.all([
|
|
35
|
+
this.#eventLogs.set(eventId, eventEntry),
|
|
36
|
+
this.#eventsByContractScopeSelector.set(eventEntry.lookupKey, eventId),
|
|
37
|
+
this.#eventsByBlockNumber.set(eventEntry.l2BlockNumber, eventId),
|
|
38
|
+
this.#seenLogs.set(eventId, true)
|
|
39
|
+
]);
|
|
40
|
+
}));
|
|
41
|
+
return this.discardStaged(jobId);
|
|
42
|
+
}
|
|
43
|
+
discardStaged(jobId) {
|
|
44
|
+
this.#eventLogsInJobStage.delete(jobId);
|
|
45
|
+
return Promise.resolve();
|
|
46
|
+
}
|
|
47
|
+
#getEventLogsInJobStage(jobId) {
|
|
48
|
+
let jobStage = this.#eventLogsInJobStage.get(jobId);
|
|
49
|
+
if (jobStage === undefined) {
|
|
50
|
+
jobStage = new Map();
|
|
51
|
+
this.#eventLogsInJobStage.set(jobId, jobStage);
|
|
52
|
+
}
|
|
53
|
+
return jobStage;
|
|
54
|
+
}
|
|
55
|
+
async #isSeenLog(jobId, eventId) {
|
|
56
|
+
const eventLogsInJobStage = this.#getEventLogsInJobStage(jobId).get(eventId);
|
|
57
|
+
return !!eventLogsInJobStage || !!await this.#seenLogs.getAsync(eventId);
|
|
58
|
+
}
|
|
59
|
+
#addEventLogToStage(jobId, eventId, eventEntry) {
|
|
60
|
+
this.#getEventLogsInJobStage(jobId).set(eventId, eventEntry);
|
|
61
|
+
}
|
|
62
|
+
async #getEventSiloedNullifiers(contractAddress, scope, eventSelector, jobId) {
|
|
63
|
+
const key = this.#keyFor(contractAddress, scope, eventSelector);
|
|
64
|
+
const eventSiloedNullifiersInStorage = [];
|
|
65
|
+
for await (const eventId of this.#eventsByContractScopeSelector.getValuesAsync(key)){
|
|
66
|
+
eventSiloedNullifiersInStorage.push(eventId);
|
|
67
|
+
}
|
|
68
|
+
if (!jobId) {
|
|
69
|
+
return eventSiloedNullifiersInStorage;
|
|
70
|
+
}
|
|
71
|
+
const eventSiloedNullifiersInJobStage = new Set([
|
|
72
|
+
...this.#getEventLogsInJobStage(jobId).entries()
|
|
73
|
+
].filter(([_, entry])=>entry.lookupKey === key).map(([idx, _])=>idx));
|
|
74
|
+
return [
|
|
75
|
+
...new Set(eventSiloedNullifiersInStorage).union(eventSiloedNullifiersInJobStage)
|
|
76
|
+
];
|
|
77
|
+
}
|
|
78
|
+
async #getEventLogBySiloedNullifier(eventId, jobId) {
|
|
79
|
+
if (jobId) {
|
|
80
|
+
return this.#getEventLogsInJobStage(jobId).get(eventId) ?? await this.#eventLogs.getAsync(eventId);
|
|
81
|
+
} else {
|
|
82
|
+
return await this.#eventLogs.getAsync(eventId);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
24
85
|
/**
|
|
25
86
|
* Store a private event log.
|
|
26
87
|
* @param eventSelector - The event selector of the event.
|
|
88
|
+
* @param randomness - The randomness used for the event commitment.
|
|
27
89
|
* @param msgContent - The content of the event.
|
|
28
|
-
* @param
|
|
90
|
+
* @param siloedEventCommitment - The siloed event commitment (used as unique identifier).
|
|
29
91
|
* @param metadata
|
|
30
92
|
* contractAddress - The address of the contract that emitted the event.
|
|
31
93
|
* scope - The address to which the event is scoped.
|
|
32
94
|
* txHash - The transaction hash of the event log.
|
|
33
95
|
* blockNumber - The block number in which the event was emitted.
|
|
34
|
-
*/ storePrivateEventLog(eventSelector, msgContent,
|
|
35
|
-
const { contractAddress, scope, txHash, l2BlockNumber, l2BlockHash } = metadata;
|
|
96
|
+
*/ storePrivateEventLog(eventSelector, randomness, msgContent, siloedEventCommitment, metadata, jobId) {
|
|
97
|
+
const { contractAddress, scope, txHash, l2BlockNumber, l2BlockHash, txIndexInBlock, eventIndexInTx } = metadata;
|
|
36
98
|
return this.#store.transactionAsync(async ()=>{
|
|
37
99
|
const key = this.#keyFor(contractAddress, scope, eventSelector);
|
|
38
|
-
//
|
|
39
|
-
|
|
100
|
+
// The siloed event commitment is guaranteed to be unique as it's inserted into the nullifier tree. For this
|
|
101
|
+
// reason we use it as id.
|
|
102
|
+
const eventId = siloedEventCommitment.toString();
|
|
103
|
+
const hasBeenSeen = await this.#isSeenLog(jobId, eventId);
|
|
40
104
|
if (hasBeenSeen) {
|
|
41
105
|
this.logger.verbose('Ignoring duplicate event log', {
|
|
42
106
|
txHash: txHash.toString(),
|
|
43
|
-
|
|
107
|
+
siloedEventCommitment
|
|
44
108
|
});
|
|
45
109
|
return;
|
|
46
110
|
}
|
|
47
|
-
this.logger.verbose('storing private event log', {
|
|
111
|
+
this.logger.verbose('storing private event log (job stage)', {
|
|
48
112
|
contractAddress,
|
|
49
113
|
scope,
|
|
50
114
|
msgContent,
|
|
51
115
|
l2BlockNumber
|
|
52
116
|
});
|
|
53
|
-
|
|
54
|
-
|
|
117
|
+
this.#addEventLogToStage(jobId, eventId, {
|
|
118
|
+
randomness,
|
|
55
119
|
msgContent: serializeToBuffer(msgContent),
|
|
56
120
|
l2BlockNumber,
|
|
57
121
|
l2BlockHash: l2BlockHash.toBuffer(),
|
|
58
|
-
|
|
59
|
-
|
|
122
|
+
txHash: txHash.toBuffer(),
|
|
123
|
+
txIndexInBlock,
|
|
124
|
+
eventIndexInTx,
|
|
125
|
+
lookupKey: key
|
|
60
126
|
});
|
|
61
|
-
const existingIndices = await this.#eventLogIndex.getAsync(key) || [];
|
|
62
|
-
await this.#eventLogIndex.set(key, [
|
|
63
|
-
...existingIndices,
|
|
64
|
-
index
|
|
65
|
-
]);
|
|
66
|
-
// Mark this log as seen using eventCommitmentIndex
|
|
67
|
-
await this.#seenLogs.set(eventCommitmentIndex, true);
|
|
68
127
|
});
|
|
69
128
|
}
|
|
70
129
|
/**
|
|
@@ -75,15 +134,14 @@ import { TxHash } from '@aztec/stdlib/tx';
|
|
|
75
134
|
* fromBlock: The block number to search from (inclusive).
|
|
76
135
|
* toBlock: The block number to search upto (exclusive).
|
|
77
136
|
* scope: - The addresses that decrypted the logs.
|
|
78
|
-
* @returns - The event log contents, augmented with metadata about
|
|
79
|
-
*
|
|
137
|
+
* @returns - The event log contents, augmented with metadata about the transaction and block in which the event was
|
|
138
|
+
* included.
|
|
80
139
|
*/ async getPrivateEvents(eventSelector, filter) {
|
|
81
140
|
const events = [];
|
|
82
141
|
for (const scope of filter.scopes){
|
|
83
|
-
const
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
const entry = await this.#eventLogs.atAsync(index);
|
|
142
|
+
const eventIds = await this.#getEventSiloedNullifiers(filter.contractAddress, scope, eventSelector);
|
|
143
|
+
for (const eventId of eventIds){
|
|
144
|
+
const entry = await this.#getEventLogBySiloedNullifier(eventId);
|
|
87
145
|
if (!entry || entry.l2BlockNumber < filter.fromBlock || entry.l2BlockNumber >= filter.toBlock) {
|
|
88
146
|
continue;
|
|
89
147
|
}
|
|
@@ -97,7 +155,9 @@ import { TxHash } from '@aztec/stdlib/tx';
|
|
|
97
155
|
continue;
|
|
98
156
|
}
|
|
99
157
|
events.push({
|
|
100
|
-
|
|
158
|
+
l2BlockNumber: entry.l2BlockNumber,
|
|
159
|
+
txIndexInBlock: entry.txIndexInBlock,
|
|
160
|
+
eventIndexInTx: entry.eventIndexInTx,
|
|
101
161
|
event: {
|
|
102
162
|
packedEvent: msgContent,
|
|
103
163
|
l2BlockNumber: BlockNumber(entry.l2BlockNumber),
|
|
@@ -108,8 +168,55 @@ import { TxHash } from '@aztec/stdlib/tx';
|
|
|
108
168
|
});
|
|
109
169
|
}
|
|
110
170
|
}
|
|
111
|
-
// Sort by
|
|
112
|
-
events.sort((a, b)=>
|
|
171
|
+
// Sort by block number, then by tx index within block, then by event index within tx
|
|
172
|
+
events.sort((a, b)=>{
|
|
173
|
+
if (a.l2BlockNumber !== b.l2BlockNumber) {
|
|
174
|
+
return a.l2BlockNumber - b.l2BlockNumber;
|
|
175
|
+
}
|
|
176
|
+
if (a.txIndexInBlock !== b.txIndexInBlock) {
|
|
177
|
+
return a.txIndexInBlock - b.txIndexInBlock;
|
|
178
|
+
}
|
|
179
|
+
return a.eventIndexInTx - b.eventIndexInTx;
|
|
180
|
+
});
|
|
113
181
|
return events.map((ev)=>ev.event);
|
|
114
182
|
}
|
|
183
|
+
/**
|
|
184
|
+
* Rolls back private events that were stored after a given `blockNumber` and up to `synchedBlockNumber` (the block
|
|
185
|
+
* number up to which PXE managed to sync before the reorg happened).
|
|
186
|
+
*
|
|
187
|
+
* We don't need staged writes for a rollback since it's handled in the context of a blockchain rewind.
|
|
188
|
+
*
|
|
189
|
+
* Rollbacks are handled by the BlockSynchronizer, which runs a DB transaction across stores when it detects a
|
|
190
|
+
* re-org, including setting the new anchor block after rolling back.
|
|
191
|
+
*
|
|
192
|
+
* So if anything fails in the process of rolling back any store, all DB changes occurring during rollbacks will be
|
|
193
|
+
* lost and the anchor block will not be updated; which means this code will eventually need to run again
|
|
194
|
+
* (i.e.: PXE will detect it's basing it work on an invalid block hash, then which re-triggers rewind).
|
|
195
|
+
*
|
|
196
|
+
* For further details, refer to `BlockSynchronizer#handleBlockStreamEvent`.
|
|
197
|
+
*
|
|
198
|
+
* IMPORTANT: This method must be called within a transaction to ensure atomicity.
|
|
199
|
+
*/ async rollback(blockNumber, synchedBlockNumber) {
|
|
200
|
+
let removedCount = 0;
|
|
201
|
+
for(let block = blockNumber + 1; block <= synchedBlockNumber; block++){
|
|
202
|
+
const eventIds = [];
|
|
203
|
+
for await (const eventId of this.#eventsByBlockNumber.getValuesAsync(block)){
|
|
204
|
+
eventIds.push(eventId);
|
|
205
|
+
}
|
|
206
|
+
if (eventIds.length > 0) {
|
|
207
|
+
await this.#eventsByBlockNumber.delete(block);
|
|
208
|
+
for (const eventId of eventIds){
|
|
209
|
+
const entry = await this.#eventLogs.getAsync(eventId);
|
|
210
|
+
if (!entry) {
|
|
211
|
+
throw new Error(`Event log not found for eventId ${eventId}`);
|
|
212
|
+
}
|
|
213
|
+
await this.#eventLogs.delete(eventId);
|
|
214
|
+
await this.#seenLogs.delete(eventId);
|
|
215
|
+
await this.#eventsByContractScopeSelector.deleteValue(entry.lookupKey, eventId);
|
|
216
|
+
removedCount++;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
this.logger.verbose(`Rolled back ${removedCount} private events after block ${blockNumber}`);
|
|
221
|
+
}
|
|
115
222
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
2
2
|
import type { DirectionalAppTaggingSecret } from '@aztec/stdlib/logs';
|
|
3
|
+
import type { StagedStore } from '../../job_coordinator/job_coordinator.js';
|
|
3
4
|
/**
|
|
4
5
|
* Data provider of tagging data used when syncing the logs as a recipient. The sender counterpart of this class
|
|
5
6
|
* is called SenderTaggingStore. We have the providers separate for the sender and recipient because
|
|
@@ -7,15 +8,21 @@ import type { DirectionalAppTaggingSecret } from '@aztec/stdlib/logs';
|
|
|
7
8
|
*
|
|
8
9
|
* @dev Chain reorgs do not need to be handled here because both the finalized and aged indexes refer to finalized
|
|
9
10
|
* blocks, which by definition cannot be affected by reorgs.
|
|
10
|
-
*
|
|
11
|
-
* TODO(benesjan): Relocate to yarn-project/pxe/src/storage/tagging_store
|
|
12
11
|
*/
|
|
13
|
-
export declare class RecipientTaggingStore {
|
|
12
|
+
export declare class RecipientTaggingStore implements StagedStore {
|
|
14
13
|
#private;
|
|
14
|
+
storeName: string;
|
|
15
15
|
constructor(store: AztecAsyncKVStore);
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Writes all job-specific in-memory data to persistent storage.
|
|
18
|
+
*
|
|
19
|
+
* @remark This method must run in a DB transaction context. It's designed to be called from JobCoordinator#commitJob.
|
|
20
|
+
*/
|
|
21
|
+
commit(jobId: string): Promise<void>;
|
|
22
|
+
discardStaged(jobId: string): Promise<void>;
|
|
23
|
+
getHighestAgedIndex(secret: DirectionalAppTaggingSecret, jobId: string): Promise<number | undefined>;
|
|
24
|
+
updateHighestAgedIndex(secret: DirectionalAppTaggingSecret, index: number, jobId: string): Promise<void>;
|
|
25
|
+
getHighestFinalizedIndex(secret: DirectionalAppTaggingSecret, jobId: string): Promise<number | undefined>;
|
|
26
|
+
updateHighestFinalizedIndex(secret: DirectionalAppTaggingSecret, index: number, jobId: string): Promise<void>;
|
|
20
27
|
}
|
|
21
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
28
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmVjaXBpZW50X3RhZ2dpbmdfc3RvcmUuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9zdG9yYWdlL3RhZ2dpbmdfc3RvcmUvcmVjaXBpZW50X3RhZ2dpbmdfc3RvcmUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLEVBQUUsaUJBQWlCLEVBQWlCLE1BQU0saUJBQWlCLENBQUM7QUFDeEUsT0FBTyxLQUFLLEVBQUUsMkJBQTJCLEVBQUUsTUFBTSxvQkFBb0IsQ0FBQztBQUV0RSxPQUFPLEtBQUssRUFBRSxXQUFXLEVBQUUsTUFBTSwwQ0FBMEMsQ0FBQztBQUU1RTs7Ozs7OztHQU9HO0FBQ0gscUJBQWEscUJBQXNCLFlBQVcsV0FBVzs7SUFDdkQsU0FBUyxFQUFFLE1BQU0sQ0FBdUI7SUFheEMsWUFBWSxLQUFLLEVBQUUsaUJBQWlCLEVBUW5DO0lBc0NEOzs7O09BSUc7SUFDRyxNQUFNLENBQUMsS0FBSyxFQUFFLE1BQU0sR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLENBZ0J6QztJQUVELGFBQWEsQ0FBQyxLQUFLLEVBQUUsTUFBTSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FJMUM7SUFFRCxtQkFBbUIsQ0FBQyxNQUFNLEVBQUUsMkJBQTJCLEVBQUUsS0FBSyxFQUFFLE1BQU0sR0FBRyxPQUFPLENBQUMsTUFBTSxHQUFHLFNBQVMsQ0FBQyxDQUVuRztJQUVLLHNCQUFzQixDQUFDLE1BQU0sRUFBRSwyQkFBMkIsRUFBRSxLQUFLLEVBQUUsTUFBTSxFQUFFLEtBQUssRUFBRSxNQUFNLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxDQU83RztJQUVELHdCQUF3QixDQUFDLE1BQU0sRUFBRSwyQkFBMkIsRUFBRSxLQUFLLEVBQUUsTUFBTSxHQUFHLE9BQU8sQ0FBQyxNQUFNLEdBQUcsU0FBUyxDQUFDLENBRXhHO0lBRUssMkJBQTJCLENBQUMsTUFBTSxFQUFFLDJCQUEyQixFQUFFLEtBQUssRUFBRSxNQUFNLEVBQUUsS0FBSyxFQUFFLE1BQU0sR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLENBUWxIO0NBQ0YifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recipient_tagging_store.d.ts","sourceRoot":"","sources":["../../../src/storage/tagging_store/recipient_tagging_store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAiB,MAAM,iBAAiB,CAAC;AACxE,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AAEtE
|
|
1
|
+
{"version":3,"file":"recipient_tagging_store.d.ts","sourceRoot":"","sources":["../../../src/storage/tagging_store/recipient_tagging_store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAiB,MAAM,iBAAiB,CAAC;AACxE,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AAEtE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0CAA0C,CAAC;AAE5E;;;;;;;GAOG;AACH,qBAAa,qBAAsB,YAAW,WAAW;;IACvD,SAAS,EAAE,MAAM,CAAuB;IAaxC,YAAY,KAAK,EAAE,iBAAiB,EAQnC;IAsCD;;;;OAIG;IACG,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBzC;IAED,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAI1C;IAED,mBAAmB,CAAC,MAAM,EAAE,2BAA2B,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAEnG;IAEK,sBAAsB,CAAC,MAAM,EAAE,2BAA2B,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAO7G;IAED,wBAAwB,CAAC,MAAM,EAAE,2BAA2B,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAExG;IAEK,2BAA2B,CAAC,MAAM,EAAE,2BAA2B,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAQlH;CACF"}
|
|
@@ -5,38 +5,95 @@
|
|
|
5
5
|
*
|
|
6
6
|
* @dev Chain reorgs do not need to be handled here because both the finalized and aged indexes refer to finalized
|
|
7
7
|
* blocks, which by definition cannot be affected by reorgs.
|
|
8
|
-
*
|
|
9
|
-
* TODO(benesjan): Relocate to yarn-project/pxe/src/storage/tagging_store
|
|
10
8
|
*/ export class RecipientTaggingStore {
|
|
9
|
+
storeName = 'recipient_tagging';
|
|
11
10
|
#store;
|
|
12
11
|
#highestAgedIndex;
|
|
13
12
|
#highestFinalizedIndex;
|
|
13
|
+
// jobId => secret => number
|
|
14
|
+
#highestAgedIndexForJob;
|
|
15
|
+
// jobId => secret => number
|
|
16
|
+
#highestFinalizedIndexForJob;
|
|
14
17
|
constructor(store){
|
|
15
18
|
this.#store = store;
|
|
16
19
|
this.#highestAgedIndex = this.#store.openMap('highest_aged_index');
|
|
17
20
|
this.#highestFinalizedIndex = this.#store.openMap('highest_finalized_index');
|
|
21
|
+
this.#highestAgedIndexForJob = new Map();
|
|
22
|
+
this.#highestFinalizedIndexForJob = new Map();
|
|
23
|
+
}
|
|
24
|
+
#getHighestAgedIndexForJob(jobId) {
|
|
25
|
+
let highestAgedIndexForJob = this.#highestAgedIndexForJob.get(jobId);
|
|
26
|
+
if (!highestAgedIndexForJob) {
|
|
27
|
+
highestAgedIndexForJob = new Map();
|
|
28
|
+
this.#highestAgedIndexForJob.set(jobId, highestAgedIndexForJob);
|
|
29
|
+
}
|
|
30
|
+
return highestAgedIndexForJob;
|
|
31
|
+
}
|
|
32
|
+
async #readHighestAgedIndex(jobId, secret) {
|
|
33
|
+
return this.#getHighestAgedIndexForJob(jobId).get(secret) ?? await this.#highestAgedIndex.getAsync(secret);
|
|
34
|
+
}
|
|
35
|
+
#writeHighestAgedIndex(jobId, secret, index) {
|
|
36
|
+
this.#getHighestAgedIndexForJob(jobId).set(secret, index);
|
|
37
|
+
}
|
|
38
|
+
#getHighestFinalizedIndexForJob(jobId) {
|
|
39
|
+
let jobStagedHighestFinalizedIndex = this.#highestFinalizedIndexForJob.get(jobId);
|
|
40
|
+
if (!jobStagedHighestFinalizedIndex) {
|
|
41
|
+
jobStagedHighestFinalizedIndex = new Map();
|
|
42
|
+
this.#highestFinalizedIndexForJob.set(jobId, jobStagedHighestFinalizedIndex);
|
|
43
|
+
}
|
|
44
|
+
return jobStagedHighestFinalizedIndex;
|
|
45
|
+
}
|
|
46
|
+
async #readHighestFinalizedIndex(jobId, secret) {
|
|
47
|
+
return this.#getHighestFinalizedIndexForJob(jobId).get(secret) ?? await this.#highestFinalizedIndex.getAsync(secret);
|
|
48
|
+
}
|
|
49
|
+
#writeHighestFinalizedIndex(jobId, secret, index) {
|
|
50
|
+
this.#getHighestFinalizedIndexForJob(jobId).set(secret, index);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Writes all job-specific in-memory data to persistent storage.
|
|
54
|
+
*
|
|
55
|
+
* @remark This method must run in a DB transaction context. It's designed to be called from JobCoordinator#commitJob.
|
|
56
|
+
*/ async commit(jobId) {
|
|
57
|
+
const highestAgedIndexForJob = this.#highestAgedIndexForJob.get(jobId);
|
|
58
|
+
if (highestAgedIndexForJob) {
|
|
59
|
+
for (const [secret, index] of highestAgedIndexForJob.entries()){
|
|
60
|
+
await this.#highestAgedIndex.set(secret, index);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const highestFinalizedIndexForJob = this.#highestFinalizedIndexForJob.get(jobId);
|
|
64
|
+
if (highestFinalizedIndexForJob) {
|
|
65
|
+
for (const [secret, index] of highestFinalizedIndexForJob.entries()){
|
|
66
|
+
await this.#highestFinalizedIndex.set(secret, index);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return this.discardStaged(jobId);
|
|
70
|
+
}
|
|
71
|
+
discardStaged(jobId) {
|
|
72
|
+
this.#highestAgedIndexForJob.delete(jobId);
|
|
73
|
+
this.#highestFinalizedIndexForJob.delete(jobId);
|
|
74
|
+
return Promise.resolve();
|
|
18
75
|
}
|
|
19
|
-
getHighestAgedIndex(secret) {
|
|
20
|
-
return this.#
|
|
76
|
+
getHighestAgedIndex(secret, jobId) {
|
|
77
|
+
return this.#readHighestAgedIndex(jobId, secret.toString());
|
|
21
78
|
}
|
|
22
|
-
async updateHighestAgedIndex(secret, index) {
|
|
23
|
-
const currentIndex = await this.#
|
|
79
|
+
async updateHighestAgedIndex(secret, index, jobId) {
|
|
80
|
+
const currentIndex = await this.#readHighestAgedIndex(jobId, secret.toString());
|
|
24
81
|
if (currentIndex !== undefined && index <= currentIndex) {
|
|
25
82
|
// Log sync should never set a lower highest aged index.
|
|
26
83
|
throw new Error(`New highest aged index (${index}) must be higher than the current one (${currentIndex})`);
|
|
27
84
|
}
|
|
28
|
-
|
|
85
|
+
this.#writeHighestAgedIndex(jobId, secret.toString(), index);
|
|
29
86
|
}
|
|
30
|
-
getHighestFinalizedIndex(secret) {
|
|
31
|
-
return this.#
|
|
87
|
+
getHighestFinalizedIndex(secret, jobId) {
|
|
88
|
+
return this.#readHighestFinalizedIndex(jobId, secret.toString());
|
|
32
89
|
}
|
|
33
|
-
async updateHighestFinalizedIndex(secret, index) {
|
|
34
|
-
const currentIndex = await this.#
|
|
90
|
+
async updateHighestFinalizedIndex(secret, index, jobId) {
|
|
91
|
+
const currentIndex = await this.#readHighestFinalizedIndex(jobId, secret.toString());
|
|
35
92
|
if (currentIndex !== undefined && index < currentIndex) {
|
|
36
93
|
// Log sync should never set a lower highest finalized index but it can happen that it would try to set the same
|
|
37
94
|
// one because we are loading logs from highest aged index + 1 and not from the highest finalized index.
|
|
38
95
|
throw new Error(`New highest finalized index (${index}) must be higher than the current one (${currentIndex})`);
|
|
39
96
|
}
|
|
40
|
-
|
|
97
|
+
this.#writeHighestFinalizedIndex(jobId, secret.toString(), index);
|
|
41
98
|
}
|
|
42
99
|
}
|
|
@@ -1,14 +1,23 @@
|
|
|
1
1
|
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
2
2
|
import type { DirectionalAppTaggingSecret, PreTag } from '@aztec/stdlib/logs';
|
|
3
3
|
import { TxHash } from '@aztec/stdlib/tx';
|
|
4
|
+
import type { StagedStore } from '../../job_coordinator/job_coordinator.js';
|
|
4
5
|
/**
|
|
5
6
|
* Data provider of tagging data used when syncing the sender tagging indexes. The recipient counterpart of this class
|
|
6
|
-
* is called RecipientTaggingStore. We have the
|
|
7
|
+
* is called RecipientTaggingStore. We have the data stores separate for sender and recipient because
|
|
7
8
|
* the algorithms are completely disjoint and there is not data reuse between the two.
|
|
8
9
|
*/
|
|
9
|
-
export declare class SenderTaggingStore {
|
|
10
|
+
export declare class SenderTaggingStore implements StagedStore {
|
|
10
11
|
#private;
|
|
12
|
+
readonly storeName = "sender_tagging";
|
|
11
13
|
constructor(store: AztecAsyncKVStore);
|
|
14
|
+
/**
|
|
15
|
+
* Writes all job-specific in-memory data to persistent storage.
|
|
16
|
+
*
|
|
17
|
+
* @remark This method must run in a DB transaction context. It's designed to be called from JobCoordinator#commitJob.
|
|
18
|
+
*/
|
|
19
|
+
commit(jobId: string): Promise<void>;
|
|
20
|
+
discardStaged(jobId: string): Promise<void>;
|
|
12
21
|
/**
|
|
13
22
|
* Stores pending indexes.
|
|
14
23
|
* @remarks Ignores the index if the same preTag + txHash combination already exists in the db with the same index.
|
|
@@ -17,6 +26,7 @@ export declare class SenderTaggingStore {
|
|
|
17
26
|
* @param preTags - The pre-tags containing the directional app tagging secrets and the indexes that are to be
|
|
18
27
|
* stored in the db.
|
|
19
28
|
* @param txHash - The tx in which the pretags were used in private logs.
|
|
29
|
+
* @param jobId - job context for staged writes to this store. See `JobCoordinator` for more details.
|
|
20
30
|
* @throws If any two pre-tags contain the same directional app tagging secret. This is enforced because we care
|
|
21
31
|
* only about the highest index for a given secret that was used in the tx. Hence this check is a good way to catch
|
|
22
32
|
* bugs.
|
|
@@ -30,7 +40,7 @@ export declare class SenderTaggingStore {
|
|
|
30
40
|
* This is enforced because this should never happen if the syncing is done correctly as we look for logs from higher
|
|
31
41
|
* indexes than finalized ones.
|
|
32
42
|
*/
|
|
33
|
-
storePendingIndexes(preTags: PreTag[], txHash: TxHash): Promise<void>;
|
|
43
|
+
storePendingIndexes(preTags: PreTag[], txHash: TxHash, jobId: string): Promise<void>;
|
|
34
44
|
/**
|
|
35
45
|
* Returns the transaction hashes of all pending transactions that contain indexes within a specified range
|
|
36
46
|
* for a given directional app tagging secret.
|
|
@@ -40,28 +50,28 @@ export declare class SenderTaggingStore {
|
|
|
40
50
|
* @returns An array of unique transaction hashes for pending transactions that contain indexes in the range
|
|
41
51
|
* [startIndex, endIndex). Returns an empty array if no pending indexes exist in the range.
|
|
42
52
|
*/
|
|
43
|
-
getTxHashesOfPendingIndexes(secret: DirectionalAppTaggingSecret, startIndex: number, endIndex: number): Promise<TxHash[]>;
|
|
53
|
+
getTxHashesOfPendingIndexes(secret: DirectionalAppTaggingSecret, startIndex: number, endIndex: number, jobId: string): Promise<TxHash[]>;
|
|
44
54
|
/**
|
|
45
55
|
* Returns the last (highest) finalized index for a given secret.
|
|
46
56
|
* @param secret - The secret to get the last finalized index for.
|
|
47
57
|
* @returns The last (highest) finalized index for the given secret.
|
|
48
58
|
*/
|
|
49
|
-
getLastFinalizedIndex(secret: DirectionalAppTaggingSecret): Promise<number | undefined>;
|
|
59
|
+
getLastFinalizedIndex(secret: DirectionalAppTaggingSecret, jobId: string): Promise<number | undefined>;
|
|
50
60
|
/**
|
|
51
61
|
* Returns the last used index for a given directional app tagging secret, considering both finalized and pending
|
|
52
62
|
* indexes.
|
|
53
63
|
* @param secret - The directional app tagging secret to query the last used index for.
|
|
54
64
|
* @returns The last used index.
|
|
55
65
|
*/
|
|
56
|
-
getLastUsedIndex(secret: DirectionalAppTaggingSecret): Promise<number | undefined>;
|
|
66
|
+
getLastUsedIndex(secret: DirectionalAppTaggingSecret, jobId: string): Promise<number | undefined>;
|
|
57
67
|
/**
|
|
58
68
|
* Drops all pending indexes corresponding to the given transaction hashes.
|
|
59
69
|
*/
|
|
60
|
-
dropPendingIndexes(txHashes: TxHash[]): Promise<void>;
|
|
70
|
+
dropPendingIndexes(txHashes: TxHash[], jobId: string): Promise<void>;
|
|
61
71
|
/**
|
|
62
72
|
* Updates pending indexes corresponding to the given transaction hashes to be finalized and prunes any lower pending
|
|
63
73
|
* indexes.
|
|
64
74
|
*/
|
|
65
|
-
finalizePendingIndexes(txHashes: TxHash[]): Promise<void>;
|
|
75
|
+
finalizePendingIndexes(txHashes: TxHash[], jobId: string): Promise<void>;
|
|
66
76
|
}
|
|
67
|
-
//# sourceMappingURL=data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QUMvQixNQUFNLEVBQUUsMkJBQTJCLEVBQ25DLFVBQVUsRUFBRSxNQUFNLEVBQ2xCLFFBQVEsRUFBRSxNQUFNLEVBQ2hCLEtBQUssRUFBRSxNQUFNLEdBQ1osT0FBTyxDQUFDLE1BQU0sRUFBRSxDQUFDLENBTW5CO0lBRUQ7Ozs7T0FJRztJQUNILHFCQUFxQixDQUFDLE1BQU0sRUFBRSwyQkFBMkIsRUFBRSxLQUFLLEVBQUUsTUFBTSxHQUFHLE9BQU8sQ0FBQyxNQUFNLEdBQUcsU0FBUyxDQUFDLENBRXJHO0lBRUQ7Ozs7O09BS0c7SUFDRyxnQkFBZ0IsQ0FBQyxNQUFNLEVBQUUsMkJBQTJCLEVBQUUsS0FBSyxFQUFFLE1BQU0sR0FBRyxPQUFPLENBQUMsTUFBTSxHQUFHLFNBQVMsQ0FBQyxDQVl0RztJQUVEOztPQUVHO0lBQ0csa0JBQWtCLENBQUMsUUFBUSxFQUFFLE1BQU0sRUFBRSxFQUFFLEtBQUssRUFBRSxNQUFNLGlCQXFCekQ7SUFFRDs7O09BR0c7SUFDRyxzQkFBc0IsQ0FBQyxRQUFRLEVBQUUsTUFBTSxFQUFFLEVBQUUsS0FBSyxFQUFFLE1BQU0saUJBcUQ3RDtDQUNGIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sender_tagging_store.d.ts","sourceRoot":"","sources":["../../../src/storage/tagging_store/sender_tagging_store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAiB,MAAM,iBAAiB,CAAC;AACxE,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC9E,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"sender_tagging_store.d.ts","sourceRoot":"","sources":["../../../src/storage/tagging_store/sender_tagging_store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBA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