@aztec/pxe 0.0.1-commit.0b941701 → 0.0.1-commit.10bd49492

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 (237) hide show
  1. package/dest/access_scopes.d.ts +9 -0
  2. package/dest/access_scopes.d.ts.map +1 -0
  3. package/dest/access_scopes.js +6 -0
  4. package/dest/block_synchronizer/block_synchronizer.d.ts +5 -3
  5. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
  6. package/dest/block_synchronizer/block_synchronizer.js +11 -5
  7. package/dest/config/index.d.ts +2 -2
  8. package/dest/config/index.d.ts.map +1 -1
  9. package/dest/config/index.js +1 -1
  10. package/dest/config/package_info.js +1 -1
  11. package/dest/contract_function_simulator/contract_function_simulator.d.ts +57 -30
  12. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  13. package/dest/contract_function_simulator/contract_function_simulator.js +181 -73
  14. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +7 -7
  15. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -1
  16. package/dest/contract_function_simulator/execution_tagging_index_cache.js +19 -11
  17. package/dest/contract_function_simulator/index.d.ts +2 -1
  18. package/dest/contract_function_simulator/index.d.ts.map +1 -1
  19. package/dest/contract_function_simulator/index.js +1 -0
  20. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +2 -3
  21. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
  22. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +5 -4
  23. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +1 -1
  24. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
  25. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +1 -3
  26. package/dest/contract_function_simulator/noir-structs/message_tx_context.d.ts +16 -0
  27. package/dest/contract_function_simulator/noir-structs/message_tx_context.d.ts.map +1 -0
  28. package/dest/contract_function_simulator/noir-structs/message_tx_context.js +57 -0
  29. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +2 -4
  30. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
  31. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +3 -5
  32. package/dest/contract_function_simulator/oracle/interfaces.d.ts +50 -46
  33. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  34. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts +9 -0
  35. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts.map +1 -0
  36. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.js +52 -0
  37. package/dest/contract_function_simulator/oracle/oracle.d.ts +44 -44
  38. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  39. package/dest/contract_function_simulator/oracle/oracle.js +170 -110
  40. package/dest/contract_function_simulator/oracle/private_execution.js +3 -3
  41. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +58 -72
  42. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  43. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +104 -77
  44. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +82 -52
  45. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  46. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +153 -96
  47. package/dest/contract_logging.d.ts +22 -0
  48. package/dest/contract_logging.d.ts.map +1 -0
  49. package/dest/contract_logging.js +23 -0
  50. package/dest/contract_sync/contract_sync_service.d.ts +43 -0
  51. package/dest/contract_sync/contract_sync_service.d.ts.map +1 -0
  52. package/dest/contract_sync/contract_sync_service.js +97 -0
  53. package/dest/contract_sync/helpers.d.ts +29 -0
  54. package/dest/contract_sync/helpers.d.ts.map +1 -0
  55. package/dest/contract_sync/{index.js → helpers.js} +13 -12
  56. package/dest/debug/pxe_debug_utils.d.ts +24 -10
  57. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  58. package/dest/debug/pxe_debug_utils.js +28 -18
  59. package/dest/entrypoints/client/bundle/index.d.ts +4 -1
  60. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  61. package/dest/entrypoints/client/bundle/index.js +3 -0
  62. package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
  63. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  64. package/dest/entrypoints/client/bundle/utils.js +21 -7
  65. package/dest/entrypoints/client/lazy/index.d.ts +4 -1
  66. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  67. package/dest/entrypoints/client/lazy/index.js +3 -0
  68. package/dest/entrypoints/client/lazy/utils.d.ts +2 -2
  69. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  70. package/dest/entrypoints/client/lazy/utils.js +22 -8
  71. package/dest/entrypoints/pxe_creation_options.d.ts +3 -2
  72. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  73. package/dest/entrypoints/server/index.d.ts +4 -2
  74. package/dest/entrypoints/server/index.d.ts.map +1 -1
  75. package/dest/entrypoints/server/index.js +3 -1
  76. package/dest/entrypoints/server/utils.d.ts +1 -1
  77. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  78. package/dest/entrypoints/server/utils.js +28 -9
  79. package/dest/events/event_service.d.ts +4 -5
  80. package/dest/events/event_service.d.ts.map +1 -1
  81. package/dest/events/event_service.js +5 -6
  82. package/dest/job_coordinator/job_coordinator.d.ts +3 -2
  83. package/dest/job_coordinator/job_coordinator.d.ts.map +1 -1
  84. package/dest/job_coordinator/job_coordinator.js +3 -2
  85. package/dest/logs/log_service.d.ts +7 -5
  86. package/dest/logs/log_service.d.ts.map +1 -1
  87. package/dest/logs/log_service.js +19 -29
  88. package/dest/messages/message_context_service.d.ts +17 -0
  89. package/dest/messages/message_context_service.d.ts.map +1 -0
  90. package/dest/messages/message_context_service.js +36 -0
  91. package/dest/notes/note_service.d.ts +7 -7
  92. package/dest/notes/note_service.d.ts.map +1 -1
  93. package/dest/notes/note_service.js +9 -9
  94. package/dest/notes_filter.d.ts +25 -0
  95. package/dest/notes_filter.d.ts.map +1 -0
  96. package/dest/notes_filter.js +4 -0
  97. package/dest/oracle_version.d.ts +3 -3
  98. package/dest/oracle_version.d.ts.map +1 -1
  99. package/dest/oracle_version.js +3 -3
  100. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts +4 -0
  101. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts.map +1 -0
  102. package/dest/private_kernel/hints/{compute_tx_include_by_timestamp.js → compute_tx_expiration_timestamp.js} +12 -12
  103. package/dest/private_kernel/hints/index.d.ts +1 -1
  104. package/dest/private_kernel/hints/index.js +1 -1
  105. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +4 -3
  106. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -1
  107. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.js +129 -68
  108. package/dest/private_kernel/hints/test_utils.d.ts +122 -0
  109. package/dest/private_kernel/hints/test_utils.d.ts.map +1 -0
  110. package/dest/private_kernel/hints/test_utils.js +203 -0
  111. package/dest/private_kernel/private_kernel_execution_prover.d.ts +3 -2
  112. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  113. package/dest/private_kernel/private_kernel_execution_prover.js +21 -13
  114. package/dest/private_kernel/private_kernel_oracle.d.ts +8 -4
  115. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  116. package/dest/private_kernel/private_kernel_oracle.js +7 -3
  117. package/dest/pxe.d.ts +72 -24
  118. package/dest/pxe.d.ts.map +1 -1
  119. package/dest/pxe.js +115 -72
  120. package/dest/storage/address_store/address_store.d.ts +1 -1
  121. package/dest/storage/address_store/address_store.d.ts.map +1 -1
  122. package/dest/storage/address_store/address_store.js +12 -11
  123. package/dest/storage/anchor_block_store/anchor_block_store.d.ts +9 -1
  124. package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -1
  125. package/dest/storage/anchor_block_store/anchor_block_store.js +8 -1
  126. package/dest/storage/capsule_store/capsule_store.js +6 -8
  127. package/dest/storage/contract_store/contract_store.d.ts +42 -15
  128. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  129. package/dest/storage/contract_store/contract_store.js +157 -72
  130. package/dest/storage/metadata.d.ts +1 -1
  131. package/dest/storage/metadata.js +1 -1
  132. package/dest/storage/note_store/note_store.d.ts +13 -3
  133. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  134. package/dest/storage/note_store/note_store.js +147 -107
  135. package/dest/storage/private_event_store/private_event_store.d.ts +1 -1
  136. package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
  137. package/dest/storage/private_event_store/private_event_store.js +84 -61
  138. package/dest/storage/private_event_store/stored_private_event.d.ts +4 -4
  139. package/dest/storage/private_event_store/stored_private_event.d.ts.map +1 -1
  140. package/dest/storage/private_event_store/stored_private_event.js +2 -2
  141. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +6 -6
  142. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
  143. package/dest/storage/tagging_store/recipient_tagging_store.js +31 -19
  144. package/dest/storage/tagging_store/sender_address_book_store.d.ts +1 -1
  145. package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +1 -1
  146. package/dest/storage/tagging_store/sender_address_book_store.js +20 -14
  147. package/dest/storage/tagging_store/sender_tagging_store.d.ts +29 -28
  148. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  149. package/dest/storage/tagging_store/sender_tagging_store.js +233 -137
  150. package/dest/tagging/get_all_logs_by_tags.d.ts +4 -4
  151. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -1
  152. package/dest/tagging/get_all_logs_by_tags.js +17 -3
  153. package/dest/tagging/index.d.ts +3 -3
  154. package/dest/tagging/index.d.ts.map +1 -1
  155. package/dest/tagging/index.js +1 -1
  156. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +5 -6
  157. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
  158. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +7 -7
  159. package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +2 -2
  160. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +7 -8
  161. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
  162. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +12 -11
  163. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +5 -9
  164. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  165. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +13 -7
  166. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +4 -3
  167. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
  168. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +20 -10
  169. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +6 -8
  170. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  171. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +36 -24
  172. package/package.json +25 -16
  173. package/src/access_scopes.ts +9 -0
  174. package/src/block_synchronizer/block_synchronizer.ts +23 -19
  175. package/src/config/index.ts +1 -1
  176. package/src/config/package_info.ts +1 -1
  177. package/src/contract_function_simulator/contract_function_simulator.ts +332 -131
  178. package/src/contract_function_simulator/execution_tagging_index_cache.ts +19 -14
  179. package/src/contract_function_simulator/index.ts +1 -0
  180. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +8 -5
  181. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +1 -4
  182. package/src/contract_function_simulator/noir-structs/message_tx_context.ts +55 -0
  183. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +3 -6
  184. package/src/contract_function_simulator/oracle/interfaces.ts +61 -62
  185. package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +77 -0
  186. package/src/contract_function_simulator/oracle/oracle.ts +182 -148
  187. package/src/contract_function_simulator/oracle/private_execution.ts +3 -3
  188. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +131 -172
  189. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +238 -112
  190. package/src/contract_logging.ts +39 -0
  191. package/src/contract_sync/contract_sync_service.ts +152 -0
  192. package/src/contract_sync/{index.ts → helpers.ts} +21 -21
  193. package/src/debug/pxe_debug_utils.ts +63 -19
  194. package/src/entrypoints/client/bundle/index.ts +3 -0
  195. package/src/entrypoints/client/bundle/utils.ts +16 -15
  196. package/src/entrypoints/client/lazy/index.ts +3 -0
  197. package/src/entrypoints/client/lazy/utils.ts +17 -15
  198. package/src/entrypoints/pxe_creation_options.ts +2 -1
  199. package/src/entrypoints/server/index.ts +3 -1
  200. package/src/entrypoints/server/utils.ts +22 -26
  201. package/src/events/event_service.ts +4 -6
  202. package/src/job_coordinator/job_coordinator.ts +4 -3
  203. package/src/logs/log_service.ts +31 -38
  204. package/src/messages/message_context_service.ts +45 -0
  205. package/src/notes/note_service.ts +9 -10
  206. package/src/notes_filter.ts +26 -0
  207. package/src/oracle_version.ts +3 -3
  208. package/src/private_kernel/hints/{compute_tx_include_by_timestamp.ts → compute_tx_expiration_timestamp.ts} +13 -13
  209. package/src/private_kernel/hints/index.ts +1 -1
  210. package/src/private_kernel/hints/private_kernel_reset_private_inputs_builder.ts +164 -117
  211. package/src/private_kernel/hints/test_utils.ts +325 -0
  212. package/src/private_kernel/private_kernel_execution_prover.ts +25 -15
  213. package/src/private_kernel/private_kernel_oracle.ts +9 -9
  214. package/src/pxe.ts +209 -124
  215. package/src/storage/address_store/address_store.ts +15 -15
  216. package/src/storage/anchor_block_store/anchor_block_store.ts +8 -0
  217. package/src/storage/capsule_store/capsule_store.ts +8 -8
  218. package/src/storage/contract_store/contract_store.ts +186 -76
  219. package/src/storage/metadata.ts +1 -1
  220. package/src/storage/note_store/note_store.ts +169 -132
  221. package/src/storage/private_event_store/private_event_store.ts +102 -81
  222. package/src/storage/private_event_store/stored_private_event.ts +3 -3
  223. package/src/storage/tagging_store/recipient_tagging_store.ts +38 -24
  224. package/src/storage/tagging_store/sender_address_book_store.ts +20 -14
  225. package/src/storage/tagging_store/sender_tagging_store.ts +287 -156
  226. package/src/tagging/get_all_logs_by_tags.ts +31 -7
  227. package/src/tagging/index.ts +2 -2
  228. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +9 -12
  229. package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +2 -2
  230. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +12 -17
  231. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +25 -12
  232. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +26 -11
  233. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +30 -29
  234. package/dest/contract_sync/index.d.ts +0 -23
  235. package/dest/contract_sync/index.d.ts.map +0 -1
  236. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +0 -4
  237. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +0 -1
