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