@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
@@ -0,0 +1,129 @@
1
+ import type { Logger } from '@aztec/foundation/log';
2
+ import type { FunctionCall, FunctionSelector } from '@aztec/stdlib/abi';
3
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
+ import type { AztecNode } from '@aztec/stdlib/interfaces/client';
5
+ import type { BlockHeader } from '@aztec/stdlib/tx';
6
+
7
+ import type { StagedStore } from '../job_coordinator/job_coordinator.js';
8
+ import type { ContractStore } from '../storage/contract_store/contract_store.js';
9
+ import type { NoteStore } from '../storage/note_store/note_store.js';
10
+ import { syncState, verifyCurrentClassId } from './helpers.js';
11
+
12
+ /**
13
+ * Service for syncing the private state of contracts and verifying that the PXE holds the current class artifact.
14
+ * It uses a cache to avoid redundant sync operations - the cache is wiped when the anchor block changes.
15
+ *
16
+ * TODO: The StagedStore naming is broken here. Figure out a better name.
17
+ */
18
+ export class ContractSyncService implements StagedStore {
19
+ readonly storeName = 'contract_sync';
20
+
21
+ // Tracks contracts synced since last wipe. Key is contract address string, value is a promise that resolves when
22
+ // the contract is synced.
23
+ private syncedContracts: Map<string, Promise<void>> = new Map();
24
+
25
+ // Per-job overridden contract addresses - these contracts should not be synced.
26
+ private overriddenContracts: Map<string, Set<string>> = new Map();
27
+
28
+ constructor(
29
+ private aztecNode: AztecNode,
30
+ private contractStore: ContractStore,
31
+ private noteStore: NoteStore,
32
+ private log: Logger,
33
+ ) {}
34
+
35
+ /** Sets contracts that should be skipped during sync for a specific job. */
36
+ setOverriddenContracts(jobId: string, addresses: Set<string>): void {
37
+ this.overriddenContracts.set(jobId, addresses);
38
+ }
39
+
40
+ /**
41
+ * Ensures a contract's private state is synchronized and that the PXE holds the current class artifact.
42
+ * Uses a cache to avoid redundant sync operations - the cache is wiped when the anchor block changes.
43
+ * @param contractAddress - The address of the contract to sync.
44
+ * @param functionToInvokeAfterSync - The function selector that will be called after sync (used to validate it's
45
+ * not sync_state itself).
46
+ * @param utilityExecutor - Executor function for running the sync_state utility function.
47
+ */
48
+ async ensureContractSynced(
49
+ contractAddress: AztecAddress,
50
+ functionToInvokeAfterSync: FunctionSelector | null,
51
+ utilityExecutor: (call: FunctionCall) => Promise<any>,
52
+ anchorBlockHeader: BlockHeader,
53
+ jobId: string,
54
+ ): Promise<void> {
55
+ const key = contractAddress.toString();
56
+
57
+ // Skip sync if this contract has an override for this job
58
+ const overrides = this.overriddenContracts.get(jobId);
59
+ if (overrides?.has(key)) {
60
+ return;
61
+ }
62
+
63
+ const existing = this.syncedContracts.get(key);
64
+ if (existing) {
65
+ return existing;
66
+ }
67
+
68
+ const syncPromise = this.#doSync(
69
+ contractAddress,
70
+ functionToInvokeAfterSync,
71
+ utilityExecutor,
72
+ anchorBlockHeader,
73
+ jobId,
74
+ );
75
+ this.syncedContracts.set(key, syncPromise);
76
+
77
+ try {
78
+ await syncPromise;
79
+ } catch (err) {
80
+ // There was an error syncing the contract, so we remove it from the cache so that it can be retried.
81
+ this.syncedContracts.delete(key);
82
+ throw err;
83
+ }
84
+ }
85
+
86
+ async #doSync(
87
+ contractAddress: AztecAddress,
88
+ functionToInvokeAfterSync: FunctionSelector | null,
89
+ utilityExecutor: (call: FunctionCall) => Promise<any>,
90
+ anchorBlockHeader: BlockHeader,
91
+ jobId: string,
92
+ ): Promise<void> {
93
+ this.log.debug(`Syncing contract ${contractAddress}`);
94
+ await Promise.all([
95
+ syncState(
96
+ contractAddress,
97
+ this.contractStore,
98
+ functionToInvokeAfterSync,
99
+ utilityExecutor,
100
+ this.noteStore,
101
+ this.aztecNode,
102
+ anchorBlockHeader,
103
+ jobId,
104
+ ),
105
+ verifyCurrentClassId(contractAddress, this.aztecNode, this.contractStore, anchorBlockHeader),
106
+ ]);
107
+ this.log.debug(`Contract ${contractAddress} synced`);
108
+ }
109
+
110
+ /** Clears sync cache. Called by BlockSynchronizer when anchor block changes. */
111
+ wipe(): void {
112
+ this.log.debug(`Wiping contract sync cache (${this.syncedContracts.size} entries)`);
113
+ this.syncedContracts.clear();
114
+ }
115
+
116
+ commit(jobId: string): Promise<void> {
117
+ // Clear overridden contracts for this job
118
+ this.overriddenContracts.delete(jobId);
119
+ return Promise.resolve();
120
+ }
121
+
122
+ discardStaged(jobId: string): Promise<void> {
123
+ // We clear the synced contracts cache here because, when the job is discarded, any associated database writes from
124
+ // the sync are also undone.
125
+ this.syncedContracts.clear();
126
+ this.overriddenContracts.delete(jobId);
127
+ return Promise.resolve();
128
+ }
129
+ }
@@ -0,0 +1,93 @@
1
+ import { ProtocolContractAddress, isProtocolContract } from '@aztec/protocol-contracts';
2
+ import type { FunctionCall, FunctionSelector } from '@aztec/stdlib/abi';
3
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
+ import type { ContractInstance } from '@aztec/stdlib/contract';
5
+ import { DelayedPublicMutableValues, DelayedPublicMutableValuesWithHash } from '@aztec/stdlib/delayed-public-mutable';
6
+ import type { AztecNode } from '@aztec/stdlib/interfaces/client';
7
+ import type { BlockHeader } from '@aztec/stdlib/tx';
8
+
9
+ import { NoteService } from '../notes/note_service.js';
10
+ import type { ContractStore } from '../storage/contract_store/contract_store.js';
11
+ import type { NoteStore } from '../storage/note_store/note_store.js';
12
+
13
+ /**
14
+ * Read the current class id of a contract from the execution data provider or AztecNode. If not found, class id
15
+ * from the instance is used.
16
+ * @param contractAddress - The address of the contract to read the class id for.
17
+ * @param instance - The instance of the contract.
18
+ * @param aztecNode - The Aztec node to query for storage.
19
+ * @param header - The header of the block at which to load the DelayedPublicMutable storing the class id.
20
+ * @returns The current class id.
21
+ */
22
+ export async function readCurrentClassId(
23
+ contractAddress: AztecAddress,
24
+ instance: ContractInstance,
25
+ aztecNode: AztecNode,
26
+ header: BlockHeader,
27
+ ) {
28
+ const blockHash = await header.hash();
29
+ const timestamp = header.globalVariables.timestamp;
30
+ const { delayedPublicMutableSlot } = await DelayedPublicMutableValuesWithHash.getContractUpdateSlots(contractAddress);
31
+ const delayedPublicMutableValues = await DelayedPublicMutableValues.readFromTree(delayedPublicMutableSlot, slot =>
32
+ aztecNode.getPublicStorageAt(blockHash, ProtocolContractAddress.ContractInstanceRegistry, slot),
33
+ );
34
+ let currentClassId = delayedPublicMutableValues.svc.getCurrentAt(timestamp)[0];
35
+ if (currentClassId.isZero()) {
36
+ currentClassId = instance.originalContractClassId;
37
+ }
38
+ return currentClassId;
39
+ }
40
+
41
+ export async function syncState(
42
+ contractAddress: AztecAddress,
43
+ contractStore: ContractStore,
44
+ functionToInvokeAfterSync: FunctionSelector | null,
45
+ utilityExecutor: (privateSyncCall: FunctionCall) => Promise<any>,
46
+ noteStore: NoteStore,
47
+ aztecNode: AztecNode,
48
+ anchorBlockHeader: BlockHeader,
49
+ jobId: string,
50
+ ) {
51
+ // Protocol contracts don't have private state to sync
52
+ if (!isProtocolContract(contractAddress)) {
53
+ const syncStateFunctionCall = await contractStore.getFunctionCall('sync_state', [], contractAddress);
54
+ if (functionToInvokeAfterSync && functionToInvokeAfterSync.equals(syncStateFunctionCall.selector)) {
55
+ throw new Error(
56
+ 'Forbidden `sync_state` invocation. `sync_state` can only be invoked by PXE, manual execution can lead to inconsistencies.',
57
+ );
58
+ }
59
+
60
+ const noteService = new NoteService(noteStore, aztecNode, anchorBlockHeader, jobId);
61
+
62
+ // Both sync_state and syncNoteNullifiers interact with the note store, but running them in parallel is safe
63
+ // because note store is designed to handle concurrent operations.
64
+ await Promise.all([utilityExecutor(syncStateFunctionCall), noteService.syncNoteNullifiers(contractAddress)]);
65
+ }
66
+ }
67
+
68
+ /**
69
+ * Verify that the current class id of a contract obtained from AztecNode is the same as the one in contract data
70
+ * provider (i.e. PXE's own storage).
71
+ * @param contractAddress - The address of the contract to verify.
72
+ * @param aztecNode - The Aztec node to query for storage.
73
+ * @param contractStore - The contract store to fetch the local instance from.
74
+ * @param header - The header of the block at which to verify the current class id.
75
+ */
76
+ export async function verifyCurrentClassId(
77
+ contractAddress: AztecAddress,
78
+ aztecNode: AztecNode,
79
+ contractStore: ContractStore,
80
+ header: BlockHeader,
81
+ ) {
82
+ const instance = await contractStore.getContractInstance(contractAddress);
83
+ if (!instance) {
84
+ throw new Error(`No contract instance found for address ${contractAddress.toString()}`);
85
+ }
86
+
87
+ const currentClassId = await readCurrentClassId(contractAddress, instance, aztecNode, header);
88
+ if (!instance.currentContractClassId.equals(currentClassId)) {
89
+ throw new Error(
90
+ `Contract ${contractAddress} is outdated, current class id is ${currentClassId}, local class id is ${instance.currentContractClassId}`,
91
+ );
92
+ }
93
+ }
@@ -1,7 +1,13 @@
1
+ import type { FunctionCall } from '@aztec/stdlib/abi';
2
+ import type { AuthWitness } from '@aztec/stdlib/auth-witness';
3
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
1
4
  import type { NoteDao, NotesFilter } from '@aztec/stdlib/note';