package/dest/pxe.js CHANGED
@@ -13,11 +13,14 @@ import { BlockSynchronizer } from './block_synchronizer/index.js';
13
13
  import { BenchmarkedNodeFactory } from './contract_function_simulator/benchmarked_node.js';
14
14
  import { ContractFunctionSimulator, generateSimulatedProvingResult } from './contract_function_simulator/contract_function_simulator.js';
15
15
  import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
16
- import { ensureContractSynced, readCurrentClassId } from './contract_sync/index.js';
16
+ import { displayDebugLogs } from './contract_logging.js';
17
+ import { ContractSyncService } from './contract_sync/contract_sync_service.js';
18
+ import { readCurrentClassId } from './contract_sync/helpers.js';
17
19
  import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
18
20
  import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
19
21
  import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
20
22
  import { JobCoordinator } from './job_coordinator/job_coordinator.js';
23
+ import { MessageContextService } from './messages/message_context_service.js';
21
24
  import { PrivateKernelExecutionProver } from './private_kernel/private_kernel_execution_prover.js';
22
25
  import { PrivateKernelOracle } from './private_kernel/private_kernel_oracle.js';
23
26
  import { AddressStore } from './storage/address_store/address_store.js';
@@ -34,6 +37,7 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
34
37
  * manage private state of users.
