@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,34 +1,120 @@
|
|
|
1
1
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
3
3
|
export class CapsuleStore {
|
|
4
|
+
storeName = 'capsule';
|
|
4
5
|
#store;
|
|
5
6
|
// Arbitrary data stored by contracts. Key is computed as `${contractAddress}:${key}`
|
|
6
7
|
#capsules;
|
|
8
|
+
// jobId => `${contractAddress}:${key}` => capsule data
|
|
9
|
+
// when `#stagedCapsules.get('some-job-id').get('${some-contract-address:some-key') === null`,
|
|
10
|
+
// it signals that the capsule was deleted during the job, so it needs to be deleted on commit
|
|
11
|
+
#stagedCapsules;
|
|
7
12
|
logger;
|
|
8
13
|
constructor(store){
|
|
9
14
|
this.#store = store;
|
|
10
15
|
this.#capsules = this.#store.openMap('capsules');
|
|
16
|
+
this.#stagedCapsules = new Map();
|
|
11
17
|
this.logger = createLogger('pxe:capsule-data-provider');
|
|
12
18
|
}
|
|
13
19
|
/**
|
|
20
|
+
* Given a job denoted by `jobId`, it returns the
|
|
21
|
+
* capsules that said job has interacted with.
|
|
22
|
+
*
|
|
23
|
+
* Capsules that haven't been committed to persistence KV storage
|
|
24
|
+
* are kept in-memory in `#stagedCapsules`, this method provides a convenient
|
|
25
|
+
* way to access that in-memory collection of data.
|
|
26
|
+
*
|
|
27
|
+
* @param jobId
|
|
28
|
+
* @returns
|
|
29
|
+
*/ #getJobStagedCapsules(jobId) {
|
|
30
|
+
let jobStagedCapsules = this.#stagedCapsules.get(jobId);
|
|
31
|
+
if (!jobStagedCapsules) {
|
|
32
|
+
jobStagedCapsules = new Map();
|
|
33
|
+
this.#stagedCapsules.set(jobId, jobStagedCapsules);
|
|
34
|
+
}
|
|
35
|
+
return jobStagedCapsules;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Reads a capsule's slot from the staged version of the data associated to the given jobId.
|
|
39
|
+
*
|
|
40
|
+
* If it is not there, it reads it from the KV store.
|
|
41
|
+
*/ async #getFromStage(jobId, dbSlotKey) {
|
|
42
|
+
const jobStagedCapsules = this.#getJobStagedCapsules(jobId);
|
|
43
|
+
let staged = jobStagedCapsules.get(dbSlotKey);
|
|
44
|
+
// Note that if staged === null, we marked it for deletion, so we don't want to
|
|
45
|
+
// re-read it from DB
|
|
46
|
+
if (staged === undefined) {
|
|
47
|
+
// If we don't have a staged version of this dbSlotKey, first we check if there's one in DB
|
|
48
|
+
staged = await this.#loadCapsuleFromDb(dbSlotKey);
|
|
49
|
+
}
|
|
50
|
+
return staged;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Writes a capsule to the stage of a job.
|
|
54
|
+
*/ #setOnStage(jobId, dbSlotKey, capsuleData) {
|
|
55
|
+
this.#getJobStagedCapsules(jobId).set(dbSlotKey, capsuleData);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Deletes a capsule on the stage of a job. Note the capsule will still
|
|
59
|
+
* exist in storage until the job is committed.
|
|
60
|
+
*/ #deleteOnStage(jobId, dbSlotKey) {
|
|
61
|
+
this.#getJobStagedCapsules(jobId).set(dbSlotKey, null);
|
|
62
|
+
}
|
|
63
|
+
async #loadCapsuleFromDb(dbSlotKey) {
|
|
64
|
+
const dataBuffer = await this.#capsules.getAsync(dbSlotKey);
|
|
65
|
+
if (!dataBuffer) {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
return dataBuffer;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Commits staged data to main storage.
|
|
72
|
+
* Called by JobCoordinator when a job completes successfully.
|
|
73
|
+
* Note: JobCoordinator wraps all commits in a single transaction, so we don't
|
|
74
|
+
* need our own transactionAsync here (and using one would deadlock on IndexedDB).
|
|
75
|
+
* @param jobId - The jobId identifying which staged data to commit
|
|
76
|
+
*/ async commit(jobId) {
|
|
77
|
+
const jobStagedCapsules = this.#getJobStagedCapsules(jobId);
|
|
78
|
+
for (const [key, value] of jobStagedCapsules){
|
|
79
|
+
// In the write stage, we represent deleted capsules with null
|
|
80
|
+
// (as opposed to undefined, which denotes there was never a capsule there to begin with).
|
|
81
|
+
// So we delete from actual KV store here.
|
|
82
|
+
if (value === null) {
|
|
83
|
+
await this.#capsules.delete(key);
|
|
84
|
+
} else {
|
|
85
|
+
await this.#capsules.set(key, value);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
this.#stagedCapsules.delete(jobId);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Discards staged data without committing.
|
|
92
|
+
*/ discardStaged(jobId) {
|
|
93
|
+
this.#stagedCapsules.delete(jobId);
|
|
94
|
+
return Promise.resolve();
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
14
97
|
* Stores arbitrary information in a per-contract non-volatile database, which can later be retrieved with `loadCapsule`.
|
|
15
98
|
* * If data was already stored at this slot, it is overwritten.
|
|
16
99
|
* @param contractAddress - The contract address to scope the data under.
|
|
17
100
|
* @param slot - The slot in the database in which to store the value. Slots need not be contiguous.
|
|
18
101
|
* @param capsule - An array of field elements representing the capsule.
|
|
102
|
+
* @param jobId - The context in which this store will be visible until PXE decides to persist it to underlying KV store
|
|
19
103
|
* @remarks A capsule is a "blob" of data that is passed to the contract through an oracle. It works similarly
|
|
20
104
|
* to public contract storage in that it's indexed by the contract address and storage slot but instead of the global
|
|
21
105
|
* network state it's backed by local PXE db.
|
|
22
|
-
*/
|
|
23
|
-
|
|
106
|
+
*/ storeCapsule(contractAddress, slot, capsule, jobId) {
|
|
107
|
+
const dbSlotKey = dbSlotToKey(contractAddress, slot);
|
|
108
|
+
// A store overrides any pre-existing data on the slot
|
|
109
|
+
this.#setOnStage(jobId, dbSlotKey, Buffer.concat(capsule.map((value)=>value.toBuffer())));
|
|
24
110
|
}
|
|
25
111
|
/**
|
|
26
112
|
* Returns data previously stored via `storeCapsule` in the per-contract non-volatile database.
|
|
27
113
|
* @param contractAddress - The contract address under which the data is scoped.
|
|
28
114
|
* @param slot - The slot in the database to read.
|
|
29
115
|
* @returns The stored data or `null` if no data is stored under the slot.
|
|
30
|
-
*/ async loadCapsule(contractAddress, slot) {
|
|
31
|
-
const dataBuffer = await this.#
|
|
116
|
+
*/ async loadCapsule(contractAddress, slot, jobId) {
|
|
117
|
+
const dataBuffer = await this.#getFromStage(jobId, dbSlotToKey(contractAddress, slot));
|
|
32
118
|
if (!dataBuffer) {
|
|
33
119
|
this.logger.trace(`Data not found for contract ${contractAddress.toString()} and slot ${slot.toString()}`);
|
|
34
120
|
return null;
|
|
@@ -43,8 +129,9 @@ export class CapsuleStore {
|
|
|
43
129
|
* Deletes data in the per-contract non-volatile database. Does nothing if no data was present.
|
|
44
130
|
* @param contractAddress - The contract address under which the data is scoped.
|
|
45
131
|
* @param slot - The slot in the database to delete.
|
|
46
|
-
*/
|
|
47
|
-
|
|
132
|
+
*/ deleteCapsule(contractAddress, slot, jobId) {
|
|
133
|
+
// When we commit this, we will interpret null as a deletion, so we'll propagate the delete to the KV store
|
|
134
|
+
this.#deleteOnStage(jobId, dbSlotToKey(contractAddress, slot));
|
|
48
135
|
}
|
|
49
136
|
/**
|
|
50
137
|
* Copies a number of contiguous entries in the per-contract non-volatile database. This allows for efficient data
|
|
@@ -56,7 +143,11 @@ export class CapsuleStore {
|
|
|
56
143
|
* @param srcSlot - The first slot to copy from.
|
|
57
144
|
* @param dstSlot - The first slot to copy to.
|
|
58
145
|
* @param numEntries - The number of entries to copy.
|
|
59
|
-
*/ copyCapsule(contractAddress, srcSlot, dstSlot, numEntries) {
|
|
146
|
+
*/ copyCapsule(contractAddress, srcSlot, dstSlot, numEntries, jobId) {
|
|
147
|
+
// This transactional context gives us "copy atomicity":
|
|
148
|
+
// there shouldn't be concurrent writes to what's being copied here.
|
|
149
|
+
// Equally important: this in practice is expected to perform thousands of DB operations
|
|
150
|
+
// and not using a transaction here would heavily impact performance.
|
|
60
151
|
return this.#store.transactionAsync(async ()=>{
|
|
61
152
|
// In order to support overlapping source and destination regions, we need to check the relative positions of source
|
|
62
153
|
// and destination. If destination is ahead of source, then by the time we overwrite source elements using forward
|
|
@@ -69,11 +160,11 @@ export class CapsuleStore {
|
|
|
69
160
|
for (const i of indexes){
|
|
70
161
|
const currentSrcSlot = dbSlotToKey(contractAddress, srcSlot.add(new Fr(i)));
|
|
71
162
|
const currentDstSlot = dbSlotToKey(contractAddress, dstSlot.add(new Fr(i)));
|
|
72
|
-
const toCopy = await this.#
|
|
163
|
+
const toCopy = await this.#getFromStage(jobId, currentSrcSlot);
|
|
73
164
|
if (!toCopy) {
|
|
74
165
|
throw new Error(`Attempted to copy empty slot ${currentSrcSlot} for contract ${contractAddress.toString()}`);
|
|
75
166
|
}
|
|
76
|
-
|
|
167
|
+
this.#setOnStage(jobId, currentDstSlot, toCopy);
|
|
77
168
|
}
|
|
78
169
|
});
|
|
79
170
|
}
|
|
@@ -84,32 +175,42 @@ export class CapsuleStore {
|
|
|
84
175
|
* @param contractAddress - The contract address that owns the capsule array
|
|
85
176
|
* @param baseSlot - The slot where the array length is stored
|
|
86
177
|
* @param content - Array of capsule data to append
|
|
87
|
-
*/ appendToCapsuleArray(contractAddress, baseSlot, content) {
|
|
178
|
+
*/ appendToCapsuleArray(contractAddress, baseSlot, content, jobId) {
|
|
179
|
+
// We wrap this in a transaction to serialize concurrent calls from Promise.all.
|
|
180
|
+
// Without this, concurrent appends to the same array could race: both read length=0,
|
|
181
|
+
// both write at the same slots, one overwrites the other.
|
|
182
|
+
// Equally important: this in practice is expected to perform thousands of DB operations
|
|
183
|
+
// and not using a transaction here would heavily impact performance.
|
|
88
184
|
return this.#store.transactionAsync(async ()=>{
|
|
89
185
|
// Load current length, defaulting to 0 if not found
|
|
90
|
-
const lengthData = await this.loadCapsule(contractAddress, baseSlot);
|
|
186
|
+
const lengthData = await this.loadCapsule(contractAddress, baseSlot, jobId);
|
|
91
187
|
const currentLength = lengthData ? lengthData[0].toNumber() : 0;
|
|
92
188
|
// Store each capsule at consecutive slots after baseSlot + 1 + currentLength
|
|
93
189
|
for(let i = 0; i < content.length; i++){
|
|
94
190
|
const nextSlot = arraySlot(baseSlot, currentLength + i);
|
|
95
|
-
|
|
191
|
+
this.storeCapsule(contractAddress, nextSlot, content[i], jobId);
|
|
96
192
|
}
|
|
97
193
|
// Update length to include all new capsules
|
|
98
194
|
const newLength = currentLength + content.length;
|
|
99
|
-
|
|
195
|
+
this.storeCapsule(contractAddress, baseSlot, [
|
|
100
196
|
new Fr(newLength)
|
|
101
|
-
]);
|
|
197
|
+
], jobId);
|
|
102
198
|
});
|
|
103
199
|
}
|
|
104
|
-
readCapsuleArray(contractAddress, baseSlot) {
|
|
200
|
+
readCapsuleArray(contractAddress, baseSlot, jobId) {
|
|
201
|
+
// I'm leaving this transactional context here though because I'm assuming this
|
|
202
|
+
// gives us "read array atomicity": there shouldn't be concurrent writes to what's being copied
|
|
203
|
+
// here.
|
|
204
|
+
// This is one point we should revisit in the future if we want to relax the concurrency
|
|
205
|
+
// of jobs: different calls running concurrently on the same contract may cause trouble.
|
|
105
206
|
return this.#store.transactionAsync(async ()=>{
|
|
106
207
|
// Load length, defaulting to 0 if not found
|
|
107
|
-
const maybeLength = await this.loadCapsule(contractAddress, baseSlot);
|
|
208
|
+
const maybeLength = await this.loadCapsule(contractAddress, baseSlot, jobId);
|
|
108
209
|
const length = maybeLength ? maybeLength[0].toBigInt() : 0n;
|
|
109
210
|
const values = [];
|
|
110
211
|
// Read each capsule at consecutive slots after baseSlot
|
|
111
212
|
for(let i = 0; i < length; i++){
|
|
112
|
-
const currentValue = await this.loadCapsule(contractAddress, arraySlot(baseSlot, i));
|
|
213
|
+
const currentValue = await this.loadCapsule(contractAddress, arraySlot(baseSlot, i), jobId);
|
|
113
214
|
if (currentValue == undefined) {
|
|
114
215
|
throw new Error(`Expected non-empty value at capsule array in base slot ${baseSlot} at index ${i} for contract ${contractAddress}`);
|
|
115
216
|
}
|
|
@@ -118,22 +219,30 @@ export class CapsuleStore {
|
|
|
118
219
|
return values;
|
|
119
220
|
});
|
|
120
221
|
}
|
|
121
|
-
setCapsuleArray(contractAddress, baseSlot, content) {
|
|
222
|
+
setCapsuleArray(contractAddress, baseSlot, content, jobId) {
|
|
223
|
+
// This transactional context in theory isn't so critical now because we aren't
|
|
224
|
+
// writing to DB so if there's exceptions midway and it blows up, no visible impact
|
|
225
|
+
// to persistent storage will happen.
|
|
226
|
+
// I'm leaving this transactional context here though because I'm assuming this
|
|
227
|
+
// gives us "write array atomicity": there shouldn't be concurrent writes to what's being copied
|
|
228
|
+
// here.
|
|
229
|
+
// This is one point we should revisit in the future if we want to relax the concurrency
|
|
230
|
+
// of jobs: different calls running concurrently on the same contract may cause trouble.
|
|
122
231
|
return this.#store.transactionAsync(async ()=>{
|
|
123
232
|
// Load current length, defaulting to 0 if not found
|
|
124
|
-
const maybeLength = await this.loadCapsule(contractAddress, baseSlot);
|
|
233
|
+
const maybeLength = await this.loadCapsule(contractAddress, baseSlot, jobId);
|
|
125
234
|
const originalLength = maybeLength ? maybeLength[0].toNumber() : 0;
|
|
126
235
|
// Set the new length
|
|
127
|
-
|
|
236
|
+
this.storeCapsule(contractAddress, baseSlot, [
|
|
128
237
|
new Fr(content.length)
|
|
129
|
-
]);
|
|
238
|
+
], jobId);
|
|
130
239
|
// Store the new content, possibly overwriting existing values
|
|
131
240
|
for(let i = 0; i < content.length; i++){
|
|
132
|
-
|
|
241
|
+
this.storeCapsule(contractAddress, arraySlot(baseSlot, i), content[i], jobId);
|
|
133
242
|
}
|
|
134
243
|
// Clear any stragglers
|
|
135
244
|
for(let i = content.length; i < originalLength; i++){
|
|
136
|
-
|
|
245
|
+
this.deleteCapsule(contractAddress, arraySlot(baseSlot, i), jobId);
|
|
137
246
|
}
|
|
138
247
|
});
|
|
139
248
|
}
|
|
@@ -62,6 +62,5 @@ export declare class ContractStore {
|
|
|
62
62
|
getDebugContractName(contractAddress: AztecAddress): Promise<string | undefined>;
|
|
63
63
|
getDebugFunctionName(contractAddress: AztecAddress, selector: FunctionSelector): Promise<string>;
|
|
64
64
|
getFunctionCall(functionName: string, args: any[], to: AztecAddress): Promise<FunctionCall>;
|
|
65
|
-
syncPrivateState(contractAddress: AztecAddress, functionToInvokeAfterSync: FunctionSelector | null, utilityExecutor: (privateSyncCall: FunctionCall) => Promise<any>): Promise<any>;
|
|
66
65
|
}
|
|
67
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
66
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29udHJhY3Rfc3RvcmUuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9zdG9yYWdlL2NvbnRyYWN0X3N0b3JlL2NvbnRyYWN0X3N0b3JlLnRzIl0sIm5hbWVzI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yxDQUk1QztJQUVZLDhCQUE4QixDQUN6QyxlQUFlLEVBQUUsWUFBWSxHQUM1QixPQUFPLENBQUMscUJBQXFCLEdBQUcsU0FBUyxDQUFDLENBSTVDO0lBRUQ7Ozs7Ozs7O09BUUc7SUFDVSw0QkFBNEIsQ0FDdkMsZUFBZSxFQUFFLEVBQUUsRUFDbkIsUUFBUSxFQUFFLGdCQUFnQixHQUN6QixPQUFPLENBQUMsaUJBQWlCLENBQUMsT0FBTyxvQkFBb0IsQ0FBQyxHQUFHLFNBQVMsQ0FBQyxDQUdyRTtJQUVZLG9CQUFvQixDQUFDLGVBQWUsRUFBRSxZQUFZLCtCQUc5RDtJQUVZLG9CQUFvQixDQUFDLGVBQWUsRUFBRSxZQUFZLEVBQUUsUUFBUSxFQUFFLGdCQUFnQixtQkFJMUY7SUE4QlksZUFBZSxDQUFDLFlBQVksRUFBRSxNQUFNLEVBQUUsSUFBSSxFQUFFLEdBQUcsRUFBRSxFQUFFLEVBQUUsRUFBRSxZQUFZLEdBQUcsT0FBTyxDQUFDLFlBQVksQ0FBQyxDQXVCdkc7Q0FDRiJ9
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract_store.d.ts","sourceRoot":"","sources":["../../../src/storage/contract_store/contract_store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AAEzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,KAAK,EAAE,iBAAiB,EAAiB,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"contract_store.d.ts","sourceRoot":"","sources":["../../../src/storage/contract_store/contract_store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,KAAK,EAAE,EAAE,EAAE,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AAgB,GACzB,OAAO,CAAC,gCAAgC,GAAG,SAAS,CAAC,CAIvD;IAEY,oCAAoC,CAC/C,eAAe,EAAE,YAAY,EAC7B,QAAQ,EAAE,gBAAgB,GACzB,OAAO,CAAC,gCAAgC,CAAC,CAU3C;IAEY,yBAAyB,CACpC,eAAe,EAAE,YAAY,GAC5B,OAAO,CAAC,gCAAgC,GAAG,SAAS,CAAC,CAIvD;IAEY,cAAc,CACzB,eAAe,EAAE,YAAY,EAC7B,QAAQ,EAAE,gBAAgB,GACzB,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC,CAGlC;IAED;;;;;;;;;OASG;IACU,wBAAwB,CACnC,eAAe,EAAE,YAAY,EAC7B,QAAQ,EAAE,gBAAgB,GACzB,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CAI5C;IAEY,8BAA8B,CACzC,eAAe,EAAE,YAAY,GAC5B,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CAI5C;IAED;;;;;;;;OAQG;IACU,4BAA4B,CACvC,eAAe,EAAE,EAAE,EACnB,QAAQ,EAAE,gBAAgB,GACzB,OAAO,CAAC,iBAAiB,CAAC,OAAO,oBAAoB,CAAC,GAAG,SAAS,CAAC,CAGrE;IAEY,oBAAoB,CAAC,eAAe,EAAE,YAAY,+BAG9D;IAEY,oBAAoB,CAAC,eAAe,EAAE,YAAY,EAAE,QAAQ,EAAE,gBAAgB,mBAI1F;IA8BY,eAAe,CAAC,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,CAuBvG;CACF"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { toArray } from '@aztec/foundation/iterable';
|
|
2
|
-
import { isProtocolContract } from '@aztec/protocol-contracts';
|
|
3
2
|
import { FunctionSelector, FunctionType, contractArtifactFromBuffer, contractArtifactToBuffer, encodeArguments, getFunctionDebugMetadata } from '@aztec/stdlib/abi';
|
|
4
3
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
4
|
import { SerializableContractInstance, getContractClassFromArtifact } from '@aztec/stdlib/contract';
|
|
@@ -222,15 +221,4 @@ import { PrivateFunctionsTree } from './private_functions_tree.js';
|
|
|
222
221
|
returnTypes: functionDao.returnTypes
|
|
223
222
|
};
|
|
224
223
|
}
|
|
225
|
-
// Synchronize target contract data
|
|
226
|
-
async syncPrivateState(contractAddress, functionToInvokeAfterSync, utilityExecutor) {
|
|
227
|
-
// Protocol contracts don't have private state to sync
|
|
228
|
-
if (!isProtocolContract(contractAddress)) {
|
|
229
|
-
const syncPrivateStateFunctionCall = await this.getFunctionCall('sync_private_state', [], contractAddress);
|
|
230
|
-
if (functionToInvokeAfterSync && functionToInvokeAfterSync.equals(syncPrivateStateFunctionCall.selector)) {
|
|
231
|
-
throw new Error('Forbidden `sync_private_state` invocation. `sync_private_state` can only be invoked by PXE, manual execution can lead to inconsistencies.');
|
|
232
|
-
}
|
|
233
|
-
return utilityExecutor(syncPrivateStateFunctionCall);
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
224
|
}
|
|
@@ -1,84 +1,73 @@
|
|
|
1
|
-
import type { Fr } from '@aztec/foundation/
|
|
1
|
+
import type { Fr } from '@aztec/foundation/schemas';
|
|
2
2
|
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
3
|
-
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
3
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
4
|
import type { DataInBlock } from '@aztec/stdlib/block';
|
|
5
|
-
import { type NotesFilter } from '@aztec/stdlib/note';
|
|
6
|
-
import {
|
|
5
|
+
import { NoteDao, type NotesFilter } from '@aztec/stdlib/note';
|
|
6
|
+
import type { StagedStore } from '../../job_coordinator/job_coordinator.js';
|
|
7
7
|
/**
|
|
8
8
|
* NoteStore manages the storage and retrieval of notes.
|
|
9
9
|
*
|
|
10
|
-
* Notes can be active or nullified. This class processes new notes, nullifications,
|
|
11
|
-
*
|
|
10
|
+
* Notes can be active or nullified. This class processes new notes, nullifications, and performs rollback handling in
|
|
11
|
+
* the case of a reorg.
|
|
12
12
|
**/
|
|
13
|
-
export declare class NoteStore {
|
|
13
|
+
export declare class NoteStore implements StagedStore {
|
|
14
14
|
#private;
|
|
15
|
-
|
|
15
|
+
readonly storeName: string;
|
|
16
|
+
constructor(store: AztecAsyncKVStore);
|
|
16
17
|
/**
|
|
17
|
-
*
|
|
18
|
+
* Adds multiple notes to the notes store under the specified scope.
|
|
18
19
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* @param store - The key-value store to use for persistence
|
|
23
|
-
* @returns Promise resolving to a fully initialized NoteStore instance
|
|
24
|
-
*/
|
|
25
|
-
static create(store: AztecAsyncKVStore): Promise<NoteStore>;
|
|
26
|
-
/**
|
|
27
|
-
* Adds a new scope to the note data provider.
|
|
28
|
-
*
|
|
29
|
-
* Scopes provide privacy isolation by creating separate indexes for each user.
|
|
30
|
-
* Each scope gets its own set of indexes for efficient note retrieval by various criteria.
|
|
31
|
-
*
|
|
32
|
-
* @param scope - The AztecAddress representing the scope/user to add
|
|
33
|
-
* @returns Promise resolving to true if scope was added, false if it already existed
|
|
34
|
-
*/
|
|
35
|
-
addScope(scope: AztecAddress): Promise<boolean>;
|
|
36
|
-
/**
|
|
37
|
-
* Adds multiple notes to the data provider under the specified scope.
|
|
38
|
-
*
|
|
39
|
-
* Notes are stored using their index from the notes hash tree as the key, which provides
|
|
40
|
-
* uniqueness and maintains creation order. Each note is indexed by multiple criteria
|
|
41
|
-
* for efficient retrieval.
|
|
20
|
+
* Notes are stored using their siloedNullifier as the key, which provides uniqueness. Each note is indexed by
|
|
21
|
+
* multiple criteria for efficient retrieval.
|
|
42
22
|
*
|
|
43
23
|
* @param notes - Notes to store
|
|
44
24
|
* @param scope - The scope (user/account) under which to store the notes
|
|
25
|
+
* @param jobId - The job context for staged writes
|
|
45
26
|
*/
|
|
46
|
-
addNotes(notes: NoteDao[], scope: AztecAddress): Promise<void>;
|
|
47
|
-
/**
|
|
48
|
-
* Synchronizes notes and nullifiers to a specific block number.
|
|
49
|
-
*
|
|
50
|
-
* This method ensures that the state of notes and nullifiers is consistent with the
|
|
51
|
-
* specified block number. It restores any notes that were nullified after the given block
|
|
52
|
-
* and deletes any active notes created after that block.
|
|
53
|
-
*
|
|
54
|
-
* @param blockNumber - The new chain tip after a reorg
|
|
55
|
-
* @param synchedBlockNumber - The block number up to which PXE managed to sync before the reorg happened.
|
|
56
|
-
*/
|
|
57
|
-
rollbackNotesAndNullifiers(blockNumber: number, synchedBlockNumber: number): Promise<void>;
|
|
27
|
+
addNotes(notes: NoteDao[], scope: AztecAddress, jobId: string): Promise<void[]>;
|
|
58
28
|
/**
|
|
59
29
|
* Retrieves notes based on the provided filter criteria.
|
|
60
30
|
*
|
|
61
|
-
* This method queries both active and optionally nullified notes based on the filter
|
|
62
|
-
* parameters.
|
|
31
|
+
* This method queries both active and optionally nullified notes based on the filter parameters.
|
|
63
32
|
*
|
|
64
|
-
* @param filter - Filter criteria including contractAddress (required), and optional
|
|
65
|
-
*
|
|
33
|
+
* @param filter - Filter criteria including contractAddress (required), and optional owner,
|
|
34
|
+
* storageSlot, status, scopes, and siloedNullifier.
|
|
35
|
+
* @params jobId - the job context to read from.
|
|
66
36
|
* @returns Filtered and deduplicated notes (a note might be present in multiple scopes - we ensure it is only
|
|
67
37
|
* returned once if this is the case)
|
|
68
38
|
* @throws If filtering by an empty scopes array. Scopes have to be set to undefined or to a non-empty array.
|
|
69
39
|
*/
|
|
70
|
-
getNotes(filter: NotesFilter): Promise<NoteDao[]>;
|
|
40
|
+
getNotes(filter: NotesFilter, jobId: string): Promise<NoteDao[]>;
|
|
71
41
|
/**
|
|
72
42
|
* Transitions notes from "active" to "nullified" state.
|
|
73
43
|
*
|
|
74
|
-
* This operation processes a batch of nullifiers to mark the corresponding notes
|
|
75
|
-
*
|
|
76
|
-
*
|
|
44
|
+
* This operation processes a batch of nullifiers to mark the corresponding notes as spent/nullified.
|
|
45
|
+
* The operation is atomic - if any nullifier is not found, the entire operation fails and no notes are modified.
|
|
46
|
+
*
|
|
47
|
+
* applyNullifiers is idempotent: the same nullifier can be applied multiple times without error.
|
|
48
|
+
* This relaxes constraints on usage of NoteService#validateAndStoreNote, which can then be run concurrently in a Promise.all
|
|
49
|
+
* context without risking unnecessarily defensive checks failing.
|
|
77
50
|
*
|
|
78
51
|
* @param nullifiers - Array of nullifiers with their block numbers to process
|
|
79
|
-
* @
|
|
80
|
-
* @
|
|
52
|
+
* @param jobId - The job context for staged writes
|
|
53
|
+
* @returns Array of NoteDao objects that were nullified
|
|
54
|
+
* @throws Error if any nullifier is not found in this notes store
|
|
55
|
+
*/
|
|
56
|
+
applyNullifiers(nullifiers: DataInBlock<Fr>[], jobId: string): Promise<NoteDao[]>;
|
|
57
|
+
/**
|
|
58
|
+
* Synchronizes notes and nullifiers to a specific block number.
|
|
59
|
+
*
|
|
60
|
+
* This method ensures that the state of notes and nullifiers is consistent with the specified block number.
|
|
61
|
+
* It restores any notes that were nullified after the given block and deletes any active notes created after that
|
|
62
|
+
* block.
|
|
63
|
+
*
|
|
64
|
+
* IMPORTANT: This method must be called within a transaction to ensure atomicity.
|
|
65
|
+
*
|
|
66
|
+
* @param blockNumber - The new chain tip after a reorg
|
|
67
|
+
* @param synchedBlockNumber - The block number up to which PXE managed to sync before the reorg happened.
|
|
81
68
|
*/
|
|
82
|
-
|
|
69
|
+
rollback(blockNumber: number, synchedBlockNumber: number): Promise<void>;
|
|
70
|
+
commit(jobId: string): Promise<void>;
|
|
71
|
+
discardStaged(jobId: string): Promise<void>;
|
|
83
72
|
}
|
|
84
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
73
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibm90ZV9zdG9yZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvd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VSxFQUFFLFdBQVcsQ0FBQyxFQUFFLENBQUMsRUFBRSxFQUFFLEtBQUssRUFBRSxNQUFNLEdBQUcsT0FBTyxDQUFDLE9BQU8sRUFBRSxDQUFDLENBc0NoRjtJQUVEOzs7Ozs7Ozs7OztPQVdHO0lBQ1UsUUFBUSxDQUFDLFdBQVcsRUFBRSxNQUFNLEVBQUUsa0JBQWtCLEVBQUUsTUFBTSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FNcEY7SUEwRUQsTUFBTSxDQUFDLEtBQUssRUFBRSxNQUFNLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxDQVluQztJQUVELGFBQWEsQ0FBQyxLQUFLLEVBQUUsTUFBTSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FFMUM7Q0FpREYifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"note_store.d.ts","sourceRoot":"","sources":["../../../src/storage/note_store/note_store.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"note_store.d.ts","sourceRoot":"","sources":["../../../src/storage/note_store/note_store.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,2BAA2B,CAAC;AACpD,OAAO,KAAK,EAAE,iBAAiB,EAAqC,MAAM,iBAAiB,CAAC;AAC5F,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,OAAO,EAAc,KAAK,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAE3E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0CAA0C,CAAC;AAG5E;;;;;IAKI;AACJ,qBAAa,SAAU,YAAW,WAAW;;IAC3C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAU;IA+BpC,YAAY,KAAK,EAAE,iBAAiB,EAQnC;IAED;;;;;;;;;OASG;IAC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