@aztec/prover-node 1.2.0 → 2.0.0-nightly.20250813

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dest/config.d.ts +2 -2
  2. package/dest/config.d.ts.map +1 -1
  3. package/dest/config.js +5 -2
  4. package/dest/factory.d.ts +8 -6
  5. package/dest/factory.d.ts.map +1 -1
  6. package/dest/factory.js +22 -14
  7. package/dest/job/epoch-proving-job-data.d.ts +3 -2
  8. package/dest/job/epoch-proving-job-data.d.ts.map +1 -1
  9. package/dest/job/epoch-proving-job-data.js +12 -5
  10. package/dest/job/epoch-proving-job.d.ts +1 -0
  11. package/dest/job/epoch-proving-job.d.ts.map +1 -1
  12. package/dest/job/epoch-proving-job.js +10 -10
  13. package/dest/prover-node-publisher.d.ts +2 -4
  14. package/dest/prover-node-publisher.d.ts.map +1 -1
  15. package/dest/prover-node-publisher.js +4 -2
  16. package/dest/prover-node.d.ts +6 -8
  17. package/dest/prover-node.d.ts.map +1 -1
  18. package/dest/prover-node.js +24 -35
  19. package/package.json +21 -21
  20. package/src/config.ts +6 -4
  21. package/src/factory.ts +46 -23
  22. package/src/job/epoch-proving-job-data.ts +13 -5
  23. package/src/job/epoch-proving-job.ts +11 -8
  24. package/src/prover-node-publisher.ts +14 -6
  25. package/src/prover-node.ts +19 -40
  26. package/dest/prover-coordination/combined-prover-coordination.d.ts +0 -22
  27. package/dest/prover-coordination/combined-prover-coordination.d.ts.map +0 -1
  28. package/dest/prover-coordination/combined-prover-coordination.js +0 -140
  29. package/dest/prover-coordination/config.d.ts +0 -7
  30. package/dest/prover-coordination/config.d.ts.map +0 -1
  31. package/dest/prover-coordination/config.js +0 -12
  32. package/dest/prover-coordination/factory.d.ts +0 -23
  33. package/dest/prover-coordination/factory.d.ts.map +0 -1
  34. package/dest/prover-coordination/factory.js +0 -52
  35. package/dest/prover-coordination/index.d.ts +0 -3
  36. package/dest/prover-coordination/index.d.ts.map +0 -1
  37. package/dest/prover-coordination/index.js +0 -2
  38. package/src/prover-coordination/combined-prover-coordination.ts +0 -164
  39. package/src/prover-coordination/config.ts +0 -18
  40. package/src/prover-coordination/factory.ts +0 -86
  41. package/src/prover-coordination/index.ts +0 -2
