@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,12 +1,12 @@
|
|
|
1
|
-
import { toArray } from '@aztec/foundation/iterable';
|
|
2
1
|
import { Semaphore } from '@aztec/foundation/queue';
|
|
3
2
|
import type { Fr } from '@aztec/foundation/schemas';
|
|
4
3
|
import type { AztecAsyncKVStore, AztecAsyncMap, AztecAsyncMultiMap } from '@aztec/kv-store';
|
|
5
4
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
6
5
|
import type { DataInBlock } from '@aztec/stdlib/block';
|
|
7
|
-
import { NoteDao, NoteStatus
|
|
6
|
+
import { NoteDao, NoteStatus } from '@aztec/stdlib/note';
|
|
8
7
|
|
|
9
8
|
import type { StagedStore } from '../../job_coordinator/job_coordinator.js';
|
|
9
|
+
import type { NotesFilter } from '../../notes_filter.js';
|
|
10
10
|
import { StoredNote } from './stored_note.js';
|
|
11
11
|
|
|
12
12
|
/**
|
|
@@ -68,32 +68,26 @@ export class NoteStore implements StagedStore {
|
|
|
68
68
|
* @param jobId - The job context for staged writes
|
|
69
69
|
*/
|
|
70
70
|
public addNotes(notes: NoteDao[], scope: AztecAddress, jobId: string): Promise<void[]> {
|
|
71
|
-
return this.#withJobLock(jobId, () =>
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
71
|
+
return this.#withJobLock(jobId, () =>
|
|
72
|
+
this.#store.transactionAsync(() =>
|
|
73
|
+
Promise.all(
|
|
74
|
+
notes.map(async note => {
|
|
75
|
+
const noteForJob =
|
|
76
|
+
(await this.#readNote(note.siloedNullifier.toString(), jobId)) ?? new StoredNote(note, new Set());
|
|
77
|
+
noteForJob.addScope(scope.toString());
|
|
78
|
+
this.#writeNote(noteForJob, jobId);
|
|
79
|
+
}),
|
|
80
|
+
),
|
|
81
|
+
),
|
|
82
|
+
);
|
|
81
83
|
}
|
|
82
84
|
|
|
83
85
|
async #readNote(nullifier: string, jobId: string): Promise<StoredNote | undefined> {
|
|
84
|
-
//
|
|
85
|
-
|
|
86
|
-
if (noteForJob) {
|
|
87
|
-
return noteForJob;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// Then check persistent storage
|
|
86
|
+
// Always issue DB read to keep IndexedDB transaction alive (they auto-commit when a new micro-task starts and there
|
|
87
|
+
// are no pending read requests). The staged value still takes precedence if it exists.
|
|
91
88
|
const noteBuffer = await this.#notes.getAsync(nullifier);
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
return undefined;
|
|
89
|
+
const noteForJob = this.#getNotesForJob(jobId).get(nullifier);
|
|
90
|
+
return noteForJob ?? (noteBuffer ? StoredNote.fromBuffer(noteBuffer) : undefined);
|
|
97
91
|
}
|
|
98
92
|
|
|
99
93
|
#writeNote(note: StoredNote, jobId: string) {
|
|
@@ -110,59 +104,99 @@ export class NoteStore implements StagedStore {
|
|
|
110
104
|
* @params jobId - the job context to read from.
|
|
111
105
|
* @returns Filtered and deduplicated notes (a note might be present in multiple scopes - we ensure it is only
|
|
112
106
|
* returned once if this is the case)
|
|
113
|
-
* @throws If filtering by an empty scopes array. Scopes have to be set to undefined or to a non-empty array.
|
|
114
107
|
*/
|
|
115
|
-
|
|
116
|
-
if (filter.scopes
|
|
117
|
-
|
|
108
|
+
getNotes(filter: NotesFilter, jobId: string): Promise<NoteDao[]> {
|
|
109
|
+
if (filter.scopes.length === 0) {
|
|
110
|
+
return Promise.resolve([]);
|
|
118
111
|
}
|
|
119
112
|
|
|
120
|
-
|
|
113
|
+
return this.#store.transactionAsync(async () => {
|
|
114
|
+
const targetStatus = filter.status ?? NoteStatus.ACTIVE;
|
|
115
|
+
|
|
116
|
+
// The code below might read a bit unnatural, the reason is that we need to be careful in how we use `await` inside
|
|
117
|
+
// `transactionAsync`, otherwise browsers might choose to auto-commit the IndexedDB transaction forcing us to
|
|
118
|
+
// explicitly handle that condition. The rule we need to honor is: do not await unless you generate a database
|
|
119
|
+
// read or write or you're done using the DB for the remainder of the transaction. The following sequence is
|
|
120
|
+
// unsafe in IndexedDB:
|
|
121
|
+
//
|
|
122
|
+
// 1. start transactionAsync()
|
|
123
|
+
// 2. await readDb() <-- OK, transaction alive because we issued DB ops
|
|
124
|
+
// 3. run a bunch of computations (no await involved) <-- OK, tx alive because we are in the same microtask
|
|
125
|
+
// 4. await doSthNotInDb() <-- no DB ops issued in this task, browser's free to decide to commit the tx
|
|
126
|
+
// 5. await readDb() <-- BOOM, TransactionInactiveError
|
|
127
|
+
//
|
|
128
|
+
// Note that the real issue is in step number 5: we try to continue using a transaction that the browser might
|
|
129
|
+
// have already committed.
|
|
130
|
+
//
|
|
131
|
+
// We need to read candidate notes which are either indexed by contract address in the DB (in
|
|
132
|
+
// #nullifiersByContractAddress), or lie in memory for the not yet committed `jobId`.
|
|
133
|
+
// So we collect promises based on both sources without awaiting for them.
|
|
134
|
+
const noteReadPromises: Map<string, Promise<StoredNote | undefined>> = new Map();
|
|
135
|
+
|
|
136
|
+
// Awaiting the getValuesAsync iterator is fine because it's reading from the DB
|
|
137
|
+
for await (const nullifier of this.#nullifiersByContractAddress.getValuesAsync(
|
|
138
|
+
filter.contractAddress.toString(),
|
|
139
|
+
)) {
|
|
140
|
+
// Each #readNote will perform a DB read
|
|
141
|
+
noteReadPromises.set(nullifier, this.#readNote(nullifier, jobId));
|
|
142
|
+
}
|
|
121
143
|
|
|
122
|
-
|
|
144
|
+
// Add staged nullifiers from job, no awaits involved, so we are fine
|
|
145
|
+
for (const storedNote of this.#getNotesForJob(jobId).values()) {
|
|
146
|
+
if (storedNote.noteDao.contractAddress.equals(filter.contractAddress)) {
|
|
147
|
+
const nullifier = storedNote.noteDao.siloedNullifier.toString();
|
|
148
|
+
if (!noteReadPromises.has(nullifier)) {
|
|
149
|
+
noteReadPromises.set(nullifier, Promise.resolve(storedNote));
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
123
153
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
const note = await this.#readNote(nullifier, jobId);
|
|
154
|
+
// By now we have pending DB requests from all the #readNote calls. Await them all together.
|
|
155
|
+
const notes = await Promise.all(noteReadPromises.values());
|
|
127
156
|
|
|
128
|
-
//
|
|
129
|
-
|
|
130
|
-
throw new Error('PXE note database is corrupted.');
|
|
131
|
-
}
|
|
157
|
+
// The rest of the function is await-free, and just deals with filtering and sorting our findings.
|
|
158
|
+
const foundNotes: Map<string, NoteDao> = new Map();
|
|
132
159
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
160
|
+
for (const note of notes) {
|
|
161
|
+
// Defensive: hitting this case means we're mishandling contract indices or in-memory job data
|
|
162
|
+
if (!note) {
|
|
163
|
+
throw new Error('PXE note database is corrupted.');
|
|
164
|
+
}
|
|
137
165
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
166
|
+
// Apply filters
|
|
167
|
+
if (targetStatus === NoteStatus.ACTIVE && note.isNullified()) {
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
141
170
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
171
|
+
if (filter.owner && !note.noteDao.owner.equals(filter.owner)) {
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
145
174
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
175
|
+
if (filter.storageSlot && !note.noteDao.storageSlot.equals(filter.storageSlot)) {
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
149
178
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
179
|
+
if (filter.siloedNullifier && !note.noteDao.siloedNullifier.equals(filter.siloedNullifier)) {
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
153
182
|
|
|
154
|
-
|
|
155
|
-
|
|
183
|
+
if (note.scopes.intersection(new Set(filter.scopes.map(s => s.toString()))).size === 0) {
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
156
186
|
|
|
157
|
-
|
|
158
|
-
return [...foundNotes.values()].sort((a, b) => {
|
|
159
|
-
if (a.l2BlockNumber !== b.l2BlockNumber) {
|
|
160
|
-
return a.l2BlockNumber - b.l2BlockNumber;
|
|
161
|
-
}
|
|
162
|
-
if (a.txIndexInBlock !== b.txIndexInBlock) {
|
|
163
|
-
return a.txIndexInBlock - b.txIndexInBlock;
|
|
187
|
+
foundNotes.set(note.noteDao.siloedNullifier.toString(), note.noteDao);
|
|
164
188
|
}
|
|
165
|
-
|
|
189
|
+
|
|
190
|
+
// Sort by block number, then by tx index within block, then by note index within tx
|
|
191
|
+
return [...foundNotes.values()].sort((a, b) => {
|
|
192
|
+
if (a.l2BlockNumber !== b.l2BlockNumber) {
|
|
193
|
+
return a.l2BlockNumber - b.l2BlockNumber;
|
|
194
|
+
}
|
|
195
|
+
if (a.txIndexInBlock !== b.txIndexInBlock) {
|
|
196
|
+
return a.txIndexInBlock - b.txIndexInBlock;
|
|
197
|
+
}
|
|
198
|
+
return a.noteIndexInTx - b.noteIndexInTx;
|
|
199
|
+
});
|
|
166
200
|
});
|
|
167
201
|
}
|
|
168
202
|
|
|
@@ -173,7 +207,7 @@ export class NoteStore implements StagedStore {
|
|
|
173
207
|
* The operation is atomic - if any nullifier is not found, the entire operation fails and no notes are modified.
|
|
174
208
|
*
|
|
175
209
|
* applyNullifiers is idempotent: the same nullifier can be applied multiple times without error.
|
|
176
|
-
* This relaxes constraints on usage of NoteService#
|
|
210
|
+
* This relaxes constraints on usage of NoteService#validateAndStoreNote, which can then be run concurrently in a Promise.all
|
|
177
211
|
* context without risking unnecessarily defensive checks failing.
|
|
178
212
|
*
|
|
179
213
|
* @param nullifiers - Array of nullifiers with their block numbers to process
|
|
@@ -182,12 +216,16 @@ export class NoteStore implements StagedStore {
|
|
|
182
216
|
* @throws Error if any nullifier is not found in this notes store
|
|
183
217
|
*/
|
|
184
218
|
applyNullifiers(nullifiers: DataInBlock<Fr>[], jobId: string): Promise<NoteDao[]> {
|
|
219
|
+
if (nullifiers.length === 0) {
|
|
220
|
+
return Promise.resolve([]);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (nullifiers.some(n => n.l2BlockNumber === 0)) {
|
|
224
|
+
return Promise.reject(new Error('applyNullifiers: nullifiers cannot have been emitted at block 0'));
|
|
225
|
+
}
|
|
226
|
+
|
|
185
227
|
return this.#withJobLock(jobId, () =>
|
|
186
228
|
this.#store.transactionAsync(async () => {
|
|
187
|
-
if (nullifiers.length === 0) {
|
|
188
|
-
return [];
|
|
189
|
-
}
|
|
190
|
-
|
|
191
229
|
const notesToNullify = await Promise.all(
|
|
192
230
|
nullifiers.map(async nullifierInBlock => {
|
|
193
231
|
const nullifier = nullifierInBlock.data.toString();
|
|
@@ -197,14 +235,13 @@ export class NoteStore implements StagedStore {
|
|
|
197
235
|
throw new Error(`Attempted to mark a note as nullified which does not exist in PXE DB`);
|
|
198
236
|
}
|
|
199
237
|
|
|
200
|
-
return { storedNote
|
|
238
|
+
return { storedNote, blockNumber: nullifierInBlock.l2BlockNumber };
|
|
201
239
|
}),
|
|
202
240
|
);
|
|
203
241
|
|
|
204
242
|
const notesNullifiedInThisCall: Map<string, NoteDao> = new Map();
|
|
205
243
|
for (const noteToNullify of notesToNullify) {
|
|
206
|
-
|
|
207
|
-
const note = noteToNullify.storedNote!;
|
|
244
|
+
const note = noteToNullify.storedNote;
|
|
208
245
|
|
|
209
246
|
// Skip already nullified notes
|
|
210
247
|
if (note.isNullified()) {
|
|
@@ -249,18 +286,23 @@ export class NoteStore implements StagedStore {
|
|
|
249
286
|
* @param blockNumber - Notes created after this block number will be deleted
|
|
250
287
|
*/
|
|
251
288
|
async #deleteActiveNotesAfterBlock(blockNumber: number): Promise<void> {
|
|
252
|
-
|
|
253
|
-
|
|
289
|
+
// Collect notes to delete during iteration to keep IndexedDB transaction alive.
|
|
290
|
+
const notesToDelete: { nullifier: string; contractAddress: string }[] = [];
|
|
291
|
+
for await (const noteBuffer of this.#notes.valuesAsync()) {
|
|
254
292
|
const storedNote = StoredNote.fromBuffer(noteBuffer);
|
|
255
293
|
if (storedNote.noteDao.l2BlockNumber > blockNumber) {
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
noteNullifier,
|
|
261
|
-
);
|
|
294
|
+
notesToDelete.push({
|
|
295
|
+
nullifier: storedNote.noteDao.siloedNullifier.toString(),
|
|
296
|
+
contractAddress: storedNote.noteDao.contractAddress.toString(),
|
|
297
|
+
});
|
|
262
298
|
}
|
|
263
299
|
}
|
|
300
|
+
|
|
301
|
+
// Delete all collected notes. Each delete is a DB operation that keeps the transaction alive.
|
|
302
|
+
for (const { nullifier, contractAddress } of notesToDelete) {
|
|
303
|
+
await this.#notes.delete(nullifier);
|
|
304
|
+
await this.#nullifiersByContractAddress.deleteValue(contractAddress, nullifier);
|
|
305
|
+
}
|
|
264
306
|
}
|
|
265
307
|
|
|
266
308
|
/**
|
|
@@ -273,62 +315,69 @@ export class NoteStore implements StagedStore {
|
|
|
273
315
|
* @param anchorBlockNumber - Upper bound for the block range to process
|
|
274
316
|
*/
|
|
275
317
|
async #rewindNullifiedNotesAfterBlock(blockNumber: number, anchorBlockNumber: number): Promise<void> {
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
const
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
return note;
|
|
291
|
-
}),
|
|
292
|
-
);
|
|
293
|
-
|
|
294
|
-
const storedNotes = nullifiedNoteBuffers.map(buffer => StoredNote.fromBuffer(buffer));
|
|
318
|
+
// First pass: collect all nullifiers for all blocks, starting reads during iteration to keep tx alive.
|
|
319
|
+
const nullifiersByBlock: Map<number, { nullifier: string; noteReadPromise: Promise<Buffer | undefined> }[]> =
|
|
320
|
+
new Map();
|
|
321
|
+
|
|
322
|
+
for (let i = blockNumber + 1; i <= anchorBlockNumber; i++) {
|
|
323
|
+
const blockNullifiers: { nullifier: string; noteReadPromise: Promise<Buffer | undefined> }[] = [];
|
|
324
|
+
for await (const nullifier of this.#nullifiersByNullificationBlockNumber.getValuesAsync(i)) {
|
|
325
|
+
// Start read immediately during iteration to keep IndexedDB transaction alive
|
|
326
|
+
blockNullifiers.push({ nullifier, noteReadPromise: this.#notes.getAsync(nullifier) });
|
|
327
|
+
}
|
|
328
|
+
if (blockNullifiers.length > 0) {
|
|
329
|
+
nullifiersByBlock.set(i, blockNullifiers);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
295
332
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
333
|
+
// Second pass: await reads and perform writes
|
|
334
|
+
for (const [block, nullifiers] of nullifiersByBlock) {
|
|
335
|
+
for (const { nullifier, noteReadPromise } of nullifiers) {
|
|
336
|
+
const noteBuffer = await noteReadPromise;
|
|
337
|
+
if (!noteBuffer) {
|
|
338
|
+
throw new Error(`PXE DB integrity error: no note found with nullifier ${nullifier}`);
|
|
339
|
+
}
|
|
299
340
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
throw new Error(`No scopes found for nullified note with nullifier ${noteNullifier}`);
|
|
341
|
+
const storedNote = StoredNote.fromBuffer(noteBuffer);
|
|
342
|
+
if (storedNote.scopes.size === 0) {
|
|
343
|
+
throw new Error(`No scopes found for nullified note with nullifier ${nullifier}`);
|
|
304
344
|
}
|
|
305
345
|
|
|
306
346
|
storedNote.markAsActive();
|
|
307
347
|
|
|
308
348
|
await Promise.all([
|
|
309
|
-
this.#notes.set(
|
|
310
|
-
this.#nullifiersByNullificationBlockNumber.deleteValue(
|
|
349
|
+
this.#notes.set(nullifier, storedNote.toBuffer()),
|
|
350
|
+
this.#nullifiersByNullificationBlockNumber.deleteValue(block, nullifier),
|
|
311
351
|
]);
|
|
312
352
|
}
|
|
313
353
|
}
|
|
314
354
|
}
|
|
315
355
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
356
|
+
/**
|
|
357
|
+
* Commits in memory job data to persistent storage.
|
|
358
|
+
*
|
|
359
|
+
* Called by JobCoordinator when a job completes successfully.
|
|
360
|
+
*
|
|
361
|
+
* Note: JobCoordinator wraps all commits in a single transaction, so we don't need our own transactionAsync here
|
|
362
|
+
* (and using one would throw on IndexedDB as it does not support nested txs).
|
|
363
|
+
*
|
|
364
|
+
* @param jobId - The jobId identifying which staged data to commit
|
|
365
|
+
*/
|
|
366
|
+
async commit(jobId: string): Promise<void> {
|
|
367
|
+
for (const [nullifier, storedNote] of this.#getNotesForJob(jobId)) {
|
|
368
|
+
await this.#notes.set(nullifier, storedNote.toBuffer());
|
|
369
|
+
await this.#nullifiersByContractAddress.set(storedNote.noteDao.contractAddress.toString(), nullifier);
|
|
370
|
+
if (storedNote.nullifiedAt !== undefined) {
|
|
371
|
+
await this.#nullifiersByNullificationBlockNumber.set(storedNote.nullifiedAt, nullifier);
|
|
324
372
|
}
|
|
373
|
+
}
|
|
325
374
|
|
|
326
|
-
|
|
327
|
-
});
|
|
375
|
+
this.#clearJobData(jobId);
|
|
328
376
|
}
|
|
329
377
|
|
|
330
378
|
discardStaged(jobId: string): Promise<void> {
|
|
331
|
-
|
|
379
|
+
this.#clearJobData(jobId);
|
|
380
|
+
return Promise.resolve();
|
|
332
381
|
}
|
|
333
382
|
|
|
334
383
|
#clearJobData(jobId: string) {
|
|
@@ -339,7 +388,7 @@ export class NoteStore implements StagedStore {
|
|
|
339
388
|
/**
|
|
340
389
|
* Functions run withJobLock are forced to wait for each other, i.e. if they share a `jobId`, they run serially
|
|
341
390
|
* instead of concurrently. This is needed because staged data is stored in memory, and concurrent async operations
|
|
342
|
-
* (e.g., Promise.all in `
|
|
391
|
+
* (e.g., Promise.all in `validateAndStoreNote`) could otherwise interleave and corrupt state.
|
|
343
392
|
*/
|
|
344
393
|
async #withJobLock<T>(jobId: string, fn: () => Promise<T>): Promise<T> {
|
|
345
394
|
let lock = this.#jobLocks.get(jobId);
|
|
@@ -363,19 +412,4 @@ export class NoteStore implements StagedStore {
|
|
|
363
412
|
}
|
|
364
413
|
return notesForJob;
|
|
365
414
|
}
|
|
366
|
-
|
|
367
|
-
async #nullifiersOfContract(contractAddress: AztecAddress, jobId: string): Promise<Set<string>> {
|
|
368
|
-
// Collect persisted nullifiers for this contract
|
|
369
|
-
const persistedNullifiers: string[] = await toArray(
|
|
370
|
-
this.#nullifiersByContractAddress.getValuesAsync(contractAddress.toString()),
|
|
371
|
-
);
|
|
372
|
-
|
|
373
|
-
// Collect staged nullifiers from the job where the note's contract matches
|
|
374
|
-
const stagedNullifiers = this.#getNotesForJob(jobId)
|
|
375
|
-
.values()
|
|
376
|
-
.filter(storedNote => storedNote.noteDao.contractAddress.equals(contractAddress))
|
|
377
|
-
.map(storedNote => storedNote.noteDao.siloedNullifier.toString());
|
|
378
|
-
|
|
379
|
-
return new Set([...persistedNullifiers, ...stagedNullifiers]);
|
|
380
|
-
}
|
|
381
415
|
}
|