@aztec/pxe 0.0.1-commit.c7c42ec → 0.0.1-commit.f295ac2
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.
- package/dest/block_synchronizer/block_synchronizer.d.ts +6 -2
- package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
- package/dest/block_synchronizer/block_synchronizer.js +21 -13
- package/dest/config/package_info.js +1 -1
- package/dest/contract_function_simulator/benchmarked_node.d.ts +9 -0
- package/dest/contract_function_simulator/benchmarked_node.d.ts.map +1 -0
- package/dest/contract_function_simulator/benchmarked_node.js +77 -0
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +8 -9
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +33 -16
- package/dest/contract_function_simulator/execution_note_cache.d.ts +18 -9
- package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -1
- package/dest/contract_function_simulator/execution_note_cache.js +45 -28
- package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +3 -2
- package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/event_validation_request.js +5 -2
- package/dest/contract_function_simulator/noir-structs/utility_context.d.ts +4 -10
- package/dest/contract_function_simulator/noir-structs/utility_context.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/utility_context.js +7 -18
- package/dest/contract_function_simulator/oracle/interfaces.d.ts +9 -8
- package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts +3 -1
- package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts +4 -4
- package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/note_packing_utils.js +5 -5
- package/dest/contract_function_simulator/oracle/oracle.d.ts +6 -6
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +20 -19
- package/dest/contract_function_simulator/oracle/private_execution.d.ts +5 -9
- package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution.js +11 -10
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +8 -18
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +10 -35
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +14 -12
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +54 -52
- package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
- package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/utils.js +10 -1
- package/dest/entrypoints/client/lazy/utils.d.ts +1 -1
- package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/utils.js +10 -1
- package/dest/entrypoints/pxe_creation_options.d.ts +3 -2
- package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
- package/dest/entrypoints/server/index.d.ts +2 -1
- package/dest/entrypoints/server/index.d.ts.map +1 -1
- package/dest/entrypoints/server/index.js +1 -0
- package/dest/entrypoints/server/utils.d.ts +1 -1
- package/dest/entrypoints/server/utils.d.ts.map +1 -1
- package/dest/entrypoints/server/utils.js +11 -7
- package/dest/events/event_service.d.ts +4 -3
- package/dest/events/event_service.d.ts.map +1 -1
- package/dest/events/event_service.js +17 -19
- package/dest/events/private_event_filter_validator.d.ts +5 -5
- package/dest/events/private_event_filter_validator.d.ts.map +1 -1
- package/dest/events/private_event_filter_validator.js +5 -6
- package/dest/job_coordinator/job_coordinator.d.ts +74 -0
- package/dest/job_coordinator/job_coordinator.d.ts.map +1 -0
- package/dest/job_coordinator/job_coordinator.js +93 -0
- package/dest/logs/log_service.d.ts +3 -2
- package/dest/logs/log_service.d.ts.map +1 -1
- package/dest/logs/log_service.js +5 -3
- package/dest/notes/note_service.d.ts +3 -3
- package/dest/notes/note_service.d.ts.map +1 -1
- package/dest/notes/note_service.js +23 -28
- package/dest/oracle_version.d.ts +2 -2
- package/dest/oracle_version.js +2 -2
- package/dest/private_kernel/hints/index.d.ts +2 -2
- package/dest/private_kernel/hints/index.d.ts.map +1 -1
- package/dest/private_kernel/hints/index.js +1 -1
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +28 -0
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -0
- package/dest/private_kernel/hints/{build_private_kernel_reset_private_inputs.js → private_kernel_reset_private_inputs_builder.js} +13 -7
- package/dest/private_kernel/private_kernel_execution_prover.d.ts +1 -1
- package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_execution_prover.js +4 -5
- package/dest/private_kernel/private_kernel_oracle.d.ts +24 -28
- package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_oracle.js +90 -2
- package/dest/pxe.d.ts +8 -36
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +65 -87
- package/dest/storage/capsule_store/capsule_store.d.ts +24 -9
- package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
- package/dest/storage/capsule_store/capsule_store.js +132 -23
- package/dest/storage/contract_store/contract_store.d.ts +2 -1
- package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
- package/dest/storage/contract_store/contract_store.js +12 -0
- package/dest/storage/note_store/note_store.d.ts +6 -5
- package/dest/storage/note_store/note_store.d.ts.map +1 -1
- package/dest/storage/note_store/note_store.js +89 -94
- package/dest/storage/private_event_store/private_event_store.d.ts +33 -6
- package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
- package/dest/storage/private_event_store/private_event_store.js +139 -32
- package/dest/storage/tagging_store/recipient_tagging_store.d.ts +15 -8
- package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/recipient_tagging_store.js +69 -12
- package/dest/storage/tagging_store/sender_tagging_store.d.ts +19 -9
- package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/sender_tagging_store.js +110 -28
- package/dest/tagging/constants.d.ts +2 -0
- package/dest/tagging/constants.d.ts.map +1 -0
- package/dest/tagging/constants.js +10 -0
- package/dest/tagging/index.d.ts +2 -2
- package/dest/tagging/index.d.ts.map +1 -1
- package/dest/tagging/index.js +1 -10
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +2 -2
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +7 -7
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +2 -2
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +8 -8
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +1 -1
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +2 -2
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +4 -2
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +4 -2
- package/dest/tree_membership/tree_membership_service.d.ts +9 -11
- package/dest/tree_membership/tree_membership_service.d.ts.map +1 -1
- package/dest/tree_membership/tree_membership_service.js +25 -34
- package/package.json +18 -18
- package/src/block_synchronizer/block_synchronizer.ts +30 -12
- package/src/config/package_info.ts +1 -1
- package/src/contract_function_simulator/benchmarked_node.ts +103 -0
- package/src/contract_function_simulator/contract_function_simulator.ts +42 -16
- package/src/contract_function_simulator/execution_note_cache.ts +44 -25
- package/src/contract_function_simulator/noir-structs/event_validation_request.ts +4 -0
- package/src/contract_function_simulator/noir-structs/utility_context.ts +6 -25
- package/src/contract_function_simulator/oracle/interfaces.ts +8 -7
- package/src/contract_function_simulator/oracle/note_packing_utils.ts +6 -6
- package/src/contract_function_simulator/oracle/oracle.ts +24 -22
- package/src/contract_function_simulator/oracle/private_execution.ts +10 -19
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +13 -38
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +56 -50
- package/src/entrypoints/client/bundle/utils.ts +7 -1
- package/src/entrypoints/client/lazy/utils.ts +7 -2
- package/src/entrypoints/pxe_creation_options.ts +2 -1
- package/src/entrypoints/server/index.ts +1 -0
- package/src/entrypoints/server/utils.ts +11 -15
- package/src/events/event_service.ts +17 -21
- package/src/events/private_event_filter_validator.ts +3 -5
- package/src/job_coordinator/job_coordinator.ts +149 -0
- package/src/logs/log_service.ts +3 -1
- package/src/notes/note_service.ts +23 -29
- package/src/oracle_version.ts +2 -2
- package/src/private_kernel/hints/index.ts +1 -1
- package/src/private_kernel/hints/{build_private_kernel_reset_private_inputs.ts → private_kernel_reset_private_inputs_builder.ts} +33 -22
- package/src/private_kernel/private_kernel_execution_prover.ts +3 -5
- package/src/private_kernel/private_kernel_oracle.ts +116 -36
- package/src/pxe.ts +98 -116
- package/src/storage/capsule_store/capsule_store.ts +159 -23
- package/src/storage/contract_store/contract_store.ts +20 -0
- package/src/storage/note_store/note_store.ts +98 -95
- package/src/storage/private_event_store/private_event_store.ts +199 -37
- package/src/storage/tagging_store/recipient_tagging_store.ts +89 -13
- package/src/storage/tagging_store/sender_tagging_store.ts +129 -28
- package/src/tagging/constants.ts +10 -0
- package/src/tagging/index.ts +1 -11
- package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +10 -6
- package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +8 -7
- package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +6 -2
- package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +4 -1
- package/src/tree_membership/tree_membership_service.ts +27 -42
- package/dest/contract_function_simulator/proxied_node.d.ts +0 -9
- package/dest/contract_function_simulator/proxied_node.d.ts.map +0 -1
- package/dest/contract_function_simulator/proxied_node.js +0 -27
- package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts +0 -28
- package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts.map +0 -1
- package/dest/private_kernel/private_kernel_oracle_impl.d.ts +0 -46
- package/dest/private_kernel/private_kernel_oracle_impl.d.ts.map +0 -1
- package/dest/private_kernel/private_kernel_oracle_impl.js +0 -86
- package/dest/public_storage/public_storage_service.d.ts +0 -24
- package/dest/public_storage/public_storage_service.d.ts.map +0 -1
- package/dest/public_storage/public_storage_service.js +0 -26
- package/src/contract_function_simulator/proxied_node.ts +0 -33
- package/src/private_kernel/private_kernel_oracle_impl.ts +0 -133
- package/src/public_storage/public_storage_service.ts +0 -33
package/src/pxe.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { PrivateEventFilter } from '@aztec/aztec.js/wallet';
|
|
2
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
3
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
4
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
4
5
|
import { SerialQueue } from '@aztec/foundation/queue';
|
|
@@ -17,16 +18,15 @@ import {
|
|
|
17
18
|
} from '@aztec/stdlib/abi';
|
|
18
19
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
19
20
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
21
|
+
import { L2BlockHash } from '@aztec/stdlib/block';
|
|
20
22
|
import {
|
|
21
23
|
CompleteAddress,
|
|
22
|
-
type ContractClassWithId,
|
|
23
24
|
type ContractInstanceWithAddress,
|
|
24
25
|
type PartialAddress,
|
|
25
26
|
computeContractAddressFromInstance,
|
|
26
27
|
getContractClassFromArtifact,
|
|
27
28
|
} from '@aztec/stdlib/contract';
|
|
28
29
|
import { SimulationError } from '@aztec/stdlib/errors';
|
|
29
|
-
import { computeProtocolNullifier, siloNullifier } from '@aztec/stdlib/hash';
|
|
30
30
|
import type { AztecNode, PrivateKernelProver } from '@aztec/stdlib/interfaces/client';
|
|
31
31
|
import type {
|
|
32
32
|
PrivateExecutionStep,
|
|
@@ -54,6 +54,7 @@ import { inspect } from 'util';
|
|
|
54
54
|
|
|
55
55
|
import { BlockSynchronizer } from './block_synchronizer/index.js';
|
|
56
56
|
import type { PXEConfig } from './config/index.js';
|
|
57
|
+
import { BenchmarkedNodeFactory } from './contract_function_simulator/benchmarked_node.js';
|
|
57
58
|
import {
|
|
58
59
|
ContractFunctionSimulator,
|
|
59
60
|
generateSimulatedProvingResult,
|
|
@@ -63,11 +64,12 @@ import { ProxiedContractStoreFactory } from './contract_function_simulator/proxi
|
|
|
63
64
|
import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
|
|
64
65
|
import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
|
|
65
66
|
import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
|
|
67
|
+
import { JobCoordinator } from './job_coordinator/job_coordinator.js';
|
|
66
68
|
import {
|
|
67
69
|
PrivateKernelExecutionProver,
|
|
68
70
|
type PrivateKernelExecutionProverConfig,
|
|
69
71
|
} from './private_kernel/private_kernel_execution_prover.js';
|
|
70
|
-
import {
|
|
72
|
+
import { PrivateKernelOracle } from './private_kernel/private_kernel_oracle.js';
|
|
71
73
|
import { AddressStore } from './storage/address_store/address_store.js';
|
|
72
74
|
import { AnchorBlockStore } from './storage/anchor_block_store/anchor_block_store.js';
|
|
73
75
|
import { CapsuleStore } from './storage/capsule_store/capsule_store.js';
|
|
@@ -107,6 +109,7 @@ export class PXE {
|
|
|
107
109
|
private protocolContractsProvider: ProtocolContractsProvider,
|
|
108
110
|
private log: Logger,
|
|
109
111
|
private jobQueue: SerialQueue,
|
|
112
|
+
private jobCoordinator: JobCoordinator,
|
|
110
113
|
public debug: PXEDebugUtils,
|
|
111
114
|
) {}
|
|
112
115
|
|
|
@@ -143,7 +146,19 @@ export class PXE {
|
|
|
143
146
|
const capsuleStore = new CapsuleStore(store);
|
|
144
147
|
const keyStore = new KeyStore(store);
|
|
145
148
|
const tipsStore = new L2TipsKVStore(store, 'pxe');
|
|
146
|
-
const synchronizer = new BlockSynchronizer(
|
|
149
|
+
const synchronizer = new BlockSynchronizer(
|
|
150
|
+
node,
|
|
151
|
+
store,
|
|
152
|
+
anchorBlockStore,
|
|
153
|
+
noteStore,
|
|
154
|
+
privateEventStore,
|
|
155
|
+
tipsStore,
|
|
156
|
+
config,
|
|
157
|
+
loggerOrSuffix,
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
const jobCoordinator = new JobCoordinator(store);
|
|
161
|
+
jobCoordinator.registerStores([capsuleStore, senderTaggingStore, recipientTaggingStore, privateEventStore]);
|
|
147
162
|
|
|
148
163
|
const debugUtils = new PXEDebugUtils(contractStore, noteStore);
|
|
149
164
|
|
|
@@ -168,6 +183,7 @@ export class PXE {
|
|
|
168
183
|
protocolContractsProvider,
|
|
169
184
|
log,
|
|
170
185
|
jobQueue,
|
|
186
|
+
jobCoordinator,
|
|
171
187
|
debugUtils,
|
|
172
188
|
);
|
|
173
189
|
|
|
@@ -191,7 +207,7 @@ export class PXE {
|
|
|
191
207
|
this.noteStore,
|
|
192
208
|
this.keyStore,
|
|
193
209
|
this.addressStore,
|
|
194
|
-
this.node,
|
|
210
|
+
BenchmarkedNodeFactory.create(this.node),
|
|
195
211
|
this.anchorBlockStore,
|
|
196
212
|
this.senderTaggingStore,
|
|
197
213
|
this.recipientTaggingStore,
|
|
@@ -222,7 +238,7 @@ export class PXE {
|
|
|
222
238
|
*
|
|
223
239
|
* Useful for tasks that cannot run concurrently, such as contract function simulation.
|
|
224
240
|
*/
|
|
225
|
-
#putInJobQueue<T>(fn: () => Promise<T>): Promise<T> {
|
|
241
|
+
#putInJobQueue<T>(fn: (jobId: string) => Promise<T>): Promise<T> {
|
|
226
242
|
// TODO(#12636): relax the conditions under which we forbid concurrency.
|
|
227
243
|
if (this.jobQueue.length() != 0) {
|
|
228
244
|
this.log.warn(
|
|
@@ -230,7 +246,22 @@ export class PXE {
|
|
|
230
246
|
);
|
|
231
247
|
}
|
|
232
248
|
|
|
233
|
-
return this.jobQueue.put(
|
|
249
|
+
return this.jobQueue.put(async () => {
|
|
250
|
+
const jobId = this.jobCoordinator.beginJob();
|
|
251
|
+
this.log.verbose(`Beginning job ${jobId}`);
|
|
252
|
+
|
|
253
|
+
try {
|
|
254
|
+
const result = await fn(jobId);
|
|
255
|
+
this.log.verbose(`Committing job ${jobId}`);
|
|
256
|
+
|
|
257
|
+
await this.jobCoordinator.commitJob(jobId);
|
|
258
|
+
return result;
|
|
259
|
+
} catch (err) {
|
|
260
|
+
this.log.verbose(`Aborting job ${jobId}`);
|
|
261
|
+
await this.jobCoordinator.abortJob(jobId);
|
|
262
|
+
throw err;
|
|
263
|
+
}
|
|
264
|
+
});
|
|
234
265
|
}
|
|
235
266
|
|
|
236
267
|
async #registerProtocolContracts() {
|
|
@@ -245,25 +276,13 @@ export class PXE {
|
|
|
245
276
|
this.log.verbose(`Registered protocol contracts in pxe`, registered);
|
|
246
277
|
}
|
|
247
278
|
|
|
248
|
-
async #isContractClassPubliclyRegistered(id: Fr): Promise<boolean> {
|
|
249
|
-
return !!(await this.node.getContractClass(id));
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
async #isContractPublished(address: AztecAddress): Promise<boolean> {
|
|
253
|
-
return !!(await this.node.getContract(address));
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
async #isContractInitialized(address: AztecAddress): Promise<boolean> {
|
|
257
|
-
const initNullifier = await siloNullifier(address, address.toField());
|
|
258
|
-
return !!(await this.node.getNullifierMembershipWitness('latest', initNullifier));
|
|
259
|
-
}
|
|
260
|
-
|
|
261
279
|
// Executes the entrypoint private function, as well as all nested private
|
|
262
280
|
// functions that might arise.
|
|
263
281
|
async #executePrivate(
|
|
264
282
|
contractFunctionSimulator: ContractFunctionSimulator,
|
|
265
283
|
txRequest: TxExecutionRequest,
|
|
266
|
-
scopes
|
|
284
|
+
scopes: AztecAddress[] | undefined,
|
|
285
|
+
jobId: string,
|
|
267
286
|
): Promise<PrivateExecutionResult> {
|
|
268
287
|
const { origin: contractAddress, functionSelector } = txRequest;
|
|
269
288
|
|
|
@@ -280,6 +299,7 @@ export class PXE {
|
|
|
280
299
|
// contract entrypoint
|
|
281
300
|
undefined, // senderForTags
|
|
282
301
|
scopes,
|
|
302
|
+
jobId,
|
|
283
303
|
);
|
|
284
304
|
this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
|
|
285
305
|
return result;
|
|
@@ -298,17 +318,19 @@ export class PXE {
|
|
|
298
318
|
* @param authWitnesses - Authentication witnesses required for the function call.
|
|
299
319
|
* @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
|
|
300
320
|
* accounts if not specified.
|
|
321
|
+
* @param jobId - The job ID for staged writes.
|
|
301
322
|
* @returns The simulation result containing the outputs of the utility function.
|
|
302
323
|
*/
|
|
303
324
|
async #simulateUtility(
|
|
304
325
|
contractFunctionSimulator: ContractFunctionSimulator,
|
|
305
326
|
call: FunctionCall,
|
|
306
|
-
authWitnesses
|
|
307
|
-
scopes
|
|
327
|
+
authWitnesses: AuthWitness[] | undefined,
|
|
328
|
+
scopes: AztecAddress[] | undefined,
|
|
329
|
+
jobId: string,
|
|
308
330
|
) {
|
|
309
331
|
try {
|
|
310
332
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
311
|
-
return contractFunctionSimulator.runUtility(call, authWitnesses ?? [], anchorBlockHeader, scopes);
|
|
333
|
+
return contractFunctionSimulator.runUtility(call, authWitnesses ?? [], anchorBlockHeader, scopes, jobId);
|
|
312
334
|
} catch (err) {
|
|
313
335
|
if (err instanceof SimulationError) {
|
|
314
336
|
await enrichSimulationError(err, this.contractStore, this.log);
|
|
@@ -361,13 +383,9 @@ export class PXE {
|
|
|
361
383
|
privateExecutionResult: PrivateExecutionResult,
|
|
362
384
|
config: PrivateKernelExecutionProverConfig,
|
|
363
385
|
): Promise<PrivateKernelExecutionProofOutput<PrivateKernelTailCircuitPublicInputs>> {
|
|
364
|
-
const
|
|
365
|
-
const
|
|
366
|
-
|
|
367
|
-
this.keyStore,
|
|
368
|
-
this.node,
|
|
369
|
-
simulationAnchorBlock,
|
|
370
|
-
);
|
|
386
|
+
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
387
|
+
const anchorBlockHash = L2BlockHash.fromField(await anchorBlockHeader.hash());
|
|
388
|
+
const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHash);
|
|
371
389
|
const kernelTraceProver = new PrivateKernelExecutionProver(kernelOracle, proofCreator, !this.proverEnabled);
|
|
372
390
|
this.log.debug(`Executing kernel trace prover (${JSON.stringify(config)})...`);
|
|
373
391
|
return await kernelTraceProver.proveWithKernels(txExecutionRequest.toTxRequest(), privateExecutionResult, config);
|
|
@@ -380,66 +398,12 @@ export class PXE {
|
|
|
380
398
|
}
|
|
381
399
|
|
|
382
400
|
/**
|
|
383
|
-
* Returns the contract
|
|
384
|
-
*
|
|
385
|
-
* @
|
|
386
|
-
* @param id - Identifier of the class.
|
|
387
|
-
* @param includeArtifact - Identifier of the class.
|
|
388
|
-
* @returns - It returns the contract class metadata, with the artifact field being optional, and will only be returned if true is passed in
|
|
389
|
-
* for `includeArtifact`
|
|
390
|
-
* TODO(@spalladino): The PXE actually holds artifacts and not classes, what should we return? Also,
|
|
391
|
-
* should the pxe query the node for contract public info, and merge it with its own definitions?
|
|
392
|
-
* TODO(@spalladino): This method is strictly needed to decide whether to publicly register a class or not
|
|
393
|
-
* during a public deployment. We probably want a nicer and more general API for this, but it'll have to
|
|
394
|
-
* do for the time being.
|
|
401
|
+
* Returns the contract artifact for a given contract class id, if it's registered in the PXE.
|
|
402
|
+
* @param id - Identifier of the contract class.
|
|
403
|
+
* @returns The contract artifact if found, undefined otherwise.
|
|
395
404
|
*/
|
|
396
|
-
public async
|
|
397
|
-
id
|
|
398
|
-
includeArtifact: boolean = false,
|
|
399
|
-
): Promise<{
|
|
400
|
-
contractClass: ContractClassWithId | undefined;
|
|
401
|
-
isContractClassPubliclyRegistered: boolean;
|
|
402
|
-
artifact: ContractArtifact | undefined;
|
|
403
|
-
}> {
|
|
404
|
-
const artifact = await this.contractStore.getContractArtifact(id);
|
|
405
|
-
if (!artifact) {
|
|
406
|
-
this.log.warn(`No artifact found for contract class ${id.toString()} when looking for its metadata`);
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
return {
|
|
410
|
-
contractClass: artifact && (await getContractClassFromArtifact(artifact)),
|
|
411
|
-
isContractClassPubliclyRegistered: await this.#isContractClassPubliclyRegistered(id),
|
|
412
|
-
artifact: includeArtifact ? artifact : undefined,
|
|
413
|
-
};
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
/**
|
|
417
|
-
* Returns the contract metadata given an address.
|
|
418
|
-
* The metadata consists of its contract instance, which includes the contract class identifier,
|
|
419
|
-
* initialization hash, deployment salt, and public keys hash; whether the contract instance has been initialized;
|
|
420
|
-
* and whether the contract instance with the given address has been publicly deployed.
|
|
421
|
-
* @remark - it queries the node to check whether the contract instance has been initialized / publicly deployed through a node.
|
|
422
|
-
* This query is not dependent on the PXE.
|
|
423
|
-
* @param address - The address that the contract instance resides at.
|
|
424
|
-
* @returns - It returns the contract metadata
|
|
425
|
-
* TODO(@spalladino): Should we return the public keys in plain as well here?
|
|
426
|
-
*/
|
|
427
|
-
public async getContractMetadata(address: AztecAddress): Promise<{
|
|
428
|
-
contractInstance: ContractInstanceWithAddress | undefined;
|
|
429
|
-
isContractInitialized: boolean;
|
|
430
|
-
isContractPublished: boolean;
|
|
431
|
-
}> {
|
|
432
|
-
let instance;
|
|
433
|
-
try {
|
|
434
|
-
instance = await this.contractStore.getContractInstance(address);
|
|
435
|
-
} catch {
|
|
436
|
-
this.log.warn(`No instance found for contract ${address.toString()} when looking for its metadata`);
|
|
437
|
-
}
|
|
438
|
-
return {
|
|
439
|
-
contractInstance: instance,
|
|
440
|
-
isContractInitialized: await this.#isContractInitialized(address),
|
|
441
|
-
isContractPublished: await this.#isContractPublished(address),
|
|
442
|
-
};
|
|
405
|
+
public async getContractArtifact(id: Fr): Promise<ContractArtifact | undefined> {
|
|
406
|
+
return await this.contractStore.getContractArtifact(id);
|
|
443
407
|
}
|
|
444
408
|
|
|
445
409
|
/**
|
|
@@ -612,13 +576,7 @@ export class PXE {
|
|
|
612
576
|
|
|
613
577
|
const header = await this.anchorBlockStore.getBlockHeader();
|
|
614
578
|
|
|
615
|
-
const currentClassId = await readCurrentClassId(
|
|
616
|
-
contractAddress,
|
|
617
|
-
currentInstance,
|
|
618
|
-
this.node,
|
|
619
|
-
header.globalVariables.blockNumber,
|
|
620
|
-
header.globalVariables.timestamp,
|
|
621
|
-
);
|
|
579
|
+
const currentClassId = await readCurrentClassId(contractAddress, currentInstance, this.node, header);
|
|
622
580
|
if (!contractClass.id.equals(currentClassId)) {
|
|
623
581
|
throw new Error('Could not update contract to a class different from the current one.');
|
|
624
582
|
}
|
|
@@ -657,14 +615,14 @@ export class PXE {
|
|
|
657
615
|
let privateExecutionResult: PrivateExecutionResult;
|
|
658
616
|
// We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
|
|
659
617
|
// computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
|
|
660
|
-
return this.#putInJobQueue(async
|
|
618
|
+
return this.#putInJobQueue(async jobId => {
|
|
661
619
|
const totalTimer = new Timer();
|
|
662
620
|
try {
|
|
663
621
|
const syncTimer = new Timer();
|
|
664
622
|
await this.blockStateSynchronizer.sync();
|
|
665
623
|
const syncTime = syncTimer.ms();
|
|
666
624
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
667
|
-
privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest);
|
|
625
|
+
privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, undefined, jobId);
|
|
668
626
|
|
|
669
627
|
const {
|
|
670
628
|
publicInputs,
|
|
@@ -711,7 +669,7 @@ export class PXE {
|
|
|
711
669
|
// TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
|
|
712
670
|
const txHash = (await txProvingResult.toTx()).txHash;
|
|
713
671
|
|
|
714
|
-
await this.senderTaggingStore.storePendingIndexes(preTagsUsedInTheTx, txHash);
|
|
672
|
+
await this.senderTaggingStore.storePendingIndexes(preTagsUsedInTheTx, txHash, jobId);
|
|
715
673
|
this.log.debug(`Stored used pre-tags as sender for the tx`, {
|
|
716
674
|
preTagsUsedInTheTx,
|
|
717
675
|
});
|
|
@@ -741,7 +699,7 @@ export class PXE {
|
|
|
741
699
|
skipProofGeneration: boolean = true,
|
|
742
700
|
): Promise<TxProfileResult> {
|
|
743
701
|
// We disable concurrent profiles for consistency with simulateTx.
|
|
744
|
-
return this.#putInJobQueue(async
|
|
702
|
+
return this.#putInJobQueue(async jobId => {
|
|
745
703
|
const totalTimer = new Timer();
|
|
746
704
|
try {
|
|
747
705
|
const txInfo = {
|
|
@@ -761,7 +719,12 @@ export class PXE {
|
|
|
761
719
|
const syncTime = syncTimer.ms();
|
|
762
720
|
|
|
763
721
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
764
|
-
const privateExecutionResult = await this.#executePrivate(
|
|
722
|
+
const privateExecutionResult = await this.#executePrivate(
|
|
723
|
+
contractFunctionSimulator,
|
|
724
|
+
txRequest,
|
|
725
|
+
undefined,
|
|
726
|
+
jobId,
|
|
727
|
+
);
|
|
765
728
|
|
|
766
729
|
const { executionSteps, timings: { proving } = {} } = await this.#prove(
|
|
767
730
|
txRequest,
|
|
@@ -841,7 +804,7 @@ export class PXE {
|
|
|
841
804
|
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
842
805
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
843
806
|
// delete the same read value, or reading values that another simulation is currently modifying).
|
|
844
|
-
return this.#putInJobQueue(async
|
|
807
|
+
return this.#putInJobQueue(async jobId => {
|
|
845
808
|
try {
|
|
846
809
|
const totalTimer = new Timer();
|
|
847
810
|
const txInfo = {
|
|
@@ -867,20 +830,14 @@ export class PXE {
|
|
|
867
830
|
const skipKernels = overrides?.contracts !== undefined && Object.keys(overrides.contracts ?? {}).length > 0;
|
|
868
831
|
|
|
869
832
|
// Execution of private functions only; no proving, and no kernel logic.
|
|
870
|
-
const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes);
|
|
833
|
+
const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
871
834
|
|
|
872
835
|
let publicInputs: PrivateKernelTailCircuitPublicInputs | undefined;
|
|
873
836
|
let executionSteps: PrivateExecutionStep[] = [];
|
|
874
837
|
|
|
875
838
|
if (skipKernels) {
|
|
876
|
-
// According to the protocol rules, the nonce generator for the note hashes
|
|
877
|
-
// can either be the first nullifier in the tx or the protocol nullifier if there are none.
|
|
878
|
-
const nonceGenerator = privateExecutionResult.firstNullifier.equals(Fr.ZERO)
|
|
879
|
-
? await computeProtocolNullifier(await txRequest.toTxRequest().hash())
|
|
880
|
-
: privateExecutionResult.firstNullifier;
|
|
881
839
|
({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
|
|
882
840
|
privateExecutionResult,
|
|
883
|
-
nonceGenerator,
|
|
884
841
|
this.contractStore,
|
|
885
842
|
));
|
|
886
843
|
} else {
|
|
@@ -982,7 +939,7 @@ export class PXE {
|
|
|
982
939
|
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
983
940
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
984
941
|
// delete the same read value, or reading values that another simulation is currently modifying).
|
|
985
|
-
return this.#putInJobQueue(async
|
|
942
|
+
return this.#putInJobQueue(async jobId => {
|
|
986
943
|
try {
|
|
987
944
|
const totalTimer = new Timer();
|
|
988
945
|
const syncTimer = new Timer();
|
|
@@ -990,7 +947,18 @@ export class PXE {
|
|
|
990
947
|
const syncTime = syncTimer.ms();
|
|
991
948
|
const functionTimer = new Timer();
|
|
992
949
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
993
|
-
|
|
950
|
+
|
|
951
|
+
await this.contractStore.syncPrivateState(call.to, call.selector, privateSyncCall =>
|
|
952
|
+
this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
|
|
953
|
+
);
|
|
954
|
+
|
|
955
|
+
const executionResult = await this.#simulateUtility(
|
|
956
|
+
contractFunctionSimulator,
|
|
957
|
+
call,
|
|
958
|
+
authwits ?? [],
|
|
959
|
+
scopes,
|
|
960
|
+
jobId,
|
|
961
|
+
);
|
|
994
962
|
const functionTime = functionTimer.ms();
|
|
995
963
|
|
|
996
964
|
const totalTime = totalTimer.ms();
|
|
@@ -1035,11 +1003,25 @@ export class PXE {
|
|
|
1035
1003
|
eventSelector: EventSelector,
|
|
1036
1004
|
filter: PrivateEventFilter,
|
|
1037
1005
|
): Promise<PackedPrivateEvent[]> {
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
await this
|
|
1006
|
+
let anchorBlockNumber: BlockNumber;
|
|
1007
|
+
|
|
1008
|
+
await this.#putInJobQueue(async jobId => {
|
|
1009
|
+
await this.blockStateSynchronizer.sync();
|
|
1010
|
+
|
|
1011
|
+
anchorBlockNumber = (await this.anchorBlockStore.getBlockHeader()).getBlockNumber();
|
|
1012
|
+
|
|
1013
|
+
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
1014
|
+
|
|
1015
|
+
await this.contractStore.syncPrivateState(
|
|
1016
|
+
filter.contractAddress,
|
|
1017
|
+
null,
|
|
1018
|
+
async privateSyncCall =>
|
|
1019
|
+
await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
|
|
1020
|
+
);
|
|
1021
|
+
});
|
|
1041
1022
|
|
|
1042
|
-
|
|
1023
|
+
// anchorBlockNumber is set during the job and fixed to whatever it is after a block sync
|
|
1024
|
+
const sanitizedFilter = new PrivateEventFilterValidator(anchorBlockNumber!).validate(filter);
|
|
1043
1025
|
|
|
1044
1026
|
this.log.debug(
|
|
1045
1027
|
`Getting private events for ${sanitizedFilter.contractAddress.toString()} from ${sanitizedFilter.fromBlock} to ${sanitizedFilter.toBlock}`,
|