@aztec/pxe 0.0.1-commit.d1f2d6c → 0.0.1-commit.d20b825a7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/bin/check_oracle_version.js +5 -5
- package/dest/block_synchronizer/block_synchronizer.d.ts +10 -4
- package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
- package/dest/block_synchronizer/block_synchronizer.js +30 -6
- package/dest/config/index.d.ts +2 -2
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +8 -15
- package/dest/config/package_info.js +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +63 -31
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +206 -77
- package/dest/contract_function_simulator/ephemeral_array_service.d.ts +28 -0
- package/dest/contract_function_simulator/ephemeral_array_service.d.ts.map +1 -0
- package/dest/contract_function_simulator/ephemeral_array_service.js +78 -0
- package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +7 -7
- package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -1
- package/dest/contract_function_simulator/execution_tagging_index_cache.js +19 -11
- package/dest/contract_function_simulator/index.d.ts +2 -1
- package/dest/contract_function_simulator/index.d.ts.map +1 -1
- package/dest/contract_function_simulator/index.js +1 -0
- package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +5 -7
- 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 +9 -11
- package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts +1 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_request.js +1 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +2 -2
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +2 -4
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +5 -8
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/note_validation_request.js +7 -12
- package/dest/contract_function_simulator/oracle/interfaces.d.ts +62 -46
- package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts +9 -0
- package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.js +47 -0
- package/dest/contract_function_simulator/oracle/oracle.d.ts +75 -44
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +310 -113
- package/dest/contract_function_simulator/oracle/private_execution.d.ts +3 -22
- package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution.js +5 -49
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +60 -84
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +125 -98
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +128 -70
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +330 -143
- package/dest/contract_function_simulator/pick_notes.d.ts +1 -1
- package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -1
- package/dest/contract_function_simulator/pick_notes.js +20 -3
- package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +1 -1
- package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +1 -1
- package/dest/contract_function_simulator/proxied_contract_data_source.js +3 -0
- package/dest/contract_logging.d.ts +27 -0
- package/dest/contract_logging.d.ts.map +1 -0
- package/dest/contract_logging.js +38 -0
- package/dest/contract_sync/contract_sync_service.d.ts +44 -0
- package/dest/contract_sync/contract_sync_service.d.ts.map +1 -0
- package/dest/contract_sync/contract_sync_service.js +116 -0
- package/dest/contract_sync/helpers.d.ts +28 -0
- package/dest/contract_sync/helpers.d.ts.map +1 -0
- package/dest/contract_sync/helpers.js +60 -0
- package/dest/debug/pxe_debug_utils.d.ts +24 -10
- package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
- package/dest/debug/pxe_debug_utils.js +28 -18
- package/dest/entrypoints/client/bundle/index.d.ts +3 -1
- package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/index.js +2 -0
- package/dest/entrypoints/client/bundle/utils.d.ts +2 -2
- package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/utils.js +23 -9
- package/dest/entrypoints/client/lazy/index.d.ts +3 -1
- package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/index.js +2 -0
- package/dest/entrypoints/client/lazy/utils.d.ts +3 -3
- package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/utils.js +24 -10
- package/dest/entrypoints/pxe_creation_options.d.ts +5 -2
- package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
- package/dest/entrypoints/pxe_creation_options.js +3 -1
- package/dest/entrypoints/server/index.d.ts +4 -2
- package/dest/entrypoints/server/index.d.ts.map +1 -1
- package/dest/entrypoints/server/index.js +3 -1
- package/dest/entrypoints/server/utils.d.ts +2 -2
- package/dest/entrypoints/server/utils.d.ts.map +1 -1
- package/dest/entrypoints/server/utils.js +30 -11
- package/dest/events/event_service.d.ts +6 -6
- package/dest/events/event_service.d.ts.map +1 -1
- package/dest/events/event_service.js +31 -11
- package/dest/events/private_event_filter_validator.d.ts +3 -2
- package/dest/events/private_event_filter_validator.d.ts.map +1 -1
- package/dest/events/private_event_filter_validator.js +15 -0
- package/dest/job_coordinator/job_coordinator.d.ts +3 -2
- package/dest/job_coordinator/job_coordinator.d.ts.map +1 -1
- package/dest/job_coordinator/job_coordinator.js +3 -2
- package/dest/logs/log_service.d.ts +10 -9
- package/dest/logs/log_service.d.ts.map +1 -1
- package/dest/logs/log_service.js +41 -62
- package/dest/messages/message_context_service.d.ts +17 -0
- package/dest/messages/message_context_service.d.ts.map +1 -0
- package/dest/messages/message_context_service.js +36 -0
- package/dest/notes/note_service.d.ts +7 -8
- package/dest/notes/note_service.d.ts.map +1 -1
- package/dest/notes/note_service.js +23 -15
- package/dest/notes_filter.d.ts +24 -0
- package/dest/notes_filter.d.ts.map +1 -0
- package/dest/notes_filter.js +4 -0
- package/dest/oracle_version.d.ts +4 -3
- package/dest/oracle_version.d.ts.map +1 -1
- package/dest/oracle_version.js +20 -10
- package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts +4 -0
- package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts.map +1 -0
- package/dest/private_kernel/hints/{compute_tx_include_by_timestamp.js → compute_tx_expiration_timestamp.js} +12 -12
- package/dest/private_kernel/hints/index.d.ts +1 -1
- package/dest/private_kernel/hints/index.js +1 -1
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +4 -3
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -1
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.js +129 -68
- package/dest/private_kernel/hints/test_utils.d.ts +122 -0
- package/dest/private_kernel/hints/test_utils.d.ts.map +1 -0
- package/dest/private_kernel/hints/test_utils.js +203 -0
- package/dest/private_kernel/private_kernel_execution_prover.d.ts +3 -2
- package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_execution_prover.js +20 -15
- package/dest/private_kernel/private_kernel_oracle.d.ts +10 -6
- package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_oracle.js +19 -18
- package/dest/pxe.d.ts +85 -24
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +169 -87
- package/dest/storage/address_store/address_store.d.ts +1 -1
- package/dest/storage/address_store/address_store.d.ts.map +1 -1
- package/dest/storage/address_store/address_store.js +12 -11
- package/dest/storage/anchor_block_store/anchor_block_store.d.ts +9 -1
- package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -1
- package/dest/storage/anchor_block_store/anchor_block_store.js +9 -2
- package/dest/storage/capsule_store/capsule_service.d.ts +21 -0
- package/dest/storage/capsule_store/capsule_service.d.ts.map +1 -0
- package/dest/storage/capsule_store/capsule_service.js +50 -0
- package/dest/storage/capsule_store/capsule_store.d.ts +9 -9
- package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
- package/dest/storage/capsule_store/capsule_store.js +42 -36
- package/dest/storage/capsule_store/index.d.ts +2 -1
- package/dest/storage/capsule_store/index.d.ts.map +1 -1
- package/dest/storage/capsule_store/index.js +1 -0
- package/dest/storage/contract_store/contract_store.d.ts +42 -16
- package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
- package/dest/storage/contract_store/contract_store.js +160 -85
- package/dest/storage/metadata.d.ts +1 -1
- package/dest/storage/metadata.js +1 -1
- package/dest/storage/note_store/note_store.d.ts +14 -4
- package/dest/storage/note_store/note_store.d.ts.map +1 -1
- package/dest/storage/note_store/note_store.js +149 -109
- package/dest/storage/private_event_store/private_event_store.d.ts +1 -1
- package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
- package/dest/storage/private_event_store/private_event_store.js +87 -61
- package/dest/storage/private_event_store/stored_private_event.d.ts +4 -4
- package/dest/storage/private_event_store/stored_private_event.d.ts.map +1 -1
- package/dest/storage/private_event_store/stored_private_event.js +2 -2
- package/dest/storage/tagging_store/recipient_tagging_store.d.ts +6 -6
- package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/recipient_tagging_store.js +31 -19
- package/dest/storage/tagging_store/sender_address_book_store.d.ts +1 -1
- package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/sender_address_book_store.js +20 -14
- package/dest/storage/tagging_store/sender_tagging_store.d.ts +29 -28
- package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/sender_tagging_store.js +233 -137
- package/dest/tagging/get_all_logs_by_tags.d.ts +4 -4
- package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -1
- package/dest/tagging/get_all_logs_by_tags.js +17 -3
- package/dest/tagging/index.d.ts +3 -3
- package/dest/tagging/index.d.ts.map +1 -1
- package/dest/tagging/index.js +1 -1
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +5 -6
- 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 +8 -22
- package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +2 -2
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +7 -8
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +12 -11
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +5 -9
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +13 -7
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +4 -3
- 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 +20 -10
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +6 -8
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +36 -24
- package/package.json +25 -16
- package/src/bin/check_oracle_version.ts +5 -4
- package/src/block_synchronizer/block_synchronizer.ts +45 -21
- package/src/config/index.ts +3 -9
- package/src/config/package_info.ts +1 -1
- package/src/contract_function_simulator/contract_function_simulator.ts +366 -136
- package/src/contract_function_simulator/ephemeral_array_service.ts +110 -0
- package/src/contract_function_simulator/execution_tagging_index_cache.ts +19 -14
- package/src/contract_function_simulator/index.ts +1 -0
- package/src/contract_function_simulator/noir-structs/event_validation_request.ts +10 -10
- package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +1 -1
- package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +2 -5
- package/src/contract_function_simulator/noir-structs/note_validation_request.ts +5 -11
- package/src/contract_function_simulator/oracle/interfaces.ts +90 -62
- package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +104 -0
- package/src/contract_function_simulator/oracle/oracle.ts +391 -150
- package/src/contract_function_simulator/oracle/private_execution.ts +5 -83
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +160 -193
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +552 -179
- package/src/contract_function_simulator/pick_notes.ts +22 -3
- package/src/contract_function_simulator/proxied_contract_data_source.ts +8 -1
- package/src/contract_logging.ts +52 -0
- package/src/contract_sync/contract_sync_service.ts +176 -0
- package/src/contract_sync/helpers.ts +98 -0
- package/src/debug/pxe_debug_utils.ts +63 -19
- package/src/entrypoints/client/bundle/index.ts +2 -0
- package/src/entrypoints/client/bundle/utils.ts +18 -18
- package/src/entrypoints/client/lazy/index.ts +2 -0
- package/src/entrypoints/client/lazy/utils.ts +19 -18
- package/src/entrypoints/pxe_creation_options.ts +9 -1
- package/src/entrypoints/server/index.ts +3 -1
- package/src/entrypoints/server/utils.ts +24 -29
- package/src/events/event_service.ts +35 -12
- package/src/events/private_event_filter_validator.ts +21 -1
- package/src/job_coordinator/job_coordinator.ts +4 -3
- package/src/logs/log_service.ts +77 -106
- package/src/messages/message_context_service.ts +44 -0
- package/src/notes/note_service.ts +25 -17
- package/src/notes_filter.ts +24 -0
- package/src/oracle_version.ts +20 -10
- package/src/private_kernel/hints/{compute_tx_include_by_timestamp.ts → compute_tx_expiration_timestamp.ts} +13 -13
- package/src/private_kernel/hints/index.ts +1 -1
- package/src/private_kernel/hints/private_kernel_reset_private_inputs_builder.ts +164 -117
- package/src/private_kernel/hints/test_utils.ts +325 -0
- package/src/private_kernel/private_kernel_execution_prover.ts +24 -19
- package/src/private_kernel/private_kernel_oracle.ts +21 -21
- package/src/pxe.ts +318 -144
- package/src/storage/address_store/address_store.ts +15 -15
- package/src/storage/anchor_block_store/anchor_block_store.ts +9 -1
- package/src/storage/capsule_store/capsule_service.ts +90 -0
- package/src/storage/capsule_store/capsule_store.ts +52 -34
- package/src/storage/capsule_store/index.ts +1 -0
- package/src/storage/contract_store/contract_store.ts +193 -101
- package/src/storage/metadata.ts +1 -1
- package/src/storage/note_store/note_store.ts +168 -134
- package/src/storage/private_event_store/private_event_store.ts +106 -81
- package/src/storage/private_event_store/stored_private_event.ts +3 -3
- package/src/storage/tagging_store/recipient_tagging_store.ts +38 -24
- package/src/storage/tagging_store/sender_address_book_store.ts +20 -14
- package/src/storage/tagging_store/sender_tagging_store.ts +287 -156
- package/src/tagging/get_all_logs_by_tags.ts +31 -7
- package/src/tagging/index.ts +2 -2
- package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +14 -27
- package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +2 -2
- package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +12 -17
- package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +25 -12
- package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +26 -11
- package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +30 -29
- package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +0 -4
- package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +0 -1
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
2
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
|
-
import { toArray } from '@aztec/foundation/iterable';
|
|
4
3
|
import { createLogger } from '@aztec/foundation/log';
|
|
5
4
|
import { Semaphore } from '@aztec/foundation/queue';
|
|
6
5
|
import type { AztecAsyncKVStore, AztecAsyncMap, AztecAsyncMultiMap } from '@aztec/kv-store';
|
|
@@ -81,43 +80,45 @@ export class PrivateEventStore implements StagedStore {
|
|
|
81
80
|
metadata: PrivateEventMetadata,
|
|
82
81
|
jobId: string,
|
|
83
82
|
) {
|
|
84
|
-
return this.#withJobLock(jobId,
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
this.logger.verbose('storing private event log (job stage)', {
|
|
89
|
-
eventId,
|
|
90
|
-
contractAddress,
|
|
91
|
-
scope,
|
|
92
|
-
msgContent,
|
|
93
|
-
l2BlockNumber,
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
const existing = await this.#readEvent(eventId, jobId);
|
|
83
|
+
return this.#withJobLock(jobId, () =>
|
|
84
|
+
this.#store.transactionAsync(async () => {
|
|
85
|
+
const { contractAddress, scope, txHash, l2BlockNumber, l2BlockHash, txIndexInBlock, eventIndexInTx } = metadata;
|
|
86
|
+
const eventId = siloedEventCommitment.toString();
|
|
97
87
|
|
|
98
|
-
|
|
99
|
-
// If we already stored this event, we still want to make sure to track it for the given scope
|
|
100
|
-
existing.addScope(scope.toString());
|
|
101
|
-
this.#writeEvent(eventId, existing, jobId);
|
|
102
|
-
} else {
|
|
103
|
-
this.#writeEvent(
|
|
88
|
+
this.logger.verbose('storing private event log (job stage)', {
|
|
104
89
|
eventId,
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
)
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
90
|
+
contractAddress,
|
|
91
|
+
scope,
|
|
92
|
+
msgContent,
|
|
93
|
+
l2BlockNumber,
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
const existing = await this.#readEvent(eventId, jobId);
|
|
97
|
+
|
|
98
|
+
if (existing) {
|
|
99
|
+
// If we already stored this event, we still want to make sure to track it for the given scope
|
|
100
|
+
existing.addScope(scope.toString());
|
|
101
|
+
this.#writeEvent(eventId, existing, jobId);
|
|
102
|
+
} else {
|
|
103
|
+
this.#writeEvent(
|
|
104
|
+
eventId,
|
|
105
|
+
new StoredPrivateEvent(
|
|
106
|
+
randomness,
|
|
107
|
+
msgContent,
|
|
108
|
+
l2BlockNumber,
|
|
109
|
+
l2BlockHash,
|
|
110
|
+
txHash,
|
|
111
|
+
txIndexInBlock,
|
|
112
|
+
eventIndexInTx,
|
|
113
|
+
contractAddress,
|
|
114
|
+
eventSelector,
|
|
115
|
+
new Set([scope.toString()]),
|
|
116
|
+
),
|
|
117
|
+
jobId,
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
}),
|
|
121
|
+
);
|
|
121
122
|
}
|
|
122
123
|
|
|
123
124
|
/**
|
|
@@ -136,6 +137,20 @@ export class PrivateEventStore implements StagedStore {
|
|
|
136
137
|
filter: PrivateEventStoreFilter,
|
|
137
138
|
): Promise<PackedPrivateEvent[]> {
|
|
138
139
|
return this.#store.transactionAsync(async () => {
|
|
140
|
+
const key = this.#keyFor(filter.contractAddress, eventSelector);
|
|
141
|
+
const targetScopes = new Set(filter.scopes.map(s => s.toString()));
|
|
142
|
+
|
|
143
|
+
// Map from eventId to the promise that reads the event buffer.
|
|
144
|
+
// We start reads during iteration to keep DB requests pending and avoid IndexedDB auto-commit.
|
|
145
|
+
const eventReadPromises: Map<string, Promise<Buffer | undefined>> = new Map();
|
|
146
|
+
|
|
147
|
+
for await (const eventId of this.#eventsByContractAndEventSelector.getValuesAsync(key)) {
|
|
148
|
+
eventReadPromises.set(eventId, this.#events.getAsync(eventId));
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const eventIds = [...eventReadPromises.keys()];
|
|
152
|
+
const eventBuffers = await Promise.all(eventReadPromises.values());
|
|
153
|
+
|
|
139
154
|
const events: Array<{
|
|
140
155
|
l2BlockNumber: number;
|
|
141
156
|
txIndexInBlock: number;
|
|
@@ -143,13 +158,9 @@ export class PrivateEventStore implements StagedStore {
|
|
|
143
158
|
event: PackedPrivateEvent;
|
|
144
159
|
}> = [];
|
|
145
160
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
const eventIds: string[] = await toArray(this.#eventsByContractAndEventSelector.getValuesAsync(key));
|
|
150
|
-
|
|
151
|
-
for (const eventId of eventIds) {
|
|
152
|
-
const eventBuffer = await this.#events.getAsync(eventId);
|
|
161
|
+
for (let i = 0; i < eventIds.length; i++) {
|
|
162
|
+
const eventId = eventIds[i];
|
|
163
|
+
const eventBuffer = eventBuffers[i];
|
|
153
164
|
|
|
154
165
|
// Defensive, if it happens, there's a problem with how we're handling #eventsByContractAndEventSelector
|
|
155
166
|
if (!eventBuffer) {
|
|
@@ -223,29 +234,43 @@ export class PrivateEventStore implements StagedStore {
|
|
|
223
234
|
* IMPORTANT: This method must be called within a transaction to ensure atomicity.
|
|
224
235
|
*/
|
|
225
236
|
public async rollback(blockNumber: number, synchedBlockNumber: number): Promise<void> {
|
|
226
|
-
|
|
237
|
+
if (this.#eventsForJob.size > 0) {
|
|
238
|
+
throw new Error('PXE private event store rollback is not allowed while jobs are running');
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// First pass: collect all event IDs for all blocks, starting reads during iteration to keep tx alive.
|
|
242
|
+
const eventsByBlock: Map<number, { eventId: string; eventReadPromise: Promise<Buffer | undefined> }[]> = new Map();
|
|
227
243
|
|
|
228
244
|
for (let block = blockNumber + 1; block <= synchedBlockNumber; block++) {
|
|
229
|
-
const
|
|
245
|
+
const blockEvents: { eventId: string; eventReadPromise: Promise<Buffer | undefined> }[] = [];
|
|
246
|
+
for await (const eventId of this.#eventsByBlockNumber.getValuesAsync(block)) {
|
|
247
|
+
// Start read immediately during iteration to keep IndexedDB transaction alive
|
|
248
|
+
blockEvents.push({ eventId, eventReadPromise: this.#events.getAsync(eventId) });
|
|
249
|
+
}
|
|
250
|
+
if (blockEvents.length > 0) {
|
|
251
|
+
eventsByBlock.set(block, blockEvents);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
230
254
|
|
|
231
|
-
|
|
232
|
-
|
|
255
|
+
// Second pass: await reads and perform deletes
|
|
256
|
+
let removedCount = 0;
|
|
257
|
+
for (const [block, events] of eventsByBlock) {
|
|
258
|
+
await this.#eventsByBlockNumber.delete(block);
|
|
233
259
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
260
|
+
for (const { eventId, eventReadPromise } of events) {
|
|
261
|
+
const buffer = await eventReadPromise;
|
|
262
|
+
if (!buffer) {
|
|
263
|
+
throw new Error(`Event not found for eventId ${eventId}`);
|
|
264
|
+
}
|
|
239
265
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
266
|
+
const entry = StoredPrivateEvent.fromBuffer(buffer);
|
|
267
|
+
await this.#events.delete(eventId);
|
|
268
|
+
await this.#eventsByContractAndEventSelector.deleteValue(
|
|
269
|
+
this.#keyFor(entry.contractAddress, entry.eventSelector),
|
|
270
|
+
eventId,
|
|
271
|
+
);
|
|
246
272
|
|
|
247
|
-
|
|
248
|
-
}
|
|
273
|
+
removedCount++;
|
|
249
274
|
}
|
|
250
275
|
}
|
|
251
276
|
|
|
@@ -262,28 +287,30 @@ export class PrivateEventStore implements StagedStore {
|
|
|
262
287
|
*
|
|
263
288
|
* @param jobId - The jobId identifying which staged data to commit
|
|
264
289
|
*/
|
|
265
|
-
commit(jobId: string): Promise<void> {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
290
|
+
async commit(jobId: string): Promise<void> {
|
|
291
|
+
// Note: Don't use #withJobLock here - commit runs within JobCoordinator's transactionAsync,
|
|
292
|
+
// and awaiting the lock would create a microtask boundary with no pending DB request,
|
|
293
|
+
// causing IndexedDB to auto-commit the transaction.
|
|
294
|
+
for (const [eventId, entry] of this.#getEventsForJob(jobId).entries()) {
|
|
295
|
+
const lookupKey = this.#keyFor(entry.contractAddress, entry.eventSelector);
|
|
296
|
+
this.logger.verbose('storing private event log', { eventId, lookupKey });
|
|
297
|
+
|
|
298
|
+
await Promise.all([
|
|
299
|
+
this.#events.set(eventId, entry.toBuffer()),
|
|
300
|
+
this.#eventsByContractAndEventSelector.set(lookupKey, eventId),
|
|
301
|
+
this.#eventsByBlockNumber.set(entry.l2BlockNumber, eventId),
|
|
302
|
+
]);
|
|
303
|
+
}
|
|
277
304
|
|
|
278
|
-
|
|
279
|
-
});
|
|
305
|
+
this.#clearJobData(jobId);
|
|
280
306
|
}
|
|
281
307
|
|
|
282
308
|
/**
|
|
283
309
|
* Discards in memory job data without persisting it.
|
|
284
310
|
*/
|
|
285
311
|
discardStaged(jobId: string): Promise<void> {
|
|
286
|
-
|
|
312
|
+
this.#clearJobData(jobId);
|
|
313
|
+
return Promise.resolve();
|
|
287
314
|
}
|
|
288
315
|
|
|
289
316
|
/**
|
|
@@ -292,13 +319,11 @@ export class PrivateEventStore implements StagedStore {
|
|
|
292
319
|
* Returns undefined if the event does not exist in the store overall.
|
|
293
320
|
*/
|
|
294
321
|
async #readEvent(eventId: string, jobId: string): Promise<StoredPrivateEvent | undefined> {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
return eventForJob;
|
|
298
|
-
}
|
|
299
|
-
|
|
322
|
+
// Always issue DB read to keep IndexedDB transaction alive (they auto-commit when a new micro-task starts and there
|
|
323
|
+
// are no pending read requests). The staged value still takes precedence if it exists.
|
|
300
324
|
const buffer = await this.#events.getAsync(eventId);
|
|
301
|
-
|
|
325
|
+
const eventForJob = this.#getEventsForJob(jobId).get(eventId);
|
|
326
|
+
return eventForJob ?? (buffer ? StoredPrivateEvent.fromBuffer(buffer) : undefined);
|
|
302
327
|
}
|
|
303
328
|
|
|
304
329
|
/**
|
|
@@ -2,7 +2,7 @@ import { Fr } from '@aztec/foundation/curves/bn254';
|
|
|
2
2
|
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
3
3
|
import { EventSelector } from '@aztec/stdlib/abi';
|
|
4
4
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
|
-
import {
|
|
5
|
+
import { BlockHash } from '@aztec/stdlib/block';
|
|
6
6
|
import { TxHash } from '@aztec/stdlib/tx';
|
|
7
7
|
|
|
8
8
|
/** Serializable private event entry with scope tracking. */
|
|
@@ -11,7 +11,7 @@ export class StoredPrivateEvent {
|
|
|
11
11
|
readonly randomness: Fr,
|
|
12
12
|
readonly msgContent: Fr[],
|
|
13
13
|
readonly l2BlockNumber: number,
|
|
14
|
-
readonly l2BlockHash:
|
|
14
|
+
readonly l2BlockHash: BlockHash,
|
|
15
15
|
readonly txHash: TxHash,
|
|
16
16
|
readonly txIndexInBlock: number,
|
|
17
17
|
readonly eventIndexInTx: number,
|
|
@@ -49,7 +49,7 @@ export class StoredPrivateEvent {
|
|
|
49
49
|
const msgContentLength = reader.readNumber();
|
|
50
50
|
const msgContent = reader.readArray(msgContentLength, Fr);
|
|
51
51
|
const l2BlockNumber = reader.readNumber();
|
|
52
|
-
const l2BlockHash =
|
|
52
|
+
const l2BlockHash = BlockHash.fromBuffer(reader);
|
|
53
53
|
const txHash = TxHash.fromBuffer(reader);
|
|
54
54
|
const txIndexInBlock = reader.readNumber();
|
|
55
55
|
const eventIndexInTx = reader.readNumber();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
|
|
2
|
-
import type {
|
|
2
|
+
import type { ExtendedDirectionalAppTaggingSecret } from '@aztec/stdlib/logs';
|
|
3
3
|
|
|
4
4
|
import type { StagedStore } from '../../job_coordinator/job_coordinator.js';
|
|
5
5
|
|
|
@@ -45,7 +45,11 @@ export class RecipientTaggingStore implements StagedStore {
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
async #readHighestAgedIndex(jobId: string, secret: string): Promise<number | undefined> {
|
|
48
|
-
|
|
48
|
+
// Always issue DB read to keep IndexedDB transaction alive (they auto-commit when a new micro-task starts and there
|
|
49
|
+
// are no pending read requests). The staged value still takes precedence if it exists.
|
|
50
|
+
const dbValue = await this.#highestAgedIndex.getAsync(secret);
|
|
51
|
+
const staged = this.#getHighestAgedIndexForJob(jobId).get(secret);
|
|
52
|
+
return staged ?? dbValue;
|
|
49
53
|
}
|
|
50
54
|
|
|
51
55
|
#writeHighestAgedIndex(jobId: string, secret: string, index: number) {
|
|
@@ -62,9 +66,11 @@ export class RecipientTaggingStore implements StagedStore {
|
|
|
62
66
|
}
|
|
63
67
|
|
|
64
68
|
async #readHighestFinalizedIndex(jobId: string, secret: string): Promise<number | undefined> {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
);
|
|
69
|
+
// Always issue DB read to keep IndexedDB transaction alive (they auto-commit when a new micro-task starts and there
|
|
70
|
+
// are no pending read requests). The staged value still takes precedence if it exists.
|
|
71
|
+
const dbValue = await this.#highestFinalizedIndex.getAsync(secret);
|
|
72
|
+
const staged = this.#getHighestFinalizedIndexForJob(jobId).get(secret);
|
|
73
|
+
return staged ?? dbValue;
|
|
68
74
|
}
|
|
69
75
|
|
|
70
76
|
#writeHighestFinalizedIndex(jobId: string, secret: string, index: number) {
|
|
@@ -100,30 +106,38 @@ export class RecipientTaggingStore implements StagedStore {
|
|
|
100
106
|
return Promise.resolve();
|
|
101
107
|
}
|
|
102
108
|
|
|
103
|
-
getHighestAgedIndex(secret:
|
|
104
|
-
return this.#readHighestAgedIndex(jobId, secret.toString());
|
|
109
|
+
getHighestAgedIndex(secret: ExtendedDirectionalAppTaggingSecret, jobId: string): Promise<number | undefined> {
|
|
110
|
+
return this.#store.transactionAsync(() => this.#readHighestAgedIndex(jobId, secret.toString()));
|
|
105
111
|
}
|
|
106
112
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
113
|
+
updateHighestAgedIndex(secret: ExtendedDirectionalAppTaggingSecret, index: number, jobId: string): Promise<void> {
|
|
114
|
+
return this.#store.transactionAsync(async () => {
|
|
115
|
+
const currentIndex = await this.#readHighestAgedIndex(jobId, secret.toString());
|
|
116
|
+
if (currentIndex !== undefined && index <= currentIndex) {
|
|
117
|
+
// Log sync should never set a lower highest aged index.
|
|
118
|
+
throw new Error(`New highest aged index (${index}) must be higher than the current one (${currentIndex})`);
|
|
119
|
+
}
|
|
120
|
+
this.#writeHighestAgedIndex(jobId, secret.toString(), index);
|
|
121
|
+
});
|
|
114
122
|
}
|
|
115
123
|
|
|
116
|
-
getHighestFinalizedIndex(secret:
|
|
117
|
-
return this.#readHighestFinalizedIndex(jobId, secret.toString());
|
|
124
|
+
getHighestFinalizedIndex(secret: ExtendedDirectionalAppTaggingSecret, jobId: string): Promise<number | undefined> {
|
|
125
|
+
return this.#store.transactionAsync(() => this.#readHighestFinalizedIndex(jobId, secret.toString()));
|
|
118
126
|
}
|
|
119
127
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
+
updateHighestFinalizedIndex(
|
|
129
|
+
secret: ExtendedDirectionalAppTaggingSecret,
|
|
130
|
+
index: number,
|
|
131
|
+
jobId: string,
|
|
132
|
+
): Promise<void> {
|
|
133
|
+
return this.#store.transactionAsync(async () => {
|
|
134
|
+
const currentIndex = await this.#readHighestFinalizedIndex(jobId, secret.toString());
|
|
135
|
+
if (currentIndex !== undefined && index < currentIndex) {
|
|
136
|
+
// Log sync should never set a lower highest finalized index but it can happen that it would try to set the same
|
|
137
|
+
// one because we are loading logs from highest aged index + 1 and not from the highest finalized index.
|
|
138
|
+
throw new Error(`New highest finalized index (${index}) must be higher than the current one (${currentIndex})`);
|
|
139
|
+
}
|
|
140
|
+
this.#writeHighestFinalizedIndex(jobId, secret.toString(), index);
|
|
141
|
+
});
|
|
128
142
|
}
|
|
129
143
|
}
|
|
@@ -16,27 +16,33 @@ export class SenderAddressBookStore {
|
|
|
16
16
|
this.#addressBook = this.#store.openMap('address_book');
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
addSender(address: AztecAddress): Promise<boolean> {
|
|
20
|
+
return this.#store.transactionAsync(async () => {
|
|
21
|
+
if (await this.#addressBook.hasAsync(address.toString())) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
23
24
|
|
|
24
|
-
|
|
25
|
+
await this.#addressBook.set(address.toString(), true);
|
|
25
26
|
|
|
26
|
-
|
|
27
|
+
return true;
|
|
28
|
+
});
|
|
27
29
|
}
|
|
28
30
|
|
|
29
|
-
|
|
30
|
-
return
|
|
31
|
+
getSenders(): Promise<AztecAddress[]> {
|
|
32
|
+
return this.#store.transactionAsync(async () => {
|
|
33
|
+
return (await toArray(this.#addressBook.keysAsync())).map(AztecAddress.fromString);
|
|
34
|
+
});
|
|
31
35
|
}
|
|
32
36
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
+
removeSender(address: AztecAddress): Promise<boolean> {
|
|
38
|
+
return this.#store.transactionAsync(async () => {
|
|
39
|
+
if (!(await this.#addressBook.hasAsync(address.toString()))) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
37
42
|
|
|
38
|
-
|
|
43
|
+
await this.#addressBook.delete(address.toString());
|
|
39
44
|
|
|
40
|
-
|
|
45
|
+
return true;
|
|
46
|
+
});
|
|
41
47
|
}
|
|
42
48
|
}
|