@aztec/pxe 0.0.1-commit.d431d1c → 0.0.1-commit.d6f2b3f94
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/bin/check_oracle_version.js +1 -1
- package/dest/block_synchronizer/block_synchronizer.d.ts +9 -5
- package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
- package/dest/block_synchronizer/block_synchronizer.js +62 -16
- package/dest/config/index.d.ts +3 -1
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +17 -0
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +5 -5
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +12 -15
- package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +1 -1
- 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 +1 -1
- package/dest/contract_function_simulator/noir-structs/note_validation_request.js +1 -1
- package/dest/contract_function_simulator/oracle/interfaces.d.ts +15 -12
- package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.d.ts +6 -4
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +51 -29
- package/dest/contract_function_simulator/oracle/private_execution.d.ts +2 -22
- package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution.js +0 -37
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +12 -3
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +20 -9
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +38 -24
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +84 -65
- package/dest/contract_sync/contract_sync_service.d.ts +41 -0
- package/dest/contract_sync/contract_sync_service.d.ts.map +1 -0
- package/dest/contract_sync/contract_sync_service.js +82 -0
- package/dest/contract_sync/helpers.d.ts +28 -0
- package/dest/contract_sync/helpers.d.ts.map +1 -0
- package/dest/contract_sync/helpers.js +55 -0
- package/dest/debug/pxe_debug_utils.d.ts +22 -9
- package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
- package/dest/debug/pxe_debug_utils.js +28 -17
- 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 +12 -6
- 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 +13 -7
- 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 +2 -1
- package/dest/entrypoints/server/index.d.ts.map +1 -1
- package/dest/entrypoints/server/index.js +1 -0
- package/dest/entrypoints/server/utils.d.ts +1 -1
- package/dest/entrypoints/server/utils.d.ts.map +1 -1
- package/dest/entrypoints/server/utils.js +19 -8
- package/dest/events/event_service.d.ts +5 -6
- package/dest/events/event_service.d.ts.map +1 -1
- package/dest/events/event_service.js +6 -7
- 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 +6 -5
- package/dest/logs/log_service.d.ts.map +1 -1
- package/dest/logs/log_service.js +20 -19
- package/dest/notes/note_service.d.ts +6 -6
- package/dest/notes/note_service.d.ts.map +1 -1
- package/dest/notes/note_service.js +14 -14
- package/dest/oracle_version.d.ts +3 -3
- package/dest/oracle_version.d.ts.map +1 -1
- package/dest/oracle_version.js +4 -3
- 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 +2 -2
- package/dest/private_kernel/private_kernel_oracle.d.ts +3 -3
- package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
- package/dest/pxe.d.ts +13 -2
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +45 -20
- 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 +1 -2
- package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
- package/dest/storage/contract_store/contract_store.js +27 -30
- package/dest/storage/metadata.d.ts +1 -1
- package/dest/storage/metadata.js +1 -1
- package/dest/storage/note_store/note_store.d.ts +48 -50
- package/dest/storage/note_store/note_store.d.ts.map +1 -1
- package/dest/storage/note_store/note_store.js +279 -252
- package/dest/storage/note_store/stored_note.d.ts +16 -0
- package/dest/storage/note_store/stored_note.d.ts.map +1 -0
- package/dest/storage/note_store/stored_note.js +43 -0
- package/dest/storage/private_event_store/private_event_store.d.ts +17 -4
- package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
- package/dest/storage/private_event_store/private_event_store.js +198 -147
- package/dest/storage/private_event_store/stored_private_event.d.ts +23 -0
- package/dest/storage/private_event_store/stored_private_event.d.ts.map +1 -0
- package/dest/storage/private_event_store/stored_private_event.js +56 -0
- package/dest/storage/tagging_store/recipient_tagging_store.d.ts +1 -1
- 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 +1 -1
- package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/sender_tagging_store.js +183 -113
- package/dest/tagging/get_all_logs_by_tags.d.ts +24 -0
- package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -0
- package/dest/tagging/get_all_logs_by_tags.js +46 -0
- package/dest/tagging/index.d.ts +2 -1
- package/dest/tagging/index.d.ts.map +1 -1
- package/dest/tagging/index.js +1 -0
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +3 -2
- 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 +2 -2
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +3 -2
- 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 +5 -2
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +3 -2
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +2 -2
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +1 -1
- 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 +5 -8
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +3 -2
- 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 +7 -4
- package/package.json +25 -16
- package/src/bin/check_oracle_version.ts +1 -0
- package/src/block_synchronizer/block_synchronizer.ts +76 -33
- package/src/config/index.ts +14 -0
- package/src/contract_function_simulator/contract_function_simulator.ts +12 -17
- 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 +20 -11
- package/src/contract_function_simulator/oracle/oracle.ts +56 -26
- package/src/contract_function_simulator/oracle/private_execution.ts +1 -60
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +34 -11
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +107 -74
- package/src/contract_sync/contract_sync_service.ts +129 -0
- package/src/contract_sync/helpers.ts +93 -0
- package/src/debug/pxe_debug_utils.ts +60 -17
- package/src/entrypoints/client/bundle/utils.ts +7 -14
- package/src/entrypoints/client/lazy/utils.ts +8 -14
- package/src/entrypoints/pxe_creation_options.ts +2 -1
- package/src/entrypoints/server/index.ts +1 -0
- package/src/entrypoints/server/utils.ts +15 -19
- package/src/events/event_service.ts +5 -7
- package/src/job_coordinator/job_coordinator.ts +4 -3
- package/src/logs/log_service.ts +31 -15
- package/src/notes/note_service.ts +21 -20
- package/src/oracle_version.ts +4 -3
- package/src/private_kernel/private_kernel_execution_prover.ts +6 -3
- package/src/private_kernel/private_kernel_oracle.ts +2 -2
- package/src/pxe.ts +84 -19
- 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 +26 -35
- package/src/storage/metadata.ts +1 -1
- package/src/storage/note_store/note_store.ts +318 -318
- package/src/storage/note_store/stored_note.ts +48 -0
- package/src/storage/private_event_store/private_event_store.ts +250 -190
- package/src/storage/private_event_store/stored_private_event.ts +73 -0
- package/src/storage/tagging_store/recipient_tagging_store.ts +31 -21
- package/src/storage/tagging_store/sender_address_book_store.ts +20 -14
- package/src/storage/tagging_store/sender_tagging_store.ts +210 -126
- package/src/tagging/get_all_logs_by_tags.ts +68 -0
- package/src/tagging/index.ts +1 -0
- package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +11 -1
- package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +7 -1
- package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +3 -1
- package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +5 -17
- package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +12 -3
- package/dest/tree_membership/tree_membership_service.d.ts +0 -50
- package/dest/tree_membership/tree_membership_service.d.ts.map +0 -1
- package/dest/tree_membership/tree_membership_service.js +0 -75
- package/src/tree_membership/tree_membership_service.ts +0 -97
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';
|
|
@@ -18,7 +18,6 @@ import {
|
|
|
18
18
|
} from '@aztec/stdlib/abi';
|
|
19
19
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
20
20
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
21
|
-
import { L2BlockHash } from '@aztec/stdlib/block';
|
|
22
21
|
import {
|
|
23
22
|
CompleteAddress,
|
|
24
23
|
type ContractInstanceWithAddress,
|
|
@@ -34,6 +33,7 @@ import type {
|
|
|
34
33
|
PrivateKernelTailCircuitPublicInputs,
|
|
35
34
|
} from '@aztec/stdlib/kernel';
|
|
36
35
|
import {
|
|
36
|
+
BlockHeader,
|
|
37
37
|
type ContractOverrides,
|
|
38
38
|
type InTx,
|
|
39
39
|
PrivateExecutionResult,
|
|
@@ -59,8 +59,9 @@ import {
|
|
|
59
59
|
ContractFunctionSimulator,
|
|
60
60
|
generateSimulatedProvingResult,
|
|
61
61
|
} from './contract_function_simulator/contract_function_simulator.js';
|
|
62
|
-
import { readCurrentClassId } from './contract_function_simulator/oracle/private_execution.js';
|
|
63
62
|
import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
|
|
63
|
+
import { ContractSyncService } from './contract_sync/contract_sync_service.js';
|
|
64
|
+
import { readCurrentClassId } from './contract_sync/helpers.js';
|
|
64
65
|
import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
|
|
65
66
|
import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
|
|
66
67
|
import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
|
|
@@ -103,6 +104,7 @@ export class PXE {
|
|
|
103
104
|
private recipientTaggingStore: RecipientTaggingStore,
|
|
104
105
|
private addressStore: AddressStore,
|
|
105
106
|
private privateEventStore: PrivateEventStore,
|
|
107
|
+
private contractSyncService: ContractSyncService,
|
|
106
108
|
private simulator: CircuitSimulator,
|
|
107
109
|
private proverEnabled: boolean,
|
|
108
110
|
private proofCreator: PrivateKernelProver,
|
|
@@ -129,6 +131,10 @@ export class PXE {
|
|
|
129
131
|
config: PXEConfig,
|
|
130
132
|
loggerOrSuffix?: string | Logger,
|
|
131
133
|
) {
|
|
134
|
+
// Extract bindings from the logger, or use empty bindings if a string suffix is provided.
|
|
135
|
+
const bindings: LoggerBindings | undefined =
|
|
136
|
+
loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
|
|
137
|
+
|
|
132
138
|
const log =
|
|
133
139
|
!loggerOrSuffix || typeof loggerOrSuffix === 'string'
|
|
134
140
|
? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
|
|
@@ -138,7 +144,7 @@ export class PXE {
|
|
|
138
144
|
const addressStore = new AddressStore(store);
|
|
139
145
|
const privateEventStore = new PrivateEventStore(store);
|
|
140
146
|
const contractStore = new ContractStore(store);
|
|
141
|
-
const noteStore =
|
|
147
|
+
const noteStore = new NoteStore(store);
|
|
142
148
|
const anchorBlockStore = new AnchorBlockStore(store);
|
|
143
149
|
const senderTaggingStore = new SenderTaggingStore(store);
|
|
144
150
|
const senderAddressBookStore = new SenderAddressBookStore(store);
|
|
@@ -146,6 +152,12 @@ export class PXE {
|
|
|
146
152
|
const capsuleStore = new CapsuleStore(store);
|
|
147
153
|
const keyStore = new KeyStore(store);
|
|
148
154
|
const tipsStore = new L2TipsKVStore(store, 'pxe');
|
|
155
|
+
const contractSyncService = new ContractSyncService(
|
|
156
|
+
node,
|
|
157
|
+
contractStore,
|
|
158
|
+
noteStore,
|
|
159
|
+
createLogger('pxe:contract_sync', bindings),
|
|
160
|
+
);
|
|
149
161
|
const synchronizer = new BlockSynchronizer(
|
|
150
162
|
node,
|
|
151
163
|
store,
|
|
@@ -153,14 +165,22 @@ export class PXE {
|
|
|
153
165
|
noteStore,
|
|
154
166
|
privateEventStore,
|
|
155
167
|
tipsStore,
|
|
168
|
+
contractSyncService,
|
|
156
169
|
config,
|
|
157
|
-
|
|
170
|
+
bindings,
|
|
158
171
|
);
|
|
159
172
|
|
|
160
|
-
const jobCoordinator = new JobCoordinator(store);
|
|
161
|
-
jobCoordinator.registerStores([
|
|
173
|
+
const jobCoordinator = new JobCoordinator(store, bindings);
|
|
174
|
+
jobCoordinator.registerStores([
|
|
175
|
+
capsuleStore,
|
|
176
|
+
senderTaggingStore,
|
|
177
|
+
recipientTaggingStore,
|
|
178
|
+
privateEventStore,
|
|
179
|
+
noteStore,
|
|
180
|
+
contractSyncService,
|
|
181
|
+
]);
|
|
162
182
|
|
|
163
|
-
const debugUtils = new PXEDebugUtils(
|
|
183
|
+
const debugUtils = new PXEDebugUtils(contractSyncService, noteStore, synchronizer, anchorBlockStore);
|
|
164
184
|
|
|
165
185
|
const jobQueue = new SerialQueue();
|
|
166
186
|
|
|
@@ -177,6 +197,7 @@ export class PXE {
|
|
|
177
197
|
recipientTaggingStore,
|
|
178
198
|
addressStore,
|
|
179
199
|
privateEventStore,
|
|
200
|
+
contractSyncService,
|
|
180
201
|
simulator,
|
|
181
202
|
proverEnabled,
|
|
182
203
|
proofCreator,
|
|
@@ -187,7 +208,11 @@ export class PXE {
|
|
|
187
208
|
debugUtils,
|
|
188
209
|
);
|
|
189
210
|
|
|
190
|
-
debugUtils.
|
|
211
|
+
debugUtils.setPXEHelpers(
|
|
212
|
+
pxe.#putInJobQueue.bind(pxe),
|
|
213
|
+
pxe.#getSimulatorForTx.bind(pxe),
|
|
214
|
+
pxe.#simulateUtility.bind(pxe),
|
|
215
|
+
);
|
|
191
216
|
|
|
192
217
|
pxe.jobQueue.start();
|
|
193
218
|
|
|
@@ -208,13 +233,13 @@ export class PXE {
|
|
|
208
233
|
this.keyStore,
|
|
209
234
|
this.addressStore,
|
|
210
235
|
BenchmarkedNodeFactory.create(this.node),
|
|
211
|
-
this.anchorBlockStore,
|
|
212
236
|
this.senderTaggingStore,
|
|
213
237
|
this.recipientTaggingStore,
|
|
214
238
|
this.senderAddressBookStore,
|
|
215
239
|
this.capsuleStore,
|
|
216
240
|
this.privateEventStore,
|
|
217
241
|
this.simulator,
|
|
242
|
+
this.contractSyncService,
|
|
218
243
|
);
|
|
219
244
|
}
|
|
220
245
|
|
|
@@ -289,6 +314,14 @@ export class PXE {
|
|
|
289
314
|
try {
|
|
290
315
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
291
316
|
|
|
317
|
+
await this.contractSyncService.ensureContractSynced(
|
|
318
|
+
contractAddress,
|
|
319
|
+
functionSelector,
|
|
320
|
+
privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
|
|
321
|
+
anchorBlockHeader,
|
|
322
|
+
jobId,
|
|
323
|
+
);
|
|
324
|
+
|
|
292
325
|
const result = await contractFunctionSimulator.run(
|
|
293
326
|
txRequest,
|
|
294
327
|
contractAddress,
|
|
@@ -384,15 +417,33 @@ export class PXE {
|
|
|
384
417
|
config: PrivateKernelExecutionProverConfig,
|
|
385
418
|
): Promise<PrivateKernelExecutionProofOutput<PrivateKernelTailCircuitPublicInputs>> {
|
|
386
419
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
387
|
-
const anchorBlockHash =
|
|
420
|
+
const anchorBlockHash = await anchorBlockHeader.hash();
|
|
388
421
|
const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHash);
|
|
389
|
-
const kernelTraceProver = new PrivateKernelExecutionProver(
|
|
422
|
+
const kernelTraceProver = new PrivateKernelExecutionProver(
|
|
423
|
+
kernelOracle,
|
|
424
|
+
proofCreator,
|
|
425
|
+
!this.proverEnabled,
|
|
426
|
+
this.log.getBindings(),
|
|
427
|
+
);
|
|
390
428
|
this.log.debug(`Executing kernel trace prover (${JSON.stringify(config)})...`);
|
|
391
429
|
return await kernelTraceProver.proveWithKernels(txExecutionRequest.toTxRequest(), privateExecutionResult, config);
|
|
392
430
|
}
|
|
393
431
|
|
|
394
432
|
// Public API
|
|
395
433
|
|
|
434
|
+
/**
|
|
435
|
+
* Returns the block header up to which the PXE has synced.
|
|
436
|
+
* @returns The synced block header
|
|
437
|
+
*/
|
|
438
|
+
public getSyncedBlockHeader(): Promise<BlockHeader> {
|
|
439
|
+
return this.anchorBlockStore.getBlockHeader();
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* Returns the contract instance for a given address, if it's registered in the PXE.
|
|
444
|
+
* @param address - The contract address.
|
|
445
|
+
* @returns The contract instance if found, undefined otherwise.
|
|
446
|
+
*/
|
|
396
447
|
public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
|
|
397
448
|
return this.contractStore.getContractInstance(address);
|
|
398
449
|
}
|
|
@@ -428,7 +479,6 @@ export class PXE {
|
|
|
428
479
|
}
|
|
429
480
|
|
|
430
481
|
await this.addressStore.addCompleteAddress(accountCompleteAddress);
|
|
431
|
-
await this.noteStore.addScope(accountCompleteAddress.address);
|
|
432
482
|
return accountCompleteAddress;
|
|
433
483
|
}
|
|
434
484
|
|
|
@@ -827,7 +877,14 @@ export class PXE {
|
|
|
827
877
|
// Temporary: in case there are overrides, we have to skip the kernels or validations
|
|
828
878
|
// will fail. Consider handing control to the user/wallet on whether they want to run them
|
|
829
879
|
// or not.
|
|
830
|
-
const
|
|
880
|
+
const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
|
|
881
|
+
const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
|
|
882
|
+
const skipKernels = hasOverriddenContracts;
|
|
883
|
+
|
|
884
|
+
// Set overridden contracts on the sync service so it knows to skip syncing them
|
|
885
|
+
if (hasOverriddenContracts) {
|
|
886
|
+
this.contractSyncService.setOverriddenContracts(jobId, overriddenContracts);
|
|
887
|
+
}
|
|
831
888
|
|
|
832
889
|
// Execution of private functions only; no proving, and no kernel logic.
|
|
833
890
|
const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
@@ -838,7 +895,7 @@ export class PXE {
|
|
|
838
895
|
if (skipKernels) {
|
|
839
896
|
({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
|
|
840
897
|
privateExecutionResult,
|
|
841
|
-
this.contractStore,
|
|
898
|
+
(addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
|
|
842
899
|
));
|
|
843
900
|
} else {
|
|
844
901
|
// Kernel logic, plus proving of all private functions and kernels.
|
|
@@ -948,8 +1005,13 @@ export class PXE {
|
|
|
948
1005
|
const functionTimer = new Timer();
|
|
949
1006
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
950
1007
|
|
|
951
|
-
await this.
|
|
952
|
-
|
|
1008
|
+
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
1009
|
+
await this.contractSyncService.ensureContractSynced(
|
|
1010
|
+
call.to,
|
|
1011
|
+
call.selector,
|
|
1012
|
+
privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
|
|
1013
|
+
anchorBlockHeader,
|
|
1014
|
+
jobId,
|
|
953
1015
|
);
|
|
954
1016
|
|
|
955
1017
|
const executionResult = await this.#simulateUtility(
|
|
@@ -1008,15 +1070,18 @@ export class PXE {
|
|
|
1008
1070
|
await this.#putInJobQueue(async jobId => {
|
|
1009
1071
|
await this.blockStateSynchronizer.sync();
|
|
1010
1072
|
|
|
1011
|
-
|
|
1073
|
+
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
1074
|
+
anchorBlockNumber = anchorBlockHeader.getBlockNumber();
|
|
1012
1075
|
|
|
1013
1076
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
1014
1077
|
|
|
1015
|
-
await this.
|
|
1078
|
+
await this.contractSyncService.ensureContractSynced(
|
|
1016
1079
|
filter.contractAddress,
|
|
1017
1080
|
null,
|
|
1018
1081
|
async privateSyncCall =>
|
|
1019
1082
|
await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
|
|
1083
|
+
anchorBlockHeader,
|
|
1084
|
+
jobId,
|
|
1020
1085
|
);
|
|
1021
1086
|
});
|
|
1022
1087
|
|
|
@@ -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
|
}
|
|
@@ -57,14 +57,14 @@ export class CapsuleStore implements StagedStore {
|
|
|
57
57
|
*/
|
|
58
58
|
async #getFromStage(jobId: string, dbSlotKey: string): Promise<Buffer | null | undefined> {
|
|
59
59
|
const jobStagedCapsules = this.#getJobStagedCapsules(jobId);
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
//
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return staged;
|
|
60
|
+
const staged: Buffer | null | undefined = jobStagedCapsules.get(dbSlotKey);
|
|
61
|
+
|
|
62
|
+
// Always issue DB read to keep IndexedDB transaction alive, even if the value is in the job staged data. This
|
|
63
|
+
// keeps IndexedDB transactions alive (they auto-commit when a new micro-task starts and there are no pending read
|
|
64
|
+
// requests). The staged value still takes precedence if it exists (including null for deletions).
|
|
65
|
+
const dbValue = await this.#loadCapsuleFromDb(dbSlotKey);
|
|
66
|
+
|
|
67
|
+
return staged !== undefined ? staged : dbValue;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
/**
|
|
@@ -3,7 +3,6 @@ import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
|
3
3
|
import { toArray } from '@aztec/foundation/iterable';
|
|
4
4
|
import type { MembershipWitness } from '@aztec/foundation/trees';
|
|
5
5
|
import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
|
|
6
|
-
import { isProtocolContract } from '@aztec/protocol-contracts';
|
|
7
6
|
import {
|
|
8
7
|
type ContractArtifact,
|
|
9
8
|
type FunctionAbi,
|
|
@@ -43,10 +42,12 @@ export class ContractStore {
|
|
|
43
42
|
/** Map from contract address to contract class id */
|
|
44
43
|
#contractClassIdMap: Map<string, Fr> = new Map();
|
|
45
44
|
|
|
45
|
+
#store: AztecAsyncKVStore;
|
|
46
46
|
#contractArtifacts: AztecAsyncMap<string, Buffer>;
|
|
47
47
|
#contractInstances: AztecAsyncMap<string, Buffer>;
|
|
48
48
|
|
|
49
49
|
constructor(store: AztecAsyncKVStore) {
|
|
50
|
+
this.#store = store;
|
|
50
51
|
this.#contractArtifacts = store.openMap('contract_artifacts');
|
|
51
52
|
this.#contractInstances = store.openMap('contracts_instances');
|
|
52
53
|
}
|
|
@@ -54,6 +55,7 @@ export class ContractStore {
|
|
|
54
55
|
// Setters
|
|
55
56
|
|
|
56
57
|
public async addContractArtifact(id: Fr, contract: ContractArtifact): Promise<void> {
|
|
58
|
+
// Validation outside transactionAsync - these are not DB operations
|
|
57
59
|
const privateFunctions = contract.functions.filter(
|
|
58
60
|
functionArtifact => functionArtifact.functionType === FunctionType.PRIVATE,
|
|
59
61
|
);
|
|
@@ -70,7 +72,9 @@ export class ContractStore {
|
|
|
70
72
|
throw new Error('Repeated function selectors of private functions');
|
|
71
73
|
}
|
|
72
74
|
|
|
73
|
-
await this.#
|
|
75
|
+
await this.#store.transactionAsync(() =>
|
|
76
|
+
this.#contractArtifacts.set(id.toString(), contractArtifactToBuffer(contract)),
|
|
77
|
+
);
|
|
74
78
|
}
|
|
75
79
|
|
|
76
80
|
async addContractInstance(contract: ContractInstanceWithAddress): Promise<void> {
|
|
@@ -124,21 +128,27 @@ export class ContractStore {
|
|
|
124
128
|
|
|
125
129
|
// Public getters
|
|
126
130
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
131
|
+
getContractsAddresses(): Promise<AztecAddress[]> {
|
|
132
|
+
return this.#store.transactionAsync(async () => {
|
|
133
|
+
const keys = await toArray(this.#contractInstances.keysAsync());
|
|
134
|
+
return keys.map(AztecAddress.fromString);
|
|
135
|
+
});
|
|
130
136
|
}
|
|
131
137
|
|
|
132
138
|
/** Returns a contract instance for a given address. Throws if not found. */
|
|
133
|
-
public
|
|
134
|
-
|
|
135
|
-
|
|
139
|
+
public getContractInstance(contractAddress: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
|
|
140
|
+
return this.#store.transactionAsync(async () => {
|
|
141
|
+
const contract = await this.#contractInstances.getAsync(contractAddress.toString());
|
|
142
|
+
return contract && SerializableContractInstance.fromBuffer(contract).withAddress(contractAddress);
|
|
143
|
+
});
|
|
136
144
|
}
|
|
137
145
|
|
|
138
|
-
public
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
146
|
+
public getContractArtifact(contractClassId: Fr): Promise<ContractArtifact | undefined> {
|
|
147
|
+
return this.#store.transactionAsync(async () => {
|
|
148
|
+
const contract = await this.#contractArtifacts.getAsync(contractClassId.toString());
|
|
149
|
+
// TODO(@spalladino): AztecAsyncMap lies and returns Uint8Arrays instead of Buffers, hence the extra Buffer.from.
|
|
150
|
+
return contract && contractArtifactFromBuffer(Buffer.from(contract));
|
|
151
|
+
});
|
|
142
152
|
}
|
|
143
153
|
|
|
144
154
|
/** Returns a contract class for a given class id. Throws if not found. */
|
|
@@ -306,34 +316,15 @@ export class ContractStore {
|
|
|
306
316
|
throw new Error(`Unknown function ${functionName} in contract ${contract.name}.`);
|
|
307
317
|
}
|
|
308
318
|
|
|
309
|
-
return {
|
|
319
|
+
return FunctionCall.from({
|
|
310
320
|
name: functionDao.name,
|
|
311
|
-
|
|
321
|
+
to,
|
|
312
322
|
selector: await FunctionSelector.fromNameAndParameters(functionDao.name, functionDao.parameters),
|
|
313
323
|
type: functionDao.functionType,
|
|
314
|
-
to,
|
|
315
324
|
hideMsgSender: false,
|
|
316
325
|
isStatic: functionDao.isStatic,
|
|
326
|
+
args: encodeArguments(functionDao, args),
|
|
317
327
|
returnTypes: functionDao.returnTypes,
|
|
318
|
-
};
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
// Synchronize target contract data
|
|
322
|
-
public async syncPrivateState(
|
|
323
|
-
contractAddress: AztecAddress,
|
|
324
|
-
functionToInvokeAfterSync: FunctionSelector | null,
|
|
325
|
-
utilityExecutor: (privateSyncCall: FunctionCall) => Promise<any>,
|
|
326
|
-
) {
|
|
327
|
-
// Protocol contracts don't have private state to sync
|
|
328
|
-
if (!isProtocolContract(contractAddress)) {
|
|
329
|
-
const syncPrivateStateFunctionCall = await this.getFunctionCall('sync_private_state', [], contractAddress);
|
|
330
|
-
if (functionToInvokeAfterSync && functionToInvokeAfterSync.equals(syncPrivateStateFunctionCall.selector)) {
|
|
331
|
-
throw new Error(
|
|
332
|
-
'Forbidden `sync_private_state` invocation. `sync_private_state` can only be invoked by PXE, manual execution can lead to inconsistencies.',
|
|
333
|
-
);
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
return utilityExecutor(syncPrivateStateFunctionCall);
|
|
337
|
-
}
|
|
328
|
+
});
|
|
338
329
|
}
|
|
339
330
|
}
|
package/src/storage/metadata.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const PXE_DATA_SCHEMA_VERSION =
|
|
1
|
+
export const PXE_DATA_SCHEMA_VERSION = 3;
|