@aztec/pxe 0.0.1-commit.fcb71a6 → 0.0.1-commit.fffb133c
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 +1 -1
- 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 +66 -18
- package/dest/config/index.d.ts +3 -1
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +17 -0
- 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 +32 -21
- 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/index.d.ts +2 -2
- package/dest/contract_function_simulator/index.d.ts.map +1 -1
- package/dest/contract_function_simulator/index.js +1 -1
- package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +4 -3
- 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 +6 -3
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +1 -1
- package/dest/contract_function_simulator/noir-structs/note_validation_request.js +1 -1
- 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 +15 -11
- 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 +6 -6
- package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/note_packing_utils.js +8 -8
- package/dest/contract_function_simulator/oracle/oracle.d.ts +10 -8
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +43 -32
- package/dest/contract_function_simulator/oracle/private_execution.d.ts +2 -26
- package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution.js +1 -37
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +11 -17
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +23 -39
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +27 -17
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +72 -72
- package/dest/contract_sync/index.d.ts +23 -0
- package/dest/contract_sync/index.d.ts.map +1 -0
- package/dest/contract_sync/index.js +54 -0
- package/dest/debug/pxe_debug_utils.d.ts +1 -1
- package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
- package/dest/debug/pxe_debug_utils.js +3 -2
- 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 +3 -1
- package/dest/entrypoints/server/index.d.ts.map +1 -1
- package/dest/entrypoints/server/index.js +2 -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 +21 -13
- package/dest/notes/note_service.d.ts +5 -4
- package/dest/notes/note_service.d.ts.map +1 -1
- package/dest/notes/note_service.js +30 -34
- package/dest/oracle_version.d.ts +3 -3
- package/dest/oracle_version.d.ts.map +1 -1
- package/dest/oracle_version.js +4 -3
- 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 +70 -93
- 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 +1 -2
- package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
- package/dest/storage/contract_store/contract_store.js +0 -12
- package/dest/storage/note_store/note_store.d.ts +45 -56
- package/dest/storage/note_store/note_store.d.ts.map +1 -1
- package/dest/storage/note_store/note_store.js +244 -263
- package/dest/storage/note_store/stored_note.d.ts +16 -0
- package/dest/storage/note_store/stored_note.d.ts.map +1 -0
- package/dest/storage/note_store/stored_note.js +43 -0
- package/dest/storage/private_event_store/private_event_store.d.ts +47 -7
- package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
- package/dest/storage/private_event_store/private_event_store.js +203 -68
- package/dest/storage/private_event_store/stored_private_event.d.ts +23 -0
- package/dest/storage/private_event_store/stored_private_event.d.ts.map +1 -0
- package/dest/storage/private_event_store/stored_private_event.js +56 -0
- 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/get_all_logs_by_tags.d.ts +24 -0
- package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -0
- package/dest/tagging/get_all_logs_by_tags.js +46 -0
- package/dest/tagging/index.d.ts +3 -2
- package/dest/tagging/index.d.ts.map +1 -1
- package/dest/tagging/index.js +2 -10
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +3 -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 +8 -8
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +3 -2
- 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 +5 -2
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +3 -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 +5 -8
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +5 -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 +10 -5
- package/package.json +18 -18
- package/src/bin/check_oracle_version.ts +1 -0
- package/src/block_synchronizer/block_synchronizer.ts +77 -20
- package/src/config/index.ts +14 -0
- 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 +37 -26
- package/src/contract_function_simulator/execution_note_cache.ts +44 -25
- package/src/contract_function_simulator/index.ts +1 -1
- package/src/contract_function_simulator/noir-structs/event_validation_request.ts +5 -1
- package/src/contract_function_simulator/noir-structs/note_validation_request.ts +1 -1
- package/src/contract_function_simulator/noir-structs/utility_context.ts +6 -25
- package/src/contract_function_simulator/oracle/interfaces.ts +20 -10
- package/src/contract_function_simulator/oracle/note_packing_utils.ts +10 -10
- package/src/contract_function_simulator/oracle/oracle.ts +56 -41
- package/src/contract_function_simulator/oracle/private_execution.ts +1 -69
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +39 -44
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +90 -76
- package/src/contract_sync/index.ts +98 -0
- package/src/debug/pxe_debug_utils.ts +3 -2
- 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 +2 -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 +27 -9
- package/src/notes/note_service.ts +37 -40
- package/src/oracle_version.ts +4 -3
- 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 +123 -127
- package/src/storage/capsule_store/capsule_store.ts +159 -23
- package/src/storage/contract_store/contract_store.ts +0 -20
- package/src/storage/note_store/note_store.ts +286 -317
- package/src/storage/note_store/stored_note.ts +48 -0
- package/src/storage/private_event_store/private_event_store.ts +277 -76
- package/src/storage/private_event_store/stored_private_event.ts +73 -0
- 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/get_all_logs_by_tags.ts +68 -0
- package/src/tagging/index.ts +2 -11
- package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +21 -7
- package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +7 -1
- package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +10 -7
- package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +5 -13
- package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +16 -4
- 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/dest/tree_membership/tree_membership_service.d.ts +0 -52
- package/dest/tree_membership/tree_membership_service.d.ts.map +0 -1
- package/dest/tree_membership/tree_membership_service.js +0 -84
- 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
- package/src/tree_membership/tree_membership_service.ts +0 -112
|
@@ -1,322 +1,303 @@
|
|
|
1
|
-
import { toBufferBE } from '@aztec/foundation/bigint-buffer';
|
|
2
1
|
import { toArray } from '@aztec/foundation/iterable';
|
|
3
|
-
import {
|
|
2
|
+
import { Semaphore } from '@aztec/foundation/queue';
|
|
4
3
|
import { NoteStatus } from '@aztec/stdlib/note';
|
|
5
|
-
import {
|
|
4
|
+
import { StoredNote } from './stored_note.js';
|
|
6
5
|
/**
|
|
7
6
|
* NoteStore manages the storage and retrieval of notes.
|
|
8
7
|
*
|
|
9
|
-
* Notes can be active or nullified. This class processes new notes, nullifications,
|
|
10
|
-
*
|
|
8
|
+
* Notes can be active or nullified. This class processes new notes, nullifications, and performs rollback handling in
|
|
9
|
+
* the case of a reorg.
|
|
11
10
|
**/ export class NoteStore {
|
|
11
|
+
storeName = 'note';
|
|
12
12
|
#store;
|
|
13
|
+
// Note that we use the siloedNullifier as the note id in the store as it's guaranteed to be unique.
|
|
14
|
+
// Main storage for notes. Avoid performing full scans on it as it contains all notes PXE knows, use
|
|
15
|
+
// #nullifiersByContractAddress or #nullifiersByNullificationBlockNumber to find relevant note nullifiers that can be
|
|
16
|
+
// used to read into this map instead.
|
|
17
|
+
// nullifier => StoredNote (serialized)
|
|
13
18
|
#notes;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
#
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
#
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
// Indexes which notes (via their nullifiers) belong to a contract. Used in `getNotes` to reduce the amount of notes
|
|
20
|
+
// checked.
|
|
21
|
+
// contract address => nullifier
|
|
22
|
+
#nullifiersByContractAddress;
|
|
23
|
+
// Groups note nullifiers by the block number they were added to the nullifier tree. Used in `rollback` to handle
|
|
24
|
+
// re-orgs.
|
|
25
|
+
// block number => nullifier (block number in which nullifier is included)
|
|
26
|
+
#nullifiersByNullificationBlockNumber;
|
|
27
|
+
// In-memory changes performed during a not-yet committed job. When `commit` is called with said job's id, these
|
|
28
|
+
// changes are persisted in the DB maps specified above and cleared.
|
|
29
|
+
// jobId => nullifier => StoredNote (serialized)
|
|
30
|
+
#notesForJob;
|
|
31
|
+
// Per job locks to prevent multiple concurrent writes to affect each other.
|
|
32
|
+
// jobId => lock
|
|
33
|
+
#jobLocks;
|
|
25
34
|
constructor(store){
|
|
26
35
|
this.#store = store;
|
|
27
36
|
this.#notes = store.openMap('notes');
|
|
28
|
-
this.#
|
|
29
|
-
this.#
|
|
30
|
-
this.#
|
|
31
|
-
this.#
|
|
32
|
-
this.#nullifiedNotesByContract = store.openMultiMap('nullified_notes_by_contract');
|
|
33
|
-
this.#nullifiedNotesByStorageSlot = store.openMultiMap('nullified_notes_by_storage_slot');
|
|
34
|
-
this.#nullifiedNotesByNullifier = store.openMap('nullified_notes_by_nullifier');
|
|
35
|
-
this.#scopes = store.openMap('scopes');
|
|
36
|
-
this.#notesToScope = store.openMultiMap('notes_to_scope');
|
|
37
|
-
this.#notesByContractAndScope = new Map();
|
|
38
|
-
this.#notesByStorageSlotAndScope = new Map();
|
|
37
|
+
this.#nullifiersByContractAddress = store.openMultiMap('note_nullifiers_by_contract');
|
|
38
|
+
this.#nullifiersByNullificationBlockNumber = store.openMultiMap('note_block_number_to_nullifier');
|
|
39
|
+
this.#jobLocks = new Map();
|
|
40
|
+
this.#notesForJob = new Map();
|
|
39
41
|
}
|
|
40
42
|
/**
|
|
41
|
-
*
|
|
43
|
+
* Adds multiple notes to the notes store under the specified scope.
|
|
42
44
|
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
+
* Notes are stored using their siloedNullifier as the key, which provides uniqueness. Each note is indexed by
|
|
46
|
+
* multiple criteria for efficient retrieval.
|
|
45
47
|
*
|
|
46
|
-
* @param
|
|
47
|
-
* @
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
* @param notes - Notes to store
|
|
49
|
+
* @param scope - The scope (user/account) under which to store the notes
|
|
50
|
+
* @param jobId - The job context for staged writes
|
|
51
|
+
*/ addNotes(notes, scope, jobId) {
|
|
52
|
+
return this.#withJobLock(jobId, ()=>Promise.all(notes.map((noteDao)=>this.#addNote(noteDao, scope, jobId))));
|
|
53
|
+
}
|
|
54
|
+
async #addNote(note, scope, jobId) {
|
|
55
|
+
const noteForJob = await this.#readNote(note.siloedNullifier.toString(), jobId) ?? new StoredNote(note, new Set());
|
|
56
|
+
// Make sure the note is linked to the scope and staged for this job
|
|
57
|
+
noteForJob.addScope(scope.toString());
|
|
58
|
+
this.#writeNote(noteForJob, jobId);
|
|
59
|
+
}
|
|
60
|
+
async #readNote(nullifier, jobId) {
|
|
61
|
+
// First check staged notes for this job
|
|
62
|
+
const noteForJob = this.#getNotesForJob(jobId).get(nullifier);
|
|
63
|
+
if (noteForJob) {
|
|
64
|
+
return noteForJob;
|
|
65
|
+
}
|
|
66
|
+
// Then check persistent storage
|
|
67
|
+
const noteBuffer = await this.#notes.getAsync(nullifier);
|
|
68
|
+
if (noteBuffer) {
|
|
69
|
+
return StoredNote.fromBuffer(noteBuffer);
|
|
53
70
|
}
|
|
54
|
-
return
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
#writeNote(note, jobId) {
|
|
74
|
+
this.#getNotesForJob(jobId).set(note.noteDao.siloedNullifier.toString(), note);
|
|
55
75
|
}
|
|
56
76
|
/**
|
|
57
|
-
*
|
|
77
|
+
* Retrieves notes based on the provided filter criteria.
|
|
58
78
|
*
|
|
59
|
-
*
|
|
60
|
-
* Each scope gets its own set of indexes for efficient note retrieval by various criteria.
|
|
79
|
+
* This method queries both active and optionally nullified notes based on the filter parameters.
|
|
61
80
|
*
|
|
62
|
-
* @param
|
|
63
|
-
*
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
81
|
+
* @param filter - Filter criteria including contractAddress (required), and optional owner,
|
|
82
|
+
* storageSlot, status, scopes, and siloedNullifier.
|
|
83
|
+
* @params jobId - the job context to read from.
|
|
84
|
+
* @returns Filtered and deduplicated notes (a note might be present in multiple scopes - we ensure it is only
|
|
85
|
+
* returned once if this is the case)
|
|
86
|
+
* @throws If filtering by an empty scopes array. Scopes have to be set to undefined or to a non-empty array.
|
|
87
|
+
*/ async getNotes(filter, jobId) {
|
|
88
|
+
if (filter.scopes !== undefined && filter.scopes.length === 0) {
|
|
89
|
+
throw new Error('Trying to get notes with an empty scopes array');
|
|
68
90
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
this.#
|
|
72
|
-
|
|
91
|
+
const targetStatus = filter.status ?? NoteStatus.ACTIVE;
|
|
92
|
+
const foundNotes = new Map();
|
|
93
|
+
const nullifiersOfContract = await this.#nullifiersOfContract(filter.contractAddress, jobId);
|
|
94
|
+
for (const nullifier of nullifiersOfContract){
|
|
95
|
+
const note = await this.#readNote(nullifier, jobId);
|
|
96
|
+
// Defensive: hitting this case means we're mishandling contract indices or in-memory job data
|
|
97
|
+
if (!note) {
|
|
98
|
+
throw new Error('PXE note database is corrupted.');
|
|
99
|
+
}
|
|
100
|
+
// Apply filters
|
|
101
|
+
if (targetStatus === NoteStatus.ACTIVE && note.isNullified()) {
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
if (filter.owner && !note.noteDao.owner.equals(filter.owner)) {
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
if (filter.storageSlot && !note.noteDao.storageSlot.equals(filter.storageSlot)) {
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
if (filter.siloedNullifier && !note.noteDao.siloedNullifier.equals(filter.siloedNullifier)) {
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
if (filter.scopes && note.scopes.intersection(new Set(filter.scopes.map((s)=>s.toString()))).size === 0) {
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
foundNotes.set(note.noteDao.siloedNullifier.toString(), note.noteDao);
|
|
117
|
+
}
|
|
118
|
+
// Sort by block number, then by tx index within block, then by note index within tx
|
|
119
|
+
return [
|
|
120
|
+
...foundNotes.values()
|
|
121
|
+
].sort((a, b)=>{
|
|
122
|
+
if (a.l2BlockNumber !== b.l2BlockNumber) {
|
|
123
|
+
return a.l2BlockNumber - b.l2BlockNumber;
|
|
124
|
+
}
|
|
125
|
+
if (a.txIndexInBlock !== b.txIndexInBlock) {
|
|
126
|
+
return a.txIndexInBlock - b.txIndexInBlock;
|
|
127
|
+
}
|
|
128
|
+
return a.noteIndexInTx - b.noteIndexInTx;
|
|
129
|
+
});
|
|
73
130
|
}
|
|
74
131
|
/**
|
|
75
|
-
*
|
|
132
|
+
* Transitions notes from "active" to "nullified" state.
|
|
76
133
|
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
* for efficient retrieval.
|
|
134
|
+
* This operation processes a batch of nullifiers to mark the corresponding notes as spent/nullified.
|
|
135
|
+
* The operation is atomic - if any nullifier is not found, the entire operation fails and no notes are modified.
|
|
80
136
|
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
await
|
|
95
|
-
|
|
96
|
-
|
|
137
|
+
* applyNullifiers is idempotent: the same nullifier can be applied multiple times without error.
|
|
138
|
+
* This relaxes constraints on usage of NoteService#validateAndStoreNote, which can then be run concurrently in a Promise.all
|
|
139
|
+
* context without risking unnecessarily defensive checks failing.
|
|
140
|
+
*
|
|
141
|
+
* @param nullifiers - Array of nullifiers with their block numbers to process
|
|
142
|
+
* @param jobId - The job context for staged writes
|
|
143
|
+
* @returns Array of NoteDao objects that were nullified
|
|
144
|
+
* @throws Error if any nullifier is not found in this notes store
|
|
145
|
+
*/ applyNullifiers(nullifiers, jobId) {
|
|
146
|
+
return this.#withJobLock(jobId, ()=>this.#store.transactionAsync(async ()=>{
|
|
147
|
+
if (nullifiers.length === 0) {
|
|
148
|
+
return [];
|
|
149
|
+
}
|
|
150
|
+
const notesToNullify = await Promise.all(nullifiers.map(async (nullifierInBlock)=>{
|
|
151
|
+
const nullifier = nullifierInBlock.data.toString();
|
|
152
|
+
const storedNote = await this.#readNote(nullifier, jobId);
|
|
153
|
+
if (!storedNote) {
|
|
154
|
+
throw new Error(`Attempted to mark a note as nullified which does not exist in PXE DB`);
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
storedNote: await this.#readNote(nullifier, jobId),
|
|
158
|
+
blockNumber: nullifierInBlock.l2BlockNumber
|
|
159
|
+
};
|
|
160
|
+
}));
|
|
161
|
+
const notesNullifiedInThisCall = new Map();
|
|
162
|
+
for (const noteToNullify of notesToNullify){
|
|
163
|
+
// Safe to coerce (!) because we throw if we find any undefined above
|
|
164
|
+
const note = noteToNullify.storedNote;
|
|
165
|
+
// Skip already nullified notes
|
|
166
|
+
if (note.isNullified()) {
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
note.markAsNullified(noteToNullify.blockNumber);
|
|
170
|
+
this.#writeNote(note, jobId);
|
|
171
|
+
notesNullifiedInThisCall.set(note.noteDao.siloedNullifier.toString(), note.noteDao);
|
|
172
|
+
}
|
|
173
|
+
return [
|
|
174
|
+
...notesNullifiedInThisCall.values()
|
|
175
|
+
];
|
|
176
|
+
}));
|
|
97
177
|
}
|
|
98
178
|
/**
|
|
99
179
|
* Synchronizes notes and nullifiers to a specific block number.
|
|
100
180
|
*
|
|
101
|
-
* This method ensures that the state of notes and nullifiers is consistent with the
|
|
102
|
-
*
|
|
103
|
-
*
|
|
181
|
+
* This method ensures that the state of notes and nullifiers is consistent with the specified block number.
|
|
182
|
+
* It restores any notes that were nullified after the given block and deletes any active notes created after that
|
|
183
|
+
* block.
|
|
184
|
+
*
|
|
185
|
+
* IMPORTANT: This method must be called within a transaction to ensure atomicity.
|
|
104
186
|
*
|
|
105
187
|
* @param blockNumber - The new chain tip after a reorg
|
|
106
188
|
* @param synchedBlockNumber - The block number up to which PXE managed to sync before the reorg happened.
|
|
107
|
-
*/ async
|
|
108
|
-
|
|
189
|
+
*/ async rollback(blockNumber, synchedBlockNumber) {
|
|
190
|
+
if (this.#notesForJob.size > 0) {
|
|
191
|
+
throw new Error('PXE note store rollback is not allowed while jobs are running');
|
|
192
|
+
}
|
|
193
|
+
await this.#rewindNullifiedNotesAfterBlock(blockNumber, synchedBlockNumber);
|
|
109
194
|
await this.#deleteActiveNotesAfterBlock(blockNumber);
|
|
110
195
|
}
|
|
111
196
|
/**
|
|
112
|
-
* Deletes (removes) all
|
|
197
|
+
* Deletes (removes) all notes created after the specified block number.
|
|
113
198
|
*
|
|
114
|
-
* Permanently delete notes from the
|
|
115
|
-
* Note: This only affects #notes (active notes), not #nullifiedNotes.
|
|
199
|
+
* Permanently delete notes from the notes store, e.g. during a reorg.
|
|
116
200
|
*
|
|
117
201
|
* @param blockNumber - Notes created after this block number will be deleted
|
|
118
|
-
*/ #deleteActiveNotesAfterBlock(blockNumber) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
await this.#notesToScope.delete(noteIndex);
|
|
127
|
-
await this.#nullifierToNoteId.delete(noteDao.siloedNullifier.toString());
|
|
128
|
-
const scopes = await toArray(this.#scopes.keysAsync());
|
|
129
|
-
for (const scope of scopes){
|
|
130
|
-
await this.#notesByContractAndScope.get(scope).deleteValue(noteDao.contractAddress.toString(), noteIndex);
|
|
131
|
-
await this.#notesByStorageSlotAndScope.get(scope).deleteValue(noteDao.storageSlot.toString(), noteIndex);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
202
|
+
*/ async #deleteActiveNotesAfterBlock(blockNumber) {
|
|
203
|
+
const notes = await toArray(this.#notes.valuesAsync());
|
|
204
|
+
for (const noteBuffer of notes){
|
|
205
|
+
const storedNote = StoredNote.fromBuffer(noteBuffer);
|
|
206
|
+
if (storedNote.noteDao.l2BlockNumber > blockNumber) {
|
|
207
|
+
const noteNullifier = storedNote.noteDao.siloedNullifier.toString();
|
|
208
|
+
await this.#notes.delete(noteNullifier);
|
|
209
|
+
await this.#nullifiersByContractAddress.deleteValue(storedNote.noteDao.contractAddress.toString(), noteNullifier);
|
|
134
210
|
}
|
|
135
|
-
}
|
|
211
|
+
}
|
|
136
212
|
}
|
|
137
213
|
/**
|
|
138
214
|
* Rewinds nullifications after a given block number.
|
|
139
215
|
*
|
|
140
|
-
* This operation "
|
|
141
|
-
*
|
|
142
|
-
* active notes store and removed from the nullified store.
|
|
216
|
+
* This operation "un-nullifies" notes, rolling back nullifications that occurred in orphaned blocks, e.g. during a
|
|
217
|
+
* reorg.
|
|
143
218
|
*
|
|
144
219
|
* @param blockNumber - Revert nullifications that occurred after this block
|
|
145
|
-
* @param
|
|
146
|
-
*/ async #
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
if (scopes.length === 0) {
|
|
220
|
+
* @param anchorBlockNumber - Upper bound for the block range to process
|
|
221
|
+
*/ async #rewindNullifiedNotesAfterBlock(blockNumber, anchorBlockNumber) {
|
|
222
|
+
const currentBlockNumber = blockNumber + 1;
|
|
223
|
+
for(let i = currentBlockNumber; i <= anchorBlockNumber; i++){
|
|
224
|
+
const noteNullifiersToReinsert = await toArray(this.#nullifiersByNullificationBlockNumber.getValuesAsync(i));
|
|
225
|
+
const nullifiedNoteBuffers = await Promise.all(noteNullifiersToReinsert.map(async (noteNullifier)=>{
|
|
226
|
+
const note = await this.#notes.getAsync(noteNullifier);
|
|
227
|
+
if (!note) {
|
|
228
|
+
throw new Error(`PXE DB integrity error: no note found with nullifier ${noteNullifier}`);
|
|
229
|
+
}
|
|
230
|
+
return note;
|
|
231
|
+
}));
|
|
232
|
+
const storedNotes = nullifiedNoteBuffers.map((buffer)=>StoredNote.fromBuffer(buffer));
|
|
233
|
+
for (const storedNote of storedNotes){
|
|
234
|
+
const noteNullifier = storedNote.noteDao.siloedNullifier.toString();
|
|
235
|
+
const scopes = storedNote.scopes;
|
|
236
|
+
if (scopes.size === 0) {
|
|
163
237
|
// We should never run into this error because notes always have a scope assigned to them - either on initial
|
|
164
238
|
// insertion via `addNotes` or when removing their nullifiers.
|
|
165
|
-
throw new Error(`No scopes found for nullified note with
|
|
239
|
+
throw new Error(`No scopes found for nullified note with nullifier ${noteNullifier}`);
|
|
166
240
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
241
|
+
storedNote.markAsActive();
|
|
242
|
+
await Promise.all([
|
|
243
|
+
this.#notes.set(noteNullifier, storedNote.toBuffer()),
|
|
244
|
+
this.#nullifiersByNullificationBlockNumber.deleteValue(i, noteNullifier)
|
|
245
|
+
]);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
commit(jobId) {
|
|
250
|
+
return this.#withJobLock(jobId, async ()=>{
|
|
251
|
+
for (const [nullifier, storedNote] of this.#getNotesForJob(jobId)){
|
|
252
|
+
await this.#notes.set(nullifier, storedNote.toBuffer());
|
|
253
|
+
await this.#nullifiersByContractAddress.set(storedNote.noteDao.contractAddress.toString(), nullifier);
|
|
254
|
+
if (storedNote.nullifiedAt !== undefined) {
|
|
255
|
+
await this.#nullifiersByNullificationBlockNumber.set(storedNote.nullifiedAt, nullifier);
|
|
171
256
|
}
|
|
172
|
-
await this.#nullifiedNotes.delete(noteIndex);
|
|
173
|
-
await this.#nullifiedNotesToScope.delete(noteIndex);
|
|
174
|
-
await this.#nullifiersByBlockNumber.deleteValue(dao.l2BlockNumber, dao.siloedNullifier.toString());
|
|
175
|
-
await this.#nullifiedNotesByContract.deleteValue(dao.contractAddress.toString(), noteIndex);
|
|
176
|
-
await this.#nullifiedNotesByStorageSlot.deleteValue(dao.storageSlot.toString(), noteIndex);
|
|
177
|
-
await this.#nullifiedNotesByNullifier.delete(dao.siloedNullifier.toString());
|
|
178
257
|
}
|
|
258
|
+
this.#clearJobData(jobId);
|
|
179
259
|
});
|
|
180
260
|
}
|
|
261
|
+
discardStaged(jobId) {
|
|
262
|
+
return this.#withJobLock(jobId, ()=>Promise.resolve(this.#clearJobData(jobId)));
|
|
263
|
+
}
|
|
264
|
+
#clearJobData(jobId) {
|
|
265
|
+
this.#notesForJob.delete(jobId);
|
|
266
|
+
this.#jobLocks.delete(jobId);
|
|
267
|
+
}
|
|
181
268
|
/**
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
* returned once if this is the case)
|
|
191
|
-
* @throws If filtering by an empty scopes array. Scopes have to be set to undefined or to a non-empty array.
|
|
192
|
-
*/ async getNotes(filter) {
|
|
193
|
-
filter.status = filter.status ?? NoteStatus.ACTIVE;
|
|
194
|
-
// throw early if scopes is an empty array
|
|
195
|
-
if (filter.scopes !== undefined && filter.scopes.length === 0) {
|
|
196
|
-
throw new Error('Trying to get notes with an empty scopes array. Scopes have to be set to undefined if intending on not filtering by scopes.');
|
|
197
|
-
}
|
|
198
|
-
const candidateNoteSources = [];
|
|
199
|
-
filter.scopes ??= (await toArray(this.#scopes.keysAsync())).map((addressString)=>AztecAddress.fromString(addressString));
|
|
200
|
-
const activeNoteIdsPerScope = [];
|
|
201
|
-
for (const scope of new Set(filter.scopes)){
|
|
202
|
-
const formattedScopeString = scope.toString();
|
|
203
|
-
if (!await this.#scopes.hasAsync(formattedScopeString)) {
|
|
204
|
-
throw new Error('Trying to get incoming notes of a scope that is not in the PXE database');
|
|
205
|
-
}
|
|
206
|
-
activeNoteIdsPerScope.push(filter.storageSlot ? await toArray(this.#notesByStorageSlotAndScope.get(formattedScopeString).getValuesAsync(filter.storageSlot.toString())) : await toArray(this.#notesByContractAndScope.get(formattedScopeString).getValuesAsync(filter.contractAddress.toString())));
|
|
207
|
-
}
|
|
208
|
-
candidateNoteSources.push({
|
|
209
|
-
ids: new Set(activeNoteIdsPerScope.flat()),
|
|
210
|
-
notes: this.#notes
|
|
211
|
-
});
|
|
212
|
-
// If status is ACTIVE_OR_NULLIFIED we add nullified notes as candidates on top of the default active ones.
|
|
213
|
-
if (filter.status === NoteStatus.ACTIVE_OR_NULLIFIED) {
|
|
214
|
-
const nullifiedIds = filter.storageSlot ? await toArray(this.#nullifiedNotesByStorageSlot.getValuesAsync(filter.storageSlot.toString())) : await toArray(this.#nullifiedNotesByContract.getValuesAsync(filter.contractAddress.toString()));
|
|
215
|
-
const setOfScopes = new Set(filter.scopes.map((s)=>s.toString()));
|
|
216
|
-
const filteredNullifiedIds = new Set();
|
|
217
|
-
for (const noteId of nullifiedIds){
|
|
218
|
-
const scopeList = await toArray(this.#nullifiedNotesToScope.getValuesAsync(noteId));
|
|
219
|
-
if (scopeList.some((scope)=>setOfScopes.has(scope))) {
|
|
220
|
-
filteredNullifiedIds.add(noteId);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
if (filteredNullifiedIds.size > 0) {
|
|
224
|
-
candidateNoteSources.push({
|
|
225
|
-
ids: filteredNullifiedIds,
|
|
226
|
-
notes: this.#nullifiedNotes
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
const result = [];
|
|
231
|
-
for (const { ids, notes } of candidateNoteSources){
|
|
232
|
-
for (const id of ids){
|
|
233
|
-
const serializedNote = await notes.getAsync(id);
|
|
234
|
-
if (!serializedNote) {
|
|
235
|
-
continue;
|
|
236
|
-
}
|
|
237
|
-
const note = NoteDao.fromBuffer(serializedNote);
|
|
238
|
-
if (!note.contractAddress.equals(filter.contractAddress)) {
|
|
239
|
-
continue;
|
|
240
|
-
}
|
|
241
|
-
if (filter.owner && !note.owner.equals(filter.owner)) {
|
|
242
|
-
continue;
|
|
243
|
-
}
|
|
244
|
-
if (filter.storageSlot && !note.storageSlot.equals(filter.storageSlot)) {
|
|
245
|
-
continue;
|
|
246
|
-
}
|
|
247
|
-
if (filter.siloedNullifier && !note.siloedNullifier.equals(filter.siloedNullifier)) {
|
|
248
|
-
continue;
|
|
249
|
-
}
|
|
250
|
-
result.push(note);
|
|
251
|
-
}
|
|
269
|
+
* Functions run withJobLock are forced to wait for each other, i.e. if they share a `jobId`, they run serially
|
|
270
|
+
* instead of concurrently. This is needed because staged data is stored in memory, and concurrent async operations
|
|
271
|
+
* (e.g., Promise.all in `validateAndStoreNote`) could otherwise interleave and corrupt state.
|
|
272
|
+
*/ async #withJobLock(jobId, fn) {
|
|
273
|
+
let lock = this.#jobLocks.get(jobId);
|
|
274
|
+
if (!lock) {
|
|
275
|
+
lock = new Semaphore(1);
|
|
276
|
+
this.#jobLocks.set(jobId, lock);
|
|
252
277
|
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
}
|
|
278
|
+
await lock.acquire();
|
|
279
|
+
try {
|
|
280
|
+
return await fn();
|
|
281
|
+
} finally{
|
|
282
|
+
lock.release();
|
|
259
283
|
}
|
|
260
|
-
return deduplicated;
|
|
261
284
|
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
* the entire operation fails and no notes are modified.
|
|
268
|
-
*
|
|
269
|
-
* @param nullifiers - Array of nullifiers with their block numbers to process
|
|
270
|
-
* @returns Promise resolving to array of nullified NoteDao objects
|
|
271
|
-
* @throws Error if any nullifier is not found in the active notes
|
|
272
|
-
*/ applyNullifiers(nullifiers) {
|
|
273
|
-
if (nullifiers.length === 0) {
|
|
274
|
-
return Promise.resolve([]);
|
|
285
|
+
#getNotesForJob(jobId) {
|
|
286
|
+
let notesForJob = this.#notesForJob.get(jobId);
|
|
287
|
+
if (!notesForJob) {
|
|
288
|
+
notesForJob = new Map();
|
|
289
|
+
this.#notesForJob.set(jobId, notesForJob);
|
|
275
290
|
}
|
|
276
|
-
return
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
}
|
|
288
|
-
throw new Error('Nullifier not found in applyNullifiers');
|
|
289
|
-
}
|
|
290
|
-
const noteBuffer = noteIndex ? await this.#notes.getAsync(noteIndex) : undefined;
|
|
291
|
-
if (!noteBuffer) {
|
|
292
|
-
throw new Error('Note not found in applyNullifiers');
|
|
293
|
-
}
|
|
294
|
-
const noteScopes = await toArray(this.#notesToScope.getValuesAsync(noteIndex));
|
|
295
|
-
if (noteScopes.length === 0) {
|
|
296
|
-
// We should never run into this error because notes always have a scope assigned to them - either on initial
|
|
297
|
-
// insertion via `addNotes` or when removing their nullifiers.
|
|
298
|
-
throw new Error('Note scopes are missing in applyNullifiers');
|
|
299
|
-
}
|
|
300
|
-
const note = NoteDao.fromBuffer(noteBuffer);
|
|
301
|
-
nullifiedNotes.push(note);
|
|
302
|
-
await this.#notes.delete(noteIndex);
|
|
303
|
-
await this.#notesToScope.delete(noteIndex);
|
|
304
|
-
const scopes = await toArray(this.#scopes.keysAsync());
|
|
305
|
-
for (const scope of scopes){
|
|
306
|
-
await this.#notesByContractAndScope.get(scope).deleteValue(note.contractAddress.toString(), noteIndex);
|
|
307
|
-
await this.#notesByStorageSlotAndScope.get(scope).deleteValue(note.storageSlot.toString(), noteIndex);
|
|
308
|
-
}
|
|
309
|
-
for (const scope of noteScopes){
|
|
310
|
-
await this.#nullifiedNotesToScope.set(noteIndex, scope);
|
|
311
|
-
}
|
|
312
|
-
await this.#nullifiedNotes.set(noteIndex, note.toBuffer());
|
|
313
|
-
await this.#nullifiersByBlockNumber.set(blockNumber, nullifier.toString());
|
|
314
|
-
await this.#nullifiedNotesByContract.set(note.contractAddress.toString(), noteIndex);
|
|
315
|
-
await this.#nullifiedNotesByStorageSlot.set(note.storageSlot.toString(), noteIndex);
|
|
316
|
-
await this.#nullifiedNotesByNullifier.set(nullifier.toString(), noteIndex);
|
|
317
|
-
await this.#nullifierToNoteId.delete(nullifier.toString());
|
|
318
|
-
}
|
|
319
|
-
return nullifiedNotes;
|
|
320
|
-
});
|
|
291
|
+
return notesForJob;
|
|
292
|
+
}
|
|
293
|
+
async #nullifiersOfContract(contractAddress, jobId) {
|
|
294
|
+
// Collect persisted nullifiers for this contract
|
|
295
|
+
const persistedNullifiers = await toArray(this.#nullifiersByContractAddress.getValuesAsync(contractAddress.toString()));
|
|
296
|
+
// Collect staged nullifiers from the job where the note's contract matches
|
|
297
|
+
const stagedNullifiers = this.#getNotesForJob(jobId).values().filter((storedNote)=>storedNote.noteDao.contractAddress.equals(contractAddress)).map((storedNote)=>storedNote.noteDao.siloedNullifier.toString());
|
|
298
|
+
return new Set([
|
|
299
|
+
...persistedNullifiers,
|
|
300
|
+
...stagedNullifiers
|
|
301
|
+
]);
|
|
321
302
|
}
|
|
322
303
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { NoteDao } from '@aztec/stdlib/note';
|
|
3
|
+
export declare class StoredNote {
|
|
4
|
+
readonly noteDao: NoteDao;
|
|
5
|
+
readonly scopes: Set<string>;
|
|
6
|
+
private _nullifiedAt;
|
|
7
|
+
constructor(noteDao: NoteDao, scopes: Set<string>, _nullifiedAt?: BlockNumber | undefined);
|
|
8
|
+
static fromBuffer(buffer: Buffer): StoredNote;
|
|
9
|
+
toBuffer(): Buffer;
|
|
10
|
+
addScope(scope: string): void;
|
|
11
|
+
markAsNullified(blockNumber: BlockNumber): void;
|
|
12
|
+
markAsActive(): void;
|
|
13
|
+
isNullified(): boolean;
|
|
14
|
+
get nullifiedAt(): BlockNumber | undefined;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3RvcmVkX25vdGUuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9zdG9yYWdlL25vdGVfc3RvcmUvc3RvcmVkX25vdGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLFdBQVcsRUFBRSxNQUFNLGlDQUFpQyxDQUFDO0FBRTlELE9BQU8sRUFBRSxPQUFPLEVBQUUsTUFBTSxvQkFBb0IsQ0FBQztBQUU3QyxxQkFBYSxVQUFVO0lBRW5CLFFBQVEsQ0FBQyxPQUFPLEVBQUUsT0FBTztJQUN6QixRQUFRLENBQUMsTUFBTSxFQUFFLEdBQUcsQ0FBQyxNQUFNLENBQUM7SUFDNUIsT0FBTyxDQUFDLFlBQVk7SUFIdEIsWUFDVyxPQUFPLEVBQUUsT0FBTyxFQUNoQixNQUFNLEVBQUUsR0FBRyxDQUFDLE1BQU0sQ0FBQyxFQUNwQixZQUFZLEdBQUUsV0FBVyxHQUFHLFNBQXFCLEVBQ3ZEO0lBRUosTUFBTSxDQUFDLFVBQVUsQ0FBQyxNQUFNLEVBQUUsTUFBTSxjQVUvQjtJQUVELFFBQVEsSUFBSSxNQUFNLENBR2pCO0lBRUQsUUFBUSxDQUFDLEtBQUssRUFBRSxNQUFNLFFBRXJCO0lBRUQsZUFBZSxDQUFDLFdBQVcsRUFBRSxXQUFXLFFBRXZDO0lBRUQsWUFBWSxTQUVYO0lBRUQsV0FBVyxZQUVWO0lBRUQsSUFBSSxXQUFXLDRCQUVkO0NBQ0YifQ==
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stored_note.d.ts","sourceRoot":"","sources":["../../../src/storage/note_store/stored_note.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAE9D,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C,qBAAa,UAAU;IAEnB,QAAQ,CAAC,OAAO,EAAE,OAAO;IACzB,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC;IAC5B,OAAO,CAAC,YAAY;IAHtB,YACW,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,EACpB,YAAY,GAAE,WAAW,GAAG,SAAqB,EACvD;IAEJ,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,cAU/B;IAED,QAAQ,IAAI,MAAM,CAGjB;IAED,QAAQ,CAAC,KAAK,EAAE,MAAM,QAErB;IAED,eAAe,CAAC,WAAW,EAAE,WAAW,QAEvC;IAED,YAAY,SAEX;IAED,WAAW,YAEV;IAED,IAAI,WAAW,4BAEd;CACF"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
2
|
+
import { NoteDao } from '@aztec/stdlib/note';
|
|
3
|
+
export class StoredNote {
|
|
4
|
+
noteDao;
|
|
5
|
+
scopes;
|
|
6
|
+
_nullifiedAt;
|
|
7
|
+
constructor(noteDao, scopes, _nullifiedAt = undefined){
|
|
8
|
+
this.noteDao = noteDao;
|
|
9
|
+
this.scopes = scopes;
|
|
10
|
+
this._nullifiedAt = _nullifiedAt;
|
|
11
|
+
}
|
|
12
|
+
static fromBuffer(buffer) {
|
|
13
|
+
const reader = BufferReader.asReader(buffer);
|
|
14
|
+
const noteDao = NoteDao.fromBuffer(reader);
|
|
15
|
+
const scopes = reader.readVector({
|
|
16
|
+
fromBuffer: (r)=>r.readString()
|
|
17
|
+
});
|
|
18
|
+
const nullifiedAtRaw = reader.readNumber();
|
|
19
|
+
const nullifiedAt = nullifiedAtRaw === 0 ? undefined : nullifiedAtRaw;
|
|
20
|
+
return new StoredNote(noteDao, new Set(scopes), nullifiedAt);
|
|
21
|
+
}
|
|
22
|
+
toBuffer() {
|
|
23
|
+
const scopesArray = [
|
|
24
|
+
...this.scopes
|
|
25
|
+
];
|
|
26
|
+
return serializeToBuffer(this.noteDao, scopesArray.length, ...scopesArray, this._nullifiedAt ?? 0);
|
|
27
|
+
}
|
|
28
|
+
addScope(scope) {
|
|
29
|
+
this.scopes.add(scope);
|
|
30
|
+
}
|
|
31
|
+
markAsNullified(blockNumber) {
|
|
32
|
+
this._nullifiedAt = blockNumber;
|
|
33
|
+
}
|
|
34
|
+
markAsActive() {
|
|
35
|
+
this._nullifiedAt = undefined;
|
|
36
|
+
}
|
|
37
|
+
isNullified() {
|
|
38
|
+
return this._nullifiedAt !== undefined;
|
|
39
|
+
}
|
|
40
|
+
get nullifiedAt() {
|
|
41
|
+
return this._nullifiedAt;
|
|
42
|
+
}
|
|
43
|
+
}
|