5
+ import type { ContractOverrides } from '@aztec/stdlib/tx';
2
6
 
3
- import type { PXE } from '../pxe.js';
4
- import type { ContractStore } from '../storage/contract_store/contract_store.js';
7
+ import type { BlockSynchronizer } from '../block_synchronizer/block_synchronizer.js';
8
+ import type { ContractFunctionSimulator } from '../contract_function_simulator/contract_function_simulator.js';
9
+ import type { ContractSyncService } from '../contract_sync/contract_sync_service.js';
10
+ import type { AnchorBlockStore } from '../storage/index.js';
5
11
  import type { NoteStore } from '../storage/note_store/note_store.js';
6
12
 
7
13
  /**
@@ -9,18 +15,38 @@ import type { NoteStore } from '../storage/note_store/note_store.js';
9
15
  * No backwards compatibility or API stability should be expected. Use at your own risk.
10
16
  */
11
17
  export class PXEDebugUtils {
12
- #pxe: PXE | undefined = undefined;
18
+ #putJobInQueue!: <T>(job: (jobId: string) => Promise<T>) => Promise<T>;
19
+ #getSimulatorForTx!: (overrides?: { contracts?: ContractOverrides }) => ContractFunctionSimulator;
20
+ #simulateUtility!: (
21
+ contractFunctionSimulator: ContractFunctionSimulator,
22
+ call: FunctionCall,
23
+ authWitnesses: AuthWitness[] | undefined,
24
+ scopes: AztecAddress[] | undefined,
25
+ jobId: string,
26
+ ) => Promise<any>;
13
27
 
