@aztec/pxe 0.0.1-commit.96bb3f7 → 0.0.1-commit.a072138

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.
Files changed (226) hide show
  1. package/dest/bin/check_oracle_version.js +1 -1
  2. package/dest/block_synchronizer/block_synchronizer.d.ts +9 -5
  3. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
  4. package/dest/block_synchronizer/block_synchronizer.js +66 -21
  5. package/dest/config/index.d.ts +3 -1
  6. package/dest/config/index.d.ts.map +1 -1
  7. package/dest/config/index.js +17 -0
  8. package/dest/contract_function_simulator/benchmarked_node.d.ts +9 -0
  9. package/dest/contract_function_simulator/benchmarked_node.d.ts.map +1 -0
  10. package/dest/contract_function_simulator/benchmarked_node.js +77 -0
  11. package/dest/contract_function_simulator/contract_function_simulator.d.ts +6 -10
  12. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  13. package/dest/contract_function_simulator/contract_function_simulator.js +33 -25
  14. package/dest/contract_function_simulator/execution_note_cache.d.ts +18 -9
  15. package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -1
  16. package/dest/contract_function_simulator/execution_note_cache.js +45 -28
  17. package/dest/contract_function_simulator/index.d.ts +2 -2
  18. package/dest/contract_function_simulator/index.d.ts.map +1 -1
  19. package/dest/contract_function_simulator/index.js +1 -1
  20. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +1 -1
  21. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +1 -1
  22. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +1 -1
  23. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +1 -1
  24. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts +4 -10
  25. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts.map +1 -1
  26. package/dest/contract_function_simulator/noir-structs/utility_context.js +7 -18
  27. package/dest/contract_function_simulator/oracle/interfaces.d.ts +15 -11
  28. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  29. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts +3 -1
  30. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts.map +1 -1
  31. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts +6 -6
  32. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts.map +1 -1
  33. package/dest/contract_function_simulator/oracle/note_packing_utils.js +8 -8
  34. package/dest/contract_function_simulator/oracle/oracle.d.ts +10 -8
  35. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  36. package/dest/contract_function_simulator/oracle/oracle.js +44 -33
  37. package/dest/contract_function_simulator/oracle/private_execution.d.ts +2 -26
  38. package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
  39. package/dest/contract_function_simulator/oracle/private_execution.js +0 -35
  40. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +11 -3
  41. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  42. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +22 -10
  43. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +33 -20
  44. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  45. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +78 -76
  46. package/dest/contract_sync/index.d.ts +23 -0
  47. package/dest/contract_sync/index.d.ts.map +1 -0
  48. package/dest/contract_sync/index.js +54 -0
  49. package/dest/debug/pxe_debug_utils.d.ts +16 -6
  50. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  51. package/dest/debug/pxe_debug_utils.js +20 -10
  52. package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
  53. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  54. package/dest/entrypoints/client/bundle/utils.js +12 -6
  55. package/dest/entrypoints/client/lazy/utils.d.ts +2 -2
  56. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  57. package/dest/entrypoints/client/lazy/utils.js +13 -7
  58. package/dest/entrypoints/pxe_creation_options.d.ts +3 -2
  59. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  60. package/dest/entrypoints/server/index.d.ts +3 -1
  61. package/dest/entrypoints/server/index.d.ts.map +1 -1
  62. package/dest/entrypoints/server/index.js +2 -0
  63. package/dest/entrypoints/server/utils.d.ts +1 -1
  64. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  65. package/dest/entrypoints/server/utils.js +19 -8
  66. package/dest/events/event_service.d.ts +6 -6
  67. package/dest/events/event_service.d.ts.map +1 -1
  68. package/dest/events/event_service.js +19 -22
  69. package/dest/events/private_event_filter_validator.d.ts +5 -5
  70. package/dest/events/private_event_filter_validator.d.ts.map +1 -1
  71. package/dest/events/private_event_filter_validator.js +5 -6
  72. package/dest/job_coordinator/job_coordinator.d.ts +3 -2
  73. package/dest/job_coordinator/job_coordinator.d.ts.map +1 -1
  74. package/dest/job_coordinator/job_coordinator.js +3 -2
  75. package/dest/logs/log_service.d.ts +6 -4
  76. package/dest/logs/log_service.d.ts.map +1 -1
  77. package/dest/logs/log_service.js +21 -16
  78. package/dest/notes/note_service.d.ts +7 -7
  79. package/dest/notes/note_service.d.ts.map +1 -1
  80. package/dest/notes/note_service.js +31 -36
  81. package/dest/oracle_version.d.ts +3 -3
  82. package/dest/oracle_version.d.ts.map +1 -1
  83. package/dest/oracle_version.js +4 -3
  84. package/dest/private_kernel/hints/index.d.ts +2 -2
  85. package/dest/private_kernel/hints/index.d.ts.map +1 -1
  86. package/dest/private_kernel/hints/index.js +1 -1
  87. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +28 -0
  88. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -0
  89. package/dest/private_kernel/hints/{build_private_kernel_reset_private_inputs.js → private_kernel_reset_private_inputs_builder.js} +12 -6
  90. package/dest/private_kernel/private_kernel_execution_prover.d.ts +3 -2
  91. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  92. package/dest/private_kernel/private_kernel_execution_prover.js +3 -3
  93. package/dest/private_kernel/private_kernel_oracle.d.ts +23 -28
  94. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  95. package/dest/private_kernel/private_kernel_oracle.js +90 -2
  96. package/dest/pxe.d.ts +7 -36
  97. package/dest/pxe.d.ts.map +1 -1
  98. package/dest/pxe.js +43 -83
  99. package/dest/storage/address_store/address_store.d.ts +1 -1
  100. package/dest/storage/address_store/address_store.d.ts.map +1 -1
  101. package/dest/storage/address_store/address_store.js +12 -11
  102. package/dest/storage/anchor_block_store/anchor_block_store.d.ts +9 -1
  103. package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -1
  104. package/dest/storage/anchor_block_store/anchor_block_store.js +8 -1
  105. package/dest/storage/capsule_store/capsule_store.d.ts +24 -9
  106. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
  107. package/dest/storage/capsule_store/capsule_store.js +130 -23
  108. package/dest/storage/contract_store/contract_store.d.ts +1 -2
  109. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  110. package/dest/storage/contract_store/contract_store.js +22 -25
  111. package/dest/storage/metadata.d.ts +1 -1
  112. package/dest/storage/metadata.js +1 -1
  113. package/dest/storage/note_store/note_store.d.ts +51 -52
  114. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  115. package/dest/storage/note_store/note_store.js +282 -263
  116. package/dest/storage/note_store/stored_note.d.ts +16 -0
  117. package/dest/storage/note_store/stored_note.d.ts.map +1 -0
  118. package/dest/storage/note_store/stored_note.js +43 -0
  119. package/dest/storage/private_event_store/private_event_store.d.ts +43 -8
  120. package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
  121. package/dest/storage/private_event_store/private_event_store.js +226 -111
  122. package/dest/storage/private_event_store/stored_private_event.d.ts +23 -0
  123. package/dest/storage/private_event_store/stored_private_event.d.ts.map +1 -0
  124. package/dest/storage/private_event_store/stored_private_event.js +56 -0
  125. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +15 -8
  126. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
  127. package/dest/storage/tagging_store/recipient_tagging_store.js +88 -19
  128. package/dest/storage/tagging_store/sender_address_book_store.d.ts +1 -1
  129. package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +1 -1
  130. package/dest/storage/tagging_store/sender_address_book_store.js +20 -14
  131. package/dest/storage/tagging_store/sender_tagging_store.d.ts +19 -9
  132. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  133. package/dest/storage/tagging_store/sender_tagging_store.js +252 -100
  134. package/dest/tagging/get_all_logs_by_tags.d.ts +24 -0
  135. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -0
  136. package/dest/tagging/get_all_logs_by_tags.js +46 -0
  137. package/dest/tagging/index.d.ts +2 -1
  138. package/dest/tagging/index.d.ts.map +1 -1
  139. package/dest/tagging/index.js +1 -0
  140. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +3 -2
  141. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
  142. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +6 -6
  143. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +3 -2
  144. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
  145. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +5 -2
  146. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +3 -2
  147. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  148. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +7 -7
  149. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +1 -1
  150. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
  151. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +5 -8
  152. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +5 -2
  153. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  154. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +10 -5
  155. package/package.json +18 -18
  156. package/src/bin/check_oracle_version.ts +1 -0
  157. package/src/block_synchronizer/block_synchronizer.ts +85 -33
  158. package/src/config/index.ts +14 -0
  159. package/src/contract_function_simulator/benchmarked_node.ts +103 -0
  160. package/src/contract_function_simulator/contract_function_simulator.ts +34 -28
  161. package/src/contract_function_simulator/execution_note_cache.ts +44 -25
  162. package/src/contract_function_simulator/index.ts +1 -1
  163. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +1 -1
  164. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +1 -1
  165. package/src/contract_function_simulator/noir-structs/utility_context.ts +6 -25
  166. package/src/contract_function_simulator/oracle/interfaces.ts +20 -10
  167. package/src/contract_function_simulator/oracle/note_packing_utils.ts +10 -10
  168. package/src/contract_function_simulator/oracle/oracle.ts +65 -40
  169. package/src/contract_function_simulator/oracle/private_execution.ts +1 -67
  170. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +35 -12
  171. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +100 -82
  172. package/src/contract_sync/index.ts +98 -0
  173. package/src/debug/pxe_debug_utils.ts +26 -11
  174. package/src/entrypoints/client/bundle/utils.ts +7 -14
  175. package/src/entrypoints/client/lazy/utils.ts +8 -14
  176. package/src/entrypoints/pxe_creation_options.ts +2 -1
  177. package/src/entrypoints/server/index.ts +2 -0
  178. package/src/entrypoints/server/utils.ts +15 -19
  179. package/src/events/event_service.ts +17 -25
  180. package/src/events/private_event_filter_validator.ts +3 -5
  181. package/src/job_coordinator/job_coordinator.ts +4 -3
  182. package/src/logs/log_service.ts +32 -14
  183. package/src/notes/note_service.ts +38 -43
  184. package/src/oracle_version.ts +4 -3
  185. package/src/private_kernel/hints/index.ts +1 -1
  186. package/src/private_kernel/hints/{build_private_kernel_reset_private_inputs.ts → private_kernel_reset_private_inputs_builder.ts} +32 -20
  187. package/src/private_kernel/private_kernel_execution_prover.ts +7 -4
  188. package/src/private_kernel/private_kernel_oracle.ts +116 -37
  189. package/src/pxe.ts +77 -118
  190. package/src/storage/address_store/address_store.ts +15 -15
  191. package/src/storage/anchor_block_store/anchor_block_store.ts +8 -0
  192. package/src/storage/capsule_store/capsule_store.ts +159 -23
  193. package/src/storage/contract_store/contract_store.ts +22 -31
  194. package/src/storage/metadata.ts +1 -1
  195. package/src/storage/note_store/note_store.ts +317 -318
  196. package/src/storage/note_store/stored_note.ts +48 -0
  197. package/src/storage/private_event_store/private_event_store.ts +292 -124
  198. package/src/storage/private_event_store/stored_private_event.ts +73 -0
  199. package/src/storage/tagging_store/recipient_tagging_store.ts +106 -20
  200. package/src/storage/tagging_store/sender_address_book_store.ts +20 -14
  201. package/src/storage/tagging_store/sender_tagging_store.ts +293 -108
  202. package/src/tagging/get_all_logs_by_tags.ts +68 -0
  203. package/src/tagging/index.ts +1 -0
  204. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +16 -5
  205. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +7 -1
  206. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +9 -6
  207. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +5 -17
  208. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +16 -4
  209. package/dest/contract_function_simulator/proxied_node.d.ts +0 -9
  210. package/dest/contract_function_simulator/proxied_node.d.ts.map +0 -1
  211. package/dest/contract_function_simulator/proxied_node.js +0 -27
  212. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts +0 -28
  213. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts.map +0 -1
  214. package/dest/private_kernel/private_kernel_oracle_impl.d.ts +0 -46
  215. package/dest/private_kernel/private_kernel_oracle_impl.d.ts.map +0 -1
  216. package/dest/private_kernel/private_kernel_oracle_impl.js +0 -85
  217. package/dest/public_storage/public_storage_service.d.ts +0 -24
  218. package/dest/public_storage/public_storage_service.d.ts.map +0 -1
  219. package/dest/public_storage/public_storage_service.js +0 -26
  220. package/dest/tree_membership/tree_membership_service.d.ts +0 -52
  221. package/dest/tree_membership/tree_membership_service.d.ts.map +0 -1
  222. package/dest/tree_membership/tree_membership_service.js +0 -84
  223. package/src/contract_function_simulator/proxied_node.ts +0 -33
  224. package/src/private_kernel/private_kernel_oracle_impl.ts +0 -127
  225. package/src/public_storage/public_storage_service.ts +0 -33
  226. package/src/tree_membership/tree_membership_service.ts +0 -112
