Skip to content

Commit

Permalink
refactor: remove prover-pool
Browse files Browse the repository at this point in the history
  • Loading branch information
alexghr committed May 29, 2024
1 parent defd2ba commit e6ee13b
Show file tree
Hide file tree
Showing 29 changed files with 306 additions and 368 deletions.
4 changes: 1 addition & 3 deletions yarn-project/aztec-node/src/aztec-node/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,7 @@ export class AztecNodeService implements AztecNode {

// start the prover if we have been told to
const simulationProvider = await getSimulationProvider(config, log);
const prover = config.disableProver
? await DummyProver.new()
: await TxProver.new(config, simulationProvider, worldStateSynchronizer);
const prover = config.disableProver ? await DummyProver.new() : await TxProver.new(config, worldStateSynchronizer);

// now create the sequencer
const sequencer = config.disableSequencer
Expand Down
1 change: 1 addition & 0 deletions yarn-project/aztec/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"@aztec/archiver": "workspace:^",
"@aztec/aztec-node": "workspace:^",
"@aztec/aztec.js": "workspace:^",
"@aztec/bb-prover": "workspace:^",
"@aztec/builder": "workspace:^",
"@aztec/circuit-types": "workspace:^",
"@aztec/circuits.js": "workspace:^",
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec/src/cli/cmds/start_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
import { NULL_KEY } from '@aztec/ethereum';
import { type ServerList } from '@aztec/foundation/json-rpc/server';
import { type LogFn } from '@aztec/foundation/log';
import { createProvingJobSourceServer } from '@aztec/prover-client/prover-pool';
import { createProvingJobSourceServer } from '@aztec/prover-client/prover-agent';
import { type PXEServiceConfig, createPXERpcServer, getPXEServiceConfig } from '@aztec/pxe';

import { mnemonicToAccount, privateKeyToAccount } from 'viem/accounts';
Expand Down
70 changes: 39 additions & 31 deletions yarn-project/aztec/src/cli/cmds/start_prover.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
import { type ProvingJobSource } from '@aztec/circuit-types';
import { ProverPool, createProvingJobSourceClient } from '@aztec/prover-client/prover-pool';

import { tmpdir } from 'node:os';
import { BBNativeRollupProver, TestCircuitProver } from '@aztec/bb-prover';
import { type ProvingJobSource, type ServerCircuitProver } from '@aztec/circuit-types';
import { type ProverClientConfig, getProverEnvVars } from '@aztec/prover-client';
import { ProverAgent, createProvingJobSourceClient } from '@aztec/prover-client/prover-agent';

import { type ServiceStarter, parseModuleOptions } from '../util.js';

type ProverOptions = Partial<{
proverUrl: string;
agents: string;
acvmBinaryPath?: string;
bbBinaryPath?: string;
simulate?: string;
}>;
type Options = ProverClientConfig &
Partial<{
proverUrl: string;
concurrency: string;
acvmBinaryPath?: string;
bbBinaryPath?: string;
}>;

export const startProver: ServiceStarter = async (options, signalHandlers, logger) => {
const proverOptions: ProverOptions = parseModuleOptions(options.prover);
const proverOptions: Options = {
proverUrl: process.env.AZTEC_NODE_URL,
...getProverEnvVars(),
...parseModuleOptions(options.prover),
};

let source: ProvingJobSource;

if (typeof proverOptions.proverUrl === 'string') {
Expand All @@ -24,31 +29,34 @@ export const startProver: ServiceStarter = async (options, signalHandlers, logge
throw new Error('Starting prover without an orchestrator is not supported');
}

const agentCount = proverOptions.agents ? parseInt(proverOptions.agents, 10) : 1;
if (agentCount === 0 || !Number.isSafeInteger(agentCount)) {
const maxConcurrency =
proverOptions.proverAgentMaxConcurrency ??
(proverOptions.concurrency ? parseInt(proverOptions.concurrency, 10) : 1);
if (maxConcurrency === 0 || !Number.isSafeInteger(maxConcurrency)) {
throw new Error('Cannot start prover without agents');
}

let pool: ProverPool;
if (proverOptions.simulate) {
pool = ProverPool.testPool(undefined, agentCount);
} else if (proverOptions.acvmBinaryPath && proverOptions.bbBinaryPath) {
pool = ProverPool.nativePool(
{
acvmBinaryPath: proverOptions.acvmBinaryPath,
bbBinaryPath: proverOptions.bbBinaryPath,
acvmWorkingDirectory: tmpdir(),
bbWorkingDirectory: tmpdir(),
},
agentCount,
);
let circuitProver: ServerCircuitProver;
if (proverOptions.realProofs) {
if (!proverOptions.acvmBinaryPath || !proverOptions.bbBinaryPath) {
throw new Error('Cannot start prover without simulation or native prover options');
}

circuitProver = await BBNativeRollupProver.new({
acvmBinaryPath: proverOptions.acvmBinaryPath,
bbBinaryPath: proverOptions.bbBinaryPath,
acvmWorkingDirectory: proverOptions.acvmWorkingDirectory,
bbWorkingDirectory: proverOptions.bbWorkingDirectory,
});
} else {
throw new Error('Cannot start prover without simulation or native prover options');
circuitProver = new TestCircuitProver();
}

logger(`Starting ${agentCount} prover agents`);
await pool.start(source);
signalHandlers.push(() => pool.stop());
const agent = new ProverAgent(circuitProver, maxConcurrency, proverOptions.proverAgentPollInterval);
agent.start(source);
logger(`Started prover agent with concurrency limit of ${maxConcurrency}`);

signalHandlers.push(() => agent.stop());

return Promise.resolve([]);
};
3 changes: 3 additions & 0 deletions yarn-project/aztec/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
{
"path": "../aztec.js"
},
{
"path": "../bb-prover"
},
{
"path": "../builder"
},
Expand Down
9 changes: 9 additions & 0 deletions yarn-project/bb-prover/src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export interface BBConfig {
bbBinaryPath: string;
bbWorkingDirectory: string;
}

export interface ACVMConfig {
acvmBinaryPath: string;
acvmWorkingDirectory: string;
}
1 change: 1 addition & 0 deletions yarn-project/bb-prover/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './prover/index.js';
export * from './test/index.js';
export * from './verifier/index.js';
export * from './config.js';
9 changes: 3 additions & 6 deletions yarn-project/bb-prover/src/prover/bb_prover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import {
verifyProof,
writeProofAsFields,
} from '../bb/execute.js';
import type { ACVMConfig, BBConfig } from '../config.js';
import { PublicKernelArtifactMapping } from '../mappings/mappings.js';
import { mapProtocolArtifactNameToCircuitName } from '../stats.js';
import { extractVkData } from '../verification_key/verification_key_data.js';
Expand All @@ -71,14 +72,10 @@ const logger = createDebugLogger('aztec:bb-prover');

const CIRCUITS_WITHOUT_AGGREGATION: Set<ServerProtocolArtifact> = new Set(['BaseParityArtifact']);

export type BBProverConfig = {
bbBinaryPath: string;
bbWorkingDirectory: string;
acvmBinaryPath: string;
acvmWorkingDirectory: string;
export interface BBProverConfig extends BBConfig, ACVMConfig {
// list of circuits supported by this prover. defaults to all circuits if empty
circuitFilter?: ServerProtocolArtifact[];
};
}

/**
* Prover implementation that uses barretenberg native proving
Expand Down
6 changes: 3 additions & 3 deletions yarn-project/bb-prover/src/verifier/bb_verifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import { type ProtocolArtifact, ProtocolCircuitArtifacts } from '@aztec/noir-pro
import * as fs from 'fs/promises';

import { BB_RESULT, generateContractForCircuit, generateKeyForNoirCircuit, verifyProof } from '../bb/execute.js';
import { type BBProverConfig } from '../prover/bb_prover.js';
import { type BBConfig } from '../config.js';
import { extractVkData } from '../verification_key/verification_key_data.js';

export class BBCircuitVerifier {
private constructor(
private config: BBProverConfig,
private config: BBConfig,
private verificationKeys = new Map<ProtocolArtifact, Promise<VerificationKeyData>>(),
private logger: DebugLogger,
) {}

public static async new(
config: BBProverConfig,
config: BBConfig,
initialCircuits: ProtocolArtifact[] = [],
logger = createDebugLogger('aztec:bb-verifier'),
) {
Expand Down
8 changes: 6 additions & 2 deletions yarn-project/circuit-types/src/interfaces/prover-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ import { type ProvingJobSource } from './proving-job.js';
* The prover configuration.
*/
export type ProverConfig = {
/** How many agents to run */
proverAgents: number;
/** Whether to construct real proofs */
realProofs: boolean;
/** Whether this prover has a local prover agent */
proverAgentEnabled: boolean;
/** The interval agents poll for jobs at */
proverAgentPollInterval: number;
/** The maximum number of proving jobs to be run in parallel */
proverAgentMaxConcurrency: number;
};

/**
Expand Down
19 changes: 2 additions & 17 deletions yarn-project/end-to-end/src/benchmarks/bench_prover.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { getSchnorrAccount, getSchnorrWallet } from '@aztec/accounts/schnorr';
import { type AztecNodeService } from '@aztec/aztec-node';
import { TxStatus } from '@aztec/aztec.js';
import { type AccountWallet } from '@aztec/aztec.js/wallet';
import { CompleteAddress, Fq, Fr } from '@aztec/circuits.js';
import { FPCContract, GasTokenContract, TestContract, TokenContract } from '@aztec/noir-contracts.js';
import { GasTokenAddress } from '@aztec/protocol-contracts/gas-token';
import { ProverPool } from '@aztec/prover-client/prover-pool';
import { type PXEService, createPXEService } from '@aztec/pxe';

import { jest } from '@jest/globals';
Expand Down Expand Up @@ -39,7 +37,6 @@ describe('benchmarks/proving', () => {

let acvmCleanup: () => Promise<void>;
let bbCleanup: () => Promise<void>;
let proverPool: ProverPool;

// setup the environment quickly using fake proofs
beforeAll(async () => {
Expand All @@ -48,7 +45,7 @@ describe('benchmarks/proving', () => {
{
// do setup with fake proofs
realProofs: false,
proverAgents: 4,
proverAgentMaxConcurrency: 4,
proverAgentPollInterval: 10,
minTxsPerBlock: 1,
},
Expand Down Expand Up @@ -110,25 +107,14 @@ describe('benchmarks/proving', () => {
acvmCleanup = acvmConfig.cleanup;
bbCleanup = bbConfig.cleanup;

proverPool = ProverPool.nativePool(
{
...acvmConfig,
...bbConfig,
},
2,
10,
);

ctx.logger.info('Stopping fake provers');
await ctx.aztecNode.setConfig({
// stop the fake provers
proverAgents: 0,
proverAgentMaxConcurrency: 1,
realProofs: true,
minTxsPerBlock: 2,
});

ctx.logger.info('Starting real provers');
await proverPool.start((ctx.aztecNode as AztecNodeService).getProver().getProvingJobSource());

ctx.logger.info('Starting PXEs configured with real proofs');
provingPxes = [];
Expand Down Expand Up @@ -161,7 +147,6 @@ describe('benchmarks/proving', () => {
for (const pxe of provingPxes) {
await pxe.stop();
}
await proverPool.stop();
await ctx.teardown();
await acvmCleanup();
await bbCleanup();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import { AvailabilityOracleAbi, InboxAbi, OutboxAbi, RollupAbi } from '@aztec/l1
import { SHA256Trunc, StandardTree } from '@aztec/merkle-tree';
import { TxProver } from '@aztec/prover-client';
import { type L1Publisher, getL1Publisher } from '@aztec/sequencer-client';
import { WASMSimulator } from '@aztec/simulator';
import { MerkleTrees, ServerWorldStateSynchronizer, type WorldStateConfig } from '@aztec/world-state';

import { beforeEach, describe, expect, it } from '@jest/globals';
Expand Down Expand Up @@ -145,7 +144,7 @@ describe('L1Publisher integration', () => {
};
const worldStateSynchronizer = new ServerWorldStateSynchronizer(tmpStore, builderDb, blockSource, worldStateConfig);
await worldStateSynchronizer.start();
builder = await TxProver.new(config, new WASMSimulator(), worldStateSynchronizer);
builder = await TxProver.new(config, worldStateSynchronizer);
l2Proof = makeEmptyProof();

publisher = getL1Publisher({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ describe('proof_verification', () => {
const acvm = await getACVMConfig(logger);

circuitVerifier = await BBCircuitVerifier.new({
acvmBinaryPath: acvm!.acvmBinaryPath,
acvmWorkingDirectory: acvm!.acvmWorkingDirectory,
bbBinaryPath: bb!.bbBinaryPath,
bbWorkingDirectory: bb!.bbWorkingDirectory,
});
Expand Down
17 changes: 1 addition & 16 deletions yarn-project/end-to-end/src/e2e_prover/e2e_prover_test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { SchnorrAccountContractArtifact, getSchnorrAccount } from '@aztec/accounts/schnorr';
import { type AztecNodeService } from '@aztec/aztec-node';
import {
type AccountWalletWithSecretKey,
type AztecNode,
Expand All @@ -18,7 +17,6 @@ import {
import { BBCircuitVerifier, BBNativeProofCreator } from '@aztec/bb-prover';
import { RollupAbi } from '@aztec/l1-artifacts';
import { TokenContract } from '@aztec/noir-contracts.js';
import { ProverPool } from '@aztec/prover-client/prover-pool';
import { type PXEService } from '@aztec/pxe';

// @ts-expect-error solc-js doesn't publish its types https://github.com/ethereum/solc-js/issues/689
Expand Down Expand Up @@ -67,7 +65,6 @@ export class FullProverTest {
tokenSim!: TokenSimulator;
aztecNode!: AztecNode;
pxe!: PXEService;
private proverPool!: ProverPool;
private provenComponents: ProvenSetup[] = [];
private bbConfigCleanup?: () => Promise<void>;
private acvmConfigCleanup?: () => Promise<void>;
Expand Down Expand Up @@ -156,25 +153,13 @@ export class FullProverTest {
...bbConfig,
});

this.proverPool = ProverPool.nativePool(
{
...acvmConfig,
...bbConfig,
},
4,
10,
);

this.logger.debug(`Configuring the node for real proofs...`);
await this.aztecNode.setConfig({
// stop the fake provers
proverAgents: 0,
proverAgentMaxConcurrency: 1,
realProofs: true,
minTxsPerBlock: 2, // min 2 txs per block
});

await this.proverPool.start((this.aztecNode as AztecNodeService).getProver().getProvingJobSource());

this.proofCreator = new BBNativeProofCreator(bbConfig.bbBinaryPath, bbConfig.bbWorkingDirectory);

this.logger.debug(`Main setup completed, initializing full prover PXE and Node...`);
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/prover-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "module",
"exports": {
".": "./dest/index.js",
"./prover-pool": "./dest/prover-pool/index.js"
"./prover-agent": "./dest/prover-agent/index.js"
},
"typedocOptions": {
"entryPoints": [
Expand Down
Loading

0 comments on commit e6ee13b

Please sign in to comment.