14
28
  constructor(
15
- private contractStore: ContractStore,
29
+ private contractSyncService: ContractSyncService,
16
30
  private noteStore: NoteStore,
31
+ private blockStateSynchronizer: BlockSynchronizer,
32
+ private anchorBlockStore: AnchorBlockStore,
17
33
  ) {}
18
34
 
19
- /**
20
- * Not injected through constructor since they're are co-dependant.
21
- */
22
- public setPXE(pxe: PXE) {
23
- this.#pxe = pxe;
35
+ /** Not injected through constructor since they're are co-dependant */
36
+ public setPXEHelpers(
37
+ putJobInQueue: <T>(job: (jobId: string) => Promise<T>) => Promise<T>,
38
+ getSimulatorForTx: (overrides?: { contracts?: ContractOverrides }) => ContractFunctionSimulator,
39
+ simulateUtility: (
40
+ contractFunctionSimulator: ContractFunctionSimulator,
41
+ call: FunctionCall,
42
+ authWitnesses: AuthWitness[] | undefined,
43
+ scopes: AztecAddress[] | undefined,
44
+ jobId: string,
45
+ ) => Promise<any>,
46
+ ) {
47
+ this.#putJobInQueue = putJobInQueue;
48
+ this.#getSimulatorForTx = getSimulatorForTx;
49
+ this.#simulateUtility = simulateUtility;
24
50
  }
25
51
 
26
52
  /**
@@ -34,15 +60,32 @@ export class PXEDebugUtils {
34
60
  * @param filter - The filter to apply to the notes.
35
61
  * @returns The requested notes.
36
62
  */
37
- public async getNotes(filter: NotesFilter): Promise<NoteDao[]> {
38
- if (!this.#pxe) {
39
- throw new Error('Cannot getNotes because no PXE is set');
40
- }
63
+ public getNotes(filter: NotesFilter): Promise<NoteDao[]> {
64
+ return this.#putJobInQueue(async (jobId: string) => {
65
+ await this.blockStateSynchronizer.sync();
66
+
67
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
68
+
69
+ const contractFunctionSimulator = this.#getSimulatorForTx();
41
70
 
42
- // We need to manually trigger private state sync to have a guarantee that all the notes are available.
43
- const call = await this.contractStore.getFunctionCall('sync_private_state', [], filter.contractAddress);
44
- await this.#pxe.simulateUtility(call);
71
+ await this.contractSyncService.ensureContractSynced(
72
+ filter.contractAddress,
73
+ null,
74
+ async privateSyncCall =>
75
+ await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
76
+ anchorBlockHeader,
77
+ jobId,
78
+ );
45
79
 
46
- return this.noteStore.getNotes(filter);
80
+ return this.noteStore.getNotes(filter, jobId);
81
+ });
82
+ }
83
+
84
+ /**
85
+ * Triggers a sync of the PXE with the node.
86
+ * Blocks until the sync is complete.
87
+ */
88
+ public sync(): Promise<void> {
89
+ return this.#putJobInQueue(() => this.blockStateSynchronizer.sync());
47
90
  }
