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

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 (187) hide show
  1. package/dest/bin/check_oracle_version.js +1 -1
  2. package/dest/block_synchronizer/block_synchronizer.d.ts +9 -5
  3. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
  4. package/dest/block_synchronizer/block_synchronizer.js +62 -16
  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/contract_function_simulator.d.ts +5 -5
  9. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  10. package/dest/contract_function_simulator/contract_function_simulator.js +12 -15
  11. package/dest/contract_function_simulator/index.d.ts +2 -2
  12. package/dest/contract_function_simulator/index.d.ts.map +1 -1
  13. package/dest/contract_function_simulator/index.js +1 -1
  14. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +1 -1
  15. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +1 -1
  16. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +1 -1
  17. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +1 -1
  18. package/dest/contract_function_simulator/oracle/interfaces.d.ts +15 -12
  19. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  20. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts +4 -4
  21. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts.map +1 -1
  22. package/dest/contract_function_simulator/oracle/note_packing_utils.js +4 -4
  23. package/dest/contract_function_simulator/oracle/oracle.d.ts +7 -5
  24. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  25. package/dest/contract_function_simulator/oracle/oracle.js +56 -34
  26. package/dest/contract_function_simulator/oracle/private_execution.d.ts +2 -22
  27. package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
  28. package/dest/contract_function_simulator/oracle/private_execution.js +0 -37
  29. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +12 -3
  30. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  31. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +20 -9
  32. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +38 -24
  33. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  34. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +84 -65
  35. package/dest/contract_sync/contract_sync_service.d.ts +41 -0
  36. package/dest/contract_sync/contract_sync_service.d.ts.map +1 -0
  37. package/dest/contract_sync/contract_sync_service.js +82 -0
  38. package/dest/contract_sync/helpers.d.ts +28 -0
  39. package/dest/contract_sync/helpers.d.ts.map +1 -0
  40. package/dest/contract_sync/helpers.js +55 -0
  41. package/dest/debug/pxe_debug_utils.d.ts +22 -9
  42. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  43. package/dest/debug/pxe_debug_utils.js +28 -17
  44. package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
  45. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  46. package/dest/entrypoints/client/bundle/utils.js +12 -6
  47. package/dest/entrypoints/client/lazy/utils.d.ts +2 -2
  48. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  49. package/dest/entrypoints/client/lazy/utils.js +13 -7
  50. package/dest/entrypoints/pxe_creation_options.d.ts +3 -2
  51. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  52. package/dest/entrypoints/server/index.d.ts +2 -1
  53. package/dest/entrypoints/server/index.d.ts.map +1 -1
  54. package/dest/entrypoints/server/index.js +1 -0
  55. package/dest/entrypoints/server/utils.d.ts +1 -1
  56. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  57. package/dest/entrypoints/server/utils.js +19 -8
  58. package/dest/events/event_service.d.ts +5 -6
  59. package/dest/events/event_service.d.ts.map +1 -1
  60. package/dest/events/event_service.js +6 -7
  61. package/dest/job_coordinator/job_coordinator.d.ts +3 -2
  62. package/dest/job_coordinator/job_coordinator.d.ts.map +1 -1
  63. package/dest/job_coordinator/job_coordinator.js +3 -2
  64. package/dest/logs/log_service.d.ts +6 -5
  65. package/dest/logs/log_service.d.ts.map +1 -1
  66. package/dest/logs/log_service.js +20 -19
  67. package/dest/notes/note_service.d.ts +6 -6
  68. package/dest/notes/note_service.d.ts.map +1 -1
  69. package/dest/notes/note_service.js +14 -14
  70. package/dest/oracle_version.d.ts +3 -3
  71. package/dest/oracle_version.d.ts.map +1 -1
  72. package/dest/oracle_version.js +4 -3
  73. package/dest/private_kernel/private_kernel_execution_prover.d.ts +3 -2
  74. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  75. package/dest/private_kernel/private_kernel_execution_prover.js +2 -2
  76. package/dest/private_kernel/private_kernel_oracle.d.ts +3 -3
  77. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  78. package/dest/pxe.d.ts +13 -2
  79. package/dest/pxe.d.ts.map +1 -1
  80. package/dest/pxe.js +45 -20
  81. package/dest/storage/address_store/address_store.d.ts +1 -1
  82. package/dest/storage/address_store/address_store.d.ts.map +1 -1
  83. package/dest/storage/address_store/address_store.js +12 -11
  84. package/dest/storage/anchor_block_store/anchor_block_store.d.ts +9 -1
  85. package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -1
  86. package/dest/storage/anchor_block_store/anchor_block_store.js +8 -1
  87. package/dest/storage/capsule_store/capsule_store.js +6 -8
  88. package/dest/storage/contract_store/contract_store.d.ts +1 -2
  89. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  90. package/dest/storage/contract_store/contract_store.js +27 -30
  91. package/dest/storage/metadata.d.ts +1 -1
  92. package/dest/storage/metadata.js +1 -1
  93. package/dest/storage/note_store/note_store.d.ts +48 -50
  94. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  95. package/dest/storage/note_store/note_store.js +279 -252
  96. package/dest/storage/note_store/stored_note.d.ts +16 -0
  97. package/dest/storage/note_store/stored_note.d.ts.map +1 -0
  98. package/dest/storage/note_store/stored_note.js +43 -0
  99. package/dest/storage/private_event_store/private_event_store.d.ts +17 -4
  100. package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
  101. package/dest/storage/private_event_store/private_event_store.js +198 -147
  102. package/dest/storage/private_event_store/stored_private_event.d.ts +23 -0
  103. package/dest/storage/private_event_store/stored_private_event.d.ts.map +1 -0
  104. package/dest/storage/private_event_store/stored_private_event.js +56 -0
  105. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +1 -1
  106. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
  107. package/dest/storage/tagging_store/recipient_tagging_store.js +31 -19
  108. package/dest/storage/tagging_store/sender_address_book_store.d.ts +1 -1
  109. package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +1 -1
  110. package/dest/storage/tagging_store/sender_address_book_store.js +20 -14
  111. package/dest/storage/tagging_store/sender_tagging_store.d.ts +1 -1
  112. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  113. package/dest/storage/tagging_store/sender_tagging_store.js +183 -113
  114. package/dest/tagging/get_all_logs_by_tags.d.ts +24 -0
  115. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -0
  116. package/dest/tagging/get_all_logs_by_tags.js +46 -0
  117. package/dest/tagging/index.d.ts +2 -1
  118. package/dest/tagging/index.d.ts.map +1 -1
  119. package/dest/tagging/index.js +1 -0
  120. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +3 -2
  121. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
  122. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +2 -2
  123. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +3 -2
  124. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
  125. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +5 -2
  126. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +3 -2
  127. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  128. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +2 -2
  129. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +1 -1
  130. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
  131. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +5 -8
  132. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +3 -2
  133. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  134. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +7 -4
  135. package/package.json +25 -16
  136. package/src/bin/check_oracle_version.ts +1 -0
  137. package/src/block_synchronizer/block_synchronizer.ts +76 -33
  138. package/src/config/index.ts +14 -0
  139. package/src/contract_function_simulator/contract_function_simulator.ts +12 -17
  140. package/src/contract_function_simulator/index.ts +1 -1
  141. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +1 -1
  142. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +1 -1
  143. package/src/contract_function_simulator/oracle/interfaces.ts +20 -11
  144. package/src/contract_function_simulator/oracle/note_packing_utils.ts +4 -4
  145. package/src/contract_function_simulator/oracle/oracle.ts +62 -32
  146. package/src/contract_function_simulator/oracle/private_execution.ts +1 -60
  147. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +34 -11
  148. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +107 -74
  149. package/src/contract_sync/contract_sync_service.ts +129 -0
  150. package/src/contract_sync/helpers.ts +93 -0
  151. package/src/debug/pxe_debug_utils.ts +60 -17
  152. package/src/entrypoints/client/bundle/utils.ts +7 -14
  153. package/src/entrypoints/client/lazy/utils.ts +8 -14
  154. package/src/entrypoints/pxe_creation_options.ts +2 -1
  155. package/src/entrypoints/server/index.ts +1 -0
  156. package/src/entrypoints/server/utils.ts +15 -19
  157. package/src/events/event_service.ts +5 -7
  158. package/src/job_coordinator/job_coordinator.ts +4 -3
  159. package/src/logs/log_service.ts +31 -15
  160. package/src/notes/note_service.ts +21 -20
  161. package/src/oracle_version.ts +4 -3
  162. package/src/private_kernel/private_kernel_execution_prover.ts +6 -3
  163. package/src/private_kernel/private_kernel_oracle.ts +2 -2
  164. package/src/pxe.ts +84 -19
  165. package/src/storage/address_store/address_store.ts +15 -15
  166. package/src/storage/anchor_block_store/anchor_block_store.ts +8 -0
  167. package/src/storage/capsule_store/capsule_store.ts +8 -8
  168. package/src/storage/contract_store/contract_store.ts +26 -35
  169. package/src/storage/metadata.ts +1 -1
  170. package/src/storage/note_store/note_store.ts +318 -318
  171. package/src/storage/note_store/stored_note.ts +48 -0
  172. package/src/storage/private_event_store/private_event_store.ts +250 -190
  173. package/src/storage/private_event_store/stored_private_event.ts +73 -0
  174. package/src/storage/tagging_store/recipient_tagging_store.ts +31 -21
  175. package/src/storage/tagging_store/sender_address_book_store.ts +20 -14
  176. package/src/storage/tagging_store/sender_tagging_store.ts +210 -126
  177. package/src/tagging/get_all_logs_by_tags.ts +68 -0
  178. package/src/tagging/index.ts +1 -0
  179. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +11 -1
  180. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +7 -1
  181. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +3 -1
  182. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +5 -17
  183. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +12 -3
  184. package/dest/tree_membership/tree_membership_service.d.ts +0 -50
  185. package/dest/tree_membership/tree_membership_service.d.ts.map +0 -1
  186. package/dest/tree_membership/tree_membership_service.js +0 -75
  187. package/src/tree_membership/tree_membership_service.ts +0 -97
