@aztec/pxe 0.0.1-commit.6230efd → 0.0.1-commit.6b90f3f5

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 (233) hide show
  1. package/dest/bin/check_oracle_version.js +1 -1
  2. package/dest/block_synchronizer/block_synchronizer.d.ts +11 -5
  3. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
  4. package/dest/block_synchronizer/block_synchronizer.js +68 -20
  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/config/package_info.js +1 -1
  9. package/dest/contract_function_simulator/benchmarked_node.d.ts +9 -0
  10. package/dest/contract_function_simulator/benchmarked_node.d.ts.map +1 -0
  11. package/dest/contract_function_simulator/benchmarked_node.js +77 -0
  12. package/dest/contract_function_simulator/contract_function_simulator.d.ts +9 -12
  13. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  14. package/dest/contract_function_simulator/contract_function_simulator.js +37 -28
  15. package/dest/contract_function_simulator/execution_note_cache.d.ts +18 -9
  16. package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -1
  17. package/dest/contract_function_simulator/execution_note_cache.js +45 -28
  18. package/dest/contract_function_simulator/index.d.ts +2 -2
  19. package/dest/contract_function_simulator/index.d.ts.map +1 -1
  20. package/dest/contract_function_simulator/index.js +1 -1
  21. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +4 -3
  22. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
  23. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +6 -3
  24. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +1 -1
  25. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +1 -1
  26. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts +4 -10
  27. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts.map +1 -1
  28. package/dest/contract_function_simulator/noir-structs/utility_context.js +7 -18
  29. package/dest/contract_function_simulator/oracle/interfaces.d.ts +15 -11
  30. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  31. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts +3 -1
  32. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts.map +1 -1
  33. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts +6 -6
  34. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts.map +1 -1
  35. package/dest/contract_function_simulator/oracle/note_packing_utils.js +8 -8
  36. package/dest/contract_function_simulator/oracle/oracle.d.ts +10 -8
  37. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  38. package/dest/contract_function_simulator/oracle/oracle.js +43 -32
  39. package/dest/contract_function_simulator/oracle/private_execution.d.ts +2 -26
  40. package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
  41. package/dest/contract_function_simulator/oracle/private_execution.js +1 -37
  42. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +11 -18
  43. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  44. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +23 -39
  45. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +27 -19
  46. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  47. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +73 -75
  48. package/dest/contract_sync/index.d.ts +23 -0
  49. package/dest/contract_sync/index.d.ts.map +1 -0
  50. package/dest/contract_sync/index.js +54 -0
  51. package/dest/debug/pxe_debug_utils.d.ts +16 -6
  52. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  53. package/dest/debug/pxe_debug_utils.js +20 -10
  54. package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
  55. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  56. package/dest/entrypoints/client/bundle/utils.js +22 -7
  57. package/dest/entrypoints/client/lazy/utils.d.ts +2 -2
  58. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  59. package/dest/entrypoints/client/lazy/utils.js +23 -8
  60. package/dest/entrypoints/pxe_creation_options.d.ts +5 -3
  61. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  62. package/dest/entrypoints/server/index.d.ts +3 -1
  63. package/dest/entrypoints/server/index.d.ts.map +1 -1
  64. package/dest/entrypoints/server/index.js +2 -0
  65. package/dest/entrypoints/server/utils.d.ts +1 -1
  66. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  67. package/dest/entrypoints/server/utils.js +30 -15
  68. package/dest/events/event_service.d.ts +6 -6
  69. package/dest/events/event_service.d.ts.map +1 -1
  70. package/dest/events/event_service.js +19 -22
  71. package/dest/events/private_event_filter_validator.d.ts +5 -5
  72. package/dest/events/private_event_filter_validator.d.ts.map +1 -1
  73. package/dest/events/private_event_filter_validator.js +5 -6
  74. package/dest/job_coordinator/job_coordinator.d.ts +75 -0
  75. package/dest/job_coordinator/job_coordinator.d.ts.map +1 -0
  76. package/dest/job_coordinator/job_coordinator.js +94 -0
  77. package/dest/logs/log_service.d.ts +6 -4
  78. package/dest/logs/log_service.d.ts.map +1 -1
  79. package/dest/logs/log_service.js +21 -16
  80. package/dest/notes/note_service.d.ts +7 -7
  81. package/dest/notes/note_service.d.ts.map +1 -1
  82. package/dest/notes/note_service.js +31 -36
  83. package/dest/oracle_version.d.ts +3 -3
  84. package/dest/oracle_version.d.ts.map +1 -1
  85. package/dest/oracle_version.js +4 -3
  86. package/dest/private_kernel/hints/index.d.ts +2 -2
  87. package/dest/private_kernel/hints/index.d.ts.map +1 -1
  88. package/dest/private_kernel/hints/index.js +1 -1
  89. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +28 -0
  90. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -0
  91. package/dest/private_kernel/hints/{build_private_kernel_reset_private_inputs.js → private_kernel_reset_private_inputs_builder.js} +13 -7
  92. package/dest/private_kernel/private_kernel_execution_prover.d.ts +3 -2
  93. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  94. package/dest/private_kernel/private_kernel_execution_prover.js +6 -7
  95. package/dest/private_kernel/private_kernel_oracle.d.ts +24 -28
  96. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  97. package/dest/private_kernel/private_kernel_oracle.js +90 -2
  98. package/dest/pxe.d.ts +8 -36
  99. package/dest/pxe.d.ts.map +1 -1
  100. package/dest/pxe.js +75 -96
  101. package/dest/storage/address_store/address_store.d.ts +1 -1
  102. package/dest/storage/address_store/address_store.d.ts.map +1 -1
  103. package/dest/storage/address_store/address_store.js +12 -11
  104. package/dest/storage/anchor_block_store/anchor_block_store.d.ts +9 -1
  105. package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -1
  106. package/dest/storage/anchor_block_store/anchor_block_store.js +8 -1
  107. package/dest/storage/capsule_store/capsule_store.d.ts +24 -9
  108. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
  109. package/dest/storage/capsule_store/capsule_store.js +130 -23
  110. package/dest/storage/contract_store/contract_store.d.ts +1 -2
  111. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  112. package/dest/storage/contract_store/contract_store.js +22 -25
  113. package/dest/storage/metadata.d.ts +1 -1
  114. package/dest/storage/metadata.js +1 -1
  115. package/dest/storage/note_store/note_store.d.ts +51 -52
  116. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  117. package/dest/storage/note_store/note_store.js +282 -263
  118. package/dest/storage/note_store/stored_note.d.ts +16 -0
  119. package/dest/storage/note_store/stored_note.d.ts.map +1 -0
  120. package/dest/storage/note_store/stored_note.js +43 -0
  121. package/dest/storage/private_event_store/private_event_store.d.ts +47 -7
  122. package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
  123. package/dest/storage/private_event_store/private_event_store.js +231 -73
  124. package/dest/storage/private_event_store/stored_private_event.d.ts +23 -0
  125. package/dest/storage/private_event_store/stored_private_event.d.ts.map +1 -0
  126. package/dest/storage/private_event_store/stored_private_event.js +56 -0
  127. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +15 -8
  128. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
  129. package/dest/storage/tagging_store/recipient_tagging_store.js +88 -19
  130. package/dest/storage/tagging_store/sender_address_book_store.d.ts +1 -1
  131. package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +1 -1
  132. package/dest/storage/tagging_store/sender_address_book_store.js +20 -14
  133. package/dest/storage/tagging_store/sender_tagging_store.d.ts +19 -9
  134. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  135. package/dest/storage/tagging_store/sender_tagging_store.js +253 -101
  136. package/dest/tagging/constants.d.ts +2 -0
  137. package/dest/tagging/constants.d.ts.map +1 -0
  138. package/dest/tagging/constants.js +10 -0
  139. package/dest/tagging/get_all_logs_by_tags.d.ts +24 -0
  140. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -0
  141. package/dest/tagging/get_all_logs_by_tags.js +46 -0
  142. package/dest/tagging/index.d.ts +3 -2
  143. package/dest/tagging/index.d.ts.map +1 -1
  144. package/dest/tagging/index.js +2 -10
  145. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +3 -2
  146. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
  147. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +8 -8
  148. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +3 -2
  149. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
  150. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +5 -2
  151. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +3 -2
  152. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  153. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +8 -8
  154. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +1 -1
  155. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
  156. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +5 -8
  157. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +5 -2
  158. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  159. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +10 -5
  160. package/package.json +18 -18
  161. package/src/bin/check_oracle_version.ts +1 -0
  162. package/src/block_synchronizer/block_synchronizer.ts +87 -32
  163. package/src/config/index.ts +14 -0
  164. package/src/config/package_info.ts +1 -1
  165. package/src/contract_function_simulator/benchmarked_node.ts +103 -0
  166. package/src/contract_function_simulator/contract_function_simulator.ts +43 -32
  167. package/src/contract_function_simulator/execution_note_cache.ts +44 -25
  168. package/src/contract_function_simulator/index.ts +1 -1
  169. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +5 -1
  170. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +1 -1
  171. package/src/contract_function_simulator/noir-structs/utility_context.ts +6 -25
  172. package/src/contract_function_simulator/oracle/interfaces.ts +20 -10
  173. package/src/contract_function_simulator/oracle/note_packing_utils.ts +10 -10
  174. package/src/contract_function_simulator/oracle/oracle.ts +56 -41
  175. package/src/contract_function_simulator/oracle/private_execution.ts +1 -69
  176. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +39 -48
  177. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +95 -81
  178. package/src/contract_sync/index.ts +98 -0
  179. package/src/debug/pxe_debug_utils.ts +26 -11
  180. package/src/entrypoints/client/bundle/utils.ts +15 -16
  181. package/src/entrypoints/client/lazy/utils.ts +16 -17
  182. package/src/entrypoints/pxe_creation_options.ts +4 -2
  183. package/src/entrypoints/server/index.ts +2 -0
  184. package/src/entrypoints/server/utils.ts +26 -34
  185. package/src/events/event_service.ts +19 -25
  186. package/src/events/private_event_filter_validator.ts +3 -5
  187. package/src/job_coordinator/job_coordinator.ts +150 -0
  188. package/src/logs/log_service.ts +32 -14
  189. package/src/notes/note_service.ts +38 -43
  190. package/src/oracle_version.ts +4 -3
  191. package/src/private_kernel/hints/index.ts +1 -1
  192. package/src/private_kernel/hints/{build_private_kernel_reset_private_inputs.ts → private_kernel_reset_private_inputs_builder.ts} +33 -22
  193. package/src/private_kernel/private_kernel_execution_prover.ts +9 -8
  194. package/src/private_kernel/private_kernel_oracle.ts +116 -36
  195. package/src/pxe.ts +135 -131
  196. package/src/storage/address_store/address_store.ts +15 -15
  197. package/src/storage/anchor_block_store/anchor_block_store.ts +8 -0
  198. package/src/storage/capsule_store/capsule_store.ts +159 -23
  199. package/src/storage/contract_store/contract_store.ts +22 -31
  200. package/src/storage/metadata.ts +1 -1
  201. package/src/storage/note_store/note_store.ts +317 -318
  202. package/src/storage/note_store/stored_note.ts +48 -0
  203. package/src/storage/private_event_store/private_event_store.ts +301 -79
  204. package/src/storage/private_event_store/stored_private_event.ts +73 -0
  205. package/src/storage/tagging_store/recipient_tagging_store.ts +106 -20
  206. package/src/storage/tagging_store/sender_address_book_store.ts +20 -14
  207. package/src/storage/tagging_store/sender_tagging_store.ts +294 -109
  208. package/src/tagging/constants.ts +10 -0
  209. package/src/tagging/get_all_logs_by_tags.ts +68 -0
  210. package/src/tagging/index.ts +2 -11
  211. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +21 -7
  212. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +7 -1
  213. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +10 -7
  214. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +5 -13
  215. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +16 -4
  216. package/dest/contract_function_simulator/proxied_node.d.ts +0 -9
  217. package/dest/contract_function_simulator/proxied_node.d.ts.map +0 -1
  218. package/dest/contract_function_simulator/proxied_node.js +0 -27
  219. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts +0 -28
  220. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts.map +0 -1
  221. package/dest/private_kernel/private_kernel_oracle_impl.d.ts +0 -46
  222. package/dest/private_kernel/private_kernel_oracle_impl.d.ts.map +0 -1
  223. package/dest/private_kernel/private_kernel_oracle_impl.js +0 -86
  224. package/dest/public_storage/public_storage_service.d.ts +0 -24
  225. package/dest/public_storage/public_storage_service.d.ts.map +0 -1
  226. package/dest/public_storage/public_storage_service.js +0 -26
  227. package/dest/tree_membership/tree_membership_service.d.ts +0 -52
  228. package/dest/tree_membership/tree_membership_service.d.ts.map +0 -1
  229. package/dest/tree_membership/tree_membership_service.js +0 -84
  230. package/src/contract_function_simulator/proxied_node.ts +0 -33
  231. package/src/private_kernel/private_kernel_oracle_impl.ts +0 -133
  232. package/src/public_storage/public_storage_service.ts +0 -33
  233. package/src/tree_membership/tree_membership_service.ts +0 -112