48
91
  }
@@ -1,6 +1,5 @@
1
1
  import { BBPrivateKernelProver } from '@aztec/bb-prover/client';
2
2
  import { BBBundlePrivateKernelProver } from '@aztec/bb-prover/client/bundle';
3
- import { randomBytes } from '@aztec/foundation/crypto/random';
4
3
  import { createLogger } from '@aztec/foundation/log';
5
4
  import { createStore } from '@aztec/kv-store/indexeddb';
6
5
  import { BundledProtocolContractsProvider } from '@aztec/protocol-contracts/providers/bundle';
@@ -9,6 +8,7 @@ import type { AztecNode } from '@aztec/stdlib/interfaces/client';
9
8
 
10
9
  import type { PXEConfig } from '../../../config/index.js';
11
10
  import { PXE } from '../../../pxe.js';
11
+ import { PXE_DATA_SCHEMA_VERSION } from '../../../storage/metadata.js';
12
12
  import type { PXECreationOptions } from '../../pxe_creation_options.js';
13
13
 
14
14
  /**
@@ -26,13 +26,7 @@ export async function createPXE(
26
26
  config: PXEConfig,
27
27
  options: PXECreationOptions = { loggers: {} },
28
28
  ) {
29
- const logSuffix =
30
- typeof options.useLogSuffix === 'boolean'
31
- ? options.useLogSuffix
32
- ? randomBytes(3).toString('hex')
33
- : undefined
34
- : options.useLogSuffix;
35
-
29
+ const actor = options.loggerActorLabel;
36
30
  const loggers = options.loggers ?? {};
37
31
 
38
32
  const l1Contracts = await aztecNode.getL1ContractAddresses();
@@ -41,14 +35,13 @@ export async function createPXE(
41
35
  l1Contracts,
42
36
  } as PXEConfig;
43
37
 
44
- const storeLogger = loggers.store ? loggers.store : createLogger('pxe:data:idb' + (logSuffix ? `:${logSuffix}` : ''));
38
+ const storeLogger = loggers.store ?? createLogger('pxe:data:idb', { actor });
45
39
 
46
- const store = options.store ?? (await createStore('pxe_data', configWithContracts, storeLogger));
40
+ const store =
41
+ options.store ?? (await createStore('pxe_data', configWithContracts, PXE_DATA_SCHEMA_VERSION, storeLogger));
47
42
 
48
43
  const simulator = options.simulator ?? new WASMSimulator();
49
- const proverLogger = loggers.prover
50
- ? loggers.prover
51
- : createLogger('pxe:bb:wasm:bundle' + (logSuffix ? `:${logSuffix}` : ''));
44
+ const proverLogger = loggers.prover ?? createLogger('pxe:bb:wasm:bundle', { actor });
52
45
 
53
46
  let prover;
54
47
  if (options.proverOrOptions instanceof BBPrivateKernelProver) {
@@ -58,7 +51,15 @@ export async function createPXE(
58
51
  }
59
52
  const protocolContractsProvider = new BundledProtocolContractsProvider();
60
53
 
61
- const pxeLogger = loggers.pxe ? loggers.pxe : createLogger('pxe:service' + (logSuffix ? `:${logSuffix}` : ''));
62
- const pxe = await PXE.create(aztecNode, store, prover, simulator, protocolContractsProvider, config, pxeLogger);
54
+ const pxeLogger = loggers.pxe ?? createLogger('pxe:service', { actor });
55
+ const pxe = await PXE.create({
56
+ node: aztecNode,
57
+ store,
58
+ proofCreator: prover,
59
+ simulator,
60
+ protocolContractsProvider,
61
+ config,
62
+ loggerOrSuffix: pxeLogger,
63
+ });
63
64
  return pxe;
64
65
  }
@@ -1,6 +1,5 @@
1
1
  import { BBPrivateKernelProver } from '@aztec/bb-prover/client';
2
2
  import { BBLazyPrivateKernelProver } from '@aztec/bb-prover/client/lazy';
3
- import { randomBytes } from '@aztec/foundation/crypto/random';
4
3
  import { createLogger } from '@aztec/foundation/log';
5
4
  import { createStore } from '@aztec/kv-store/indexeddb';
6
5
  import { LazyProtocolContractsProvider } from '@aztec/protocol-contracts/providers/lazy';
@@ -9,6 +8,7 @@ import type { AztecNode } from '@aztec/stdlib/interfaces/client';
9
8
 
10
9
  import type { PXEConfig } from '../../../config/index.js';
11
10
  import { PXE } from '../../../pxe.js';
11
+ import { PXE_DATA_SCHEMA_VERSION } from '../../../storage/metadata.js';
12
12
  import type { PXECreationOptions } from '../../pxe_creation_options.js';
13
13
 
14
14
  /**
@@ -17,7 +17,7 @@ import type { PXECreationOptions } from '../../pxe_creation_options.js';
17
17
  *
18
18
  * @param aztecNode - The AztecNode instance to be used by the server.
19
19
  * @param config - The PXE Config to use
20
- * @param
20
+ * @param options - (Optional) Optional information for creating an PXE.
21
21
  * @returns A Promise that resolves to the started PXE instance.
22
22
  */