package/dest/pxe.js CHANGED
@@ -5,7 +5,6 @@ import { KeyStore } from '@aztec/key-store';
5
5
  import { L2TipsKVStore } from '@aztec/kv-store/stores';
6
6
  import { protocolContractNames } from '@aztec/protocol-contracts';
7
7
  import { FunctionType, decodeFunctionSignature } from '@aztec/stdlib/abi';
8
- import { L2BlockHash } from '@aztec/stdlib/block';
9
8
  import { computeContractAddressFromInstance, getContractClassFromArtifact } from '@aztec/stdlib/contract';
10
9
  import { SimulationError } from '@aztec/stdlib/errors';
11
10
  import { PrivateSimulationResult, TxProfileResult, TxProvingResult, TxSimulationResult } from '@aztec/stdlib/tx';
@@ -13,8 +12,9 @@ import { inspect } from 'util';
13
12
  import { BlockSynchronizer } from './block_synchronizer/index.js';
14
13
  import { BenchmarkedNodeFactory } from './contract_function_simulator/benchmarked_node.js';
15
14
  import { ContractFunctionSimulator, generateSimulatedProvingResult } from './contract_function_simulator/contract_function_simulator.js';
16
- import { readCurrentClassId } from './contract_function_simulator/oracle/private_execution.js';
17
15
  import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
16
+ import { ContractSyncService } from './contract_sync/contract_sync_service.js';
17
+ import { readCurrentClassId } from './contract_sync/helpers.js';
18
18
  import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
19
19
  import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
20
20
  import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
@@ -46,6 +46,7 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
46
46
  recipientTaggingStore;
47
47
  addressStore;
48
48
  privateEventStore;
49
+ contractSyncService;
49
50
  simulator;
50
51
  proverEnabled;
51
52
  proofCreator;
@@ -54,7 +55,7 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
54
55
  jobQueue;
55
56
  jobCoordinator;
56
57
  debug;
