@aztec/pxe 0.0.1-commit.7d4e6cd → 0.0.1-commit.858058eac

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 (230) hide show
  1. package/dest/bin/check_oracle_version.js +1 -1
  2. package/dest/block_synchronizer/block_synchronizer.d.ts +11 -5
  3. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
  4. package/dest/block_synchronizer/block_synchronizer.js +72 -21
  5. package/dest/config/index.d.ts +3 -1
  6. package/dest/config/index.d.ts.map +1 -1
  7. package/dest/config/index.js +17 -0
  8. package/dest/contract_function_simulator/benchmarked_node.d.ts +9 -0
  9. package/dest/contract_function_simulator/benchmarked_node.d.ts.map +1 -0
  10. package/dest/contract_function_simulator/benchmarked_node.js +77 -0
  11. package/dest/contract_function_simulator/contract_function_simulator.d.ts +53 -33
  12. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  13. package/dest/contract_function_simulator/contract_function_simulator.js +95 -51
  14. package/dest/contract_function_simulator/execution_note_cache.d.ts +18 -9
  15. package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -1
  16. package/dest/contract_function_simulator/execution_note_cache.js +45 -28
  17. package/dest/contract_function_simulator/index.d.ts +2 -2
  18. package/dest/contract_function_simulator/index.d.ts.map +1 -1
  19. package/dest/contract_function_simulator/index.js +1 -1
  20. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +1 -1
  21. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +1 -1
  22. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +1 -1
  23. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +1 -1
  24. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts +4 -10
  25. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts.map +1 -1
  26. package/dest/contract_function_simulator/noir-structs/utility_context.js +7 -18
  27. package/dest/contract_function_simulator/oracle/interfaces.d.ts +17 -13
  28. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  29. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts +3 -1
  30. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts.map +1 -1
  31. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts +6 -6
  32. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts.map +1 -1
  33. package/dest/contract_function_simulator/oracle/note_packing_utils.js +8 -8
  34. package/dest/contract_function_simulator/oracle/oracle.d.ts +12 -10
  35. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  36. package/dest/contract_function_simulator/oracle/oracle.js +67 -44
  37. package/dest/contract_function_simulator/oracle/private_execution.d.ts +2 -26
  38. package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
  39. package/dest/contract_function_simulator/oracle/private_execution.js +0 -35
  40. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +43 -35
  41. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  42. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +82 -25
  43. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +65 -33
  44. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  45. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +126 -109
  46. package/dest/contract_sync/contract_sync_service.d.ts +41 -0
  47. package/dest/contract_sync/contract_sync_service.d.ts.map +1 -0
  48. package/dest/contract_sync/contract_sync_service.js +82 -0
  49. package/dest/contract_sync/helpers.d.ts +28 -0
  50. package/dest/contract_sync/helpers.d.ts.map +1 -0
  51. package/dest/contract_sync/helpers.js +55 -0
  52. package/dest/debug/pxe_debug_utils.d.ts +22 -9
  53. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  54. package/dest/debug/pxe_debug_utils.js +28 -17
  55. package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
  56. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  57. package/dest/entrypoints/client/bundle/utils.js +21 -7
  58. package/dest/entrypoints/client/lazy/utils.d.ts +2 -2
  59. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  60. package/dest/entrypoints/client/lazy/utils.js +22 -8
  61. package/dest/entrypoints/pxe_creation_options.d.ts +3 -2
  62. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  63. package/dest/entrypoints/server/index.d.ts +3 -1
  64. package/dest/entrypoints/server/index.d.ts.map +1 -1
  65. package/dest/entrypoints/server/index.js +2 -0
  66. package/dest/entrypoints/server/utils.d.ts +1 -1
  67. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  68. package/dest/entrypoints/server/utils.js +28 -9
  69. package/dest/events/event_service.d.ts +6 -6
  70. package/dest/events/event_service.d.ts.map +1 -1
  71. package/dest/events/event_service.js +19 -22
  72. package/dest/events/private_event_filter_validator.d.ts +5 -5
  73. package/dest/events/private_event_filter_validator.d.ts.map +1 -1
  74. package/dest/events/private_event_filter_validator.js +5 -6
  75. package/dest/job_coordinator/job_coordinator.d.ts +3 -2
  76. package/dest/job_coordinator/job_coordinator.d.ts.map +1 -1
  77. package/dest/job_coordinator/job_coordinator.js +3 -2
  78. package/dest/logs/log_service.d.ts +7 -5
  79. package/dest/logs/log_service.d.ts.map +1 -1
  80. package/dest/logs/log_service.js +23 -20
  81. package/dest/notes/note_service.d.ts +7 -7
  82. package/dest/notes/note_service.d.ts.map +1 -1
  83. package/dest/notes/note_service.js +31 -36
  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 +4 -3
  87. package/dest/private_kernel/hints/index.d.ts +2 -2
  88. package/dest/private_kernel/hints/index.d.ts.map +1 -1
  89. package/dest/private_kernel/hints/index.js +1 -1
  90. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +28 -0
  91. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -0
  92. package/dest/private_kernel/hints/{build_private_kernel_reset_private_inputs.js → private_kernel_reset_private_inputs_builder.js} +12 -6
  93. package/dest/private_kernel/private_kernel_execution_prover.d.ts +3 -2
  94. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  95. package/dest/private_kernel/private_kernel_execution_prover.js +3 -3
  96. package/dest/private_kernel/private_kernel_oracle.d.ts +23 -28
  97. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  98. package/dest/private_kernel/private_kernel_oracle.js +90 -2
  99. package/dest/pxe.d.ts +70 -57
  100. package/dest/pxe.d.ts.map +1 -1
  101. package/dest/pxe.js +96 -111
  102. package/dest/storage/address_store/address_store.d.ts +1 -1
  103. package/dest/storage/address_store/address_store.d.ts.map +1 -1
  104. package/dest/storage/address_store/address_store.js +12 -11
  105. package/dest/storage/anchor_block_store/anchor_block_store.d.ts +9 -1
  106. package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -1
  107. package/dest/storage/anchor_block_store/anchor_block_store.js +8 -1
  108. package/dest/storage/capsule_store/capsule_store.d.ts +24 -9
  109. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
  110. package/dest/storage/capsule_store/capsule_store.js +130 -23
  111. package/dest/storage/contract_store/contract_store.d.ts +1 -2
  112. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  113. package/dest/storage/contract_store/contract_store.js +27 -30
  114. package/dest/storage/metadata.d.ts +1 -1
  115. package/dest/storage/metadata.js +1 -1
  116. package/dest/storage/note_store/note_store.d.ts +51 -52
  117. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  118. package/dest/storage/note_store/note_store.js +285 -263
  119. package/dest/storage/note_store/stored_note.d.ts +16 -0
  120. package/dest/storage/note_store/stored_note.d.ts.map +1 -0
  121. package/dest/storage/note_store/stored_note.js +43 -0
  122. package/dest/storage/private_event_store/private_event_store.d.ts +43 -8
  123. package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
  124. package/dest/storage/private_event_store/private_event_store.js +226 -111
  125. package/dest/storage/private_event_store/stored_private_event.d.ts +23 -0
  126. package/dest/storage/private_event_store/stored_private_event.d.ts.map +1 -0
  127. package/dest/storage/private_event_store/stored_private_event.js +56 -0
  128. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +15 -8
  129. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
  130. package/dest/storage/tagging_store/recipient_tagging_store.js +88 -19
  131. package/dest/storage/tagging_store/sender_address_book_store.d.ts +1 -1
  132. package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +1 -1
  133. package/dest/storage/tagging_store/sender_address_book_store.js +20 -14
  134. package/dest/storage/tagging_store/sender_tagging_store.d.ts +19 -9
  135. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  136. package/dest/storage/tagging_store/sender_tagging_store.js +252 -100
  137. package/dest/tagging/get_all_logs_by_tags.d.ts +24 -0
  138. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -0
  139. package/dest/tagging/get_all_logs_by_tags.js +46 -0
  140. package/dest/tagging/index.d.ts +2 -1
  141. package/dest/tagging/index.d.ts.map +1 -1
  142. package/dest/tagging/index.js +1 -0
  143. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +3 -2
  144. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
  145. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +6 -6
  146. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +3 -2
  147. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
  148. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +5 -2
  149. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +3 -2
  150. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  151. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +7 -7
  152. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +1 -1
  153. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
  154. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +5 -8
  155. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +5 -2
  156. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  157. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +10 -5
  158. package/package.json +27 -18
  159. package/src/bin/check_oracle_version.ts +1 -0
  160. package/src/block_synchronizer/block_synchronizer.ts +91 -33
  161. package/src/config/index.ts +14 -0
  162. package/src/contract_function_simulator/benchmarked_node.ts +103 -0
  163. package/src/contract_function_simulator/contract_function_simulator.ts +143 -99
  164. package/src/contract_function_simulator/execution_note_cache.ts +44 -25
  165. package/src/contract_function_simulator/index.ts +1 -1
  166. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +1 -1
  167. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +1 -1
  168. package/src/contract_function_simulator/noir-structs/utility_context.ts +6 -25
  169. package/src/contract_function_simulator/oracle/interfaces.ts +22 -12
  170. package/src/contract_function_simulator/oracle/note_packing_utils.ts +10 -10
  171. package/src/contract_function_simulator/oracle/oracle.ts +79 -47
  172. package/src/contract_function_simulator/oracle/private_execution.ts +1 -67
  173. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +116 -104
  174. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +190 -116
  175. package/src/contract_sync/contract_sync_service.ts +129 -0
  176. package/src/contract_sync/helpers.ts +93 -0
  177. package/src/debug/pxe_debug_utils.ts +60 -17
  178. package/src/entrypoints/client/bundle/utils.ts +16 -15
  179. package/src/entrypoints/client/lazy/utils.ts +17 -15
  180. package/src/entrypoints/pxe_creation_options.ts +2 -1
  181. package/src/entrypoints/server/index.ts +2 -0
  182. package/src/entrypoints/server/utils.ts +22 -26
  183. package/src/events/event_service.ts +17 -25
  184. package/src/events/private_event_filter_validator.ts +3 -5
  185. package/src/job_coordinator/job_coordinator.ts +4 -3
  186. package/src/logs/log_service.ts +34 -16
  187. package/src/notes/note_service.ts +38 -43
  188. package/src/oracle_version.ts +4 -3
  189. package/src/private_kernel/hints/index.ts +1 -1
  190. package/src/private_kernel/hints/{build_private_kernel_reset_private_inputs.ts → private_kernel_reset_private_inputs_builder.ts} +32 -20
  191. package/src/private_kernel/private_kernel_execution_prover.ts +7 -4
  192. package/src/private_kernel/private_kernel_oracle.ts +116 -37
  193. package/src/pxe.ts +191 -173
  194. package/src/storage/address_store/address_store.ts +15 -15
  195. package/src/storage/anchor_block_store/anchor_block_store.ts +8 -0
  196. package/src/storage/capsule_store/capsule_store.ts +159 -23
  197. package/src/storage/contract_store/contract_store.ts +26 -35
  198. package/src/storage/metadata.ts +1 -1
  199. package/src/storage/note_store/note_store.ts +321 -318
  200. package/src/storage/note_store/stored_note.ts +48 -0
  201. package/src/storage/private_event_store/private_event_store.ts +292 -124
  202. package/src/storage/private_event_store/stored_private_event.ts +73 -0
  203. package/src/storage/tagging_store/recipient_tagging_store.ts +106 -20
  204. package/src/storage/tagging_store/sender_address_book_store.ts +20 -14
  205. package/src/storage/tagging_store/sender_tagging_store.ts +293 -108
  206. package/src/tagging/get_all_logs_by_tags.ts +68 -0
  207. package/src/tagging/index.ts +1 -0
  208. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +16 -5
  209. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +7 -1
  210. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +9 -6
  211. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +5 -17
  212. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +16 -4
  213. package/dest/contract_function_simulator/proxied_node.d.ts +0 -9
  214. package/dest/contract_function_simulator/proxied_node.d.ts.map +0 -1
  215. package/dest/contract_function_simulator/proxied_node.js +0 -27
  216. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts +0 -28
  217. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts.map +0 -1
  218. package/dest/private_kernel/private_kernel_oracle_impl.d.ts +0 -46
  219. package/dest/private_kernel/private_kernel_oracle_impl.d.ts.map +0 -1
  220. package/dest/private_kernel/private_kernel_oracle_impl.js +0 -85
  221. package/dest/public_storage/public_storage_service.d.ts +0 -24
  222. package/dest/public_storage/public_storage_service.d.ts.map +0 -1
  223. package/dest/public_storage/public_storage_service.js +0 -26
  224. package/dest/tree_membership/tree_membership_service.d.ts +0 -52
  225. package/dest/tree_membership/tree_membership_service.d.ts.map +0 -1
  226. package/dest/tree_membership/tree_membership_service.js +0 -84
  227. package/src/contract_function_simulator/proxied_node.ts +0 -33
  228. package/src/private_kernel/private_kernel_oracle_impl.ts +0 -127
  229. package/src/public_storage/public_storage_service.ts +0 -33
  230. package/src/tree_membership/tree_membership_service.ts +0 -112