package/src/pxe.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { PrivateEventFilter } from '@aztec/aztec.js/wallet';
2
+ import { BlockNumber } from '@aztec/foundation/branded-types';
2
3
  import { Fr } from '@aztec/foundation/curves/bn254';
3
- import { type Logger, createLogger } from '@aztec/foundation/log';
4
+ import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
4
5
  import { SerialQueue } from '@aztec/foundation/queue';
5
6
  import { Timer } from '@aztec/foundation/timer';
6
7
  import { KeyStore } from '@aztec/key-store';
@@ -19,14 +20,12 @@ import type { AuthWitness } from '@aztec/stdlib/auth-witness';
19
20
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
20
21
  import {
21
22
  CompleteAddress,
22
- type ContractClassWithId,
23
23
  type ContractInstanceWithAddress,
24
24
  type PartialAddress,
25
25
  computeContractAddressFromInstance,
26
26
  getContractClassFromArtifact,
27
27
  } from '@aztec/stdlib/contract';
28
28
  import { SimulationError } from '@aztec/stdlib/errors';
29
- import { computeProtocolNullifier, siloNullifier } from '@aztec/stdlib/hash';
30
29
  import type { AztecNode, PrivateKernelProver } from '@aztec/stdlib/interfaces/client';
31
30
  import type {
32
31
  PrivateExecutionStep,
@@ -54,20 +53,22 @@ import { inspect } from 'util';
54
53
 
55
54
  import { BlockSynchronizer } from './block_synchronizer/index.js';
56
55
  import type { PXEConfig } from './config/index.js';
56
+ import { BenchmarkedNodeFactory } from './contract_function_simulator/benchmarked_node.js';
57
57
  import {
58
58
  ContractFunctionSimulator,
59
59
  generateSimulatedProvingResult,
60
60
  } from './contract_function_simulator/contract_function_simulator.js';
61
- import { readCurrentClassId } from './contract_function_simulator/oracle/private_execution.js';
62
61
  import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
62
+ import { ensureContractSynced, readCurrentClassId } from './contract_sync/index.js';
63
63
  import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
64
64
  import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
65
65
  import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
66
+ import { JobCoordinator } from './job_coordinator/job_coordinator.js';
66
67
  import {
67
68
  PrivateKernelExecutionProver,
68
69
  type PrivateKernelExecutionProverConfig,
69
70
  } from './private_kernel/private_kernel_execution_prover.js';
70
- import { PrivateKernelOracleImpl } from './private_kernel/private_kernel_oracle_impl.js';
71
+ import { PrivateKernelOracle } from './private_kernel/private_kernel_oracle.js';
71
72
  import { AddressStore } from './storage/address_store/address_store.js';
72
73
  import { AnchorBlockStore } from './storage/anchor_block_store/anchor_block_store.js';
73
74
  import { CapsuleStore } from './storage/capsule_store/capsule_store.js';
@@ -107,6 +108,7 @@ export class PXE {
107
108
  private protocolContractsProvider: ProtocolContractsProvider,
108
109
  private log: Logger,
109
110
  private jobQueue: SerialQueue,
111
+ private jobCoordinator: JobCoordinator,
110
112
  public debug: PXEDebugUtils,
111
113
  ) {}
112
114
 
@@ -126,6 +128,10 @@ export class PXE {
126
128
  config: PXEConfig,
127
129
  loggerOrSuffix?: string | Logger,
128
130
  ) {
131
+ // Extract bindings from the logger, or use empty bindings if a string suffix is provided.
132
+ const bindings: LoggerBindings | undefined =
133
+ loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
134
+
129
135
  const log =
130
136
  !loggerOrSuffix || typeof loggerOrSuffix === 'string'
131
137
  ? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
@@ -135,7 +141,7 @@ export class PXE {
135
141
  const addressStore = new AddressStore(store);
136
142
  const privateEventStore = new PrivateEventStore(store);
137
143
  const contractStore = new ContractStore(store);
138
- const noteStore = await NoteStore.create(store);
144
+ const noteStore = new NoteStore(store);
139
145
  const anchorBlockStore = new AnchorBlockStore(store);
140
146
  const senderTaggingStore = new SenderTaggingStore(store);
141
147
  const senderAddressBookStore = new SenderAddressBookStore(store);
@@ -143,9 +149,27 @@ export class PXE {
143
149
  const capsuleStore = new CapsuleStore(store);
144
150
  const keyStore = new KeyStore(store);
145
151
  const tipsStore = new L2TipsKVStore(store, 'pxe');
146
- const synchronizer = new BlockSynchronizer(node, anchorBlockStore, noteStore, tipsStore, config, loggerOrSuffix);
152
+ const synchronizer = new BlockSynchronizer(
153
+ node,
154
+ store,
155
+ anchorBlockStore,
156
+ noteStore,
157
+ privateEventStore,
158
+ tipsStore,
159
+ config,
160
+ bindings,
161
+ );
162
+
163
+ const jobCoordinator = new JobCoordinator(store, bindings);
164
+ jobCoordinator.registerStores([
165
+ capsuleStore,
166
+ senderTaggingStore,
167
+ recipientTaggingStore,
168
+ privateEventStore,
169
+ noteStore,
170
+ ]);
147
171
 
148
- const debugUtils = new PXEDebugUtils(contractStore, noteStore);
172
+ const debugUtils = new PXEDebugUtils(contractStore, noteStore, synchronizer, anchorBlockStore);
149
173
 
150
174
  const jobQueue = new SerialQueue();
151
175
 
@@ -168,10 +192,11 @@ export class PXE {
168
192
  protocolContractsProvider,
169
193
  log,
170
194
  jobQueue,
195
+ jobCoordinator,
171
196
  debugUtils,
172
197
  );
173
198
 
174
- debugUtils.setPXE(pxe);
199
+ debugUtils.setPXE(pxe, pxe.#putInJobQueue.bind(pxe));
175
200
 
176
201
  pxe.jobQueue.start();
177
202
 
@@ -191,8 +216,7 @@ export class PXE {
191
216
  this.noteStore,
192
217
  this.keyStore,
193
218
  this.addressStore,
194
- this.node,
195
- this.anchorBlockStore,
219
+ BenchmarkedNodeFactory.create(this.node),
196
220
  this.senderTaggingStore,
197
221
  this.recipientTaggingStore,
198
222
  this.senderAddressBookStore,
@@ -222,7 +246,7 @@ export class PXE {
222
246
  *
223
247
  * Useful for tasks that cannot run concurrently, such as contract function simulation.
224
248
  */
225
- #putInJobQueue<T>(fn: () => Promise<T>): Promise<T> {
249
+ #putInJobQueue<T>(fn: (jobId: string) => Promise<T>): Promise<T> {
226
250
  // TODO(#12636): relax the conditions under which we forbid concurrency.
227
251
  if (this.jobQueue.length() != 0) {
228
252
  this.log.warn(
@@ -230,7 +254,22 @@ export class PXE {
230
254
  );
231
255
  }
232
256
 
233
- return this.jobQueue.put(fn);
257
+ return this.jobQueue.put(async () => {
258
+ const jobId = this.jobCoordinator.beginJob();
259
+ this.log.verbose(`Beginning job ${jobId}`);
260
+
261
+ try {
262
+ const result = await fn(jobId);
263
+ this.log.verbose(`Committing job ${jobId}`);
264
+
265
+ await this.jobCoordinator.commitJob(jobId);
266
+ return result;
267
+ } catch (err) {
268
+ this.log.verbose(`Aborting job ${jobId}`);
269
+ await this.jobCoordinator.abortJob(jobId);
270
+ throw err;
271
+ }
272
+ });
234
273
  }
235
274
 
236
275
  async #registerProtocolContracts() {
@@ -245,31 +284,28 @@ export class PXE {
245
284
  this.log.verbose(`Registered protocol contracts in pxe`, registered);
246
285
  }
247
286
 
248
- async #isContractClassPubliclyRegistered(id: Fr): Promise<boolean> {
249
- return !!(await this.node.getContractClass(id));
250
- }
251
-
252
- async #isContractPublished(address: AztecAddress): Promise<boolean> {
253
- return !!(await this.node.getContract(address));
254
- }
255
-
256
- async #isContractInitialized(address: AztecAddress): Promise<boolean> {
257
- const initNullifier = await siloNullifier(address, address.toField());
258
- return !!(await this.node.getNullifierMembershipWitness('latest', initNullifier));
259
- }
260
-
261
287
  // Executes the entrypoint private function, as well as all nested private
262
288
  // functions that might arise.
263
289
  async #executePrivate(
264
290
  contractFunctionSimulator: ContractFunctionSimulator,
265
291
  txRequest: TxExecutionRequest,
266
- scopes?: AztecAddress[],
292
+ scopes: AztecAddress[] | undefined,
293
+ jobId: string,
267
294
  ): Promise<PrivateExecutionResult> {
268
295
  const { origin: contractAddress, functionSelector } = txRequest;
269
296
 
270
297
  try {
271
298
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
272
299
 
300
+ await ensureContractSynced(
301
+ contractAddress,
302
+ functionSelector,
303
+ privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
304
+ this.node,
305
+ this.contractStore,
306
+ anchorBlockHeader,
307
+ );
308
+
273
309
  const result = await contractFunctionSimulator.run(
274
310
  txRequest,
275
311
  contractAddress,
@@ -280,6 +316,7 @@ export class PXE {
280
316
  // contract entrypoint
281
317
  undefined, // senderForTags
282
318
  scopes,
319
+ jobId,
283
320
  );
284
321
  this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
285
322
  return result;
@@ -298,17 +335,19 @@ export class PXE {
298
335
  * @param authWitnesses - Authentication witnesses required for the function call.
299
336
  * @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
300
337
  * accounts if not specified.
338
+ * @param jobId - The job ID for staged writes.
301
339
  * @returns The simulation result containing the outputs of the utility function.
302
340
  */
303
341
  async #simulateUtility(
304
342
  contractFunctionSimulator: ContractFunctionSimulator,
305
343
  call: FunctionCall,
306
- authWitnesses?: AuthWitness[],
307
- scopes?: AztecAddress[],
344
+ authWitnesses: AuthWitness[] | undefined,
345
+ scopes: AztecAddress[] | undefined,
346
+ jobId: string,
308
347
  ) {
309
348
  try {
310
349
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
311
- return contractFunctionSimulator.runUtility(call, authWitnesses ?? [], anchorBlockHeader, scopes);
350
+ return contractFunctionSimulator.runUtility(call, authWitnesses ?? [], anchorBlockHeader, scopes, jobId);
312
351
  } catch (err) {
313
352
  if (err instanceof SimulationError) {
314
353
  await enrichSimulationError(err, this.contractStore, this.log);
@@ -361,14 +400,15 @@ export class PXE {
361
400
  privateExecutionResult: PrivateExecutionResult,
362
401
  config: PrivateKernelExecutionProverConfig,
363
402
  ): Promise<PrivateKernelExecutionProofOutput<PrivateKernelTailCircuitPublicInputs>> {
364
- const simulationAnchorBlock = privateExecutionResult.getSimulationAnchorBlockNumber();
365
- const kernelOracle = new PrivateKernelOracleImpl(
366
- this.contractStore,
367
- this.keyStore,
368
- this.node,
369
- simulationAnchorBlock,
403
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
404
+ const anchorBlockHash = await anchorBlockHeader.hash();
405
+ const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHash);
406
+ const kernelTraceProver = new PrivateKernelExecutionProver(
407
+ kernelOracle,
408
+ proofCreator,
409
+ !this.proverEnabled,
410
+ this.log.getBindings(),
370
411
  );
371
- const kernelTraceProver = new PrivateKernelExecutionProver(kernelOracle, proofCreator, !this.proverEnabled);
372
412
  this.log.debug(`Executing kernel trace prover (${JSON.stringify(config)})...`);
373
413
  return await kernelTraceProver.proveWithKernels(txExecutionRequest.toTxRequest(), privateExecutionResult, config);
374
414
  }
@@ -380,66 +420,12 @@ export class PXE {
380
420
  }
381
421
 
382
422
  /**
383
- * Returns the contract class metadata given a contract class id.
384
- * The metadata consists of its contract class, whether it has been publicly registered, and its artifact.
385
- * @remark - it queries the node to check whether the contract class with the given id has been publicly registered.
386
- * @param id - Identifier of the class.
387
- * @param includeArtifact - Identifier of the class.
388
- * @returns - It returns the contract class metadata, with the artifact field being optional, and will only be returned if true is passed in
389
- * for `includeArtifact`
390
- * TODO(@spalladino): The PXE actually holds artifacts and not classes, what should we return? Also,
391
- * should the pxe query the node for contract public info, and merge it with its own definitions?
392
- * TODO(@spalladino): This method is strictly needed to decide whether to publicly register a class or not
393
- * during a public deployment. We probably want a nicer and more general API for this, but it'll have to
394
- * do for the time being.
423
+ * Returns the contract artifact for a given contract class id, if it's registered in the PXE.
424
+ * @param id - Identifier of the contract class.
425
+ * @returns The contract artifact if found, undefined otherwise.
395
426
  */
396
- public async getContractClassMetadata(
397
- id: Fr,
398
- includeArtifact: boolean = false,
399
- ): Promise<{
400
- contractClass: ContractClassWithId | undefined;
401
- isContractClassPubliclyRegistered: boolean;
402
- artifact: ContractArtifact | undefined;
403
- }> {
404
- const artifact = await this.contractStore.getContractArtifact(id);
405
- if (!artifact) {
406
- this.log.warn(`No artifact found for contract class ${id.toString()} when looking for its metadata`);
407
- }
408
-
409
- return {
410
- contractClass: artifact && (await getContractClassFromArtifact(artifact)),
411
- isContractClassPubliclyRegistered: await this.#isContractClassPubliclyRegistered(id),
412
- artifact: includeArtifact ? artifact : undefined,
413
- };
414
- }
415
-
416
- /**
417
- * Returns the contract metadata given an address.
418
- * The metadata consists of its contract instance, which includes the contract class identifier,
419
- * initialization hash, deployment salt, and public keys hash; whether the contract instance has been initialized;
420
- * and whether the contract instance with the given address has been publicly deployed.
421
- * @remark - it queries the node to check whether the contract instance has been initialized / publicly deployed through a node.
422
- * This query is not dependent on the PXE.
423
- * @param address - The address that the contract instance resides at.
424
- * @returns - It returns the contract metadata
425
- * TODO(@spalladino): Should we return the public keys in plain as well here?
426
- */
427
- public async getContractMetadata(address: AztecAddress): Promise<{
428
- contractInstance: ContractInstanceWithAddress | undefined;
429
- isContractInitialized: boolean;
430
- isContractPublished: boolean;
431
- }> {
432
- let instance;
433
- try {
434
- instance = await this.contractStore.getContractInstance(address);
435
- } catch {
436
- this.log.warn(`No instance found for contract ${address.toString()} when looking for its metadata`);
437
- }
438
- return {
439
- contractInstance: instance,
440
- isContractInitialized: await this.#isContractInitialized(address),
441
- isContractPublished: await this.#isContractPublished(address),
442
- };
427
+ public async getContractArtifact(id: Fr): Promise<ContractArtifact | undefined> {
428
+ return await this.contractStore.getContractArtifact(id);
443
429
  }
444
430
 
445
431
  /**
@@ -464,7 +450,6 @@ export class PXE {
464
450
  }
465
451
 
466
452
  await this.addressStore.addCompleteAddress(accountCompleteAddress);
467
- await this.noteStore.addScope(accountCompleteAddress.address);
468
453
  return accountCompleteAddress;
469
454
  }
470
455
 
@@ -612,13 +597,7 @@ export class PXE {
612
597
 
613
598
  const header = await this.anchorBlockStore.getBlockHeader();
614
599
 
615
- const currentClassId = await readCurrentClassId(
616
- contractAddress,
617
- currentInstance,
618
- this.node,
619
- header.globalVariables.blockNumber,
620
- header.globalVariables.timestamp,
621
- );
600
+ const currentClassId = await readCurrentClassId(contractAddress, currentInstance, this.node, header);
622
601
  if (!contractClass.id.equals(currentClassId)) {
623
602
  throw new Error('Could not update contract to a class different from the current one.');
624
603
  }
@@ -657,14 +636,14 @@ export class PXE {
657
636
  let privateExecutionResult: PrivateExecutionResult;
658
637
  // We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
659
638
  // computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
660
- return this.#putInJobQueue(async () => {
639
+ return this.#putInJobQueue(async jobId => {
661
640
  const totalTimer = new Timer();
662
641
  try {
663
642
  const syncTimer = new Timer();
664
643
  await this.blockStateSynchronizer.sync();
665
644
  const syncTime = syncTimer.ms();
666
645
  const contractFunctionSimulator = this.#getSimulatorForTx();
667
- privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest);
646
+ privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, undefined, jobId);
668
647
 
669
648
  const {
670
649
  publicInputs,
@@ -711,7 +690,7 @@ export class PXE {
711
690
  // TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
712
691
  const txHash = (await txProvingResult.toTx()).txHash;
713
692
 
714
- await this.senderTaggingStore.storePendingIndexes(preTagsUsedInTheTx, txHash);
693
+ await this.senderTaggingStore.storePendingIndexes(preTagsUsedInTheTx, txHash, jobId);
715
694
  this.log.debug(`Stored used pre-tags as sender for the tx`, {
716
695
  preTagsUsedInTheTx,
717
696
  });
@@ -741,7 +720,7 @@ export class PXE {
741
720
  skipProofGeneration: boolean = true,
742
721
  ): Promise<TxProfileResult> {
743
722
  // We disable concurrent profiles for consistency with simulateTx.
744
- return this.#putInJobQueue(async () => {
723
+ return this.#putInJobQueue(async jobId => {
745
724
  const totalTimer = new Timer();
746
725
  try {
747
726
  const txInfo = {
@@ -761,7 +740,12 @@ export class PXE {
761
740
  const syncTime = syncTimer.ms();
762
741
 
763
742
  const contractFunctionSimulator = this.#getSimulatorForTx();
764
- const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest);
743
+ const privateExecutionResult = await this.#executePrivate(
744
+ contractFunctionSimulator,
745
+ txRequest,
746
+ undefined,
747
+ jobId,
748
+ );
765
749
 
766
750
  const { executionSteps, timings: { proving } = {} } = await this.#prove(
767
751
  txRequest,
@@ -841,7 +825,7 @@ export class PXE {
841
825
  // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
842
826
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
843
827
  // delete the same read value, or reading values that another simulation is currently modifying).
844
- return this.#putInJobQueue(async () => {
828
+ return this.#putInJobQueue(async jobId => {
845
829
  try {
846
830
  const totalTimer = new Timer();
847
831
  const txInfo = {
@@ -867,20 +851,14 @@ export class PXE {
867
851
  const skipKernels = overrides?.contracts !== undefined && Object.keys(overrides.contracts ?? {}).length > 0;
868
852
 
869
853
  // Execution of private functions only; no proving, and no kernel logic.
870
- const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes);
854
+ const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
871
855
 
872
856
  let publicInputs: PrivateKernelTailCircuitPublicInputs | undefined;
873
857
  let executionSteps: PrivateExecutionStep[] = [];
874
858
 
875
859
  if (skipKernels) {
876
- // According to the protocol rules, the nonce generator for the note hashes
877
- // can either be the first nullifier in the tx or the protocol nullifier if there are none.
878
- const nonceGenerator = privateExecutionResult.firstNullifier.equals(Fr.ZERO)
879
- ? await computeProtocolNullifier(await txRequest.toTxRequest().hash())
880
- : privateExecutionResult.firstNullifier;
881
860
  ({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
882
861
  privateExecutionResult,
883
- nonceGenerator,
884
862
  this.contractStore,
885
863
  ));
886
864
  } else {
@@ -982,7 +960,7 @@ export class PXE {
982
960
  // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
983
961
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
984
962
  // delete the same read value, or reading values that another simulation is currently modifying).
985
- return this.#putInJobQueue(async () => {
963
+ return this.#putInJobQueue(async jobId => {
986
964
  try {
987
965
  const totalTimer = new Timer();
988
966
  const syncTimer = new Timer();
@@ -991,11 +969,23 @@ export class PXE {
991
969
  const functionTimer = new Timer();
992
970
  const contractFunctionSimulator = this.#getSimulatorForTx();
993
971
 
994
- await this.contractStore.syncPrivateState(call.to, call.selector, privateSyncCall =>
995
- this.#simulateUtility(contractFunctionSimulator, privateSyncCall),
972
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
973
+ await ensureContractSynced(
974
+ call.to,
975
+ call.selector,
976
+ privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
977
+ this.node,
978
+ this.contractStore,
979
+ anchorBlockHeader,
996
980
  );
997
981
 
998
- const executionResult = await this.#simulateUtility(contractFunctionSimulator, call, authwits ?? [], scopes);
982
+ const executionResult = await this.#simulateUtility(
983
+ contractFunctionSimulator,
984
+ call,
985
+ authwits ?? [],
986
+ scopes,
987
+ jobId,
988
+ );
999
989
  const functionTime = functionTimer.ms();
1000
990
 
1001
991
  const totalTime = totalTimer.ms();
@@ -1036,25 +1026,39 @@ export class PXE {
1036
1026
  * Defaults to the latest known block to PXE + 1.
1037
1027
  * @returns - The packed events with block and tx metadata.
1038
1028
  */
1039
- public getPrivateEvents(eventSelector: EventSelector, filter: PrivateEventFilter): Promise<PackedPrivateEvent[]> {
1040
- return this.#putInJobQueue(async () => {
1029
+ public async getPrivateEvents(
1030
+ eventSelector: EventSelector,
1031
+ filter: PrivateEventFilter,
1032
+ ): Promise<PackedPrivateEvent[]> {
1033
+ let anchorBlockNumber: BlockNumber;
1034
+
1035
+ await this.#putInJobQueue(async jobId => {
1041
1036
  await this.blockStateSynchronizer.sync();
1037
+
1038
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
1039
+ anchorBlockNumber = anchorBlockHeader.getBlockNumber();
1040
+
1042
1041
  const contractFunctionSimulator = this.#getSimulatorForTx();
1043
1042
 
1044
- await this.contractStore.syncPrivateState(
1043
+ await ensureContractSynced(
1045
1044
  filter.contractAddress,
1046
1045
  null,
1047
- async privateSyncCall => await this.#simulateUtility(contractFunctionSimulator, privateSyncCall),
1046
+ async privateSyncCall =>
1047
+ await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
1048
+ this.node,
1049
+ this.contractStore,
1050
+ anchorBlockHeader,
1048
1051
  );
1052
+ });
1049
1053
 
1050
- const sanitizedFilter = await new PrivateEventFilterValidator(this.anchorBlockStore).validate(filter);
1054
+ // anchorBlockNumber is set during the job and fixed to whatever it is after a block sync
1055
+ const sanitizedFilter = new PrivateEventFilterValidator(anchorBlockNumber!).validate(filter);
1051
1056
 
1052
- this.log.debug(
1053
- `Getting private events for ${sanitizedFilter.contractAddress.toString()} from ${sanitizedFilter.fromBlock} to ${sanitizedFilter.toBlock}`,
1054
- );
1057
+ this.log.debug(
1058
+ `Getting private events for ${sanitizedFilter.contractAddress.toString()} from ${sanitizedFilter.fromBlock} to ${sanitizedFilter.toBlock}`,
1059
+ );
1055
1060
 
1056
- return this.privateEventStore.getPrivateEvents(eventSelector, sanitizedFilter);
1057
- });
1061
+ return this.privateEventStore.getPrivateEvents(eventSelector, sanitizedFilter);
1058
1062
  }
1059
1063
 
1060
1064
  /**
@@ -43,23 +43,23 @@ export class AddressStore {
43
43
  });
44
44
  }
45
45
 
46
- async #getCompleteAddress(address: AztecAddress): Promise<CompleteAddress | undefined> {
47
- const index = await this.#completeAddressIndex.getAsync(address.toString());
48
- if (index === undefined) {
49
- return undefined;
50
- }
51
-
52
- const value = await this.#completeAddresses.atAsync(index);
53
- return value ? await CompleteAddress.fromBuffer(value) : undefined;
54
- }
55
-
56
46
  getCompleteAddress(account: AztecAddress): Promise<CompleteAddress | undefined> {
57
- return this.#getCompleteAddress(account);
47
+ return this.#store.transactionAsync(async () => {
48
+ const index = await this.#completeAddressIndex.getAsync(account.toString());
49
+ if (index === undefined) {
50
+ return undefined;
51
+ }
52
+
53
+ const value = await this.#completeAddresses.atAsync(index);
54
+ return value ? await CompleteAddress.fromBuffer(value) : undefined;
55
+ });
58
56
  }
59
57
 
60
- async getCompleteAddresses(): Promise<CompleteAddress[]> {
61
- return await Promise.all(
62
- (await toArray(this.#completeAddresses.valuesAsync())).map(v => CompleteAddress.fromBuffer(v)),
63
- );
58
+ getCompleteAddresses(): Promise<CompleteAddress[]> {
59
+ return this.#store.transactionAsync(async () => {
60
+ return await Promise.all(
61
+ (await toArray(this.#completeAddresses.valuesAsync())).map(v => CompleteAddress.fromBuffer(v)),
62
+ );
63
+ });
64
64
  }
65
65
  }
@@ -10,6 +10,14 @@ export class AnchorBlockStore {
10
10
  this.#synchronizedHeader = this.#store.openSingleton('header');
11
11
  }
12
12
 
13
+ /**
14
+ * Sets the currently synchronized block
15
+ *
16
+ * Important: this method is only called from BlockSynchronizer, and since we need it to run atomically with other
17
+ * stores in the case of a reorg, it MUST NOT be wrapped in a `transactionAsync` call. Doing so would result in a
18
+ * deadlock when the backend is IndexedDB, because `transactionAsync` is not designed to support reentrancy.
19
+ *
20
+ */
13
21
  async setHeader(header: BlockHeader): Promise<void> {
14
22
  await this.#synchronizedHeader.set(header.toBuffer());
15
23
  }