Skip to content

Commit 4526059

Browse files
authored
chore: cleanup in AVM test fixture (#11850)
Pulls creation of WorldStateDB instance from `simulateTx` function into tester constructor, so that it isn't constructed again for every TX. This speeds up tests a bit, but not prod.
1 parent c26177f commit 4526059

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

yarn-project/bb-prover/src/avm_proving_tests/avm_proving_tester.ts

+15-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { type MerkleTreeWriteOperations } from '@aztec/circuit-types';
22
import { type AvmCircuitInputs, AztecAddress, VerificationKeyData } from '@aztec/circuits.js';
33
import { PublicTxSimulationTester, type TestEnqueuedCall } from '@aztec/simulator/public/fixtures';
4+
import { WorldStateDB } from '@aztec/simulator/server';
45
import { NativeWorldStateService } from '@aztec/world-state';
56

67
import fs from 'node:fs/promises';
@@ -25,21 +26,24 @@ export class AvmProvingTester extends PublicTxSimulationTester {
2526
constructor(
2627
private bbWorkingDirectory: string,
2728
private checkCircuitOnly: boolean,
29+
worldStateDB: WorldStateDB,
2830
contractDataSource: SimpleContractDataSource,
2931
merkleTrees: MerkleTreeWriteOperations,
3032
skipContractDeployments: boolean,
3133
) {
32-
super(contractDataSource, merkleTrees, skipContractDeployments);
34+
super(worldStateDB, contractDataSource, merkleTrees, skipContractDeployments);
3335
}
3436

3537
static override async create(checkCircuitOnly: boolean = false, skipContractDeployments: boolean = false) {
3638
const bbWorkingDirectory = await fs.mkdtemp(path.join(tmpdir(), 'bb-'));
3739

3840
const contractDataSource = new SimpleContractDataSource();
3941
const merkleTrees = await (await NativeWorldStateService.tmp()).fork();
42+
const worldStateDB = new WorldStateDB(merkleTrees, contractDataSource);
4043
return new AvmProvingTester(
4144
bbWorkingDirectory,
4245
checkCircuitOnly,
46+
worldStateDB,
4347
contractDataSource,
4448
merkleTrees,
4549
skipContractDeployments,
@@ -110,19 +114,27 @@ export class AvmProvingTester extends PublicTxSimulationTester {
110114
export class AvmProvingTesterV2 extends PublicTxSimulationTester {
111115
constructor(
112116
private bbWorkingDirectory: string,
117+
worldStateDB: WorldStateDB,
113118
contractDataSource: SimpleContractDataSource,
114119
merkleTrees: MerkleTreeWriteOperations,
115120
skipContractDeployments: boolean,
116121
) {
117-
super(contractDataSource, merkleTrees, skipContractDeployments);
122+
super(worldStateDB, contractDataSource, merkleTrees, skipContractDeployments);
118123
}
119124

120125
static override async create(skipContractDeployments: boolean = false) {
121126
const bbWorkingDirectory = await fs.mkdtemp(path.join(tmpdir(), 'bb-'));
122127

123128
const contractDataSource = new SimpleContractDataSource();
124129
const merkleTrees = await (await NativeWorldStateService.tmp()).fork();
125-
return new AvmProvingTesterV2(bbWorkingDirectory, contractDataSource, merkleTrees, skipContractDeployments);
130+
const worldStateDB = new WorldStateDB(merkleTrees, contractDataSource);
131+
return new AvmProvingTesterV2(
132+
bbWorkingDirectory,
133+
worldStateDB,
134+
contractDataSource,
135+
merkleTrees,
136+
skipContractDeployments,
137+
);
126138
}
127139

128140
async proveV2(avmCircuitInputs: AvmCircuitInputs): Promise<BBResult> {

yarn-project/simulator/src/public/fixtures/public_tx_simulation_tester.ts

+16-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { MerkleTreeId, PublicExecutionRequest, type Tx } from '@aztec/circuit-types';
1+
import { MerkleTreeId, type MerkleTreeWriteOperations, PublicExecutionRequest, type Tx } from '@aztec/circuit-types';
22
import {
33
type AvmCircuitPublicInputs,
44
CallContext,
@@ -43,10 +43,20 @@ export type TestEnqueuedCall = {
4343
export class PublicTxSimulationTester extends BaseAvmSimulationTester {
4444
private txCount = 0;
4545

46+
constructor(
47+
private worldStateDB: WorldStateDB,
48+
contractDataSource: SimpleContractDataSource,
49+
merkleTrees: MerkleTreeWriteOperations,
50+
skipContractDeployments: boolean,
51+
) {
52+
super(contractDataSource, merkleTrees, skipContractDeployments);
53+
}
54+
4655
public static async create(skipContractDeployments = false): Promise<PublicTxSimulationTester> {
4756
const contractDataSource = new SimpleContractDataSource();
4857
const merkleTrees = await (await NativeWorldStateService.tmp()).fork();
49-
return new PublicTxSimulationTester(contractDataSource, merkleTrees, skipContractDeployments);
58+
const worldStateDB = new WorldStateDB(merkleTrees, contractDataSource);
59+
return new PublicTxSimulationTester(worldStateDB, contractDataSource, merkleTrees, skipContractDeployments);
5060
}
5161

5262
public async simulateTx(
@@ -60,8 +70,7 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
6070
globals.timestamp = TIMESTAMP;
6171
globals.gasFees = DEFAULT_GAS_FEES;
6272

63-
const worldStateDB = new WorldStateDB(this.merkleTrees, this.contractDataSource);
64-
const simulator = new PublicTxSimulator(this.merkleTrees, worldStateDB, globals, /*doMerkleOperations=*/ true);
73+
const simulator = new PublicTxSimulator(this.merkleTrees, this.worldStateDB, globals, /*doMerkleOperations=*/ true);
6574

6675
const setupExecutionRequests: PublicExecutionRequest[] = [];
6776
for (let i = 0; i < setupCalls.length; i++) {
@@ -118,7 +127,10 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
118127
feePayer,
119128
);
120129

130+
const startTime = performance.now();
121131
const avmResult = await simulator.simulate(tx);
132+
const endTime = performance.now();
133+
this.logger.debug(`Public transaction simulation took ${endTime - startTime}ms`);
122134

123135
if (avmResult.revertCode.isOK()) {
124136
await this.commitTxStateUpdates(avmResult.avmProvingRequest.inputs.publicInputs);

0 commit comments

Comments
 (0)