57
- constructor(node, blockStateSynchronizer, keyStore, contractStore, noteStore, capsuleStore, anchorBlockStore, senderTaggingStore, senderAddressBookStore, recipientTaggingStore, addressStore, privateEventStore, simulator, proverEnabled, proofCreator, protocolContractsProvider, log, jobQueue, jobCoordinator, debug){
58
+ constructor(node, blockStateSynchronizer, keyStore, contractStore, noteStore, capsuleStore, anchorBlockStore, senderTaggingStore, senderAddressBookStore, recipientTaggingStore, addressStore, privateEventStore, contractSyncService, simulator, proverEnabled, proofCreator, protocolContractsProvider, log, jobQueue, jobCoordinator, debug){
58
59
  this.node = node;
59
60
  this.blockStateSynchronizer = blockStateSynchronizer;
60
61
  this.keyStore = keyStore;
@@ -67,6 +68,7 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
67
68
  this.recipientTaggingStore = recipientTaggingStore;
68
69
  this.addressStore = addressStore;
69
70
  this.privateEventStore = privateEventStore;
71
+ this.contractSyncService = contractSyncService;
70
72
  this.simulator = simulator;
71
73
  this.proverEnabled = proverEnabled;
72
74
  this.proofCreator = proofCreator;
@@ -83,12 +85,14 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
83
85
  *
84
86
  * @returns A promise that resolves PXE is ready to be used.
85
87
  */ static async create(node, store, proofCreator, simulator, protocolContractsProvider, config, loggerOrSuffix) {
88
+ // Extract bindings from the logger, or use empty bindings if a string suffix is provided.
89
+ const bindings = loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
86
90
  const log = !loggerOrSuffix || typeof loggerOrSuffix === 'string' ? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`) : loggerOrSuffix;
87
91
  const proverEnabled = !!config.proverEnabled;
88
92
  const addressStore = new AddressStore(store);
89
93
  const privateEventStore = new PrivateEventStore(store);
90
94
  const contractStore = new ContractStore(store);
91
- const noteStore = await NoteStore.create(store);
95
+ const noteStore = new NoteStore(store);
92
96
  const anchorBlockStore = new AnchorBlockStore(store);
93
97
  const senderTaggingStore = new SenderTaggingStore(store);
94
98
  const senderAddressBookStore = new SenderAddressBookStore(store);
@@ -96,18 +100,21 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
96
100
  const capsuleStore = new CapsuleStore(store);
97
101
  const keyStore = new KeyStore(store);
98
102
  const tipsStore = new L2TipsKVStore(store, 'pxe');
99
- const synchronizer = new BlockSynchronizer(node, store, anchorBlockStore, noteStore, privateEventStore, tipsStore, config, loggerOrSuffix);
100
- const jobCoordinator = new JobCoordinator(store);
103
+ const contractSyncService = new ContractSyncService(node, contractStore, noteStore, createLogger('pxe:contract_sync', bindings));
104
+ const synchronizer = new BlockSynchronizer(node, store, anchorBlockStore, noteStore, privateEventStore, tipsStore, contractSyncService, config, bindings);
105
+ const jobCoordinator = new JobCoordinator(store, bindings);
101
106
  jobCoordinator.registerStores([
102
107
  capsuleStore,
103
108
  senderTaggingStore,
104
109
  recipientTaggingStore,
105
- privateEventStore
110
+ privateEventStore,
111
+ noteStore,
112
+ contractSyncService
106
113
  ]);
107
- const debugUtils = new PXEDebugUtils(contractStore, noteStore);
114
+ const debugUtils = new PXEDebugUtils(contractSyncService, noteStore, synchronizer, anchorBlockStore);
108
115
  const jobQueue = new SerialQueue();
109
- const pxe = new PXE(node, synchronizer, keyStore, contractStore, noteStore, capsuleStore, anchorBlockStore, senderTaggingStore, senderAddressBookStore, recipientTaggingStore, addressStore, privateEventStore, simulator, proverEnabled, proofCreator, protocolContractsProvider, log, jobQueue, jobCoordinator, debugUtils);
110
- debugUtils.setPXE(pxe);
116
+ const pxe = new PXE(node, synchronizer, keyStore, contractStore, noteStore, capsuleStore, anchorBlockStore, senderTaggingStore, senderAddressBookStore, recipientTaggingStore, addressStore, privateEventStore, contractSyncService, simulator, proverEnabled, proofCreator, protocolContractsProvider, log, jobQueue, jobCoordinator, debugUtils);
117
+ debugUtils.setPXEHelpers(pxe.#putInJobQueue.bind(pxe), pxe.#getSimulatorForTx.bind(pxe), pxe.#simulateUtility.bind(pxe));
111
118
  pxe.jobQueue.start();
112
119
  await pxe.#registerProtocolContracts();
113
120
  const info = await node.getNodeInfo();
@@ -117,7 +124,7 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
117
124
  // Internal methods
118
125
  #getSimulatorForTx(overrides) {
119
126
  const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
120
- return new ContractFunctionSimulator(proxyContractStore, this.noteStore, this.keyStore, this.addressStore, BenchmarkedNodeFactory.create(this.node), this.anchorBlockStore, this.senderTaggingStore, this.recipientTaggingStore, this.senderAddressBookStore, this.capsuleStore, this.privateEventStore, this.simulator);
127
+ return new ContractFunctionSimulator(proxyContractStore, this.noteStore, this.keyStore, this.addressStore, BenchmarkedNodeFactory.create(this.node), this.senderTaggingStore, this.recipientTaggingStore, this.senderAddressBookStore, this.capsuleStore, this.privateEventStore, this.simulator, this.contractSyncService);
121
128
  }
122
129
  #contextualizeError(err, ...context) {
123
130
  let contextStr = '';
@@ -173,6 +180,7 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
173
180
  const { origin: contractAddress, functionSelector } = txRequest;
174
181
  try {
175
182
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
183
+ await this.contractSyncService.ensureContractSynced(contractAddress, functionSelector, (privateSyncCall)=>this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId), anchorBlockHeader, jobId);
176
184
  const result = await contractFunctionSimulator.run(txRequest, contractAddress, functionSelector, undefined, anchorBlockHeader, // The sender for tags is set by contracts, typically by an account
177
185
  // contract entrypoint
178
186
  undefined, scopes, jobId);
@@ -242,14 +250,24 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
242
250
  * @returns An object that contains the output of the kernel execution, including the ChonkProof if proving is enabled.
243
251
  */ async #prove(txExecutionRequest, proofCreator, privateExecutionResult, config) {
244
252
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
245
- const anchorBlockHash = L2BlockHash.fromField(await anchorBlockHeader.hash());
253
+ const anchorBlockHash = await anchorBlockHeader.hash();
246
254
  const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHash);
247
- const kernelTraceProver = new PrivateKernelExecutionProver(kernelOracle, proofCreator, !this.proverEnabled);
255
+ const kernelTraceProver = new PrivateKernelExecutionProver(kernelOracle, proofCreator, !this.proverEnabled, this.log.getBindings());
248
256
  this.log.debug(`Executing kernel trace prover (${JSON.stringify(config)})...`);
249
257
  return await kernelTraceProver.proveWithKernels(txExecutionRequest.toTxRequest(), privateExecutionResult, config);
250
258
  }
251
259
  // Public API
252
- getContractInstance(address) {
260
+ /**
261
+ * Returns the block header up to which the PXE has synced.
262
+ * @returns The synced block header
263
+ */ getSyncedBlockHeader() {
264
+ return this.anchorBlockStore.getBlockHeader();
265
+ }
266
+ /**
267
+ * Returns the contract instance for a given address, if it's registered in the PXE.
268
+ * @param address - The contract address.
269
+ * @returns The contract instance if found, undefined otherwise.
270
+ */ getContractInstance(address) {
253
271
  return this.contractStore.getContractInstance(address);
254
272
  }
255
273
  /**
@@ -279,7 +297,6 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
279
297
  this.log.debug(`Registered account\n ${accountCompleteAddress.toReadableString()}`);
280
298
  }
281
299
  await this.addressStore.addCompleteAddress(accountCompleteAddress);
282
- await this.noteStore.addScope(accountCompleteAddress.address);
283
300
  return accountCompleteAddress;
284
301
  }
285
302
  /**
@@ -584,13 +601,19 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
584
601
  // Temporary: in case there are overrides, we have to skip the kernels or validations
585
602
  // will fail. Consider handing control to the user/wallet on whether they want to run them
586
603
  // or not.
587
- const skipKernels = overrides?.contracts !== undefined && Object.keys(overrides.contracts ?? {}).length > 0;
604
+ const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
605
+ const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
606
+ const skipKernels = hasOverriddenContracts;
607
+ // Set overridden contracts on the sync service so it knows to skip syncing them
608
+ if (hasOverriddenContracts) {
609
+ this.contractSyncService.setOverriddenContracts(jobId, overriddenContracts);
610
+ }
588
611
  // Execution of private functions only; no proving, and no kernel logic.
589
612
  const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
590
613
  let publicInputs;
591
614
  let executionSteps = [];
592
615
  if (skipKernels) {
593
- ({ publicInputs, executionSteps } = await generateSimulatedProvingResult(privateExecutionResult, this.contractStore));
616
+ ({ publicInputs, executionSteps } = await generateSimulatedProvingResult(privateExecutionResult, (addr, sel)=>this.contractStore.getDebugFunctionName(addr, sel)));
594
617
  } else {
595
618
  // Kernel logic, plus proving of all private functions and kernels.
596
619
  ({ publicInputs, executionSteps } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, {
@@ -674,7 +697,8 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
674
697
  const syncTime = syncTimer.ms();
675
698
  const functionTimer = new Timer();
676
699
  const contractFunctionSimulator = this.#getSimulatorForTx();
677
- await this.contractStore.syncPrivateState(call.to, call.selector, (privateSyncCall)=>this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId));
700
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
701
+ await this.contractSyncService.ensureContractSynced(call.to, call.selector, (privateSyncCall)=>this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId), anchorBlockHeader, jobId);
678
702
  const executionResult = await this.#simulateUtility(contractFunctionSimulator, call, authwits ?? [], scopes, jobId);
679
703
  const functionTime = functionTimer.ms();
680
704
  const totalTime = totalTimer.ms();
@@ -721,9 +745,10 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
721
745
  let anchorBlockNumber;
722
746
  await this.#putInJobQueue(async (jobId)=>{
723
747
  await this.blockStateSynchronizer.sync();
724
- anchorBlockNumber = (await this.anchorBlockStore.getBlockHeader()).getBlockNumber();
748
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
749
+ anchorBlockNumber = anchorBlockHeader.getBlockNumber();
725
750
  const contractFunctionSimulator = this.#getSimulatorForTx();
726
- await this.contractStore.syncPrivateState(filter.contractAddress, null, async (privateSyncCall)=>await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId));
751
+ await this.contractSyncService.ensureContractSynced(filter.contractAddress, null, async (privateSyncCall)=>await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId), anchorBlockHeader, jobId);
727
752
  });
728
753
  // anchorBlockNumber is set during the job and fixed to whatever it is after a block sync
729
754
  const sanitizedFilter = new PrivateEventFilterValidator(anchorBlockNumber).validate(filter);
@@ -8,4 +8,4 @@ export declare class AddressStore {
8
8
  getCompleteAddress(account: AztecAddress): Promise<CompleteAddress | undefined>;
9
9
  getCompleteAddresses(): Promise<CompleteAddress[]>;
10
10
  }
11
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWRkcmVzc19zdG9yZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL3N0b3JhZ2UvYWRkcmVzc19zdG9yZS9hZGRyZXNzX3N0b3JlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLE9BQU8sS0FBSyxFQUFtQixpQkFBaUIsRUFBaUIsTUFBTSxpQkFBaUIsQ0FBQztBQUN6RixPQUFPLEtBQUssRUFBRSxZQUFZLEVBQUUsTUFBTSw2QkFBNkIsQ0FBQztBQUNoRSxPQUFPLEVBQUUsZUFBZSxFQUFFLE1BQU0sd0JBQXdCLENBQUM7QUFFekQscUJBQWEsWUFBWTs7SUFLdkIsWUFBWSxLQUFLLEVBQUUsaUJBQWlCLEVBS25DO0lBRUQsa0JBQWtCLENBQUMsZUFBZSxFQUFFLGVBQWUsR0FBRyxPQUFPLENBQUMsT0FBTyxDQUFDLENBMEJyRTtJQVlELGtCQUFrQixDQUFDLE9BQU8sRUFBRSxZQUFZLEdBQUcsT0FBTyxDQUFDLGVBQWUsR0FBRyxTQUFTLENBQUMsQ0FFOUU7SUFFSyxvQkFBb0IsSUFBSSxPQUFPLENBQUMsZUFBZSxFQUFFLENBQUMsQ0FJdkQ7Q0FDRiJ9
11
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWRkcmVzc19zdG9yZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL3N0b3JhZ2UvYWRkcmVzc19zdG9yZS9hZGRyZXNzX3N0b3JlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLE9BQU8sS0FBSyxFQUFtQixpQkFBaUIsRUFBaUIsTUFBTSxpQkFBaUIsQ0FBQztBQUN6RixPQUFPLEtBQUssRUFBRSxZQUFZLEVBQUUsTUFBTSw2QkFBNkIsQ0FBQztBQUNoRSxPQUFPLEVBQUUsZUFBZSxFQUFFLE1BQU0sd0JBQXdCLENBQUM7QUFFekQscUJBQWEsWUFBWTs7SUFLdkIsWUFBWSxLQUFLLEVBQUUsaUJBQWlCLEVBS25DO0lBRUQsa0JBQWtCLENBQUMsZUFBZSxFQUFFLGVBQWUsR0FBRyxPQUFPLENBQUMsT0FBTyxDQUFDLENBMEJyRTtJQUVELGtCQUFrQixDQUFDLE9BQU8sRUFBRSxZQUFZLEdBQUcsT0FBTyxDQUFDLGVBQWUsR0FBRyxTQUFTLENBQUMsQ0FVOUU7SUFFRCxvQkFBb0IsSUFBSSxPQUFPLENBQUMsZUFBZSxFQUFFLENBQUMsQ0FNakQ7Q0FDRiJ9
@@ -1 +1 @@
1
- {"version":3,"file":"address_store.d.ts","sourceRoot":"","sources":["../../../src/storage/address_store/address_store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAmB,iBAAiB,EAAiB,MAAM,iBAAiB,CAAC;AACzF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,qBAAa,YAAY;;IAKvB,YAAY,KAAK,EAAE,iBAAiB,EAKnC;IAED,kBAAkB,CAAC,eAAe,EAAE,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC,CA0BrE;IAYD,kBAAkB,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,eAAe,GAAG,SAAS,CAAC,CAE9E;IAEK,oBAAoB,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC,CAIvD;CACF"}
1
+ {"version":3,"file":"address_store.d.ts","sourceRoot":"","sources":["../../../src/storage/address_store/address_store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAmB,iBAAiB,EAAiB,MAAM,iBAAiB,CAAC;AACzF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,qBAAa,YAAY;;IAKvB,YAAY,KAAK,EAAE,iBAAiB,EAKnC;IAED,kBAAkB,CAAC,eAAe,EAAE,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC,CA0BrE;IAED,kBAAkB,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,eAAe,GAAG,SAAS,CAAC,CAU9E;IAED,oBAAoB,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC,CAMjD;CACF"}
@@ -30,18 +30,19 @@ export class AddressStore {
30
30
  }
31
31
  });
32
32
  }
33
- async #getCompleteAddress(address) {
34
- const index = await this.#completeAddressIndex.getAsync(address.toString());
35
- if (index === undefined) {
36
- return undefined;
37
- }
38
- const value = await this.#completeAddresses.atAsync(index);
39
- return value ? await CompleteAddress.fromBuffer(value) : undefined;
40
- }
41
33
  getCompleteAddress(account) {
42
- return this.#getCompleteAddress(account);
34
+ return this.#store.transactionAsync(async ()=>{
35
+ const index = await this.#completeAddressIndex.getAsync(account.toString());
36
+ if (index === undefined) {
37
+ return undefined;
38
+ }
39
+ const value = await this.#completeAddresses.atAsync(index);
40
+ return value ? await CompleteAddress.fromBuffer(value) : undefined;
41
+ });
43
42
  }
44
- async getCompleteAddresses() {
45
- return await Promise.all((await toArray(this.#completeAddresses.valuesAsync())).map((v)=>CompleteAddress.fromBuffer(v)));
43
+ getCompleteAddresses() {
44
+ return this.#store.transactionAsync(async ()=>{
45
+ return await Promise.all((await toArray(this.#completeAddresses.valuesAsync())).map((v)=>CompleteAddress.fromBuffer(v)));
46
+ });
46
47
  }
47
48
  }
@@ -3,7 +3,15 @@ import { BlockHeader } from '@aztec/stdlib/tx';
3
3
  export declare class AnchorBlockStore {
4
4
  #private;
5
5
  constructor(store: AztecAsyncKVStore);
6
+ /**
7
+ * Sets the currently synchronized block
8
+ *
9
+ * Important: this method is only called from BlockSynchronizer, and since we need it to run atomically with other
10
+ * stores in the case of a reorg, it MUST NOT be wrapped in a `transactionAsync` call. Doing so would result in a
11
+ * deadlock when the backend is IndexedDB, because `transactionAsync` is not designed to support reentrancy.
12
+ *
13
+ */
6
14
  setHeader(header: BlockHeader): Promise<void>;
7
15
  getBlockHeader(): Promise<BlockHeader>;
8
16
  }
9
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYW5jaG9yX2Jsb2NrX3N0b3JlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvc3RvcmFnZS9hbmNob3JfYmxvY2tfc3RvcmUvYW5jaG9yX2Jsb2NrX3N0b3JlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLGlCQUFpQixFQUF1QixNQUFNLGlCQUFpQixDQUFDO0FBQzlFLE9BQU8sRUFBRSxXQUFXLEVBQUUsTUFBTSxrQkFBa0IsQ0FBQztBQUUvQyxxQkFBYSxnQkFBZ0I7O0lBSTNCLFlBQVksS0FBSyxFQUFFLGlCQUFpQixFQUduQztJQUVLLFNBQVMsQ0FBQyxNQUFNLEVBQUUsV0FBVyxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FFbEQ7SUFFSyxjQUFjLElBQUksT0FBTyxDQUFDLFdBQVcsQ0FBQyxDQU8zQztDQUNGIn0=
17
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYW5jaG9yX2Jsb2NrX3N0b3JlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvc3RvcmFnZS9hbmNob3JfYmxvY2tfc3RvcmUvYW5jaG9yX2Jsb2NrX3N0b3JlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLGlCQUFpQixFQUF1QixNQUFNLGlCQUFpQixDQUFDO0FBQzlFLE9BQU8sRUFBRSxXQUFXLEVBQUUsTUFBTSxrQkFBa0IsQ0FBQztBQUUvQyxxQkFBYSxnQkFBZ0I7O0lBSTNCLFlBQVksS0FBSyxFQUFFLGlCQUFpQixFQUduQztJQUVEOzs7Ozs7O09BT0c7SUFDRyxTQUFTLENBQUMsTUFBTSxFQUFFLFdBQVcsR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLENBRWxEO0lBRUssY0FBYyxJQUFJLE9BQU8sQ0FBQyxXQUFXLENBQUMsQ0FPM0M7Q0FDRiJ9
@@ -1 +1 @@
1
- {"version":3,"file":"anchor_block_store.d.ts","sourceRoot":"","sources":["../../../src/storage/anchor_block_store/anchor_block_store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAuB,MAAM,iBAAiB,CAAC;AAC9E,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,qBAAa,gBAAgB;;IAI3B,YAAY,KAAK,EAAE,iBAAiB,EAGnC;IAEK,SAAS,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAElD;IAEK,cAAc,IAAI,OAAO,CAAC,WAAW,CAAC,CAO3C;CACF"}
1
+ {"version":3,"file":"anchor_block_store.d.ts","sourceRoot":"","sources":["../../../src/storage/anchor_block_store/anchor_block_store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAuB,MAAM,iBAAiB,CAAC;AAC9E,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,qBAAa,gBAAgB;;IAI3B,YAAY,KAAK,EAAE,iBAAiB,EAGnC;IAED;;;;;;;OAOG;IACG,SAAS,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAElD;IAEK,cAAc,IAAI,OAAO,CAAC,WAAW,CAAC,CAO3C;CACF"}
@@ -6,7 +6,14 @@ export class AnchorBlockStore {
6
6
  this.#store = store;
7
7
  this.#synchronizedHeader = this.#store.openSingleton('header');
8
8
  }
9
- async setHeader(header) {
9
+ /**
10
+ * Sets the currently synchronized block
11
+ *
12
+ * Important: this method is only called from BlockSynchronizer, and since we need it to run atomically with other
13
+ * stores in the case of a reorg, it MUST NOT be wrapped in a `transactionAsync` call. Doing so would result in a
14
+ * deadlock when the backend is IndexedDB, because `transactionAsync` is not designed to support reentrancy.
15
+ *
16
+ */ async setHeader(header) {
10
17
  await this.#synchronizedHeader.set(header.toBuffer());
11
18
  }
12
19
  async getBlockHeader() {
@@ -40,14 +40,12 @@ export class CapsuleStore {
40
40
  * If it is not there, it reads it from the KV store.
41
41
  */ async #getFromStage(jobId, dbSlotKey) {
42
42
  const jobStagedCapsules = this.#getJobStagedCapsules(jobId);
43
- let staged = jobStagedCapsules.get(dbSlotKey);
44
- // Note that if staged === null, we marked it for deletion, so we don't want to
45
- // re-read it from DB
46
- if (staged === undefined) {
47
- // If we don't have a staged version of this dbSlotKey, first we check if there's one in DB
48
- staged = await this.#loadCapsuleFromDb(dbSlotKey);
49
- }
50
- return staged;
43
+ const staged = jobStagedCapsules.get(dbSlotKey);
44
+ // Always issue DB read to keep IndexedDB transaction alive, even if the value is in the job staged data. This
45
+ // keeps IndexedDB transactions alive (they auto-commit when a new micro-task starts and there are no pending read
46
+ // requests). The staged value still takes precedence if it exists (including null for deletions).
47
+ const dbValue = await this.#loadCapsuleFromDb(dbSlotKey);
48
+ return staged !== undefined ? staged : dbValue;
51
49
  }
52
50
  /**
53
51
  * Writes a capsule to the stage of a job.
@@ -62,6 +62,5 @@ export declare class ContractStore {
62
62
  getDebugContractName(contractAddress: AztecAddress): Promise<string | undefined>;
63
63
  getDebugFunctionName(contractAddress: AztecAddress, selector: FunctionSelector): Promise<string>;
64
64
  getFunctionCall(functionName: string, args: any[], to: AztecAddress): Promise<FunctionCall>;
65
- syncPrivateState(contractAddress: AztecAddress, functionToInvokeAfterSync: FunctionSelector | null, utilityExecutor: (privateSyncCall: FunctionCall) => Promise<any>): Promise<any>;
66
65
  }
67
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29udHJhY3Rfc3RvcmUuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9zdG9yYWdlL2NvbnRyYWN0X3N0b3JlL2NvbnRyYWN0X3N0b3JlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLG9CQUFvQixFQUFFLE1BQU0sa0JBQWtCLENBQUM7QUFDN0QsT0FBTyxLQUFLLEVBQUUsRUFBRSxFQUFFLE1BQU0sZ0NBQWdDLENBQUM7QUFFekQsT0FBTyxLQUFLLEVBQUUsaUJBQWlCLEVBQUUsTUFBTSx5QkFBeUIsQ0FBQztBQUNqRSxPQUFPLEtBQUssRUFBRSxpQkFBaUIsRUFBaUIsTUFBTSxpQkFBaUIsQ0FBQztBQUV4RSxPQUFPLEVBQ0wsS0FBSyxnQkFBZ0IsRUFDckIsS0FBSyxXQUFXLEVBRWhCLEtBQUssZ0NBQWdDLEVBQ3JDLFlBQVksRUFDWixLQUFLLHFCQUFxQixFQUMxQixn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AAe,EAAE,YAAY,+BAG9D;IAEY,oBAAoB,CAAC,eAAe,EAAE,YAAY,EAAE,QAAQ,EAAE,gBAAgB,mBAI1F;IA8BY,eAAe,CAAC,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,CAuBvG;CACF"}
@@ -1,6 +1,5 @@
1
1
  import { toArray } from '@aztec/foundation/iterable';
2
- import { isProtocolContract } from '@aztec/protocol-contracts';
3
- import { FunctionSelector, FunctionType, contractArtifactFromBuffer, contractArtifactToBuffer, encodeArguments, getFunctionDebugMetadata } from '@aztec/stdlib/abi';
2
+ import { FunctionCall, FunctionSelector, FunctionType, contractArtifactFromBuffer, contractArtifactToBuffer, encodeArguments, getFunctionDebugMetadata } from '@aztec/stdlib/abi';
4
3
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
5
4
  import { SerializableContractInstance, getContractClassFromArtifact } from '@aztec/stdlib/contract';
6
5
  import { PrivateFunctionsTree } from './private_functions_tree.js';
@@ -14,20 +13,23 @@ import { PrivateFunctionsTree } from './private_functions_tree.js';
14
13
  /** Map from contract class id to private function tree. */ // TODO: Update it to be LRU cache so that it doesn't keep all the data all the time.
15
14
  #privateFunctionTrees = new Map();
16
15
  /** Map from contract address to contract class id */ #contractClassIdMap = new Map();
16
+ #store;
17
17
  #contractArtifacts;
18
18
  #contractInstances;
19
19
  constructor(store){
20
+ this.#store = store;
20
21
  this.#contractArtifacts = store.openMap('contract_artifacts');
21
22
  this.#contractInstances = store.openMap('contracts_instances');
22
23
  }
23
24
  // Setters
24
25
  async addContractArtifact(id, contract) {
26
+ // Validation outside transactionAsync - these are not DB operations
25
27
  const privateFunctions = contract.functions.filter((functionArtifact)=>functionArtifact.functionType === FunctionType.PRIVATE);
26
28
  const privateSelectors = await Promise.all(privateFunctions.map(async (privateFunctionArtifact)=>(await FunctionSelector.fromNameAndParameters(privateFunctionArtifact.name, privateFunctionArtifact.parameters)).toString()));
27
29
  if (privateSelectors.length !== new Set(privateSelectors).size) {
28
30
  throw new Error('Repeated function selectors of private functions');
29
31
  }
30
- await this.#contractArtifacts.set(id.toString(), contractArtifactToBuffer(contract));
32
+ await this.#store.transactionAsync(()=>this.#contractArtifacts.set(id.toString(), contractArtifactToBuffer(contract)));
31
33
  }
32
34
  async addContractInstance(contract) {
33
35
  this.#contractClassIdMap.set(contract.address.toString(), contract.currentContractClassId);
@@ -69,18 +71,24 @@ import { PrivateFunctionsTree } from './private_functions_tree.js';
69
71
  return contractClassId && this.getContractArtifact(contractClassId);
70
72
  }
71
73
  // Public getters
72
- async getContractsAddresses() {
73
- const keys = await toArray(this.#contractInstances.keysAsync());
74
- return keys.map(AztecAddress.fromString);
75
- }
76
- /** Returns a contract instance for a given address. Throws if not found. */ async getContractInstance(contractAddress) {
77
- const contract = await this.#contractInstances.getAsync(contractAddress.toString());
78
- return contract && SerializableContractInstance.fromBuffer(contract).withAddress(contractAddress);
79
- }
80
- async getContractArtifact(contractClassId) {
81
- const contract = await this.#contractArtifacts.getAsync(contractClassId.toString());
82
- // TODO(@spalladino): AztecAsyncMap lies and returns Uint8Arrays instead of Buffers, hence the extra Buffer.from.
83
- return contract && contractArtifactFromBuffer(Buffer.from(contract));
74
+ getContractsAddresses() {
75
+ return this.#store.transactionAsync(async ()=>{
76
+ const keys = await toArray(this.#contractInstances.keysAsync());
77
+ return keys.map(AztecAddress.fromString);
78
+ });
79
+ }
80
+ /** Returns a contract instance for a given address. Throws if not found. */ getContractInstance(contractAddress) {
81
+ return this.#store.transactionAsync(async ()=>{
82
+ const contract = await this.#contractInstances.getAsync(contractAddress.toString());
83
+ return contract && SerializableContractInstance.fromBuffer(contract).withAddress(contractAddress);
84
+ });
85
+ }
86
+ getContractArtifact(contractClassId) {
87
+ return this.#store.transactionAsync(async ()=>{
88
+ const contract = await this.#contractArtifacts.getAsync(contractClassId.toString());
89
+ // TODO(@spalladino): AztecAsyncMap lies and returns Uint8Arrays instead of Buffers, hence the extra Buffer.from.
90
+ return contract && contractArtifactFromBuffer(Buffer.from(contract));
91
+ });
84
92
  }
85
93
  /** Returns a contract class for a given class id. Throws if not found. */ async getContractClass(contractClassId) {
86
94
  const artifact = await this.getContractArtifact(contractClassId);
@@ -211,26 +219,15 @@ import { PrivateFunctionsTree } from './private_functions_tree.js';
211
219
  if (!functionDao) {
212
220
  throw new Error(`Unknown function ${functionName} in contract ${contract.name}.`);
213
221
  }
214
- return {
222
+ return FunctionCall.from({
215
223
  name: functionDao.name,
216
- args: encodeArguments(functionDao, args),
224
+ to,
217
225
  selector: await FunctionSelector.fromNameAndParameters(functionDao.name, functionDao.parameters),
218
226
  type: functionDao.functionType,
219
- to,
220
227
  hideMsgSender: false,
221
228
  isStatic: functionDao.isStatic,
229
+ args: encodeArguments(functionDao, args),
222
230
  returnTypes: functionDao.returnTypes
223
- };
224
- }
225
- // Synchronize target contract data
226
- async syncPrivateState(contractAddress, functionToInvokeAfterSync, utilityExecutor) {
227
- // Protocol contracts don't have private state to sync
228
- if (!isProtocolContract(contractAddress)) {
229
- const syncPrivateStateFunctionCall = await this.getFunctionCall('sync_private_state', [], contractAddress);
230
- if (functionToInvokeAfterSync && functionToInvokeAfterSync.equals(syncPrivateStateFunctionCall.selector)) {
231
- throw new Error('Forbidden `sync_private_state` invocation. `sync_private_state` can only be invoked by PXE, manual execution can lead to inconsistencies.');
232
- }
233
- return utilityExecutor(syncPrivateStateFunctionCall);
234
- }
231
+ });
235
232
  }
236
233
  }
@@ -1,2 +1,2 @@
1
- export declare const PXE_DATA_SCHEMA_VERSION = 2;
1
+ export declare const PXE_DATA_SCHEMA_VERSION = 3;
2
2
  //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWV0YWRhdGEuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9zdG9yYWdlL21ldGFkYXRhLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLGVBQU8sTUFBTSx1QkFBdUIsSUFBSSxDQUFDIn0=
@@ -1 +1 @@
1
- export const PXE_DATA_SCHEMA_VERSION = 2;
1
+ export const PXE_DATA_SCHEMA_VERSION = 3;
@@ -1,54 +1,65 @@
1
- import type { Fr } from '@aztec/foundation/curves/bn254';
1
+ import type { Fr } from '@aztec/foundation/schemas';
2
2
  import type { AztecAsyncKVStore } from '@aztec/kv-store';
3
- import { AztecAddress } from '@aztec/stdlib/aztec-address';
3
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
4
  import type { DataInBlock } from '@aztec/stdlib/block';
5
- import { type NotesFilter } from '@aztec/stdlib/note';
6
- import { NoteDao } from '@aztec/stdlib/note';
5
+ import { NoteDao, type NotesFilter } from '@aztec/stdlib/note';
6
+ import type { StagedStore } from '../../job_coordinator/job_coordinator.js';
7
7
  /**
8
8
  * NoteStore manages the storage and retrieval of notes.
9
9
  *
10
- * Notes can be active or nullified. This class processes new notes, nullifications,
11
- * and performs rollback handling in the case of a reorg.
10
+ * Notes can be active or nullified. This class processes new notes, nullifications, and performs rollback handling in
11
+ * the case of a reorg.
12
12
  **/
13
- export declare class NoteStore {
13
+ export declare class NoteStore implements StagedStore {
14
14
  #private;
15
- private constructor();
15
+ readonly storeName: string;
16
+ constructor(store: AztecAsyncKVStore);
16
17
  /**
17
- * Creates and initializes a new NoteStore instance.
18
+ * Adds multiple notes to the notes store under the specified scope.
18
19
  *
19
- * This factory method creates a NoteStore and restores any existing
20
- * scope-specific indexes from the database.
20
+ * Notes are stored using their siloedNullifier as the key, which provides uniqueness. Each note is indexed by
21
+ * multiple criteria for efficient retrieval.
21
22
  *
22
- * @param store - The key-value store to use for persistence
23
- * @returns Promise resolving to a fully initialized NoteStore instance
23
+ * @param notes - Notes to store
24
+ * @param scope - The scope (user/account) under which to store the notes
25
+ * @param jobId - The job context for staged writes
24
26
  */
25
- static create(store: AztecAsyncKVStore): Promise<NoteStore>;
27
+ addNotes(notes: NoteDao[], scope: AztecAddress, jobId: string): Promise<void[]>;
26
28
  /**
27
- * Adds a new scope to the note data provider.
29
+ * Retrieves notes based on the provided filter criteria.
28
30
  *
29
- * Scopes provide privacy isolation by creating separate indexes for each user.
30
- * Each scope gets its own set of indexes for efficient note retrieval by various criteria.
31
+ * This method queries both active and optionally nullified notes based on the filter parameters.
31
32
  *
32
- * @param scope - The AztecAddress representing the scope/user to add
33
- * @returns Promise resolving to true if scope was added, false if it already existed
33
+ * @param filter - Filter criteria including contractAddress (required), and optional owner,
34
+ * storageSlot, status, scopes, and siloedNullifier.
35
+ * @params jobId - the job context to read from.
36
+ * @returns Filtered and deduplicated notes (a note might be present in multiple scopes - we ensure it is only
37
+ * returned once if this is the case)
38
+ * @throws If filtering by an empty scopes array. Scopes have to be set to undefined or to a non-empty array.
34
39
  */
35
- addScope(scope: AztecAddress): Promise<boolean>;
40
+ getNotes(filter: NotesFilter, jobId: string): Promise<NoteDao[]>;
36
41
  /**
37
- * Adds multiple notes to the data provider under the specified scope.
42
+ * Transitions notes from "active" to "nullified" state.
38
43
  *
39
- * Notes are stored using their siloedNullifier as the key, which provides uniqueness. Each note is indexed
40
- * by multiple criteria for efficient retrieval.
44
+ * This operation processes a batch of nullifiers to mark the corresponding notes as spent/nullified.
45
+ * The operation is atomic - if any nullifier is not found, the entire operation fails and no notes are modified.
41
46
  *
42
- * @param notes - Notes to store
43
- * @param scope - The scope (user/account) under which to store the notes
47
+ * applyNullifiers is idempotent: the same nullifier can be applied multiple times without error.
48
+ * This relaxes constraints on usage of NoteService#validateAndStoreNote, which can then be run concurrently in a Promise.all
49
+ * context without risking unnecessarily defensive checks failing.
50
+ *
51
+ * @param nullifiers - Array of nullifiers with their block numbers to process
52
+ * @param jobId - The job context for staged writes
53
+ * @returns Array of NoteDao objects that were nullified
54
+ * @throws Error if any nullifier is not found in this notes store
44
55
  */
45
- addNotes(notes: NoteDao[], scope: AztecAddress): Promise<void>;
56
+ applyNullifiers(nullifiers: DataInBlock<Fr>[], jobId: string): Promise<NoteDao[]>;
46
57
  /**
47
58
  * Synchronizes notes and nullifiers to a specific block number.
48
59
  *
49
- * This method ensures that the state of notes and nullifiers is consistent with the
50
- * specified block number. It restores any notes that were nullified after the given block
51
- * and deletes any active notes created after that block.
60
+ * This method ensures that the state of notes and nullifiers is consistent with the specified block number.
61
+ * It restores any notes that were nullified after the given block and deletes any active notes created after that
62
+ * block.
52
63
  *
53
64
  * IMPORTANT: This method must be called within a transaction to ensure atomicity.
54
65
  *
@@ -57,29 +68,16 @@ export declare class NoteStore {
57
68
  */
58
69
  rollback(blockNumber: number, synchedBlockNumber: number): Promise<void>;
59
70
  /**
60
- * Retrieves notes based on the provided filter criteria.
61
- *
62
- * This method queries both active and optionally nullified notes based on the filter
63
- * parameters.
71
+ * Commits in memory job data to persistent storage.
64
72
  *
65
- * @param filter - Filter criteria including contractAddress (required), and optional
66
- * owner, storageSlot, status, scopes, and siloedNullifier.
67
- * @returns Filtered and deduplicated notes (a note might be present in multiple scopes - we ensure it is only
68
- * returned once if this is the case)
69
- * @throws If filtering by an empty scopes array. Scopes have to be set to undefined or to a non-empty array.
70
- */
71
- getNotes(filter: NotesFilter): Promise<NoteDao[]>;
72
- /**
73
- * Transitions notes from "active" to "nullified" state.
73
+ * Called by JobCoordinator when a job completes successfully.
74
74
  *
75
- * This operation processes a batch of nullifiers to mark the corresponding notes
76
- * as spent/nullified. The operation is atomic - if any nullifier is not found,
77
- * the entire operation fails and no notes are modified.
75
+ * Note: JobCoordinator wraps all commits in a single transaction, so we don't need our own transactionAsync here
76
+ * (and using one would throw on IndexedDB as it does not support nested txs).
78
77
  *
79
- * @param nullifiers - Array of nullifiers with their block numbers to process
80
- * @returns Promise resolving to array of nullified NoteDao objects
81
- * @throws Error if any nullifier is not found in the active notes
78
+ * @param jobId - The jobId identifying which staged data to commit
82
79
  */
83
- applyNullifiers(nullifiers: DataInBlock<Fr>[]): Promise<NoteDao[]>;
80
+ commit(jobId: string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../../../src/storage/note_store/note_store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AAEzD,OAAO,KAAK,EAAE,iBAAiB,EAAqC,MAAM,iBAAiB,CAAC;AAC5F,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAc,KAAK,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C;;;;;IAKI;AACJ,qBAAa,SAAS;;IA4BpB,OAAO,eAcN;IAED;;;;;;;;OAQG;IACH,OAAoB,MAAM,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,SAAS,CAAC,CAOvE;IAED;;;;;;;;OAQG;IACU,QAAQ,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,CAY3D;IAED;;;;;;;;OAQG;IACH,QAAQ,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAe7D;IAED;;;;;;;;;;;OAWG;IACU,QAAQ,CAAC,WAAW,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAGpF;IAiFD;;;;;;;;;;;OAWG;IACG,QAAQ,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAmHtD;IAED;;;;;;;;;;OAUG;IACH,eAAe,CAAC,UAAU,EAAE,WAAW,CAAC,EAAE,CAAC,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAoDjE;CACF"}
1
+ {"version":3,"file":"note_store.d.ts","sourceRoot":"","sources":["../../../src/storage/note_store/note_store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,2B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