Skip to content

Commit

Permalink
chore: Do not start prover node in e2e tests if not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
spalladino committed Oct 4, 2024
1 parent 931c59b commit e905c8a
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 51 deletions.
5 changes: 1 addition & 4 deletions yarn-project/end-to-end/src/e2e_fees/fees_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import {
TokenContract,
} from '@aztec/noir-contracts.js';
import { getCanonicalFeeJuice } from '@aztec/protocol-contracts/fee-juice';
import { type ProverNode } from '@aztec/prover-node';

import { getContract } from 'viem';

Expand All @@ -55,7 +54,6 @@ export class FeesTest {
public logger: DebugLogger;
public pxe!: PXE;
public aztecNode!: AztecNode;
public proverNode!: ProverNode;

public aliceWallet!: AccountWallet;
public aliceAddress!: AztecAddress;
Expand Down Expand Up @@ -175,10 +173,9 @@ export class FeesTest {
await this.snapshotManager.snapshot(
'initial_accounts',
addAccounts(3, this.logger),
async ({ accountKeys }, { pxe, aztecNode, aztecNodeConfig, proverNode }) => {
async ({ accountKeys }, { pxe, aztecNode, aztecNodeConfig }) => {
this.pxe = pxe;
this.aztecNode = aztecNode;
this.proverNode = proverNode;
const accountManagers = accountKeys.map(ak => getSchnorrAccount(pxe, ak[0], ak[1], 1));
await Promise.all(accountManagers.map(a => a.register()));
this.wallets = await Promise.all(accountManagers.map(a => a.getWallet()));
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/end-to-end/src/e2e_prover/e2e_prover_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class FullProverTest {
this.snapshotManager = createSnapshotManager(
`full_prover_integration/${testName}`,
dataPath,
{},
{ startProverNode: true },
{ assumeProvenThrough: undefined, useRealProofCommitmentEscrow: true },
);
}
Expand Down Expand Up @@ -155,10 +155,10 @@ export class FullProverTest {

async setup() {
this.context = await this.snapshotManager.setup();
this.simulatedProverNode = this.context.proverNode!;
({
pxe: this.pxe,
aztecNode: this.aztecNode,
proverNode: this.simulatedProverNode,
deployL1ContractsValues: this.l1Contracts,
cheatCodes: this.cheatCodes,
} = this.context);
Expand Down
41 changes: 23 additions & 18 deletions yarn-project/end-to-end/src/fixtures/snapshot_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export type SubsystemsContext = {
aztecNodeConfig: AztecNodeConfig;
pxe: PXEService;
deployL1ContractsValues: DeployL1Contracts;
proverNode: ProverNode;
proverNode?: ProverNode;
watcher: AnvilTestWatcher;
cheatCodes: CheatCodes;
};
Expand Down Expand Up @@ -251,15 +251,15 @@ async function teardown(context: SubsystemsContext | undefined) {
if (!context) {
return;
}
await context.proverNode.stop();
await context.proverNode?.stop();
await context.aztecNode.stop();
await context.pxe.stop();
await context.acvmConfig?.cleanup();
await context.anvil.stop();
await context.watcher.stop();
}

export async function createAndSyncProverNode(
async function createAndSyncProverNode(
proverNodePrivateKey: `0x${string}`,
aztecNodeConfig: AztecNodeConfig,
aztecNode: AztecNode,
Expand All @@ -281,8 +281,8 @@ export async function createAndSyncProverNode(
proverNodePollingIntervalMs: 200,
quoteProviderBasisPointFee: 100,
quoteProviderBondAmount: 1000n,
proverMinimumStakeAmount: 0n,
proverTargetStakeAmount: 0n,
proverMinimumStakeAmount: 1000n,
proverTargetStakeAmount: 2000n,
};
const proverNode = await createProverNode(proverConfig, {
aztecNodeTxProvider: aztecNode,
Expand All @@ -309,7 +309,7 @@ async function setupFromFresh(

// Fetch the AztecNode config.
// TODO: For some reason this is currently the union of a bunch of subsystems. That needs fixing.
const aztecNodeConfig: AztecNodeConfig = { ...getConfigEnvVars(), ...opts };
const aztecNodeConfig: AztecNodeConfig & SetupOptions = { ...getConfigEnvVars(), ...opts };
aztecNodeConfig.dataDirectory = statePath;

// Start anvil. We go via a wrapper script to ensure if the parent dies, anvil dies.
Expand Down Expand Up @@ -367,12 +367,15 @@ async function setupFromFresh(
logger.verbose('Creating and synching an aztec node...');
const aztecNode = await AztecNodeService.createAndSync(aztecNodeConfig, telemetry);

logger.verbose('Creating and syncing a simulated prover node...');
const proverNode = await createAndSyncProverNode(
`0x${proverNodePrivateKey!.toString('hex')}`,
aztecNodeConfig,
aztecNode,
);
let proverNode: ProverNode | undefined = undefined;
if (opts.startProverNode) {
logger.verbose('Creating and syncing a simulated prover node...');
proverNode = await createAndSyncProverNode(
`0x${proverNodePrivateKey!.toString('hex')}`,
aztecNodeConfig,
aztecNode,
);
}

logger.verbose('Creating pxe...');
const pxeConfig = getPXEServiceConfig();
Expand Down Expand Up @@ -416,7 +419,7 @@ async function setupFromState(statePath: string, logger: Logger): Promise<Subsys

// Load config.
// TODO: For some reason this is currently the union of a bunch of subsystems. That needs fixing.
const aztecNodeConfig: AztecNodeConfig = JSON.parse(
const aztecNodeConfig: AztecNodeConfig & SetupOptions = JSON.parse(
readFileSync(`${statePath}/aztec_node_config.json`, 'utf-8'),
reviver,
);
Expand Down Expand Up @@ -459,11 +462,13 @@ async function setupFromState(statePath: string, logger: Logger): Promise<Subsys
const telemetry = await createAndStartTelemetryClient(getTelemetryConfig());
const aztecNode = await AztecNodeService.createAndSync(aztecNodeConfig, telemetry);

const proverNodePrivateKey = getPrivateKeyFromIndex(2);
const proverNodePrivateKeyHex: Hex = `0x${proverNodePrivateKey!.toString('hex')}`;

logger.verbose('Creating and syncing a simulated prover node...');
const proverNode = await createAndSyncProverNode(proverNodePrivateKeyHex, aztecNodeConfig, aztecNode);
let proverNode: ProverNode | undefined = undefined;
if (aztecNodeConfig.startProverNode) {
logger.verbose('Creating and syncing a simulated prover node...');
const proverNodePrivateKey = getPrivateKeyFromIndex(2);
const proverNodePrivateKeyHex: Hex = `0x${proverNodePrivateKey!.toString('hex')}`;
proverNode = await createAndSyncProverNode(proverNodePrivateKeyHex, aztecNodeConfig, aztecNode);
}

logger.verbose('Creating pxe...');
const pxeConfig = getPXEServiceConfig();
Expand Down
2 changes: 2 additions & 0 deletions yarn-project/end-to-end/src/fixtures/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,8 @@ export type SetupOptions = {
l2StartTime?: number;
/** How far we should assume proven */
assumeProvenThrough?: number;
/** Whether to start a prover node */
startProverNode?: boolean;
} & Partial<AztecNodeConfig>;

/** Context for an end-to-end test as returned by the `setup` function */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@ describe('e2e_prover_coordination', () => {
snapshotManager = createSnapshotManager(
`prover_coordination/e2e_json_coordination`,
process.env.E2E_DATA_PATH,
{},
{
assumeProvenThrough: undefined,
},
{ startProverNode: true },
{ assumeProvenThrough: undefined },
);

await snapshotManager.snapshot('setup', addAccounts(2, logger), async ({ accountKeys }, ctx) => {
Expand All @@ -80,7 +78,7 @@ describe('e2e_prover_coordination', () => {

ctx = await snapshotManager.setup();

await ctx.proverNode.stop();
await ctx.proverNode!.stop();

cc = new EthCheatCodes(ctx.aztecNodeConfig.l1RpcUrl);

Expand Down Expand Up @@ -195,7 +193,7 @@ describe('e2e_prover_coordination', () => {
});

// Send in the quote
await ctx.proverNode.sendEpochProofQuote(quoteForEpoch0);
await ctx.proverNode!.sendEpochProofQuote(quoteForEpoch0);

// Build a block, this should NOT use the above quote as it is for the current epoch (0)
await contract.methods.create_note(recipient, recipient, 10).send().wait();
Expand Down Expand Up @@ -272,7 +270,7 @@ describe('e2e_prover_coordination', () => {

const allQuotes = [proofQuoteInvalidSlot, proofQuoteInvalidEpoch, ...validQuotes, proofQuoteInsufficientBond];

await Promise.all(allQuotes.map(x => ctx.proverNode.sendEpochProofQuote(x)));
await Promise.all(allQuotes.map(x => ctx.proverNode!.sendEpochProofQuote(x)));

// now build another block and we should see the best valid quote being published
await contract.methods.create_note(recipient, recipient, 10).send().wait();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { createAccounts } from '@aztec/accounts/testing';
import { type AztecNodeConfig } from '@aztec/aztec-node';
import { type AztecNode, type DebugLogger, Fr, type PXE } from '@aztec/aztec.js';
import { NULL_KEY } from '@aztec/ethereum';
import { type DebugLogger, Fr, type PXE } from '@aztec/aztec.js';
import { EasyPrivateTokenContract } from '@aztec/noir-contracts.js';
import { type ProverNode, type ProverNodeConfig, getProverNodeConfigFromEnv } from '@aztec/prover-node';

import { foundry, sepolia } from 'viem/chains';

import { createAndSyncProverNode } from '../fixtures/snapshot_manager.js';
import { getPrivateKeyFromIndex, setup } from '../fixtures/utils.js';
import { setup } from '../fixtures/utils.js';

// process.env.SEQ_PUBLISHER_PRIVATE_KEY = '<PRIVATE_KEY_WITH_SEPOLIA_ETH>';
// process.env.PROVER_PUBLISHER_PRIVATE_KEY = '<PRIVATE_KEY_WITH_SEPOLIA_ETH>';
Expand All @@ -18,10 +14,6 @@ import { getPrivateKeyFromIndex, setup } from '../fixtures/utils.js';
describe(`deploys and transfers a private only token`, () => {
let secretKey1: Fr;
let secretKey2: Fr;
let proverConfig: ProverNodeConfig;
let config: AztecNodeConfig;
let aztecNode: AztecNode;
let proverNode: ProverNode;

let pxe: PXE;
let logger: DebugLogger;
Expand All @@ -30,25 +22,16 @@ describe(`deploys and transfers a private only token`, () => {
beforeEach(async () => {
const chainId = !process.env.L1_CHAIN_ID ? foundry.id : +process.env.L1_CHAIN_ID;
const chain = chainId == sepolia.id ? sepolia : foundry; // Not the best way of doing this.
({ logger, pxe, teardown, config, aztecNode } = await setup(
({ logger, pxe, teardown } = await setup(
0,
{ skipProtocolContracts: true, stateLoad: undefined },
{},
false,
chain,
));
proverConfig = getProverNodeConfigFromEnv();
const proverNodePrivateKey = getPrivateKeyFromIndex(2);
proverConfig.publisherPrivateKey =
proverConfig.publisherPrivateKey === NULL_KEY
? `0x${proverNodePrivateKey?.toString('hex')}`
: proverConfig.publisherPrivateKey;

proverNode = await createAndSyncProverNode(proverConfig.publisherPrivateKey, config, aztecNode);
}, 600_000);

afterEach(async () => {
await proverNode.stop();
await teardown();
});

Expand Down

0 comments on commit e905c8a

Please sign in to comment.