From 2a834ba8fb8389135e597c2bb39cc1b871bbdfc9 Mon Sep 17 00:00:00 2001 From: Alex Gherghisan Date: Tue, 26 Nov 2024 15:28:40 +0000 Subject: [PATCH] refactor: prover broker host --- docker-compose.provernet.yml | 4 +-- .../aztec-network/templates/prover-agent.yaml | 1 - .../aztec-network/templates/prover-node.yaml | 3 -- .../aztec/src/cli/cmds/start_prover_broker.ts | 6 ++-- .../aztec/src/cli/cmds/start_prover_node.ts | 29 ++++++++++++------- .../src/interfaces/prover-agent.ts | 2 +- .../src/interfaces/prover-broker.ts | 7 ----- .../scripts/native-network/prover-node.sh | 3 +- yarn-project/foundation/src/config/env_var.ts | 3 +- yarn-project/prover-client/src/config.ts | 13 +-------- 10 files changed, 28 insertions(+), 43 deletions(-) diff --git a/docker-compose.provernet.yml b/docker-compose.provernet.yml index 7b398b0b0a37..372d2602e9eb 100644 --- a/docker-compose.provernet.yml +++ b/docker-compose.provernet.yml @@ -66,7 +66,7 @@ services: ARCHIVER_VIEM_POLLING_INTERVAL_MS: 1000 PROVER_VIEM_POLLING_INTERVAL_MS: 1000 PROVER_AGENT_COUNT: 0 - PROVER_BROKER_URL: http://aztec-prover-broker + PROVER_BROKER_HOST: http://aztec-prover-broker PROVER_PUBLISHER_PRIVATE_KEY: "0xdbda1821b80551c9d65939329250298aa3472ba22feea921c0cf5d620ea67b97" PROVER_REAL_PROOFS: "${PROVER_REAL_PROOFS:-false}" PROVER_MINIMUM_ESCROW_AMOUNT: 1000000000 @@ -111,7 +111,7 @@ services: environment: LOG_LEVEL: verbose ETHEREUM_HOST: http://ethereum:8545 - PROVER_BROKER_URL: http://aztec-prover-broker + PROVER_BROKER_HOST: http://aztec-prover-broker L1_CHAIN_ID: 31337 AZTEC_PORT: 80 PROVER_REAL_PROOFS: "${PROVER_REAL_PROOFS:-false}" diff --git a/spartan/aztec-network/templates/prover-agent.yaml b/spartan/aztec-network/templates/prover-agent.yaml index 1367340c7054..ef080501868c 100644 --- a/spartan/aztec-network/templates/prover-agent.yaml +++ b/spartan/aztec-network/templates/prover-agent.yaml @@ -77,7 +77,6 @@ spec: - "-c" - | source /shared/config/service-addresses && \ - PROVER_BROKER_URL=${PROVER_NODE_HOST} \ node --no-warnings /usr/src/yarn-project/aztec/dest/bin/index.js start --prover-agent env: - name: AZTEC_PORT diff --git a/spartan/aztec-network/templates/prover-node.yaml b/spartan/aztec-network/templates/prover-node.yaml index 4a3ab02bf19d..bf13dad18219 100644 --- a/spartan/aztec-network/templates/prover-node.yaml +++ b/spartan/aztec-network/templates/prover-node.yaml @@ -142,9 +142,6 @@ spec: value: "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" - name: OTEL_RESOURCE_ATTRIBUTES value: service.name={{ .Release.Name }},service.namespace={{ .Release.Namespace }},service.version={{ .Chart.AppVersion }},environment={{ .Values.environment | default "production" }} - # get private proofs from the boot node - - name: PROVER_JOB_SOURCE_URL - value: "http://$(POD_IP):{{ .Values.proverNode.service.nodePort }}" - name: OTEL_EXPORTER_OTLP_METRICS_ENDPOINT value: {{ include "aztec-network.otelCollectorMetricsEndpoint" . | quote }} - name: OTEL_EXPORTER_OTLP_TRACES_ENDPOINT diff --git a/yarn-project/aztec/src/cli/cmds/start_prover_broker.ts b/yarn-project/aztec/src/cli/cmds/start_prover_broker.ts index 26535a7b10a0..197d48971c91 100644 --- a/yarn-project/aztec/src/cli/cmds/start_prover_broker.ts +++ b/yarn-project/aztec/src/cli/cmds/start_prover_broker.ts @@ -1,4 +1,4 @@ -import { type ProverBrokerConfig, proverBrokerConfigMappings } from '@aztec/circuit-types'; +import { type ProverBrokerConfig, type ProvingJobBroker, proverBrokerConfigMappings } from '@aztec/circuit-types'; import { type NamespacedApiHandlers } from '@aztec/foundation/json-rpc/server'; import { type LogFn } from '@aztec/foundation/log'; import { ProvingJobBrokerSchema, createAndStartProvingBroker } from '@aztec/prover-client/broker'; @@ -11,7 +11,7 @@ export async function startProverBroker( signalHandlers: (() => Promise)[], services: NamespacedApiHandlers, userLog: LogFn, -) { +): Promise { if (options.node || options.sequencer || options.pxe || options.p2pBootstrap || options.txe) { userLog(`Starting a prover broker with --node, --sequencer, --pxe, --p2p-bootstrap, or --txe is not supported.`); process.exit(1); @@ -27,4 +27,6 @@ export async function startProverBroker( signalHandlers.push(() => broker.stop()); await broker.start(); + + return broker; } diff --git a/yarn-project/aztec/src/cli/cmds/start_prover_node.ts b/yarn-project/aztec/src/cli/cmds/start_prover_node.ts index 44aa13eee931..0d6fa266edc8 100644 --- a/yarn-project/aztec/src/cli/cmds/start_prover_node.ts +++ b/yarn-project/aztec/src/cli/cmds/start_prover_node.ts @@ -1,4 +1,4 @@ -import { ProverNodeApiSchema, createAztecNodeClient } from '@aztec/circuit-types'; +import { ProverNodeApiSchema, type ProvingJobBroker, createAztecNodeClient } from '@aztec/circuit-types'; import { NULL_KEY } from '@aztec/ethereum'; import { type NamespacedApiHandlers } from '@aztec/foundation/json-rpc/server'; import { type LogFn } from '@aztec/foundation/log'; @@ -14,6 +14,7 @@ import { createAndStartTelemetryClient, telemetryClientConfigMappings } from '@a import { mnemonicToAccount } from 'viem/accounts'; import { extractRelevantOptions } from '../util.js'; +import { startProverBroker } from './start_prover_broker.js'; export async function startProverNode( options: any, @@ -36,14 +37,6 @@ export async function startProverNode( process.exit(1); } - if (options.prover || options.proverAgentEnabled) { - userLog(`Running prover node with local prover agent.`); - proverConfig.proverAgentCount = 1; - } else { - userLog(`Running prover node without local prover agent. Connect one or more prover agents to this node.`); - proverConfig.proverAgentCount = 0; - } - if (!proverConfig.publisherPrivateKey || proverConfig.publisherPrivateKey === NULL_KEY) { if (!options.l1Mnemonic) { userLog(`--l1-mnemonic is required to start a Prover Node without --node.publisherPrivateKey`); @@ -69,9 +62,23 @@ export async function startProverNode( extractRelevantOptions(options, telemetryClientConfigMappings, 'tel'), ); - const broker = proverConfig.proverBrokerUrl ? createProvingJobBrokerClient(proverConfig.proverBrokerUrl) : undefined; - const proverNode = await createProverNode(proverConfig, { telemetry, broker }); + let broker: ProvingJobBroker; + if (proverConfig.proverBrokerUrl) { + broker = createProvingJobBrokerClient(proverConfig.proverBrokerUrl); + } else if (options.proverBroker) { + broker = await startProverBroker(options, signalHandlers, services, userLog); + } else { + userLog(`--prover-broker-url or --prover-broker is required to start a Prover Node`); + process.exit(1); + } + if (proverConfig.proverAgentCount === 0) { + userLog( + `Running prover node without local prover agent. Connect one or more prover agents to this node or pass --proverAgent.proverAgentCount`, + ); + } + + const proverNode = await createProverNode(proverConfig, { telemetry, broker }); services.proverNode = [proverNode, ProverNodeApiSchema]; if (!proverConfig.proverBrokerUrl) { diff --git a/yarn-project/circuit-types/src/interfaces/prover-agent.ts b/yarn-project/circuit-types/src/interfaces/prover-agent.ts index c0fe9a76160a..7a2cb519a9e2 100644 --- a/yarn-project/circuit-types/src/interfaces/prover-agent.ts +++ b/yarn-project/circuit-types/src/interfaces/prover-agent.ts @@ -43,7 +43,7 @@ export const proverAgentConfigMappings: ConfigMappingsType = .filter(v => typeof v === 'number'), }, proverBrokerUrl: { - env: 'PROVER_BROKER_URL', + env: 'PROVER_BROKER_HOST', description: 'The URL where this agent takes jobs from', }, realProofs: { diff --git a/yarn-project/circuit-types/src/interfaces/prover-broker.ts b/yarn-project/circuit-types/src/interfaces/prover-broker.ts index 06457fdb1e17..5f11be3347ed 100644 --- a/yarn-project/circuit-types/src/interfaces/prover-broker.ts +++ b/yarn-project/circuit-types/src/interfaces/prover-broker.ts @@ -11,8 +11,6 @@ import { type ConfigMappingsType, numberConfigHelper } from '@aztec/foundation/c import { z } from 'zod'; export const ProverBrokerConfig = z.object({ - /** Whether to enable the prover broker */ - proverBrokerEnabled: z.boolean(), /** If starting a prover broker locally, the max number of retries per proving job */ proverBrokerJobMaxRetries: z.number(), /** If starting a prover broker locally, the time after which a job times out and gets assigned to a different agent */ @@ -26,11 +24,6 @@ export const ProverBrokerConfig = z.object({ export type ProverBrokerConfig = z.infer; export const proverBrokerConfigMappings: ConfigMappingsType = { - proverBrokerEnabled: { - env: 'PROVER_BROKER_ENABLED', - description: 'Whether to enable the prover broker', - ...numberConfigHelper(1), - }, proverBrokerJobTimeoutMs: { env: 'PROVER_BROKER_JOB_TIMEOUT_MS', description: 'Jobs are retried if not kept alive for this long', diff --git a/yarn-project/end-to-end/scripts/native-network/prover-node.sh b/yarn-project/end-to-end/scripts/native-network/prover-node.sh index 774ffcbe6178..1fa0ac6865c8 100755 --- a/yarn-project/end-to-end/scripts/native-network/prover-node.sh +++ b/yarn-project/end-to-end/scripts/native-network/prover-node.sh @@ -36,7 +36,6 @@ export LOG_LEVEL=${LOG_LEVEL:-"debug"} export DEBUG=${DEBUG:-"aztec:*,-aztec:avm_simulator*,-aztec:libp2p_service*,-aztec:circuits:artifact_hash,-json-rpc*,-aztec:l2_block_stream,-aztec:world-state:*"} export ETHEREUM_HOST="http://127.0.0.1:8545" export PROVER_AGENT_COUNT="1" -export PROVER_BROKER_ENABLED="true" export PROVER_PUBLISHER_PRIVATE_KEY="0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" export PROVER_COORDINATION_NODE_URL="http://127.0.0.1:8080" export AZTEC_NODE_URL="http://127.0.0.1:8080" @@ -46,4 +45,4 @@ export OTEL_EXPORTER_OTLP_TRACES_ENDPOINT="${OTEL_EXPORTER_OTLP_TRACES_ENDPOINT: export OTEL_EXPORTER_OTLP_LOGS_ENDPOINT="${OTEL_EXPORTER_OTLP_LOGS_ENDPOINT:-}" # Start the Prover Node with the prover and archiver -node --no-warnings "$REPO"/yarn-project/aztec/dest/bin/index.js start --port="$PORT" --prover-node --archiver +node --no-warnings "$REPO"/yarn-project/aztec/dest/bin/index.js start --port="$PORT" --prover-node --prover-broker --archiver diff --git a/yarn-project/foundation/src/config/env_var.ts b/yarn-project/foundation/src/config/env_var.ts index 595b112134cc..1456a668ed44 100644 --- a/yarn-project/foundation/src/config/env_var.ts +++ b/yarn-project/foundation/src/config/env_var.ts @@ -102,7 +102,7 @@ export type EnvVar = | 'PROVER_AGENT_COUNT' | 'PROVER_AGENT_PROOF_TYPES' | 'PROVER_AGENT_POLL_INTERVAL_MS' - | 'PROVER_BROKER_URL' + | 'PROVER_BROKER_HOST' | 'PROVER_BROKER_ENABLED' | 'PROVER_BROKER_JOB_TIMEOUT_MS' | 'PROVER_BROKER_POLL_INTERVAL_MS' @@ -113,7 +113,6 @@ export type EnvVar = | 'PROVER_ID' | 'PROVER_JOB_POLL_INTERVAL_MS' | 'PROVER_JOB_TIMEOUT_MS' - | 'PROVER_JOB_SOURCE_URL' | 'PROVER_NODE_POLLING_INTERVAL_MS' | 'PROVER_NODE_MAX_PENDING_JOBS' | 'PROVER_PUBLISH_RETRY_INTERVAL_MS' diff --git a/yarn-project/prover-client/src/config.ts b/yarn-project/prover-client/src/config.ts index 8d64bde6cb2e..347301ebb26b 100644 --- a/yarn-project/prover-client/src/config.ts +++ b/yarn-project/prover-client/src/config.ts @@ -12,14 +12,7 @@ import { type ConfigMappingsType, booleanConfigHelper, getConfigFromMappings } f /** * The prover configuration. */ -export type ProverClientConfig = ProverConfig & - ProverAgentConfig & - ProverBrokerConfig & - BBConfig & - ACVMConfig & { - /** The URL to the Aztec prover node to take proving jobs from */ - proverJobSourceUrl?: string; - }; +export type ProverClientConfig = ProverConfig & ProverAgentConfig & ProverBrokerConfig & BBConfig & ACVMConfig; export const bbConfigMappings: ConfigMappingsType = { acvmWorkingDirectory: { @@ -46,10 +39,6 @@ export const bbConfigMappings: ConfigMappingsType = { }; export const proverClientConfigMappings: ConfigMappingsType = { - proverJobSourceUrl: { - env: 'PROVER_JOB_SOURCE_URL', - description: 'The URL to the Aztec prover node to take proving jobs from', - }, ...bbConfigMappings, ...proverConfigMappings, ...proverAgentConfigMappings,