@aztec/pxe 0.0.1-commit.e558bd1c → 0.0.1-commit.e588bc7e5
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 +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 +59 -30
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +200 -73
- 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 +188 -98
- package/dest/contract_function_simulator/oracle/private_execution.js +5 -3
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +53 -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 +107 -85
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +90 -51
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +220 -111
- 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 +7 -4
- package/dest/contract_sync/contract_sync_service.d.ts.map +1 -1
- package/dest/contract_sync/contract_sync_service.js +51 -29
- package/dest/contract_sync/helpers.d.ts +2 -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 -6
- package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
- package/dest/debug/pxe_debug_utils.js +4 -7
- package/dest/entrypoints/client/bundle/index.d.ts +3 -1
- package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/index.js +2 -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 +3 -1
- package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/index.js +2 -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 +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.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 +38 -41
- 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 +4 -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 +24 -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 +72 -24
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +114 -73
- package/dest/storage/capsule_store/capsule_service.d.ts +21 -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 +145 -69
- 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/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 +359 -135
- 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 +224 -140
- package/src/contract_function_simulator/oracle/private_execution.ts +4 -4
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +131 -177
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +383 -127
- package/src/contract_logging.ts +52 -0
- package/src/contract_sync/contract_sync_service.ts +86 -45
- package/src/contract_sync/helpers.ts +8 -3
- package/src/debug/pxe_debug_utils.ts +11 -14
- package/src/entrypoints/client/bundle/index.ts +2 -0
- package/src/entrypoints/client/bundle/utils.ts +9 -1
- package/src/entrypoints/client/lazy/index.ts +2 -0
- package/src/entrypoints/client/lazy/utils.ts +9 -1
- package/src/entrypoints/server/index.ts +1 -0
- package/src/entrypoints/server/utils.ts +7 -7
- package/src/events/event_service.ts +17 -4
- package/src/logs/log_service.ts +72 -64
- package/src/messages/message_context_service.ts +44 -0
- package/src/notes/note_service.ts +19 -8
- package/src/notes_filter.ts +24 -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 +202 -117
- package/src/storage/capsule_store/capsule_service.ts +90 -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 +174 -75
- package/src/storage/metadata.ts +1 -1
- package/src/storage/note_store/note_store.ts +5 -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
|
@@ -33,6 +33,7 @@ import type {
|
|
|
33
33
|
PrivateKernelTailCircuitPublicInputs,
|
|
34
34
|
} from '@aztec/stdlib/kernel';
|
|
35
35
|
import {
|
|
36
|
+
BlockHeader,
|
|
36
37
|
type ContractOverrides,
|
|
37
38
|
type InTx,
|
|
38
39
|
PrivateExecutionResult,
|
|
@@ -46,7 +47,7 @@ import {
|
|
|
46
47
|
TxProfileResult,
|
|
47
48
|
TxProvingResult,
|
|
48
49
|
TxSimulationResult,
|
|
49
|
-
|
|
50
|
+
UtilityExecutionResult,
|
|
50
51
|
} from '@aztec/stdlib/tx';
|
|
51
52
|
|
|
52
53
|
import { inspect } from 'util';
|
|
@@ -59,12 +60,14 @@ import {
|
|
|
59
60
|
generateSimulatedProvingResult,
|
|
60
61
|
} from './contract_function_simulator/contract_function_simulator.js';
|
|
61
62
|
import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
|
|
63
|
+
import { displayDebugLogs } from './contract_logging.js';
|
|
62
64
|
import { ContractSyncService } from './contract_sync/contract_sync_service.js';
|
|
63
65
|
import { readCurrentClassId } from './contract_sync/helpers.js';
|
|
64
66
|
import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
|
|
65
67
|
import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
|
|
66
68
|
import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
|
|
67
69
|
import { JobCoordinator } from './job_coordinator/job_coordinator.js';
|
|
70
|
+
import { MessageContextService } from './messages/message_context_service.js';
|
|
68
71
|
import {
|
|
69
72
|
PrivateKernelExecutionProver,
|
|
70
73
|
type PrivateKernelExecutionProverConfig,
|
|
@@ -85,6 +88,58 @@ export type PackedPrivateEvent = InTx & {
|
|
|
85
88
|
eventSelector: EventSelector;
|
|
86
89
|
};
|
|
87
90
|
|
|
91
|
+
/** Options for PXE.profileTx. */
|
|
92
|
+
export type ProfileTxOpts = {
|
|
93
|
+
/** The profiling mode to use. */
|
|
94
|
+
profileMode: 'full' | 'execution-steps' | 'gates';
|
|
95
|
+
/** If true, proof generation is skipped during profiling. Defaults to true. */
|
|
96
|
+
skipProofGeneration?: boolean;
|
|
97
|
+
/** Addresses whose private state and keys are accessible during private execution. */
|
|
98
|
+
scopes: AztecAddress[];
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
/** Options for PXE.simulateTx. */
|
|
102
|
+
export type SimulateTxOpts = {
|
|
103
|
+
/** Whether to simulate the public part of the transaction. */
|
|
104
|
+
simulatePublic: boolean;
|
|
105
|
+
/** If false, this function throws if the transaction is unable to be included in a block at the current state. */
|
|
106
|
+
skipTxValidation?: boolean;
|
|
107
|
+
/** If false, fees are enforced. */
|
|
108
|
+
skipFeeEnforcement?: boolean;
|
|
109
|
+
/** If true, kernel logic is emulated in TS for simulation */
|
|
110
|
+
skipKernels?: boolean;
|
|
111
|
+
/** State overrides for the simulation, such as contract instances and artifacts. Requires skipKernels: true */
|
|
112
|
+
overrides?: SimulationOverrides;
|
|
113
|
+
/** Addresses whose private state and keys are accessible during private execution */
|
|
114
|
+
scopes: AztecAddress[];
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
/** Options for PXE.executeUtility. */
|
|
118
|
+
export type ExecuteUtilityOpts = {
|
|
119
|
+
/** The authentication witnesses required for the function call. */
|
|
120
|
+
authwits?: AuthWitness[];
|
|
121
|
+
/** The accounts whose notes we can access in this call */
|
|
122
|
+
scopes: AztecAddress[];
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
/** Args for PXE.create. */
|
|
126
|
+
export type PXECreateArgs = {
|
|
127
|
+
/** The Aztec node to connect to. */
|
|
128
|
+
node: AztecNode;
|
|
129
|
+
/** The key-value store for persisting PXE state. */
|
|
130
|
+
store: AztecAsyncKVStore;
|
|
131
|
+
/** The prover for generating private kernel proofs. */
|
|
132
|
+
proofCreator: PrivateKernelProver;
|
|
133
|
+
/** The circuit simulator for executing ACIR circuits. */
|
|
134
|
+
simulator: CircuitSimulator;
|
|
135
|
+
/** Provider for protocol contract artifacts and instances. */
|
|
136
|
+
protocolContractsProvider: ProtocolContractsProvider;
|
|
137
|
+
/** PXE configuration options. */
|
|
138
|
+
config: PXEConfig;
|
|
139
|
+
/** Optional logger instance or string suffix for the logger name. */
|
|
140
|
+
loggerOrSuffix?: string | Logger;
|
|
141
|
+
};
|
|
142
|
+
|
|
88
143
|
/**
|
|
89
144
|
* Private eXecution Environment (PXE) is a library used by wallets to simulate private phase of transactions and to
|
|
90
145
|
* manage private state of users.
|
|
@@ -92,6 +147,7 @@ export type PackedPrivateEvent = InTx & {
|
|
|
92
147
|
export class PXE {
|
|
93
148
|
private constructor(
|
|
94
149
|
private node: AztecNode,
|
|
150
|
+
private db: AztecAsyncKVStore,
|
|
95
151
|
private blockStateSynchronizer: BlockSynchronizer,
|
|
96
152
|
private keyStore: KeyStore,
|
|
97
153
|
private contractStore: ContractStore,
|
|
@@ -104,6 +160,7 @@ export class PXE {
|
|
|
104
160
|
private addressStore: AddressStore,
|
|
105
161
|
private privateEventStore: PrivateEventStore,
|
|
106
162
|
private contractSyncService: ContractSyncService,
|
|
163
|
+
private messageContextService: MessageContextService,
|
|
107
164
|
private simulator: CircuitSimulator,
|
|
108
165
|
private proverEnabled: boolean,
|
|
109
166
|
private proofCreator: PrivateKernelProver,
|
|
@@ -121,15 +178,15 @@ export class PXE {
|
|
|
121
178
|
*
|
|
122
179
|
* @returns A promise that resolves PXE is ready to be used.
|
|
123
180
|
*/
|
|
124
|
-
public static async create(
|
|
125
|
-
node
|
|
126
|
-
store
|
|
127
|
-
proofCreator
|
|
128
|
-
simulator
|
|
129
|
-
protocolContractsProvider
|
|
130
|
-
config
|
|
131
|
-
loggerOrSuffix
|
|
132
|
-
) {
|
|
181
|
+
public static async create({
|
|
182
|
+
node,
|
|
183
|
+
store,
|
|
184
|
+
proofCreator,
|
|
185
|
+
simulator,
|
|
186
|
+
protocolContractsProvider,
|
|
187
|
+
config,
|
|
188
|
+
loggerOrSuffix,
|
|
189
|
+
}: PXECreateArgs) {
|
|
133
190
|
// Extract bindings from the logger, or use empty bindings if a string suffix is provided.
|
|
134
191
|
const bindings: LoggerBindings | undefined =
|
|
135
192
|
loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
|
|
@@ -139,7 +196,9 @@ export class PXE {
|
|
|
139
196
|
? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
|
|
140
197
|
: loggerOrSuffix;
|
|
141
198
|
|
|
142
|
-
const
|
|
199
|
+
const info = await node.getNodeInfo();
|
|
200
|
+
|
|
201
|
+
const proverEnabled = config.proverEnabled !== undefined ? config.proverEnabled : info.realProofs;
|
|
143
202
|
const addressStore = new AddressStore(store);
|
|
144
203
|
const privateEventStore = new PrivateEventStore(store);
|
|
145
204
|
const contractStore = new ContractStore(store);
|
|
@@ -157,6 +216,8 @@ export class PXE {
|
|
|
157
216
|
noteStore,
|
|
158
217
|
createLogger('pxe:contract_sync', bindings),
|
|
159
218
|
);
|
|
219
|
+
const messageContextService = new MessageContextService(node);
|
|
220
|
+
|
|
160
221
|
const synchronizer = new BlockSynchronizer(
|
|
161
222
|
node,
|
|
162
223
|
store,
|
|
@@ -185,6 +246,7 @@ export class PXE {
|
|
|
185
246
|
|
|
186
247
|
const pxe = new PXE(
|
|
187
248
|
node,
|
|
249
|
+
store,
|
|
188
250
|
synchronizer,
|
|
189
251
|
keyStore,
|
|
190
252
|
contractStore,
|
|
@@ -197,6 +259,7 @@ export class PXE {
|
|
|
197
259
|
addressStore,
|
|
198
260
|
privateEventStore,
|
|
199
261
|
contractSyncService,
|
|
262
|
+
messageContextService,
|
|
200
263
|
simulator,
|
|
201
264
|
proverEnabled,
|
|
202
265
|
proofCreator,
|
|
@@ -210,13 +273,12 @@ export class PXE {
|
|
|
210
273
|
debugUtils.setPXEHelpers(
|
|
211
274
|
pxe.#putInJobQueue.bind(pxe),
|
|
212
275
|
pxe.#getSimulatorForTx.bind(pxe),
|
|
213
|
-
pxe.#
|
|
276
|
+
pxe.#executeUtility.bind(pxe),
|
|
214
277
|
);
|
|
215
278
|
|
|
216
279
|
pxe.jobQueue.start();
|
|
217
280
|
|
|
218
281
|
await pxe.#registerProtocolContracts();
|
|
219
|
-
const info = await node.getNodeInfo();
|
|
220
282
|
log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
|
|
221
283
|
return pxe;
|
|
222
284
|
}
|
|
@@ -226,20 +288,21 @@ export class PXE {
|
|
|
226
288
|
#getSimulatorForTx(overrides?: { contracts?: ContractOverrides }) {
|
|
227
289
|
const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
|
|
228
290
|
|
|
229
|
-
return new ContractFunctionSimulator(
|
|
230
|
-
proxyContractStore,
|
|
231
|
-
this.noteStore,
|
|
232
|
-
this.keyStore,
|
|
233
|
-
this.addressStore,
|
|
234
|
-
BenchmarkedNodeFactory.create(this.node),
|
|
235
|
-
this.senderTaggingStore,
|
|
236
|
-
this.recipientTaggingStore,
|
|
237
|
-
this.senderAddressBookStore,
|
|
238
|
-
this.capsuleStore,
|
|
239
|
-
this.privateEventStore,
|
|
240
|
-
this.simulator,
|
|
241
|
-
this.contractSyncService,
|
|
242
|
-
|
|
291
|
+
return new ContractFunctionSimulator({
|
|
292
|
+
contractStore: proxyContractStore,
|
|
293
|
+
noteStore: this.noteStore,
|
|
294
|
+
keyStore: this.keyStore,
|
|
295
|
+
addressStore: this.addressStore,
|
|
296
|
+
aztecNode: BenchmarkedNodeFactory.create(this.node),
|
|
297
|
+
senderTaggingStore: this.senderTaggingStore,
|
|
298
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
299
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
300
|
+
capsuleStore: this.capsuleStore,
|
|
301
|
+
privateEventStore: this.privateEventStore,
|
|
302
|
+
simulator: this.simulator,
|
|
303
|
+
contractSyncService: this.contractSyncService,
|
|
304
|
+
messageContextService: this.messageContextService,
|
|
305
|
+
});
|
|
243
306
|
}
|
|
244
307
|
|
|
245
308
|
#contextualizeError(err: Error, ...context: string[]): Error {
|
|
@@ -291,9 +354,8 @@ export class PXE {
|
|
|
291
354
|
async #registerProtocolContracts() {
|
|
292
355
|
const registered: Record<string, string> = {};
|
|
293
356
|
for (const name of protocolContractNames) {
|
|
294
|
-
const { address,
|
|
295
|
-
|
|
296
|
-
await this.contractStore.addContractArtifact(contractClass.id, artifact);
|
|
357
|
+
const { address, instance, artifact } = await this.protocolContractsProvider.getProtocolContractArtifact(name);
|
|
358
|
+
await this.contractStore.addContractArtifact(artifact);
|
|
297
359
|
await this.contractStore.addContractInstance(instance);
|
|
298
360
|
registered[name] = address.toString();
|
|
299
361
|
}
|
|
@@ -305,7 +367,7 @@ export class PXE {
|
|
|
305
367
|
async #executePrivate(
|
|
306
368
|
contractFunctionSimulator: ContractFunctionSimulator,
|
|
307
369
|
txRequest: TxExecutionRequest,
|
|
308
|
-
scopes: AztecAddress[]
|
|
370
|
+
scopes: AztecAddress[],
|
|
309
371
|
jobId: string,
|
|
310
372
|
): Promise<PrivateExecutionResult> {
|
|
311
373
|
const { origin: contractAddress, functionSelector } = txRequest;
|
|
@@ -316,23 +378,20 @@ export class PXE {
|
|
|
316
378
|
await this.contractSyncService.ensureContractSynced(
|
|
317
379
|
contractAddress,
|
|
318
380
|
functionSelector,
|
|
319
|
-
|
|
381
|
+
(privateSyncCall, execScopes) =>
|
|
382
|
+
this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
320
383
|
anchorBlockHeader,
|
|
321
384
|
jobId,
|
|
385
|
+
scopes,
|
|
322
386
|
);
|
|
323
387
|
|
|
324
|
-
const result = await contractFunctionSimulator.run(
|
|
325
|
-
txRequest,
|
|
388
|
+
const result = await contractFunctionSimulator.run(txRequest, {
|
|
326
389
|
contractAddress,
|
|
327
|
-
functionSelector,
|
|
328
|
-
undefined,
|
|
390
|
+
selector: functionSelector,
|
|
329
391
|
anchorBlockHeader,
|
|
330
|
-
// The sender for tags is set by contracts, typically by an account
|
|
331
|
-
// contract entrypoint
|
|
332
|
-
undefined, // senderForTags
|
|
333
392
|
scopes,
|
|
334
393
|
jobId,
|
|
335
|
-
);
|
|
394
|
+
});
|
|
336
395
|
this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
|
|
337
396
|
return result;
|
|
338
397
|
} catch (err) {
|
|
@@ -344,25 +403,32 @@ export class PXE {
|
|
|
344
403
|
}
|
|
345
404
|
|
|
346
405
|
/**
|
|
347
|
-
*
|
|
406
|
+
* Execute a utility function call on the given contract.
|
|
348
407
|
* @param contractFunctionSimulator - The simulator to use for the function call.
|
|
349
408
|
* @param call - The function call to execute.
|
|
350
409
|
* @param authWitnesses - Authentication witnesses required for the function call.
|
|
351
410
|
* @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
|
|
352
411
|
* accounts if not specified.
|
|
353
412
|
* @param jobId - The job ID for staged writes.
|
|
354
|
-
* @returns The
|
|
413
|
+
* @returns The execution result containing the outputs of the utility function.
|
|
355
414
|
*/
|
|
356
|
-
async #
|
|
415
|
+
async #executeUtility(
|
|
357
416
|
contractFunctionSimulator: ContractFunctionSimulator,
|
|
358
417
|
call: FunctionCall,
|
|
359
418
|
authWitnesses: AuthWitness[] | undefined,
|
|
360
|
-
scopes: AztecAddress[]
|
|
419
|
+
scopes: AztecAddress[],
|
|
361
420
|
jobId: string,
|
|
362
421
|
) {
|
|
363
422
|
try {
|
|
364
423
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
365
|
-
|
|
424
|
+
const { result, offchainEffects } = await contractFunctionSimulator.runUtility(
|
|
425
|
+
call,
|
|
426
|
+
authWitnesses ?? [],
|
|
427
|
+
anchorBlockHeader,
|
|
428
|
+
scopes,
|
|
429
|
+
jobId,
|
|
430
|
+
);
|
|
431
|
+
return { result, offchainEffects };
|
|
366
432
|
} catch (err) {
|
|
367
433
|
if (err instanceof SimulationError) {
|
|
368
434
|
await enrichSimulationError(err, this.contractStore, this.log);
|
|
@@ -430,6 +496,21 @@ export class PXE {
|
|
|
430
496
|
|
|
431
497
|
// Public API
|
|
432
498
|
|
|
499
|
+
/**
|
|
500
|
+
* Returns the block header up to which the PXE has synced.
|
|
501
|
+
* @returns The synced block header
|
|
502
|
+
*/
|
|
503
|
+
public getSyncedBlockHeader(): Promise<BlockHeader> {
|
|
504
|
+
return this.#putInJobQueue(() => {
|
|
505
|
+
return this.anchorBlockStore.getBlockHeader();
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
/**
|
|
510
|
+
* Returns the contract instance for a given address, if it's registered in the PXE.
|
|
511
|
+
* @param address - The contract address.
|
|
512
|
+
* @returns The contract instance if found, undefined otherwise.
|
|
513
|
+
*/
|
|
433
514
|
public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
|
|
434
515
|
return this.contractStore.getContractInstance(address);
|
|
435
516
|
}
|
|
@@ -489,6 +570,9 @@ export class PXE {
|
|
|
489
570
|
|
|
490
571
|
if (wasAdded) {
|
|
491
572
|
this.log.info(`Added sender:\n ${sender.toString()}`);
|
|
573
|
+
// Wipe the entire sync cache: the new sender's tagged logs could contain notes/events for any contract, so
|
|
574
|
+
// all contracts must re-sync to discover them.
|
|
575
|
+
this.contractSyncService.wipe();
|
|
492
576
|
} else {
|
|
493
577
|
this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
|
|
494
578
|
}
|
|
@@ -538,8 +622,7 @@ export class PXE {
|
|
|
538
622
|
* @param artifact - The build artifact for the contract class.
|
|
539
623
|
*/
|
|
540
624
|
public async registerContractClass(artifact: ContractArtifact): Promise<void> {
|
|
541
|
-
const
|
|
542
|
-
await this.contractStore.addContractArtifact(contractClassId, artifact);
|
|
625
|
+
const contractClassId = await this.contractStore.addContractArtifact(artifact);
|
|
543
626
|
this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
|
|
544
627
|
}
|
|
545
628
|
|
|
@@ -558,17 +641,17 @@ export class PXE {
|
|
|
558
641
|
if (artifact) {
|
|
559
642
|
// If the user provides an artifact, validate it against the expected class id and register it
|
|
560
643
|
const contractClass = await getContractClassFromArtifact(artifact);
|
|
561
|
-
|
|
562
|
-
if (!contractClassId.equals(instance.currentContractClassId)) {
|
|
644
|
+
if (!contractClass.id.equals(instance.currentContractClassId)) {
|
|
563
645
|
throw new Error(
|
|
564
|
-
`Artifact does not match expected class id (computed ${
|
|
646
|
+
`Artifact does not match expected class id (computed ${contractClass.id} but instance refers to ${instance.currentContractClassId})`,
|
|
565
647
|
);
|
|
566
648
|
}
|
|
567
649
|
const computedAddress = await computeContractAddressFromInstance(instance);
|
|
568
650
|
if (!computedAddress.equals(instance.address)) {
|
|
569
651
|
throw new Error('Added a contract in which the address does not match the contract instance.');
|
|
570
652
|
}
|
|
571
|
-
|
|
653
|
+
|
|
654
|
+
await this.contractStore.addContractArtifact(artifact, contractClass);
|
|
572
655
|
|
|
573
656
|
const publicFunctionSignatures = artifact.functions
|
|
574
657
|
.filter(fn => fn.functionType === FunctionType.PUBLIC)
|
|
@@ -617,15 +700,16 @@ export class PXE {
|
|
|
617
700
|
throw new Error('Could not update contract to a class different from the current one.');
|
|
618
701
|
}
|
|
619
702
|
|
|
620
|
-
await this.contractStore.addContractArtifact(contractClass.id, artifact);
|
|
621
|
-
|
|
622
703
|
const publicFunctionSignatures = artifact.functions
|
|
623
704
|
.filter(fn => fn.functionType === FunctionType.PUBLIC)
|
|
624
705
|
.map(fn => decodeFunctionSignature(fn.name, fn.parameters));
|
|
625
706
|
await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
|
|
626
707
|
|
|
627
708
|
currentInstance.currentContractClassId = contractClass.id;
|
|
628
|
-
await
|
|
709
|
+
await Promise.all([
|
|
710
|
+
this.contractStore.addContractArtifact(artifact, contractClass),
|
|
711
|
+
this.contractStore.addContractInstance(currentInstance),
|
|
712
|
+
]);
|
|
629
713
|
this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
|
|
630
714
|
});
|
|
631
715
|
}
|
|
@@ -643,11 +727,12 @@ export class PXE {
|
|
|
643
727
|
* (where validators prove the public portion).
|
|
644
728
|
*
|
|
645
729
|
* @param txRequest - An authenticated tx request ready for proving
|
|
730
|
+
* @param scopes - Addresses whose private state and keys are accessible during private execution.
|
|
646
731
|
* @returns A result containing the proof and public inputs of the tail circuit.
|
|
647
732
|
* @throws If contract code not found, or public simulation reverts.
|
|
648
733
|
* Also throws if simulatePublic is true and public simulation reverts.
|
|
649
734
|
*/
|
|
650
|
-
public proveTx(txRequest: TxExecutionRequest): Promise<TxProvingResult> {
|
|
735
|
+
public proveTx(txRequest: TxExecutionRequest, scopes: AztecAddress[]): Promise<TxProvingResult> {
|
|
651
736
|
let privateExecutionResult: PrivateExecutionResult;
|
|
652
737
|
// We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
|
|
653
738
|
// computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
|
|
@@ -658,7 +743,7 @@ export class PXE {
|
|
|
658
743
|
await this.blockStateSynchronizer.sync();
|
|
659
744
|
const syncTime = syncTimer.ms();
|
|
660
745
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
661
|
-
privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest,
|
|
746
|
+
privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
662
747
|
|
|
663
748
|
const {
|
|
664
749
|
publicInputs,
|
|
@@ -700,17 +785,17 @@ export class PXE {
|
|
|
700
785
|
// transaction before this one is included in a block from this PXE, and that transaction contains a log with
|
|
701
786
|
// a tag derived from the same secret, we would reuse the tag and the transactions would be linked. Hence
|
|
702
787
|
// storing the tags here prevents linkage of txs sent from the same PXE.
|
|
703
|
-
const
|
|
704
|
-
if (
|
|
788
|
+
const taggingIndexRangesUsedInTheTx = privateExecutionResult.entrypoint.taggingIndexRanges;
|
|
789
|
+
if (taggingIndexRangesUsedInTheTx.length > 0) {
|
|
705
790
|
// TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
|
|
706
791
|
const txHash = (await txProvingResult.toTx()).txHash;
|
|
707
792
|
|
|
708
|
-
await this.senderTaggingStore.storePendingIndexes(
|
|
709
|
-
this.log.debug(`Stored used
|
|
710
|
-
|
|
793
|
+
await this.senderTaggingStore.storePendingIndexes(taggingIndexRangesUsedInTheTx, txHash, jobId);
|
|
794
|
+
this.log.debug(`Stored used tagging index ranges as sender for the tx`, {
|
|
795
|
+
taggingIndexRangesUsedInTheTx,
|
|
711
796
|
});
|
|
712
797
|
} else {
|
|
713
|
-
this.log.debug(`No
|
|
798
|
+
this.log.debug(`No tagging index ranges used in the tx`);
|
|
714
799
|
}
|
|
715
800
|
|
|
716
801
|
return txProvingResult;
|
|
@@ -722,17 +807,13 @@ export class PXE {
|
|
|
722
807
|
|
|
723
808
|
/**
|
|
724
809
|
* Profiles a transaction, reporting gate counts (unless disabled) and returns an execution trace.
|
|
725
|
-
*
|
|
726
|
-
* @param txRequest - An authenticated tx request ready for simulation
|
|
727
|
-
* @param msgSender - (Optional) The message sender to use for the simulation.
|
|
728
|
-
* @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
|
|
810
|
+
* @param txRequest - An authenticated tx request ready for simulation.
|
|
729
811
|
* @returns A trace of the program execution with gate counts.
|
|
730
812
|
* @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
|
|
731
813
|
*/
|
|
732
814
|
public profileTx(
|
|
733
815
|
txRequest: TxExecutionRequest,
|
|
734
|
-
profileMode
|
|
735
|
-
skipProofGeneration: boolean = true,
|
|
816
|
+
{ profileMode, skipProofGeneration = true, scopes }: ProfileTxOpts,
|
|
736
817
|
): Promise<TxProfileResult> {
|
|
737
818
|
// We disable concurrent profiles for consistency with simulateTx.
|
|
738
819
|
return this.#putInJobQueue(async jobId => {
|
|
@@ -755,12 +836,7 @@ export class PXE {
|
|
|
755
836
|
const syncTime = syncTimer.ms();
|
|
756
837
|
|
|
757
838
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
758
|
-
const privateExecutionResult = await this.#executePrivate(
|
|
759
|
-
contractFunctionSimulator,
|
|
760
|
-
txRequest,
|
|
761
|
-
undefined,
|
|
762
|
-
jobId,
|
|
763
|
-
);
|
|
839
|
+
const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
764
840
|
|
|
765
841
|
const { executionSteps, timings: { proving } = {} } = await this.#prove(
|
|
766
842
|
txRequest,
|
|
@@ -817,12 +893,7 @@ export class PXE {
|
|
|
817
893
|
* In that case, the transaction returned is only potentially ready to be sent to the network for execution.
|
|
818
894
|
*
|
|
819
895
|
*
|
|
820
|
-
* @param txRequest - An authenticated tx request ready for simulation
|
|
821
|
-
* @param simulatePublic - Whether to simulate the public part of the transaction.
|
|
822
|
-
* @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
|
|
823
|
-
* @param skipFeeEnforcement - (Optional) If false, fees are enforced.
|
|
824
|
-
* @param overrides - (Optional) State overrides for the simulation, such as msgSender, contract instances and artifacts.
|
|
825
|
-
* @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will default to all.
|
|
896
|
+
* @param txRequest - An authenticated tx request ready for simulation.
|
|
826
897
|
* @returns A simulated transaction result object that includes public and private return values.
|
|
827
898
|
* @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
|
|
828
899
|
* Also throws if simulatePublic is true and public simulation reverts.
|
|
@@ -831,11 +902,14 @@ export class PXE {
|
|
|
831
902
|
*/
|
|
832
903
|
public simulateTx(
|
|
833
904
|
txRequest: TxExecutionRequest,
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
905
|
+
{
|
|
906
|
+
simulatePublic,
|
|
907
|
+
skipTxValidation = false,
|
|
908
|
+
skipFeeEnforcement = false,
|
|
909
|
+
skipKernels = true,
|
|
910
|
+
overrides,
|
|
911
|
+
scopes,
|
|
912
|
+
}: SimulateTxOpts,
|
|
839
913
|
): Promise<TxSimulationResult> {
|
|
840
914
|
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
841
915
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
@@ -859,17 +933,20 @@ export class PXE {
|
|
|
859
933
|
await this.blockStateSynchronizer.sync();
|
|
860
934
|
const syncTime = syncTimer.ms();
|
|
861
935
|
|
|
862
|
-
const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
|
|
863
|
-
// Temporary: in case there are overrides, we have to skip the kernels or validations
|
|
864
|
-
// will fail. Consider handing control to the user/wallet on whether they want to run them
|
|
865
|
-
// or not.
|
|
866
936
|
const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
|
|
867
937
|
const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
|
|
868
|
-
const skipKernels = hasOverriddenContracts;
|
|
869
938
|
|
|
870
|
-
|
|
939
|
+
if (hasOverriddenContracts && !skipKernels) {
|
|
940
|
+
throw new Error(
|
|
941
|
+
'Simulating with overridden contracts is not compatible with kernel execution. Please set skipKernels to true when simulating with overridden contracts.',
|
|
942
|
+
);
|
|
943
|
+
}
|
|
944
|
+
const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
|
|
945
|
+
|
|
871
946
|
if (hasOverriddenContracts) {
|
|
872
|
-
|
|
947
|
+
// Overridden contracts don't have a sync function, so calling sync on them would fail.
|
|
948
|
+
// We exclude them so the sync service skips them entirely.
|
|
949
|
+
this.contractSyncService.setExcludedFromSync(jobId, overriddenContracts);
|
|
873
950
|
}
|
|
874
951
|
|
|
875
952
|
// Execution of private functions only; no proving, and no kernel logic.
|
|
@@ -881,7 +958,8 @@ export class PXE {
|
|
|
881
958
|
if (skipKernels) {
|
|
882
959
|
({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
|
|
883
960
|
privateExecutionResult,
|
|
884
|
-
this.contractStore,
|
|
961
|
+
(addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
|
|
962
|
+
this.node,
|
|
885
963
|
));
|
|
886
964
|
} else {
|
|
887
965
|
// Kernel logic, plus proving of all private functions and kernels.
|
|
@@ -900,6 +978,9 @@ export class PXE {
|
|
|
900
978
|
const publicSimulationTimer = new Timer();
|
|
901
979
|
publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement);
|
|
902
980
|
publicSimulationTime = publicSimulationTimer.ms();
|
|
981
|
+
if (publicOutput?.debugLogs?.length) {
|
|
982
|
+
await displayDebugLogs(publicOutput.debugLogs, addr => this.contractStore.getDebugContractName(addr));
|
|
983
|
+
}
|
|
903
984
|
}
|
|
904
985
|
|
|
905
986
|
let validationTime: number | undefined;
|
|
@@ -908,7 +989,8 @@ export class PXE {
|
|
|
908
989
|
const validationResult = await this.node.isValidTx(simulatedTx, { isSimulation: true, skipFeeEnforcement });
|
|
909
990
|
validationTime = validationTimer.ms();
|
|
910
991
|
if (validationResult.result === 'invalid') {
|
|
911
|
-
|
|
992
|
+
const reason = validationResult.reason.length > 0 ? ` Reason: ${validationResult.reason.join(', ')}` : '';
|
|
993
|
+
throw new Error(`The simulated transaction is unable to be added to state and is invalid.${reason}`);
|
|
912
994
|
}
|
|
913
995
|
}
|
|
914
996
|
|
|
@@ -959,29 +1041,23 @@ export class PXE {
|
|
|
959
1041
|
inspect(txRequest),
|
|
960
1042
|
`simulatePublic=${simulatePublic}`,
|
|
961
1043
|
`skipTxValidation=${skipTxValidation}`,
|
|
962
|
-
`scopes=${scopes
|
|
1044
|
+
`scopes=${scopes.map(s => s.toString()).join(', ')}`,
|
|
963
1045
|
);
|
|
964
1046
|
}
|
|
965
1047
|
});
|
|
966
1048
|
}
|
|
967
1049
|
|
|
968
1050
|
/**
|
|
969
|
-
*
|
|
970
|
-
*
|
|
1051
|
+
* Executes a contract utility function.
|
|
971
1052
|
* @param call - The function call containing the function details, arguments, and target contract address.
|
|
972
|
-
* @param authwits - (Optional) The authentication witnesses required for the function call.
|
|
973
|
-
* @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will
|
|
974
|
-
* default to all.
|
|
975
|
-
* @returns The result of the utility function call, structured based on the function ABI.
|
|
976
1053
|
*/
|
|
977
|
-
public
|
|
1054
|
+
public executeUtility(
|
|
978
1055
|
call: FunctionCall,
|
|
979
|
-
authwits
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
1056
|
+
{ authwits, scopes }: ExecuteUtilityOpts = { scopes: [] },
|
|
1057
|
+
): Promise<UtilityExecutionResult> {
|
|
1058
|
+
// We disable concurrent executions since those might execute oracles which read and write to the PXE stores (e.g.
|
|
983
1059
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
984
|
-
// delete the same read value, or reading values that another
|
|
1060
|
+
// delete the same read value, or reading values that another execution is currently modifying).
|
|
985
1061
|
return this.#putInJobQueue(async jobId => {
|
|
986
1062
|
try {
|
|
987
1063
|
const totalTimer = new Timer();
|
|
@@ -995,12 +1071,14 @@ export class PXE {
|
|
|
995
1071
|
await this.contractSyncService.ensureContractSynced(
|
|
996
1072
|
call.to,
|
|
997
1073
|
call.selector,
|
|
998
|
-
|
|
1074
|
+
(privateSyncCall, execScopes) =>
|
|
1075
|
+
this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
999
1076
|
anchorBlockHeader,
|
|
1000
1077
|
jobId,
|
|
1078
|
+
scopes,
|
|
1001
1079
|
);
|
|
1002
1080
|
|
|
1003
|
-
const executionResult = await this.#
|
|
1081
|
+
const { result: executionResult, offchainEffects } = await this.#executeUtility(
|
|
1004
1082
|
contractFunctionSimulator,
|
|
1005
1083
|
call,
|
|
1006
1084
|
authwits ?? [],
|
|
@@ -1021,14 +1099,19 @@ export class PXE {
|
|
|
1021
1099
|
};
|
|
1022
1100
|
|
|
1023
1101
|
const simulationStats = contractFunctionSimulator.getStats();
|
|
1024
|
-
return {
|
|
1102
|
+
return {
|
|
1103
|
+
result: executionResult,
|
|
1104
|
+
offchainEffects,
|
|
1105
|
+
anchorBlockTimestamp: anchorBlockHeader.globalVariables.timestamp,
|
|
1106
|
+
stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls },
|
|
1107
|
+
};
|
|
1025
1108
|
} catch (err: any) {
|
|
1026
1109
|
const { to, name, args } = call;
|
|
1027
1110
|
const stringifiedArgs = args.map(arg => arg.toString()).join(', ');
|
|
1028
1111
|
throw this.#contextualizeError(
|
|
1029
1112
|
err,
|
|
1030
|
-
`
|
|
1031
|
-
`scopes=${scopes
|
|
1113
|
+
`executeUtility ${to}:${name}(${stringifiedArgs})`,
|
|
1114
|
+
`scopes=${scopes.map(s => s.toString()).join(', ')}`,
|
|
1032
1115
|
);
|
|
1033
1116
|
}
|
|
1034
1117
|
});
|
|
@@ -1064,10 +1147,11 @@ export class PXE {
|
|
|
1064
1147
|
await this.contractSyncService.ensureContractSynced(
|
|
1065
1148
|
filter.contractAddress,
|
|
1066
1149
|
null,
|
|
1067
|
-
async privateSyncCall =>
|
|
1068
|
-
await this.#
|
|
1150
|
+
async (privateSyncCall, execScopes) =>
|
|
1151
|
+
await this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
1069
1152
|
anchorBlockHeader,
|
|
1070
1153
|
jobId,
|
|
1154
|
+
filter.scopes,
|
|
1071
1155
|
);
|
|
1072
1156
|
});
|
|
1073
1157
|
|
|
@@ -1082,9 +1166,10 @@ export class PXE {
|
|
|
1082
1166
|
}
|
|
1083
1167
|
|
|
1084
1168
|
/**
|
|
1085
|
-
* Stops the PXE's job queue.
|
|
1169
|
+
* Stops the PXE's job queue and closes the backing store.
|
|
1086
1170
|
*/
|
|
1087
|
-
public stop(): Promise<void> {
|
|
1088
|
-
|
|
1171
|
+
public async stop(): Promise<void> {
|
|
1172
|
+
await this.jobQueue.end();
|
|
1173
|
+
await this.db.close();
|
|
1089
1174
|
}
|
|
1090
1175
|
}
|