@@ -2,34 +2,49 @@ import { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import { type Logger } from '@aztec/foundation/log';
3
3
  import type { AztecAsyncKVStore } from '@aztec/kv-store';
4
4
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
5
- export declare class CapsuleStore {
5
+ import type { StagedStore } from '../../job_coordinator/job_coordinator.js';
6
+ export declare class CapsuleStore implements StagedStore {
6
7
  #private;
8
+ readonly storeName = "capsule";
7
9
  logger: Logger;
8
10
  constructor(store: AztecAsyncKVStore);
11
+ /**
12
+ * Commits staged data to main storage.
13
+ * Called by JobCoordinator when a job completes successfully.
14
+ * Note: JobCoordinator wraps all commits in a single transaction, so we don't
15
+ * need our own transactionAsync here (and using one would deadlock on IndexedDB).
16
+ * @param jobId - The jobId identifying which staged data to commit
17
+ */
18
+ commit(jobId: string): Promise<void>;
19
+ /**
20
+ * Discards staged data without committing.
21
+ */
22
+ discardStaged(jobId: string): Promise<void>;
9
23
  /**
10
24
  * Stores arbitrary information in a per-contract non-volatile database, which can later be retrieved with `loadCapsule`.
11
25
  * * If data was already stored at this slot, it is overwritten.
12
26
  * @param contractAddress - The contract address to scope the data under.
13
27
  * @param slot - The slot in the database in which to store the value. Slots need not be contiguous.
14
28
  * @param capsule - An array of field elements representing the capsule.
29
+ * @param jobId - The context in which this store will be visible until PXE decides to persist it to underlying KV store
15
30
  * @remarks A capsule is a "blob" of data that is passed to the contract through an oracle. It works similarly
16
31
  * to public contract storage in that it's indexed by the contract address and storage slot but instead of the global
17
32
  * network state it's backed by local PXE db.
18
33
  */
19
- storeCapsule(contractAddress: AztecAddress, slot: Fr, capsule: Fr[]): Promise<void>;
34
+ storeCapsule(contractAddress: AztecAddress, slot: Fr, capsule: Fr[], jobId: string): void;
20
35
  /**
21
36
  * Returns data previously stored via `storeCapsule` in the per-contract non-volatile database.
22
37
  * @param contractAddress - The contract address under which the data is scoped.
23
38
  * @param slot - The slot in the database to read.
24
39
  * @returns The stored data or `null` if no data is stored under the slot.
25
40
  */
26
- loadCapsule(contractAddress: AztecAddress, slot: Fr): Promise<Fr[] | null>;
41
+ loadCapsule(contractAddress: AztecAddress, slot: Fr, jobId: string): Promise<Fr[] | null>;
27
42
  /**
28
43
  * Deletes data in the per-contract non-volatile database. Does nothing if no data was present.
29
44
  * @param contractAddress - The contract address under which the data is scoped.
30
45
  * @param slot - The slot in the database to delete.
31
46
  */
32
- deleteCapsule(contractAddress: AztecAddress, slot: Fr): Promise<void>;
47
+ deleteCapsule(contractAddress: AztecAddress, slot: Fr, jobId: string): void;
33
48
  /**
34
49
  * Copies a number of contiguous entries in the per-contract non-volatile database. This allows for efficient data
35
50
  * structures by avoiding repeated calls to `loadCapsule` and `storeCapsule`.
@@ -41,7 +56,7 @@ export declare class CapsuleStore {
41
56
  * @param dstSlot - The first slot to copy to.
42
57
  * @param numEntries - The number of entries to copy.
43
58
  */
44
- copyCapsule(contractAddress: AztecAddress, srcSlot: Fr, dstSlot: Fr, numEntries: number): Promise<void>;
59
+ copyCapsule(contractAddress: AztecAddress, srcSlot: Fr, dstSlot: Fr, numEntries: number, jobId: string): Promise<void>;
45
60
  /**
46
61
  * Appends multiple capsules to a capsule array stored at the base slot.
47
62
  * The array length is stored at the base slot, and elements are stored in consecutive slots after it.
@@ -50,8 +65,8 @@ export declare class CapsuleStore {
50
65
  * @param baseSlot - The slot where the array length is stored
51
66
  * @param content - Array of capsule data to append
52
67
  */
53
- appendToCapsuleArray(contractAddress: AztecAddress, baseSlot: Fr, content: Fr[][]): Promise<void>;
54
- readCapsuleArray(contractAddress: AztecAddress, baseSlot: Fr): Promise<Fr[][]>;
55
- setCapsuleArray(contractAddress: AztecAddress, baseSlot: Fr, content: Fr[][]): Promise<void>;
68
+ appendToCapsuleArray(contractAddress: AztecAddress, baseSlot: Fr, content: Fr[][], jobId: string): Promise<void>;
69
+ readCapsuleArray(contractAddress: AztecAddress, baseSlot: Fr, jobId: string): Promise<Fr[][]>;
70
+ setCapsuleArray(contractAddress: AztecAddress, baseSlot: Fr, content: Fr[][], jobId: string): Promise<void>;
56
71
  }
57
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2Fwc3VsZV9zdG9yZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL3N0b3JhZ2UvY2Fwc3VsZV9zdG9yZS9jYXBzdWxlX3N0b3JlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxFQUFFLEVBQUUsTUFBTSxnQ0FBZ0MsQ0FBQztBQUNwRCxPQUFPLEVBQUUsS0FBSyxNQUFNLEVBQWdCLE1BQU0sdUJBQXVCLENBQUM7QUFDbEUsT0FBTyxLQUFLLEVBQUUsaUJBQWlCLEVBQWlCLE1BQU0saUJBQWlCLENBQUM7QUFDeEUsT0FBTyxLQUFLLEVBQUUsWUFBWSxFQUFFLE1BQU0sNkJBQTZCLENBQUM7QUFFaEUscUJBQWEsWUFBWTs7SUFNdkIsTUFBTSxFQUFFLE1BQU0sQ0FBQztJQUVmLFlBQVksS0FBSyxFQUFFLGlCQUFpQixFQU1uQztJQUVEOzs7Ozs7Ozs7T0FTRztJQUNHLFlBQVksQ0FBQyxlQUFlLEVBQUUsWUFBWSxFQUFFLElBQUks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,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,IAAI,CAAC,CA2Bf;IAED;;;;;;;OAOG;IACH,oBAAoB,CAAC,eAAe,EAAE,YAAY,EAAE,QAAQ,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAqB/G;IAED,gBAAgB,CAAC,eAAe,EAAE,YAAY,EAAE,QAAQ,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,CA2B5F;IAED,eAAe,CAAC,eAAe,EAAE,YAAY,EAAE,QAAQ,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,iBA2B1F;CACF"}
@@ -1,34 +1,118 @@
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
+ const staged = jobStagedCapsules.get(dbSlotKey);
44
+ // Always issue DB read to keep IndexedDB transaction alive, even if the value is in the job staged data. This
45
+ // keeps IndexedDB transactions alive (they auto-commit when a new micro-task starts and there are no pending read
46
+ // requests). The staged value still takes precedence if it exists (including null for deletions).
47
+ const dbValue = await this.#loadCapsuleFromDb(dbSlotKey);
48
+ return staged !== undefined ? staged : dbValue;
49
+ }
50
+ /**
51
+ * Writes a capsule to the stage of a job.
52
+ */ #setOnStage(jobId, dbSlotKey, capsuleData) {
53
+ this.#getJobStagedCapsules(jobId).set(dbSlotKey, capsuleData);
54
+ }
55
+ /**
56
+ * Deletes a capsule on the stage of a job. Note the capsule will still
57
+ * exist in storage until the job is committed.
58
+ */ #deleteOnStage(jobId, dbSlotKey) {
59
+ this.#getJobStagedCapsules(jobId).set(dbSlotKey, null);
60
+ }
61
+ async #loadCapsuleFromDb(dbSlotKey) {
62
+ const dataBuffer = await this.#capsules.getAsync(dbSlotKey);
63
+ if (!dataBuffer) {
64
+ return null;
65
+ }
66
+ return dataBuffer;
67
+ }
68
+ /**
69
+ * Commits staged data to main storage.
70
+ * Called by JobCoordinator when a job completes successfully.
71
+ * Note: JobCoordinator wraps all commits in a single transaction, so we don't
72
+ * need our own transactionAsync here (and using one would deadlock on IndexedDB).
73
+ * @param jobId - The jobId identifying which staged data to commit
74
+ */ async commit(jobId) {
75
+ const jobStagedCapsules = this.#getJobStagedCapsules(jobId);
76
+ for (const [key, value] of jobStagedCapsules){
77
+ // In the write stage, we represent deleted capsules with null
78
+ // (as opposed to undefined, which denotes there was never a capsule there to begin with).
79
+ // So we delete from actual KV store here.
80
+ if (value === null) {
81
+ await this.#capsules.delete(key);
82
+ } else {
83
+ await this.#capsules.set(key, value);
84
+ }
85
+ }
86
+ this.#stagedCapsules.delete(jobId);
87
+ }
88
+ /**
89
+ * Discards staged data without committing.
90
+ */ discardStaged(jobId) {
91
+ this.#stagedCapsules.delete(jobId);
92
+ return Promise.resolve();
93
+ }
94
+ /**
14
95
  * Stores arbitrary information in a per-contract non-volatile database, which can later be retrieved with `loadCapsule`.
15
96
  * * If data was already stored at this slot, it is overwritten.
16
97
  * @param contractAddress - The contract address to scope the data under.
17
98
  * @param slot - The slot in the database in which to store the value. Slots need not be contiguous.
18
99
  * @param capsule - An array of field elements representing the capsule.
100
+ * @param jobId - The context in which this store will be visible until PXE decides to persist it to underlying KV store
19
101
  * @remarks A capsule is a "blob" of data that is passed to the contract through an oracle. It works similarly
20
102
  * to public contract storage in that it's indexed by the contract address and storage slot but instead of the global
21
103
  * network state it's backed by local PXE db.
22
- */ async storeCapsule(contractAddress, slot, capsule) {
23
- await this.#capsules.set(dbSlotToKey(contractAddress, slot), Buffer.concat(capsule.map((value)=>value.toBuffer())));
104
+ */ storeCapsule(contractAddress, slot, capsule, jobId) {
105
+ const dbSlotKey = dbSlotToKey(contractAddress, slot);
106
+ // A store overrides any pre-existing data on the slot
107
+ this.#setOnStage(jobId, dbSlotKey, Buffer.concat(capsule.map((value)=>value.toBuffer())));
24
108
  }
25
109
  /**
26
110
  * Returns data previously stored via `storeCapsule` in the per-contract non-volatile database.
27
111
  * @param contractAddress - The contract address under which the data is scoped.
28
112
  * @param slot - The slot in the database to read.
29
113
  * @returns The stored data or `null` if no data is stored under the slot.
30
- */ async loadCapsule(contractAddress, slot) {
31
- const dataBuffer = await this.#capsules.getAsync(dbSlotToKey(contractAddress, slot));
114
+ */ async loadCapsule(contractAddress, slot, jobId) {
115
+ const dataBuffer = await this.#getFromStage(jobId, dbSlotToKey(contractAddress, slot));
32
116
  if (!dataBuffer) {
33
117
  this.logger.trace(`Data not found for contract ${contractAddress.toString()} and slot ${slot.toString()}`);
34
118
  return null;
@@ -43,8 +127,9 @@ export class CapsuleStore {
43
127
  * Deletes data in the per-contract non-volatile database. Does nothing if no data was present.
44
128
  * @param contractAddress - The contract address under which the data is scoped.
45
129
  * @param slot - The slot in the database to delete.
46
- */ async deleteCapsule(contractAddress, slot) {
47
- await this.#capsules.delete(dbSlotToKey(contractAddress, slot));
130
+ */ deleteCapsule(contractAddress, slot, jobId) {
131
+ // When we commit this, we will interpret null as a deletion, so we'll propagate the delete to the KV store
132
+ this.#deleteOnStage(jobId, dbSlotToKey(contractAddress, slot));
48
133
  }
49
134
  /**
50
135
  * Copies a number of contiguous entries in the per-contract non-volatile database. This allows for efficient data
@@ -56,7 +141,11 @@ export class CapsuleStore {
56
141
  * @param srcSlot - The first slot to copy from.
57
142
  * @param dstSlot - The first slot to copy to.
58
143
  * @param numEntries - The number of entries to copy.
59
- */ copyCapsule(contractAddress, srcSlot, dstSlot, numEntries) {
144
+ */ copyCapsule(contractAddress, srcSlot, dstSlot, numEntries, jobId) {
145
+ // This transactional context gives us "copy atomicity":
146
+ // there shouldn't be concurrent writes to what's being copied here.
147
+ // Equally important: this in practice is expected to perform thousands of DB operations
148
+ // and not using a transaction here would heavily impact performance.
60
149
  return this.#store.transactionAsync(async ()=>{
61
150
  // In order to support overlapping source and destination regions, we need to check the relative positions of source
62
151
  // and destination. If destination is ahead of source, then by the time we overwrite source elements using forward
@@ -69,11 +158,11 @@ export class CapsuleStore {
69
158
  for (const i of indexes){
70
159
  const currentSrcSlot = dbSlotToKey(contractAddress, srcSlot.add(new Fr(i)));
71
160
  const currentDstSlot = dbSlotToKey(contractAddress, dstSlot.add(new Fr(i)));
72
- const toCopy = await this.#capsules.getAsync(currentSrcSlot);
161
+ const toCopy = await this.#getFromStage(jobId, currentSrcSlot);
73
162
  if (!toCopy) {
74
163
  throw new Error(`Attempted to copy empty slot ${currentSrcSlot} for contract ${contractAddress.toString()}`);
75
164
  }
76
- await this.#capsules.set(currentDstSlot, toCopy);
165
+ this.#setOnStage(jobId, currentDstSlot, toCopy);
77
166
  }
78
167
  });
79
168
  }
@@ -84,32 +173,42 @@ export class CapsuleStore {
84
173
  * @param contractAddress - The contract address that owns the capsule array
85
174
  * @param baseSlot - The slot where the array length is stored
86
175
  * @param content - Array of capsule data to append
87
- */ appendToCapsuleArray(contractAddress, baseSlot, content) {
176
+ */ appendToCapsuleArray(contractAddress, baseSlot, content, jobId) {
177
+ // We wrap this in a transaction to serialize concurrent calls from Promise.all.
178
+ // Without this, concurrent appends to the same array could race: both read length=0,
179
+ // both write at the same slots, one overwrites the other.
180
+ // Equally important: this in practice is expected to perform thousands of DB operations
181
+ // and not using a transaction here would heavily impact performance.
88
182
  return this.#store.transactionAsync(async ()=>{
89
183
  // Load current length, defaulting to 0 if not found
90
- const lengthData = await this.loadCapsule(contractAddress, baseSlot);
184
+ const lengthData = await this.loadCapsule(contractAddress, baseSlot, jobId);
91
185
  const currentLength = lengthData ? lengthData[0].toNumber() : 0;
92
186
  // Store each capsule at consecutive slots after baseSlot + 1 + currentLength
93
187
  for(let i = 0; i < content.length; i++){
94
188
  const nextSlot = arraySlot(baseSlot, currentLength + i);
95
- await this.storeCapsule(contractAddress, nextSlot, content[i]);
189
+ this.storeCapsule(contractAddress, nextSlot, content[i], jobId);
96
190
  }
97
191
  // Update length to include all new capsules
98
192
  const newLength = currentLength + content.length;
99
- await this.storeCapsule(contractAddress, baseSlot, [
193
+ this.storeCapsule(contractAddress, baseSlot, [
100
194
  new Fr(newLength)
101
- ]);
195
+ ], jobId);
102
196
  });
103
197
  }
104
- readCapsuleArray(contractAddress, baseSlot) {
198
+ readCapsuleArray(contractAddress, baseSlot, jobId) {
199
+ // I'm leaving this transactional context here though because I'm assuming this
200
+ // gives us "read array atomicity": there shouldn't be concurrent writes to what's being copied
201
+ // here.
202
+ // This is one point we should revisit in the future if we want to relax the concurrency
203
+ // of jobs: different calls running concurrently on the same contract may cause trouble.
105
204
  return this.#store.transactionAsync(async ()=>{
106
205
  // Load length, defaulting to 0 if not found
107
- const maybeLength = await this.loadCapsule(contractAddress, baseSlot);
206
+ const maybeLength = await this.loadCapsule(contractAddress, baseSlot, jobId);
108
207
  const length = maybeLength ? maybeLength[0].toBigInt() : 0n;
109
208
  const values = [];
110
209
  // Read each capsule at consecutive slots after baseSlot
111
210
  for(let i = 0; i < length; i++){
112
- const currentValue = await this.loadCapsule(contractAddress, arraySlot(baseSlot, i));
211
+ const currentValue = await this.loadCapsule(contractAddress, arraySlot(baseSlot, i), jobId);
113
212
  if (currentValue == undefined) {
114
213
  throw new Error(`Expected non-empty value at capsule array in base slot ${baseSlot} at index ${i} for contract ${contractAddress}`);
115
214
  }
@@ -118,22 +217,30 @@ export class CapsuleStore {
118
217
  return values;
119
218
  });
120
219
  }
121
- setCapsuleArray(contractAddress, baseSlot, content) {
220
+ setCapsuleArray(contractAddress, baseSlot, content, jobId) {
221
+ // This transactional context in theory isn't so critical now because we aren't
222
+ // writing to DB so if there's exceptions midway and it blows up, no visible impact
223
+ // to persistent storage will happen.
224
+ // I'm leaving this transactional context here though because I'm assuming this
225
+ // gives us "write array atomicity": there shouldn't be concurrent writes to what's being copied
226
+ // here.
227
+ // This is one point we should revisit in the future if we want to relax the concurrency
228
+ // of jobs: different calls running concurrently on the same contract may cause trouble.
122
229
  return this.#store.transactionAsync(async ()=>{
123
230
  // Load current length, defaulting to 0 if not found
124
- const maybeLength = await this.loadCapsule(contractAddress, baseSlot);
231
+ const maybeLength = await this.loadCapsule(contractAddress, baseSlot, jobId);
125
232
  const originalLength = maybeLength ? maybeLength[0].toNumber() : 0;
126
233
  // Set the new length
127
- await this.storeCapsule(contractAddress, baseSlot, [
234
+ this.storeCapsule(contractAddress, baseSlot, [
128
235
  new Fr(content.length)
129
- ]);
236
+ ], jobId);
130
237
  // Store the new content, possibly overwriting existing values
131
238
  for(let i = 0; i < content.length; i++){
132
- await this.storeCapsule(contractAddress, arraySlot(baseSlot, i), content[i]);
239
+ this.storeCapsule(contractAddress, arraySlot(baseSlot, i), content[i], jobId);
133
240
  }
134
241
  // Clear any stragglers
135
242
  for(let i = content.length; i < originalLength; i++){
136
- await this.deleteCapsule(contractAddress, arraySlot(baseSlot, i));
243
+ this.deleteCapsule(contractAddress, arraySlot(baseSlot, i), jobId);
137
244
  }
138
245
  });
139
246
  }
@@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29udHJhY3Rfc3RvcmUuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9zdG9yYWdlL2NvbnRyYWN0X3N0b3JlL2NvbnRyYWN0X3N0b3JlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLG9CQUFvQixFQUFFLE1BQU0sa0JBQWtCLENBQUM7QUFDN0QsT0FBTyxLQUFLLEVBQUUsRUFBRSxFQUFFLE1BQU0sZ0NBQWdDLENBQUM7QUFFekQsT0FBTyxLQUFLLEVBQUUsaUJBQWlCLEVBQUUsTUFBTSx5QkFBeUIsQ0FBQztBQUNqRSxPQUFPLEtBQUssRUFBRSxpQkFBaUIsRUFBaUIsTUFBTSxpQkFBaUIsQ0FBQztBQUV4RSxPQUFPLEVBQ0wsS0FBSyxnQkFBZ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E,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';
@@ -14,20 +13,23 @@ import { PrivateFunctionsTree } from './private_functions_tree.js';
14
13
  /** Map from contract class id to private function tree. */ // TODO: Update it to be LRU cache so that it doesn't keep all the data all the time.
15
14
  #privateFunctionTrees = new Map();
16
15
  /** Map from contract address to contract class id */ #contractClassIdMap = new Map();
16
+ #store;
17
17
  #contractArtifacts;
18
18
  #contractInstances;
19
19
  constructor(store){
20
+ this.#store = store;
20
21
  this.#contractArtifacts = store.openMap('contract_artifacts');
21
22
  this.#contractInstances = store.openMap('contracts_instances');
22
23
  }
23
24
  // Setters
24
25
  async addContractArtifact(id, contract) {
26
+ // Validation outside transactionAsync - these are not DB operations
25
27
  const privateFunctions = contract.functions.filter((functionArtifact)=>functionArtifact.functionType === FunctionType.PRIVATE);
26
28
  const privateSelectors = await Promise.all(privateFunctions.map(async (privateFunctionArtifact)=>(await FunctionSelector.fromNameAndParameters(privateFunctionArtifact.name, privateFunctionArtifact.parameters)).toString()));
27
29
  if (privateSelectors.length !== new Set(privateSelectors).size) {
28
30
  throw new Error('Repeated function selectors of private functions');
29
31
  }
30
- await this.#contractArtifacts.set(id.toString(), contractArtifactToBuffer(contract));
32
+ await this.#store.transactionAsync(()=>this.#contractArtifacts.set(id.toString(), contractArtifactToBuffer(contract)));
31
33
  }
32
34
  async addContractInstance(contract) {
33
35
  this.#contractClassIdMap.set(contract.address.toString(), contract.currentContractClassId);
@@ -69,18 +71,24 @@ import { PrivateFunctionsTree } from './private_functions_tree.js';
69
71
  return contractClassId && this.getContractArtifact(contractClassId);
70
72
  }
71
73
  // Public getters
72
- async getContractsAddresses() {
73
- const keys = await toArray(this.#contractInstances.keysAsync());
74
- return keys.map(AztecAddress.fromString);
75
- }
76
- /** Returns a contract instance for a given address. Throws if not found. */ async getContractInstance(contractAddress) {
77
- const contract = await this.#contractInstances.getAsync(contractAddress.toString());
78
- return contract && SerializableContractInstance.fromBuffer(contract).withAddress(contractAddress);
79
- }
80
- async getContractArtifact(contractClassId) {
81
- const contract = await this.#contractArtifacts.getAsync(contractClassId.toString());
82
- // TODO(@spalladino): AztecAsyncMap lies and returns Uint8Arrays instead of Buffers, hence the extra Buffer.from.
83
- return contract && contractArtifactFromBuffer(Buffer.from(contract));
74
+ getContractsAddresses() {
75
+ return this.#store.transactionAsync(async ()=>{
76
+ const keys = await toArray(this.#contractInstances.keysAsync());
77
+ return keys.map(AztecAddress.fromString);
78
+ });
79
+ }
80
+ /** Returns a contract instance for a given address. Throws if not found. */ getContractInstance(contractAddress) {
81
+ return this.#store.transactionAsync(async ()=>{
82
+ const contract = await this.#contractInstances.getAsync(contractAddress.toString());
83
+ return contract && SerializableContractInstance.fromBuffer(contract).withAddress(contractAddress);
84
+ });
85
+ }
86
+ getContractArtifact(contractClassId) {
87
+ return this.#store.transactionAsync(async ()=>{
88
+ const contract = await this.#contractArtifacts.getAsync(contractClassId.toString());
89
+ // TODO(@spalladino): AztecAsyncMap lies and returns Uint8Arrays instead of Buffers, hence the extra Buffer.from.
90
+ return contract && contractArtifactFromBuffer(Buffer.from(contract));
91
+ });
84
92
  }
85
93
  /** Returns a contract class for a given class id. Throws if not found. */ async getContractClass(contractClassId) {
86
94
  const artifact = await this.getContractArtifact(contractClassId);
@@ -222,15 +230,4 @@ import { PrivateFunctionsTree } from './private_functions_tree.js';
222
230
  returnTypes: functionDao.returnTypes
223
231
  };
224
232
  }
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
233
  }
@@ -1,2 +1,2 @@
1
- export declare const PXE_DATA_SCHEMA_VERSION = 2;
1
+ export declare const PXE_DATA_SCHEMA_VERSION = 3;
2
2
  //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWV0YWRhdGEuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9zdG9yYWdlL21ldGFkYXRhLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLGVBQU8sTUFBTSx1QkFBdUIsSUFBSSxDQUFDIn0=
@@ -1 +1 @@
1
- export const PXE_DATA_SCHEMA_VERSION = 2;
1
+ export const PXE_DATA_SCHEMA_VERSION = 3;
@@ -1,84 +1,83 @@
1
- import type { Fr } from '@aztec/foundation/curves/bn254';
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 { NoteDao } from '@aztec/stdlib/note';
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
- * and performs rollback handling in the case of a reorg.
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
- private constructor();
15
+ readonly storeName: string;
16
+ constructor(store: AztecAsyncKVStore);
16
17
  /**
17
- * Creates and initializes a new NoteStore instance.
18
+ * Adds multiple notes to the notes store under the specified scope.
18
19
  *
19
- * This factory method creates a NoteStore and restores any existing
20
- * scope-specific indexes from the database.
20
+ * Notes are stored using their siloedNullifier as the key, which provides uniqueness. Each note is indexed by
21
+ * multiple criteria for efficient retrieval.
21
22
  *
22
- * @param store - The key-value store to use for persistence
23
- * @returns Promise resolving to a fully initialized NoteStore instance
23
+ * @param notes - Notes to store
24
+ * @param scope - The scope (user/account) under which to store the notes
25
+ * @param jobId - The job context for staged writes
24
26
  */
25
- static create(store: AztecAsyncKVStore): Promise<NoteStore>;
27
+ addNotes(notes: NoteDao[], scope: AztecAddress, jobId: string): Promise<void[]>;
26
28
  /**
27
- * Adds a new scope to the note data provider.
29
+ * Retrieves notes based on the provided filter criteria.
28
30
  *
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
+ * This method queries both active and optionally nullified notes based on the filter parameters.
31
32
  *
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
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.
36
+ * @returns Filtered and deduplicated notes (a note might be present in multiple scopes - we ensure it is only
37
+ * returned once if this is the case)
38
+ * @throws If filtering by an empty scopes array. Scopes have to be set to undefined or to a non-empty array.
34
39
  */
35
- addScope(scope: AztecAddress): Promise<boolean>;
40
+ getNotes(filter: NotesFilter, jobId: string): Promise<NoteDao[]>;
36
41
  /**
37
- * Adds multiple notes to the data provider under the specified scope.
42
+ * Transitions notes from "active" to "nullified" state.
38
43
  *
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.
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.
42
46
  *
43
- * @param notes - Notes to store
44
- * @param scope - The scope (user/account) under which to store the notes
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.
50
+ *
51
+ * @param nullifiers - Array of nullifiers with their block numbers to process
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
45
55
  */
46
- addNotes(notes: NoteDao[], scope: AztecAddress): Promise<void>;
56
+ applyNullifiers(nullifiers: DataInBlock<Fr>[], jobId: string): Promise<NoteDao[]>;
47
57
  /**
48
58
  * Synchronizes notes and nullifiers to a specific block number.
49
59
  *
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.
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.
53
65
  *
54
66
  * @param blockNumber - The new chain tip after a reorg
55
67
  * @param synchedBlockNumber - The block number up to which PXE managed to sync before the reorg happened.
56
68
  */
57
- rollbackNotesAndNullifiers(blockNumber: number, synchedBlockNumber: number): Promise<void>;
69
+ rollback(blockNumber: number, synchedBlockNumber: number): Promise<void>;
58
70
  /**
59
- * Retrieves notes based on the provided filter criteria.
60
- *
61
- * This method queries both active and optionally nullified notes based on the filter
62
- * parameters.
71
+ * Commits in memory job data to persistent storage.
63
72
  *
64
- * @param filter - Filter criteria including contractAddress (required), and optional
65
- * owner, storageSlot, status, scopes, and siloedNullifier.
66
- * @returns Filtered and deduplicated notes (a note might be present in multiple scopes - we ensure it is only
67
- * returned once if this is the case)
68
- * @throws If filtering by an empty scopes array. Scopes have to be set to undefined or to a non-empty array.
69
- */
70
- getNotes(filter: NotesFilter): Promise<NoteDao[]>;
71
- /**
72
- * Transitions notes from "active" to "nullified" state.
73
+ * Called by JobCoordinator when a job completes successfully.
73
74
  *
74
- * This operation processes a batch of nullifiers to mark the corresponding notes
75
- * as spent/nullified. The operation is atomic - if any nullifier is not found,
76
- * the entire operation fails and no notes are modified.
75
+ * Note: JobCoordinator wraps all commits in a single transaction, so we don't need our own transactionAsync here
76
+ * (and using one would throw on IndexedDB as it does not support nested txs).
77
77
  *
78
- * @param nullifiers - Array of nullifiers with their block numbers to process
79
- * @returns Promise resolving to array of nullified NoteDao objects
80
- * @throws Error if any nullifier is not found in the active notes
78
+ * @param jobId - The jobId identifying which staged data to commit
81
79
  */
82
- applyNullifiers(nullifiers: DataInBlock<Fr>[]): Promise<NoteDao[]>;
80
+ commit(jobId: string): Promise<void>;
81
+ discardStaged(jobId: string): Promise<void>;
83
82
  }
84
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibm90ZV9zdG9yZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL3N0b3JhZ2Uvbm90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