@aztec/pxe 0.0.1-commit.e3c1de76 → 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 +4 -2
- package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
- package/dest/block_synchronizer/block_synchronizer.js +13 -1
- 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 -29
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +201 -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 +211 -109
- package/dest/contract_function_simulator/oracle/private_execution.js +5 -3
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +53 -78
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +108 -86
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +100 -55
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +238 -121
- 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 +44 -0
- package/dest/contract_sync/contract_sync_service.d.ts.map +1 -0
- package/dest/contract_sync/contract_sync_service.js +104 -0
- package/dest/contract_sync/helpers.d.ts +28 -0
- package/dest/contract_sync/helpers.d.ts.map +1 -0
- package/dest/contract_sync/{index.js → helpers.js} +19 -13
- package/dest/debug/pxe_debug_utils.d.ts +14 -10
- package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
- package/dest/debug/pxe_debug_utils.js +16 -15
- 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 +3 -2
- package/dest/entrypoints/server/index.d.ts.map +1 -1
- package/dest/entrypoints/server/index.js +2 -1
- 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 +39 -44
- 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 +3 -3
- package/dest/oracle_version.d.ts.map +1 -1
- 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 +73 -24
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +126 -74
- 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 +6 -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 +25 -16
- package/src/block_synchronizer/block_synchronizer.ts +12 -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 +360 -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 +69 -60
- package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +98 -0
- package/src/contract_function_simulator/oracle/oracle.ts +245 -144
- package/src/contract_function_simulator/oracle/private_execution.ts +4 -4
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +134 -179
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +403 -138
- package/src/contract_logging.ts +52 -0
- package/src/contract_sync/contract_sync_service.ts +170 -0
- package/src/contract_sync/{index.ts → helpers.ts} +22 -22
- package/src/debug/pxe_debug_utils.ts +48 -18
- 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 +2 -1
- package/src/entrypoints/server/utils.ts +7 -7
- package/src/events/event_service.ts +17 -4
- package/src/logs/log_service.ts +74 -66
- 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 +229 -124
- 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 +9 -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/contract_sync/index.d.ts +0 -23
- package/dest/contract_sync/index.d.ts.map +0 -1
- 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,11 +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';
|
|
62
|
-
import {
|
|
63
|
+
import { displayDebugLogs } from './contract_logging.js';
|
|
64
|
+
import { ContractSyncService } from './contract_sync/contract_sync_service.js';
|
|
65
|
+
import { readCurrentClassId } from './contract_sync/helpers.js';
|
|
63
66
|
import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
|
|
64
67
|
import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
|
|
65
68
|
import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
|
|
66
69
|
import { JobCoordinator } from './job_coordinator/job_coordinator.js';
|
|
70
|
+
import { MessageContextService } from './messages/message_context_service.js';
|
|
67
71
|
import {
|
|
68
72
|
PrivateKernelExecutionProver,
|
|
69
73
|
type PrivateKernelExecutionProverConfig,
|
|
@@ -84,6 +88,58 @@ export type PackedPrivateEvent = InTx & {
|
|
|
84
88
|
eventSelector: EventSelector;
|
|
85
89
|
};
|
|
86
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
|
+
|
|
87
143
|
/**
|
|
88
144
|
* Private eXecution Environment (PXE) is a library used by wallets to simulate private phase of transactions and to
|
|
89
145
|
* manage private state of users.
|
|
@@ -91,6 +147,7 @@ export type PackedPrivateEvent = InTx & {
|
|
|
91
147
|
export class PXE {
|
|
92
148
|
private constructor(
|
|
93
149
|
private node: AztecNode,
|
|
150
|
+
private db: AztecAsyncKVStore,
|
|
94
151
|
private blockStateSynchronizer: BlockSynchronizer,
|
|
95
152
|
private keyStore: KeyStore,
|
|
96
153
|
private contractStore: ContractStore,
|
|
@@ -102,6 +159,8 @@ export class PXE {
|
|
|
102
159
|
private recipientTaggingStore: RecipientTaggingStore,
|
|
103
160
|
private addressStore: AddressStore,
|
|
104
161
|
private privateEventStore: PrivateEventStore,
|
|
162
|
+
private contractSyncService: ContractSyncService,
|
|
163
|
+
private messageContextService: MessageContextService,
|
|
105
164
|
private simulator: CircuitSimulator,
|
|
106
165
|
private proverEnabled: boolean,
|
|
107
166
|
private proofCreator: PrivateKernelProver,
|
|
@@ -119,15 +178,15 @@ export class PXE {
|
|
|
119
178
|
*
|
|
120
179
|
* @returns A promise that resolves PXE is ready to be used.
|
|
121
180
|
*/
|
|
122
|
-
public static async create(
|
|
123
|
-
node
|
|
124
|
-
store
|
|
125
|
-
proofCreator
|
|
126
|
-
simulator
|
|
127
|
-
protocolContractsProvider
|
|
128
|
-
config
|
|
129
|
-
loggerOrSuffix
|
|
130
|
-
) {
|
|
181
|
+
public static async create({
|
|
182
|
+
node,
|
|
183
|
+
store,
|
|
184
|
+
proofCreator,
|
|
185
|
+
simulator,
|
|
186
|
+
protocolContractsProvider,
|
|
187
|
+
config,
|
|
188
|
+
loggerOrSuffix,
|
|
189
|
+
}: PXECreateArgs) {
|
|
131
190
|
// Extract bindings from the logger, or use empty bindings if a string suffix is provided.
|
|
132
191
|
const bindings: LoggerBindings | undefined =
|
|
133
192
|
loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
|
|
@@ -137,7 +196,9 @@ export class PXE {
|
|
|
137
196
|
? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
|
|
138
197
|
: loggerOrSuffix;
|
|
139
198
|
|
|
140
|
-
const
|
|
199
|
+
const info = await node.getNodeInfo();
|
|
200
|
+
|
|
201
|
+
const proverEnabled = config.proverEnabled !== undefined ? config.proverEnabled : info.realProofs;
|
|
141
202
|
const addressStore = new AddressStore(store);
|
|
142
203
|
const privateEventStore = new PrivateEventStore(store);
|
|
143
204
|
const contractStore = new ContractStore(store);
|
|
@@ -149,6 +210,14 @@ export class PXE {
|
|
|
149
210
|
const capsuleStore = new CapsuleStore(store);
|
|
150
211
|
const keyStore = new KeyStore(store);
|
|
151
212
|
const tipsStore = new L2TipsKVStore(store, 'pxe');
|
|
213
|
+
const contractSyncService = new ContractSyncService(
|
|
214
|
+
node,
|
|
215
|
+
contractStore,
|
|
216
|
+
noteStore,
|
|
217
|
+
createLogger('pxe:contract_sync', bindings),
|
|
218
|
+
);
|
|
219
|
+
const messageContextService = new MessageContextService(node);
|
|
220
|
+
|
|
152
221
|
const synchronizer = new BlockSynchronizer(
|
|
153
222
|
node,
|
|
154
223
|
store,
|
|
@@ -156,6 +225,7 @@ export class PXE {
|
|
|
156
225
|
noteStore,
|
|
157
226
|
privateEventStore,
|
|
158
227
|
tipsStore,
|
|
228
|
+
contractSyncService,
|
|
159
229
|
config,
|
|
160
230
|
bindings,
|
|
161
231
|
);
|
|
@@ -167,14 +237,16 @@ export class PXE {
|
|
|
167
237
|
recipientTaggingStore,
|
|
168
238
|
privateEventStore,
|
|
169
239
|
noteStore,
|
|
240
|
+
contractSyncService,
|
|
170
241
|
]);
|
|
171
242
|
|
|
172
|
-
const debugUtils = new PXEDebugUtils(
|
|
243
|
+
const debugUtils = new PXEDebugUtils(contractSyncService, noteStore, synchronizer, anchorBlockStore);
|
|
173
244
|
|
|
174
245
|
const jobQueue = new SerialQueue();
|
|
175
246
|
|
|
176
247
|
const pxe = new PXE(
|
|
177
248
|
node,
|
|
249
|
+
store,
|
|
178
250
|
synchronizer,
|
|
179
251
|
keyStore,
|
|
180
252
|
contractStore,
|
|
@@ -186,6 +258,8 @@ export class PXE {
|
|
|
186
258
|
recipientTaggingStore,
|
|
187
259
|
addressStore,
|
|
188
260
|
privateEventStore,
|
|
261
|
+
contractSyncService,
|
|
262
|
+
messageContextService,
|
|
189
263
|
simulator,
|
|
190
264
|
proverEnabled,
|
|
191
265
|
proofCreator,
|
|
@@ -196,12 +270,15 @@ export class PXE {
|
|
|
196
270
|
debugUtils,
|
|
197
271
|
);
|
|
198
272
|
|
|
199
|
-
debugUtils.
|
|
273
|
+
debugUtils.setPXEHelpers(
|
|
274
|
+
pxe.#putInJobQueue.bind(pxe),
|
|
275
|
+
pxe.#getSimulatorForTx.bind(pxe),
|
|
276
|
+
pxe.#executeUtility.bind(pxe),
|
|
277
|
+
);
|
|
200
278
|
|
|
201
279
|
pxe.jobQueue.start();
|
|
202
280
|
|
|
203
281
|
await pxe.#registerProtocolContracts();
|
|
204
|
-
const info = await node.getNodeInfo();
|
|
205
282
|
log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
|
|
206
283
|
return pxe;
|
|
207
284
|
}
|
|
@@ -211,19 +288,21 @@ export class PXE {
|
|
|
211
288
|
#getSimulatorForTx(overrides?: { contracts?: ContractOverrides }) {
|
|
212
289
|
const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
|
|
213
290
|
|
|
214
|
-
return new ContractFunctionSimulator(
|
|
215
|
-
proxyContractStore,
|
|
216
|
-
this.noteStore,
|
|
217
|
-
this.keyStore,
|
|
218
|
-
this.addressStore,
|
|
219
|
-
BenchmarkedNodeFactory.create(this.node),
|
|
220
|
-
this.senderTaggingStore,
|
|
221
|
-
this.recipientTaggingStore,
|
|
222
|
-
this.senderAddressBookStore,
|
|
223
|
-
this.capsuleStore,
|
|
224
|
-
this.privateEventStore,
|
|
225
|
-
this.simulator,
|
|
226
|
-
|
|
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
|
+
});
|
|
227
306
|
}
|
|
228
307
|
|
|
229
308
|
#contextualizeError(err: Error, ...context: string[]): Error {
|
|
@@ -275,9 +354,8 @@ export class PXE {
|
|
|
275
354
|
async #registerProtocolContracts() {
|
|
276
355
|
const registered: Record<string, string> = {};
|
|
277
356
|
for (const name of protocolContractNames) {
|
|
278
|
-
const { address,
|
|
279
|
-
|
|
280
|
-
await this.contractStore.addContractArtifact(contractClass.id, artifact);
|
|
357
|
+
const { address, instance, artifact } = await this.protocolContractsProvider.getProtocolContractArtifact(name);
|
|
358
|
+
await this.contractStore.addContractArtifact(artifact);
|
|
281
359
|
await this.contractStore.addContractInstance(instance);
|
|
282
360
|
registered[name] = address.toString();
|
|
283
361
|
}
|
|
@@ -289,7 +367,7 @@ export class PXE {
|
|
|
289
367
|
async #executePrivate(
|
|
290
368
|
contractFunctionSimulator: ContractFunctionSimulator,
|
|
291
369
|
txRequest: TxExecutionRequest,
|
|
292
|
-
scopes: AztecAddress[]
|
|
370
|
+
scopes: AztecAddress[],
|
|
293
371
|
jobId: string,
|
|
294
372
|
): Promise<PrivateExecutionResult> {
|
|
295
373
|
const { origin: contractAddress, functionSelector } = txRequest;
|
|
@@ -297,27 +375,23 @@ export class PXE {
|
|
|
297
375
|
try {
|
|
298
376
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
299
377
|
|
|
300
|
-
await ensureContractSynced(
|
|
378
|
+
await this.contractSyncService.ensureContractSynced(
|
|
301
379
|
contractAddress,
|
|
302
380
|
functionSelector,
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
this.contractStore,
|
|
381
|
+
(privateSyncCall, execScopes) =>
|
|
382
|
+
this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
306
383
|
anchorBlockHeader,
|
|
384
|
+
jobId,
|
|
385
|
+
scopes,
|
|
307
386
|
);
|
|
308
387
|
|
|
309
|
-
const result = await contractFunctionSimulator.run(
|
|
310
|
-
txRequest,
|
|
388
|
+
const result = await contractFunctionSimulator.run(txRequest, {
|
|
311
389
|
contractAddress,
|
|
312
|
-
functionSelector,
|
|
313
|
-
undefined,
|
|
390
|
+
selector: functionSelector,
|
|
314
391
|
anchorBlockHeader,
|
|
315
|
-
// The sender for tags is set by contracts, typically by an account
|
|
316
|
-
// contract entrypoint
|
|
317
|
-
undefined, // senderForTags
|
|
318
392
|
scopes,
|
|
319
393
|
jobId,
|
|
320
|
-
);
|
|
394
|
+
});
|
|
321
395
|
this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
|
|
322
396
|
return result;
|
|
323
397
|
} catch (err) {
|
|
@@ -329,25 +403,32 @@ export class PXE {
|
|
|
329
403
|
}
|
|
330
404
|
|
|
331
405
|
/**
|
|
332
|
-
*
|
|
406
|
+
* Execute a utility function call on the given contract.
|
|
333
407
|
* @param contractFunctionSimulator - The simulator to use for the function call.
|
|
334
408
|
* @param call - The function call to execute.
|
|
335
409
|
* @param authWitnesses - Authentication witnesses required for the function call.
|
|
336
410
|
* @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
|
|
337
411
|
* accounts if not specified.
|
|
338
412
|
* @param jobId - The job ID for staged writes.
|
|
339
|
-
* @returns The
|
|
413
|
+
* @returns The execution result containing the outputs of the utility function.
|
|
340
414
|
*/
|
|
341
|
-
async #
|
|
415
|
+
async #executeUtility(
|
|
342
416
|
contractFunctionSimulator: ContractFunctionSimulator,
|
|
343
417
|
call: FunctionCall,
|
|
344
418
|
authWitnesses: AuthWitness[] | undefined,
|
|
345
|
-
scopes: AztecAddress[]
|
|
419
|
+
scopes: AztecAddress[],
|
|
346
420
|
jobId: string,
|
|
347
421
|
) {
|
|
348
422
|
try {
|
|
349
423
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
350
|
-
|
|
424
|
+
const { result, offchainEffects } = await contractFunctionSimulator.runUtility(
|
|
425
|
+
call,
|
|
426
|
+
authWitnesses ?? [],
|
|
427
|
+
anchorBlockHeader,
|
|
428
|
+
scopes,
|
|
429
|
+
jobId,
|
|
430
|
+
);
|
|
431
|
+
return { result, offchainEffects };
|
|
351
432
|
} catch (err) {
|
|
352
433
|
if (err instanceof SimulationError) {
|
|
353
434
|
await enrichSimulationError(err, this.contractStore, this.log);
|
|
@@ -415,6 +496,21 @@ export class PXE {
|
|
|
415
496
|
|
|
416
497
|
// Public API
|
|
417
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
|
+
*/
|
|
418
514
|
public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
|
|
419
515
|
return this.contractStore.getContractInstance(address);
|
|
420
516
|
}
|
|
@@ -474,6 +570,9 @@ export class PXE {
|
|
|
474
570
|
|
|
475
571
|
if (wasAdded) {
|
|
476
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();
|
|
477
576
|
} else {
|
|
478
577
|
this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
|
|
479
578
|
}
|
|
@@ -523,8 +622,7 @@ export class PXE {
|
|
|
523
622
|
* @param artifact - The build artifact for the contract class.
|
|
524
623
|
*/
|
|
525
624
|
public async registerContractClass(artifact: ContractArtifact): Promise<void> {
|
|
526
|
-
const
|
|
527
|
-
await this.contractStore.addContractArtifact(contractClassId, artifact);
|
|
625
|
+
const contractClassId = await this.contractStore.addContractArtifact(artifact);
|
|
528
626
|
this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
|
|
529
627
|
}
|
|
530
628
|
|
|
@@ -543,17 +641,17 @@ export class PXE {
|
|
|
543
641
|
if (artifact) {
|
|
544
642
|
// If the user provides an artifact, validate it against the expected class id and register it
|
|
545
643
|
const contractClass = await getContractClassFromArtifact(artifact);
|
|
546
|
-
|
|
547
|
-
if (!contractClassId.equals(instance.currentContractClassId)) {
|
|
644
|
+
if (!contractClass.id.equals(instance.currentContractClassId)) {
|
|
548
645
|
throw new Error(
|
|
549
|
-
`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})`,
|
|
550
647
|
);
|
|
551
648
|
}
|
|
552
649
|
const computedAddress = await computeContractAddressFromInstance(instance);
|
|
553
650
|
if (!computedAddress.equals(instance.address)) {
|
|
554
651
|
throw new Error('Added a contract in which the address does not match the contract instance.');
|
|
555
652
|
}
|
|
556
|
-
|
|
653
|
+
|
|
654
|
+
await this.contractStore.addContractArtifact(artifact, contractClass);
|
|
557
655
|
|
|
558
656
|
const publicFunctionSignatures = artifact.functions
|
|
559
657
|
.filter(fn => fn.functionType === FunctionType.PUBLIC)
|
|
@@ -602,15 +700,16 @@ export class PXE {
|
|
|
602
700
|
throw new Error('Could not update contract to a class different from the current one.');
|
|
603
701
|
}
|
|
604
702
|
|
|
605
|
-
await this.contractStore.addContractArtifact(contractClass.id, artifact);
|
|
606
|
-
|
|
607
703
|
const publicFunctionSignatures = artifact.functions
|
|
608
704
|
.filter(fn => fn.functionType === FunctionType.PUBLIC)
|
|
609
705
|
.map(fn => decodeFunctionSignature(fn.name, fn.parameters));
|
|
610
706
|
await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
|
|
611
707
|
|
|
612
708
|
currentInstance.currentContractClassId = contractClass.id;
|
|
613
|
-
await
|
|
709
|
+
await Promise.all([
|
|
710
|
+
this.contractStore.addContractArtifact(artifact, contractClass),
|
|
711
|
+
this.contractStore.addContractInstance(currentInstance),
|
|
712
|
+
]);
|
|
614
713
|
this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
|
|
615
714
|
});
|
|
616
715
|
}
|
|
@@ -628,11 +727,12 @@ export class PXE {
|
|
|
628
727
|
* (where validators prove the public portion).
|
|
629
728
|
*
|
|
630
729
|
* @param txRequest - An authenticated tx request ready for proving
|
|
730
|
+
* @param scopes - Addresses whose private state and keys are accessible during private execution.
|
|
631
731
|
* @returns A result containing the proof and public inputs of the tail circuit.
|
|
632
732
|
* @throws If contract code not found, or public simulation reverts.
|
|
633
733
|
* Also throws if simulatePublic is true and public simulation reverts.
|
|
634
734
|
*/
|
|
635
|
-
public proveTx(txRequest: TxExecutionRequest): Promise<TxProvingResult> {
|
|
735
|
+
public proveTx(txRequest: TxExecutionRequest, scopes: AztecAddress[]): Promise<TxProvingResult> {
|
|
636
736
|
let privateExecutionResult: PrivateExecutionResult;
|
|
637
737
|
// We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
|
|
638
738
|
// computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
|
|
@@ -643,7 +743,7 @@ export class PXE {
|
|
|
643
743
|
await this.blockStateSynchronizer.sync();
|
|
644
744
|
const syncTime = syncTimer.ms();
|
|
645
745
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
646
|
-
privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest,
|
|
746
|
+
privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
647
747
|
|
|
648
748
|
const {
|
|
649
749
|
publicInputs,
|
|
@@ -685,17 +785,17 @@ export class PXE {
|
|
|
685
785
|
// transaction before this one is included in a block from this PXE, and that transaction contains a log with
|
|
686
786
|
// a tag derived from the same secret, we would reuse the tag and the transactions would be linked. Hence
|
|
687
787
|
// storing the tags here prevents linkage of txs sent from the same PXE.
|
|
688
|
-
const
|
|
689
|
-
if (
|
|
788
|
+
const taggingIndexRangesUsedInTheTx = privateExecutionResult.entrypoint.taggingIndexRanges;
|
|
789
|
+
if (taggingIndexRangesUsedInTheTx.length > 0) {
|
|
690
790
|
// TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
|
|
691
791
|
const txHash = (await txProvingResult.toTx()).txHash;
|
|
692
792
|
|
|
693
|
-
await this.senderTaggingStore.storePendingIndexes(
|
|
694
|
-
this.log.debug(`Stored used
|
|
695
|
-
|
|
793
|
+
await this.senderTaggingStore.storePendingIndexes(taggingIndexRangesUsedInTheTx, txHash, jobId);
|
|
794
|
+
this.log.debug(`Stored used tagging index ranges as sender for the tx`, {
|
|
795
|
+
taggingIndexRangesUsedInTheTx,
|
|
696
796
|
});
|
|
697
797
|
} else {
|
|
698
|
-
this.log.debug(`No
|
|
798
|
+
this.log.debug(`No tagging index ranges used in the tx`);
|
|
699
799
|
}
|
|
700
800
|
|
|
701
801
|
return txProvingResult;
|
|
@@ -707,17 +807,13 @@ export class PXE {
|
|
|
707
807
|
|
|
708
808
|
/**
|
|
709
809
|
* Profiles a transaction, reporting gate counts (unless disabled) and returns an execution trace.
|
|
710
|
-
*
|
|
711
|
-
* @param txRequest - An authenticated tx request ready for simulation
|
|
712
|
-
* @param msgSender - (Optional) The message sender to use for the simulation.
|
|
713
|
-
* @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.
|
|
714
811
|
* @returns A trace of the program execution with gate counts.
|
|
715
812
|
* @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
|
|
716
813
|
*/
|
|
717
814
|
public profileTx(
|
|
718
815
|
txRequest: TxExecutionRequest,
|
|
719
|
-
profileMode
|
|
720
|
-
skipProofGeneration: boolean = true,
|
|
816
|
+
{ profileMode, skipProofGeneration = true, scopes }: ProfileTxOpts,
|
|
721
817
|
): Promise<TxProfileResult> {
|
|
722
818
|
// We disable concurrent profiles for consistency with simulateTx.
|
|
723
819
|
return this.#putInJobQueue(async jobId => {
|
|
@@ -740,12 +836,7 @@ export class PXE {
|
|
|
740
836
|
const syncTime = syncTimer.ms();
|
|
741
837
|
|
|
742
838
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
743
|
-
const privateExecutionResult = await this.#executePrivate(
|
|
744
|
-
contractFunctionSimulator,
|
|
745
|
-
txRequest,
|
|
746
|
-
undefined,
|
|
747
|
-
jobId,
|
|
748
|
-
);
|
|
839
|
+
const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
749
840
|
|
|
750
841
|
const { executionSteps, timings: { proving } = {} } = await this.#prove(
|
|
751
842
|
txRequest,
|
|
@@ -802,12 +893,7 @@ export class PXE {
|
|
|
802
893
|
* In that case, the transaction returned is only potentially ready to be sent to the network for execution.
|
|
803
894
|
*
|
|
804
895
|
*
|
|
805
|
-
* @param txRequest - An authenticated tx request ready for simulation
|
|
806
|
-
* @param simulatePublic - Whether to simulate the public part of the transaction.
|
|
807
|
-
* @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
|
|
808
|
-
* @param skipFeeEnforcement - (Optional) If false, fees are enforced.
|
|
809
|
-
* @param overrides - (Optional) State overrides for the simulation, such as msgSender, contract instances and artifacts.
|
|
810
|
-
* @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.
|
|
811
897
|
* @returns A simulated transaction result object that includes public and private return values.
|
|
812
898
|
* @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
|
|
813
899
|
* Also throws if simulatePublic is true and public simulation reverts.
|
|
@@ -816,11 +902,14 @@ export class PXE {
|
|
|
816
902
|
*/
|
|
817
903
|
public simulateTx(
|
|
818
904
|
txRequest: TxExecutionRequest,
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
905
|
+
{
|
|
906
|
+
simulatePublic,
|
|
907
|
+
skipTxValidation = false,
|
|
908
|
+
skipFeeEnforcement = false,
|
|
909
|
+
skipKernels = true,
|
|
910
|
+
overrides,
|
|
911
|
+
scopes,
|
|
912
|
+
}: SimulateTxOpts,
|
|
824
913
|
): Promise<TxSimulationResult> {
|
|
825
914
|
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
826
915
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
@@ -844,11 +933,21 @@ export class PXE {
|
|
|
844
933
|
await this.blockStateSynchronizer.sync();
|
|
845
934
|
const syncTime = syncTimer.ms();
|
|
846
935
|
|
|
936
|
+
const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
|
|
937
|
+
const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
|
|
938
|
+
|
|
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
|
+
}
|
|
847
944
|
const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
945
|
+
|
|
946
|
+
if (hasOverriddenContracts) {
|
|
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);
|
|
950
|
+
}
|
|
852
951
|
|
|
853
952
|
// Execution of private functions only; no proving, and no kernel logic.
|
|
854
953
|
const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
@@ -859,7 +958,8 @@ export class PXE {
|
|
|
859
958
|
if (skipKernels) {
|
|
860
959
|
({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
|
|
861
960
|
privateExecutionResult,
|
|
862
|
-
this.contractStore,
|
|
961
|
+
(addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
|
|
962
|
+
this.node,
|
|
863
963
|
));
|
|
864
964
|
} else {
|
|
865
965
|
// Kernel logic, plus proving of all private functions and kernels.
|
|
@@ -878,6 +978,9 @@ export class PXE {
|
|
|
878
978
|
const publicSimulationTimer = new Timer();
|
|
879
979
|
publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement);
|
|
880
980
|
publicSimulationTime = publicSimulationTimer.ms();
|
|
981
|
+
if (publicOutput?.debugLogs?.length) {
|
|
982
|
+
await displayDebugLogs(publicOutput.debugLogs, addr => this.contractStore.getDebugContractName(addr));
|
|
983
|
+
}
|
|
881
984
|
}
|
|
882
985
|
|
|
883
986
|
let validationTime: number | undefined;
|
|
@@ -886,7 +989,8 @@ export class PXE {
|
|
|
886
989
|
const validationResult = await this.node.isValidTx(simulatedTx, { isSimulation: true, skipFeeEnforcement });
|
|
887
990
|
validationTime = validationTimer.ms();
|
|
888
991
|
if (validationResult.result === 'invalid') {
|
|
889
|
-
|
|
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}`);
|
|
890
994
|
}
|
|
891
995
|
}
|
|
892
996
|
|
|
@@ -937,29 +1041,23 @@ export class PXE {
|
|
|
937
1041
|
inspect(txRequest),
|
|
938
1042
|
`simulatePublic=${simulatePublic}`,
|
|
939
1043
|
`skipTxValidation=${skipTxValidation}`,
|
|
940
|
-
`scopes=${scopes
|
|
1044
|
+
`scopes=${scopes.map(s => s.toString()).join(', ')}`,
|
|
941
1045
|
);
|
|
942
1046
|
}
|
|
943
1047
|
});
|
|
944
1048
|
}
|
|
945
1049
|
|
|
946
1050
|
/**
|
|
947
|
-
*
|
|
948
|
-
*
|
|
1051
|
+
* Executes a contract utility function.
|
|
949
1052
|
* @param call - The function call containing the function details, arguments, and target contract address.
|
|
950
|
-
* @param authwits - (Optional) The authentication witnesses required for the function call.
|
|
951
|
-
* @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will
|
|
952
|
-
* default to all.
|
|
953
|
-
* @returns The result of the utility function call, structured based on the function ABI.
|
|
954
1053
|
*/
|
|
955
|
-
public
|
|
1054
|
+
public executeUtility(
|
|
956
1055
|
call: FunctionCall,
|
|
957
|
-
authwits
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
// 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.
|
|
961
1059
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
962
|
-
// 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).
|
|
963
1061
|
return this.#putInJobQueue(async jobId => {
|
|
964
1062
|
try {
|
|
965
1063
|
const totalTimer = new Timer();
|
|
@@ -970,16 +1068,17 @@ export class PXE {
|
|
|
970
1068
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
971
1069
|
|
|
972
1070
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
973
|
-
await ensureContractSynced(
|
|
1071
|
+
await this.contractSyncService.ensureContractSynced(
|
|
974
1072
|
call.to,
|
|
975
1073
|
call.selector,
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
this.contractStore,
|
|
1074
|
+
(privateSyncCall, execScopes) =>
|
|
1075
|
+
this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
979
1076
|
anchorBlockHeader,
|
|
1077
|
+
jobId,
|
|
1078
|
+
scopes,
|
|
980
1079
|
);
|
|
981
1080
|
|
|
982
|
-
const executionResult = await this.#
|
|
1081
|
+
const { result: executionResult, offchainEffects } = await this.#executeUtility(
|
|
983
1082
|
contractFunctionSimulator,
|
|
984
1083
|
call,
|
|
985
1084
|
authwits ?? [],
|
|
@@ -1000,14 +1099,19 @@ export class PXE {
|
|
|
1000
1099
|
};
|
|
1001
1100
|
|
|
1002
1101
|
const simulationStats = contractFunctionSimulator.getStats();
|
|
1003
|
-
return {
|
|
1102
|
+
return {
|
|
1103
|
+
result: executionResult,
|
|
1104
|
+
offchainEffects,
|
|
1105
|
+
anchorBlockTimestamp: anchorBlockHeader.globalVariables.timestamp,
|
|
1106
|
+
stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls },
|
|
1107
|
+
};
|
|
1004
1108
|
} catch (err: any) {
|
|
1005
1109
|
const { to, name, args } = call;
|
|
1006
1110
|
const stringifiedArgs = args.map(arg => arg.toString()).join(', ');
|
|
1007
1111
|
throw this.#contextualizeError(
|
|
1008
1112
|
err,
|
|
1009
|
-
`
|
|
1010
|
-
`scopes=${scopes
|
|
1113
|
+
`executeUtility ${to}:${name}(${stringifiedArgs})`,
|
|
1114
|
+
`scopes=${scopes.map(s => s.toString()).join(', ')}`,
|
|
1011
1115
|
);
|
|
1012
1116
|
}
|
|
1013
1117
|
});
|
|
@@ -1040,14 +1144,14 @@ export class PXE {
|
|
|
1040
1144
|
|
|
1041
1145
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
1042
1146
|
|
|
1043
|
-
await ensureContractSynced(
|
|
1147
|
+
await this.contractSyncService.ensureContractSynced(
|
|
1044
1148
|
filter.contractAddress,
|
|
1045
1149
|
null,
|
|
1046
|
-
async privateSyncCall =>
|
|
1047
|
-
await this.#
|
|
1048
|
-
this.node,
|
|
1049
|
-
this.contractStore,
|
|
1150
|
+
async (privateSyncCall, execScopes) =>
|
|
1151
|
+
await this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
1050
1152
|
anchorBlockHeader,
|
|
1153
|
+
jobId,
|
|
1154
|
+
filter.scopes,
|
|
1051
1155
|
);
|
|
1052
1156
|
});
|
|
1053
1157
|
|
|
@@ -1062,9 +1166,10 @@ export class PXE {
|
|
|
1062
1166
|
}
|
|
1063
1167
|
|
|
1064
1168
|
/**
|
|
1065
|
-
* Stops the PXE's job queue.
|
|
1169
|
+
* Stops the PXE's job queue and closes the backing store.
|
|
1066
1170
|
*/
|
|
1067
|
-
public stop(): Promise<void> {
|
|
1068
|
-
|
|
1171
|
+
public async stop(): Promise<void> {
|
|
1172
|
+
await this.jobQueue.end();
|
|
1173
|
+
await this.db.close();
|
|
1069
1174
|
}
|
|
1070
1175
|
}
|