@aztec/pxe 0.0.1-commit.e588bc7e5 → 0.0.1-commit.e5a3663dd
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 +4 -4
- package/dest/block_synchronizer/block_stream_source.d.ts +10 -0
- package/dest/block_synchronizer/block_stream_source.d.ts.map +1 -0
- package/dest/block_synchronizer/block_stream_source.js +37 -0
- package/dest/block_synchronizer/block_synchronizer.d.ts +6 -2
- package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
- package/dest/block_synchronizer/block_synchronizer.js +24 -10
- package/dest/config/index.d.ts +1 -1
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +7 -14
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +4 -1
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +8 -5
- package/dest/contract_function_simulator/ephemeral_array_service.d.ts +28 -0
- package/dest/contract_function_simulator/ephemeral_array_service.d.ts.map +1 -0
- package/dest/contract_function_simulator/ephemeral_array_service.js +78 -0
- 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/log_retrieval_request.d.ts +1 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_request.js +1 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +1 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.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 -2
- package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts +1 -1
- package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.js +10 -1
- package/dest/contract_function_simulator/oracle/oracle.d.ts +14 -2
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +105 -3
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +10 -11
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +21 -17
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +34 -13
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +149 -28
- package/dest/contract_function_simulator/pick_notes.d.ts +1 -1
- package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -1
- package/dest/contract_function_simulator/pick_notes.js +20 -3
- package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +1 -1
- package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +1 -1
- package/dest/contract_function_simulator/proxied_contract_data_source.js +3 -0
- package/dest/contract_sync/contract_sync_service.d.ts +1 -1
- package/dest/contract_sync/contract_sync_service.d.ts.map +1 -1
- package/dest/contract_sync/contract_sync_service.js +35 -23
- package/dest/entrypoints/client/bundle/utils.d.ts +2 -2
- package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/utils.js +2 -2
- 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 +2 -2
- package/dest/entrypoints/pxe_creation_options.d.ts +3 -1
- package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
- package/dest/entrypoints/pxe_creation_options.js +3 -1
- package/dest/entrypoints/server/index.d.ts +2 -2
- package/dest/entrypoints/server/index.d.ts.map +1 -1
- package/dest/entrypoints/server/index.js +1 -1
- package/dest/entrypoints/server/utils.d.ts +2 -2
- package/dest/entrypoints/server/utils.d.ts.map +1 -1
- package/dest/entrypoints/server/utils.js +2 -2
- package/dest/events/event_service.d.ts +1 -1
- package/dest/events/event_service.d.ts.map +1 -1
- package/dest/events/event_service.js +10 -1
- package/dest/events/private_event_filter_validator.d.ts +3 -2
- package/dest/events/private_event_filter_validator.d.ts.map +1 -1
- package/dest/events/private_event_filter_validator.js +15 -0
- package/dest/logs/log_service.d.ts +6 -6
- package/dest/logs/log_service.d.ts.map +1 -1
- package/dest/logs/log_service.js +8 -20
- package/dest/oracle_version.d.ts +4 -3
- package/dest/oracle_version.d.ts.map +1 -1
- package/dest/oracle_version.js +20 -10
- 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 +4 -7
- package/dest/private_kernel/private_kernel_oracle.d.ts +5 -5
- package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_oracle.js +12 -15
- package/dest/pxe.d.ts +16 -4
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +49 -20
- package/dest/storage/anchor_block_store/anchor_block_store.js +1 -1
- package/dest/storage/capsule_store/capsule_store.d.ts +1 -1
- package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
- package/dest/storage/capsule_store/capsule_store.js +8 -5
- package/dest/storage/contract_store/contract_store.d.ts +1 -1
- package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
- package/dest/storage/contract_store/contract_store.js +4 -2
- 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 +3 -0
- package/dest/storage/private_event_store/stored_private_event.js +1 -1
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +2 -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 -16
- package/package.json +16 -16
- package/src/bin/check_oracle_version.ts +4 -4
- package/src/block_synchronizer/block_stream_source.ts +52 -0
- package/src/block_synchronizer/block_synchronizer.ts +27 -11
- package/src/config/index.ts +2 -8
- package/src/contract_function_simulator/contract_function_simulator.ts +8 -4
- package/src/contract_function_simulator/ephemeral_array_service.ts +110 -0
- package/src/contract_function_simulator/noir-structs/event_validation_request.ts +1 -1
- package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +1 -1
- package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +1 -1
- package/src/contract_function_simulator/noir-structs/note_validation_request.ts +1 -1
- package/src/contract_function_simulator/oracle/interfaces.ts +30 -1
- package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +7 -1
- package/src/contract_function_simulator/oracle/oracle.ts +157 -3
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +34 -20
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +241 -55
- package/src/contract_function_simulator/pick_notes.ts +22 -3
- package/src/contract_function_simulator/proxied_contract_data_source.ts +8 -1
- package/src/contract_sync/contract_sync_service.ts +57 -51
- package/src/entrypoints/client/bundle/utils.ts +2 -3
- package/src/entrypoints/client/lazy/utils.ts +2 -3
- package/src/entrypoints/pxe_creation_options.ts +7 -0
- package/src/entrypoints/server/index.ts +1 -1
- package/src/entrypoints/server/utils.ts +2 -3
- package/src/events/event_service.ts +13 -1
- package/src/events/private_event_filter_validator.ts +21 -1
- package/src/logs/log_service.ts +14 -50
- package/src/oracle_version.ts +20 -10
- package/src/private_kernel/private_kernel_execution_prover.ts +4 -9
- package/src/private_kernel/private_kernel_oracle.ts +14 -14
- package/src/pxe.ts +86 -24
- package/src/storage/anchor_block_store/anchor_block_store.ts +1 -1
- package/src/storage/capsule_store/capsule_store.ts +15 -5
- package/src/storage/contract_store/contract_store.ts +8 -6
- package/src/storage/private_event_store/private_event_store.ts +4 -0
- package/src/storage/private_event_store/stored_private_event.ts +1 -1
- package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +5 -15
package/src/pxe.ts
CHANGED
|
@@ -18,6 +18,7 @@ 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 type { L2TipsProvider } from '@aztec/stdlib/block';
|
|
21
22
|
import {
|
|
22
23
|
CompleteAddress,
|
|
23
24
|
type ContractInstanceWithAddress,
|
|
@@ -88,6 +89,14 @@ export type PackedPrivateEvent = InTx & {
|
|
|
88
89
|
eventSelector: EventSelector;
|
|
89
90
|
};
|
|
90
91
|
|
|
92
|
+
/** Options for PXE.proveTx. */
|
|
93
|
+
export type ProveTxOpts = {
|
|
94
|
+
/** Addresses whose private state and keys are accessible during private execution. */
|
|
95
|
+
scopes: AztecAddress[];
|
|
96
|
+
/** Sender address used to derive discovery tags for private messages (notes, events, logs) this tx emits. */
|
|
97
|
+
senderForTags?: AztecAddress;
|
|
98
|
+
};
|
|
99
|
+
|
|
91
100
|
/** Options for PXE.profileTx. */
|
|
92
101
|
export type ProfileTxOpts = {
|
|
93
102
|
/** The profiling mode to use. */
|
|
@@ -96,6 +105,8 @@ export type ProfileTxOpts = {
|
|
|
96
105
|
skipProofGeneration?: boolean;
|
|
97
106
|
/** Addresses whose private state and keys are accessible during private execution. */
|
|
98
107
|
scopes: AztecAddress[];
|
|
108
|
+
/** Sender address used to derive discovery tags for private messages (notes, events, logs) this tx emits. */
|
|
109
|
+
senderForTags?: AztecAddress;
|
|
99
110
|
};
|
|
100
111
|
|
|
101
112
|
/** Options for PXE.simulateTx. */
|
|
@@ -112,6 +123,8 @@ export type SimulateTxOpts = {
|
|
|
112
123
|
overrides?: SimulationOverrides;
|
|
113
124
|
/** Addresses whose private state and keys are accessible during private execution */
|
|
114
125
|
scopes: AztecAddress[];
|
|
126
|
+
/** Sender address used to derive discovery tags for private messages (notes, events, logs) this tx emits. */
|
|
127
|
+
senderForTags?: AztecAddress;
|
|
115
128
|
};
|
|
116
129
|
|
|
117
130
|
/** Options for PXE.executeUtility. */
|
|
@@ -161,6 +174,7 @@ export class PXE {
|
|
|
161
174
|
private privateEventStore: PrivateEventStore,
|
|
162
175
|
private contractSyncService: ContractSyncService,
|
|
163
176
|
private messageContextService: MessageContextService,
|
|
177
|
+
private l2TipsStore: L2TipsProvider,
|
|
164
178
|
private simulator: CircuitSimulator,
|
|
165
179
|
private proverEnabled: boolean,
|
|
166
180
|
private proofCreator: PrivateKernelProver,
|
|
@@ -260,6 +274,7 @@ export class PXE {
|
|
|
260
274
|
privateEventStore,
|
|
261
275
|
contractSyncService,
|
|
262
276
|
messageContextService,
|
|
277
|
+
tipsStore,
|
|
263
278
|
simulator,
|
|
264
279
|
proverEnabled,
|
|
265
280
|
proofCreator,
|
|
@@ -294,6 +309,7 @@ export class PXE {
|
|
|
294
309
|
keyStore: this.keyStore,
|
|
295
310
|
addressStore: this.addressStore,
|
|
296
311
|
aztecNode: BenchmarkedNodeFactory.create(this.node),
|
|
312
|
+
l2TipsStore: this.l2TipsStore,
|
|
297
313
|
senderTaggingStore: this.senderTaggingStore,
|
|
298
314
|
recipientTaggingStore: this.recipientTaggingStore,
|
|
299
315
|
senderAddressBookStore: this.senderAddressBookStore,
|
|
@@ -364,17 +380,24 @@ export class PXE {
|
|
|
364
380
|
|
|
365
381
|
// Executes the entrypoint private function, as well as all nested private
|
|
366
382
|
// functions that might arise.
|
|
367
|
-
async #executePrivate(
|
|
368
|
-
contractFunctionSimulator
|
|
369
|
-
txRequest
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
383
|
+
async #executePrivate({
|
|
384
|
+
contractFunctionSimulator,
|
|
385
|
+
txRequest,
|
|
386
|
+
anchorBlockHeader,
|
|
387
|
+
scopes,
|
|
388
|
+
jobId,
|
|
389
|
+
senderForTags,
|
|
390
|
+
}: {
|
|
391
|
+
contractFunctionSimulator: ContractFunctionSimulator;
|
|
392
|
+
txRequest: TxExecutionRequest;
|
|
393
|
+
anchorBlockHeader: BlockHeader;
|
|
394
|
+
scopes: AztecAddress[];
|
|
395
|
+
jobId: string;
|
|
396
|
+
senderForTags?: AztecAddress;
|
|
397
|
+
}): Promise<PrivateExecutionResult> {
|
|
373
398
|
const { origin: contractAddress, functionSelector } = txRequest;
|
|
374
399
|
|
|
375
400
|
try {
|
|
376
|
-
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
377
|
-
|
|
378
401
|
await this.contractSyncService.ensureContractSynced(
|
|
379
402
|
contractAddress,
|
|
380
403
|
functionSelector,
|
|
@@ -391,6 +414,7 @@ export class PXE {
|
|
|
391
414
|
anchorBlockHeader,
|
|
392
415
|
scopes,
|
|
393
416
|
jobId,
|
|
417
|
+
senderForTags,
|
|
394
418
|
});
|
|
395
419
|
this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
|
|
396
420
|
return result;
|
|
@@ -479,11 +503,10 @@ export class PXE {
|
|
|
479
503
|
txExecutionRequest: TxExecutionRequest,
|
|
480
504
|
proofCreator: PrivateKernelProver,
|
|
481
505
|
privateExecutionResult: PrivateExecutionResult,
|
|
506
|
+
anchorBlockHeader: BlockHeader,
|
|
482
507
|
config: PrivateKernelExecutionProverConfig,
|
|
483
508
|
): Promise<PrivateKernelExecutionProofOutput<PrivateKernelTailCircuitPublicInputs>> {
|
|
484
|
-
const
|
|
485
|
-
const anchorBlockHash = await anchorBlockHeader.hash();
|
|
486
|
-
const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHash);
|
|
509
|
+
const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHeader);
|
|
487
510
|
const kernelTraceProver = new PrivateKernelExecutionProver(
|
|
488
511
|
kernelOracle,
|
|
489
512
|
proofCreator,
|
|
@@ -560,6 +583,12 @@ export class PXE {
|
|
|
560
583
|
* TODO: It's strange that we return the address here and I (benesjan) think we should drop the return value.
|
|
561
584
|
*/
|
|
562
585
|
public async registerSender(sender: AztecAddress): Promise<AztecAddress> {
|
|
586
|
+
if (!(await sender.isValid())) {
|
|
587
|
+
throw new Error(
|
|
588
|
+
`Address ${sender} is not valid: it does not correspond to a point on the Grumpkin curve. Cannot register it as a sender.`,
|
|
589
|
+
);
|
|
590
|
+
}
|
|
591
|
+
|
|
563
592
|
const accounts = await this.keyStore.getAccounts();
|
|
564
593
|
if (accounts.includes(sender)) {
|
|
565
594
|
this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
|
|
@@ -571,8 +600,8 @@ export class PXE {
|
|
|
571
600
|
if (wasAdded) {
|
|
572
601
|
this.log.info(`Added sender:\n ${sender.toString()}`);
|
|
573
602
|
// Wipe the entire sync cache: the new sender's tagged logs could contain notes/events for any contract, so
|
|
574
|
-
// all contracts must re-sync to discover them.
|
|
575
|
-
this.contractSyncService.wipe();
|
|
603
|
+
// all contracts must re-sync to discover them. Queued to avoid wiping while a job is in flight.
|
|
604
|
+
await this.#putInJobQueue(() => Promise.resolve(this.contractSyncService.wipe()));
|
|
576
605
|
} else {
|
|
577
606
|
this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
|
|
578
607
|
}
|
|
@@ -732,7 +761,7 @@ export class PXE {
|
|
|
732
761
|
* @throws If contract code not found, or public simulation reverts.
|
|
733
762
|
* Also throws if simulatePublic is true and public simulation reverts.
|
|
734
763
|
*/
|
|
735
|
-
public proveTx(txRequest: TxExecutionRequest, scopes:
|
|
764
|
+
public proveTx(txRequest: TxExecutionRequest, { scopes, senderForTags }: ProveTxOpts): Promise<TxProvingResult> {
|
|
736
765
|
let privateExecutionResult: PrivateExecutionResult;
|
|
737
766
|
// We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
|
|
738
767
|
// computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
|
|
@@ -741,16 +770,24 @@ export class PXE {
|
|
|
741
770
|
try {
|
|
742
771
|
const syncTimer = new Timer();
|
|
743
772
|
await this.blockStateSynchronizer.sync();
|
|
773
|
+
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
744
774
|
const syncTime = syncTimer.ms();
|
|
745
775
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
746
|
-
privateExecutionResult = await this.#executePrivate(
|
|
776
|
+
privateExecutionResult = await this.#executePrivate({
|
|
777
|
+
contractFunctionSimulator,
|
|
778
|
+
txRequest,
|
|
779
|
+
anchorBlockHeader,
|
|
780
|
+
scopes,
|
|
781
|
+
jobId,
|
|
782
|
+
senderForTags,
|
|
783
|
+
});
|
|
747
784
|
|
|
748
785
|
const {
|
|
749
786
|
publicInputs,
|
|
750
787
|
chonkProof,
|
|
751
788
|
executionSteps,
|
|
752
789
|
timings: { proving } = {},
|
|
753
|
-
} = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, {
|
|
790
|
+
} = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, anchorBlockHeader, {
|
|
754
791
|
simulate: false,
|
|
755
792
|
skipFeeEnforcement: false,
|
|
756
793
|
profileMode: 'none',
|
|
@@ -813,7 +850,7 @@ export class PXE {
|
|
|
813
850
|
*/
|
|
814
851
|
public profileTx(
|
|
815
852
|
txRequest: TxExecutionRequest,
|
|
816
|
-
{ profileMode, skipProofGeneration = true, scopes }: ProfileTxOpts,
|
|
853
|
+
{ profileMode, skipProofGeneration = true, scopes, senderForTags }: ProfileTxOpts,
|
|
817
854
|
): Promise<TxProfileResult> {
|
|
818
855
|
// We disable concurrent profiles for consistency with simulateTx.
|
|
819
856
|
return this.#putInJobQueue(async jobId => {
|
|
@@ -833,15 +870,24 @@ export class PXE {
|
|
|
833
870
|
);
|
|
834
871
|
const syncTimer = new Timer();
|
|
835
872
|
await this.blockStateSynchronizer.sync();
|
|
873
|
+
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
836
874
|
const syncTime = syncTimer.ms();
|
|
837
875
|
|
|
838
876
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
839
|
-
const privateExecutionResult = await this.#executePrivate(
|
|
877
|
+
const privateExecutionResult = await this.#executePrivate({
|
|
878
|
+
contractFunctionSimulator,
|
|
879
|
+
txRequest,
|
|
880
|
+
anchorBlockHeader,
|
|
881
|
+
scopes,
|
|
882
|
+
jobId,
|
|
883
|
+
senderForTags,
|
|
884
|
+
});
|
|
840
885
|
|
|
841
886
|
const { executionSteps, timings: { proving } = {} } = await this.#prove(
|
|
842
887
|
txRequest,
|
|
843
888
|
this.proofCreator,
|
|
844
889
|
privateExecutionResult,
|
|
890
|
+
anchorBlockHeader,
|
|
845
891
|
{
|
|
846
892
|
simulate: skipProofGeneration,
|
|
847
893
|
skipFeeEnforcement: false,
|
|
@@ -909,6 +955,7 @@ export class PXE {
|
|
|
909
955
|
skipKernels = true,
|
|
910
956
|
overrides,
|
|
911
957
|
scopes,
|
|
958
|
+
senderForTags,
|
|
912
959
|
}: SimulateTxOpts,
|
|
913
960
|
): Promise<TxSimulationResult> {
|
|
914
961
|
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
@@ -931,6 +978,7 @@ export class PXE {
|
|
|
931
978
|
);
|
|
932
979
|
const syncTimer = new Timer();
|
|
933
980
|
await this.blockStateSynchronizer.sync();
|
|
981
|
+
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
934
982
|
const syncTime = syncTimer.ms();
|
|
935
983
|
|
|
936
984
|
const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
|
|
@@ -950,7 +998,14 @@ export class PXE {
|
|
|
950
998
|
}
|
|
951
999
|
|
|
952
1000
|
// Execution of private functions only; no proving, and no kernel logic.
|
|
953
|
-
const privateExecutionResult = await this.#executePrivate(
|
|
1001
|
+
const privateExecutionResult = await this.#executePrivate({
|
|
1002
|
+
contractFunctionSimulator,
|
|
1003
|
+
txRequest,
|
|
1004
|
+
anchorBlockHeader,
|
|
1005
|
+
scopes,
|
|
1006
|
+
jobId,
|
|
1007
|
+
senderForTags,
|
|
1008
|
+
});
|
|
954
1009
|
|
|
955
1010
|
let publicInputs: PrivateKernelTailCircuitPublicInputs | undefined;
|
|
956
1011
|
let executionSteps: PrivateExecutionStep[] = [];
|
|
@@ -963,11 +1018,17 @@ export class PXE {
|
|
|
963
1018
|
));
|
|
964
1019
|
} else {
|
|
965
1020
|
// Kernel logic, plus proving of all private functions and kernels.
|
|
966
|
-
({ publicInputs, executionSteps } = await this.#prove(
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
1021
|
+
({ publicInputs, executionSteps } = await this.#prove(
|
|
1022
|
+
txRequest,
|
|
1023
|
+
this.proofCreator,
|
|
1024
|
+
privateExecutionResult,
|
|
1025
|
+
anchorBlockHeader,
|
|
1026
|
+
{
|
|
1027
|
+
simulate: true,
|
|
1028
|
+
skipFeeEnforcement,
|
|
1029
|
+
profileMode: 'none',
|
|
1030
|
+
},
|
|
1031
|
+
));
|
|
971
1032
|
}
|
|
972
1033
|
|
|
973
1034
|
const privateSimulationResult = new PrivateSimulationResult(privateExecutionResult, publicInputs);
|
|
@@ -1170,6 +1231,7 @@ export class PXE {
|
|
|
1170
1231
|
*/
|
|
1171
1232
|
public async stop(): Promise<void> {
|
|
1172
1233
|
await this.jobQueue.end();
|
|
1234
|
+
await this.blockStateSynchronizer.stop();
|
|
1173
1235
|
await this.db.close();
|
|
1174
1236
|
}
|
|
1175
1237
|
}
|
|
@@ -23,7 +23,7 @@ export class AnchorBlockStore {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
async getBlockHeader(): Promise<BlockHeader> {
|
|
26
|
-
const headerBuffer = await this.#synchronizedHeader.getAsync();
|
|
26
|
+
const headerBuffer = await this.#store.transactionAsync(() => this.#synchronizedHeader.getAsync());
|
|
27
27
|
if (!headerBuffer) {
|
|
28
28
|
throw new Error(`Trying to get block header with a not-yet-synchronized PXE - this should never happen`);
|
|
29
29
|
}
|
|
@@ -148,7 +148,17 @@ export class CapsuleStore implements StagedStore {
|
|
|
148
148
|
* @param slot - The slot in the database to read.
|
|
149
149
|
* @returns The stored data or `null` if no data is stored under the slot.
|
|
150
150
|
*/
|
|
151
|
-
|
|
151
|
+
getCapsule(contractAddress: AztecAddress, slot: Fr, jobId: string, scope: AztecAddress): Promise<Fr[] | null> {
|
|
152
|
+
return this.#store.transactionAsync(() => this.#getCapsuleInternal(contractAddress, slot, jobId, scope));
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** Same as getCapsule but without its own transaction, for use inside an existing transactionAsync. */
|
|
156
|
+
async #getCapsuleInternal(
|
|
157
|
+
contractAddress: AztecAddress,
|
|
158
|
+
slot: Fr,
|
|
159
|
+
jobId: string,
|
|
160
|
+
scope: AztecAddress,
|
|
161
|
+
): Promise<Fr[] | null> {
|
|
152
162
|
const dataBuffer = await this.#getFromStage(jobId, dbSlotToKey(contractAddress, slot, scope));
|
|
153
163
|
if (!dataBuffer) {
|
|
154
164
|
this.logger.trace(`Data not found for contract ${contractAddress.toString()} and slot ${slot.toString()}`);
|
|
@@ -240,7 +250,7 @@ export class CapsuleStore implements StagedStore {
|
|
|
240
250
|
// and not using a transaction here would heavily impact performance.
|
|
241
251
|
return this.#store.transactionAsync(async () => {
|
|
242
252
|
// Load current length, defaulting to 0 if not found
|
|
243
|
-
const lengthData = await this
|
|
253
|
+
const lengthData = await this.#getCapsuleInternal(contractAddress, baseSlot, jobId, scope);
|
|
244
254
|
const currentLength = lengthData ? lengthData[0].toNumber() : 0;
|
|
245
255
|
|
|
246
256
|
// Store each capsule at consecutive slots after baseSlot + 1 + currentLength
|
|
@@ -263,14 +273,14 @@ export class CapsuleStore implements StagedStore {
|
|
|
263
273
|
// of jobs: different calls running concurrently on the same contract may cause trouble.
|
|
264
274
|
return this.#store.transactionAsync(async () => {
|
|
265
275
|
// Load length, defaulting to 0 if not found
|
|
266
|
-
const maybeLength = await this
|
|
276
|
+
const maybeLength = await this.#getCapsuleInternal(contractAddress, baseSlot, jobId, scope);
|
|
267
277
|
const length = maybeLength ? maybeLength[0].toBigInt() : 0n;
|
|
268
278
|
|
|
269
279
|
const values: Fr[][] = [];
|
|
270
280
|
|
|
271
281
|
// Read each capsule at consecutive slots after baseSlot
|
|
272
282
|
for (let i = 0; i < length; i++) {
|
|
273
|
-
const currentValue = await this
|
|
283
|
+
const currentValue = await this.#getCapsuleInternal(contractAddress, arraySlot(baseSlot, i), jobId, scope);
|
|
274
284
|
if (currentValue == undefined) {
|
|
275
285
|
throw new Error(
|
|
276
286
|
`Expected non-empty value at capsule array in base slot ${baseSlot} at index ${i} for contract ${contractAddress}`,
|
|
@@ -295,7 +305,7 @@ export class CapsuleStore implements StagedStore {
|
|
|
295
305
|
// of jobs: different calls running concurrently on the same contract may cause trouble.
|
|
296
306
|
return this.#store.transactionAsync(async () => {
|
|
297
307
|
// Load current length, defaulting to 0 if not found
|
|
298
|
-
const maybeLength = await this
|
|
308
|
+
const maybeLength = await this.#getCapsuleInternal(contractAddress, baseSlot, jobId, scope);
|
|
299
309
|
const originalLength = maybeLength ? maybeLength[0].toNumber() : 0;
|
|
300
310
|
|
|
301
311
|
// Set the new length
|
|
@@ -168,12 +168,14 @@ export class ContractStore {
|
|
|
168
168
|
}
|
|
169
169
|
|
|
170
170
|
async addContractInstance(contract: ContractInstanceWithAddress): Promise<void> {
|
|
171
|
-
this.#
|
|
171
|
+
await this.#store.transactionAsync(async () => {
|
|
172
|
+
await this.#contractInstances.set(
|
|
173
|
+
contract.address.toString(),
|
|
174
|
+
new SerializableContractInstance(contract).toBuffer(),
|
|
175
|
+
);
|
|
176
|
+
});
|
|
172
177
|
|
|
173
|
-
|
|
174
|
-
contract.address.toString(),
|
|
175
|
-
new SerializableContractInstance(contract).toBuffer(),
|
|
176
|
-
);
|
|
178
|
+
this.#contractClassIdMap.set(contract.address.toString(), contract.currentContractClassId);
|
|
177
179
|
}
|
|
178
180
|
|
|
179
181
|
// Private getters
|
|
@@ -246,7 +248,7 @@ export class ContractStore {
|
|
|
246
248
|
contractClassId: Fr,
|
|
247
249
|
): Promise<(ContractClassWithId & ContractClassIdPreimage) | undefined> {
|
|
248
250
|
const key = contractClassId.toString();
|
|
249
|
-
const buf = await this.#contractClassData.getAsync(key);
|
|
251
|
+
const buf = await this.#store.transactionAsync(() => this.#contractClassData.getAsync(key));
|
|
250
252
|
if (!buf) {
|
|
251
253
|
return undefined;
|
|
252
254
|
}
|
|
@@ -234,6 +234,10 @@ export class PrivateEventStore implements StagedStore {
|
|
|
234
234
|
* IMPORTANT: This method must be called within a transaction to ensure atomicity.
|
|
235
235
|
*/
|
|
236
236
|
public async rollback(blockNumber: number, synchedBlockNumber: number): Promise<void> {
|
|
237
|
+
if (this.#eventsForJob.size > 0) {
|
|
238
|
+
throw new Error('PXE private event store rollback is not allowed while jobs are running');
|
|
239
|
+
}
|
|
240
|
+
|
|
237
241
|
// First pass: collect all event IDs for all blocks, starting reads during iteration to keep tx alive.
|
|
238
242
|
const eventsByBlock: Map<number, { eventId: string; eventReadPromise: Promise<Buffer | undefined> }[]> = new Map();
|
|
239
243
|
|
|
@@ -49,7 +49,7 @@ export class StoredPrivateEvent {
|
|
|
49
49
|
const msgContentLength = reader.readNumber();
|
|
50
50
|
const msgContent = reader.readArray(msgContentLength, Fr);
|
|
51
51
|
const l2BlockNumber = reader.readNumber();
|
|
52
|
-
const l2BlockHash =
|
|
52
|
+
const l2BlockHash = BlockHash.fromBuffer(reader);
|
|
53
53
|
const txHash = TxHash.fromBuffer(reader);
|
|
54
54
|
const txIndexInBlock = reader.readNumber();
|
|
55
55
|
const eventIndexInTx = reader.readNumber();
|
|
@@ -21,6 +21,8 @@ export async function loadPrivateLogsForSenderRecipientPair(
|
|
|
21
21
|
taggingStore: RecipientTaggingStore,
|
|
22
22
|
anchorBlockNumber: BlockNumber,
|
|
23
23
|
anchorBlockHash: BlockHash,
|
|
24
|
+
currentTimestamp: bigint,
|
|
25
|
+
finalizedBlockNumber: BlockNumber,
|
|
24
26
|
jobId: string,
|
|
25
27
|
): Promise<TxScopedL2Log[]> {
|
|
26
28
|
// # Explanation of how the algorithm works
|
|
@@ -61,20 +63,6 @@ export async function loadPrivateLogsForSenderRecipientPair(
|
|
|
61
63
|
// the highest finalized index. If that index was already used, they will throw an error. For this reason we
|
|
62
64
|
// don't have to look further than `highestFinalizedIndex + WINDOW_LEN`.
|
|
63
65
|
|
|
64
|
-
let finalizedBlockNumber: number, currentTimestamp: bigint;
|
|
65
|
-
{
|
|
66
|
-
const [l2Tips, latestBlockHeader] = await Promise.all([aztecNode.getL2Tips(), aztecNode.getBlockHeader('latest')]);
|
|
67
|
-
|
|
68
|
-
if (!latestBlockHeader) {
|
|
69
|
-
throw new Error('Node failed to return latest block header when syncing logs');
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
[finalizedBlockNumber, currentTimestamp] = [
|
|
73
|
-
l2Tips.finalized.block.number,
|
|
74
|
-
latestBlockHeader.globalVariables.timestamp,
|
|
75
|
-
];
|
|
76
|
-
}
|
|
77
|
-
|
|
78
66
|
let start: number, end: number;
|
|
79
67
|
{
|
|
80
68
|
const currentHighestAgedIndex = await taggingStore.getHighestAgedIndex(secret, jobId);
|
|
@@ -125,7 +113,9 @@ export async function loadPrivateLogsForSenderRecipientPair(
|
|
|
125
113
|
|
|
126
114
|
if (highestAgedIndex !== undefined && highestAgedIndex > highestFinalizedIndex) {
|
|
127
115
|
// This is just a sanity check as this should never happen.
|
|
128
|
-
throw new Error(
|
|
116
|
+
throw new Error(
|
|
117
|
+
`Highest aged index (${highestAgedIndex}) must not exceed highest finalized index (${highestFinalizedIndex})`,
|
|
118
|
+
);
|
|
129
119
|
}
|
|
130
120
|
|
|
131
121
|
await taggingStore.updateHighestFinalizedIndex(secret, highestFinalizedIndex, jobId);
|