@aztec/pxe 0.0.1-commit.c7c42ec → 0.0.1-commit.f295ac2

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 (180) hide show
  1. package/dest/block_synchronizer/block_synchronizer.d.ts +6 -2
  2. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
  3. package/dest/block_synchronizer/block_synchronizer.js +21 -13
  4. package/dest/config/package_info.js +1 -1
  5. package/dest/contract_function_simulator/benchmarked_node.d.ts +9 -0
  6. package/dest/contract_function_simulator/benchmarked_node.d.ts.map +1 -0
  7. package/dest/contract_function_simulator/benchmarked_node.js +77 -0
  8. package/dest/contract_function_simulator/contract_function_simulator.d.ts +8 -9
  9. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  10. package/dest/contract_function_simulator/contract_function_simulator.js +33 -16
  11. package/dest/contract_function_simulator/execution_note_cache.d.ts +18 -9
  12. package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -1
  13. package/dest/contract_function_simulator/execution_note_cache.js +45 -28
  14. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +3 -2
  15. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
  16. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +5 -2
  17. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts +4 -10
  18. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts.map +1 -1
  19. package/dest/contract_function_simulator/noir-structs/utility_context.js +7 -18
  20. package/dest/contract_function_simulator/oracle/interfaces.d.ts +9 -8
  21. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  22. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts +3 -1
  23. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts.map +1 -1
  24. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts +4 -4
  25. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts.map +1 -1
  26. package/dest/contract_function_simulator/oracle/note_packing_utils.js +5 -5
  27. package/dest/contract_function_simulator/oracle/oracle.d.ts +6 -6
  28. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  29. package/dest/contract_function_simulator/oracle/oracle.js +20 -19
  30. package/dest/contract_function_simulator/oracle/private_execution.d.ts +5 -9
  31. package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
  32. package/dest/contract_function_simulator/oracle/private_execution.js +11 -10
  33. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +8 -18
  34. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  35. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +10 -35
  36. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +14 -12
  37. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  38. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +54 -52
  39. package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
  40. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  41. package/dest/entrypoints/client/bundle/utils.js +10 -1
  42. package/dest/entrypoints/client/lazy/utils.d.ts +1 -1
  43. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  44. package/dest/entrypoints/client/lazy/utils.js +10 -1
  45. package/dest/entrypoints/pxe_creation_options.d.ts +3 -2
  46. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  47. package/dest/entrypoints/server/index.d.ts +2 -1
  48. package/dest/entrypoints/server/index.d.ts.map +1 -1
  49. package/dest/entrypoints/server/index.js +1 -0
  50. package/dest/entrypoints/server/utils.d.ts +1 -1
  51. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  52. package/dest/entrypoints/server/utils.js +11 -7
  53. package/dest/events/event_service.d.ts +4 -3
  54. package/dest/events/event_service.d.ts.map +1 -1
  55. package/dest/events/event_service.js +17 -19
  56. package/dest/events/private_event_filter_validator.d.ts +5 -5
  57. package/dest/events/private_event_filter_validator.d.ts.map +1 -1
  58. package/dest/events/private_event_filter_validator.js +5 -6
  59. package/dest/job_coordinator/job_coordinator.d.ts +74 -0
  60. package/dest/job_coordinator/job_coordinator.d.ts.map +1 -0
  61. package/dest/job_coordinator/job_coordinator.js +93 -0
  62. package/dest/logs/log_service.d.ts +3 -2
  63. package/dest/logs/log_service.d.ts.map +1 -1
  64. package/dest/logs/log_service.js +5 -3
  65. package/dest/notes/note_service.d.ts +3 -3
  66. package/dest/notes/note_service.d.ts.map +1 -1
  67. package/dest/notes/note_service.js +23 -28
  68. package/dest/oracle_version.d.ts +2 -2
  69. package/dest/oracle_version.js +2 -2
  70. package/dest/private_kernel/hints/index.d.ts +2 -2
  71. package/dest/private_kernel/hints/index.d.ts.map +1 -1
  72. package/dest/private_kernel/hints/index.js +1 -1
  73. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +28 -0
  74. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -0
  75. package/dest/private_kernel/hints/{build_private_kernel_reset_private_inputs.js → private_kernel_reset_private_inputs_builder.js} +13 -7
  76. package/dest/private_kernel/private_kernel_execution_prover.d.ts +1 -1
  77. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  78. package/dest/private_kernel/private_kernel_execution_prover.js +4 -5
  79. package/dest/private_kernel/private_kernel_oracle.d.ts +24 -28
  80. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  81. package/dest/private_kernel/private_kernel_oracle.js +90 -2
  82. package/dest/pxe.d.ts +8 -36
  83. package/dest/pxe.d.ts.map +1 -1
  84. package/dest/pxe.js +65 -87
  85. package/dest/storage/capsule_store/capsule_store.d.ts +24 -9
  86. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
  87. package/dest/storage/capsule_store/capsule_store.js +132 -23
  88. package/dest/storage/contract_store/contract_store.d.ts +2 -1
  89. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  90. package/dest/storage/contract_store/contract_store.js +12 -0
  91. package/dest/storage/note_store/note_store.d.ts +6 -5
  92. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  93. package/dest/storage/note_store/note_store.js +89 -94
  94. package/dest/storage/private_event_store/private_event_store.d.ts +33 -6
  95. package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
  96. package/dest/storage/private_event_store/private_event_store.js +139 -32
  97. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +15 -8
  98. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
  99. package/dest/storage/tagging_store/recipient_tagging_store.js +69 -12
  100. package/dest/storage/tagging_store/sender_tagging_store.d.ts +19 -9
  101. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  102. package/dest/storage/tagging_store/sender_tagging_store.js +110 -28
  103. package/dest/tagging/constants.d.ts +2 -0
  104. package/dest/tagging/constants.d.ts.map +1 -0
  105. package/dest/tagging/constants.js +10 -0
  106. package/dest/tagging/index.d.ts +2 -2
  107. package/dest/tagging/index.d.ts.map +1 -1
  108. package/dest/tagging/index.js +1 -10
  109. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +2 -2
  110. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
  111. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +7 -7
  112. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +2 -2
  113. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  114. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +8 -8
  115. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +1 -1
  116. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
  117. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +2 -2
  118. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +4 -2
  119. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  120. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +4 -2
  121. package/dest/tree_membership/tree_membership_service.d.ts +9 -11
  122. package/dest/tree_membership/tree_membership_service.d.ts.map +1 -1
  123. package/dest/tree_membership/tree_membership_service.js +25 -34
  124. package/package.json +18 -18
  125. package/src/block_synchronizer/block_synchronizer.ts +30 -12
  126. package/src/config/package_info.ts +1 -1
  127. package/src/contract_function_simulator/benchmarked_node.ts +103 -0
  128. package/src/contract_function_simulator/contract_function_simulator.ts +42 -16
  129. package/src/contract_function_simulator/execution_note_cache.ts +44 -25
  130. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +4 -0
  131. package/src/contract_function_simulator/noir-structs/utility_context.ts +6 -25
  132. package/src/contract_function_simulator/oracle/interfaces.ts +8 -7
  133. package/src/contract_function_simulator/oracle/note_packing_utils.ts +6 -6
  134. package/src/contract_function_simulator/oracle/oracle.ts +24 -22
  135. package/src/contract_function_simulator/oracle/private_execution.ts +10 -19
  136. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +13 -38
  137. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +56 -50
  138. package/src/entrypoints/client/bundle/utils.ts +7 -1
  139. package/src/entrypoints/client/lazy/utils.ts +7 -2
  140. package/src/entrypoints/pxe_creation_options.ts +2 -1
  141. package/src/entrypoints/server/index.ts +1 -0
  142. package/src/entrypoints/server/utils.ts +11 -15
  143. package/src/events/event_service.ts +17 -21
  144. package/src/events/private_event_filter_validator.ts +3 -5
  145. package/src/job_coordinator/job_coordinator.ts +149 -0
  146. package/src/logs/log_service.ts +3 -1
  147. package/src/notes/note_service.ts +23 -29
  148. package/src/oracle_version.ts +2 -2
  149. package/src/private_kernel/hints/index.ts +1 -1
  150. package/src/private_kernel/hints/{build_private_kernel_reset_private_inputs.ts → private_kernel_reset_private_inputs_builder.ts} +33 -22
  151. package/src/private_kernel/private_kernel_execution_prover.ts +3 -5
  152. package/src/private_kernel/private_kernel_oracle.ts +116 -36
  153. package/src/pxe.ts +98 -116
  154. package/src/storage/capsule_store/capsule_store.ts +159 -23
  155. package/src/storage/contract_store/contract_store.ts +20 -0
  156. package/src/storage/note_store/note_store.ts +98 -95
  157. package/src/storage/private_event_store/private_event_store.ts +199 -37
  158. package/src/storage/tagging_store/recipient_tagging_store.ts +89 -13
  159. package/src/storage/tagging_store/sender_tagging_store.ts +129 -28
  160. package/src/tagging/constants.ts +10 -0
  161. package/src/tagging/index.ts +1 -11
  162. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +10 -6
  163. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +8 -7
  164. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +6 -2
  165. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +4 -1
  166. package/src/tree_membership/tree_membership_service.ts +27 -42
  167. package/dest/contract_function_simulator/proxied_node.d.ts +0 -9
  168. package/dest/contract_function_simulator/proxied_node.d.ts.map +0 -1
  169. package/dest/contract_function_simulator/proxied_node.js +0 -27
  170. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts +0 -28
  171. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts.map +0 -1
  172. package/dest/private_kernel/private_kernel_oracle_impl.d.ts +0 -46
  173. package/dest/private_kernel/private_kernel_oracle_impl.d.ts.map +0 -1
  174. package/dest/private_kernel/private_kernel_oracle_impl.js +0 -86
  175. package/dest/public_storage/public_storage_service.d.ts +0 -24
  176. package/dest/public_storage/public_storage_service.d.ts.map +0 -1
  177. package/dest/public_storage/public_storage_service.js +0 -26
  178. package/src/contract_function_simulator/proxied_node.ts +0 -33
  179. package/src/private_kernel/private_kernel_oracle_impl.ts +0 -133
  180. package/src/public_storage/public_storage_service.ts +0 -33
