@aztec/pxe 0.0.1-commit.e3c1de76 → 0.0.1-commit.e588bc7e5

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 (209) hide show
  1. package/dest/block_synchronizer/block_synchronizer.d.ts +4 -2
  2. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
  3. package/dest/block_synchronizer/block_synchronizer.js +13 -1
  4. package/dest/config/index.d.ts +2 -2
  5. package/dest/config/index.d.ts.map +1 -1
  6. package/dest/config/index.js +1 -1
  7. package/dest/config/package_info.js +1 -1
  8. package/dest/contract_function_simulator/contract_function_simulator.d.ts +60 -29
  9. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  10. package/dest/contract_function_simulator/contract_function_simulator.js +201 -72
  11. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +7 -7
  12. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -1
  13. package/dest/contract_function_simulator/execution_tagging_index_cache.js +19 -11
  14. package/dest/contract_function_simulator/index.d.ts +2 -1
  15. package/dest/contract_function_simulator/index.d.ts.map +1 -1
  16. package/dest/contract_function_simulator/index.js +1 -0
  17. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +3 -5
  18. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
  19. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +7 -9
  20. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +1 -1
  21. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
  22. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +1 -3
  23. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +3 -6
  24. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
  25. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +5 -10
  26. package/dest/contract_function_simulator/oracle/interfaces.d.ts +50 -45
  27. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  28. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts +9 -0
  29. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts.map +1 -0
  30. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.js +38 -0
  31. package/dest/contract_function_simulator/oracle/oracle.d.ts +64 -44
  32. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  33. package/dest/contract_function_simulator/oracle/oracle.js +211 -109
  34. package/dest/contract_function_simulator/oracle/private_execution.js +5 -3
  35. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +53 -78
  36. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  37. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +108 -86
  38. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +100 -55
  39. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  40. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +238 -121
  41. package/dest/contract_logging.d.ts +27 -0
  42. package/dest/contract_logging.d.ts.map +1 -0
  43. package/dest/contract_logging.js +38 -0
  44. package/dest/contract_sync/contract_sync_service.d.ts +44 -0
  45. package/dest/contract_sync/contract_sync_service.d.ts.map +1 -0
  46. package/dest/contract_sync/contract_sync_service.js +104 -0
  47. package/dest/contract_sync/helpers.d.ts +28 -0
  48. package/dest/contract_sync/helpers.d.ts.map +1 -0
  49. package/dest/contract_sync/{index.js → helpers.js} +19 -13
  50. package/dest/debug/pxe_debug_utils.d.ts +14 -10
  51. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  52. package/dest/debug/pxe_debug_utils.js +16 -15
  53. package/dest/entrypoints/client/bundle/index.d.ts +3 -1
  54. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  55. package/dest/entrypoints/client/bundle/index.js +2 -0
  56. package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
  57. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  58. package/dest/entrypoints/client/bundle/utils.js +9 -1
  59. package/dest/entrypoints/client/lazy/index.d.ts +3 -1
  60. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  61. package/dest/entrypoints/client/lazy/index.js +2 -0
  62. package/dest/entrypoints/client/lazy/utils.d.ts +1 -1
  63. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  64. package/dest/entrypoints/client/lazy/utils.js +9 -1
  65. package/dest/entrypoints/server/index.d.ts +3 -2
  66. package/dest/entrypoints/server/index.d.ts.map +1 -1
  67. package/dest/entrypoints/server/index.js +2 -1
  68. package/dest/entrypoints/server/utils.js +9 -1
  69. package/dest/events/event_service.d.ts +3 -2
  70. package/dest/events/event_service.d.ts.map +1 -1
  71. package/dest/events/event_service.js +16 -4
  72. package/dest/logs/log_service.d.ts +6 -6
  73. package/dest/logs/log_service.d.ts.map +1 -1
  74. package/dest/logs/log_service.js +39 -44
  75. package/dest/messages/message_context_service.d.ts +17 -0
  76. package/dest/messages/message_context_service.d.ts.map +1 -0
  77. package/dest/messages/message_context_service.js +36 -0
  78. package/dest/notes/note_service.d.ts +4 -4
  79. package/dest/notes/note_service.d.ts.map +1 -1
  80. package/dest/notes/note_service.js +17 -7
  81. package/dest/notes_filter.d.ts +24 -0
  82. package/dest/notes_filter.d.ts.map +1 -0
  83. package/dest/notes_filter.js +4 -0
  84. package/dest/oracle_version.d.ts +3 -3
  85. package/dest/oracle_version.d.ts.map +1 -1
  86. package/dest/oracle_version.js +3 -3
  87. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts +4 -0
  88. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts.map +1 -0
  89. package/dest/private_kernel/hints/{compute_tx_include_by_timestamp.js → compute_tx_expiration_timestamp.js} +12 -12
  90. package/dest/private_kernel/hints/index.d.ts +1 -1
  91. package/dest/private_kernel/hints/index.js +1 -1
  92. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +4 -3
  93. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -1
  94. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.js +129 -68
  95. package/dest/private_kernel/hints/test_utils.d.ts +122 -0
  96. package/dest/private_kernel/hints/test_utils.d.ts.map +1 -0
  97. package/dest/private_kernel/hints/test_utils.js +203 -0
  98. package/dest/private_kernel/private_kernel_execution_prover.d.ts +1 -1
  99. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  100. package/dest/private_kernel/private_kernel_execution_prover.js +19 -11
  101. package/dest/private_kernel/private_kernel_oracle.d.ts +6 -2
  102. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  103. package/dest/private_kernel/private_kernel_oracle.js +7 -3
  104. package/dest/pxe.d.ts +73 -24
  105. package/dest/pxe.d.ts.map +1 -1
  106. package/dest/pxe.js +126 -74
  107. package/dest/storage/capsule_store/capsule_service.d.ts +21 -0
  108. package/dest/storage/capsule_store/capsule_service.d.ts.map +1 -0
  109. package/dest/storage/capsule_store/capsule_service.js +50 -0
  110. package/dest/storage/capsule_store/capsule_store.d.ts +9 -9
  111. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
  112. package/dest/storage/capsule_store/capsule_store.js +33 -28
  113. package/dest/storage/capsule_store/index.d.ts +2 -1
  114. package/dest/storage/capsule_store/index.d.ts.map +1 -1
  115. package/dest/storage/capsule_store/index.js +1 -0
  116. package/dest/storage/contract_store/contract_store.d.ts +42 -15
  117. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  118. package/dest/storage/contract_store/contract_store.js +145 -69
  119. package/dest/storage/metadata.d.ts +1 -1
  120. package/dest/storage/metadata.js +1 -1
  121. package/dest/storage/note_store/note_store.d.ts +3 -3
  122. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  123. package/dest/storage/note_store/note_store.js +6 -4
  124. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +6 -6
  125. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
  126. package/dest/storage/tagging_store/sender_tagging_store.d.ts +29 -28
  127. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  128. package/dest/storage/tagging_store/sender_tagging_store.js +141 -115
  129. package/dest/tagging/get_all_logs_by_tags.d.ts +1 -1
  130. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -1
  131. package/dest/tagging/get_all_logs_by_tags.js +17 -3
  132. package/dest/tagging/index.d.ts +3 -3
  133. package/dest/tagging/index.d.ts.map +1 -1
  134. package/dest/tagging/index.js +1 -1
  135. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +4 -5
  136. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
  137. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +7 -7
  138. package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +2 -2
  139. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +6 -7
  140. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
  141. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +12 -11
  142. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +4 -8
  143. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  144. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +13 -7
  145. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +4 -3
  146. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
  147. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +20 -10
  148. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +5 -7
  149. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  150. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +36 -24
  151. package/package.json +25 -16
  152. package/src/block_synchronizer/block_synchronizer.ts +12 -0
  153. package/src/config/index.ts +1 -1
  154. package/src/config/package_info.ts +1 -1
  155. package/src/contract_function_simulator/contract_function_simulator.ts +360 -133
  156. package/src/contract_function_simulator/execution_tagging_index_cache.ts +19 -14
  157. package/src/contract_function_simulator/index.ts +1 -0
  158. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +8 -8
  159. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +1 -4
  160. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +3 -9
  161. package/src/contract_function_simulator/oracle/interfaces.ts +69 -60
  162. package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +98 -0
  163. package/src/contract_function_simulator/oracle/oracle.ts +245 -144
  164. package/src/contract_function_simulator/oracle/private_execution.ts +4 -4
  165. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +134 -179
  166. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +403 -138
  167. package/src/contract_logging.ts +52 -0
  168. package/src/contract_sync/contract_sync_service.ts +170 -0
  169. package/src/contract_sync/{index.ts → helpers.ts} +22 -22
  170. package/src/debug/pxe_debug_utils.ts +48 -18
  171. package/src/entrypoints/client/bundle/index.ts +2 -0
  172. package/src/entrypoints/client/bundle/utils.ts +9 -1
  173. package/src/entrypoints/client/lazy/index.ts +2 -0
  174. package/src/entrypoints/client/lazy/utils.ts +9 -1
  175. package/src/entrypoints/server/index.ts +2 -1
  176. package/src/entrypoints/server/utils.ts +7 -7
  177. package/src/events/event_service.ts +17 -4
  178. package/src/logs/log_service.ts +74 -66
  179. package/src/messages/message_context_service.ts +44 -0
  180. package/src/notes/note_service.ts +19 -8
  181. package/src/notes_filter.ts +24 -0
  182. package/src/oracle_version.ts +3 -3
  183. package/src/private_kernel/hints/{compute_tx_include_by_timestamp.ts → compute_tx_expiration_timestamp.ts} +13 -13
  184. package/src/private_kernel/hints/index.ts +1 -1
  185. package/src/private_kernel/hints/private_kernel_reset_private_inputs_builder.ts +164 -117
  186. package/src/private_kernel/hints/test_utils.ts +325 -0
  187. package/src/private_kernel/private_kernel_execution_prover.ts +19 -12
  188. package/src/private_kernel/private_kernel_oracle.ts +7 -7
  189. package/src/pxe.ts +229 -124
  190. package/src/storage/capsule_store/capsule_service.ts +90 -0
  191. package/src/storage/capsule_store/capsule_store.ts +34 -26
  192. package/src/storage/capsule_store/index.ts +1 -0
  193. package/src/storage/contract_store/contract_store.ts +174 -75
  194. package/src/storage/metadata.ts +1 -1
  195. package/src/storage/note_store/note_store.ts +9 -5
  196. package/src/storage/tagging_store/recipient_tagging_store.ts +9 -5
  197. package/src/storage/tagging_store/sender_tagging_store.ts +185 -138
  198. package/src/tagging/get_all_logs_by_tags.ts +28 -4
  199. package/src/tagging/index.ts +2 -2
  200. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +7 -10
  201. package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +2 -2
  202. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +10 -15
  203. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +23 -10
  204. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +26 -11
  205. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +27 -26
  206. package/dest/contract_sync/index.d.ts +0 -23
  207. package/dest/contract_sync/index.d.ts.map +0 -1
  208. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +0 -4
  209. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +0 -1
