@aztec/pxe 0.0.1-commit.e61ad554 → 0.0.1-commit.ec5f612
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 +11 -5
- 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 +10 -10
- 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 +38 -26
- 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 +53 -29
- 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 +8 -4
- 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 +69 -23
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +98 -63
- 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.d.ts +4 -4
- package/dest/storage/private_event_store/stored_private_event.d.ts.map +1 -1
- package/dest/storage/private_event_store/stored_private_event.js +2 -2
- 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 +4 -4
- 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 +5 -6
- 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 +7 -8
- 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 +5 -9
- 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 +5 -8
- 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 +23 -19
- 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 +12 -12
- package/src/contract_function_simulator/oracle/oracle.ts +41 -24
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +100 -110
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +139 -70
- 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 +9 -9
- package/src/pxe.ts +191 -115
- 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 +3 -3
- 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 +31 -7
- package/src/tagging/index.ts +1 -1
- package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +9 -12
- package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +2 -2
- package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +12 -17
- package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +6 -11
- package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +14 -23
- 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.
|
|
@@ -102,6 +156,7 @@ export class PXE {
|
|
|
102
156
|
private recipientTaggingStore: RecipientTaggingStore,
|
|
103
157
|
private addressStore: AddressStore,
|
|
104
158
|
private privateEventStore: PrivateEventStore,
|
|
159
|
+
private contractSyncService: ContractSyncService,
|
|
105
160
|
private simulator: CircuitSimulator,
|
|
106
161
|
private proverEnabled: boolean,
|
|
107
162
|
private proofCreator: PrivateKernelProver,
|
|
@@ -119,21 +174,27 @@ export class PXE {
|
|
|
119
174
|
*
|
|
120
175
|
* @returns A promise that resolves PXE is ready to be used.
|
|
121
176
|
*/
|
|
122
|
-
public static async create(
|
|
123
|
-
node
|
|
124
|
-
store
|
|
125
|
-
proofCreator
|
|
126
|
-
simulator
|
|
127
|
-
protocolContractsProvider
|
|
128
|
-
config
|
|
129
|
-
loggerOrSuffix
|
|
130
|
-
) {
|
|
177
|
+
public static async create({
|
|
178
|
+
node,
|
|
179
|
+
store,
|
|
180
|
+
proofCreator,
|
|
181
|
+
simulator,
|
|
182
|
+
protocolContractsProvider,
|
|
183
|
+
config,
|
|
184
|
+
loggerOrSuffix,
|
|
185
|
+
}: PXECreateArgs) {
|
|
186
|
+
// Extract bindings from the logger, or use empty bindings if a string suffix is provided.
|
|
187
|
+
const bindings: LoggerBindings | undefined =
|
|
188
|
+
loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
|
|
189
|
+
|
|
131
190
|
const log =
|
|
132
191
|
!loggerOrSuffix || typeof loggerOrSuffix === 'string'
|
|
133
192
|
? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
|
|
134
193
|
: loggerOrSuffix;
|
|
135
194
|
|
|
136
|
-
const
|
|
195
|
+
const info = await node.getNodeInfo();
|
|
196
|
+
|
|
197
|
+
const proverEnabled = config.proverEnabled !== undefined ? config.proverEnabled : info.realProofs;
|
|
137
198
|
const addressStore = new AddressStore(store);
|
|
138
199
|
const privateEventStore = new PrivateEventStore(store);
|
|
139
200
|
const contractStore = new ContractStore(store);
|
|
@@ -145,6 +206,12 @@ export class PXE {
|
|
|
145
206
|
const capsuleStore = new CapsuleStore(store);
|
|
146
207
|
const keyStore = new KeyStore(store);
|
|
147
208
|
const tipsStore = new L2TipsKVStore(store, 'pxe');
|
|
209
|
+
const contractSyncService = new ContractSyncService(
|
|
210
|
+
node,
|
|
211
|
+
contractStore,
|
|
212
|
+
noteStore,
|
|
213
|
+
createLogger('pxe:contract_sync', bindings),
|
|
214
|
+
);
|
|
148
215
|
const synchronizer = new BlockSynchronizer(
|
|
149
216
|
node,
|
|
150
217
|
store,
|
|
@@ -152,20 +219,22 @@ export class PXE {
|
|
|
152
219
|
noteStore,
|
|
153
220
|
privateEventStore,
|
|
154
221
|
tipsStore,
|
|
222
|
+
contractSyncService,
|
|
155
223
|
config,
|
|
156
|
-
|
|
224
|
+
bindings,
|
|
157
225
|
);
|
|
158
226
|
|
|
159
|
-
const jobCoordinator = new JobCoordinator(store);
|
|
227
|
+
const jobCoordinator = new JobCoordinator(store, bindings);
|
|
160
228
|
jobCoordinator.registerStores([
|
|
161
229
|
capsuleStore,
|
|
162
230
|
senderTaggingStore,
|
|
163
231
|
recipientTaggingStore,
|
|
164
232
|
privateEventStore,
|
|
165
233
|
noteStore,
|
|
234
|
+
contractSyncService,
|
|
166
235
|
]);
|
|
167
236
|
|
|
168
|
-
const debugUtils = new PXEDebugUtils(
|
|
237
|
+
const debugUtils = new PXEDebugUtils(contractSyncService, noteStore, synchronizer, anchorBlockStore);
|
|
169
238
|
|
|
170
239
|
const jobQueue = new SerialQueue();
|
|
171
240
|
|
|
@@ -182,6 +251,7 @@ export class PXE {
|
|
|
182
251
|
recipientTaggingStore,
|
|
183
252
|
addressStore,
|
|
184
253
|
privateEventStore,
|
|
254
|
+
contractSyncService,
|
|
185
255
|
simulator,
|
|
186
256
|
proverEnabled,
|
|
187
257
|
proofCreator,
|
|
@@ -192,12 +262,15 @@ export class PXE {
|
|
|
192
262
|
debugUtils,
|
|
193
263
|
);
|
|
194
264
|
|
|
195
|
-
debugUtils.
|
|
265
|
+
debugUtils.setPXEHelpers(
|
|
266
|
+
pxe.#putInJobQueue.bind(pxe),
|
|
267
|
+
pxe.#getSimulatorForTx.bind(pxe),
|
|
268
|
+
pxe.#executeUtility.bind(pxe),
|
|
269
|
+
);
|
|
196
270
|
|
|
197
271
|
pxe.jobQueue.start();
|
|
198
272
|
|
|
199
273
|
await pxe.#registerProtocolContracts();
|
|
200
|
-
const info = await node.getNodeInfo();
|
|
201
274
|
log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
|
|
202
275
|
return pxe;
|
|
203
276
|
}
|
|
@@ -207,20 +280,20 @@ export class PXE {
|
|
|
207
280
|
#getSimulatorForTx(overrides?: { contracts?: ContractOverrides }) {
|
|
208
281
|
const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
|
|
209
282
|
|
|
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
|
-
);
|
|
283
|
+
return new ContractFunctionSimulator({
|
|
284
|
+
contractStore: proxyContractStore,
|
|
285
|
+
noteStore: this.noteStore,
|
|
286
|
+
keyStore: this.keyStore,
|
|
287
|
+
addressStore: this.addressStore,
|
|
288
|
+
aztecNode: BenchmarkedNodeFactory.create(this.node),
|
|
289
|
+
senderTaggingStore: this.senderTaggingStore,
|
|
290
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
291
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
292
|
+
capsuleStore: this.capsuleStore,
|
|
293
|
+
privateEventStore: this.privateEventStore,
|
|
294
|
+
simulator: this.simulator,
|
|
295
|
+
contractSyncService: this.contractSyncService,
|
|
296
|
+
});
|
|
224
297
|
}
|
|
225
298
|
|
|
226
299
|
#contextualizeError(err: Error, ...context: string[]): Error {
|
|
@@ -272,9 +345,8 @@ export class PXE {
|
|
|
272
345
|
async #registerProtocolContracts() {
|
|
273
346
|
const registered: Record<string, string> = {};
|
|
274
347
|
for (const name of protocolContractNames) {
|
|
275
|
-
const { address,
|
|
276
|
-
|
|
277
|
-
await this.contractStore.addContractArtifact(contractClass.id, artifact);
|
|
348
|
+
const { address, instance, artifact } = await this.protocolContractsProvider.getProtocolContractArtifact(name);
|
|
349
|
+
await this.contractStore.addContractArtifact(artifact);
|
|
278
350
|
await this.contractStore.addContractInstance(instance);
|
|
279
351
|
registered[name] = address.toString();
|
|
280
352
|
}
|
|
@@ -286,7 +358,7 @@ export class PXE {
|
|
|
286
358
|
async #executePrivate(
|
|
287
359
|
contractFunctionSimulator: ContractFunctionSimulator,
|
|
288
360
|
txRequest: TxExecutionRequest,
|
|
289
|
-
scopes:
|
|
361
|
+
scopes: AccessScopes,
|
|
290
362
|
jobId: string,
|
|
291
363
|
): Promise<PrivateExecutionResult> {
|
|
292
364
|
const { origin: contractAddress, functionSelector } = txRequest;
|
|
@@ -294,27 +366,23 @@ export class PXE {
|
|
|
294
366
|
try {
|
|
295
367
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
296
368
|
|
|
297
|
-
await ensureContractSynced(
|
|
369
|
+
await this.contractSyncService.ensureContractSynced(
|
|
298
370
|
contractAddress,
|
|
299
371
|
functionSelector,
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
this.contractStore,
|
|
372
|
+
(privateSyncCall, execScopes) =>
|
|
373
|
+
this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
303
374
|
anchorBlockHeader,
|
|
375
|
+
jobId,
|
|
376
|
+
scopes,
|
|
304
377
|
);
|
|
305
378
|
|
|
306
|
-
const result = await contractFunctionSimulator.run(
|
|
307
|
-
txRequest,
|
|
379
|
+
const result = await contractFunctionSimulator.run(txRequest, {
|
|
308
380
|
contractAddress,
|
|
309
|
-
functionSelector,
|
|
310
|
-
undefined,
|
|
381
|
+
selector: functionSelector,
|
|
311
382
|
anchorBlockHeader,
|
|
312
|
-
// The sender for tags is set by contracts, typically by an account
|
|
313
|
-
// contract entrypoint
|
|
314
|
-
undefined, // senderForTags
|
|
315
383
|
scopes,
|
|
316
384
|
jobId,
|
|
317
|
-
);
|
|
385
|
+
});
|
|
318
386
|
this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
|
|
319
387
|
return result;
|
|
320
388
|
} catch (err) {
|
|
@@ -326,20 +394,20 @@ export class PXE {
|
|
|
326
394
|
}
|
|
327
395
|
|
|
328
396
|
/**
|
|
329
|
-
*
|
|
397
|
+
* Execute a utility function call on the given contract.
|
|
330
398
|
* @param contractFunctionSimulator - The simulator to use for the function call.
|
|
331
399
|
* @param call - The function call to execute.
|
|
332
400
|
* @param authWitnesses - Authentication witnesses required for the function call.
|
|
333
401
|
* @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
|
|
334
402
|
* accounts if not specified.
|
|
335
403
|
* @param jobId - The job ID for staged writes.
|
|
336
|
-
* @returns The
|
|
404
|
+
* @returns The execution result containing the outputs of the utility function.
|
|
337
405
|
*/
|
|
338
|
-
async #
|
|
406
|
+
async #executeUtility(
|
|
339
407
|
contractFunctionSimulator: ContractFunctionSimulator,
|
|
340
408
|
call: FunctionCall,
|
|
341
409
|
authWitnesses: AuthWitness[] | undefined,
|
|
342
|
-
scopes:
|
|
410
|
+
scopes: AccessScopes,
|
|
343
411
|
jobId: string,
|
|
344
412
|
) {
|
|
345
413
|
try {
|
|
@@ -400,13 +468,31 @@ export class PXE {
|
|
|
400
468
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
401
469
|
const anchorBlockHash = await anchorBlockHeader.hash();
|
|
402
470
|
const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHash);
|
|
403
|
-
const kernelTraceProver = new PrivateKernelExecutionProver(
|
|
471
|
+
const kernelTraceProver = new PrivateKernelExecutionProver(
|
|
472
|
+
kernelOracle,
|
|
473
|
+
proofCreator,
|
|
474
|
+
!this.proverEnabled,
|
|
475
|
+
this.log.getBindings(),
|
|
476
|
+
);
|
|
404
477
|
this.log.debug(`Executing kernel trace prover (${JSON.stringify(config)})...`);
|
|
405
478
|
return await kernelTraceProver.proveWithKernels(txExecutionRequest.toTxRequest(), privateExecutionResult, config);
|
|
406
479
|
}
|
|
407
480
|
|
|
408
481
|
// Public API
|
|
409
482
|
|
|
483
|
+
/**
|
|
484
|
+
* Returns the block header up to which the PXE has synced.
|
|
485
|
+
* @returns The synced block header
|
|
486
|
+
*/
|
|
487
|
+
public getSyncedBlockHeader(): Promise<BlockHeader> {
|
|
488
|
+
return this.anchorBlockStore.getBlockHeader();
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
/**
|
|
492
|
+
* Returns the contract instance for a given address, if it's registered in the PXE.
|
|
493
|
+
* @param address - The contract address.
|
|
494
|
+
* @returns The contract instance if found, undefined otherwise.
|
|
495
|
+
*/
|
|
410
496
|
public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
|
|
411
497
|
return this.contractStore.getContractInstance(address);
|
|
412
498
|
}
|
|
@@ -515,8 +601,7 @@ export class PXE {
|
|
|
515
601
|
* @param artifact - The build artifact for the contract class.
|
|
516
602
|
*/
|
|
517
603
|
public async registerContractClass(artifact: ContractArtifact): Promise<void> {
|
|
518
|
-
const
|
|
519
|
-
await this.contractStore.addContractArtifact(contractClassId, artifact);
|
|
604
|
+
const contractClassId = await this.contractStore.addContractArtifact(artifact);
|
|
520
605
|
this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
|
|
521
606
|
}
|
|
522
607
|
|
|
@@ -535,17 +620,17 @@ export class PXE {
|
|
|
535
620
|
if (artifact) {
|
|
536
621
|
// If the user provides an artifact, validate it against the expected class id and register it
|
|
537
622
|
const contractClass = await getContractClassFromArtifact(artifact);
|
|
538
|
-
|
|
539
|
-
if (!contractClassId.equals(instance.currentContractClassId)) {
|
|
623
|
+
if (!contractClass.id.equals(instance.currentContractClassId)) {
|
|
540
624
|
throw new Error(
|
|
541
|
-
`Artifact does not match expected class id (computed ${
|
|
625
|
+
`Artifact does not match expected class id (computed ${contractClass.id} but instance refers to ${instance.currentContractClassId})`,
|
|
542
626
|
);
|
|
543
627
|
}
|
|
544
628
|
const computedAddress = await computeContractAddressFromInstance(instance);
|
|
545
629
|
if (!computedAddress.equals(instance.address)) {
|
|
546
630
|
throw new Error('Added a contract in which the address does not match the contract instance.');
|
|
547
631
|
}
|
|
548
|
-
|
|
632
|
+
|
|
633
|
+
await this.contractStore.addContractArtifact(artifact, contractClass);
|
|
549
634
|
|
|
550
635
|
const publicFunctionSignatures = artifact.functions
|
|
551
636
|
.filter(fn => fn.functionType === FunctionType.PUBLIC)
|
|
@@ -594,15 +679,16 @@ export class PXE {
|
|
|
594
679
|
throw new Error('Could not update contract to a class different from the current one.');
|
|
595
680
|
}
|
|
596
681
|
|
|
597
|
-
await this.contractStore.addContractArtifact(contractClass.id, artifact);
|
|
598
|
-
|
|
599
682
|
const publicFunctionSignatures = artifact.functions
|
|
600
683
|
.filter(fn => fn.functionType === FunctionType.PUBLIC)
|
|
601
684
|
.map(fn => decodeFunctionSignature(fn.name, fn.parameters));
|
|
602
685
|
await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
|
|
603
686
|
|
|
604
687
|
currentInstance.currentContractClassId = contractClass.id;
|
|
605
|
-
await
|
|
688
|
+
await Promise.all([
|
|
689
|
+
this.contractStore.addContractArtifact(artifact, contractClass),
|
|
690
|
+
this.contractStore.addContractInstance(currentInstance),
|
|
691
|
+
]);
|
|
606
692
|
this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
|
|
607
693
|
});
|
|
608
694
|
}
|
|
@@ -620,11 +706,12 @@ export class PXE {
|
|
|
620
706
|
* (where validators prove the public portion).
|
|
621
707
|
*
|
|
622
708
|
* @param txRequest - An authenticated tx request ready for proving
|
|
709
|
+
* @param scopes - Addresses whose private state and keys are accessible during private execution.
|
|
623
710
|
* @returns A result containing the proof and public inputs of the tail circuit.
|
|
624
711
|
* @throws If contract code not found, or public simulation reverts.
|
|
625
712
|
* Also throws if simulatePublic is true and public simulation reverts.
|
|
626
713
|
*/
|
|
627
|
-
public proveTx(txRequest: TxExecutionRequest): Promise<TxProvingResult> {
|
|
714
|
+
public proveTx(txRequest: TxExecutionRequest, scopes: AztecAddress[]): Promise<TxProvingResult> {
|
|
628
715
|
let privateExecutionResult: PrivateExecutionResult;
|
|
629
716
|
// We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
|
|
630
717
|
// computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
|
|
@@ -635,7 +722,7 @@ export class PXE {
|
|
|
635
722
|
await this.blockStateSynchronizer.sync();
|
|
636
723
|
const syncTime = syncTimer.ms();
|
|
637
724
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
638
|
-
privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest,
|
|
725
|
+
privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
639
726
|
|
|
640
727
|
const {
|
|
641
728
|
publicInputs,
|
|
@@ -699,17 +786,13 @@ export class PXE {
|
|
|
699
786
|
|
|
700
787
|
/**
|
|
701
788
|
* 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.
|
|
789
|
+
* @param txRequest - An authenticated tx request ready for simulation.
|
|
706
790
|
* @returns A trace of the program execution with gate counts.
|
|
707
791
|
* @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
|
|
708
792
|
*/
|
|
709
793
|
public profileTx(
|
|
710
794
|
txRequest: TxExecutionRequest,
|
|
711
|
-
profileMode
|
|
712
|
-
skipProofGeneration: boolean = true,
|
|
795
|
+
{ profileMode, skipProofGeneration = true, scopes }: ProfileTxOpts,
|
|
713
796
|
): Promise<TxProfileResult> {
|
|
714
797
|
// We disable concurrent profiles for consistency with simulateTx.
|
|
715
798
|
return this.#putInJobQueue(async jobId => {
|
|
@@ -732,12 +815,7 @@ export class PXE {
|
|
|
732
815
|
const syncTime = syncTimer.ms();
|
|
733
816
|
|
|
734
817
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
735
|
-
const privateExecutionResult = await this.#executePrivate(
|
|
736
|
-
contractFunctionSimulator,
|
|
737
|
-
txRequest,
|
|
738
|
-
undefined,
|
|
739
|
-
jobId,
|
|
740
|
-
);
|
|
818
|
+
const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
741
819
|
|
|
742
820
|
const { executionSteps, timings: { proving } = {} } = await this.#prove(
|
|
743
821
|
txRequest,
|
|
@@ -794,12 +872,7 @@ export class PXE {
|
|
|
794
872
|
* In that case, the transaction returned is only potentially ready to be sent to the network for execution.
|
|
795
873
|
*
|
|
796
874
|
*
|
|
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.
|
|
875
|
+
* @param txRequest - An authenticated tx request ready for simulation.
|
|
803
876
|
* @returns A simulated transaction result object that includes public and private return values.
|
|
804
877
|
* @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
|
|
805
878
|
* Also throws if simulatePublic is true and public simulation reverts.
|
|
@@ -808,11 +881,7 @@ export class PXE {
|
|
|
808
881
|
*/
|
|
809
882
|
public simulateTx(
|
|
810
883
|
txRequest: TxExecutionRequest,
|
|
811
|
-
simulatePublic:
|
|
812
|
-
skipTxValidation: boolean = false,
|
|
813
|
-
skipFeeEnforcement: boolean = false,
|
|
814
|
-
overrides?: SimulationOverrides,
|
|
815
|
-
scopes?: AztecAddress[],
|
|
884
|
+
{ simulatePublic, skipTxValidation = false, skipFeeEnforcement = false, overrides, scopes }: SimulateTxOpts,
|
|
816
885
|
): Promise<TxSimulationResult> {
|
|
817
886
|
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
818
887
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
@@ -840,7 +909,14 @@ export class PXE {
|
|
|
840
909
|
// Temporary: in case there are overrides, we have to skip the kernels or validations
|
|
841
910
|
// will fail. Consider handing control to the user/wallet on whether they want to run them
|
|
842
911
|
// or not.
|
|
843
|
-
const
|
|
912
|
+
const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
|
|
913
|
+
const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
|
|
914
|
+
const skipKernels = hasOverriddenContracts;
|
|
915
|
+
|
|
916
|
+
// Set overridden contracts on the sync service so it knows to skip syncing them
|
|
917
|
+
if (hasOverriddenContracts) {
|
|
918
|
+
this.contractSyncService.setOverriddenContracts(jobId, overriddenContracts);
|
|
919
|
+
}
|
|
844
920
|
|
|
845
921
|
// Execution of private functions only; no proving, and no kernel logic.
|
|
846
922
|
const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
@@ -851,7 +927,8 @@ export class PXE {
|
|
|
851
927
|
if (skipKernels) {
|
|
852
928
|
({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
|
|
853
929
|
privateExecutionResult,
|
|
854
|
-
this.contractStore,
|
|
930
|
+
(addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
|
|
931
|
+
this.node,
|
|
855
932
|
));
|
|
856
933
|
} else {
|
|
857
934
|
// Kernel logic, plus proving of all private functions and kernels.
|
|
@@ -870,6 +947,9 @@ export class PXE {
|
|
|
870
947
|
const publicSimulationTimer = new Timer();
|
|
871
948
|
publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement);
|
|
872
949
|
publicSimulationTime = publicSimulationTimer.ms();
|
|
950
|
+
if (publicOutput?.debugLogs?.length) {
|
|
951
|
+
await displayDebugLogs(publicOutput.debugLogs, addr => this.contractStore.getDebugContractName(addr));
|
|
952
|
+
}
|
|
873
953
|
}
|
|
874
954
|
|
|
875
955
|
let validationTime: number | undefined;
|
|
@@ -878,7 +958,8 @@ export class PXE {
|
|
|
878
958
|
const validationResult = await this.node.isValidTx(simulatedTx, { isSimulation: true, skipFeeEnforcement });
|
|
879
959
|
validationTime = validationTimer.ms();
|
|
880
960
|
if (validationResult.result === 'invalid') {
|
|
881
|
-
|
|
961
|
+
const reason = validationResult.reason.length > 0 ? ` Reason: ${validationResult.reason.join(', ')}` : '';
|
|
962
|
+
throw new Error(`The simulated transaction is unable to be added to state and is invalid.${reason}`);
|
|
882
963
|
}
|
|
883
964
|
}
|
|
884
965
|
|
|
@@ -929,29 +1010,23 @@ export class PXE {
|
|
|
929
1010
|
inspect(txRequest),
|
|
930
1011
|
`simulatePublic=${simulatePublic}`,
|
|
931
1012
|
`skipTxValidation=${skipTxValidation}`,
|
|
932
|
-
`scopes=${scopes
|
|
1013
|
+
`scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
|
|
933
1014
|
);
|
|
934
1015
|
}
|
|
935
1016
|
});
|
|
936
1017
|
}
|
|
937
1018
|
|
|
938
1019
|
/**
|
|
939
|
-
*
|
|
940
|
-
*
|
|
1020
|
+
* Executes a contract utility function.
|
|
941
1021
|
* @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
1022
|
*/
|
|
947
|
-
public
|
|
1023
|
+
public executeUtility(
|
|
948
1024
|
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.
|
|
1025
|
+
{ authwits, scopes }: ExecuteUtilityOpts = { scopes: 'ALL_SCOPES' },
|
|
1026
|
+
): Promise<UtilityExecutionResult> {
|
|
1027
|
+
// We disable concurrent executions since those might execute oracles which read and write to the PXE stores (e.g.
|
|
953
1028
|
// 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
|
|
1029
|
+
// delete the same read value, or reading values that another execution is currently modifying).
|
|
955
1030
|
return this.#putInJobQueue(async jobId => {
|
|
956
1031
|
try {
|
|
957
1032
|
const totalTimer = new Timer();
|
|
@@ -962,16 +1037,17 @@ export class PXE {
|
|
|
962
1037
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
963
1038
|
|
|
964
1039
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
965
|
-
await ensureContractSynced(
|
|
1040
|
+
await this.contractSyncService.ensureContractSynced(
|
|
966
1041
|
call.to,
|
|
967
1042
|
call.selector,
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
this.contractStore,
|
|
1043
|
+
(privateSyncCall, execScopes) =>
|
|
1044
|
+
this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
971
1045
|
anchorBlockHeader,
|
|
1046
|
+
jobId,
|
|
1047
|
+
scopes,
|
|
972
1048
|
);
|
|
973
1049
|
|
|
974
|
-
const executionResult = await this.#
|
|
1050
|
+
const executionResult = await this.#executeUtility(
|
|
975
1051
|
contractFunctionSimulator,
|
|
976
1052
|
call,
|
|
977
1053
|
authwits ?? [],
|
|
@@ -998,8 +1074,8 @@ export class PXE {
|
|
|
998
1074
|
const stringifiedArgs = args.map(arg => arg.toString()).join(', ');
|
|
999
1075
|
throw this.#contextualizeError(
|
|
1000
1076
|
err,
|
|
1001
|
-
`
|
|
1002
|
-
`scopes=${scopes
|
|
1077
|
+
`executeUtility ${to}:${name}(${stringifiedArgs})`,
|
|
1078
|
+
`scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
|
|
1003
1079
|
);
|
|
1004
1080
|
}
|
|
1005
1081
|
});
|
|
@@ -1032,14 +1108,14 @@ export class PXE {
|
|
|
1032
1108
|
|
|
1033
1109
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
1034
1110
|
|
|
1035
|
-
await ensureContractSynced(
|
|
1111
|
+
await this.contractSyncService.ensureContractSynced(
|
|
1036
1112
|
filter.contractAddress,
|
|
1037
1113
|
null,
|
|
1038
|
-
async privateSyncCall =>
|
|
1039
|
-
await this.#
|
|
1040
|
-
this.node,
|
|
1041
|
-
this.contractStore,
|
|
1114
|
+
async (privateSyncCall, execScopes) =>
|
|
1115
|
+
await this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
1042
1116
|
anchorBlockHeader,
|
|
1117
|
+
jobId,
|
|
1118
|
+
filter.scopes,
|
|
1043
1119
|
);
|
|
1044
1120
|
});
|
|
1045
1121
|
|
|
@@ -43,23 +43,23 @@ export class AddressStore {
|
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
async #getCompleteAddress(address: AztecAddress): Promise<CompleteAddress | undefined> {
|
|
47
|
-
const index = await this.#completeAddressIndex.getAsync(address.toString());
|
|
48
|
-
if (index === undefined) {
|
|
49
|
-
return undefined;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const value = await this.#completeAddresses.atAsync(index);
|
|
53
|
-
return value ? await CompleteAddress.fromBuffer(value) : undefined;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
46
|
getCompleteAddress(account: AztecAddress): Promise<CompleteAddress | undefined> {
|
|
57
|
-
return this.#
|
|
47
|
+
return this.#store.transactionAsync(async () => {
|
|
48
|
+
const index = await this.#completeAddressIndex.getAsync(account.toString());
|
|
49
|
+
if (index === undefined) {
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const value = await this.#completeAddresses.atAsync(index);
|
|
54
|
+
return value ? await CompleteAddress.fromBuffer(value) : undefined;
|
|
55
|
+
});
|
|
58
56
|
}
|
|
59
57
|
|
|
60
|
-
|
|
61
|
-
return
|
|
62
|
-
|
|
63
|
-
|
|
58
|
+
getCompleteAddresses(): Promise<CompleteAddress[]> {
|
|
59
|
+
return this.#store.transactionAsync(async () => {
|
|
60
|
+
return await Promise.all(
|
|
61
|
+
(await toArray(this.#completeAddresses.valuesAsync())).map(v => CompleteAddress.fromBuffer(v)),
|
|
62
|
+
);
|
|
63
|
+
});
|
|
64
64
|
}
|
|
65
65
|
}
|
|
@@ -10,6 +10,14 @@ export class AnchorBlockStore {
|
|
|
10
10
|
this.#synchronizedHeader = this.#store.openSingleton('header');
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Sets the currently synchronized block
|
|
15
|
+
*
|
|
16
|
+
* Important: this method is only called from BlockSynchronizer, and since we need it to run atomically with other
|
|
17
|
+
* stores in the case of a reorg, it MUST NOT be wrapped in a `transactionAsync` call. Doing so would result in a
|
|
18
|
+
* deadlock when the backend is IndexedDB, because `transactionAsync` is not designed to support reentrancy.
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
13
21
|
async setHeader(header: BlockHeader): Promise<void> {
|
|
14
22
|
await this.#synchronizedHeader.set(header.toBuffer());
|
|
15
23
|
}
|