35
38
  */ export class PXE {
36
39
  node;
40
+ db;
37
41
  blockStateSynchronizer;
38
42
  keyStore;
39
43
  contractStore;
@@ -45,6 +49,8 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
45
49
  recipientTaggingStore;
46
50
  addressStore;
47
51
  privateEventStore;
52
+ contractSyncService;
53
+ messageContextService;
48
54
  simulator;
49
55
  proverEnabled;
50
56
  proofCreator;
@@ -53,8 +59,9 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
53
59
  jobQueue;
54
60
  jobCoordinator;
55
61
  debug;
56
- constructor(node, blockStateSynchronizer, keyStore, contractStore, noteStore, capsuleStore, anchorBlockStore, senderTaggingStore, senderAddressBookStore, recipientTaggingStore, addressStore, privateEventStore, simulator, proverEnabled, proofCreator, protocolContractsProvider, log, jobQueue, jobCoordinator, debug){
62
+ constructor(node, db, blockStateSynchronizer, keyStore, contractStore, noteStore, capsuleStore, anchorBlockStore, senderTaggingStore, senderAddressBookStore, recipientTaggingStore, addressStore, privateEventStore, contractSyncService, messageContextService, simulator, proverEnabled, proofCreator, protocolContractsProvider, log, jobQueue, jobCoordinator, debug){
57
63
  this.node = node;
64
+ this.db = db;
58
65
  this.blockStateSynchronizer = blockStateSynchronizer;
59
66
  this.keyStore = keyStore;
60
67
  this.contractStore = contractStore;
@@ -66,6 +73,8 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
66
73
  this.recipientTaggingStore = recipientTaggingStore;
67
74
  this.addressStore = addressStore;
68
75
  this.privateEventStore = privateEventStore;
76
+ this.contractSyncService = contractSyncService;
77
+ this.messageContextService = messageContextService;
69
78
  this.simulator = simulator;
70
79
  this.proverEnabled = proverEnabled;
71
80
  this.proofCreator = proofCreator;
@@ -81,9 +90,12 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
81
90
  * can be contacted.
82
91
  *
83
92
  * @returns A promise that resolves PXE is ready to be used.
84
- */ static async create(node, store, proofCreator, simulator, protocolContractsProvider, config, loggerOrSuffix) {
93
+ */ static async create({ node, store, proofCreator, simulator, protocolContractsProvider, config, loggerOrSuffix }) {
94
+ // Extract bindings from the logger, or use empty bindings if a string suffix is provided.
95
+ const bindings = loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
85
96
  const log = !loggerOrSuffix || typeof loggerOrSuffix === 'string' ? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`) : loggerOrSuffix;
86
- const proverEnabled = !!config.proverEnabled;
97
+ const info = await node.getNodeInfo();
98
+ const proverEnabled = config.proverEnabled !== undefined ? config.proverEnabled : info.realProofs;
87
99
  const addressStore = new AddressStore(store);
88
100
  const privateEventStore = new PrivateEventStore(store);
89
101
  const contractStore = new ContractStore(store);
@@ -95,29 +107,45 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
95
107
  const capsuleStore = new CapsuleStore(store);
96
108
  const keyStore = new KeyStore(store);
97
109
  const tipsStore = new L2TipsKVStore(store, 'pxe');
98
- const synchronizer = new BlockSynchronizer(node, store, anchorBlockStore, noteStore, privateEventStore, tipsStore, config, loggerOrSuffix);
99
- const jobCoordinator = new JobCoordinator(store);
110
+ const contractSyncService = new ContractSyncService(node, contractStore, noteStore, createLogger('pxe:contract_sync', bindings));
111
+ const messageContextService = new MessageContextService(node);
112
+ const synchronizer = new BlockSynchronizer(node, store, anchorBlockStore, noteStore, privateEventStore, tipsStore, contractSyncService, config, bindings);
113
+ const jobCoordinator = new JobCoordinator(store, bindings);
100
114
  jobCoordinator.registerStores([
101
115
  capsuleStore,
102
116
  senderTaggingStore,
103
117
  recipientTaggingStore,
104
118
  privateEventStore,
105
- noteStore
119
+ noteStore,
120
+ contractSyncService
106
121
  ]);
107
- const debugUtils = new PXEDebugUtils(contractStore, noteStore);
122
+ const debugUtils = new PXEDebugUtils(contractSyncService, noteStore, synchronizer, anchorBlockStore);
108
123
  const jobQueue = new SerialQueue();
109
- const pxe = new PXE(node, synchronizer, keyStore, contractStore, noteStore, capsuleStore, anchorBlockStore, senderTaggingStore, senderAddressBookStore, recipientTaggingStore, addressStore, privateEventStore, simulator, proverEnabled, proofCreator, protocolContractsProvider, log, jobQueue, jobCoordinator, debugUtils);
110
- debugUtils.setPXE(pxe);
124
+ const pxe = new PXE(node, store, synchronizer, keyStore, contractStore, noteStore, capsuleStore, anchorBlockStore, senderTaggingStore, senderAddressBookStore, recipientTaggingStore, addressStore, privateEventStore, contractSyncService, messageContextService, simulator, proverEnabled, proofCreator, protocolContractsProvider, log, jobQueue, jobCoordinator, debugUtils);
125
+ debugUtils.setPXEHelpers(pxe.#putInJobQueue.bind(pxe), pxe.#getSimulatorForTx.bind(pxe), pxe.#executeUtility.bind(pxe));
111
126
  pxe.jobQueue.start();
112
127
  await pxe.#registerProtocolContracts();
113
- const info = await node.getNodeInfo();
114
128
  log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
115
129
  return pxe;
116
130
  }
117
131
  // Internal methods
118
132
  #getSimulatorForTx(overrides) {
119
133
  const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
120
- return new ContractFunctionSimulator(proxyContractStore, this.noteStore, this.keyStore, this.addressStore, BenchmarkedNodeFactory.create(this.node), this.anchorBlockStore, this.senderTaggingStore, this.recipientTaggingStore, this.senderAddressBookStore, this.capsuleStore, this.privateEventStore, this.simulator);
134
+ return new ContractFunctionSimulator({
135
+ contractStore: proxyContractStore,
136
+ noteStore: this.noteStore,
137
+ keyStore: this.keyStore,
138
+ addressStore: this.addressStore,
139
+ aztecNode: BenchmarkedNodeFactory.create(this.node),
140
+ senderTaggingStore: this.senderTaggingStore,
141
+ recipientTaggingStore: this.recipientTaggingStore,
142
+ senderAddressBookStore: this.senderAddressBookStore,
143
+ capsuleStore: this.capsuleStore,
144
+ privateEventStore: this.privateEventStore,
145
+ simulator: this.simulator,
146
+ contractSyncService: this.contractSyncService,
147
+ messageContextService: this.messageContextService
148
+ });
121
149
  }
122
150
  #contextualizeError(err, ...context) {
123
151
  let contextStr = '';
@@ -160,8 +188,8 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
160
188
  async #registerProtocolContracts() {
161
189
  const registered = {};
162
190
  for (const name of protocolContractNames){
163
- const { address, contractClass, instance, artifact } = await this.protocolContractsProvider.getProtocolContractArtifact(name);
164
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
191
+ const { address, instance, artifact } = await this.protocolContractsProvider.getProtocolContractArtifact(name);
192
+ await this.contractStore.addContractArtifact(artifact);
165
193
  await this.contractStore.addContractInstance(instance);
166
194
  registered[name] = address.toString();
167
195
  }
@@ -173,10 +201,14 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
173
201
  const { origin: contractAddress, functionSelector } = txRequest;
174
202
  try {
175
203
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
176
- await ensureContractSynced(contractAddress, functionSelector, (privateSyncCall)=>this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId), this.node, this.contractStore, anchorBlockHeader);
177
- const result = await contractFunctionSimulator.run(txRequest, contractAddress, functionSelector, undefined, anchorBlockHeader, // The sender for tags is set by contracts, typically by an account
178
- // contract entrypoint
179
- undefined, scopes, jobId);
204
+ await this.contractSyncService.ensureContractSynced(contractAddress, functionSelector, (privateSyncCall, execScopes)=>this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId), anchorBlockHeader, jobId, scopes);
205
+ const result = await contractFunctionSimulator.run(txRequest, {
206
+ contractAddress,
207
+ selector: functionSelector,
208
+ anchorBlockHeader,
209
+ scopes,
210
+ jobId
211
+ });
180
212
  this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
181
213
  return result;
182
214
  } catch (err) {
@@ -187,15 +219,15 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
187
219
  }
188
220
  }
189
221
  /**
190
- * Simulate a utility function call on the given contract.
222
+ * Execute a utility function call on the given contract.
191
223
  * @param contractFunctionSimulator - The simulator to use for the function call.
192
224
  * @param call - The function call to execute.
193
225
  * @param authWitnesses - Authentication witnesses required for the function call.
194
226
  * @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
195
227
  * accounts if not specified.
196
228
  * @param jobId - The job ID for staged writes.
197
- * @returns The simulation result containing the outputs of the utility function.
198
- */ async #simulateUtility(contractFunctionSimulator, call, authWitnesses, scopes, jobId) {
229
+ * @returns The execution result containing the outputs of the utility function.
230
+ */ async #executeUtility(contractFunctionSimulator, call, authWitnesses, scopes, jobId) {
199
231
  try {
200
232
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
201
233
  return contractFunctionSimulator.runUtility(call, authWitnesses ?? [], anchorBlockHeader, scopes, jobId);
@@ -245,12 +277,22 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
245
277
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
246
278
  const anchorBlockHash = await anchorBlockHeader.hash();
247
279
  const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHash);
248
- const kernelTraceProver = new PrivateKernelExecutionProver(kernelOracle, proofCreator, !this.proverEnabled);
280
+ const kernelTraceProver = new PrivateKernelExecutionProver(kernelOracle, proofCreator, !this.proverEnabled, this.log.getBindings());
249
281
  this.log.debug(`Executing kernel trace prover (${JSON.stringify(config)})...`);
250
282
  return await kernelTraceProver.proveWithKernels(txExecutionRequest.toTxRequest(), privateExecutionResult, config);
251
283
  }
252
284
  // Public API
253
- getContractInstance(address) {
285
+ /**
286
+ * Returns the block header up to which the PXE has synced.
287
+ * @returns The synced block header
288
+ */ getSyncedBlockHeader() {
289
+ return this.anchorBlockStore.getBlockHeader();
290
+ }
291
+ /**
292
+ * Returns the contract instance for a given address, if it's registered in the PXE.
293
+ * @param address - The contract address.
294
+ * @returns The contract instance if found, undefined otherwise.
295
+ */ getContractInstance(address) {
254
296
  return this.contractStore.getContractInstance(address);
255
297
  }
256
298
  /**
@@ -337,8 +379,7 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
337
379
  *
338
380
  * @param artifact - The build artifact for the contract class.
339
381
  */ async registerContractClass(artifact) {
340
- const { id: contractClassId } = await getContractClassFromArtifact(artifact);
341
- await this.contractStore.addContractArtifact(contractClassId, artifact);
382
+ const contractClassId = await this.contractStore.addContractArtifact(artifact);
342
383
  this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
343
384
  }
344
385
  /**
@@ -354,15 +395,14 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
354
395
  if (artifact) {
355
396
  // If the user provides an artifact, validate it against the expected class id and register it
356
397
  const contractClass = await getContractClassFromArtifact(artifact);
357
- const contractClassId = contractClass.id;
358
- if (!contractClassId.equals(instance.currentContractClassId)) {
359
- throw new Error(`Artifact does not match expected class id (computed ${contractClassId} but instance refers to ${instance.currentContractClassId})`);
398
+ if (!contractClass.id.equals(instance.currentContractClassId)) {
399
+ throw new Error(`Artifact does not match expected class id (computed ${contractClass.id} but instance refers to ${instance.currentContractClassId})`);
360
400
  }
361
401
  const computedAddress = await computeContractAddressFromInstance(instance);
362
402
  if (!computedAddress.equals(instance.address)) {
363
403
  throw new Error('Added a contract in which the address does not match the contract instance.');
364
404
  }
365
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
405
+ await this.contractStore.addContractArtifact(artifact, contractClass);
366
406
  const publicFunctionSignatures = artifact.functions.filter((fn)=>fn.functionType === FunctionType.PUBLIC).map((fn)=>decodeFunctionSignature(fn.name, fn.parameters));
367
407
  await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
368
408
  } else {
@@ -398,11 +438,13 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
398
438
  if (!contractClass.id.equals(currentClassId)) {
399
439
  throw new Error('Could not update contract to a class different from the current one.');
400
440
  }
401
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
402
441
  const publicFunctionSignatures = artifact.functions.filter((fn)=>fn.functionType === FunctionType.PUBLIC).map((fn)=>decodeFunctionSignature(fn.name, fn.parameters));
403
442
  await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
404
443
  currentInstance.currentContractClassId = contractClass.id;
405
- await this.contractStore.addContractInstance(currentInstance);
444
+ await Promise.all([
445
+ this.contractStore.addContractArtifact(artifact, contractClass),
446
+ this.contractStore.addContractInstance(currentInstance)
447
+ ]);
406
448
  this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
407
449
  });
408
450
  }
@@ -417,10 +459,11 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
417
459
  * (where validators prove the public portion).
418
460
  *
419
461
  * @param txRequest - An authenticated tx request ready for proving
462
+ * @param scopes - Addresses whose private state and keys are accessible during private execution.
420
463
  * @returns A result containing the proof and public inputs of the tail circuit.
421
464
  * @throws If contract code not found, or public simulation reverts.
422
465
  * Also throws if simulatePublic is true and public simulation reverts.
423
- */ proveTx(txRequest) {
466
+ */ proveTx(txRequest, scopes) {
424
467
  let privateExecutionResult;
425
468
  // We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
426
469
  // computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
@@ -431,7 +474,7 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
431
474
  await this.blockStateSynchronizer.sync();
432
475
  const syncTime = syncTimer.ms();
433
476
  const contractFunctionSimulator = this.#getSimulatorForTx();
434
- privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, undefined, jobId);
477
+ privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
435
478
  const { publicInputs, chonkProof, executionSteps, timings: { proving } = {} } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, {
436
479
  simulate: false,
437
480
  skipFeeEnforcement: false,
@@ -462,16 +505,16 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
462
505
  // transaction before this one is included in a block from this PXE, and that transaction contains a log with
463
506
  // a tag derived from the same secret, we would reuse the tag and the transactions would be linked. Hence
464
507
  // storing the tags here prevents linkage of txs sent from the same PXE.
465
- const preTagsUsedInTheTx = privateExecutionResult.entrypoint.preTags;
466
- if (preTagsUsedInTheTx.length > 0) {
508
+ const taggingIndexRangesUsedInTheTx = privateExecutionResult.entrypoint.taggingIndexRanges;
509
+ if (taggingIndexRangesUsedInTheTx.length > 0) {
467
510
  // TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
468
511
  const txHash = (await txProvingResult.toTx()).txHash;
469
- await this.senderTaggingStore.storePendingIndexes(preTagsUsedInTheTx, txHash, jobId);
470
- this.log.debug(`Stored used pre-tags as sender for the tx`, {
471
- preTagsUsedInTheTx
512
+ await this.senderTaggingStore.storePendingIndexes(taggingIndexRangesUsedInTheTx, txHash, jobId);
513
+ this.log.debug(`Stored used tagging index ranges as sender for the tx`, {
514
+ taggingIndexRangesUsedInTheTx
472
515
  });
473
516
  } else {
474
- this.log.debug(`No pre-tags used in the tx`);
517
+ this.log.debug(`No tagging index ranges used in the tx`);
475
518
  }
476
519
  return txProvingResult;
477
520
  } catch (err) {
@@ -481,13 +524,10 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
481
524
  }
482
525
  /**
483
526
  * Profiles a transaction, reporting gate counts (unless disabled) and returns an execution trace.
484
- *
485
- * @param txRequest - An authenticated tx request ready for simulation
486
- * @param msgSender - (Optional) The message sender to use for the simulation.
487
- * @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
527
+ * @param txRequest - An authenticated tx request ready for simulation.
488
528
  * @returns A trace of the program execution with gate counts.
489
529
  * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
490
- */ profileTx(txRequest, profileMode, skipProofGeneration = true) {
530
+ */ profileTx(txRequest, { profileMode, skipProofGeneration = true, scopes }) {
491
531
  // We disable concurrent profiles for consistency with simulateTx.
492
532
  return this.#putInJobQueue(async (jobId)=>{
493
533
  const totalTimer = new Timer();
@@ -505,7 +545,7 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
505
545
  await this.blockStateSynchronizer.sync();
506
546
  const syncTime = syncTimer.ms();
507
547
  const contractFunctionSimulator = this.#getSimulatorForTx();
508
- const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, undefined, jobId);
548
+ const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
509
549
  const { executionSteps, timings: { proving } = {} } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, {
510
550
  simulate: skipProofGeneration,
511
551
  skipFeeEnforcement: false,
@@ -550,18 +590,13 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
550
590
  * In that case, the transaction returned is only potentially ready to be sent to the network for execution.
551
591
  *
552
592
  *
553
- * @param txRequest - An authenticated tx request ready for simulation
554
- * @param simulatePublic - Whether to simulate the public part of the transaction.
555
- * @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
556
- * @param skipFeeEnforcement - (Optional) If false, fees are enforced.
557
- * @param overrides - (Optional) State overrides for the simulation, such as msgSender, contract instances and artifacts.
558
- * @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will default to all.
593
+ * @param txRequest - An authenticated tx request ready for simulation.
559
594
  * @returns A simulated transaction result object that includes public and private return values.
560
595
  * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
561
596
  * Also throws if simulatePublic is true and public simulation reverts.
562
597
  *
563
598
  * TODO(#7456) Prevent msgSender being defined here for the first call
564
- */ simulateTx(txRequest, simulatePublic, skipTxValidation = false, skipFeeEnforcement = false, overrides, scopes) {
599
+ */ simulateTx(txRequest, { simulatePublic, skipTxValidation = false, skipFeeEnforcement = false, overrides, scopes }) {
565
600
  // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
566
601
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
567
602
  // delete the same read value, or reading values that another simulation is currently modifying).
@@ -584,13 +619,19 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
584
619
  // Temporary: in case there are overrides, we have to skip the kernels or validations
585
620
  // will fail. Consider handing control to the user/wallet on whether they want to run them
586
621
  // or not.
587
- const skipKernels = overrides?.contracts !== undefined && Object.keys(overrides.contracts ?? {}).length > 0;
622
+ const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
623
+ const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
624
+ const skipKernels = hasOverriddenContracts;
625
+ // Set overridden contracts on the sync service so it knows to skip syncing them
626
+ if (hasOverriddenContracts) {
627
+ this.contractSyncService.setOverriddenContracts(jobId, overriddenContracts);
628
+ }
588
629
  // Execution of private functions only; no proving, and no kernel logic.
589
630
  const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
590
631
  let publicInputs;
591
632
  let executionSteps = [];
592
633
  if (skipKernels) {
593
- ({ publicInputs, executionSteps } = await generateSimulatedProvingResult(privateExecutionResult, this.contractStore));
634
+ ({ publicInputs, executionSteps } = await generateSimulatedProvingResult(privateExecutionResult, (addr, sel)=>this.contractStore.getDebugFunctionName(addr, sel), this.node));
594
635
  } else {
595
636
  // Kernel logic, plus proving of all private functions and kernels.
596
637
  ({ publicInputs, executionSteps } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, {
@@ -607,6 +648,9 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
607
648
  const publicSimulationTimer = new Timer();
608
649
  publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement);
609
650
  publicSimulationTime = publicSimulationTimer.ms();
651
+ if (publicOutput?.debugLogs?.length) {
652
+ await displayDebugLogs(publicOutput.debugLogs, (addr)=>this.contractStore.getDebugContractName(addr));
653
+ }
610
654
  }
611
655
  let validationTime;
612
656
  if (!skipTxValidation) {
@@ -617,7 +661,8 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
617
661
  });
618
662
  validationTime = validationTimer.ms();
619
663
  if (validationResult.result === 'invalid') {
620
- throw new Error('The simulated transaction is unable to be added to state and is invalid.');
664
+ const reason = validationResult.reason.length > 0 ? ` Reason: ${validationResult.reason.join(', ')}` : '';
665
+ throw new Error(`The simulated transaction is unable to be added to state and is invalid.${reason}`);
621
666
  }
622
667
  }
623
668
  const txHash = simulatedTx.getTxHash();
@@ -650,22 +695,19 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
650
695
  nodeRPCCalls: simulatorStats.nodeRPCCalls
651
696
  });
652
697
  } catch (err) {
653
- throw this.#contextualizeError(err, inspect(txRequest), `simulatePublic=${simulatePublic}`, `skipTxValidation=${skipTxValidation}`, `scopes=${scopes?.map((s)=>s.toString()).join(', ') ?? 'undefined'}`);
698
+ throw this.#contextualizeError(err, inspect(txRequest), `simulatePublic=${simulatePublic}`, `skipTxValidation=${skipTxValidation}`, `scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map((s)=>s.toString()).join(', ')}`);
654
699
  }
655
700
  });
656
701
  }
657
702
  /**
658
- * Simulate the execution of a contract utility function.
659
- *
703
+ * Executes a contract utility function.
660
704
  * @param call - The function call containing the function details, arguments, and target contract address.
661
- * @param authwits - (Optional) The authentication witnesses required for the function call.
662
- * @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will
663
- * default to all.
664
- * @returns The result of the utility function call, structured based on the function ABI.
665
- */ simulateUtility(call, authwits, scopes) {
666
- // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
705
+ */ executeUtility(call, { authwits, scopes } = {
706
+ scopes: 'ALL_SCOPES'
707
+ }) {
708
+ // We disable concurrent executions since those might execute oracles which read and write to the PXE stores (e.g.
667
709
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
668
- // delete the same read value, or reading values that another simulation is currently modifying).
710
+ // delete the same read value, or reading values that another execution is currently modifying).
669
711
  return this.#putInJobQueue(async (jobId)=>{
670
712
  try {
671
713
  const totalTimer = new Timer();
@@ -675,8 +717,8 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
675
717
  const functionTimer = new Timer();
676
718
  const contractFunctionSimulator = this.#getSimulatorForTx();
677
719
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
678
- await ensureContractSynced(call.to, call.selector, (privateSyncCall)=>this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId), this.node, this.contractStore, anchorBlockHeader);
679
- const executionResult = await this.#simulateUtility(contractFunctionSimulator, call, authwits ?? [], scopes, jobId);
720
+ await this.contractSyncService.ensureContractSynced(call.to, call.selector, (privateSyncCall, execScopes)=>this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId), anchorBlockHeader, jobId, scopes);
721
+ const executionResult = await this.#executeUtility(contractFunctionSimulator, call, authwits ?? [], scopes, jobId);
680
722
  const functionTime = functionTimer.ms();
681
723
  const totalTime = totalTimer.ms();
682
724
  const perFunction = [
@@ -702,7 +744,7 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
702
744
  } catch (err) {
703
745
  const { to, name, args } = call;
704
746
  const stringifiedArgs = args.map((arg)=>arg.toString()).join(', ');
705
- throw this.#contextualizeError(err, `simulateUtility ${to}:${name}(${stringifiedArgs})`, `scopes=${scopes?.map((s)=>s.toString()).join(', ') ?? 'undefined'}`);
747
+ throw this.#contextualizeError(err, `executeUtility ${to}:${name}(${stringifiedArgs})`, `scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map((s)=>s.toString()).join(', ')}`);
706
748
  }
707
749
  });
708
750
  }
@@ -725,7 +767,7 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
725
767
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
726
768
  anchorBlockNumber = anchorBlockHeader.getBlockNumber();
727
769
  const contractFunctionSimulator = this.#getSimulatorForTx();
728
- await ensureContractSynced(filter.contractAddress, null, async (privateSyncCall)=>await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId), this.node, this.contractStore, anchorBlockHeader);
770
+ await this.contractSyncService.ensureContractSynced(filter.contractAddress, null, async (privateSyncCall, execScopes)=>await this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId), anchorBlockHeader, jobId, filter.scopes);
729
771
  });
730
772
  // anchorBlockNumber is set during the job and fixed to whatever it is after a block sync
731
773
  const sanitizedFilter = new PrivateEventFilterValidator(anchorBlockNumber).validate(filter);
@@ -733,8 +775,9 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
733
775
  return this.privateEventStore.getPrivateEvents(eventSelector, sanitizedFilter);
734
776
  }
735
777
  /**
736
- * Stops the PXE's job queue.
737
- */ stop() {
738
- return this.jobQueue.end();
778
+ * Stops the PXE's job queue and closes the backing store.
779
+ */ async stop() {
780
+ await this.jobQueue.end();
781
+ await this.db.close();
739
782
  }
740
783
  }
@@ -8,4 +8,4 @@ export declare class AddressStore {
8
8
  getCompleteAddress(account: AztecAddress): Promise<CompleteAddress | undefined>;
9
9
  getCompleteAddresses(): Promise<CompleteAddress[]>;
10
10
  }
11
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWRkcmVzc19zdG9yZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL3N0b3JhZ2UvYWRkcmVzc19zdG9yZS9hZGRyZXNzX3N0b3JlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLE9BQU8sS0FBSyxFQUFtQixpQkFBaUIsRUFBaUIsTUFBTSxpQkFBaUIsQ0FBQztBQUN6RixPQUFPLEtBQUssRUFBRSxZQUFZLEVBQUUsTUFBTSw2QkFBNkIsQ0FBQztBQUNoRSxPQUFPLEVBQUUsZUFBZSxFQUFFLE1BQU0sd0JBQXdCLENBQUM7QUFFekQscUJBQWEsWUFBWTs7SUFLdkIsWUFBWSxLQUFLLEVBQUUsaUJBQWlCLEVBS25DO0lBRUQsa0JBQWtCLENBQUMsZUFBZSxFQUFFLGVBQWUsR0FBRyxPQUFPLENBQUMsT0FBTyxDQUFDLENBMEJyRTtJQVlELGtCQUFrQixDQUFDLE9BQU8sRUFBRSxZQUFZLEdBQUcsT0FBTyxDQUFDLGVBQWUsR0FBRyxTQUFTLENBQUMsQ0FFOUU7SUFFSyxvQkFBb0IsSUFBSSxPQUFPLENBQUMsZUFBZSxFQUFFLENBQUMsQ0FJdkQ7Q0FDRiJ9
11
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWRkcmVzc19zdG9yZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL3N0b3JhZ2UvYWRkcmVzc19zdG9yZS9hZGRyZXNzX3N0b3JlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLE9BQU8sS0FBSyxFQUFtQixpQkFBaUIsRUFBaUIsTUFBTSxpQkFBaUIsQ0FBQztBQUN6RixPQUFPLEtBQUssRUFBRSxZQUFZLEVBQUUsTUFBTSw2QkFBNkIsQ0FBQztBQUNoRSxPQUFPLEVBQUUsZUFBZSxFQUFFLE1BQU0sd0JBQXdCLENBQUM7QUFFekQscUJBQWEsWUFBWTs7SUFLdkIsWUFBWSxLQUFLLEVBQUUsaUJBQWlCLEVBS25DO0lBRUQsa0JBQWtCLENBQUMsZUFBZSxFQUFFLGVBQWUsR0FBRyxPQUFPLENBQUMsT0FBTyxDQUFDLENBMEJyRTtJQUVELGtCQUFrQixDQUFDLE9BQU8sRUFBRSxZQUFZLEdBQUcsT0FBTyxDQUFDLGVBQWUsR0FBRyxTQUFTLENBQUMsQ0FVOUU7SUFFRCxvQkFBb0IsSUFBSSxPQUFPLENBQUMsZUFBZSxFQUFFLENBQUMsQ0FNakQ7Q0FDRiJ9
@@ -1 +1 @@
1
- {"version":3,"file":"address_store.d.ts","sourceRoot":"","sources":["../../../src/storage/address_store/address_store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAmB,iBAAiB,EAAiB,MAAM,iBAAiB,CAAC;AACzF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,qBAAa,YAAY;;IAKvB,YAAY,KAAK,EAAE,iBAAiB,EAKnC;IAED,kBAAkB,CAAC,eAAe,EAAE,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC,CA0BrE;IAYD,kBAAkB,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,eAAe,GAAG,SAAS,CAAC,CAE9E;IAEK,oBAAoB,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC,CAIvD;CACF"}
1
+ {"version":3,"file":"address_store.d.ts","sourceRoot":"","sources":["../../../src/storage/address_store/address_store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAmB,iBAAiB,EAAiB,MAAM,iBAAiB,CAAC;AACzF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,qBAAa,YAAY;;IAKvB,YAAY,KAAK,EAAE,iBAAiB,EAKnC;IAED,kBAAkB,CAAC,eAAe,EAAE,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC,CA0BrE;IAED,kBAAkB,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,eAAe,GAAG,SAAS,CAAC,CAU9E;IAED,oBAAoB,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC,CAMjD;CACF"}
@@ -30,18 +30,19 @@ export class AddressStore {
30
30
  }
31
31
  });
32
32
  }
33
- async #getCompleteAddress(address) {
34
- const index = await this.#completeAddressIndex.getAsync(address.toString());
35
- if (index === undefined) {
36
- return undefined;
37
- }
38
- const value = await this.#completeAddresses.atAsync(index);
39
- return value ? await CompleteAddress.fromBuffer(value) : undefined;
40
- }
41
33
  getCompleteAddress(account) {
42
- return this.#getCompleteAddress(account);
34
+ return this.#store.transactionAsync(async ()=>{
35
+ const index = await this.#completeAddressIndex.getAsync(account.toString());
36
+ if (index === undefined) {
37
+ return undefined;
38
+ }
39
+ const value = await this.#completeAddresses.atAsync(index);
40
+ return value ? await CompleteAddress.fromBuffer(value) : undefined;
41
+ });
43
42
  }
44
- async getCompleteAddresses() {
45
- return await Promise.all((await toArray(this.#completeAddresses.valuesAsync())).map((v)=>CompleteAddress.fromBuffer(v)));
43
+ getCompleteAddresses() {
44
+ return this.#store.transactionAsync(async ()=>{
45
+ return await Promise.all((await toArray(this.#completeAddresses.valuesAsync())).map((v)=>CompleteAddress.fromBuffer(v)));
46
+ });
46
47
  }
47
48
  }
@@ -3,7 +3,15 @@ import { BlockHeader } from '@aztec/stdlib/tx';
3
3
  export declare class AnchorBlockStore {
4
4
  #private;
5
5
  constructor(store: AztecAsyncKVStore);
6
+ /**
7
+ * Sets the currently synchronized block
8
+ *
9
+ * Important: this method is only called from BlockSynchronizer, and since we need it to run atomically with other
10
+ * stores in the case of a reorg, it MUST NOT be wrapped in a `transactionAsync` call. Doing so would result in a
11
+ * deadlock when the backend is IndexedDB, because `transactionAsync` is not designed to support reentrancy.
12
+ *
13
+ */
6
14
  setHeader(header: BlockHeader): Promise<void>;
7
15
  getBlockHeader(): Promise<BlockHeader>;
8
16
  }
9
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYW5jaG9yX2Jsb2NrX3N0b3JlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvc3RvcmFnZS9hbmNob3JfYmxvY2tfc3RvcmUvYW5jaG9yX2Jsb2NrX3N0b3JlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLGlCQUFpQixFQUF1QixNQUFNLGlCQUFpQixDQUFDO0FBQzlFLE9BQU8sRUFBRSxXQUFXLEVBQUUsTUFBTSxrQkFBa0IsQ0FBQztBQUUvQyxxQkFBYSxnQkFBZ0I7O0lBSTNCLFlBQVksS0FBSyxFQUFFLGlCQUFpQixFQUduQztJQUVLLFNBQVMsQ0FBQyxNQUFNLEVBQUUsV0FBVyxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FFbEQ7SUFFSyxjQUFjLElBQUksT0FBTyxDQUFDLFdBQVcsQ0FBQyxDQU8zQztDQUNGIn0=
17
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYW5jaG9yX2Jsb2NrX3N0b3JlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvc3RvcmFnZS9hbmNob3JfYmxvY2tfc3RvcmUvYW5jaG9yX2Jsb2NrX3N0b3JlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLGlCQUFpQixFQUF1QixNQUFNLGlCQUFpQixDQUFDO0FBQzlFLE9BQU8sRUFBRSxXQUFXLEVBQUUsTUFBTSxrQkFBa0IsQ0FBQztBQUUvQyxxQkFBYSxnQkFBZ0I7O0lBSTNCLFlBQVksS0FBSyxFQUFFLGlCQUFpQixFQUduQztJQUVEOzs7Ozs7O09BT0c7SUFDRyxTQUFTLENBQUMsTUFBTSxFQUFFLFdBQVcsR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLENBRWxEO0lBRUssY0FBYyxJQUFJLE9BQU8sQ0FBQyxXQUFXLENBQUMsQ0FPM0M7Q0FDRiJ9
@@ -1 +1 @@
1
- {"version":3,"file":"anchor_block_store.d.ts","sourceRoot":"","sources":["../../../src/storage/anchor_block_store/anchor_block_store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAuB,MAAM,iBAAiB,CAAC;AAC9E,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,qBAAa,gBAAgB;;IAI3B,YAAY,KAAK,EAAE,iBAAiB,EAGnC;IAEK,SAAS,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAElD;IAEK,cAAc,IAAI,OAAO,CAAC,WAAW,CAAC,CAO3C;CACF"}
1
+ {"version":3,"file":"anchor_block_store.d.ts","sourceRoot":"","sources":["../../../src/storage/anchor_block_store/anchor_block_store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAuB,MAAM,iBAAiB,CAAC;AAC9E,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,qBAAa,gBAAgB;;IAI3B,YAAY,KAAK,EAAE,iBAAiB,EAGnC;IAED;;;;;;;OAOG;IACG,SAAS,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAElD;IAEK,cAAc,IAAI,OAAO,CAAC,WAAW,CAAC,CAO3C;CACF"}
@@ -6,7 +6,14 @@ export class AnchorBlockStore {
6
6
  this.#store = store;
7
7
  this.#synchronizedHeader = this.#store.openSingleton('header');
8
8
  }
9
- async setHeader(header) {
9
+ /**
10
+ * Sets the currently synchronized block
11
+ *
12
+ * Important: this method is only called from BlockSynchronizer, and since we need it to run atomically with other
13
+ * stores in the case of a reorg, it MUST NOT be wrapped in a `transactionAsync` call. Doing so would result in a
14
+ * deadlock when the backend is IndexedDB, because `transactionAsync` is not designed to support reentrancy.
15
+ *
16
+ */ async setHeader(header) {
10
17
  await this.#synchronizedHeader.set(header.toBuffer());
11
18
  }
12
19
  async getBlockHeader() {
@@ -40,14 +40,12 @@ export class CapsuleStore {
40
40
  * If it is not there, it reads it from the KV store.
41
41
  */ async #getFromStage(jobId, dbSlotKey) {
42
42
  const jobStagedCapsules = this.#getJobStagedCapsules(jobId);
43
- let staged = jobStagedCapsules.get(dbSlotKey);
44
- // Note that if staged === null, we marked it for deletion, so we don't want to
45
- // re-read it from DB
46
- if (staged === undefined) {
47
- // If we don't have a staged version of this dbSlotKey, first we check if there's one in DB
48
- staged = await this.#loadCapsuleFromDb(dbSlotKey);
49
- }
50
- return staged;
43
+ const staged = jobStagedCapsules.get(dbSlotKey);
44
+ // Always issue DB read to keep IndexedDB transaction alive, even if the value is in the job staged data. This
45
+ // keeps IndexedDB transactions alive (they auto-commit when a new micro-task starts and there are no pending read
46
+ // requests). The staged value still takes precedence if it exists (including null for deletions).
47
+ const dbValue = await this.#loadCapsuleFromDb(dbSlotKey);
48
+ return staged !== undefined ? staged : dbValue;
51
49
  }
52
50
  /**
53
51
  * Writes a capsule to the stage of a job.