@aztec/pxe 0.0.1-commit.bf2612ae → 0.0.1-commit.c0b82b2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/access_scopes.d.ts +9 -0
- package/dest/access_scopes.d.ts.map +1 -0
- package/dest/access_scopes.js +6 -0
- package/dest/block_synchronizer/block_synchronizer.d.ts +5 -3
- package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
- package/dest/block_synchronizer/block_synchronizer.js +9 -3
- package/dest/config/package_info.js +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +54 -30
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +174 -70
- package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +5 -5
- package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -1
- package/dest/contract_function_simulator/execution_tagging_index_cache.js +3 -3
- package/dest/contract_function_simulator/noir-structs/event_validation_request.js +1 -1
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +2 -2
- 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 +1 -1
- package/dest/contract_function_simulator/oracle/interfaces.d.ts +9 -9
- package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.d.ts +5 -5
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +32 -20
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +36 -36
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +74 -29
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +48 -24
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +84 -63
- package/dest/contract_logging.d.ts +22 -0
- package/dest/contract_logging.d.ts.map +1 -0
- package/dest/contract_logging.js +23 -0
- package/dest/contract_sync/contract_sync_service.d.ts +43 -0
- package/dest/contract_sync/contract_sync_service.d.ts.map +1 -0
- package/dest/contract_sync/contract_sync_service.js +97 -0
- package/dest/contract_sync/helpers.d.ts +29 -0
- package/dest/contract_sync/helpers.d.ts.map +1 -0
- package/dest/contract_sync/{index.js → helpers.js} +13 -12
- package/dest/debug/pxe_debug_utils.d.ts +24 -10
- package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
- package/dest/debug/pxe_debug_utils.js +28 -18
- package/dest/entrypoints/client/bundle/index.d.ts +4 -1
- package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/index.js +3 -0
- package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
- package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/utils.js +21 -7
- package/dest/entrypoints/client/lazy/index.d.ts +4 -1
- package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/index.js +3 -0
- package/dest/entrypoints/client/lazy/utils.d.ts +2 -2
- package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/utils.js +22 -8
- package/dest/entrypoints/pxe_creation_options.d.ts +3 -2
- package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
- package/dest/entrypoints/server/index.d.ts +4 -2
- package/dest/entrypoints/server/index.d.ts.map +1 -1
- package/dest/entrypoints/server/index.js +3 -1
- package/dest/entrypoints/server/utils.d.ts +1 -1
- package/dest/entrypoints/server/utils.d.ts.map +1 -1
- package/dest/entrypoints/server/utils.js +28 -9
- package/dest/events/event_service.d.ts +4 -5
- package/dest/events/event_service.d.ts.map +1 -1
- package/dest/events/event_service.js +5 -6
- package/dest/job_coordinator/job_coordinator.d.ts +3 -2
- package/dest/job_coordinator/job_coordinator.d.ts.map +1 -1
- package/dest/job_coordinator/job_coordinator.js +3 -2
- package/dest/logs/log_service.d.ts +7 -5
- package/dest/logs/log_service.d.ts.map +1 -1
- package/dest/logs/log_service.js +19 -29
- package/dest/notes/note_service.d.ts +7 -7
- package/dest/notes/note_service.d.ts.map +1 -1
- package/dest/notes/note_service.js +9 -9
- package/dest/notes_filter.d.ts +25 -0
- package/dest/notes_filter.d.ts.map +1 -0
- package/dest/notes_filter.js +4 -0
- package/dest/oracle_version.d.ts +3 -3
- package/dest/oracle_version.d.ts.map +1 -1
- package/dest/oracle_version.js +2 -2
- 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 +3 -2
- package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_execution_prover.js +21 -13
- 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 +71 -24
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +104 -66
- package/dest/storage/address_store/address_store.d.ts +1 -1
- package/dest/storage/address_store/address_store.d.ts.map +1 -1
- package/dest/storage/address_store/address_store.js +12 -11
- package/dest/storage/anchor_block_store/anchor_block_store.d.ts +9 -1
- package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -1
- package/dest/storage/anchor_block_store/anchor_block_store.js +8 -1
- package/dest/storage/capsule_store/capsule_store.js +6 -8
- 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 +157 -72
- package/dest/storage/metadata.d.ts +1 -1
- package/dest/storage/metadata.js +1 -1
- package/dest/storage/note_store/note_store.d.ts +13 -3
- package/dest/storage/note_store/note_store.d.ts.map +1 -1
- package/dest/storage/note_store/note_store.js +147 -107
- package/dest/storage/private_event_store/private_event_store.d.ts +1 -1
- package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
- package/dest/storage/private_event_store/private_event_store.js +84 -61
- package/dest/storage/private_event_store/stored_private_event.js +1 -1
- 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/recipient_tagging_store.js +31 -19
- package/dest/storage/tagging_store/sender_address_book_store.d.ts +1 -1
- package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/sender_address_book_store.js +20 -14
- package/dest/storage/tagging_store/sender_tagging_store.d.ts +5 -5
- package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/sender_tagging_store.js +184 -114
- 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 +2 -2
- 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 +3 -6
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +4 -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 +14 -15
- package/package.json +25 -16
- package/src/access_scopes.ts +9 -0
- package/src/block_synchronizer/block_synchronizer.ts +21 -12
- package/src/config/package_info.ts +1 -1
- package/src/contract_function_simulator/contract_function_simulator.ts +323 -128
- package/src/contract_function_simulator/execution_tagging_index_cache.ts +5 -5
- package/src/contract_function_simulator/noir-structs/event_validation_request.ts +1 -1
- package/src/contract_function_simulator/noir-structs/note_validation_request.ts +1 -1
- package/src/contract_function_simulator/oracle/interfaces.ts +10 -10
- package/src/contract_function_simulator/oracle/oracle.ts +35 -18
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +100 -110
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +133 -64
- package/src/contract_logging.ts +39 -0
- package/src/contract_sync/contract_sync_service.ts +152 -0
- package/src/contract_sync/{index.ts → helpers.ts} +21 -21
- package/src/debug/pxe_debug_utils.ts +63 -19
- package/src/entrypoints/client/bundle/index.ts +3 -0
- package/src/entrypoints/client/bundle/utils.ts +16 -15
- package/src/entrypoints/client/lazy/index.ts +3 -0
- package/src/entrypoints/client/lazy/utils.ts +17 -15
- package/src/entrypoints/pxe_creation_options.ts +2 -1
- package/src/entrypoints/server/index.ts +3 -1
- package/src/entrypoints/server/utils.ts +22 -26
- package/src/events/event_service.ts +4 -6
- package/src/job_coordinator/job_coordinator.ts +4 -3
- package/src/logs/log_service.ts +31 -38
- package/src/notes/note_service.ts +9 -10
- package/src/notes_filter.ts +26 -0
- package/src/oracle_version.ts +2 -2
- 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 +25 -15
- package/src/private_kernel/private_kernel_oracle.ts +7 -7
- package/src/pxe.ts +197 -118
- package/src/storage/address_store/address_store.ts +15 -15
- package/src/storage/anchor_block_store/anchor_block_store.ts +8 -0
- package/src/storage/capsule_store/capsule_store.ts +8 -8
- package/src/storage/contract_store/contract_store.ts +186 -76
- package/src/storage/metadata.ts +1 -1
- package/src/storage/note_store/note_store.ts +169 -132
- package/src/storage/private_event_store/private_event_store.ts +102 -81
- package/src/storage/private_event_store/stored_private_event.ts +1 -1
- package/src/storage/tagging_store/recipient_tagging_store.ts +38 -24
- package/src/storage/tagging_store/sender_address_book_store.ts +20 -14
- package/src/storage/tagging_store/sender_tagging_store.ts +214 -130
- package/src/tagging/get_all_logs_by_tags.ts +28 -4
- package/src/tagging/index.ts +1 -1
- 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 +4 -9
- package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +11 -20
- 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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { PrivateEventFilter } from '@aztec/aztec.js/wallet';
|
|
2
2
|
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
3
3
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
|
-
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
4
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
5
5
|
import { SerialQueue } from '@aztec/foundation/queue';
|
|
6
6
|
import { Timer } from '@aztec/foundation/timer';
|
|
7
7
|
import { KeyStore } from '@aztec/key-store';
|
|
@@ -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,11 +47,12 @@ 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';
|
|
53
54
|
|
|
55
|
+
import type { AccessScopes } from './access_scopes.js';
|
|
54
56
|
import { BlockSynchronizer } from './block_synchronizer/index.js';
|
|
55
57
|
import type { PXEConfig } from './config/index.js';
|
|
56
58
|
import { BenchmarkedNodeFactory } from './contract_function_simulator/benchmarked_node.js';
|
|
@@ -59,7 +61,9 @@ import {
|
|
|
59
61
|
generateSimulatedProvingResult,
|
|
60
62
|
} from './contract_function_simulator/contract_function_simulator.js';
|
|
61
63
|
import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
|
|
62
|
-
import {
|
|
64
|
+
import { displayDebugLogs } from './contract_logging.js';
|
|
65
|
+
import { ContractSyncService } from './contract_sync/contract_sync_service.js';
|
|
66
|
+
import { readCurrentClassId } from './contract_sync/helpers.js';
|
|
63
67
|
import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
|
|
64
68
|
import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
|
|
65
69
|
import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
|
|
@@ -84,6 +88,56 @@ 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: AccessScopes;
|
|
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
|
+
/** State overrides for the simulation, such as contract instances and artifacts. */
|
|
110
|
+
overrides?: SimulationOverrides;
|
|
111
|
+
/** Addresses whose private state and keys are accessible during private execution */
|
|
112
|
+
scopes: AccessScopes;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
/** Options for PXE.executeUtility. */
|
|
116
|
+
export type ExecuteUtilityOpts = {
|
|
117
|
+
/** The authentication witnesses required for the function call. */
|
|
118
|
+
authwits?: AuthWitness[];
|
|
119
|
+
/** The accounts whose notes we can access in this call */
|
|
120
|
+
scopes: AccessScopes;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
/** Args for PXE.create. */
|
|
124
|
+
export type PXECreateArgs = {
|
|
125
|
+
/** The Aztec node to connect to. */
|
|
126
|
+
node: AztecNode;
|
|
127
|
+
/** The key-value store for persisting PXE state. */
|
|
128
|
+
store: AztecAsyncKVStore;
|
|
129
|
+
/** The prover for generating private kernel proofs. */
|
|
130
|
+
proofCreator: PrivateKernelProver;
|
|
131
|
+
/** The circuit simulator for executing ACIR circuits. */
|
|
132
|
+
simulator: CircuitSimulator;
|
|
133
|
+
/** Provider for protocol contract artifacts and instances. */
|
|
134
|
+
protocolContractsProvider: ProtocolContractsProvider;
|
|
135
|
+
/** PXE configuration options. */
|
|
136
|
+
config: PXEConfig;
|
|
137
|
+
/** Optional logger instance or string suffix for the logger name. */
|
|
138
|
+
loggerOrSuffix?: string | Logger;
|
|
139
|
+
};
|
|
140
|
+
|
|
87
141
|
/**
|
|
88
142
|
* Private eXecution Environment (PXE) is a library used by wallets to simulate private phase of transactions and to
|
|
89
143
|
* manage private state of users.
|
|
@@ -91,6 +145,7 @@ export type PackedPrivateEvent = InTx & {
|
|
|
91
145
|
export class PXE {
|
|
92
146
|
private constructor(
|
|
93
147
|
private node: AztecNode,
|
|
148
|
+
private db: AztecAsyncKVStore,
|
|
94
149
|
private blockStateSynchronizer: BlockSynchronizer,
|
|
95
150
|
private keyStore: KeyStore,
|
|
96
151
|
private contractStore: ContractStore,
|
|
@@ -102,6 +157,7 @@ export class PXE {
|
|
|
102
157
|
private recipientTaggingStore: RecipientTaggingStore,
|
|
103
158
|
private addressStore: AddressStore,
|
|
104
159
|
private privateEventStore: PrivateEventStore,
|
|
160
|
+
private contractSyncService: ContractSyncService,
|
|
105
161
|
private simulator: CircuitSimulator,
|
|
106
162
|
private proverEnabled: boolean,
|
|
107
163
|
private proofCreator: PrivateKernelProver,
|
|
@@ -119,21 +175,27 @@ export class PXE {
|
|
|
119
175
|
*
|
|
120
176
|
* @returns A promise that resolves PXE is ready to be used.
|
|
121
177
|
*/
|
|
122
|
-
public static async create(
|
|
123
|
-
node
|
|
124
|
-
store
|
|
125
|
-
proofCreator
|
|
126
|
-
simulator
|
|
127
|
-
protocolContractsProvider
|
|
128
|
-
config
|
|
129
|
-
loggerOrSuffix
|
|
130
|
-
) {
|
|
178
|
+
public static async create({
|
|
179
|
+
node,
|
|
180
|
+
store,
|
|
181
|
+
proofCreator,
|
|
182
|
+
simulator,
|
|
183
|
+
protocolContractsProvider,
|
|
184
|
+
config,
|
|
185
|
+
loggerOrSuffix,
|
|
186
|
+
}: PXECreateArgs) {
|
|
187
|
+
// Extract bindings from the logger, or use empty bindings if a string suffix is provided.
|
|
188
|
+
const bindings: LoggerBindings | undefined =
|
|
189
|
+
loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
|
|
190
|
+
|
|
131
191
|
const log =
|
|
132
192
|
!loggerOrSuffix || typeof loggerOrSuffix === 'string'
|
|
133
193
|
? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
|
|
134
194
|
: loggerOrSuffix;
|
|
135
195
|
|
|
136
|
-
const
|
|
196
|
+
const info = await node.getNodeInfo();
|
|
197
|
+
|
|
198
|
+
const proverEnabled = config.proverEnabled !== undefined ? config.proverEnabled : info.realProofs;
|
|
137
199
|
const addressStore = new AddressStore(store);
|
|
138
200
|
const privateEventStore = new PrivateEventStore(store);
|
|
139
201
|
const contractStore = new ContractStore(store);
|
|
@@ -145,6 +207,12 @@ export class PXE {
|
|
|
145
207
|
const capsuleStore = new CapsuleStore(store);
|
|
146
208
|
const keyStore = new KeyStore(store);
|
|
147
209
|
const tipsStore = new L2TipsKVStore(store, 'pxe');
|
|
210
|
+
const contractSyncService = new ContractSyncService(
|
|
211
|
+
node,
|
|
212
|
+
contractStore,
|
|
213
|
+
noteStore,
|
|
214
|
+
createLogger('pxe:contract_sync', bindings),
|
|
215
|
+
);
|
|
148
216
|
const synchronizer = new BlockSynchronizer(
|
|
149
217
|
node,
|
|
150
218
|
store,
|
|
@@ -152,25 +220,28 @@ export class PXE {
|
|
|
152
220
|
noteStore,
|
|
153
221
|
privateEventStore,
|
|
154
222
|
tipsStore,
|
|
223
|
+
contractSyncService,
|
|
155
224
|
config,
|
|
156
|
-
|
|
225
|
+
bindings,
|
|
157
226
|
);
|
|
158
227
|
|
|
159
|
-
const jobCoordinator = new JobCoordinator(store);
|
|
228
|
+
const jobCoordinator = new JobCoordinator(store, bindings);
|
|
160
229
|
jobCoordinator.registerStores([
|
|
161
230
|
capsuleStore,
|
|
162
231
|
senderTaggingStore,
|
|
163
232
|
recipientTaggingStore,
|
|
164
233
|
privateEventStore,
|
|
165
234
|
noteStore,
|
|
235
|
+
contractSyncService,
|
|
166
236
|
]);
|
|
167
237
|
|
|
168
|
-
const debugUtils = new PXEDebugUtils(
|
|
238
|
+
const debugUtils = new PXEDebugUtils(contractSyncService, noteStore, synchronizer, anchorBlockStore);
|
|
169
239
|
|
|
170
240
|
const jobQueue = new SerialQueue();
|
|
171
241
|
|
|
172
242
|
const pxe = new PXE(
|
|
173
243
|
node,
|
|
244
|
+
store,
|
|
174
245
|
synchronizer,
|
|
175
246
|
keyStore,
|
|
176
247
|
contractStore,
|
|
@@ -182,6 +253,7 @@ export class PXE {
|
|
|
182
253
|
recipientTaggingStore,
|
|
183
254
|
addressStore,
|
|
184
255
|
privateEventStore,
|
|
256
|
+
contractSyncService,
|
|
185
257
|
simulator,
|
|
186
258
|
proverEnabled,
|
|
187
259
|
proofCreator,
|
|
@@ -192,12 +264,15 @@ export class PXE {
|
|
|
192
264
|
debugUtils,
|
|
193
265
|
);
|
|
194
266
|
|
|
195
|
-
debugUtils.
|
|
267
|
+
debugUtils.setPXEHelpers(
|
|
268
|
+
pxe.#putInJobQueue.bind(pxe),
|
|
269
|
+
pxe.#getSimulatorForTx.bind(pxe),
|
|
270
|
+
pxe.#executeUtility.bind(pxe),
|
|
271
|
+
);
|
|
196
272
|
|
|
197
273
|
pxe.jobQueue.start();
|
|
198
274
|
|
|
199
275
|
await pxe.#registerProtocolContracts();
|
|
200
|
-
const info = await node.getNodeInfo();
|
|
201
276
|
log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
|
|
202
277
|
return pxe;
|
|
203
278
|
}
|
|
@@ -207,20 +282,20 @@ export class PXE {
|
|
|
207
282
|
#getSimulatorForTx(overrides?: { contracts?: ContractOverrides }) {
|
|
208
283
|
const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
|
|
209
284
|
|
|
210
|
-
return new ContractFunctionSimulator(
|
|
211
|
-
proxyContractStore,
|
|
212
|
-
this.noteStore,
|
|
213
|
-
this.keyStore,
|
|
214
|
-
this.addressStore,
|
|
215
|
-
BenchmarkedNodeFactory.create(this.node),
|
|
216
|
-
this.
|
|
217
|
-
this.
|
|
218
|
-
this.
|
|
219
|
-
this.
|
|
220
|
-
this.
|
|
221
|
-
this.
|
|
222
|
-
this.
|
|
223
|
-
);
|
|
285
|
+
return new ContractFunctionSimulator({
|
|
286
|
+
contractStore: proxyContractStore,
|
|
287
|
+
noteStore: this.noteStore,
|
|
288
|
+
keyStore: this.keyStore,
|
|
289
|
+
addressStore: this.addressStore,
|
|
290
|
+
aztecNode: BenchmarkedNodeFactory.create(this.node),
|
|
291
|
+
senderTaggingStore: this.senderTaggingStore,
|
|
292
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
293
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
294
|
+
capsuleStore: this.capsuleStore,
|
|
295
|
+
privateEventStore: this.privateEventStore,
|
|
296
|
+
simulator: this.simulator,
|
|
297
|
+
contractSyncService: this.contractSyncService,
|
|
298
|
+
});
|
|
224
299
|
}
|
|
225
300
|
|
|
226
301
|
#contextualizeError(err: Error, ...context: string[]): Error {
|
|
@@ -272,9 +347,8 @@ export class PXE {
|
|
|
272
347
|
async #registerProtocolContracts() {
|
|
273
348
|
const registered: Record<string, string> = {};
|
|
274
349
|
for (const name of protocolContractNames) {
|
|
275
|
-
const { address,
|
|
276
|
-
|
|
277
|
-
await this.contractStore.addContractArtifact(contractClass.id, artifact);
|
|
350
|
+
const { address, instance, artifact } = await this.protocolContractsProvider.getProtocolContractArtifact(name);
|
|
351
|
+
await this.contractStore.addContractArtifact(artifact);
|
|
278
352
|
await this.contractStore.addContractInstance(instance);
|
|
279
353
|
registered[name] = address.toString();
|
|
280
354
|
}
|
|
@@ -286,7 +360,7 @@ export class PXE {
|
|
|
286
360
|
async #executePrivate(
|
|
287
361
|
contractFunctionSimulator: ContractFunctionSimulator,
|
|
288
362
|
txRequest: TxExecutionRequest,
|
|
289
|
-
scopes:
|
|
363
|
+
scopes: AccessScopes,
|
|
290
364
|
jobId: string,
|
|
291
365
|
): Promise<PrivateExecutionResult> {
|
|
292
366
|
const { origin: contractAddress, functionSelector } = txRequest;
|
|
@@ -294,27 +368,23 @@ export class PXE {
|
|
|
294
368
|
try {
|
|
295
369
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
296
370
|
|
|
297
|
-
await ensureContractSynced(
|
|
371
|
+
await this.contractSyncService.ensureContractSynced(
|
|
298
372
|
contractAddress,
|
|
299
373
|
functionSelector,
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
this.contractStore,
|
|
374
|
+
(privateSyncCall, execScopes) =>
|
|
375
|
+
this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
303
376
|
anchorBlockHeader,
|
|
377
|
+
jobId,
|
|
378
|
+
scopes,
|
|
304
379
|
);
|
|
305
380
|
|
|
306
|
-
const result = await contractFunctionSimulator.run(
|
|
307
|
-
txRequest,
|
|
381
|
+
const result = await contractFunctionSimulator.run(txRequest, {
|
|
308
382
|
contractAddress,
|
|
309
|
-
functionSelector,
|
|
310
|
-
undefined,
|
|
383
|
+
selector: functionSelector,
|
|
311
384
|
anchorBlockHeader,
|
|
312
|
-
// The sender for tags is set by contracts, typically by an account
|
|
313
|
-
// contract entrypoint
|
|
314
|
-
undefined, // senderForTags
|
|
315
385
|
scopes,
|
|
316
386
|
jobId,
|
|
317
|
-
);
|
|
387
|
+
});
|
|
318
388
|
this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
|
|
319
389
|
return result;
|
|
320
390
|
} catch (err) {
|
|
@@ -326,20 +396,20 @@ export class PXE {
|
|
|
326
396
|
}
|
|
327
397
|
|
|
328
398
|
/**
|
|
329
|
-
*
|
|
399
|
+
* Execute a utility function call on the given contract.
|
|
330
400
|
* @param contractFunctionSimulator - The simulator to use for the function call.
|
|
331
401
|
* @param call - The function call to execute.
|
|
332
402
|
* @param authWitnesses - Authentication witnesses required for the function call.
|
|
333
403
|
* @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
|
|
334
404
|
* accounts if not specified.
|
|
335
405
|
* @param jobId - The job ID for staged writes.
|
|
336
|
-
* @returns The
|
|
406
|
+
* @returns The execution result containing the outputs of the utility function.
|
|
337
407
|
*/
|
|
338
|
-
async #
|
|
408
|
+
async #executeUtility(
|
|
339
409
|
contractFunctionSimulator: ContractFunctionSimulator,
|
|
340
410
|
call: FunctionCall,
|
|
341
411
|
authWitnesses: AuthWitness[] | undefined,
|
|
342
|
-
scopes:
|
|
412
|
+
scopes: AccessScopes,
|
|
343
413
|
jobId: string,
|
|
344
414
|
) {
|
|
345
415
|
try {
|
|
@@ -400,13 +470,31 @@ export class PXE {
|
|
|
400
470
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
401
471
|
const anchorBlockHash = await anchorBlockHeader.hash();
|
|
402
472
|
const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHash);
|
|
403
|
-
const kernelTraceProver = new PrivateKernelExecutionProver(
|
|
473
|
+
const kernelTraceProver = new PrivateKernelExecutionProver(
|
|
474
|
+
kernelOracle,
|
|
475
|
+
proofCreator,
|
|
476
|
+
!this.proverEnabled,
|
|
477
|
+
this.log.getBindings(),
|
|
478
|
+
);
|
|
404
479
|
this.log.debug(`Executing kernel trace prover (${JSON.stringify(config)})...`);
|
|
405
480
|
return await kernelTraceProver.proveWithKernels(txExecutionRequest.toTxRequest(), privateExecutionResult, config);
|
|
406
481
|
}
|
|
407
482
|
|
|
408
483
|
// Public API
|
|
409
484
|
|
|
485
|
+
/**
|
|
486
|
+
* Returns the block header up to which the PXE has synced.
|
|
487
|
+
* @returns The synced block header
|
|
488
|
+
*/
|
|
489
|
+
public getSyncedBlockHeader(): Promise<BlockHeader> {
|
|
490
|
+
return this.anchorBlockStore.getBlockHeader();
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* Returns the contract instance for a given address, if it's registered in the PXE.
|
|
495
|
+
* @param address - The contract address.
|
|
496
|
+
* @returns The contract instance if found, undefined otherwise.
|
|
497
|
+
*/
|
|
410
498
|
public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
|
|
411
499
|
return this.contractStore.getContractInstance(address);
|
|
412
500
|
}
|
|
@@ -515,8 +603,7 @@ export class PXE {
|
|
|
515
603
|
* @param artifact - The build artifact for the contract class.
|
|
516
604
|
*/
|
|
517
605
|
public async registerContractClass(artifact: ContractArtifact): Promise<void> {
|
|
518
|
-
const
|
|
519
|
-
await this.contractStore.addContractArtifact(contractClassId, artifact);
|
|
606
|
+
const contractClassId = await this.contractStore.addContractArtifact(artifact);
|
|
520
607
|
this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
|
|
521
608
|
}
|
|
522
609
|
|
|
@@ -535,17 +622,17 @@ export class PXE {
|
|
|
535
622
|
if (artifact) {
|
|
536
623
|
// If the user provides an artifact, validate it against the expected class id and register it
|
|
537
624
|
const contractClass = await getContractClassFromArtifact(artifact);
|
|
538
|
-
|
|
539
|
-
if (!contractClassId.equals(instance.currentContractClassId)) {
|
|
625
|
+
if (!contractClass.id.equals(instance.currentContractClassId)) {
|
|
540
626
|
throw new Error(
|
|
541
|
-
`Artifact does not match expected class id (computed ${
|
|
627
|
+
`Artifact does not match expected class id (computed ${contractClass.id} but instance refers to ${instance.currentContractClassId})`,
|
|
542
628
|
);
|
|
543
629
|
}
|
|
544
630
|
const computedAddress = await computeContractAddressFromInstance(instance);
|
|
545
631
|
if (!computedAddress.equals(instance.address)) {
|
|
546
632
|
throw new Error('Added a contract in which the address does not match the contract instance.');
|
|
547
633
|
}
|
|
548
|
-
|
|
634
|
+
|
|
635
|
+
await this.contractStore.addContractArtifact(artifact, contractClass);
|
|
549
636
|
|
|
550
637
|
const publicFunctionSignatures = artifact.functions
|
|
551
638
|
.filter(fn => fn.functionType === FunctionType.PUBLIC)
|
|
@@ -594,15 +681,16 @@ export class PXE {
|
|
|
594
681
|
throw new Error('Could not update contract to a class different from the current one.');
|
|
595
682
|
}
|
|
596
683
|
|
|
597
|
-
await this.contractStore.addContractArtifact(contractClass.id, artifact);
|
|
598
|
-
|
|
599
684
|
const publicFunctionSignatures = artifact.functions
|
|
600
685
|
.filter(fn => fn.functionType === FunctionType.PUBLIC)
|
|
601
686
|
.map(fn => decodeFunctionSignature(fn.name, fn.parameters));
|
|
602
687
|
await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
|
|
603
688
|
|
|
604
689
|
currentInstance.currentContractClassId = contractClass.id;
|
|
605
|
-
await
|
|
690
|
+
await Promise.all([
|
|
691
|
+
this.contractStore.addContractArtifact(artifact, contractClass),
|
|
692
|
+
this.contractStore.addContractInstance(currentInstance),
|
|
693
|
+
]);
|
|
606
694
|
this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
|
|
607
695
|
});
|
|
608
696
|
}
|
|
@@ -620,11 +708,12 @@ export class PXE {
|
|
|
620
708
|
* (where validators prove the public portion).
|
|
621
709
|
*
|
|
622
710
|
* @param txRequest - An authenticated tx request ready for proving
|
|
711
|
+
* @param scopes - Addresses whose private state and keys are accessible during private execution.
|
|
623
712
|
* @returns A result containing the proof and public inputs of the tail circuit.
|
|
624
713
|
* @throws If contract code not found, or public simulation reverts.
|
|
625
714
|
* Also throws if simulatePublic is true and public simulation reverts.
|
|
626
715
|
*/
|
|
627
|
-
public proveTx(txRequest: TxExecutionRequest): Promise<TxProvingResult> {
|
|
716
|
+
public proveTx(txRequest: TxExecutionRequest, scopes: AztecAddress[]): Promise<TxProvingResult> {
|
|
628
717
|
let privateExecutionResult: PrivateExecutionResult;
|
|
629
718
|
// We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
|
|
630
719
|
// computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
|
|
@@ -635,7 +724,7 @@ export class PXE {
|
|
|
635
724
|
await this.blockStateSynchronizer.sync();
|
|
636
725
|
const syncTime = syncTimer.ms();
|
|
637
726
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
638
|
-
privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest,
|
|
727
|
+
privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
639
728
|
|
|
640
729
|
const {
|
|
641
730
|
publicInputs,
|
|
@@ -699,17 +788,13 @@ export class PXE {
|
|
|
699
788
|
|
|
700
789
|
/**
|
|
701
790
|
* Profiles a transaction, reporting gate counts (unless disabled) and returns an execution trace.
|
|
702
|
-
*
|
|
703
|
-
* @param txRequest - An authenticated tx request ready for simulation
|
|
704
|
-
* @param msgSender - (Optional) The message sender to use for the simulation.
|
|
705
|
-
* @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
|
|
791
|
+
* @param txRequest - An authenticated tx request ready for simulation.
|
|
706
792
|
* @returns A trace of the program execution with gate counts.
|
|
707
793
|
* @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
|
|
708
794
|
*/
|
|
709
795
|
public profileTx(
|
|
710
796
|
txRequest: TxExecutionRequest,
|
|
711
|
-
profileMode
|
|
712
|
-
skipProofGeneration: boolean = true,
|
|
797
|
+
{ profileMode, skipProofGeneration = true, scopes }: ProfileTxOpts,
|
|
713
798
|
): Promise<TxProfileResult> {
|
|
714
799
|
// We disable concurrent profiles for consistency with simulateTx.
|
|
715
800
|
return this.#putInJobQueue(async jobId => {
|
|
@@ -732,12 +817,7 @@ export class PXE {
|
|
|
732
817
|
const syncTime = syncTimer.ms();
|
|
733
818
|
|
|
734
819
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
735
|
-
const privateExecutionResult = await this.#executePrivate(
|
|
736
|
-
contractFunctionSimulator,
|
|
737
|
-
txRequest,
|
|
738
|
-
undefined,
|
|
739
|
-
jobId,
|
|
740
|
-
);
|
|
820
|
+
const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
741
821
|
|
|
742
822
|
const { executionSteps, timings: { proving } = {} } = await this.#prove(
|
|
743
823
|
txRequest,
|
|
@@ -794,12 +874,7 @@ export class PXE {
|
|
|
794
874
|
* In that case, the transaction returned is only potentially ready to be sent to the network for execution.
|
|
795
875
|
*
|
|
796
876
|
*
|
|
797
|
-
* @param txRequest - An authenticated tx request ready for simulation
|
|
798
|
-
* @param simulatePublic - Whether to simulate the public part of the transaction.
|
|
799
|
-
* @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
|
|
800
|
-
* @param skipFeeEnforcement - (Optional) If false, fees are enforced.
|
|
801
|
-
* @param overrides - (Optional) State overrides for the simulation, such as msgSender, contract instances and artifacts.
|
|
802
|
-
* @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will default to all.
|
|
877
|
+
* @param txRequest - An authenticated tx request ready for simulation.
|
|
803
878
|
* @returns A simulated transaction result object that includes public and private return values.
|
|
804
879
|
* @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
|
|
805
880
|
* Also throws if simulatePublic is true and public simulation reverts.
|
|
@@ -808,11 +883,7 @@ export class PXE {
|
|
|
808
883
|
*/
|
|
809
884
|
public simulateTx(
|
|
810
885
|
txRequest: TxExecutionRequest,
|
|
811
|
-
simulatePublic:
|
|
812
|
-
skipTxValidation: boolean = false,
|
|
813
|
-
skipFeeEnforcement: boolean = false,
|
|
814
|
-
overrides?: SimulationOverrides,
|
|
815
|
-
scopes?: AztecAddress[],
|
|
886
|
+
{ simulatePublic, skipTxValidation = false, skipFeeEnforcement = false, overrides, scopes }: SimulateTxOpts,
|
|
816
887
|
): Promise<TxSimulationResult> {
|
|
817
888
|
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
818
889
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
@@ -840,7 +911,14 @@ export class PXE {
|
|
|
840
911
|
// Temporary: in case there are overrides, we have to skip the kernels or validations
|
|
841
912
|
// will fail. Consider handing control to the user/wallet on whether they want to run them
|
|
842
913
|
// or not.
|
|
843
|
-
const
|
|
914
|
+
const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
|
|
915
|
+
const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
|
|
916
|
+
const skipKernels = hasOverriddenContracts;
|
|
917
|
+
|
|
918
|
+
// Set overridden contracts on the sync service so it knows to skip syncing them
|
|
919
|
+
if (hasOverriddenContracts) {
|
|
920
|
+
this.contractSyncService.setOverriddenContracts(jobId, overriddenContracts);
|
|
921
|
+
}
|
|
844
922
|
|
|
845
923
|
// Execution of private functions only; no proving, and no kernel logic.
|
|
846
924
|
const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
@@ -851,7 +929,8 @@ export class PXE {
|
|
|
851
929
|
if (skipKernels) {
|
|
852
930
|
({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
|
|
853
931
|
privateExecutionResult,
|
|
854
|
-
this.contractStore,
|
|
932
|
+
(addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
|
|
933
|
+
this.node,
|
|
855
934
|
));
|
|
856
935
|
} else {
|
|
857
936
|
// Kernel logic, plus proving of all private functions and kernels.
|
|
@@ -870,6 +949,9 @@ export class PXE {
|
|
|
870
949
|
const publicSimulationTimer = new Timer();
|
|
871
950
|
publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement);
|
|
872
951
|
publicSimulationTime = publicSimulationTimer.ms();
|
|
952
|
+
if (publicOutput?.debugLogs?.length) {
|
|
953
|
+
await displayDebugLogs(publicOutput.debugLogs, addr => this.contractStore.getDebugContractName(addr));
|
|
954
|
+
}
|
|
873
955
|
}
|
|
874
956
|
|
|
875
957
|
let validationTime: number | undefined;
|
|
@@ -878,7 +960,8 @@ export class PXE {
|
|
|
878
960
|
const validationResult = await this.node.isValidTx(simulatedTx, { isSimulation: true, skipFeeEnforcement });
|
|
879
961
|
validationTime = validationTimer.ms();
|
|
880
962
|
if (validationResult.result === 'invalid') {
|
|
881
|
-
|
|
963
|
+
const reason = validationResult.reason.length > 0 ? ` Reason: ${validationResult.reason.join(', ')}` : '';
|
|
964
|
+
throw new Error(`The simulated transaction is unable to be added to state and is invalid.${reason}`);
|
|
882
965
|
}
|
|
883
966
|
}
|
|
884
967
|
|
|
@@ -929,29 +1012,23 @@ export class PXE {
|
|
|
929
1012
|
inspect(txRequest),
|
|
930
1013
|
`simulatePublic=${simulatePublic}`,
|
|
931
1014
|
`skipTxValidation=${skipTxValidation}`,
|
|
932
|
-
`scopes=${scopes
|
|
1015
|
+
`scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
|
|
933
1016
|
);
|
|
934
1017
|
}
|
|
935
1018
|
});
|
|
936
1019
|
}
|
|
937
1020
|
|
|
938
1021
|
/**
|
|
939
|
-
*
|
|
940
|
-
*
|
|
1022
|
+
* Executes a contract utility function.
|
|
941
1023
|
* @param call - The function call containing the function details, arguments, and target contract address.
|
|
942
|
-
* @param authwits - (Optional) The authentication witnesses required for the function call.
|
|
943
|
-
* @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will
|
|
944
|
-
* default to all.
|
|
945
|
-
* @returns The result of the utility function call, structured based on the function ABI.
|
|
946
1024
|
*/
|
|
947
|
-
public
|
|
1025
|
+
public executeUtility(
|
|
948
1026
|
call: FunctionCall,
|
|
949
|
-
authwits
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
1027
|
+
{ authwits, scopes }: ExecuteUtilityOpts = { scopes: 'ALL_SCOPES' },
|
|
1028
|
+
): Promise<UtilityExecutionResult> {
|
|
1029
|
+
// We disable concurrent executions since those might execute oracles which read and write to the PXE stores (e.g.
|
|
953
1030
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
954
|
-
// delete the same read value, or reading values that another
|
|
1031
|
+
// delete the same read value, or reading values that another execution is currently modifying).
|
|
955
1032
|
return this.#putInJobQueue(async jobId => {
|
|
956
1033
|
try {
|
|
957
1034
|
const totalTimer = new Timer();
|
|
@@ -962,16 +1039,17 @@ export class PXE {
|
|
|
962
1039
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
963
1040
|
|
|
964
1041
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
965
|
-
await ensureContractSynced(
|
|
1042
|
+
await this.contractSyncService.ensureContractSynced(
|
|
966
1043
|
call.to,
|
|
967
1044
|
call.selector,
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
this.contractStore,
|
|
1045
|
+
(privateSyncCall, execScopes) =>
|
|
1046
|
+
this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
971
1047
|
anchorBlockHeader,
|
|
1048
|
+
jobId,
|
|
1049
|
+
scopes,
|
|
972
1050
|
);
|
|
973
1051
|
|
|
974
|
-
const executionResult = await this.#
|
|
1052
|
+
const executionResult = await this.#executeUtility(
|
|
975
1053
|
contractFunctionSimulator,
|
|
976
1054
|
call,
|
|
977
1055
|
authwits ?? [],
|
|
@@ -998,8 +1076,8 @@ export class PXE {
|
|
|
998
1076
|
const stringifiedArgs = args.map(arg => arg.toString()).join(', ');
|
|
999
1077
|
throw this.#contextualizeError(
|
|
1000
1078
|
err,
|
|
1001
|
-
`
|
|
1002
|
-
`scopes=${scopes
|
|
1079
|
+
`executeUtility ${to}:${name}(${stringifiedArgs})`,
|
|
1080
|
+
`scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
|
|
1003
1081
|
);
|
|
1004
1082
|
}
|
|
1005
1083
|
});
|
|
@@ -1032,14 +1110,14 @@ export class PXE {
|
|
|
1032
1110
|
|
|
1033
1111
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
1034
1112
|
|
|
1035
|
-
await ensureContractSynced(
|
|
1113
|
+
await this.contractSyncService.ensureContractSynced(
|
|
1036
1114
|
filter.contractAddress,
|
|
1037
1115
|
null,
|
|
1038
|
-
async privateSyncCall =>
|
|
1039
|
-
await this.#
|
|
1040
|
-
this.node,
|
|
1041
|
-
this.contractStore,
|
|
1116
|
+
async (privateSyncCall, execScopes) =>
|
|
1117
|
+
await this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
1042
1118
|
anchorBlockHeader,
|
|
1119
|
+
jobId,
|
|
1120
|
+
filter.scopes,
|
|
1043
1121
|
);
|
|
1044
1122
|
});
|
|
1045
1123
|
|
|
@@ -1054,9 +1132,10 @@ export class PXE {
|
|
|
1054
1132
|
}
|
|
1055
1133
|
|
|
1056
1134
|
/**
|
|
1057
|
-
* Stops the PXE's job queue.
|
|
1135
|
+
* Stops the PXE's job queue and closes the backing store.
|
|
1058
1136
|
*/
|
|
1059
|
-
public stop(): Promise<void> {
|
|
1060
|
-
|
|
1137
|
+
public async stop(): Promise<void> {
|
|
1138
|
+
await this.jobQueue.end();
|
|
1139
|
+
await this.db.close();
|
|
1061
1140
|
}
|
|
1062
1141
|
}
|