package/src/pxe.ts CHANGED
@@ -33,6 +33,7 @@ import type {
33
33
  PrivateKernelTailCircuitPublicInputs,
34
34
  } from '@aztec/stdlib/kernel';
35
35
  import {
36
+ BlockHeader,
36
37
  type ContractOverrides,
37
38
  type InTx,
38
39
  PrivateExecutionResult,
@@ -46,7 +47,7 @@ import {
46
47
  TxProfileResult,
47
48
  TxProvingResult,
48
49
  TxSimulationResult,
49
- UtilitySimulationResult,
50
+ UtilityExecutionResult,
50
51
  } from '@aztec/stdlib/tx';
51
52
 
52
53
  import { inspect } from 'util';
@@ -59,11 +60,14 @@ import {
59
60
  generateSimulatedProvingResult,
60
61
  } from './contract_function_simulator/contract_function_simulator.js';
61
62
  import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
62
- import { ensureContractSynced, readCurrentClassId } from './contract_sync/index.js';
63
+ import { displayDebugLogs } from './contract_logging.js';
64
+ import { ContractSyncService } from './contract_sync/contract_sync_service.js';
65
+ import { readCurrentClassId } from './contract_sync/helpers.js';
63
66
  import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
64
67
  import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
65
68
  import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
66
69
  import { JobCoordinator } from './job_coordinator/job_coordinator.js';
70
+ import { MessageContextService } from './messages/message_context_service.js';
67
71
  import {
68
72
  PrivateKernelExecutionProver,
69
73
  type PrivateKernelExecutionProverConfig,
@@ -84,6 +88,58 @@ export type PackedPrivateEvent = InTx & {
84
88
  eventSelector: EventSelector;
85
89
  };
86
90
 
91
+ /** Options for PXE.profileTx. */
92
+ export type ProfileTxOpts = {
93
+ /** The profiling mode to use. */
94
+ profileMode: 'full' | 'execution-steps' | 'gates';
95
+ /** If true, proof generation is skipped during profiling. Defaults to true. */
96
+ skipProofGeneration?: boolean;
97
+ /** Addresses whose private state and keys are accessible during private execution. */
98
+ scopes: AztecAddress[];
99
+ };
100
+
101
+ /** Options for PXE.simulateTx. */
102
+ export type SimulateTxOpts = {
103
+ /** Whether to simulate the public part of the transaction. */
104
+ simulatePublic: boolean;
105
+ /** If false, this function throws if the transaction is unable to be included in a block at the current state. */
106
+ skipTxValidation?: boolean;
107
+ /** If false, fees are enforced. */
108
+ skipFeeEnforcement?: boolean;
109
+ /** If true, kernel logic is emulated in TS for simulation */
110
+ skipKernels?: boolean;
111
+ /** State overrides for the simulation, such as contract instances and artifacts. Requires skipKernels: true */
112
+ overrides?: SimulationOverrides;
113
+ /** Addresses whose private state and keys are accessible during private execution */
114
+ scopes: AztecAddress[];
115
+ };
116
+
117
+ /** Options for PXE.executeUtility. */
118
+ export type ExecuteUtilityOpts = {
119
+ /** The authentication witnesses required for the function call. */
120
+ authwits?: AuthWitness[];
121
+ /** The accounts whose notes we can access in this call */
122
+ scopes: AztecAddress[];
123
+ };
124
+
125
+ /** Args for PXE.create. */
126
+ export type PXECreateArgs = {
127
+ /** The Aztec node to connect to. */
128
+ node: AztecNode;
129
+ /** The key-value store for persisting PXE state. */
130
+ store: AztecAsyncKVStore;
131
+ /** The prover for generating private kernel proofs. */
132
+ proofCreator: PrivateKernelProver;
133
+ /** The circuit simulator for executing ACIR circuits. */
134
+ simulator: CircuitSimulator;
135
+ /** Provider for protocol contract artifacts and instances. */
136
+ protocolContractsProvider: ProtocolContractsProvider;
137
+ /** PXE configuration options. */
138
+ config: PXEConfig;
139
+ /** Optional logger instance or string suffix for the logger name. */
140
+ loggerOrSuffix?: string | Logger;
141
+ };
142
+
87
143
  /**
88
144
  * Private eXecution Environment (PXE) is a library used by wallets to simulate private phase of transactions and to
89
145
  * manage private state of users.
@@ -91,6 +147,7 @@ export type PackedPrivateEvent = InTx & {
91
147
  export class PXE {
92
148
  private constructor(
93
149
  private node: AztecNode,
150
+ private db: AztecAsyncKVStore,
94
151
  private blockStateSynchronizer: BlockSynchronizer,
95
152
  private keyStore: KeyStore,
96
153
  private contractStore: ContractStore,
@@ -102,6 +159,8 @@ export class PXE {
102
159
  private recipientTaggingStore: RecipientTaggingStore,
103
160
  private addressStore: AddressStore,
104
161
  private privateEventStore: PrivateEventStore,
162
+ private contractSyncService: ContractSyncService,
163
+ private messageContextService: MessageContextService,
105
164
  private simulator: CircuitSimulator,
106
165
  private proverEnabled: boolean,
107
166
  private proofCreator: PrivateKernelProver,
@@ -119,15 +178,15 @@ export class PXE {
119
178
  *
120
179
  * @returns A promise that resolves PXE is ready to be used.
121
180
  */
122
- public static async create(
123
- node: AztecNode,
124
- store: AztecAsyncKVStore,
125
- proofCreator: PrivateKernelProver,
126
- simulator: CircuitSimulator,
127
- protocolContractsProvider: ProtocolContractsProvider,
128
- config: PXEConfig,
129
- loggerOrSuffix?: string | Logger,
130
- ) {
181
+ public static async create({
182
+ node,
183
+ store,
184
+ proofCreator,
185
+ simulator,
186
+ protocolContractsProvider,
187
+ config,
188
+ loggerOrSuffix,
189
+ }: PXECreateArgs) {
131
190
  // Extract bindings from the logger, or use empty bindings if a string suffix is provided.
132
191
  const bindings: LoggerBindings | undefined =
133
192
  loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
@@ -137,7 +196,9 @@ export class PXE {
137
196
  ? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
138
197
  : loggerOrSuffix;
139
198
 
140
- const proverEnabled = !!config.proverEnabled;
199
+ const info = await node.getNodeInfo();
200
+
201
+ const proverEnabled = config.proverEnabled !== undefined ? config.proverEnabled : info.realProofs;
141
202
  const addressStore = new AddressStore(store);
142
203
  const privateEventStore = new PrivateEventStore(store);
143
204
  const contractStore = new ContractStore(store);
@@ -149,6 +210,14 @@ export class PXE {
149
210
  const capsuleStore = new CapsuleStore(store);
150
211
  const keyStore = new KeyStore(store);
151
212
  const tipsStore = new L2TipsKVStore(store, 'pxe');
213
+ const contractSyncService = new ContractSyncService(
214
+ node,
215
+ contractStore,
216
+ noteStore,
217
+ createLogger('pxe:contract_sync', bindings),
218
+ );
219
+ const messageContextService = new MessageContextService(node);
220
+
152
221
  const synchronizer = new BlockSynchronizer(
153
222
  node,
154
223
  store,
@@ -156,6 +225,7 @@ export class PXE {
156
225
  noteStore,
157
226
  privateEventStore,
158
227
  tipsStore,
228
+ contractSyncService,
159
229
  config,
160
230
  bindings,
161
231
  );
@@ -167,14 +237,16 @@ export class PXE {
167
237
  recipientTaggingStore,
168
238
  privateEventStore,
169
239
  noteStore,
240
+ contractSyncService,
170
241
  ]);
171
242
 
172
- const debugUtils = new PXEDebugUtils(contractStore, noteStore, synchronizer, anchorBlockStore);
243
+ const debugUtils = new PXEDebugUtils(contractSyncService, noteStore, synchronizer, anchorBlockStore);
173
244
 
174
245
  const jobQueue = new SerialQueue();
175
246
 
176
247
  const pxe = new PXE(
177
248
  node,
249
+ store,
178
250
  synchronizer,
179
251
  keyStore,
180
252
  contractStore,
@@ -186,6 +258,8 @@ export class PXE {
186
258
  recipientTaggingStore,
187
259
  addressStore,
188
260
  privateEventStore,
261
+ contractSyncService,
262
+ messageContextService,
189
263
  simulator,
190
264
  proverEnabled,
191
265
  proofCreator,
@@ -196,12 +270,15 @@ export class PXE {
196
270
  debugUtils,
197
271
  );
198
272
 
199
- debugUtils.setPXE(pxe, pxe.#putInJobQueue.bind(pxe));
273
+ debugUtils.setPXEHelpers(
274
+ pxe.#putInJobQueue.bind(pxe),
275
+ pxe.#getSimulatorForTx.bind(pxe),
276
+ pxe.#executeUtility.bind(pxe),
277
+ );
200
278
 
201
279
  pxe.jobQueue.start();
202
280
 
203
281
  await pxe.#registerProtocolContracts();
204
- const info = await node.getNodeInfo();
205
282
  log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
206
283
  return pxe;
207
284
  }
@@ -211,19 +288,21 @@ export class PXE {
211
288
  #getSimulatorForTx(overrides?: { contracts?: ContractOverrides }) {
212
289
  const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
213
290
 
214
- return new ContractFunctionSimulator(
215
- proxyContractStore,
216
- this.noteStore,
217
- this.keyStore,
218
- this.addressStore,
219
- BenchmarkedNodeFactory.create(this.node),
220
- this.senderTaggingStore,
221
- this.recipientTaggingStore,
222
- this.senderAddressBookStore,
223
- this.capsuleStore,
224
- this.privateEventStore,
225
- this.simulator,
226
- );
291
+ return new ContractFunctionSimulator({
292
+ contractStore: proxyContractStore,
293
+ noteStore: this.noteStore,
294
+ keyStore: this.keyStore,
295
+ addressStore: this.addressStore,
296
+ aztecNode: BenchmarkedNodeFactory.create(this.node),
297
+ senderTaggingStore: this.senderTaggingStore,
298
+ recipientTaggingStore: this.recipientTaggingStore,
299
+ senderAddressBookStore: this.senderAddressBookStore,
300
+ capsuleStore: this.capsuleStore,
301
+ privateEventStore: this.privateEventStore,
302
+ simulator: this.simulator,
303
+ contractSyncService: this.contractSyncService,
304
+ messageContextService: this.messageContextService,
305
+ });
227
306
  }
228
307
 
229
308
  #contextualizeError(err: Error, ...context: string[]): Error {
@@ -275,9 +354,8 @@ export class PXE {
275
354
  async #registerProtocolContracts() {
276
355
  const registered: Record<string, string> = {};
277
356
  for (const name of protocolContractNames) {
278
- const { address, contractClass, instance, artifact } =
279
- await this.protocolContractsProvider.getProtocolContractArtifact(name);
280
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
357
+ const { address, instance, artifact } = await this.protocolContractsProvider.getProtocolContractArtifact(name);
358
+ await this.contractStore.addContractArtifact(artifact);
281
359
  await this.contractStore.addContractInstance(instance);
282
360
  registered[name] = address.toString();
283
361
  }
@@ -289,7 +367,7 @@ export class PXE {
289
367
  async #executePrivate(
290
368
  contractFunctionSimulator: ContractFunctionSimulator,
291
369
  txRequest: TxExecutionRequest,
292
- scopes: AztecAddress[] | undefined,
370
+ scopes: AztecAddress[],
293
371
  jobId: string,
294
372
  ): Promise<PrivateExecutionResult> {
295
373
  const { origin: contractAddress, functionSelector } = txRequest;
@@ -297,27 +375,23 @@ export class PXE {
297
375
  try {
298
376
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
299
377
 
300
- await ensureContractSynced(
378
+ await this.contractSyncService.ensureContractSynced(
301
379
  contractAddress,
302
380
  functionSelector,
303
- privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
304
- this.node,
305
- this.contractStore,
381
+ (privateSyncCall, execScopes) =>
382
+ this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
306
383
  anchorBlockHeader,
384
+ jobId,
385
+ scopes,
307
386
  );
308
387
 
309
- const result = await contractFunctionSimulator.run(
310
- txRequest,
388
+ const result = await contractFunctionSimulator.run(txRequest, {
311
389
  contractAddress,
312
- functionSelector,
313
- undefined,
390
+ selector: functionSelector,
314
391
  anchorBlockHeader,
315
- // The sender for tags is set by contracts, typically by an account
316
- // contract entrypoint
317
- undefined, // senderForTags
318
392
  scopes,
319
393
  jobId,
320
- );
394
+ });
321
395
  this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
322
396
  return result;
323
397
  } catch (err) {
@@ -329,25 +403,32 @@ export class PXE {
329
403
  }
330
404
 
331
405
  /**
332
- * Simulate a utility function call on the given contract.
406
+ * Execute a utility function call on the given contract.
333
407
  * @param contractFunctionSimulator - The simulator to use for the function call.
334
408
  * @param call - The function call to execute.
335
409
  * @param authWitnesses - Authentication witnesses required for the function call.
336
410
  * @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
337
411
  * accounts if not specified.
338
412
  * @param jobId - The job ID for staged writes.
339
- * @returns The simulation result containing the outputs of the utility function.
413
+ * @returns The execution result containing the outputs of the utility function.
340
414
  */
341
- async #simulateUtility(
415
+ async #executeUtility(
342
416
  contractFunctionSimulator: ContractFunctionSimulator,
343
417
  call: FunctionCall,
344
418
  authWitnesses: AuthWitness[] | undefined,
345
- scopes: AztecAddress[] | undefined,
419
+ scopes: AztecAddress[],
346
420
  jobId: string,
347
421
  ) {
348
422
  try {
349
423
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
350
- return contractFunctionSimulator.runUtility(call, authWitnesses ?? [], anchorBlockHeader, scopes, jobId);
424
+ const { result, offchainEffects } = await contractFunctionSimulator.runUtility(
425
+ call,
426
+ authWitnesses ?? [],
427
+ anchorBlockHeader,
428
+ scopes,
429
+ jobId,
430
+ );
431
+ return { result, offchainEffects };
351
432
  } catch (err) {
352
433
  if (err instanceof SimulationError) {
353
434
  await enrichSimulationError(err, this.contractStore, this.log);
@@ -415,6 +496,21 @@ export class PXE {
415
496
 
416
497
  // Public API
417
498
 
499
+ /**
500
+ * Returns the block header up to which the PXE has synced.
501
+ * @returns The synced block header
502
+ */
503
+ public getSyncedBlockHeader(): Promise<BlockHeader> {
504
+ return this.#putInJobQueue(() => {
505
+ return this.anchorBlockStore.getBlockHeader();
506
+ });
507
+ }
508
+
509
+ /**
510
+ * Returns the contract instance for a given address, if it's registered in the PXE.
511
+ * @param address - The contract address.
512
+ * @returns The contract instance if found, undefined otherwise.
513
+ */
418
514
  public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
419
515
  return this.contractStore.getContractInstance(address);
420
516
  }
@@ -474,6 +570,9 @@ export class PXE {
474
570
 
475
571
  if (wasAdded) {
476
572
  this.log.info(`Added sender:\n ${sender.toString()}`);
573
+ // Wipe the entire sync cache: the new sender's tagged logs could contain notes/events for any contract, so
574
+ // all contracts must re-sync to discover them.
575
+ this.contractSyncService.wipe();
477
576
  } else {
478
577
  this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
479
578
  }
@@ -523,8 +622,7 @@ export class PXE {
523
622
  * @param artifact - The build artifact for the contract class.
524
623
  */
525
624
  public async registerContractClass(artifact: ContractArtifact): Promise<void> {
526
- const { id: contractClassId } = await getContractClassFromArtifact(artifact);
527
- await this.contractStore.addContractArtifact(contractClassId, artifact);
625
+ const contractClassId = await this.contractStore.addContractArtifact(artifact);
528
626
  this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
529
627
  }
530
628
 
@@ -543,17 +641,17 @@ export class PXE {
543
641
  if (artifact) {
544
642
  // If the user provides an artifact, validate it against the expected class id and register it
545
643
  const contractClass = await getContractClassFromArtifact(artifact);
546
- const contractClassId = contractClass.id;
547
- if (!contractClassId.equals(instance.currentContractClassId)) {
644
+ if (!contractClass.id.equals(instance.currentContractClassId)) {
548
645
  throw new Error(
549
- `Artifact does not match expected class id (computed ${contractClassId} but instance refers to ${instance.currentContractClassId})`,
646
+ `Artifact does not match expected class id (computed ${contractClass.id} but instance refers to ${instance.currentContractClassId})`,
550
647
  );
551
648
  }
552
649
  const computedAddress = await computeContractAddressFromInstance(instance);
553
650
  if (!computedAddress.equals(instance.address)) {
554
651
  throw new Error('Added a contract in which the address does not match the contract instance.');
555
652
  }
556
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
653
+
654
+ await this.contractStore.addContractArtifact(artifact, contractClass);
557
655
 
558
656
  const publicFunctionSignatures = artifact.functions
559
657
  .filter(fn => fn.functionType === FunctionType.PUBLIC)
@@ -602,15 +700,16 @@ export class PXE {
602
700
  throw new Error('Could not update contract to a class different from the current one.');
603
701
  }
604
702
 
605
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
606
-
607
703
  const publicFunctionSignatures = artifact.functions
608
704
  .filter(fn => fn.functionType === FunctionType.PUBLIC)
609
705
  .map(fn => decodeFunctionSignature(fn.name, fn.parameters));
610
706
  await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
611
707
 
612
708
  currentInstance.currentContractClassId = contractClass.id;
613
- await this.contractStore.addContractInstance(currentInstance);
709
+ await Promise.all([
710
+ this.contractStore.addContractArtifact(artifact, contractClass),
711
+ this.contractStore.addContractInstance(currentInstance),
712
+ ]);
614
713
  this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
615
714
  });
616
715
  }
@@ -628,11 +727,12 @@ export class PXE {
628
727
  * (where validators prove the public portion).
629
728
  *
630
729
  * @param txRequest - An authenticated tx request ready for proving
730
+ * @param scopes - Addresses whose private state and keys are accessible during private execution.
631
731
  * @returns A result containing the proof and public inputs of the tail circuit.
632
732
  * @throws If contract code not found, or public simulation reverts.
633
733
  * Also throws if simulatePublic is true and public simulation reverts.
634
734
  */
635
- public proveTx(txRequest: TxExecutionRequest): Promise<TxProvingResult> {
735
+ public proveTx(txRequest: TxExecutionRequest, scopes: AztecAddress[]): Promise<TxProvingResult> {
636
736
  let privateExecutionResult: PrivateExecutionResult;
637
737
  // We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
638
738
  // computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
@@ -643,7 +743,7 @@ export class PXE {
643
743
  await this.blockStateSynchronizer.sync();
644
744
  const syncTime = syncTimer.ms();
645
745
  const contractFunctionSimulator = this.#getSimulatorForTx();
646
- privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, undefined, jobId);
746
+ privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
647
747
 
648
748
  const {
649
749
  publicInputs,
@@ -685,17 +785,17 @@ export class PXE {
685
785
  // transaction before this one is included in a block from this PXE, and that transaction contains a log with
686
786
  // a tag derived from the same secret, we would reuse the tag and the transactions would be linked. Hence
687
787
  // storing the tags here prevents linkage of txs sent from the same PXE.
688
- const preTagsUsedInTheTx = privateExecutionResult.entrypoint.preTags;
689
- if (preTagsUsedInTheTx.length > 0) {
788
+ const taggingIndexRangesUsedInTheTx = privateExecutionResult.entrypoint.taggingIndexRanges;
789
+ if (taggingIndexRangesUsedInTheTx.length > 0) {
690
790
  // TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
691
791
  const txHash = (await txProvingResult.toTx()).txHash;
692
792
 
693
- await this.senderTaggingStore.storePendingIndexes(preTagsUsedInTheTx, txHash, jobId);
694
- this.log.debug(`Stored used pre-tags as sender for the tx`, {
695
- preTagsUsedInTheTx,
793
+ await this.senderTaggingStore.storePendingIndexes(taggingIndexRangesUsedInTheTx, txHash, jobId);
794
+ this.log.debug(`Stored used tagging index ranges as sender for the tx`, {
795
+ taggingIndexRangesUsedInTheTx,
696
796
  });
697
797
  } else {
698
- this.log.debug(`No pre-tags used in the tx`);
798
+ this.log.debug(`No tagging index ranges used in the tx`);
699
799
  }
700
800
 
701
801
  return txProvingResult;
@@ -707,17 +807,13 @@ export class PXE {
707
807
 
708
808
  /**
709
809
  * Profiles a transaction, reporting gate counts (unless disabled) and returns an execution trace.
710
- *
711
- * @param txRequest - An authenticated tx request ready for simulation
712
- * @param msgSender - (Optional) The message sender to use for the simulation.
713
- * @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
810
+ * @param txRequest - An authenticated tx request ready for simulation.
714
811
  * @returns A trace of the program execution with gate counts.
715
812
  * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
716
813
  */
717
814
  public profileTx(
718
815
  txRequest: TxExecutionRequest,
719
- profileMode: 'full' | 'execution-steps' | 'gates',
720
- skipProofGeneration: boolean = true,
816
+ { profileMode, skipProofGeneration = true, scopes }: ProfileTxOpts,
721
817
  ): Promise<TxProfileResult> {
722
818
  // We disable concurrent profiles for consistency with simulateTx.
723
819
  return this.#putInJobQueue(async jobId => {
@@ -740,12 +836,7 @@ export class PXE {
740
836
  const syncTime = syncTimer.ms();
741
837
 
742
838
  const contractFunctionSimulator = this.#getSimulatorForTx();
743
- const privateExecutionResult = await this.#executePrivate(
744
- contractFunctionSimulator,
745
- txRequest,
746
- undefined,
747
- jobId,
748
- );
839
+ const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
749
840
 
750
841
  const { executionSteps, timings: { proving } = {} } = await this.#prove(
751
842
  txRequest,
@@ -802,12 +893,7 @@ export class PXE {
802
893
  * In that case, the transaction returned is only potentially ready to be sent to the network for execution.
803
894
  *
804
895
  *
805
- * @param txRequest - An authenticated tx request ready for simulation
806
- * @param simulatePublic - Whether to simulate the public part of the transaction.
807
- * @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
808
- * @param skipFeeEnforcement - (Optional) If false, fees are enforced.
809
- * @param overrides - (Optional) State overrides for the simulation, such as msgSender, contract instances and artifacts.
810
- * @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will default to all.
896
+ * @param txRequest - An authenticated tx request ready for simulation.
811
897
  * @returns A simulated transaction result object that includes public and private return values.
812
898
  * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
813
899
  * Also throws if simulatePublic is true and public simulation reverts.
@@ -816,11 +902,14 @@ export class PXE {
816
902
  */
817
903
  public simulateTx(
818
904
  txRequest: TxExecutionRequest,
819
- simulatePublic: boolean,
820
- skipTxValidation: boolean = false,
821
- skipFeeEnforcement: boolean = false,
822
- overrides?: SimulationOverrides,
823
- scopes?: AztecAddress[],
905
+ {
906
+ simulatePublic,
907
+ skipTxValidation = false,
908
+ skipFeeEnforcement = false,
909
+ skipKernels = true,
910
+ overrides,
911
+ scopes,
912
+ }: SimulateTxOpts,
824
913
  ): Promise<TxSimulationResult> {
825
914
  // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
826
915
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
@@ -844,11 +933,21 @@ export class PXE {
844
933
  await this.blockStateSynchronizer.sync();
845
934
  const syncTime = syncTimer.ms();
846
935
 
936
+ const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
937
+ const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
938
+
939
+ if (hasOverriddenContracts && !skipKernels) {
940
+ throw new Error(
941
+ 'Simulating with overridden contracts is not compatible with kernel execution. Please set skipKernels to true when simulating with overridden contracts.',
942
+ );
943
+ }
847
944
  const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
848
- // Temporary: in case there are overrides, we have to skip the kernels or validations
849
- // will fail. Consider handing control to the user/wallet on whether they want to run them
850
- // or not.
851
- const skipKernels = overrides?.contracts !== undefined && Object.keys(overrides.contracts ?? {}).length > 0;
945
+
946
+ if (hasOverriddenContracts) {
947
+ // Overridden contracts don't have a sync function, so calling sync on them would fail.
948
+ // We exclude them so the sync service skips them entirely.
949
+ this.contractSyncService.setExcludedFromSync(jobId, overriddenContracts);
950
+ }
852
951
 
853
952
  // Execution of private functions only; no proving, and no kernel logic.
854
953
  const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
@@ -859,7 +958,8 @@ export class PXE {
859
958
  if (skipKernels) {
860
959
  ({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
861
960
  privateExecutionResult,
862
- this.contractStore,
961
+ (addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
962
+ this.node,
863
963
  ));
864
964
  } else {
865
965
  // Kernel logic, plus proving of all private functions and kernels.
@@ -878,6 +978,9 @@ export class PXE {
878
978
  const publicSimulationTimer = new Timer();
879
979
  publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement);
880
980
  publicSimulationTime = publicSimulationTimer.ms();
981
+ if (publicOutput?.debugLogs?.length) {
982
+ await displayDebugLogs(publicOutput.debugLogs, addr => this.contractStore.getDebugContractName(addr));
983
+ }
881
984
  }
882
985
 
883
986
  let validationTime: number | undefined;
@@ -886,7 +989,8 @@ export class PXE {
886
989
  const validationResult = await this.node.isValidTx(simulatedTx, { isSimulation: true, skipFeeEnforcement });
887
990
  validationTime = validationTimer.ms();
888
991
  if (validationResult.result === 'invalid') {
889
- throw new Error('The simulated transaction is unable to be added to state and is invalid.');
992
+ const reason = validationResult.reason.length > 0 ? ` Reason: ${validationResult.reason.join(', ')}` : '';
993
+ throw new Error(`The simulated transaction is unable to be added to state and is invalid.${reason}`);
890
994
  }
891
995
  }
892
996
 
@@ -937,29 +1041,23 @@ export class PXE {
937
1041
  inspect(txRequest),
938
1042
  `simulatePublic=${simulatePublic}`,
939
1043
  `skipTxValidation=${skipTxValidation}`,
940
- `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
1044
+ `scopes=${scopes.map(s => s.toString()).join(', ')}`,
941
1045
  );
942
1046
  }
943
1047
  });
944
1048
  }
945
1049
 
946
1050
  /**
947
- * Simulate the execution of a contract utility function.
948
- *
1051
+ * Executes a contract utility function.
949
1052
  * @param call - The function call containing the function details, arguments, and target contract address.
950
- * @param authwits - (Optional) The authentication witnesses required for the function call.
951
- * @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will
952
- * default to all.
953
- * @returns The result of the utility function call, structured based on the function ABI.
954
1053
  */
955
- public simulateUtility(
1054
+ public executeUtility(
956
1055
  call: FunctionCall,
957
- authwits?: AuthWitness[],
958
- scopes?: AztecAddress[],
959
- ): Promise<UtilitySimulationResult> {
960
- // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
1056
+ { authwits, scopes }: ExecuteUtilityOpts = { scopes: [] },
1057
+ ): Promise<UtilityExecutionResult> {
1058
+ // We disable concurrent executions since those might execute oracles which read and write to the PXE stores (e.g.
961
1059
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
962
- // delete the same read value, or reading values that another simulation is currently modifying).
1060
+ // delete the same read value, or reading values that another execution is currently modifying).
963
1061
  return this.#putInJobQueue(async jobId => {
964
1062
  try {
965
1063
  const totalTimer = new Timer();
@@ -970,16 +1068,17 @@ export class PXE {
970
1068
  const contractFunctionSimulator = this.#getSimulatorForTx();
971
1069
 
972
1070
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
973
- await ensureContractSynced(
1071
+ await this.contractSyncService.ensureContractSynced(
974
1072
  call.to,
975
1073
  call.selector,
976
- privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
977
- this.node,
978
- this.contractStore,
1074
+ (privateSyncCall, execScopes) =>
1075
+ this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
979
1076
  anchorBlockHeader,
1077
+ jobId,
1078
+ scopes,
980
1079
  );
981
1080
 
982
- const executionResult = await this.#simulateUtility(
1081
+ const { result: executionResult, offchainEffects } = await this.#executeUtility(
983
1082
  contractFunctionSimulator,
984
1083
  call,
985
1084
  authwits ?? [],
@@ -1000,14 +1099,19 @@ export class PXE {
1000
1099
  };
1001
1100
 
1002
1101
  const simulationStats = contractFunctionSimulator.getStats();
1003
- return { result: executionResult, stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls } };
1102
+ return {
1103
+ result: executionResult,
1104
+ offchainEffects,
1105
+ anchorBlockTimestamp: anchorBlockHeader.globalVariables.timestamp,
1106
+ stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls },
1107
+ };
1004
1108
  } catch (err: any) {
1005
1109
  const { to, name, args } = call;
1006
1110
  const stringifiedArgs = args.map(arg => arg.toString()).join(', ');
1007
1111
  throw this.#contextualizeError(
1008
1112
  err,
1009
- `simulateUtility ${to}:${name}(${stringifiedArgs})`,
1010
- `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
1113
+ `executeUtility ${to}:${name}(${stringifiedArgs})`,
1114
+ `scopes=${scopes.map(s => s.toString()).join(', ')}`,
1011
1115
  );
1012
1116
  }
1013
1117
  });
@@ -1040,14 +1144,14 @@ export class PXE {
1040
1144
 
1041
1145
  const contractFunctionSimulator = this.#getSimulatorForTx();
1042
1146
 
1043
- await ensureContractSynced(
1147
+ await this.contractSyncService.ensureContractSynced(
1044
1148
  filter.contractAddress,
1045
1149
  null,
1046
- async privateSyncCall =>
1047
- await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
1048
- this.node,
1049
- this.contractStore,
1150
+ async (privateSyncCall, execScopes) =>
1151
+ await this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
1050
1152
  anchorBlockHeader,
1153
+ jobId,
1154
+ filter.scopes,
1051
1155
  );
1052
1156
  });
1053
1157
 
@@ -1062,9 +1166,10 @@ export class PXE {
1062
1166
  }
1063
1167
 
1064
1168
  /**
1065
- * Stops the PXE's job queue.
1169
+ * Stops the PXE's job queue and closes the backing store.
1066
1170
  */
1067
- public stop(): Promise<void> {
1068
- return this.jobQueue.end();
1171
+ public async stop(): Promise<void> {
1172
+ await this.jobQueue.end();
1173
+ await this.db.close();
1069
1174
  }
1070
1175
  }