23
23
  export async function createPXE(
@@ -25,12 +25,7 @@ export async function createPXE(
25
25
  config: PXEConfig,
26
26
  options: PXECreationOptions = { loggers: {} },
27
27
  ) {
28
- const logSuffix =
29
- typeof options.useLogSuffix === 'boolean'
30
- ? options.useLogSuffix
31
- ? randomBytes(3).toString('hex')
32
- : undefined
33
- : options.useLogSuffix;
28
+ const actor = options.loggerActorLabel;
34
29
 
35
30
  const l1Contracts = await aztecNode.getL1ContractAddresses();
36
31
  const configWithContracts = {
@@ -40,14 +35,13 @@ export async function createPXE(
40
35
 
41
36
  const loggers = options.loggers ?? {};
42
37
 
43
- const storeLogger = loggers.store ? loggers.store : createLogger('pxe:data:idb' + (logSuffix ? `:${logSuffix}` : ''));
38
+ const storeLogger = loggers.store ?? createLogger('pxe:data:idb', { actor });
44
39
 
45
- const store = options.store ?? (await createStore('pxe_data', configWithContracts, storeLogger));
40
+ const store =
41
+ options.store ?? (await createStore('pxe_data', configWithContracts, PXE_DATA_SCHEMA_VERSION, storeLogger));
46
42
 
47
43
  const simulator = options.simulator ?? new WASMSimulator();
48
- const proverLogger = loggers.prover
49
- ? loggers.prover
50
- : createLogger('pxe:bb:wasm:bundle' + (logSuffix ? `:${logSuffix}` : ''));
44
+ const proverLogger = loggers.prover ?? createLogger('pxe:bb:wasm:bundle', { actor });
51
45
 
52
46
  let prover;
53
47
  if (options.proverOrOptions instanceof BBPrivateKernelProver) {
@@ -57,7 +51,15 @@ export async function createPXE(
57
51
  }
58
52
  const protocolContractsProvider = new LazyProtocolContractsProvider();
59
53
 
60
- const pxeLogger = loggers.pxe ? loggers.pxe : createLogger('pxe:service' + (logSuffix ? `:${logSuffix}` : ''));
61
- const pxe = await PXE.create(aztecNode, store, prover, simulator, protocolContractsProvider, config, pxeLogger);
54
+ const pxeLogger = loggers.pxe ?? createLogger('pxe:service', { actor });
55
+ const pxe = await PXE.create({
56
+ node: aztecNode,
57
+ store,
58
+ proofCreator: prover,
59
+ simulator,
60
+ protocolContractsProvider,
61
+ config,
62
+ loggerOrSuffix: pxeLogger,
63
+ });
62
64
  return pxe;
63
65
  }
@@ -6,7 +6,8 @@ import type { PrivateKernelProver } from '@aztec/stdlib/interfaces/client';
6
6
 
7
7
  export type PXECreationOptions = {
8
8
  loggers?: { store?: Logger; pxe?: Logger; prover?: Logger };
9
- useLogSuffix?: boolean | string;
9
+ /** Actor label to include in log output (e.g., 'pxe-0', 'pxe-test'). */
10
+ loggerActorLabel?: string;
10
11
  proverOrOptions?: PrivateKernelProver | BBPrivateKernelProverOptions;
11
12
  store?: AztecAsyncKVStore;
12
13
  simulator?: CircuitSimulator;
@@ -6,3 +6,5 @@ export * from './utils.js';
6
6
  export { NoteService } from '../../notes/note_service.js';
7
7
  export { ORACLE_VERSION } from '../../oracle_version.js';
8
8
  export { type PXECreationOptions } from '../pxe_creation_options.js';
9
+ export { JobCoordinator } from '../../job_coordinator/job_coordinator.js';
10
+ export { ContractSyncService } from '../../contract_sync/contract_sync_service.js';
@@ -1,6 +1,5 @@
1
1
  import { BBPrivateKernelProver } from '@aztec/bb-prover/client';
2
2
  import { BBBundlePrivateKernelProver } from '@aztec/bb-prover/client/bundle';
3
- import { randomBytes } from '@aztec/foundation/crypto/random';
4
3
  import { createLogger } from '@aztec/foundation/log';
5
4
  import { createStore } from '@aztec/kv-store/lmdb-v2';
6
5
  import { BundledProtocolContractsProvider } from '@aztec/protocol-contracts/providers/bundle';
@@ -20,17 +19,13 @@ export async function createPXE(
20
19
  config: PXEConfigWithoutDefaults,
21
20
  options: PXECreationOptions = { loggers: {} },
22
21
  ) {
22
+ const actor = options.loggerActorLabel;
23
+ const recorderLogger = createLogger('simulator:acvm:recording', { actor });
23
24
  const recorder = process.env.CIRCUIT_RECORD_DIR
24
- ? new FileCircuitRecorder(process.env.CIRCUIT_RECORD_DIR)
25
- : new MemoryCircuitRecorder();
26
- const simulator = new SimulatorRecorderWrapper(new WASMSimulator(), recorder);
27
-
28
- const logSuffix =
29
- typeof options.useLogSuffix === 'boolean'
30
- ? options.useLogSuffix
31
- ? randomBytes(3).toString('hex')
32
- : undefined
33
- : options.useLogSuffix;
25
+ ? new FileCircuitRecorder(process.env.CIRCUIT_RECORD_DIR, recorderLogger)
26
+ : new MemoryCircuitRecorder(recorderLogger);
27
+ const simulatorLogger = createLogger('wasm-simulator', { actor });
28
+ const simulator = new SimulatorRecorderWrapper(new WASMSimulator(simulatorLogger), recorder);
34
29
  const loggers = options.loggers ?? {};
35
30
 
36
31
  const { l1ChainId, l1ContractAddresses: l1Contracts, rollupVersion } = await aztecNode.getNodeInfo();
@@ -43,14 +38,15 @@ export async function createPXE(
43
38
  };
44
39
 
45
40
  if (!options.store) {
46
- const storeLogger = loggers.store
47
- ? loggers.store
48
- : createLogger('pxe:data:lmdb' + (logSuffix ? `:${logSuffix}` : ''));
49
- options.store = await createStore('pxe_data', PXE_DATA_SCHEMA_VERSION, configWithContracts, storeLogger);
41
+ const storeLogger = loggers.store ?? createLogger('pxe:data:lmdb', { actor });
42
+ options.store = await createStore(
43
+ 'pxe_data',
44
+ PXE_DATA_SCHEMA_VERSION,
45
+ configWithContracts,
46
+ storeLogger.getBindings(),
47
+ );
50
48
  }
51
- const proverLogger = loggers.prover
52
- ? loggers.prover
53
- : createLogger('pxe:bb:native' + (logSuffix ? `:${logSuffix}` : ''));
49
+ const proverLogger = loggers.prover ?? createLogger('pxe:bb:native', { actor });
54
50
 
55
51
  let prover;
56
52
  if (options.proverOrOptions instanceof BBPrivateKernelProver) {
@@ -61,15 +57,15 @@ export async function createPXE(
61
57
 
62
58
  const protocolContractsProvider = new BundledProtocolContractsProvider();
63
59
 
64
- const pxeLogger = loggers.pxe ? loggers.pxe : createLogger('pxe:service' + (logSuffix ? `:${logSuffix}` : ''));
65
- const pxe = await PXE.create(
66
- aztecNode,
67
- options.store,
68
- prover,
60
+ const pxeLogger = loggers.pxe ?? createLogger('pxe:service', { actor });
61
+ const pxe = await PXE.create({
62
+ node: aztecNode,
63
+ store: options.store,
64
+ proofCreator: prover,
69
65
  simulator,
70
66
  protocolContractsProvider,
71
- configWithContracts,
72
- pxeLogger,
73
- );
67
+ config: configWithContracts,
68
+ loggerOrSuffix: pxeLogger,
69
+ });
74
70
  return pxe;
75
71
  }
@@ -3,20 +3,19 @@ import type { EventSelector } from '@aztec/stdlib/abi';
3
3
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
4
  import { siloNullifier } from '@aztec/stdlib/hash';
5
5
  import type { AztecNode } from '@aztec/stdlib/interfaces/server';
6
- import { MerkleTreeId } from '@aztec/stdlib/trees';
7
- import type { TxHash } from '@aztec/stdlib/tx';
6
+ import type { BlockHeader, TxHash } from '@aztec/stdlib/tx';
8
7
 
9
- import { AnchorBlockStore } from '../storage/anchor_block_store/anchor_block_store.js';
10
8
  import { PrivateEventStore } from '../storage/private_event_store/private_event_store.js';
11
9
 
12
10
  export class EventService {
13
11
  constructor(
14
- private readonly anchorBlockStore: AnchorBlockStore,
12
+ private readonly anchorBlockHeader: BlockHeader,
15
13
  private readonly aztecNode: AztecNode,
16
14
  private readonly privateEventStore: PrivateEventStore,
15
+ private readonly jobId: string,
17
16
  ) {}
18
17
 
19
- public async deliverEvent(
18
+ public async validateAndStoreEvent(
20
19
  contractAddress: AztecAddress,
21
20
  selector: EventSelector,
22
21
  randomness: Fr,
@@ -29,51 +28,44 @@ export class EventService {
29
28
  // (and thus we're less concerned about being ahead of the synced block), we use the synced block number to
30
29
  // maintain consistent behavior in the PXE. Additionally, events should never be ahead of the synced block here
31
30
  // since `fetchTaggedLogs` only processes logs up to the synced block.
32
- const [syncedBlockHeader, siloedEventCommitment, txEffect] = await Promise.all([
33
- this.anchorBlockStore.getBlockHeader(),
31
+ const [siloedEventCommitment, txEffect] = await Promise.all([
34
32
  siloNullifier(contractAddress, eventCommitment),
35
33
  this.aztecNode.getTxEffect(txHash),
36
34
  ]);
37
35
 
38
- const syncedBlockNumber = syncedBlockHeader.getBlockNumber();
36
+ const anchorBlockNumber = this.anchorBlockHeader.getBlockNumber();
39
37
 
40
38
  if (!txEffect) {
41
39
  throw new Error(`Could not find tx effect for tx hash ${txHash}`);
42
40
  }
43
41
 
44
- if (txEffect.l2BlockNumber > syncedBlockNumber) {
45
- throw new Error(`Could not find tx effect for tx hash ${txHash} as of block number ${syncedBlockNumber}`);
42
+ if (txEffect.l2BlockNumber > anchorBlockNumber) {
43
+ throw new Error(`Could not find tx effect for tx hash ${txHash} as of block number ${anchorBlockNumber}`);
46
44
  }
47
45
 
48
- const eventInTx = txEffect.data.nullifiers.some(n => n.equals(siloedEventCommitment));
49
- if (!eventInTx) {
46
+ // Find the index of the event commitment in the nullifiers array to determine event ordering within the tx
47
+ const eventIndexInTx = txEffect.data.nullifiers.findIndex(n => n.equals(siloedEventCommitment));
48
+ if (eventIndexInTx === -1) {
50
49
  throw new Error(
51
50
  `Event commitment ${eventCommitment} (siloed as ${siloedEventCommitment}) is not present in tx ${txHash}`,
52
51
  );
53
52
  }
54
53
 
55
- const [nullifierIndex] = await this.aztecNode.findLeavesIndexes(syncedBlockNumber, MerkleTreeId.NULLIFIER_TREE, [
56
- siloedEventCommitment,
57
- ]);
58
-
59
- if (nullifierIndex === undefined) {
60
- throw new Error(
61
- `Event commitment ${eventCommitment} (siloed as ${siloedEventCommitment}) is not present on the nullifier tree at block ${syncedBlockNumber} (from tx ${txHash})`,
62
- );
63
- }
64
-
65
54
  return this.privateEventStore.storePrivateEventLog(
66
55
  selector,
67
56
  randomness,
68
57
  content,
69
- Number(nullifierIndex.data), // Index of the event commitment in the nullifier tree
58
+ siloedEventCommitment,
70
59
  {
71
60
  contractAddress,
72
61
  scope,
73
62
  txHash,
74
- l2BlockNumber: nullifierIndex.l2BlockNumber, // Block number in which the event was emitted
75
- l2BlockHash: nullifierIndex.l2BlockHash, // Block hash in which the event was emitted
63
+ l2BlockNumber: txEffect.l2BlockNumber,
64
+ l2BlockHash: txEffect.l2BlockHash,
65
+ txIndexInBlock: txEffect.txIndexInBlock,
66
+ eventIndexInTx,
76
67
  },
68
+ this.jobId,
77
69
  );
78
70
  }
79
71
  }