@aztec/pxe 0.0.1-commit.f2ce05ee → 0.0.1-commit.f5d02921e
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/access_scopes.d.ts +9 -0
- package/dest/access_scopes.d.ts.map +1 -0
- package/dest/access_scopes.js +6 -0
- package/dest/block_synchronizer/block_synchronizer.d.ts +1 -1
- package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
- package/dest/block_synchronizer/block_synchronizer.js +6 -0
- package/dest/config/index.d.ts +2 -2
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +1 -1
- package/dest/config/package_info.js +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +60 -30
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +199 -72
- package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +7 -7
- package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -1
- package/dest/contract_function_simulator/execution_tagging_index_cache.js +19 -11
- package/dest/contract_function_simulator/index.d.ts +2 -1
- package/dest/contract_function_simulator/index.d.ts.map +1 -1
- package/dest/contract_function_simulator/index.js +1 -0
- package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +3 -5
- 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 +7 -9
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +1 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +1 -3
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +3 -6
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/note_validation_request.js +5 -10
- package/dest/contract_function_simulator/oracle/interfaces.d.ts +50 -45
- package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts +9 -0
- package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.js +38 -0
- package/dest/contract_function_simulator/oracle/oracle.d.ts +64 -44
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +187 -97
- package/dest/contract_function_simulator/oracle/private_execution.js +5 -3
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +54 -80
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +98 -85
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +90 -52
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +213 -116
- package/dest/contract_logging.d.ts +27 -0
- package/dest/contract_logging.d.ts.map +1 -0
- package/dest/contract_logging.js +38 -0
- package/dest/contract_sync/contract_sync_service.d.ts +10 -5
- package/dest/contract_sync/contract_sync_service.d.ts.map +1 -1
- package/dest/contract_sync/contract_sync_service.js +72 -30
- package/dest/contract_sync/helpers.d.ts +3 -2
- package/dest/contract_sync/helpers.d.ts.map +1 -1
- package/dest/contract_sync/helpers.js +9 -4
- package/dest/debug/pxe_debug_utils.d.ts +5 -4
- package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
- package/dest/debug/pxe_debug_utils.js +4 -4
- package/dest/entrypoints/client/bundle/index.d.ts +4 -1
- package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/index.js +3 -0
- 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 +9 -1
- package/dest/entrypoints/client/lazy/index.d.ts +4 -1
- package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/index.js +3 -0
- 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 +9 -1
- package/dest/entrypoints/server/index.d.ts +3 -1
- package/dest/entrypoints/server/index.d.ts.map +1 -1
- package/dest/entrypoints/server/index.js +2 -0
- package/dest/entrypoints/server/utils.js +9 -1
- package/dest/events/event_service.d.ts +3 -2
- package/dest/events/event_service.d.ts.map +1 -1
- package/dest/events/event_service.js +16 -4
- package/dest/logs/log_service.d.ts +6 -6
- package/dest/logs/log_service.d.ts.map +1 -1
- package/dest/logs/log_service.js +31 -40
- package/dest/messages/message_context_service.d.ts +17 -0
- package/dest/messages/message_context_service.d.ts.map +1 -0
- package/dest/messages/message_context_service.js +36 -0
- package/dest/notes/note_service.d.ts +5 -4
- package/dest/notes/note_service.d.ts.map +1 -1
- package/dest/notes/note_service.js +17 -7
- package/dest/notes_filter.d.ts +25 -0
- package/dest/notes_filter.d.ts.map +1 -0
- package/dest/notes_filter.js +4 -0
- package/dest/oracle_version.d.ts +2 -2
- package/dest/oracle_version.js +3 -3
- package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts +4 -0
- package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts.map +1 -0
- package/dest/private_kernel/hints/{compute_tx_include_by_timestamp.js → compute_tx_expiration_timestamp.js} +12 -12
- package/dest/private_kernel/hints/index.d.ts +1 -1
- package/dest/private_kernel/hints/index.js +1 -1
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +4 -3
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -1
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.js +129 -68
- package/dest/private_kernel/hints/test_utils.d.ts +122 -0
- package/dest/private_kernel/hints/test_utils.d.ts.map +1 -0
- package/dest/private_kernel/hints/test_utils.js +203 -0
- 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 +19 -11
- package/dest/private_kernel/private_kernel_oracle.d.ts +6 -2
- package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_oracle.js +7 -3
- package/dest/pxe.d.ts +63 -24
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +105 -74
- package/dest/storage/capsule_store/capsule_service.d.ts +22 -0
- package/dest/storage/capsule_store/capsule_service.d.ts.map +1 -0
- package/dest/storage/capsule_store/capsule_service.js +50 -0
- package/dest/storage/capsule_store/capsule_store.d.ts +9 -9
- package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
- package/dest/storage/capsule_store/capsule_store.js +33 -28
- package/dest/storage/capsule_store/index.d.ts +2 -1
- package/dest/storage/capsule_store/index.d.ts.map +1 -1
- package/dest/storage/capsule_store/index.js +1 -0
- package/dest/storage/contract_store/contract_store.d.ts +42 -15
- package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
- package/dest/storage/contract_store/contract_store.js +140 -64
- package/dest/storage/metadata.d.ts +1 -1
- package/dest/storage/metadata.js +1 -1
- package/dest/storage/note_store/note_store.d.ts +3 -3
- package/dest/storage/note_store/note_store.d.ts.map +1 -1
- package/dest/storage/note_store/note_store.js +3 -4
- package/dest/storage/tagging_store/recipient_tagging_store.d.ts +6 -6
- package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/sender_tagging_store.d.ts +29 -28
- package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/sender_tagging_store.js +141 -115
- package/dest/tagging/get_all_logs_by_tags.d.ts +1 -1
- package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -1
- package/dest/tagging/get_all_logs_by_tags.js +17 -3
- package/dest/tagging/index.d.ts +3 -3
- package/dest/tagging/index.d.ts.map +1 -1
- package/dest/tagging/index.js +1 -1
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +4 -5
- 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/recipient_sync/utils/find_highest_indexes.js +2 -2
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +6 -7
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +12 -11
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +4 -8
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +13 -7
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +4 -3
- 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 +20 -10
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +5 -7
- 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 +36 -24
- package/package.json +16 -16
- package/src/access_scopes.ts +9 -0
- package/src/block_synchronizer/block_synchronizer.ts +6 -0
- package/src/config/index.ts +1 -1
- package/src/config/package_info.ts +1 -1
- package/src/contract_function_simulator/contract_function_simulator.ts +358 -133
- package/src/contract_function_simulator/execution_tagging_index_cache.ts +19 -14
- package/src/contract_function_simulator/index.ts +1 -0
- package/src/contract_function_simulator/noir-structs/event_validation_request.ts +8 -8
- package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +1 -4
- package/src/contract_function_simulator/noir-structs/note_validation_request.ts +3 -9
- package/src/contract_function_simulator/oracle/interfaces.ts +63 -54
- package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +98 -0
- package/src/contract_function_simulator/oracle/oracle.ts +223 -139
- package/src/contract_function_simulator/oracle/private_execution.ts +4 -4
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +122 -177
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +375 -131
- package/src/contract_logging.ts +52 -0
- package/src/contract_sync/contract_sync_service.ts +108 -45
- package/src/contract_sync/helpers.ts +9 -3
- package/src/debug/pxe_debug_utils.ts +11 -9
- package/src/entrypoints/client/bundle/index.ts +3 -0
- package/src/entrypoints/client/bundle/utils.ts +9 -1
- package/src/entrypoints/client/lazy/index.ts +3 -0
- package/src/entrypoints/client/lazy/utils.ts +9 -1
- package/src/entrypoints/server/index.ts +2 -0
- package/src/entrypoints/server/utils.ts +7 -7
- package/src/events/event_service.ts +17 -4
- package/src/logs/log_service.ts +61 -63
- package/src/messages/message_context_service.ts +44 -0
- package/src/notes/note_service.ts +20 -8
- package/src/notes_filter.ts +26 -0
- package/src/oracle_version.ts +3 -3
- package/src/private_kernel/hints/{compute_tx_include_by_timestamp.ts → compute_tx_expiration_timestamp.ts} +13 -13
- package/src/private_kernel/hints/index.ts +1 -1
- package/src/private_kernel/hints/private_kernel_reset_private_inputs_builder.ts +164 -117
- package/src/private_kernel/hints/test_utils.ts +325 -0
- package/src/private_kernel/private_kernel_execution_prover.ts +19 -12
- package/src/private_kernel/private_kernel_oracle.ts +7 -7
- package/src/pxe.ts +190 -117
- package/src/storage/capsule_store/capsule_service.ts +91 -0
- package/src/storage/capsule_store/capsule_store.ts +34 -26
- package/src/storage/capsule_store/index.ts +1 -0
- package/src/storage/contract_store/contract_store.ts +170 -71
- package/src/storage/metadata.ts +1 -1
- package/src/storage/note_store/note_store.ts +8 -5
- package/src/storage/tagging_store/recipient_tagging_store.ts +9 -5
- package/src/storage/tagging_store/sender_tagging_store.ts +185 -138
- package/src/tagging/get_all_logs_by_tags.ts +28 -4
- package/src/tagging/index.ts +2 -2
- package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +7 -10
- package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +2 -2
- package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +10 -15
- package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +23 -10
- package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +26 -11
- package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +27 -26
- package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +0 -4
- package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +0 -1
package/src/pxe.ts
CHANGED
|
@@ -47,11 +47,12 @@ import {
|
|
|
47
47
|
TxProfileResult,
|
|
48
48
|
TxProvingResult,
|
|
49
49
|
TxSimulationResult,
|
|
50
|
-
|
|
50
|
+
UtilityExecutionResult,
|
|
51
51
|
} from '@aztec/stdlib/tx';
|
|
52
52
|
|
|
53
53
|
import { inspect } from 'util';
|
|
54
54
|
|
|
55
|
+
import type { AccessScopes } from './access_scopes.js';
|
|
55
56
|
import { BlockSynchronizer } from './block_synchronizer/index.js';
|
|
56
57
|
import type { PXEConfig } from './config/index.js';
|
|
57
58
|
import { BenchmarkedNodeFactory } from './contract_function_simulator/benchmarked_node.js';
|
|
@@ -60,12 +61,14 @@ import {
|
|
|
60
61
|
generateSimulatedProvingResult,
|
|
61
62
|
} from './contract_function_simulator/contract_function_simulator.js';
|
|
62
63
|
import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
|
|
64
|
+
import { displayDebugLogs } from './contract_logging.js';
|
|
63
65
|
import { ContractSyncService } from './contract_sync/contract_sync_service.js';
|
|
64
66
|
import { readCurrentClassId } from './contract_sync/helpers.js';
|
|
65
67
|
import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
|
|
66
68
|
import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
|
|
67
69
|
import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
|
|
68
70
|
import { JobCoordinator } from './job_coordinator/job_coordinator.js';
|
|
71
|
+
import { MessageContextService } from './messages/message_context_service.js';
|
|
69
72
|
import {
|
|
70
73
|
PrivateKernelExecutionProver,
|
|
71
74
|
type PrivateKernelExecutionProverConfig,
|
|
@@ -86,6 +89,58 @@ export type PackedPrivateEvent = InTx & {
|
|
|
86
89
|
eventSelector: EventSelector;
|
|
87
90
|
};
|
|
88
91
|
|
|
92
|
+
/** Options for PXE.profileTx. */
|
|
93
|
+
export type ProfileTxOpts = {
|
|
94
|
+
/** The profiling mode to use. */
|
|
95
|
+
profileMode: 'full' | 'execution-steps' | 'gates';
|
|
96
|
+
/** If true, proof generation is skipped during profiling. Defaults to true. */
|
|
97
|
+
skipProofGeneration?: boolean;
|
|
98
|
+
/** Addresses whose private state and keys are accessible during private execution. */
|
|
99
|
+
scopes: AccessScopes;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
/** Options for PXE.simulateTx. */
|
|
103
|
+
export type SimulateTxOpts = {
|
|
104
|
+
/** Whether to simulate the public part of the transaction. */
|
|
105
|
+
simulatePublic: boolean;
|
|
106
|
+
/** If false, this function throws if the transaction is unable to be included in a block at the current state. */
|
|
107
|
+
skipTxValidation?: boolean;
|
|
108
|
+
/** If false, fees are enforced. */
|
|
109
|
+
skipFeeEnforcement?: boolean;
|
|
110
|
+
/** If true, kernel logic is emulated in TS for simulation */
|
|
111
|
+
skipKernels?: boolean;
|
|
112
|
+
/** State overrides for the simulation, such as contract instances and artifacts. Requires skipKernels: true */
|
|
113
|
+
overrides?: SimulationOverrides;
|
|
114
|
+
/** Addresses whose private state and keys are accessible during private execution */
|
|
115
|
+
scopes: AccessScopes;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
/** Options for PXE.executeUtility. */
|
|
119
|
+
export type ExecuteUtilityOpts = {
|
|
120
|
+
/** The authentication witnesses required for the function call. */
|
|
121
|
+
authwits?: AuthWitness[];
|
|
122
|
+
/** The accounts whose notes we can access in this call */
|
|
123
|
+
scopes: AccessScopes;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
/** Args for PXE.create. */
|
|
127
|
+
export type PXECreateArgs = {
|
|
128
|
+
/** The Aztec node to connect to. */
|
|
129
|
+
node: AztecNode;
|
|
130
|
+
/** The key-value store for persisting PXE state. */
|
|
131
|
+
store: AztecAsyncKVStore;
|
|
132
|
+
/** The prover for generating private kernel proofs. */
|
|
133
|
+
proofCreator: PrivateKernelProver;
|
|
134
|
+
/** The circuit simulator for executing ACIR circuits. */
|
|
135
|
+
simulator: CircuitSimulator;
|
|
136
|
+
/** Provider for protocol contract artifacts and instances. */
|
|
137
|
+
protocolContractsProvider: ProtocolContractsProvider;
|
|
138
|
+
/** PXE configuration options. */
|
|
139
|
+
config: PXEConfig;
|
|
140
|
+
/** Optional logger instance or string suffix for the logger name. */
|
|
141
|
+
loggerOrSuffix?: string | Logger;
|
|
142
|
+
};
|
|
143
|
+
|
|
89
144
|
/**
|
|
90
145
|
* Private eXecution Environment (PXE) is a library used by wallets to simulate private phase of transactions and to
|
|
91
146
|
* manage private state of users.
|
|
@@ -93,6 +148,7 @@ export type PackedPrivateEvent = InTx & {
|
|
|
93
148
|
export class PXE {
|
|
94
149
|
private constructor(
|
|
95
150
|
private node: AztecNode,
|
|
151
|
+
private db: AztecAsyncKVStore,
|
|
96
152
|
private blockStateSynchronizer: BlockSynchronizer,
|
|
97
153
|
private keyStore: KeyStore,
|
|
98
154
|
private contractStore: ContractStore,
|
|
@@ -105,6 +161,7 @@ export class PXE {
|
|
|
105
161
|
private addressStore: AddressStore,
|
|
106
162
|
private privateEventStore: PrivateEventStore,
|
|
107
163
|
private contractSyncService: ContractSyncService,
|
|
164
|
+
private messageContextService: MessageContextService,
|
|
108
165
|
private simulator: CircuitSimulator,
|
|
109
166
|
private proverEnabled: boolean,
|
|
110
167
|
private proofCreator: PrivateKernelProver,
|
|
@@ -122,15 +179,15 @@ export class PXE {
|
|
|
122
179
|
*
|
|
123
180
|
* @returns A promise that resolves PXE is ready to be used.
|
|
124
181
|
*/
|
|
125
|
-
public static async create(
|
|
126
|
-
node
|
|
127
|
-
store
|
|
128
|
-
proofCreator
|
|
129
|
-
simulator
|
|
130
|
-
protocolContractsProvider
|
|
131
|
-
config
|
|
132
|
-
loggerOrSuffix
|
|
133
|
-
) {
|
|
182
|
+
public static async create({
|
|
183
|
+
node,
|
|
184
|
+
store,
|
|
185
|
+
proofCreator,
|
|
186
|
+
simulator,
|
|
187
|
+
protocolContractsProvider,
|
|
188
|
+
config,
|
|
189
|
+
loggerOrSuffix,
|
|
190
|
+
}: PXECreateArgs) {
|
|
134
191
|
// Extract bindings from the logger, or use empty bindings if a string suffix is provided.
|
|
135
192
|
const bindings: LoggerBindings | undefined =
|
|
136
193
|
loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
|
|
@@ -140,7 +197,9 @@ export class PXE {
|
|
|
140
197
|
? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
|
|
141
198
|
: loggerOrSuffix;
|
|
142
199
|
|
|
143
|
-
const
|
|
200
|
+
const info = await node.getNodeInfo();
|
|
201
|
+
|
|
202
|
+
const proverEnabled = config.proverEnabled !== undefined ? config.proverEnabled : info.realProofs;
|
|
144
203
|
const addressStore = new AddressStore(store);
|
|
145
204
|
const privateEventStore = new PrivateEventStore(store);
|
|
146
205
|
const contractStore = new ContractStore(store);
|
|
@@ -156,8 +215,11 @@ export class PXE {
|
|
|
156
215
|
node,
|
|
157
216
|
contractStore,
|
|
158
217
|
noteStore,
|
|
218
|
+
() => keyStore.getAccounts(),
|
|
159
219
|
createLogger('pxe:contract_sync', bindings),
|
|
160
220
|
);
|
|
221
|
+
const messageContextService = new MessageContextService(node);
|
|
222
|
+
|
|
161
223
|
const synchronizer = new BlockSynchronizer(
|
|
162
224
|
node,
|
|
163
225
|
store,
|
|
@@ -186,6 +248,7 @@ export class PXE {
|
|
|
186
248
|
|
|
187
249
|
const pxe = new PXE(
|
|
188
250
|
node,
|
|
251
|
+
store,
|
|
189
252
|
synchronizer,
|
|
190
253
|
keyStore,
|
|
191
254
|
contractStore,
|
|
@@ -198,6 +261,7 @@ export class PXE {
|
|
|
198
261
|
addressStore,
|
|
199
262
|
privateEventStore,
|
|
200
263
|
contractSyncService,
|
|
264
|
+
messageContextService,
|
|
201
265
|
simulator,
|
|
202
266
|
proverEnabled,
|
|
203
267
|
proofCreator,
|
|
@@ -211,13 +275,12 @@ export class PXE {
|
|
|
211
275
|
debugUtils.setPXEHelpers(
|
|
212
276
|
pxe.#putInJobQueue.bind(pxe),
|
|
213
277
|
pxe.#getSimulatorForTx.bind(pxe),
|
|
214
|
-
pxe.#
|
|
278
|
+
pxe.#executeUtility.bind(pxe),
|
|
215
279
|
);
|
|
216
280
|
|
|
217
281
|
pxe.jobQueue.start();
|
|
218
282
|
|
|
219
283
|
await pxe.#registerProtocolContracts();
|
|
220
|
-
const info = await node.getNodeInfo();
|
|
221
284
|
log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
|
|
222
285
|
return pxe;
|
|
223
286
|
}
|
|
@@ -227,20 +290,21 @@ export class PXE {
|
|
|
227
290
|
#getSimulatorForTx(overrides?: { contracts?: ContractOverrides }) {
|
|
228
291
|
const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
|
|
229
292
|
|
|
230
|
-
return new ContractFunctionSimulator(
|
|
231
|
-
proxyContractStore,
|
|
232
|
-
this.noteStore,
|
|
233
|
-
this.keyStore,
|
|
234
|
-
this.addressStore,
|
|
235
|
-
BenchmarkedNodeFactory.create(this.node),
|
|
236
|
-
this.senderTaggingStore,
|
|
237
|
-
this.recipientTaggingStore,
|
|
238
|
-
this.senderAddressBookStore,
|
|
239
|
-
this.capsuleStore,
|
|
240
|
-
this.privateEventStore,
|
|
241
|
-
this.simulator,
|
|
242
|
-
this.contractSyncService,
|
|
243
|
-
|
|
293
|
+
return new ContractFunctionSimulator({
|
|
294
|
+
contractStore: proxyContractStore,
|
|
295
|
+
noteStore: this.noteStore,
|
|
296
|
+
keyStore: this.keyStore,
|
|
297
|
+
addressStore: this.addressStore,
|
|
298
|
+
aztecNode: BenchmarkedNodeFactory.create(this.node),
|
|
299
|
+
senderTaggingStore: this.senderTaggingStore,
|
|
300
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
301
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
302
|
+
capsuleStore: this.capsuleStore,
|
|
303
|
+
privateEventStore: this.privateEventStore,
|
|
304
|
+
simulator: this.simulator,
|
|
305
|
+
contractSyncService: this.contractSyncService,
|
|
306
|
+
messageContextService: this.messageContextService,
|
|
307
|
+
});
|
|
244
308
|
}
|
|
245
309
|
|
|
246
310
|
#contextualizeError(err: Error, ...context: string[]): Error {
|
|
@@ -292,9 +356,8 @@ export class PXE {
|
|
|
292
356
|
async #registerProtocolContracts() {
|
|
293
357
|
const registered: Record<string, string> = {};
|
|
294
358
|
for (const name of protocolContractNames) {
|
|
295
|
-
const { address,
|
|
296
|
-
|
|
297
|
-
await this.contractStore.addContractArtifact(contractClass.id, artifact);
|
|
359
|
+
const { address, instance, artifact } = await this.protocolContractsProvider.getProtocolContractArtifact(name);
|
|
360
|
+
await this.contractStore.addContractArtifact(artifact);
|
|
298
361
|
await this.contractStore.addContractInstance(instance);
|
|
299
362
|
registered[name] = address.toString();
|
|
300
363
|
}
|
|
@@ -306,7 +369,7 @@ export class PXE {
|
|
|
306
369
|
async #executePrivate(
|
|
307
370
|
contractFunctionSimulator: ContractFunctionSimulator,
|
|
308
371
|
txRequest: TxExecutionRequest,
|
|
309
|
-
scopes:
|
|
372
|
+
scopes: AccessScopes,
|
|
310
373
|
jobId: string,
|
|
311
374
|
): Promise<PrivateExecutionResult> {
|
|
312
375
|
const { origin: contractAddress, functionSelector } = txRequest;
|
|
@@ -317,23 +380,20 @@ export class PXE {
|
|
|
317
380
|
await this.contractSyncService.ensureContractSynced(
|
|
318
381
|
contractAddress,
|
|
319
382
|
functionSelector,
|
|
320
|
-
|
|
383
|
+
(privateSyncCall, execScopes) =>
|
|
384
|
+
this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
321
385
|
anchorBlockHeader,
|
|
322
386
|
jobId,
|
|
387
|
+
scopes,
|
|
323
388
|
);
|
|
324
389
|
|
|
325
|
-
const result = await contractFunctionSimulator.run(
|
|
326
|
-
txRequest,
|
|
390
|
+
const result = await contractFunctionSimulator.run(txRequest, {
|
|
327
391
|
contractAddress,
|
|
328
|
-
functionSelector,
|
|
329
|
-
undefined,
|
|
392
|
+
selector: functionSelector,
|
|
330
393
|
anchorBlockHeader,
|
|
331
|
-
// The sender for tags is set by contracts, typically by an account
|
|
332
|
-
// contract entrypoint
|
|
333
|
-
undefined, // senderForTags
|
|
334
394
|
scopes,
|
|
335
395
|
jobId,
|
|
336
|
-
);
|
|
396
|
+
});
|
|
337
397
|
this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
|
|
338
398
|
return result;
|
|
339
399
|
} catch (err) {
|
|
@@ -345,25 +405,32 @@ export class PXE {
|
|
|
345
405
|
}
|
|
346
406
|
|
|
347
407
|
/**
|
|
348
|
-
*
|
|
408
|
+
* Execute a utility function call on the given contract.
|
|
349
409
|
* @param contractFunctionSimulator - The simulator to use for the function call.
|
|
350
410
|
* @param call - The function call to execute.
|
|
351
411
|
* @param authWitnesses - Authentication witnesses required for the function call.
|
|
352
412
|
* @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
|
|
353
413
|
* accounts if not specified.
|
|
354
414
|
* @param jobId - The job ID for staged writes.
|
|
355
|
-
* @returns The
|
|
415
|
+
* @returns The execution result containing the outputs of the utility function.
|
|
356
416
|
*/
|
|
357
|
-
async #
|
|
417
|
+
async #executeUtility(
|
|
358
418
|
contractFunctionSimulator: ContractFunctionSimulator,
|
|
359
419
|
call: FunctionCall,
|
|
360
420
|
authWitnesses: AuthWitness[] | undefined,
|
|
361
|
-
scopes:
|
|
421
|
+
scopes: AccessScopes,
|
|
362
422
|
jobId: string,
|
|
363
423
|
) {
|
|
364
424
|
try {
|
|
365
425
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
366
|
-
|
|
426
|
+
const { result, offchainEffects } = await contractFunctionSimulator.runUtility(
|
|
427
|
+
call,
|
|
428
|
+
authWitnesses ?? [],
|
|
429
|
+
anchorBlockHeader,
|
|
430
|
+
scopes,
|
|
431
|
+
jobId,
|
|
432
|
+
);
|
|
433
|
+
return { result, offchainEffects };
|
|
367
434
|
} catch (err) {
|
|
368
435
|
if (err instanceof SimulationError) {
|
|
369
436
|
await enrichSimulationError(err, this.contractStore, this.log);
|
|
@@ -436,7 +503,9 @@ export class PXE {
|
|
|
436
503
|
* @returns The synced block header
|
|
437
504
|
*/
|
|
438
505
|
public getSyncedBlockHeader(): Promise<BlockHeader> {
|
|
439
|
-
return this
|
|
506
|
+
return this.#putInJobQueue(() => {
|
|
507
|
+
return this.anchorBlockStore.getBlockHeader();
|
|
508
|
+
});
|
|
440
509
|
}
|
|
441
510
|
|
|
442
511
|
/**
|
|
@@ -503,6 +572,9 @@ export class PXE {
|
|
|
503
572
|
|
|
504
573
|
if (wasAdded) {
|
|
505
574
|
this.log.info(`Added sender:\n ${sender.toString()}`);
|
|
575
|
+
// Wipe the entire sync cache: the new sender's tagged logs could contain notes/events for any contract, so
|
|
576
|
+
// all contracts must re-sync to discover them.
|
|
577
|
+
this.contractSyncService.wipe();
|
|
506
578
|
} else {
|
|
507
579
|
this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
|
|
508
580
|
}
|
|
@@ -552,8 +624,7 @@ export class PXE {
|
|
|
552
624
|
* @param artifact - The build artifact for the contract class.
|
|
553
625
|
*/
|
|
554
626
|
public async registerContractClass(artifact: ContractArtifact): Promise<void> {
|
|
555
|
-
const
|
|
556
|
-
await this.contractStore.addContractArtifact(contractClassId, artifact);
|
|
627
|
+
const contractClassId = await this.contractStore.addContractArtifact(artifact);
|
|
557
628
|
this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
|
|
558
629
|
}
|
|
559
630
|
|
|
@@ -572,17 +643,17 @@ export class PXE {
|
|
|
572
643
|
if (artifact) {
|
|
573
644
|
// If the user provides an artifact, validate it against the expected class id and register it
|
|
574
645
|
const contractClass = await getContractClassFromArtifact(artifact);
|
|
575
|
-
|
|
576
|
-
if (!contractClassId.equals(instance.currentContractClassId)) {
|
|
646
|
+
if (!contractClass.id.equals(instance.currentContractClassId)) {
|
|
577
647
|
throw new Error(
|
|
578
|
-
`Artifact does not match expected class id (computed ${
|
|
648
|
+
`Artifact does not match expected class id (computed ${contractClass.id} but instance refers to ${instance.currentContractClassId})`,
|
|
579
649
|
);
|
|
580
650
|
}
|
|
581
651
|
const computedAddress = await computeContractAddressFromInstance(instance);
|
|
582
652
|
if (!computedAddress.equals(instance.address)) {
|
|
583
653
|
throw new Error('Added a contract in which the address does not match the contract instance.');
|
|
584
654
|
}
|
|
585
|
-
|
|
655
|
+
|
|
656
|
+
await this.contractStore.addContractArtifact(artifact, contractClass);
|
|
586
657
|
|
|
587
658
|
const publicFunctionSignatures = artifact.functions
|
|
588
659
|
.filter(fn => fn.functionType === FunctionType.PUBLIC)
|
|
@@ -631,15 +702,16 @@ export class PXE {
|
|
|
631
702
|
throw new Error('Could not update contract to a class different from the current one.');
|
|
632
703
|
}
|
|
633
704
|
|
|
634
|
-
await this.contractStore.addContractArtifact(contractClass.id, artifact);
|
|
635
|
-
|
|
636
705
|
const publicFunctionSignatures = artifact.functions
|
|
637
706
|
.filter(fn => fn.functionType === FunctionType.PUBLIC)
|
|
638
707
|
.map(fn => decodeFunctionSignature(fn.name, fn.parameters));
|
|
639
708
|
await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
|
|
640
709
|
|
|
641
710
|
currentInstance.currentContractClassId = contractClass.id;
|
|
642
|
-
await
|
|
711
|
+
await Promise.all([
|
|
712
|
+
this.contractStore.addContractArtifact(artifact, contractClass),
|
|
713
|
+
this.contractStore.addContractInstance(currentInstance),
|
|
714
|
+
]);
|
|
643
715
|
this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
|
|
644
716
|
});
|
|
645
717
|
}
|
|
@@ -657,11 +729,12 @@ export class PXE {
|
|
|
657
729
|
* (where validators prove the public portion).
|
|
658
730
|
*
|
|
659
731
|
* @param txRequest - An authenticated tx request ready for proving
|
|
732
|
+
* @param scopes - Addresses whose private state and keys are accessible during private execution.
|
|
660
733
|
* @returns A result containing the proof and public inputs of the tail circuit.
|
|
661
734
|
* @throws If contract code not found, or public simulation reverts.
|
|
662
735
|
* Also throws if simulatePublic is true and public simulation reverts.
|
|
663
736
|
*/
|
|
664
|
-
public proveTx(txRequest: TxExecutionRequest): Promise<TxProvingResult> {
|
|
737
|
+
public proveTx(txRequest: TxExecutionRequest, scopes: AztecAddress[]): Promise<TxProvingResult> {
|
|
665
738
|
let privateExecutionResult: PrivateExecutionResult;
|
|
666
739
|
// We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
|
|
667
740
|
// computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
|
|
@@ -672,7 +745,7 @@ export class PXE {
|
|
|
672
745
|
await this.blockStateSynchronizer.sync();
|
|
673
746
|
const syncTime = syncTimer.ms();
|
|
674
747
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
675
|
-
privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest,
|
|
748
|
+
privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
676
749
|
|
|
677
750
|
const {
|
|
678
751
|
publicInputs,
|
|
@@ -714,17 +787,17 @@ export class PXE {
|
|
|
714
787
|
// transaction before this one is included in a block from this PXE, and that transaction contains a log with
|
|
715
788
|
// a tag derived from the same secret, we would reuse the tag and the transactions would be linked. Hence
|
|
716
789
|
// storing the tags here prevents linkage of txs sent from the same PXE.
|
|
717
|
-
const
|
|
718
|
-
if (
|
|
790
|
+
const taggingIndexRangesUsedInTheTx = privateExecutionResult.entrypoint.taggingIndexRanges;
|
|
791
|
+
if (taggingIndexRangesUsedInTheTx.length > 0) {
|
|
719
792
|
// TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
|
|
720
793
|
const txHash = (await txProvingResult.toTx()).txHash;
|
|
721
794
|
|
|
722
|
-
await this.senderTaggingStore.storePendingIndexes(
|
|
723
|
-
this.log.debug(`Stored used
|
|
724
|
-
|
|
795
|
+
await this.senderTaggingStore.storePendingIndexes(taggingIndexRangesUsedInTheTx, txHash, jobId);
|
|
796
|
+
this.log.debug(`Stored used tagging index ranges as sender for the tx`, {
|
|
797
|
+
taggingIndexRangesUsedInTheTx,
|
|
725
798
|
});
|
|
726
799
|
} else {
|
|
727
|
-
this.log.debug(`No
|
|
800
|
+
this.log.debug(`No tagging index ranges used in the tx`);
|
|
728
801
|
}
|
|
729
802
|
|
|
730
803
|
return txProvingResult;
|
|
@@ -736,17 +809,13 @@ export class PXE {
|
|
|
736
809
|
|
|
737
810
|
/**
|
|
738
811
|
* Profiles a transaction, reporting gate counts (unless disabled) and returns an execution trace.
|
|
739
|
-
*
|
|
740
|
-
* @param txRequest - An authenticated tx request ready for simulation
|
|
741
|
-
* @param msgSender - (Optional) The message sender to use for the simulation.
|
|
742
|
-
* @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
|
|
812
|
+
* @param txRequest - An authenticated tx request ready for simulation.
|
|
743
813
|
* @returns A trace of the program execution with gate counts.
|
|
744
814
|
* @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
|
|
745
815
|
*/
|
|
746
816
|
public profileTx(
|
|
747
817
|
txRequest: TxExecutionRequest,
|
|
748
|
-
profileMode
|
|
749
|
-
skipProofGeneration: boolean = true,
|
|
818
|
+
{ profileMode, skipProofGeneration = true, scopes }: ProfileTxOpts,
|
|
750
819
|
): Promise<TxProfileResult> {
|
|
751
820
|
// We disable concurrent profiles for consistency with simulateTx.
|
|
752
821
|
return this.#putInJobQueue(async jobId => {
|
|
@@ -769,12 +838,7 @@ export class PXE {
|
|
|
769
838
|
const syncTime = syncTimer.ms();
|
|
770
839
|
|
|
771
840
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
772
|
-
const privateExecutionResult = await this.#executePrivate(
|
|
773
|
-
contractFunctionSimulator,
|
|
774
|
-
txRequest,
|
|
775
|
-
undefined,
|
|
776
|
-
jobId,
|
|
777
|
-
);
|
|
841
|
+
const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
778
842
|
|
|
779
843
|
const { executionSteps, timings: { proving } = {} } = await this.#prove(
|
|
780
844
|
txRequest,
|
|
@@ -831,12 +895,7 @@ export class PXE {
|
|
|
831
895
|
* In that case, the transaction returned is only potentially ready to be sent to the network for execution.
|
|
832
896
|
*
|
|
833
897
|
*
|
|
834
|
-
* @param txRequest - An authenticated tx request ready for simulation
|
|
835
|
-
* @param simulatePublic - Whether to simulate the public part of the transaction.
|
|
836
|
-
* @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
|
|
837
|
-
* @param skipFeeEnforcement - (Optional) If false, fees are enforced.
|
|
838
|
-
* @param overrides - (Optional) State overrides for the simulation, such as msgSender, contract instances and artifacts.
|
|
839
|
-
* @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will default to all.
|
|
898
|
+
* @param txRequest - An authenticated tx request ready for simulation.
|
|
840
899
|
* @returns A simulated transaction result object that includes public and private return values.
|
|
841
900
|
* @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
|
|
842
901
|
* Also throws if simulatePublic is true and public simulation reverts.
|
|
@@ -845,11 +904,14 @@ export class PXE {
|
|
|
845
904
|
*/
|
|
846
905
|
public simulateTx(
|
|
847
906
|
txRequest: TxExecutionRequest,
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
907
|
+
{
|
|
908
|
+
simulatePublic,
|
|
909
|
+
skipTxValidation = false,
|
|
910
|
+
skipFeeEnforcement = false,
|
|
911
|
+
skipKernels = true,
|
|
912
|
+
overrides,
|
|
913
|
+
scopes,
|
|
914
|
+
}: SimulateTxOpts,
|
|
853
915
|
): Promise<TxSimulationResult> {
|
|
854
916
|
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
855
917
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
@@ -873,17 +935,20 @@ export class PXE {
|
|
|
873
935
|
await this.blockStateSynchronizer.sync();
|
|
874
936
|
const syncTime = syncTimer.ms();
|
|
875
937
|
|
|
876
|
-
const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
|
|
877
|
-
// Temporary: in case there are overrides, we have to skip the kernels or validations
|
|
878
|
-
// will fail. Consider handing control to the user/wallet on whether they want to run them
|
|
879
|
-
// or not.
|
|
880
938
|
const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
|
|
881
939
|
const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
|
|
882
|
-
const skipKernels = hasOverriddenContracts;
|
|
883
940
|
|
|
884
|
-
|
|
941
|
+
if (hasOverriddenContracts && !skipKernels) {
|
|
942
|
+
throw new Error(
|
|
943
|
+
'Simulating with overridden contracts is not compatible with kernel execution. Please set skipKernels to true when simulating with overridden contracts.',
|
|
944
|
+
);
|
|
945
|
+
}
|
|
946
|
+
const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
|
|
947
|
+
|
|
885
948
|
if (hasOverriddenContracts) {
|
|
886
|
-
|
|
949
|
+
// Overridden contracts don't have a sync function, so calling sync on them would fail.
|
|
950
|
+
// We exclude them so the sync service skips them entirely.
|
|
951
|
+
this.contractSyncService.setExcludedFromSync(jobId, overriddenContracts);
|
|
887
952
|
}
|
|
888
953
|
|
|
889
954
|
// Execution of private functions only; no proving, and no kernel logic.
|
|
@@ -896,6 +961,7 @@ export class PXE {
|
|
|
896
961
|
({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
|
|
897
962
|
privateExecutionResult,
|
|
898
963
|
(addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
|
|
964
|
+
this.node,
|
|
899
965
|
));
|
|
900
966
|
} else {
|
|
901
967
|
// Kernel logic, plus proving of all private functions and kernels.
|
|
@@ -914,6 +980,9 @@ export class PXE {
|
|
|
914
980
|
const publicSimulationTimer = new Timer();
|
|
915
981
|
publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement);
|
|
916
982
|
publicSimulationTime = publicSimulationTimer.ms();
|
|
983
|
+
if (publicOutput?.debugLogs?.length) {
|
|
984
|
+
await displayDebugLogs(publicOutput.debugLogs, addr => this.contractStore.getDebugContractName(addr));
|
|
985
|
+
}
|
|
917
986
|
}
|
|
918
987
|
|
|
919
988
|
let validationTime: number | undefined;
|
|
@@ -922,7 +991,8 @@ export class PXE {
|
|
|
922
991
|
const validationResult = await this.node.isValidTx(simulatedTx, { isSimulation: true, skipFeeEnforcement });
|
|
923
992
|
validationTime = validationTimer.ms();
|
|
924
993
|
if (validationResult.result === 'invalid') {
|
|
925
|
-
|
|
994
|
+
const reason = validationResult.reason.length > 0 ? ` Reason: ${validationResult.reason.join(', ')}` : '';
|
|
995
|
+
throw new Error(`The simulated transaction is unable to be added to state and is invalid.${reason}`);
|
|
926
996
|
}
|
|
927
997
|
}
|
|
928
998
|
|
|
@@ -973,29 +1043,23 @@ export class PXE {
|
|
|
973
1043
|
inspect(txRequest),
|
|
974
1044
|
`simulatePublic=${simulatePublic}`,
|
|
975
1045
|
`skipTxValidation=${skipTxValidation}`,
|
|
976
|
-
`scopes=${scopes
|
|
1046
|
+
`scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
|
|
977
1047
|
);
|
|
978
1048
|
}
|
|
979
1049
|
});
|
|
980
1050
|
}
|
|
981
1051
|
|
|
982
1052
|
/**
|
|
983
|
-
*
|
|
984
|
-
*
|
|
1053
|
+
* Executes a contract utility function.
|
|
985
1054
|
* @param call - The function call containing the function details, arguments, and target contract address.
|
|
986
|
-
* @param authwits - (Optional) The authentication witnesses required for the function call.
|
|
987
|
-
* @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will
|
|
988
|
-
* default to all.
|
|
989
|
-
* @returns The result of the utility function call, structured based on the function ABI.
|
|
990
1055
|
*/
|
|
991
|
-
public
|
|
1056
|
+
public executeUtility(
|
|
992
1057
|
call: FunctionCall,
|
|
993
|
-
authwits
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
1058
|
+
{ authwits, scopes }: ExecuteUtilityOpts = { scopes: 'ALL_SCOPES' },
|
|
1059
|
+
): Promise<UtilityExecutionResult> {
|
|
1060
|
+
// We disable concurrent executions since those might execute oracles which read and write to the PXE stores (e.g.
|
|
997
1061
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
998
|
-
// delete the same read value, or reading values that another
|
|
1062
|
+
// delete the same read value, or reading values that another execution is currently modifying).
|
|
999
1063
|
return this.#putInJobQueue(async jobId => {
|
|
1000
1064
|
try {
|
|
1001
1065
|
const totalTimer = new Timer();
|
|
@@ -1009,12 +1073,14 @@ export class PXE {
|
|
|
1009
1073
|
await this.contractSyncService.ensureContractSynced(
|
|
1010
1074
|
call.to,
|
|
1011
1075
|
call.selector,
|
|
1012
|
-
|
|
1076
|
+
(privateSyncCall, execScopes) =>
|
|
1077
|
+
this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
1013
1078
|
anchorBlockHeader,
|
|
1014
1079
|
jobId,
|
|
1080
|
+
scopes,
|
|
1015
1081
|
);
|
|
1016
1082
|
|
|
1017
|
-
const executionResult = await this.#
|
|
1083
|
+
const { result: executionResult, offchainEffects } = await this.#executeUtility(
|
|
1018
1084
|
contractFunctionSimulator,
|
|
1019
1085
|
call,
|
|
1020
1086
|
authwits ?? [],
|
|
@@ -1035,14 +1101,19 @@ export class PXE {
|
|
|
1035
1101
|
};
|
|
1036
1102
|
|
|
1037
1103
|
const simulationStats = contractFunctionSimulator.getStats();
|
|
1038
|
-
return {
|
|
1104
|
+
return {
|
|
1105
|
+
result: executionResult,
|
|
1106
|
+
offchainEffects,
|
|
1107
|
+
anchorBlockTimestamp: anchorBlockHeader.globalVariables.timestamp,
|
|
1108
|
+
stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls },
|
|
1109
|
+
};
|
|
1039
1110
|
} catch (err: any) {
|
|
1040
1111
|
const { to, name, args } = call;
|
|
1041
1112
|
const stringifiedArgs = args.map(arg => arg.toString()).join(', ');
|
|
1042
1113
|
throw this.#contextualizeError(
|
|
1043
1114
|
err,
|
|
1044
|
-
`
|
|
1045
|
-
`scopes=${scopes
|
|
1115
|
+
`executeUtility ${to}:${name}(${stringifiedArgs})`,
|
|
1116
|
+
`scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
|
|
1046
1117
|
);
|
|
1047
1118
|
}
|
|
1048
1119
|
});
|
|
@@ -1078,10 +1149,11 @@ export class PXE {
|
|
|
1078
1149
|
await this.contractSyncService.ensureContractSynced(
|
|
1079
1150
|
filter.contractAddress,
|
|
1080
1151
|
null,
|
|
1081
|
-
async privateSyncCall =>
|
|
1082
|
-
await this.#
|
|
1152
|
+
async (privateSyncCall, execScopes) =>
|
|
1153
|
+
await this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
1083
1154
|
anchorBlockHeader,
|
|
1084
1155
|
jobId,
|
|
1156
|
+
filter.scopes,
|
|
1085
1157
|
);
|
|
1086
1158
|
});
|
|
1087
1159
|
|
|
@@ -1096,9 +1168,10 @@ export class PXE {
|
|
|
1096
1168
|
}
|
|
1097
1169
|
|
|
1098
1170
|
/**
|
|
1099
|
-
* Stops the PXE's job queue.
|
|
1171
|
+
* Stops the PXE's job queue and closes the backing store.
|
|
1100
1172
|
*/
|
|
1101
|
-
public stop(): Promise<void> {
|
|
1102
|
-
|
|
1173
|
+
public async stop(): Promise<void> {
|
|
1174
|
+
await this.jobQueue.end();
|
|
1175
|
+
await this.db.close();
|
|
1103
1176
|
}
|
|
1104
1177
|
}
|