package/src/pxe.ts CHANGED
@@ -1,4 +1,5 @@
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
4
  import { type Logger, createLogger } from '@aztec/foundation/log';
4
5
  import { SerialQueue } from '@aztec/foundation/queue';
@@ -17,16 +18,15 @@ import {
17
18
  } from '@aztec/stdlib/abi';
18
19
  import type { AuthWitness } from '@aztec/stdlib/auth-witness';
19
20
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
21
+ import { L2BlockHash } from '@aztec/stdlib/block';
20
22
  import {
21
23
  CompleteAddress,
22
- type ContractClassWithId,
23
24
  type ContractInstanceWithAddress,
24
25
  type PartialAddress,
25
26
  computeContractAddressFromInstance,
26
27
  getContractClassFromArtifact,
27
28
  } from '@aztec/stdlib/contract';
28
29
  import { SimulationError } from '@aztec/stdlib/errors';
29
- import { computeProtocolNullifier, siloNullifier } from '@aztec/stdlib/hash';
30
30
  import type { AztecNode, PrivateKernelProver } from '@aztec/stdlib/interfaces/client';
31
31
  import type {
32
32
  PrivateExecutionStep,
@@ -54,6 +54,7 @@ import { inspect } from 'util';
54
54
 
55
55
  import { BlockSynchronizer } from './block_synchronizer/index.js';
56
56
  import type { PXEConfig } from './config/index.js';
57
+ import { BenchmarkedNodeFactory } from './contract_function_simulator/benchmarked_node.js';
57
58
  import {
58
59
  ContractFunctionSimulator,
59
60
  generateSimulatedProvingResult,
@@ -63,11 +64,12 @@ import { ProxiedContractStoreFactory } from './contract_function_simulator/proxi
63
64
  import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
64
65
  import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
65
66
  import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
67
+ import { JobCoordinator } from './job_coordinator/job_coordinator.js';
66
68
  import {
67
69
  PrivateKernelExecutionProver,
68
70
  type PrivateKernelExecutionProverConfig,
69
71
  } from './private_kernel/private_kernel_execution_prover.js';
70
- import { PrivateKernelOracleImpl } from './private_kernel/private_kernel_oracle_impl.js';
72
+ import { PrivateKernelOracle } from './private_kernel/private_kernel_oracle.js';
71
73
  import { AddressStore } from './storage/address_store/address_store.js';
72
74
  import { AnchorBlockStore } from './storage/anchor_block_store/anchor_block_store.js';
73
75
  import { CapsuleStore } from './storage/capsule_store/capsule_store.js';
@@ -107,6 +109,7 @@ export class PXE {
107
109
  private protocolContractsProvider: ProtocolContractsProvider,
108
110
  private log: Logger,
109
111
  private jobQueue: SerialQueue,
112
+ private jobCoordinator: JobCoordinator,
110
113
  public debug: PXEDebugUtils,
111
114
  ) {}
112
115
 
@@ -143,7 +146,19 @@ export class PXE {
143
146
  const capsuleStore = new CapsuleStore(store);
144
147
  const keyStore = new KeyStore(store);
145
148
  const tipsStore = new L2TipsKVStore(store, 'pxe');
146
- const synchronizer = new BlockSynchronizer(node, anchorBlockStore, noteStore, tipsStore, config, loggerOrSuffix);
149
+ const synchronizer = new BlockSynchronizer(
150
+ node,
151
+ store,
152
+ anchorBlockStore,
153
+ noteStore,
154
+ privateEventStore,
155
+ tipsStore,
156
+ config,
157
+ loggerOrSuffix,
158
+ );
159
+
160
+ const jobCoordinator = new JobCoordinator(store);
161
+ jobCoordinator.registerStores([capsuleStore, senderTaggingStore, recipientTaggingStore, privateEventStore]);
147
162
 
148
163
  const debugUtils = new PXEDebugUtils(contractStore, noteStore);
149
164
 
@@ -168,6 +183,7 @@ export class PXE {
168
183
  protocolContractsProvider,
169
184
  log,
170
185
  jobQueue,
186
+ jobCoordinator,
171
187
  debugUtils,
172
188
  );
173
189
 
@@ -191,7 +207,7 @@ export class PXE {
191
207
  this.noteStore,
192
208
  this.keyStore,
193
209
  this.addressStore,
194
- this.node,
210
+ BenchmarkedNodeFactory.create(this.node),
195
211
  this.anchorBlockStore,
196
212
  this.senderTaggingStore,
197
213
  this.recipientTaggingStore,
@@ -222,7 +238,7 @@ export class PXE {
222
238
  *
223
239
  * Useful for tasks that cannot run concurrently, such as contract function simulation.
224
240
  */
225
- #putInJobQueue<T>(fn: () => Promise<T>): Promise<T> {
241
+ #putInJobQueue<T>(fn: (jobId: string) => Promise<T>): Promise<T> {
226
242
  // TODO(#12636): relax the conditions under which we forbid concurrency.
227
243
  if (this.jobQueue.length() != 0) {
228
244
  this.log.warn(
@@ -230,7 +246,22 @@ export class PXE {
230
246
  );
231
247
  }
232
248
 
233
- return this.jobQueue.put(fn);
249
+ return this.jobQueue.put(async () => {
250
+ const jobId = this.jobCoordinator.beginJob();
251
+ this.log.verbose(`Beginning job ${jobId}`);
252
+
253
+ try {
254
+ const result = await fn(jobId);
255
+ this.log.verbose(`Committing job ${jobId}`);
256
+
257
+ await this.jobCoordinator.commitJob(jobId);
258
+ return result;
259
+ } catch (err) {
260
+ this.log.verbose(`Aborting job ${jobId}`);
261
+ await this.jobCoordinator.abortJob(jobId);
262
+ throw err;
263
+ }
264
+ });
234
265
  }
235
266
 
236
267
  async #registerProtocolContracts() {
@@ -245,25 +276,13 @@ export class PXE {
245
276
  this.log.verbose(`Registered protocol contracts in pxe`, registered);
246
277
  }
247
278
 
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
279
  // Executes the entrypoint private function, as well as all nested private
262
280
  // functions that might arise.
263
281
  async #executePrivate(
264
282
  contractFunctionSimulator: ContractFunctionSimulator,
265
283
  txRequest: TxExecutionRequest,
266
- scopes?: AztecAddress[],
284
+ scopes: AztecAddress[] | undefined,
285
+ jobId: string,
267
286
  ): Promise<PrivateExecutionResult> {
268
287
  const { origin: contractAddress, functionSelector } = txRequest;
269
288
 
@@ -280,6 +299,7 @@ export class PXE {
280
299
  // contract entrypoint
281
300
  undefined, // senderForTags
282
301
  scopes,
302
+ jobId,
283
303
  );
284
304
  this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
285
305
  return result;
@@ -298,17 +318,19 @@ export class PXE {
298
318
  * @param authWitnesses - Authentication witnesses required for the function call.
299
319
  * @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
300
320
  * accounts if not specified.
321
+ * @param jobId - The job ID for staged writes.
301
322
  * @returns The simulation result containing the outputs of the utility function.
302
323
  */
303
324
  async #simulateUtility(
304
325
  contractFunctionSimulator: ContractFunctionSimulator,
305
326
  call: FunctionCall,
306
- authWitnesses?: AuthWitness[],
307
- scopes?: AztecAddress[],
327
+ authWitnesses: AuthWitness[] | undefined,
328
+ scopes: AztecAddress[] | undefined,
329
+ jobId: string,
308
330
  ) {
309
331
  try {
310
332
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
311
- return contractFunctionSimulator.runUtility(call, authWitnesses ?? [], anchorBlockHeader, scopes);
333
+ return contractFunctionSimulator.runUtility(call, authWitnesses ?? [], anchorBlockHeader, scopes, jobId);
312
334
  } catch (err) {
313
335
  if (err instanceof SimulationError) {
314
336
  await enrichSimulationError(err, this.contractStore, this.log);
@@ -361,13 +383,9 @@ export class PXE {
361
383
  privateExecutionResult: PrivateExecutionResult,
362
384
  config: PrivateKernelExecutionProverConfig,
363
385
  ): Promise<PrivateKernelExecutionProofOutput<PrivateKernelTailCircuitPublicInputs>> {
364
- const simulationAnchorBlock = privateExecutionResult.getSimulationAnchorBlockNumber();
365
- const kernelOracle = new PrivateKernelOracleImpl(
366
- this.contractStore,
367
- this.keyStore,
368
- this.node,
369
- simulationAnchorBlock,
370
- );
386
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
387
+ const anchorBlockHash = L2BlockHash.fromField(await anchorBlockHeader.hash());
388
+ const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHash);
371
389
  const kernelTraceProver = new PrivateKernelExecutionProver(kernelOracle, proofCreator, !this.proverEnabled);
372
390
  this.log.debug(`Executing kernel trace prover (${JSON.stringify(config)})...`);
373
391
  return await kernelTraceProver.proveWithKernels(txExecutionRequest.toTxRequest(), privateExecutionResult, config);
@@ -380,66 +398,12 @@ export class PXE {
380
398
  }
381
399
 
382
400
  /**
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.
401
+ * Returns the contract artifact for a given contract class id, if it's registered in the PXE.
402
+ * @param id - Identifier of the contract class.
403
+ * @returns The contract artifact if found, undefined otherwise.
395
404
  */
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
- };
405
+ public async getContractArtifact(id: Fr): Promise<ContractArtifact | undefined> {
406
+ return await this.contractStore.getContractArtifact(id);
443
407
  }
444
408
 
445
409
  /**
@@ -612,13 +576,7 @@ export class PXE {
612
576
 
613
577
  const header = await this.anchorBlockStore.getBlockHeader();
614
578
 
615
- const currentClassId = await readCurrentClassId(
616
- contractAddress,
617
- currentInstance,
618
- this.node,
619
- header.globalVariables.blockNumber,
620
- header.globalVariables.timestamp,
621
- );
579
+ const currentClassId = await readCurrentClassId(contractAddress, currentInstance, this.node, header);
622
580
  if (!contractClass.id.equals(currentClassId)) {
623
581
  throw new Error('Could not update contract to a class different from the current one.');
624
582
  }
@@ -657,14 +615,14 @@ export class PXE {
657
615
  let privateExecutionResult: PrivateExecutionResult;
658
616
  // We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
659
617
  // computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
660
- return this.#putInJobQueue(async () => {
618
+ return this.#putInJobQueue(async jobId => {
661
619
  const totalTimer = new Timer();
662
620
  try {
663
621
  const syncTimer = new Timer();
664
622
  await this.blockStateSynchronizer.sync();
665
623
  const syncTime = syncTimer.ms();
666
624
  const contractFunctionSimulator = this.#getSimulatorForTx();
667
- privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest);
625
+ privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, undefined, jobId);
668
626
 
669
627
  const {
670
628
  publicInputs,
@@ -711,7 +669,7 @@ export class PXE {
711
669
  // TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
712
670
  const txHash = (await txProvingResult.toTx()).txHash;
713
671
 
714
- await this.senderTaggingStore.storePendingIndexes(preTagsUsedInTheTx, txHash);
672
+ await this.senderTaggingStore.storePendingIndexes(preTagsUsedInTheTx, txHash, jobId);
715
673
  this.log.debug(`Stored used pre-tags as sender for the tx`, {
716
674
  preTagsUsedInTheTx,
717
675
  });
@@ -741,7 +699,7 @@ export class PXE {
741
699
  skipProofGeneration: boolean = true,
742
700
  ): Promise<TxProfileResult> {
743
701
  // We disable concurrent profiles for consistency with simulateTx.
744
- return this.#putInJobQueue(async () => {
702
+ return this.#putInJobQueue(async jobId => {
745
703
  const totalTimer = new Timer();
746
704
  try {
747
705
  const txInfo = {
@@ -761,7 +719,12 @@ export class PXE {
761
719
  const syncTime = syncTimer.ms();
762
720
 
763
721
  const contractFunctionSimulator = this.#getSimulatorForTx();
764
- const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest);
722
+ const privateExecutionResult = await this.#executePrivate(
723
+ contractFunctionSimulator,
724
+ txRequest,
725
+ undefined,
726
+ jobId,
727
+ );
765
728
 
766
729
  const { executionSteps, timings: { proving } = {} } = await this.#prove(
767
730
  txRequest,
@@ -841,7 +804,7 @@ export class PXE {
841
804
  // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
842
805
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
843
806
  // delete the same read value, or reading values that another simulation is currently modifying).
844
- return this.#putInJobQueue(async () => {
807
+ return this.#putInJobQueue(async jobId => {
845
808
  try {
846
809
  const totalTimer = new Timer();
847
810
  const txInfo = {
@@ -867,20 +830,14 @@ export class PXE {
867
830
  const skipKernels = overrides?.contracts !== undefined && Object.keys(overrides.contracts ?? {}).length > 0;
868
831
 
869
832
  // Execution of private functions only; no proving, and no kernel logic.
870
- const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes);
833
+ const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
871
834
 
872
835
  let publicInputs: PrivateKernelTailCircuitPublicInputs | undefined;
873
836
  let executionSteps: PrivateExecutionStep[] = [];
874
837
 
875
838
  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
839
  ({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
882
840
  privateExecutionResult,
883
- nonceGenerator,
884
841
  this.contractStore,
885
842
  ));
886
843
  } else {
@@ -982,7 +939,7 @@ export class PXE {
982
939
  // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
983
940
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
984
941
  // delete the same read value, or reading values that another simulation is currently modifying).
985
- return this.#putInJobQueue(async () => {
942
+ return this.#putInJobQueue(async jobId => {
986
943
  try {
987
944
  const totalTimer = new Timer();
988
945
  const syncTimer = new Timer();
@@ -990,7 +947,18 @@ export class PXE {
990
947
  const syncTime = syncTimer.ms();
991
948
  const functionTimer = new Timer();
992
949
  const contractFunctionSimulator = this.#getSimulatorForTx();
993
- const executionResult = await this.#simulateUtility(contractFunctionSimulator, call, authwits ?? [], scopes);
950
+
951
+ await this.contractStore.syncPrivateState(call.to, call.selector, privateSyncCall =>
952
+ this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
953
+ );
954
+
955
+ const executionResult = await this.#simulateUtility(
956
+ contractFunctionSimulator,
957
+ call,
958
+ authwits ?? [],
959
+ scopes,
960
+ jobId,
961
+ );
994
962
  const functionTime = functionTimer.ms();
995
963
 
996
964
  const totalTime = totalTimer.ms();
@@ -1035,11 +1003,25 @@ export class PXE {
1035
1003
  eventSelector: EventSelector,
1036
1004
  filter: PrivateEventFilter,
1037
1005
  ): Promise<PackedPrivateEvent[]> {
1038
- // We need to manually trigger private state sync to have a guarantee that all the events are available.
1039
- const call = await this.contractStore.getFunctionCall('sync_private_state', [], filter.contractAddress);
1040
- await this.simulateUtility(call);
1006
+ let anchorBlockNumber: BlockNumber;
1007
+
1008
+ await this.#putInJobQueue(async jobId => {
1009
+ await this.blockStateSynchronizer.sync();
1010
+
1011
+ anchorBlockNumber = (await this.anchorBlockStore.getBlockHeader()).getBlockNumber();
1012
+
1013
+ const contractFunctionSimulator = this.#getSimulatorForTx();
1014
+
1015
+ await this.contractStore.syncPrivateState(
1016
+ filter.contractAddress,
1017
+ null,
1018
+ async privateSyncCall =>
1019
+ await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
1020
+ );
1021
+ });
1041
1022
 
1042
- const sanitizedFilter = await new PrivateEventFilterValidator(this.anchorBlockStore).validate(filter);
1023
+ // anchorBlockNumber is set during the job and fixed to whatever it is after a block sync
1024
+ const sanitizedFilter = new PrivateEventFilterValidator(anchorBlockNumber!).validate(filter);
1043
1025
 
1044
1026
  this.log.debug(
1045
1027
  `Getting private events for ${sanitizedFilter.contractAddress.toString()} from ${sanitizedFilter.fromBlock} to ${sanitizedFilter.toBlock}`,