@@ -1,140 +0,0 @@
1
- import { asyncPool } from '@aztec/foundation/async-pool';
2
- import { createLogger } from '@aztec/foundation/log';
3
- import { TxHash } from '@aztec/stdlib/tx';
4
- // Wraps the p2p client into a coordination pool
5
- class P2PCoordinationPool {
6
- p2p;
7
- constructor(p2p){
8
- this.p2p = p2p;
9
- }
10
- getTxsByHash(txHashes) {
11
- return this.p2p.getTxsByHash(txHashes, undefined);
12
- }
13
- hasTxsInPool(txHashes) {
14
- return this.p2p.hasTxsInPool(txHashes);
15
- }
16
- getTxsByHashFromPool(txHashes) {
17
- return this.p2p.getTxsByHashFromPool(txHashes);
18
- }
19
- addTxs(txs) {
20
- return this.p2p.addTxsToPool(txs);
21
- }
22
- }
23
- // Wraps an in memory tx pool into a coordination pool. Used for testing when no p2p/tx pool is available.
24
- class InMemoryCoordinationPool {
25
- txs = new Map();
26
- getTxsByHash(txHashes) {
27
- return Promise.resolve(txHashes.map((hash)=>this.txs.get(hash.toString())));
28
- }
29
- hasTxsInPool(txHashes) {
30
- return Promise.resolve(txHashes.map((hash)=>this.txs.has(hash.toString())));
31
- }
32
- getTxsByHashFromPool(txHashes) {
33
- return this.getTxsByHash(txHashes);
34
- }
35
- async addTxs(txs) {
36
- const hashes = await Promise.all(txs.map((tx)=>tx.getTxHash()));
37
- txs.forEach((tx, index)=>this.txs.set(hashes[index].toString(), tx));
38
- return txs.length;
39
- }
40
- }
41
- // Class to implement combined transaction retrieval from p2p and any available nodes
42
- export class CombinedProverCoordination {
43
- p2p;
44
- aztecNodes;
45
- options;
46
- log;
47
- constructor(p2p, aztecNodes, options = {
48
- txGatheringBatchSize: 10,
49
- txGatheringMaxParallelRequestsPerNode: 10
50
- }, log = createLogger('prover-node:combined-prover-coordination')){
51
- this.p2p = p2p;
52
- this.aztecNodes = aztecNodes;
53
- this.options = options;
54
- this.log = log;
55
- }
56
- getP2PClient() {
57
- return this.p2p;
58
- }
59
- async getTxsByHash(txHashes) {
60
- const pool = this.p2p ? new P2PCoordinationPool(this.p2p) : new InMemoryCoordinationPool();
61
- await this.#gatherTxs(txHashes, pool);
62
- const availability = await pool.hasTxsInPool(txHashes);
63
- const notFound = txHashes.filter((_, index)=>!availability[index]);
64
- if (notFound.length > 0) {
65
- throw new Error(`Could not find txs: ${notFound.map((tx)=>tx.toString())}`);
66
- }
67
- const txs = await pool.getTxsByHashFromPool(txHashes);
68
- return txs.filter((tx)=>tx !== undefined);
69
- }
70
- async gatherTxs(txHashes) {
71
- const pool = this.p2p ? new P2PCoordinationPool(this.p2p) : new InMemoryCoordinationPool();
72
- await this.#gatherTxs(txHashes, pool);
73
- }
74
- async #gatherTxs(txHashes, pool) {
75
- const availability = await pool.hasTxsInPool(txHashes);
76
- const notFound = txHashes.filter((_, index)=>!availability[index]);
77
- const txsToFind = new Set(notFound.map((tx)=>tx.toString()));
78
- if (txsToFind.size === 0) {
79
- this.log.info(`Check for ${txHashes.length} txs found all in the pool`);
80
- return;
81
- }
82
- this.log.info(`Check for ${txHashes.length} txs found ${txsToFind.size} missing. Will gather from nodes and p2p`);
83
- const originalToFind = txsToFind.size;
84
- await this.#gatherTxsFromAllNodes(txsToFind, pool);
85
- if (txsToFind.size === 0) {
86
- this.log.info(`Found all ${originalToFind} txs directly from nodes`);
87
- return;
88
- }
89
- const toFindFromP2P = txsToFind.size;
90
- this.log.verbose(`Gathering ${toFindFromP2P} txs from p2p network`);
91
- const foundFromP2P = await pool.getTxsByHash([
92
- ...txsToFind
93
- ].map((tx)=>TxHash.fromString(tx)));
94
- // TODO(!!): test for this
95
- // getTxsByHash returns undefined for transactions that are not found, so it must be filtered to find the true length
96
- const foundFromP2PLength = foundFromP2P.filter((tx)=>!!tx).length;
97
- const numFoundFromNodes = originalToFind - toFindFromP2P;
98
- const numNotFound = toFindFromP2P - foundFromP2PLength;
99
- if (numNotFound === 0) {
100
- this.log.info(`Found all ${originalToFind} txs. ${numFoundFromNodes} from nodes, ${foundFromP2PLength} from p2p`);
101
- return;
102
- }
103
- this.log.warn(`Failed to find ${numNotFound} txs from any source. Found ${foundFromP2PLength} from p2p and ${numFoundFromNodes} from nodes`);
104
- }
105
- async #gatherTxsFromAllNodes(txsToFind, pool) {
106
- if (txsToFind.size === 0 || this.aztecNodes.length === 0) {
107
- return;
108
- }
109
- await Promise.all(this.aztecNodes.map((aztecNode)=>this.#gatherTxsFromNode(txsToFind, aztecNode, pool)));
110
- }
111
- async #gatherTxsFromNode(txsToFind, aztecNode, pool) {
112
- const totalTxsRequired = txsToFind.size;
113
- // It's possible that the set is empty as we already found the txs
114
- if (totalTxsRequired === 0) {
115
- return;
116
- }
117
- let totalTxsGathered = 0;
118
- const batches = [];
119
- const allTxs = [
120
- ...txsToFind
121
- ];
122
- while(allTxs.length){
123
- const batch = allTxs.splice(0, this.options.txGatheringBatchSize);
124
- batches.push(batch);
125
- }
126
- await asyncPool(this.options.txGatheringMaxParallelRequestsPerNode, batches, async (batch)=>{
127
- try {
128
- const txs = (await aztecNode.getTxsByHash(batch.map((b)=>TxHash.fromString(b)))).filter((tx)=>!!tx);
129
- const hashes = await Promise.all(txs.map((tx)=>tx.getTxHash()));
130
- await pool.addTxs(txs);
131
- hashes.forEach((hash)=>txsToFind.delete(hash.toString()));
132
- totalTxsGathered += txs.length;
133
- } catch (err) {
134
- this.log.error(`Error gathering txs from aztec node: ${err}`);
135
- return;
136
- }
137
- });
138
- this.log.verbose(`Gathered ${totalTxsGathered} of ${totalTxsRequired} txs from a node`);
139
- }
140
- }
@@ -1,7 +0,0 @@
1
- import { type ConfigMappingsType } from '@aztec/foundation/config';
2
- export type ProverCoordinationConfig = {
3
- proverCoordinationNodeUrls: string[];
4
- };
5
- export declare const proverCoordinationConfigMappings: ConfigMappingsType<ProverCoordinationConfig>;
6
- export declare function getTxProviderConfigFromEnv(): ProverCoordinationConfig;
7
- //# sourceMappingURL=config.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/prover-coordination/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,kBAAkB,EAAyB,MAAM,0BAA0B,CAAC;AAE1F,MAAM,MAAM,wBAAwB,GAAG;IACrC,0BAA0B,EAAE,MAAM,EAAE,CAAC;CACtC,CAAC;AAEF,eAAO,MAAM,gCAAgC,EAAE,kBAAkB,CAAC,wBAAwB,CAOzF,CAAC;AAEF,wBAAgB,0BAA0B,IAAI,wBAAwB,CAErE"}
@@ -1,12 +0,0 @@
1
- import { getConfigFromMappings } from '@aztec/foundation/config';
2
- export const proverCoordinationConfigMappings = {
3
- proverCoordinationNodeUrls: {
4
- env: 'PROVER_COORDINATION_NODE_URLS',
5
- description: 'The URLs of the tx provider nodes',
6
- parseEnv: (val)=>val.split(',').map((url)=>url.trim().replace(/\/$/, '')),
7
- defaultValue: []
8
- }
9
- };
10
- export function getTxProviderConfigFromEnv() {
11
- return getConfigFromMappings(proverCoordinationConfigMappings);
12
- }
@@ -1,23 +0,0 @@
1
- import type { ArchiveSource, Archiver } from '@aztec/archiver';
2
- import type { EpochCache } from '@aztec/epoch-cache';
3
- import type { DataStoreConfig } from '@aztec/kv-store/config';
4
- import type { ProverCoordination, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
5
- import { type TelemetryClient } from '@aztec/telemetry-client';
6
- import type { ProverNodeConfig } from '../config.js';
7
- import { type TxSource } from './combined-prover-coordination.js';
8
- type ProverCoordinationDeps = {
9
- aztecNodeTxProvider?: TxSource;
10
- worldStateSynchronizer: WorldStateSynchronizer;
11
- archiver: Archiver | ArchiveSource;
12
- telemetry?: TelemetryClient;
13
- epochCache: EpochCache;
14
- };
15
- /**
16
- * Creates a prover coordination service.
17
- * If p2p is enabled, prover coordination is done via p2p.
18
- * If an Aztec node URL is provided, prover coordination is done via the Aztec node over http.
19
- * If an aztec node is provided, it is returned directly.
20
- */
21
- export declare function createProverCoordination(config: ProverNodeConfig & DataStoreConfig, deps: ProverCoordinationDeps): Promise<ProverCoordination>;
22
- export {};
23
- //# sourceMappingURL=factory.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/prover-coordination/factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE/D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAK9D,OAAO,KAAK,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAIlG,OAAO,EAAE,KAAK,eAAe,EAAmB,MAAM,yBAAyB,CAAC;AAEhF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAGL,KAAK,QAAQ,EACd,MAAM,mCAAmC,CAAC;AAG3C,KAAK,sBAAsB,GAAG;IAC5B,mBAAmB,CAAC,EAAE,QAAQ,CAAC;IAC/B,sBAAsB,EAAE,sBAAsB,CAAC;IAC/C,QAAQ,EAAE,QAAQ,GAAG,aAAa,CAAC;IACnC,SAAS,CAAC,EAAE,eAAe,CAAC;IAC5B,UAAU,EAAE,UAAU,CAAC;CACxB,CAAC;AAEF;;;;;GAKG;AACH,wBAAsB,wBAAwB,CAC5C,MAAM,EAAE,gBAAgB,GAAG,eAAe,EAC1C,IAAI,EAAE,sBAAsB,GAC3B,OAAO,CAAC,kBAAkB,CAAC,CA6C7B"}
@@ -1,52 +0,0 @@
1
- import { BBCircuitVerifier, TestCircuitVerifier } from '@aztec/bb-prover';
2
- import { createLogger } from '@aztec/foundation/log';
3
- import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
4
- import { createP2PClient } from '@aztec/p2p';
5
- import { protocolContractTreeRoot } from '@aztec/protocol-contracts';
6
- import { createAztecNodeClient } from '@aztec/stdlib/interfaces/client';
7
- import { P2PClientType } from '@aztec/stdlib/p2p';
8
- import { getPackageVersion } from '@aztec/stdlib/update-checker';
9
- import { getComponentsVersionsFromConfig } from '@aztec/stdlib/versioning';
10
- import { makeTracedFetch } from '@aztec/telemetry-client';
11
- import { CombinedProverCoordination } from './combined-prover-coordination.js';
12
- /**
13
- * Creates a prover coordination service.
14
- * If p2p is enabled, prover coordination is done via p2p.
15
- * If an Aztec node URL is provided, prover coordination is done via the Aztec node over http.
16
- * If an aztec node is provided, it is returned directly.
17
- */ export async function createProverCoordination(config, deps) {
18
- const log = createLogger('prover-node:prover-coordination');
19
- const coordinationConfig = {
20
- txGatheringBatchSize: config.txGatheringBatchSize ?? 10,
21
- txGatheringMaxParallelRequestsPerNode: config.txGatheringMaxParallelRequestsPerNode ?? 10
22
- };
23
- if (deps.aztecNodeTxProvider) {
24
- log.info('Using prover coordination via aztec node');
25
- return new CombinedProverCoordination(undefined, [
26
- deps.aztecNodeTxProvider
27
- ], coordinationConfig);
28
- }
29
- if (config.p2pEnabled) {
30
- log.info('Using prover coordination via p2p');
31
- if (!deps.archiver || !deps.worldStateSynchronizer || !deps.telemetry || !deps.epochCache) {
32
- throw new Error('Missing dependencies for p2p prover coordination');
33
- }
34
- }
35
- let nodes = [];
36
- if (config.proverCoordinationNodeUrls && config.proverCoordinationNodeUrls.length > 0) {
37
- log.info('Using prover coordination via node urls');
38
- const versions = getComponentsVersionsFromConfig(config, protocolContractTreeRoot, getVKTreeRoot());
39
- nodes = config.proverCoordinationNodeUrls.map((url)=>{
40
- log.info(`Creating aztec node client for prover coordination with url: ${url}`);
41
- return createAztecNodeClient(url, versions, makeTracedFetch([
42
- 1,
43
- 2,
44
- 3
45
- ], false));
46
- });
47
- }
48
- const proofVerifier = config.realProofs ? await BBCircuitVerifier.new(config) : new TestCircuitVerifier();
49
- const p2pClient = await createP2PClient(P2PClientType.Prover, config, deps.archiver, proofVerifier, deps.worldStateSynchronizer, deps.epochCache, getPackageVersion() ?? '', deps.telemetry);
50
- await p2pClient.start();
51
- return new CombinedProverCoordination(p2pClient, nodes, coordinationConfig);
52
- }
@@ -1,3 +0,0 @@
1
- export * from './config.js';
2
- export * from './factory.js';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/prover-coordination/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC"}
@@ -1,2 +0,0 @@
1
- export * from './config.js';
2
- export * from './factory.js';
@@ -1,164 +0,0 @@
1
- import { asyncPool } from '@aztec/foundation/async-pool';
2
- import { createLogger } from '@aztec/foundation/log';
3
- import type { P2P } from '@aztec/p2p';
4
- import type { P2PClient, ProverCoordination } from '@aztec/stdlib/interfaces/server';
5
- import { type Tx, TxHash } from '@aztec/stdlib/tx';
6
-
7
- export type CombinedCoordinationOptions = {
8
- // These options apply to http tx gathering only
9
- txGatheringBatchSize: number;
10
- txGatheringMaxParallelRequestsPerNode: number;
11
- };
12
-
13
- interface CoordinationPool {
14
- getTxsByHash(txHashes: TxHash[]): Promise<(Tx | undefined)[]>;
15
- hasTxsInPool(txHashes: TxHash[]): Promise<boolean[]>;
16
- getTxsByHashFromPool(txHashes: TxHash[]): Promise<(Tx | undefined)[]>;
17
- addTxs(txs: Tx[]): Promise<number>;
18
- }
19
-
20
- export interface TxSource {
21
- getTxsByHash(txHashes: TxHash[]): Promise<(Tx | undefined)[]>;
22
- }
23
-
24
- // Wraps the p2p client into a coordination pool
25
- class P2PCoordinationPool implements CoordinationPool {
26
- constructor(private readonly p2p: P2P) {}
27
- getTxsByHash(txHashes: TxHash[]): Promise<(Tx | undefined)[]> {
28
- return this.p2p.getTxsByHash(txHashes, undefined);
29
- }
30
- hasTxsInPool(txHashes: TxHash[]): Promise<boolean[]> {
31
- return this.p2p.hasTxsInPool(txHashes);
32
- }
33
- getTxsByHashFromPool(txHashes: TxHash[]): Promise<(Tx | undefined)[]> {
34
- return this.p2p.getTxsByHashFromPool(txHashes);
35
- }
36
- addTxs(txs: Tx[]): Promise<number> {
37
- return this.p2p.addTxsToPool(txs);
38
- }
39
- }
40
-
41
- // Wraps an in memory tx pool into a coordination pool. Used for testing when no p2p/tx pool is available.
42
- class InMemoryCoordinationPool implements CoordinationPool {
43
- private txs: Map<string, Tx> = new Map();
44
- getTxsByHash(txHashes: TxHash[]): Promise<(Tx | undefined)[]> {
45
- return Promise.resolve(txHashes.map(hash => this.txs.get(hash.toString())));
46
- }
47
- hasTxsInPool(txHashes: TxHash[]): Promise<boolean[]> {
48
- return Promise.resolve(txHashes.map(hash => this.txs.has(hash.toString())));
49
- }
50
- getTxsByHashFromPool(txHashes: TxHash[]): Promise<(Tx | undefined)[]> {
51
- return this.getTxsByHash(txHashes);
52
- }
53
- async addTxs(txs: Tx[]): Promise<number> {
54
- const hashes = await Promise.all(txs.map(tx => tx.getTxHash()));
55
- txs.forEach((tx, index) => this.txs.set(hashes[index].toString(), tx));
56
- return txs.length;
57
- }
58
- }
59
-
60
- // Class to implement combined transaction retrieval from p2p and any available nodes
61
- export class CombinedProverCoordination implements ProverCoordination {
62
- constructor(
63
- public readonly p2p: P2P | undefined,
64
- public readonly aztecNodes: TxSource[],
65
- private readonly options: CombinedCoordinationOptions = {
66
- txGatheringBatchSize: 10,
67
- txGatheringMaxParallelRequestsPerNode: 10,
68
- },
69
- private readonly log = createLogger('prover-node:combined-prover-coordination'),
70
- ) {}
71
-
72
- public getP2PClient(): P2PClient | undefined {
73
- return this.p2p;
74
- }
75
-
76
- public async getTxsByHash(txHashes: TxHash[]): Promise<Tx[]> {
77
- const pool = this.p2p ? new P2PCoordinationPool(this.p2p) : new InMemoryCoordinationPool();
78
- await this.#gatherTxs(txHashes, pool);
79
- const availability = await pool.hasTxsInPool(txHashes);
80
- const notFound = txHashes.filter((_, index) => !availability[index]);
81
- if (notFound.length > 0) {
82
- throw new Error(`Could not find txs: ${notFound.map(tx => tx.toString())}`);
83
- }
84
- const txs = await pool.getTxsByHashFromPool(txHashes);
85
- return txs.filter(tx => tx !== undefined) as Tx[];
86
- }
87
-
88
- public async gatherTxs(txHashes: TxHash[]): Promise<void> {
89
- const pool = this.p2p ? new P2PCoordinationPool(this.p2p) : new InMemoryCoordinationPool();
90
- await this.#gatherTxs(txHashes, pool);
91
- }
92
-
93
- async #gatherTxs(txHashes: TxHash[], pool: CoordinationPool): Promise<void> {
94
- const availability = await pool.hasTxsInPool(txHashes);
95
- const notFound = txHashes.filter((_, index) => !availability[index]);
96
- const txsToFind = new Set(notFound.map(tx => tx.toString()));
97
- if (txsToFind.size === 0) {
98
- this.log.info(`Check for ${txHashes.length} txs found all in the pool`);
99
- return;
100
- }
101
- this.log.info(`Check for ${txHashes.length} txs found ${txsToFind.size} missing. Will gather from nodes and p2p`);
102
- const originalToFind = txsToFind.size;
103
- await this.#gatherTxsFromAllNodes(txsToFind, pool);
104
- if (txsToFind.size === 0) {
105
- this.log.info(`Found all ${originalToFind} txs directly from nodes`);
106
- return;
107
- }
108
- const toFindFromP2P = txsToFind.size;
109
- this.log.verbose(`Gathering ${toFindFromP2P} txs from p2p network`);
110
- const foundFromP2P = await pool.getTxsByHash([...txsToFind].map(tx => TxHash.fromString(tx)));
111
-
112
- // TODO(!!): test for this
113
- // getTxsByHash returns undefined for transactions that are not found, so it must be filtered to find the true length
114
- const foundFromP2PLength = foundFromP2P.filter(tx => !!tx).length;
115
-
116
- const numFoundFromNodes = originalToFind - toFindFromP2P;
117
- const numNotFound = toFindFromP2P - foundFromP2PLength;
118
- if (numNotFound === 0) {
119
- this.log.info(`Found all ${originalToFind} txs. ${numFoundFromNodes} from nodes, ${foundFromP2PLength} from p2p`);
120
- return;
121
- }
122
- this.log.warn(
123
- `Failed to find ${numNotFound} txs from any source. Found ${foundFromP2PLength} from p2p and ${numFoundFromNodes} from nodes`,
124
- );
125
- }
126
-
127
- async #gatherTxsFromAllNodes(txsToFind: Set<string>, pool: CoordinationPool) {
128
- if (txsToFind.size === 0 || this.aztecNodes.length === 0) {
129
- return;
130
- }
131
- await Promise.all(this.aztecNodes.map(aztecNode => this.#gatherTxsFromNode(txsToFind, aztecNode, pool)));
132
- }
133
-
134
- async #gatherTxsFromNode(txsToFind: Set<string>, aztecNode: TxSource, pool: CoordinationPool) {
135
- const totalTxsRequired = txsToFind.size;
136
-
137
- // It's possible that the set is empty as we already found the txs
138
- if (totalTxsRequired === 0) {
139
- return;
140
- }
141
- let totalTxsGathered = 0;
142
-
143
- const batches: string[][] = [];
144
- const allTxs: string[] = [...txsToFind];
145
- while (allTxs.length) {
146
- const batch = allTxs.splice(0, this.options.txGatheringBatchSize);
147
- batches.push(batch);
148
- }
149
-
150
- await asyncPool(this.options.txGatheringMaxParallelRequestsPerNode, batches, async batch => {
151
- try {
152
- const txs = (await aztecNode.getTxsByHash(batch.map(b => TxHash.fromString(b)))).filter((tx): tx is Tx => !!tx);
153
- const hashes = await Promise.all(txs.map(tx => tx.getTxHash()));
154
- await pool.addTxs(txs);
155
- hashes.forEach(hash => txsToFind.delete(hash.toString()));
156
- totalTxsGathered += txs.length;
157
- } catch (err) {
158
- this.log.error(`Error gathering txs from aztec node: ${err}`);
159
- return;
160
- }
161
- });
162
- this.log.verbose(`Gathered ${totalTxsGathered} of ${totalTxsRequired} txs from a node`);
163
- }
164
- }
@@ -1,18 +0,0 @@
1
- import { type ConfigMappingsType, getConfigFromMappings } from '@aztec/foundation/config';
2
-
3
- export type ProverCoordinationConfig = {
4
- proverCoordinationNodeUrls: string[];
5
- };
6
-
7
- export const proverCoordinationConfigMappings: ConfigMappingsType<ProverCoordinationConfig> = {
8
- proverCoordinationNodeUrls: {
9
- env: 'PROVER_COORDINATION_NODE_URLS',
10
- description: 'The URLs of the tx provider nodes',
11
- parseEnv: (val: string) => val.split(',').map(url => url.trim().replace(/\/$/, '')),
12
- defaultValue: [],
13
- },
14
- };
15
-
16
- export function getTxProviderConfigFromEnv(): ProverCoordinationConfig {
17
- return getConfigFromMappings<ProverCoordinationConfig>(proverCoordinationConfigMappings);
18
- }
@@ -1,86 +0,0 @@
1
- import type { ArchiveSource, Archiver } from '@aztec/archiver';
2
- import { BBCircuitVerifier, TestCircuitVerifier } from '@aztec/bb-prover';
3
- import type { EpochCache } from '@aztec/epoch-cache';
4
- import { createLogger } from '@aztec/foundation/log';
5
- import type { DataStoreConfig } from '@aztec/kv-store/config';
6
- import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
7
- import { createP2PClient } from '@aztec/p2p';
8
- import { protocolContractTreeRoot } from '@aztec/protocol-contracts';
9
- import { type AztecNode, createAztecNodeClient } from '@aztec/stdlib/interfaces/client';
10
- import type { ProverCoordination, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
11
- import { P2PClientType } from '@aztec/stdlib/p2p';
12
- import { getPackageVersion } from '@aztec/stdlib/update-checker';
13
- import { getComponentsVersionsFromConfig } from '@aztec/stdlib/versioning';
14
- import { type TelemetryClient, makeTracedFetch } from '@aztec/telemetry-client';
15
-
16
- import type { ProverNodeConfig } from '../config.js';
17
- import {
18
- type CombinedCoordinationOptions,
19
- CombinedProverCoordination,
20
- type TxSource,
21
- } from './combined-prover-coordination.js';
22
-
23
- // We return a reference to the P2P client so that the prover node can stop the service when it shuts down.
24
- type ProverCoordinationDeps = {
25
- aztecNodeTxProvider?: TxSource;
26
- worldStateSynchronizer: WorldStateSynchronizer;
27
- archiver: Archiver | ArchiveSource;
28
- telemetry?: TelemetryClient;
29
- epochCache: EpochCache;
30
- };
31
-
32
- /**
33
- * Creates a prover coordination service.
34
- * If p2p is enabled, prover coordination is done via p2p.
35
- * If an Aztec node URL is provided, prover coordination is done via the Aztec node over http.
36
- * If an aztec node is provided, it is returned directly.
37
- */
38
- export async function createProverCoordination(
39
- config: ProverNodeConfig & DataStoreConfig,
40
- deps: ProverCoordinationDeps,
41
- ): Promise<ProverCoordination> {
42
- const log = createLogger('prover-node:prover-coordination');
43
-
44
- const coordinationConfig: CombinedCoordinationOptions = {
45
- txGatheringBatchSize: config.txGatheringBatchSize ?? 10,
46
- txGatheringMaxParallelRequestsPerNode: config.txGatheringMaxParallelRequestsPerNode ?? 10,
47
- };
48
-
49
- if (deps.aztecNodeTxProvider) {
50
- log.info('Using prover coordination via aztec node');
51
- return new CombinedProverCoordination(undefined, [deps.aztecNodeTxProvider!], coordinationConfig);
52
- }
53
-
54
- if (config.p2pEnabled) {
55
- log.info('Using prover coordination via p2p');
56
-
57
- if (!deps.archiver || !deps.worldStateSynchronizer || !deps.telemetry || !deps.epochCache) {
58
- throw new Error('Missing dependencies for p2p prover coordination');
59
- }
60
- }
61
-
62
- let nodes: AztecNode[] = [];
63
- if (config.proverCoordinationNodeUrls && config.proverCoordinationNodeUrls.length > 0) {
64
- log.info('Using prover coordination via node urls');
65
- const versions = getComponentsVersionsFromConfig(config, protocolContractTreeRoot, getVKTreeRoot());
66
- nodes = config.proverCoordinationNodeUrls.map(url => {
67
- log.info(`Creating aztec node client for prover coordination with url: ${url}`);
68
- return createAztecNodeClient(url, versions, makeTracedFetch([1, 2, 3], false));
69
- });
70
- }
71
-
72
- const proofVerifier = config.realProofs ? await BBCircuitVerifier.new(config) : new TestCircuitVerifier();
73
- const p2pClient = await createP2PClient(
74
- P2PClientType.Prover,
75
- config,
76
- deps.archiver,
77
- proofVerifier,
78
- deps.worldStateSynchronizer,
79
- deps.epochCache,
80
- getPackageVersion() ?? '',
81
- deps.telemetry,
82
- );
83
- await p2pClient.start();
84
-
85
- return new CombinedProverCoordination(p2pClient, nodes, coordinationConfig);
86
- }
@@ -1,2 +0,0 @@
1
- export * from './config.js';
2
- export * from './factory.js';