package/src/pxe.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { PrivateEventFilter } from '@aztec/aztec.js/wallet';
2
+ import { BlockNumber } from '@aztec/foundation/branded-types';
2
3
  import { Fr } from '@aztec/foundation/curves/bn254';
3
- import { type Logger, createLogger } from '@aztec/foundation/log';
4
+ import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
4
5
  import { SerialQueue } from '@aztec/foundation/queue';
5
6
  import { Timer } from '@aztec/foundation/timer';
6
7
  import { KeyStore } from '@aztec/key-store';
@@ -19,14 +20,12 @@ import type { AuthWitness } from '@aztec/stdlib/auth-witness';
19
20
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
20
21
  import {
21
22
  CompleteAddress,
22
- type ContractClassWithId,
23
23
  type ContractInstanceWithAddress,
24
24
  type PartialAddress,
25
25
  computeContractAddressFromInstance,
26
26
  getContractClassFromArtifact,
27
27
  } from '@aztec/stdlib/contract';
28
28
  import { SimulationError } from '@aztec/stdlib/errors';
29
- import { computeProtocolNullifier, siloNullifier } from '@aztec/stdlib/hash';
30
29
  import type { AztecNode, PrivateKernelProver } from '@aztec/stdlib/interfaces/client';
31
30
  import type {
32
31
  PrivateExecutionStep,
@@ -34,6 +33,7 @@ import type {
34
33
  PrivateKernelTailCircuitPublicInputs,
35
34
  } from '@aztec/stdlib/kernel';
36
35
  import {
36
+ BlockHeader,
37
37
  type ContractOverrides,
38
38
  type InTx,
39
39
  PrivateExecutionResult,
@@ -54,13 +54,14 @@ import { inspect } from 'util';
54
54
 
55
55
  import { BlockSynchronizer } from './block_synchronizer/index.js';
56
56
  import type { PXEConfig } from './config/index.js';
57
+ import { BenchmarkedNodeFactory } from './contract_function_simulator/benchmarked_node.js';
57
58
  import {
58
59
  ContractFunctionSimulator,
59
60
  generateSimulatedProvingResult,
60
61
  } from './contract_function_simulator/contract_function_simulator.js';
61
- import { readCurrentClassId } from './contract_function_simulator/oracle/private_execution.js';
62
62
  import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
63
- import { ProxiedNodeFactory } from './contract_function_simulator/proxied_node.js';
63
+ import { ContractSyncService } from './contract_sync/contract_sync_service.js';
64
+ import { readCurrentClassId } from './contract_sync/helpers.js';
64
65
  import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
65
66
  import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
66
67
  import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
@@ -69,7 +70,7 @@ import {
69
70
  PrivateKernelExecutionProver,
70
71
  type PrivateKernelExecutionProverConfig,
71
72
  } from './private_kernel/private_kernel_execution_prover.js';
72
- import { PrivateKernelOracleImpl } from './private_kernel/private_kernel_oracle_impl.js';
73
+ import { PrivateKernelOracle } from './private_kernel/private_kernel_oracle.js';
73
74
  import { AddressStore } from './storage/address_store/address_store.js';
74
75
  import { AnchorBlockStore } from './storage/anchor_block_store/anchor_block_store.js';
75
76
  import { CapsuleStore } from './storage/capsule_store/capsule_store.js';
@@ -85,6 +86,54 @@ export type PackedPrivateEvent = InTx & {
85
86
  eventSelector: EventSelector;
86
87
  };
87
88
 
89
+ /** Options for PXE.profileTx. */
90
+ export type ProfileTxOpts = {
91
+ /** The profiling mode to use. */
92
+ profileMode: 'full' | 'execution-steps' | 'gates';
93
+ /** If true, proof generation is skipped during profiling. Defaults to true. */
94
+ skipProofGeneration?: boolean;
95
+ };
96
+
97
+ /** Options for PXE.simulateTx. */
98
+ export type SimulateTxOpts = {
99
+ /** Whether to simulate the public part of the transaction. */
100
+ simulatePublic: boolean;
101
+ /** If false, this function throws if the transaction is unable to be included in a block at the current state. */
102
+ skipTxValidation?: boolean;
103
+ /** If false, fees are enforced. */
104
+ skipFeeEnforcement?: boolean;
105
+ /** State overrides for the simulation, such as contract instances and artifacts. */
106
+ overrides?: SimulationOverrides;
107
+ /** The accounts whose notes we can access in this call. Defaults to all. */
108
+ scopes?: AztecAddress[];
109
+ };
110
+
111
+ /** Options for PXE.simulateUtility. */
112
+ export type SimulateUtilityOpts = {
113
+ /** The authentication witnesses required for the function call. */
114
+ authwits?: AuthWitness[];
115
+ /** The accounts whose notes we can access in this call. Defaults to all. */
116
+ scopes?: AztecAddress[];
117
+ };
118
+
119
+ /** Args for PXE.create. */
120
+ export type PXECreateArgs = {
121
+ /** The Aztec node to connect to. */
122
+ node: AztecNode;
123
+ /** The key-value store for persisting PXE state. */
124
+ store: AztecAsyncKVStore;
125
+ /** The prover for generating private kernel proofs. */
126
+ proofCreator: PrivateKernelProver;
127
+ /** The circuit simulator for executing ACIR circuits. */
128
+ simulator: CircuitSimulator;
129
+ /** Provider for protocol contract artifacts and instances. */
130
+ protocolContractsProvider: ProtocolContractsProvider;
131
+ /** PXE configuration options. */
132
+ config: PXEConfig;
133
+ /** Optional logger instance or string suffix for the logger name. */
134
+ loggerOrSuffix?: string | Logger;
135
+ };
136
+
88
137
  /**
89
138
  * Private eXecution Environment (PXE) is a library used by wallets to simulate private phase of transactions and to
90
139
  * manage private state of users.
@@ -103,6 +152,7 @@ export class PXE {
103
152
  private recipientTaggingStore: RecipientTaggingStore,
104
153
  private addressStore: AddressStore,
105
154
  private privateEventStore: PrivateEventStore,
155
+ private contractSyncService: ContractSyncService,
106
156
  private simulator: CircuitSimulator,
107
157
  private proverEnabled: boolean,
108
158
  private proofCreator: PrivateKernelProver,
@@ -120,25 +170,31 @@ export class PXE {
120
170
  *
121
171
  * @returns A promise that resolves PXE is ready to be used.
122
172
  */
123
- public static async create(
124
- node: AztecNode,
125
- store: AztecAsyncKVStore,
126
- proofCreator: PrivateKernelProver,
127
- simulator: CircuitSimulator,
128
- protocolContractsProvider: ProtocolContractsProvider,
129
- config: PXEConfig,
130
- loggerOrSuffix?: string | Logger,
131
- ) {
173
+ public static async create({
174
+ node,
175
+ store,
176
+ proofCreator,
177
+ simulator,
178
+ protocolContractsProvider,
179
+ config,
180
+ loggerOrSuffix,
181
+ }: PXECreateArgs) {
182
+ // Extract bindings from the logger, or use empty bindings if a string suffix is provided.
183
+ const bindings: LoggerBindings | undefined =
184
+ loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
185
+
132
186
  const log =
133
187
  !loggerOrSuffix || typeof loggerOrSuffix === 'string'
134
188
  ? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
135
189
  : loggerOrSuffix;
136
190
 
137
- const proverEnabled = !!config.proverEnabled;
191
+ const info = await node.getNodeInfo();
192
+
193
+ const proverEnabled = config.proverEnabled !== undefined ? config.proverEnabled : info.realProofs;
138
194
  const addressStore = new AddressStore(store);
139
195
  const privateEventStore = new PrivateEventStore(store);
140
196
  const contractStore = new ContractStore(store);
141
- const noteStore = await NoteStore.create(store);
197
+ const noteStore = new NoteStore(store);
142
198
  const anchorBlockStore = new AnchorBlockStore(store);
143
199
  const senderTaggingStore = new SenderTaggingStore(store);
144
200
  const senderAddressBookStore = new SenderAddressBookStore(store);
@@ -146,19 +202,35 @@ export class PXE {
146
202
  const capsuleStore = new CapsuleStore(store);
147
203
  const keyStore = new KeyStore(store);
148
204
  const tipsStore = new L2TipsKVStore(store, 'pxe');
205
+ const contractSyncService = new ContractSyncService(
206
+ node,
207
+ contractStore,
208
+ noteStore,
209
+ createLogger('pxe:contract_sync', bindings),
210
+ );
149
211
  const synchronizer = new BlockSynchronizer(
150
212
  node,
213
+ store,
151
214
  anchorBlockStore,
152
215
  noteStore,
153
216
  privateEventStore,
154
217
  tipsStore,
218
+ contractSyncService,
155
219
  config,
156
- loggerOrSuffix,
220
+ bindings,
157
221
  );
158
222
 
159
- const jobCoordinator = new JobCoordinator(store);
223
+ const jobCoordinator = new JobCoordinator(store, bindings);
224
+ jobCoordinator.registerStores([
225
+ capsuleStore,
226
+ senderTaggingStore,
227
+ recipientTaggingStore,
228
+ privateEventStore,
229
+ noteStore,
230
+ contractSyncService,
231
+ ]);
160
232
 
161
- const debugUtils = new PXEDebugUtils(contractStore, noteStore);
233
+ const debugUtils = new PXEDebugUtils(contractSyncService, noteStore, synchronizer, anchorBlockStore);
162
234
 
163
235
  const jobQueue = new SerialQueue();
164
236
 
@@ -175,6 +247,7 @@ export class PXE {
175
247
  recipientTaggingStore,
176
248
  addressStore,
177
249
  privateEventStore,
250
+ contractSyncService,
178
251
  simulator,
179
252
  proverEnabled,
180
253
  proofCreator,
@@ -185,12 +258,15 @@ export class PXE {
185
258
  debugUtils,
186
259
  );
187
260
 
188
- debugUtils.setPXE(pxe);
261
+ debugUtils.setPXEHelpers(
262
+ pxe.#putInJobQueue.bind(pxe),
263
+ pxe.#getSimulatorForTx.bind(pxe),
264
+ pxe.#simulateUtility.bind(pxe),
265
+ );
189
266
 
190
267
  pxe.jobQueue.start();
191
268
 
192
269
  await pxe.#registerProtocolContracts();
193
- const info = await node.getNodeInfo();
194
270
  log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
195
271
  return pxe;
196
272
  }
@@ -200,20 +276,20 @@ export class PXE {
200
276
  #getSimulatorForTx(overrides?: { contracts?: ContractOverrides }) {
201
277
  const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
202
278
 
203
- return new ContractFunctionSimulator(
204
- proxyContractStore,
205
- this.noteStore,
206
- this.keyStore,
207
- this.addressStore,
208
- ProxiedNodeFactory.create(this.node),
209
- this.anchorBlockStore,
210
- this.senderTaggingStore,
211
- this.recipientTaggingStore,
212
- this.senderAddressBookStore,
213
- this.capsuleStore,
214
- this.privateEventStore,
215
- this.simulator,
216
- );
279
+ return new ContractFunctionSimulator({
280
+ contractStore: proxyContractStore,
281
+ noteStore: this.noteStore,
282
+ keyStore: this.keyStore,
283
+ addressStore: this.addressStore,
284
+ aztecNode: BenchmarkedNodeFactory.create(this.node),
285
+ senderTaggingStore: this.senderTaggingStore,
286
+ recipientTaggingStore: this.recipientTaggingStore,
287
+ senderAddressBookStore: this.senderAddressBookStore,
288
+ capsuleStore: this.capsuleStore,
289
+ privateEventStore: this.privateEventStore,
290
+ simulator: this.simulator,
291
+ contractSyncService: this.contractSyncService,
292
+ });
217
293
  }
218
294
 
219
295
  #contextualizeError(err: Error, ...context: string[]): Error {
@@ -274,19 +350,6 @@ export class PXE {
274
350
  this.log.verbose(`Registered protocol contracts in pxe`, registered);
275
351
  }
276
352
 
277
- async #isContractClassPubliclyRegistered(id: Fr): Promise<boolean> {
278
- return !!(await this.node.getContractClass(id));
279
- }
280
-
281
- async #isContractPublished(address: AztecAddress): Promise<boolean> {
282
- return !!(await this.node.getContract(address));
283
- }
284
-
285
- async #isContractInitialized(address: AztecAddress): Promise<boolean> {
286
- const initNullifier = await siloNullifier(address, address.toField());
287
- return !!(await this.node.getNullifierMembershipWitness('latest', initNullifier));
288
- }
289
-
290
353
  // Executes the entrypoint private function, as well as all nested private
291
354
  // functions that might arise.
292
355
  async #executePrivate(
@@ -300,18 +363,21 @@ export class PXE {
300
363
  try {
301
364
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
302
365
 
303
- const result = await contractFunctionSimulator.run(
304
- txRequest,
366
+ await this.contractSyncService.ensureContractSynced(
305
367
  contractAddress,
306
368
  functionSelector,
307
- undefined,
369
+ privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
308
370
  anchorBlockHeader,
309
- // The sender for tags is set by contracts, typically by an account
310
- // contract entrypoint
311
- undefined, // senderForTags
312
- scopes,
313
371
  jobId,
314
372
  );
373
+
374
+ const result = await contractFunctionSimulator.run(txRequest, {
375
+ contractAddress,
376
+ selector: functionSelector,
377
+ anchorBlockHeader,
378
+ scopes,
379
+ jobId,
380
+ });
315
381
  this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
316
382
  return result;
317
383
  } catch (err) {
@@ -394,85 +460,45 @@ export class PXE {
394
460
  privateExecutionResult: PrivateExecutionResult,
395
461
  config: PrivateKernelExecutionProverConfig,
396
462
  ): Promise<PrivateKernelExecutionProofOutput<PrivateKernelTailCircuitPublicInputs>> {
397
- const simulationAnchorBlock = privateExecutionResult.getSimulationAnchorBlockNumber();
398
- const kernelOracle = new PrivateKernelOracleImpl(
399
- this.contractStore,
400
- this.keyStore,
401
- this.node,
402
- simulationAnchorBlock,
463
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
464
+ const anchorBlockHash = await anchorBlockHeader.hash();
465
+ const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHash);
466
+ const kernelTraceProver = new PrivateKernelExecutionProver(
467
+ kernelOracle,
468
+ proofCreator,
469
+ !this.proverEnabled,
470
+ this.log.getBindings(),
403
471
  );
404
- const kernelTraceProver = new PrivateKernelExecutionProver(kernelOracle, proofCreator, !this.proverEnabled);
405
472
  this.log.debug(`Executing kernel trace prover (${JSON.stringify(config)})...`);
406
473
  return await kernelTraceProver.proveWithKernels(txExecutionRequest.toTxRequest(), privateExecutionResult, config);
407
474
  }
408
475
 
409
476
  // Public API
410
477
 
411
- public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
412
- return this.contractStore.getContractInstance(address);
478
+ /**
479
+ * Returns the block header up to which the PXE has synced.
480
+ * @returns The synced block header
481
+ */
482
+ public getSyncedBlockHeader(): Promise<BlockHeader> {
483
+ return this.anchorBlockStore.getBlockHeader();
413
484
  }
414
485
 
415
486
  /**
416
- * Returns the contract class metadata given a contract class id.
417
- * The metadata consists of its contract class, whether it has been publicly registered, and its artifact.
418
- * @remark - it queries the node to check whether the contract class with the given id has been publicly registered.
419
- * @param id - Identifier of the class.
420
- * @param includeArtifact - Identifier of the class.
421
- * @returns - It returns the contract class metadata, with the artifact field being optional, and will only be returned if true is passed in
422
- * for `includeArtifact`
423
- * TODO(@spalladino): The PXE actually holds artifacts and not classes, what should we return? Also,
424
- * should the pxe query the node for contract public info, and merge it with its own definitions?
425
- * TODO(@spalladino): This method is strictly needed to decide whether to publicly register a class or not
426
- * during a public deployment. We probably want a nicer and more general API for this, but it'll have to
427
- * do for the time being.
487
+ * Returns the contract instance for a given address, if it's registered in the PXE.
488
+ * @param address - The contract address.
489
+ * @returns The contract instance if found, undefined otherwise.
428
490
  */
429
- public async getContractClassMetadata(
430
- id: Fr,
431
- includeArtifact: boolean = false,
432
- ): Promise<{
433
- contractClass: ContractClassWithId | undefined;
434
- isContractClassPubliclyRegistered: boolean;
435
- artifact: ContractArtifact | undefined;
436
- }> {
437
- const artifact = await this.contractStore.getContractArtifact(id);
438
- if (!artifact) {
439
- this.log.warn(`No artifact found for contract class ${id.toString()} when looking for its metadata`);
440
- }
441
-
442
- return {
443
- contractClass: artifact && (await getContractClassFromArtifact(artifact)),
444
- isContractClassPubliclyRegistered: await this.#isContractClassPubliclyRegistered(id),
445
- artifact: includeArtifact ? artifact : undefined,
446
- };
491
+ public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
492
+ return this.contractStore.getContractInstance(address);
447
493
  }
448
494
 
449
495
  /**
450
- * Returns the contract metadata given an address.
451
- * The metadata consists of its contract instance, which includes the contract class identifier,
452
- * initialization hash, deployment salt, and public keys hash; whether the contract instance has been initialized;
453
- * and whether the contract instance with the given address has been publicly deployed.
454
- * @remark - it queries the node to check whether the contract instance has been initialized / publicly deployed through a node.
455
- * This query is not dependent on the PXE.
456
- * @param address - The address that the contract instance resides at.
457
- * @returns - It returns the contract metadata
458
- * TODO(@spalladino): Should we return the public keys in plain as well here?
496
+ * Returns the contract artifact for a given contract class id, if it's registered in the PXE.
497
+ * @param id - Identifier of the contract class.
498
+ * @returns The contract artifact if found, undefined otherwise.
459
499
  */
460
- public async getContractMetadata(address: AztecAddress): Promise<{
461
- contractInstance: ContractInstanceWithAddress | undefined;
462
- isContractInitialized: boolean;
463
- isContractPublished: boolean;
464
- }> {
465
- let instance;
466
- try {
467
- instance = await this.contractStore.getContractInstance(address);
468
- } catch {
469
- this.log.warn(`No instance found for contract ${address.toString()} when looking for its metadata`);
470
- }
471
- return {
472
- contractInstance: instance,
473
- isContractInitialized: await this.#isContractInitialized(address),
474
- isContractPublished: await this.#isContractPublished(address),
475
- };
500
+ public async getContractArtifact(id: Fr): Promise<ContractArtifact | undefined> {
501
+ return await this.contractStore.getContractArtifact(id);
476
502
  }
477
503
 
478
504
  /**
@@ -497,7 +523,6 @@ export class PXE {
497
523
  }
498
524
 
499
525
  await this.addressStore.addCompleteAddress(accountCompleteAddress);
500
- await this.noteStore.addScope(accountCompleteAddress.address);
501
526
  return accountCompleteAddress;
502
527
  }
503
528
 
@@ -645,13 +670,7 @@ export class PXE {
645
670
 
646
671
  const header = await this.anchorBlockStore.getBlockHeader();
647
672
 
648
- const currentClassId = await readCurrentClassId(
649
- contractAddress,
650
- currentInstance,
651
- this.node,
652
- header.globalVariables.blockNumber,
653
- header.globalVariables.timestamp,
654
- );
673
+ const currentClassId = await readCurrentClassId(contractAddress, currentInstance, this.node, header);
655
674
  if (!contractClass.id.equals(currentClassId)) {
656
675
  throw new Error('Could not update contract to a class different from the current one.');
657
676
  }
@@ -744,7 +763,7 @@ export class PXE {
744
763
  // TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
745
764
  const txHash = (await txProvingResult.toTx()).txHash;
746
765
 
747
- await this.senderTaggingStore.storePendingIndexes(preTagsUsedInTheTx, txHash);
766
+ await this.senderTaggingStore.storePendingIndexes(preTagsUsedInTheTx, txHash, jobId);
748
767
  this.log.debug(`Stored used pre-tags as sender for the tx`, {
749
768
  preTagsUsedInTheTx,
750
769
  });
@@ -761,17 +780,13 @@ export class PXE {
761
780
 
762
781
  /**
763
782
  * Profiles a transaction, reporting gate counts (unless disabled) and returns an execution trace.
764
- *
765
- * @param txRequest - An authenticated tx request ready for simulation
766
- * @param msgSender - (Optional) The message sender to use for the simulation.
767
- * @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
783
+ * @param txRequest - An authenticated tx request ready for simulation.
768
784
  * @returns A trace of the program execution with gate counts.
769
785
  * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
770
786
  */
771
787
  public profileTx(
772
788
  txRequest: TxExecutionRequest,
773
- profileMode: 'full' | 'execution-steps' | 'gates',
774
- skipProofGeneration: boolean = true,
789
+ { profileMode, skipProofGeneration = true }: ProfileTxOpts,
775
790
  ): Promise<TxProfileResult> {
776
791
  // We disable concurrent profiles for consistency with simulateTx.
777
792
  return this.#putInJobQueue(async jobId => {
@@ -856,12 +871,7 @@ export class PXE {
856
871
  * In that case, the transaction returned is only potentially ready to be sent to the network for execution.
857
872
  *
858
873
  *
859
- * @param txRequest - An authenticated tx request ready for simulation
860
- * @param simulatePublic - Whether to simulate the public part of the transaction.
861
- * @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
862
- * @param skipFeeEnforcement - (Optional) If false, fees are enforced.
863
- * @param overrides - (Optional) State overrides for the simulation, such as msgSender, contract instances and artifacts.
864
- * @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will default to all.
874
+ * @param txRequest - An authenticated tx request ready for simulation.
865
875
  * @returns A simulated transaction result object that includes public and private return values.
866
876
  * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
867
877
  * Also throws if simulatePublic is true and public simulation reverts.
@@ -870,11 +880,7 @@ export class PXE {
870
880
  */
871
881
  public simulateTx(
872
882
  txRequest: TxExecutionRequest,
873
- simulatePublic: boolean,
874
- skipTxValidation: boolean = false,
875
- skipFeeEnforcement: boolean = false,
876
- overrides?: SimulationOverrides,
877
- scopes?: AztecAddress[],
883
+ { simulatePublic, skipTxValidation = false, skipFeeEnforcement = false, overrides, scopes }: SimulateTxOpts,
878
884
  ): Promise<TxSimulationResult> {
879
885
  // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
880
886
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
@@ -902,7 +908,14 @@ export class PXE {
902
908
  // Temporary: in case there are overrides, we have to skip the kernels or validations
903
909
  // will fail. Consider handing control to the user/wallet on whether they want to run them
904
910
  // or not.
905
- const skipKernels = overrides?.contracts !== undefined && Object.keys(overrides.contracts ?? {}).length > 0;
911
+ const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
912
+ const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
913
+ const skipKernels = hasOverriddenContracts;
914
+
915
+ // Set overridden contracts on the sync service so it knows to skip syncing them
916
+ if (hasOverriddenContracts) {
917
+ this.contractSyncService.setOverriddenContracts(jobId, overriddenContracts);
918
+ }
906
919
 
907
920
  // Execution of private functions only; no proving, and no kernel logic.
908
921
  const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
@@ -911,15 +924,9 @@ export class PXE {
911
924
  let executionSteps: PrivateExecutionStep[] = [];
912
925
 
913
926
  if (skipKernels) {
914
- // According to the protocol rules, the nonce generator for the note hashes
915
- // can either be the first nullifier in the tx or the protocol nullifier if there are none.
916
- const nonceGenerator = privateExecutionResult.firstNullifier.equals(Fr.ZERO)
917
- ? await computeProtocolNullifier(await txRequest.toTxRequest().hash())
918
- : privateExecutionResult.firstNullifier;
919
927
  ({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
920
928
  privateExecutionResult,
921
- nonceGenerator,
922
- this.contractStore,
929
+ (addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
923
930
  ));
924
931
  } else {
925
932
  // Kernel logic, plus proving of all private functions and kernels.
@@ -1004,18 +1011,12 @@ export class PXE {
1004
1011
  }
1005
1012
 
1006
1013
  /**
1007
- * Simulate the execution of a contract utility function.
1008
- *
1014
+ * Simulates the execution of a contract utility function.
1009
1015
  * @param call - The function call containing the function details, arguments, and target contract address.
1010
- * @param authwits - (Optional) The authentication witnesses required for the function call.
1011
- * @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will
1012
- * default to all.
1013
- * @returns The result of the utility function call, structured based on the function ABI.
1014
1016
  */
1015
1017
  public simulateUtility(
1016
1018
  call: FunctionCall,
1017
- authwits?: AuthWitness[],
1018
- scopes?: AztecAddress[],
1019
+ { authwits, scopes }: SimulateUtilityOpts = {},
1019
1020
  ): Promise<UtilitySimulationResult> {
1020
1021
  // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
1021
1022
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
@@ -1029,8 +1030,13 @@ export class PXE {
1029
1030
  const functionTimer = new Timer();
1030
1031
  const contractFunctionSimulator = this.#getSimulatorForTx();
1031
1032
 
1032
- await this.contractStore.syncPrivateState(call.to, call.selector, privateSyncCall =>
1033
- this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
1033
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
1034
+ await this.contractSyncService.ensureContractSynced(
1035
+ call.to,
1036
+ call.selector,
1037
+ privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
1038
+ anchorBlockHeader,
1039
+ jobId,
1034
1040
  );
1035
1041
 
1036
1042
  const executionResult = await this.#simulateUtility(
@@ -1080,26 +1086,38 @@ export class PXE {
1080
1086
  * Defaults to the latest known block to PXE + 1.
1081
1087
  * @returns - The packed events with block and tx metadata.
1082
1088
  */
1083
- public getPrivateEvents(eventSelector: EventSelector, filter: PrivateEventFilter): Promise<PackedPrivateEvent[]> {
1084
- return this.#putInJobQueue(async jobId => {
1089
+ public async getPrivateEvents(
1090
+ eventSelector: EventSelector,
1091
+ filter: PrivateEventFilter,
1092
+ ): Promise<PackedPrivateEvent[]> {
1093
+ let anchorBlockNumber: BlockNumber;
1094
+
1095
+ await this.#putInJobQueue(async jobId => {
1085
1096
  await this.blockStateSynchronizer.sync();
1097
+
1098
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
1099
+ anchorBlockNumber = anchorBlockHeader.getBlockNumber();
1100
+
1086
1101
  const contractFunctionSimulator = this.#getSimulatorForTx();
1087
1102
 
1088
- await this.contractStore.syncPrivateState(
1103
+ await this.contractSyncService.ensureContractSynced(
1089
1104
  filter.contractAddress,
1090
1105
  null,
1091
1106
  async privateSyncCall =>
1092
1107
  await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
1108
+ anchorBlockHeader,
1109
+ jobId,
1093
1110
  );
1111
+ });
1094
1112
 
1095
- const sanitizedFilter = await new PrivateEventFilterValidator(this.anchorBlockStore).validate(filter);
1113
+ // anchorBlockNumber is set during the job and fixed to whatever it is after a block sync
1114
+ const sanitizedFilter = new PrivateEventFilterValidator(anchorBlockNumber!).validate(filter);
1096
1115
 
1097
- this.log.debug(
1098
- `Getting private events for ${sanitizedFilter.contractAddress.toString()} from ${sanitizedFilter.fromBlock} to ${sanitizedFilter.toBlock}`,
1099
- );
1116
+ this.log.debug(
1117
+ `Getting private events for ${sanitizedFilter.contractAddress.toString()} from ${sanitizedFilter.fromBlock} to ${sanitizedFilter.toBlock}`,
1118
+ );
1100
1119
 
1101
- return this.privateEventStore.getPrivateEvents(eventSelector, sanitizedFilter);
1102
- });
1120
+ return this.privateEventStore.getPrivateEvents(eventSelector, sanitizedFilter);
1103
1121
  }
1104
1122
 
1105
1123
  /**
@@ -43,23 +43,23 @@ export class AddressStore {
43
43
  });
44
44
  }
45
45
 
46
- async #getCompleteAddress(address: AztecAddress): Promise<CompleteAddress | undefined> {
47
- const index = await this.#completeAddressIndex.getAsync(address.toString());
48
- if (index === undefined) {
49
- return undefined;
50
- }
51
-
52
- const value = await this.#completeAddresses.atAsync(index);
53
- return value ? await CompleteAddress.fromBuffer(value) : undefined;
54
- }
55
-
56
46
  getCompleteAddress(account: AztecAddress): Promise<CompleteAddress | undefined> {
57
- return this.#getCompleteAddress(account);
47
+ return this.#store.transactionAsync(async () => {
48
+ const index = await this.#completeAddressIndex.getAsync(account.toString());
49
+ if (index === undefined) {
50
+ return undefined;
51
+ }
52
+
53
+ const value = await this.#completeAddresses.atAsync(index);
54
+ return value ? await CompleteAddress.fromBuffer(value) : undefined;
55
+ });
58
56
  }
59
57
 
60
- async getCompleteAddresses(): Promise<CompleteAddress[]> {
61
- return await Promise.all(
62
- (await toArray(this.#completeAddresses.valuesAsync())).map(v => CompleteAddress.fromBuffer(v)),
63
- );
58
+ getCompleteAddresses(): Promise<CompleteAddress[]> {
59
+ return this.#store.transactionAsync(async () => {
60
+ return await Promise.all(
61
+ (await toArray(this.#completeAddresses.valuesAsync())).map(v => CompleteAddress.fromBuffer(v)),
62
+ );
63
+ });
64
64
  }
65
65
  }
@@ -10,6 +10,14 @@ export class AnchorBlockStore {
10
10
  this.#synchronizedHeader = this.#store.openSingleton('header');
11
11
  }
12
12
 
13
+ /**
14
+ * Sets the currently synchronized block
15
+ *
16
+ * Important: this method is only called from BlockSynchronizer, and since we need it to run atomically with other
17
+ * stores in the case of a reorg, it MUST NOT be wrapped in a `transactionAsync` call. Doing so would result in a
18
+ * deadlock when the backend is IndexedDB, because `transactionAsync` is not designed to support reentrancy.
19
+ *
20
+ */
13
21
  async setHeader(header: BlockHeader): Promise<void> {
14
22
  await this.#synchronizedHeader.set(header.toBuffer());
15
23
  }