Skip to content

Commit

Permalink
fix: dont kill coordination node only p2p node
Browse files Browse the repository at this point in the history
  • Loading branch information
Maddiaa0 committed Oct 23, 2024
1 parent f96e438 commit cfbbf13
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,4 @@ export interface ProverCoordination {
* @param quote - The quote to store
*/
addEpochProofQuote(quote: EpochProofQuote): Promise<void>;

/**
* Stops the prover coordination.
*/
stop(): Promise<void>;
}
2 changes: 1 addition & 1 deletion yarn-project/p2p/src/client/p2p_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ describe('In-Memory P2P Client', () => {
];

for (const quote of proofQuotes) {
client.addEpochProofQuote(quote);
await client.addEpochProofQuote(quote);
}
expect(epochProofQuotePool.addQuote).toBeCalledTimes(proofQuotes.length);

Expand Down
1 change: 1 addition & 0 deletions yarn-project/p2p/src/client/p2p_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ export class P2PClient extends WithTracer implements P2P {
}

#assertIsReady() {
// this.log.info('Checking if p2p client is ready, current state: ', this.currentState);
if (!this.isReady()) {
throw new Error('P2P client not ready');
}
Expand Down
11 changes: 8 additions & 3 deletions yarn-project/prover-node/src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,13 @@ export async function createProverNode(

// If config.p2pEnabled is true, createProverCoordination will create a p2p client where quotes will be shared and tx's requested
// If config.p2pEnabled is false, createProverCoordination request information from the AztecNode
const proverCoordination = deps.aztecNodeTxProvider
? deps.aztecNodeTxProvider
: await createProverCoordination(config, worldStateSynchronizer, archiver, telemetry);
const [proverCoordination, p2pClient] = await createProverCoordination(config, {
aztecNodeTxProvider: deps.aztecNodeTxProvider,
worldStateSynchronizer,
archiver,
telemetry,
});

const quoteProvider = createQuoteProvider(config);
const quoteSigner = createQuoteSigner(config);

Expand Down Expand Up @@ -83,6 +87,7 @@ export async function createProverNode(
claimsMonitor,
epochMonitor,
bondManager,
p2pClient,
telemetry,
proverNodeConfig,
);
Expand Down
49 changes: 39 additions & 10 deletions yarn-project/prover-node/src/prover-coordination/factory.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,60 @@
import { type ArchiveSource, type Archiver } from '@aztec/archiver';
import { BBCircuitVerifier, TestCircuitVerifier } from '@aztec/bb-prover';
import { type ProverCoordination, type WorldStateSynchronizer, createAztecNodeClient } from '@aztec/circuit-types';
import {
type AztecNode,
type ProverCoordination,
type WorldStateSynchronizer,
createAztecNodeClient,
} from '@aztec/circuit-types';
import { createDebugLogger } from '@aztec/foundation/log';
import { createP2PClient } from '@aztec/p2p';
import { type P2PClient, createP2PClient } from '@aztec/p2p';
import { type TelemetryClient } from '@aztec/telemetry-client';

import { type ProverNodeConfig } from '../config.js';

// We return a reference to the P2P client so that the prover node can stop the service when it shuts down.
type ProverCoordinationWithP2P = [ProverCoordination, P2PClient | undefined];
type ProverCoordinationDeps = {
aztecNodeTxProvider?: AztecNode;
worldStateSynchronizer?: WorldStateSynchronizer;
archiver?: Archiver | ArchiveSource;
telemetry?: TelemetryClient;
};

export async function createProverCoordination(
config: ProverNodeConfig,
worldStateSynchronizer: WorldStateSynchronizer,
archiver: Archiver | ArchiveSource,
telemetry: TelemetryClient,
): Promise<ProverCoordination> {
deps: ProverCoordinationDeps,
): Promise<ProverCoordinationWithP2P> {
const log = createDebugLogger('aztec:createProverCoordination');

if (deps.aztecNodeTxProvider) {
log.info('Using prover coordination via aztec node');
return [deps.aztecNodeTxProvider, undefined];
}

if (config.p2pEnabled) {
log.info('Using prover coordination via p2p');

if (!deps.archiver || !deps.worldStateSynchronizer || !deps.telemetry) {
throw new Error('Missing dependencies for p2p prover coordination');
}

const proofVerifier = config.realProofs ? await BBCircuitVerifier.new(config) : new TestCircuitVerifier();
const p2pClient = await createP2PClient(config, archiver, proofVerifier, worldStateSynchronizer, telemetry);
const p2pClient = await createP2PClient(
config,
deps.archiver,
proofVerifier,
deps.worldStateSynchronizer,
deps.telemetry,
);
await p2pClient.start();

return p2pClient;
} else if (config.proverCoordinationNodeUrl) {
return [p2pClient, p2pClient];
}

if (config.proverCoordinationNodeUrl) {
log.info('Using prover coordination via node url');
return createAztecNodeClient(config.proverCoordinationNodeUrl);
return [createAztecNodeClient(config.proverCoordinationNodeUrl), undefined];
} else {
throw new Error(`Aztec Node URL for Tx Provider is not set.`);
}
Expand Down
4 changes: 3 additions & 1 deletion yarn-project/prover-node/src/prover-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
import { type ContractDataSource } from '@aztec/circuits.js';
import { compact } from '@aztec/foundation/collection';
import { createDebugLogger } from '@aztec/foundation/log';
import { type P2PClient } from '@aztec/p2p';
import { type L1Publisher } from '@aztec/sequencer-client';
import { PublicProcessorFactory, type SimulationProvider } from '@aztec/simulator';
import { type TelemetryClient } from '@aztec/telemetry-client';
Expand Down Expand Up @@ -58,6 +59,7 @@ export class ProverNode implements ClaimsMonitorHandler, EpochMonitorHandler {
private readonly claimsMonitor: ClaimsMonitor,
private readonly epochsMonitor: EpochMonitor,
private readonly bondManager: BondManager,
private readonly p2pClient: P2PClient | undefined,
private readonly telemetryClient: TelemetryClient,
options: Partial<ProverNodeOptions> = {},
) {
Expand Down Expand Up @@ -169,7 +171,7 @@ export class ProverNode implements ClaimsMonitorHandler, EpochMonitorHandler {
this.publisher.interrupt();
await Promise.all(Array.from(this.jobs.values()).map(job => job.stop()));
await this.worldState.stop();
await this.coordination.stop();
await this.p2pClient?.stop();
this.log.info('Stopped ProverNode');
}

Expand Down

0 comments on commit cfbbf13

Please sign in to comment.