-
Notifications
You must be signed in to change notification settings - Fork 594
Expand file tree
/
Copy pathstart_prover_node.ts
More file actions
132 lines (112 loc) · 5.92 KB
/
start_prover_node.ts
File metadata and controls
132 lines (112 loc) · 5.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import { getInitialTestAccounts } from '@aztec/accounts/testing';
import { getSponsoredFPCAddress } from '@aztec/cli/cli-utils';
import { NULL_KEY } from '@aztec/ethereum';
import type { NamespacedApiHandlers } from '@aztec/foundation/json-rpc/server';
import { Agent, makeUndiciFetch } from '@aztec/foundation/json-rpc/undici';
import type { LogFn } from '@aztec/foundation/log';
import { ProvingJobConsumerSchema, createProvingJobBrokerClient } from '@aztec/prover-client/broker';
import {
type ProverNodeConfig,
createProverNode,
getProverNodeConfigFromEnv,
proverNodeConfigMappings,
} from '@aztec/prover-node';
import { createAztecNodeClient } from '@aztec/stdlib/interfaces/client';
import { P2PApiSchema, ProverNodeApiSchema, type ProvingJobBroker } from '@aztec/stdlib/interfaces/server';
import { initTelemetryClient, makeTracedFetch, telemetryClientConfigMappings } from '@aztec/telemetry-client';
import { getGenesisValues } from '@aztec/world-state/testing';
import { mnemonicToAccount } from 'viem/accounts';
import { getL1Config } from '../get_l1_config.js';
import { extractRelevantOptions, preloadCrsDataForVerifying } from '../util.js';
import { getVersions } from '../versioning.js';
import { startProverBroker } from './start_prover_broker.js';
export async function startProverNode(
options: any,
signalHandlers: (() => Promise<void>)[],
services: NamespacedApiHandlers,
userLog: LogFn,
): Promise<{ config: ProverNodeConfig }> {
if (options.node || options.sequencer || options.pxe || options.p2pBootstrap || options.txe) {
userLog(`Starting a prover-node with --node, --sequencer, --pxe, --p2p-bootstrap, or --txe is not supported.`);
process.exit(1);
}
let proverConfig = {
...getProverNodeConfigFromEnv(), // get default config from env
...extractRelevantOptions<ProverNodeConfig>(options, proverNodeConfigMappings, 'proverNode'), // override with command line options
};
if (!options.archiver && !proverConfig.archiverUrl) {
userLog('--archiver.archiverUrl is required to start a Prover Node without --archiver option');
process.exit(1);
}
if (!proverConfig.publisherPrivateKey || proverConfig.publisherPrivateKey === NULL_KEY) {
if (!options.l1Mnemonic) {
userLog(`--l1-mnemonic is required to start a Prover Node without --node.publisherPrivateKey`);
process.exit(1);
}
const hdAccount = mnemonicToAccount(options.l1Mnemonic);
const privKey = hdAccount.getHdKey().privateKey;
proverConfig.publisherPrivateKey = `0x${Buffer.from(privKey!).toString('hex')}`;
}
// TODO(palla/prover-node) L1 contract addresses should not silently default to zero,
// they should be undefined if not set and fail loudly.
// Load l1 contract addresses from aztec node if not set.
const isRollupAddressSet =
proverConfig.l1Contracts?.rollupAddress && !proverConfig.l1Contracts.rollupAddress.isZero();
const nodeUrl = proverConfig.nodeUrl ?? proverConfig.proverCoordinationNodeUrl;
if (nodeUrl && !isRollupAddressSet) {
userLog(`Loading L1 contract addresses from aztec node at ${nodeUrl}`);
proverConfig.l1Contracts = await createAztecNodeClient(nodeUrl).getL1ContractAddresses();
}
// If we create an archiver here, validate the L1 config
if (options.archiver) {
if (!proverConfig.l1Contracts.registryAddress || proverConfig.l1Contracts.registryAddress.isZero()) {
throw new Error('L1 registry address is required to start a Prover Node with --archiver option');
}
const { addresses, config } = await getL1Config(
proverConfig.l1Contracts.registryAddress,
proverConfig.l1RpcUrls,
proverConfig.l1ChainId,
proverConfig.rollupVersion,
);
proverConfig.l1Contracts = addresses;
proverConfig = { ...proverConfig, ...config };
}
const telemetry = initTelemetryClient(extractRelevantOptions(options, telemetryClientConfigMappings, 'tel'));
let broker: ProvingJobBroker;
if (proverConfig.proverBrokerUrl) {
// at 1TPS we'd enqueue ~1k tube proofs and ~1k AVM proofs immediately
// set a lower connectio limit such that we don't overload the server
const fetch = makeTracedFetch([1, 2, 3], false, makeUndiciFetch(new Agent({ connections: 100 })));
broker = createProvingJobBrokerClient(proverConfig.proverBrokerUrl, getVersions(proverConfig), fetch);
} 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`,
);
}
await preloadCrsDataForVerifying(proverConfig, userLog);
const testAccounts = proverConfig.testAccounts ? (await getInitialTestAccounts()).map(a => a.address) : [];
const sponsoredFPCAccounts = proverConfig.sponsoredFPC ? [await getSponsoredFPCAddress()] : [];
const initialFundedAccounts = testAccounts.concat(sponsoredFPCAccounts);
userLog(`Initial funded accounts: ${initialFundedAccounts.map(a => a.toString()).join(', ')}`);
const { genesisArchiveRoot, genesisBlockHash, prefilledPublicData } = await getGenesisValues(initialFundedAccounts);
userLog(`Genesis block hash: ${genesisBlockHash.toString()}`);
userLog(`Genesis archive root: ${genesisArchiveRoot.toString()}`);
const proverNode = await createProverNode(proverConfig, { telemetry, broker }, { prefilledPublicData });
services.proverNode = [proverNode, ProverNodeApiSchema];
const p2p = proverNode.getP2P();
if (p2p) {
services.p2p = [proverNode.getP2P(), P2PApiSchema];
}
if (!proverConfig.proverBrokerUrl) {
services.provingJobSource = [proverNode.getProver().getProvingJobSource(), ProvingJobConsumerSchema];
}
signalHandlers.push(proverNode.stop.bind(proverNode));
proverNode.start();
return { config: proverConfig };
}