@aztec/prover-node 0.85.0 → 0.86.0-nightly.20250425

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 (69) hide show
  1. package/dest/actions/download-epoch-proving-job.d.ts +15 -0
  2. package/dest/actions/download-epoch-proving-job.d.ts.map +1 -0
  3. package/dest/actions/download-epoch-proving-job.js +35 -0
  4. package/dest/actions/index.d.ts +3 -0
  5. package/dest/actions/index.d.ts.map +1 -0
  6. package/dest/actions/index.js +2 -0
  7. package/dest/actions/rerun-epoch-proving-job.d.ts +11 -0
  8. package/dest/actions/rerun-epoch-proving-job.d.ts.map +1 -0
  9. package/dest/actions/rerun-epoch-proving-job.js +37 -0
  10. package/dest/actions/upload-epoch-proof-failure.d.ts +15 -0
  11. package/dest/actions/upload-epoch-proof-failure.d.ts.map +1 -0
  12. package/dest/actions/upload-epoch-proof-failure.js +78 -0
  13. package/dest/config.d.ts +4 -4
  14. package/dest/config.d.ts.map +1 -1
  15. package/dest/config.js +12 -7
  16. package/dest/factory.d.ts +3 -2
  17. package/dest/factory.d.ts.map +1 -1
  18. package/dest/factory.js +13 -13
  19. package/dest/index.d.ts +1 -0
  20. package/dest/index.d.ts.map +1 -1
  21. package/dest/index.js +1 -0
  22. package/dest/job/epoch-proving-job-data.d.ts +17 -0
  23. package/dest/job/epoch-proving-job-data.d.ts.map +1 -0
  24. package/dest/job/epoch-proving-job-data.js +45 -0
  25. package/dest/job/epoch-proving-job.d.ts +9 -9
  26. package/dest/job/epoch-proving-job.d.ts.map +1 -1
  27. package/dest/job/epoch-proving-job.js +38 -21
  28. package/dest/metrics.d.ts +27 -4
  29. package/dest/metrics.d.ts.map +1 -1
  30. package/dest/metrics.js +104 -36
  31. package/dest/monitors/epoch-monitor.d.ts +1 -1
  32. package/dest/monitors/epoch-monitor.d.ts.map +1 -1
  33. package/dest/monitors/epoch-monitor.js +7 -2
  34. package/dest/prover-coordination/combined-prover-coordination.d.ts +22 -0
  35. package/dest/prover-coordination/combined-prover-coordination.d.ts.map +1 -0
  36. package/dest/prover-coordination/combined-prover-coordination.js +136 -0
  37. package/dest/prover-coordination/config.d.ts +1 -1
  38. package/dest/prover-coordination/config.d.ts.map +1 -1
  39. package/dest/prover-coordination/config.js +5 -4
  40. package/dest/prover-coordination/factory.d.ts +5 -4
  41. package/dest/prover-coordination/factory.d.ts.map +1 -1
  42. package/dest/prover-coordination/factory.js +20 -14
  43. package/dest/prover-node-publisher.d.ts +1 -2
  44. package/dest/prover-node-publisher.d.ts.map +1 -1
  45. package/dest/prover-node-publisher.js +7 -13
  46. package/dest/prover-node.d.ts +26 -24
  47. package/dest/prover-node.d.ts.map +1 -1
  48. package/dest/prover-node.js +103 -51
  49. package/dest/test/index.d.ts +4 -2
  50. package/dest/test/index.d.ts.map +1 -1
  51. package/dest/test/index.js +1 -1
  52. package/package.json +20 -22
  53. package/src/actions/download-epoch-proving-job.ts +46 -0
  54. package/src/actions/index.ts +2 -0
  55. package/src/actions/rerun-epoch-proving-job.ts +59 -0
  56. package/src/actions/upload-epoch-proof-failure.ts +88 -0
  57. package/src/config.ts +16 -10
  58. package/src/factory.ts +31 -17
  59. package/src/index.ts +1 -0
  60. package/src/job/epoch-proving-job-data.ts +68 -0
  61. package/src/job/epoch-proving-job.ts +53 -23
  62. package/src/metrics.ts +111 -38
  63. package/src/monitors/epoch-monitor.ts +5 -3
  64. package/src/prover-coordination/combined-prover-coordination.ts +160 -0
  65. package/src/prover-coordination/config.ts +6 -5
  66. package/src/prover-coordination/factory.ts +36 -25
  67. package/src/prover-node-publisher.ts +9 -18
  68. package/src/prover-node.ts +151 -74
  69. package/src/test/index.ts +5 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/prover-node",
3
- "version": "0.85.0",
3
+ "version": "0.86.0-nightly.20250425",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./dest/index.js",
@@ -14,8 +14,6 @@
14
14
  "build": "yarn clean && tsc -b",
15
15
  "build:dev": "tsc -b --watch",
16
16
  "clean": "rm -rf ./dest .tsbuildinfo",
17
- "formatting": "run -T prettier --check ./src && run -T eslint ./src",
18
- "formatting:fix": "run -T eslint --fix ./src && run -T prettier -w ./src",
19
17
  "bb": "node --no-warnings ./dest/bb/index.js",
20
18
  "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
21
19
  },
@@ -53,25 +51,25 @@
53
51
  ]
54
52
  },
55
53
  "dependencies": {
56
- "@aztec/archiver": "0.85.0",
57
- "@aztec/bb-prover": "0.85.0",
58
- "@aztec/blob-sink": "0.85.0",
59
- "@aztec/constants": "0.85.0",
60
- "@aztec/epoch-cache": "0.85.0",
61
- "@aztec/ethereum": "0.85.0",
62
- "@aztec/foundation": "0.85.0",
63
- "@aztec/kv-store": "0.85.0",
64
- "@aztec/l1-artifacts": "0.85.0",
65
- "@aztec/node-lib": "0.85.0",
66
- "@aztec/noir-protocol-circuits-types": "0.85.0",
67
- "@aztec/p2p": "0.85.0",
68
- "@aztec/protocol-contracts": "0.85.0",
69
- "@aztec/prover-client": "0.85.0",
70
- "@aztec/sequencer-client": "0.85.0",
71
- "@aztec/simulator": "0.85.0",
72
- "@aztec/stdlib": "0.85.0",
73
- "@aztec/telemetry-client": "0.85.0",
74
- "@aztec/world-state": "0.85.0",
54
+ "@aztec/archiver": "0.86.0-nightly.20250425",
55
+ "@aztec/bb-prover": "0.86.0-nightly.20250425",
56
+ "@aztec/blob-sink": "0.86.0-nightly.20250425",
57
+ "@aztec/constants": "0.86.0-nightly.20250425",
58
+ "@aztec/epoch-cache": "0.86.0-nightly.20250425",
59
+ "@aztec/ethereum": "0.86.0-nightly.20250425",
60
+ "@aztec/foundation": "0.86.0-nightly.20250425",
61
+ "@aztec/kv-store": "0.86.0-nightly.20250425",
62
+ "@aztec/l1-artifacts": "0.86.0-nightly.20250425",
63
+ "@aztec/node-lib": "0.86.0-nightly.20250425",
64
+ "@aztec/noir-protocol-circuits-types": "0.86.0-nightly.20250425",
65
+ "@aztec/p2p": "0.86.0-nightly.20250425",
66
+ "@aztec/protocol-contracts": "0.86.0-nightly.20250425",
67
+ "@aztec/prover-client": "0.86.0-nightly.20250425",
68
+ "@aztec/sequencer-client": "0.86.0-nightly.20250425",
69
+ "@aztec/simulator": "0.86.0-nightly.20250425",
70
+ "@aztec/stdlib": "0.86.0-nightly.20250425",
71
+ "@aztec/telemetry-client": "0.86.0-nightly.20250425",
72
+ "@aztec/world-state": "0.86.0-nightly.20250425",
75
73
  "source-map-support": "^0.5.21",
76
74
  "tslib": "^2.4.0",
77
75
  "viem": "2.23.7"
@@ -0,0 +1,46 @@
1
+ import type { EthAddress } from '@aztec/foundation/eth-address';
2
+ import { jsonParseWithSchemaSync } from '@aztec/foundation/json-rpc';
3
+ import type { Logger } from '@aztec/foundation/log';
4
+ import { snapshotSync } from '@aztec/node-lib/actions';
5
+ import { createReadOnlyFileStore } from '@aztec/stdlib/file-store';
6
+ import { UploadSnapshotMetadataSchema, makeSnapshotPaths } from '@aztec/stdlib/snapshots';
7
+
8
+ import { readFileSync } from 'fs';
9
+ import { join } from 'path';
10
+
11
+ import { deserializeEpochProvingJobData } from '../job/epoch-proving-job-data.js';
12
+
13
+ /**
14
+ * Given a location returned by `uploadEpochProofFailure`, downloads the world state and archiver snapshots
15
+ * and the proving job data, so we can re-run the job later using `rerunEpochProvingJob`. This is decoupled
16
+ * from actually proving so we can download once and run multiple times.
17
+ */
18
+ export async function downloadEpochProvingJob(
19
+ location: string,
20
+ log: Logger,
21
+ config: {
22
+ dataDirectory: string;
23
+ rollupAddress: EthAddress;
24
+ jobDataDownloadPath: string;
25
+ rollupVersion: number;
26
+ l1ChainId: number;
27
+ },
28
+ ) {
29
+ log.info(`Downloading epoch proving job data from ${location}`);
30
+ const fileStore = await createReadOnlyFileStore(location);
31
+ const metadataUrl = join(location, 'metadata.json');
32
+ const metadataRaw = await fileStore.read(metadataUrl);
33
+ const metadata = jsonParseWithSchemaSync(metadataRaw.toString(), UploadSnapshotMetadataSchema);
34
+
35
+ const dataUrls = makeSnapshotPaths(location);
36
+ log.info(`Downloading state snapshot from ${location} to local data directory`, { metadata, dataUrls });
37
+ await snapshotSync({ dataUrls }, log, { ...config, snapshotsUrl: location });
38
+
39
+ const dataPath = join(location, 'data.bin');
40
+ const localPath = config.jobDataDownloadPath;
41
+ log.info(`Downloading epoch proving job data from ${dataPath} to ${localPath}`);
42
+ await fileStore.download(dataPath, localPath);
43
+
44
+ const jobData = deserializeEpochProvingJobData(readFileSync(localPath));
45
+ log.info(`Epoch proving job data for epoch ${jobData.epochNumber} downloaded successfully`);
46
+ }
@@ -0,0 +1,2 @@
1
+ export * from './download-epoch-proving-job.js';
2
+ export * from './rerun-epoch-proving-job.js';
@@ -0,0 +1,59 @@
1
+ import { createArchiverStore } from '@aztec/archiver';
2
+ import type { Logger } from '@aztec/foundation/log';
3
+ import type { DataStoreConfig } from '@aztec/kv-store/config';
4
+ import { type ProverClientConfig, createProverClient } from '@aztec/prover-client';
5
+ import { ProverBrokerConfig, createAndStartProvingBroker } from '@aztec/prover-client/broker';
6
+ import { PublicProcessorFactory } from '@aztec/simulator/server';
7
+ import { getTelemetryClient } from '@aztec/telemetry-client';
8
+ import { createWorldState } from '@aztec/world-state';
9
+
10
+ import { readFileSync } from 'fs';
11
+
12
+ import { deserializeEpochProvingJobData } from '../job/epoch-proving-job-data.js';
13
+ import { EpochProvingJob } from '../job/epoch-proving-job.js';
14
+ import { ProverNodeJobMetrics } from '../metrics.js';
15
+
16
+ /**
17
+ * Given a local folder where `downloadEpochProvingJob` was called, creates a new archiver and world state
18
+ * using the state snapshots, and creates a new epoch proving job to prove the downloaded proving job.
19
+ * Proving is done with a local proving broker and agents as specified by the config.
20
+ */
21
+ export async function rerunEpochProvingJob(
22
+ localPath: string,
23
+ log: Logger,
24
+ config: DataStoreConfig & ProverBrokerConfig & ProverClientConfig,
25
+ ) {
26
+ const jobData = deserializeEpochProvingJobData(readFileSync(localPath));
27
+ log.info(`Loaded proving job data for epoch ${jobData.epochNumber}`);
28
+
29
+ const telemetry = getTelemetryClient();
30
+ const metrics = new ProverNodeJobMetrics(telemetry.getMeter('prover-job'), telemetry.getTracer('prover-job'));
31
+ const worldState = await createWorldState(config);
32
+ const archiver = await createArchiverStore(config);
33
+ const publicProcessorFactory = new PublicProcessorFactory(archiver);
34
+
35
+ const publisher = { submitEpochProof: () => Promise.resolve(true) };
36
+ const l2BlockSourceForReorgDetection = undefined;
37
+ const deadline = undefined;
38
+
39
+ // This starts a local proving broker that does not get exposed as a service. This should be good enough for
40
+ // smallish epochs to be proven if we run on a large machine, but as epochs grow larger, we may want to switch
41
+ // this out for a live proving broker with multiple agents that we can connect to.
42
+ const broker = await createAndStartProvingBroker(config, telemetry);
43
+ const prover = await createProverClient(config, worldState, broker, telemetry);
44
+
45
+ const provingJob = new EpochProvingJob(
46
+ jobData,
47
+ worldState,
48
+ prover.createEpochProver(),
49
+ publicProcessorFactory,
50
+ publisher,
51
+ l2BlockSourceForReorgDetection,
52
+ metrics,
53
+ deadline,
54
+ );
55
+
56
+ log.info(`Rerunning epoch proving job for epoch ${jobData.epochNumber}`);
57
+ await provingJob.run();
58
+ log.info(`Completed job for epoch ${jobData.epochNumber} with status ${provingJob.getState()}`);
59
+ }
@@ -0,0 +1,88 @@
1
+ import { ARCHIVER_DB_VERSION, type Archiver } from '@aztec/archiver';
2
+ import { tryRmDir } from '@aztec/foundation/fs';
3
+ import { jsonStringify } from '@aztec/foundation/json-rpc';
4
+ import type { Logger } from '@aztec/foundation/log';
5
+ import { isoDate } from '@aztec/foundation/string';
6
+ import type { DataStoreConfig } from '@aztec/kv-store/config';
7
+ import { buildSnapshotMetadata, createBackups } from '@aztec/node-lib/actions';
8
+ import type { ChainConfig } from '@aztec/stdlib/config';
9
+ import { type FileStore, createFileStore } from '@aztec/stdlib/file-store';
10
+ import type { WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
11
+ import { type UploadSnapshotMetadata, getBasePath, uploadSnapshotData } from '@aztec/stdlib/snapshots';
12
+ import { WORLD_STATE_DB_VERSION } from '@aztec/world-state';
13
+
14
+ import { mkdtemp } from 'fs/promises';
15
+ import { tmpdir } from 'os';
16
+ import { dirname, join } from 'path';
17
+
18
+ import { type EpochProvingJobData, serializeEpochProvingJobData } from '../job/epoch-proving-job-data.js';
19
+
20
+ type UploadEpochProofConfig = Pick<ChainConfig, 'l1ChainId' | 'rollupVersion'> & Pick<DataStoreConfig, 'dataDirectory'>;
21
+
22
+ /** Whether uploaded data to the file store should be of public access. */
23
+ const PUBLIC_UPLOADS = true;
24
+
25
+ /**
26
+ * Uploads a snapshot of world state and archiver (requires pausing them) along with the proving job data,
27
+ * so we can download and re-run the job later under the same conditions.
28
+ * @param location The location to upload the data to (used to create the `FileStore`).
29
+ */
30
+ export async function uploadEpochProofFailure(
31
+ location: string,
32
+ jobId: string,
33
+ jobData: EpochProvingJobData,
34
+ archiver: Archiver,
35
+ worldState: WorldStateSynchronizer,
36
+ config: UploadEpochProofConfig,
37
+ log: Logger,
38
+ ) {
39
+ const epochNumber = jobData.epochNumber;
40
+ log.warn(`Uploading epoch proof failure for ${epochNumber} to ${location}`, { epochNumber, jobId, location });
41
+
42
+ const backupDir = await mkdtemp(join(config.dataDirectory ?? tmpdir(), 'epoch-proof-data-'));
43
+ const store = await createFileStore(location);
44
+ if (!store) {
45
+ throw new Error(`Failed to create file store for epoch proof failure upload for location ${location}.`);
46
+ }
47
+
48
+ try {
49
+ const versions = { archiver: ARCHIVER_DB_VERSION, worldState: WORLD_STATE_DB_VERSION };
50
+ const uploadMetadata = await buildSnapshotMetadata(archiver, config);
51
+ const paths = await createBackups(backupDir, archiver, worldState, log);
52
+
53
+ const basePath = `${getBasePath(uploadMetadata)}/${epochNumber}-${isoDate()}-${jobId}`;
54
+ const pathFor = (key: string) => `${basePath}/${key}.db`;
55
+ const [metadata, dataUrl, metadataUrl] = await Promise.all([
56
+ uploadSnapshotData(paths, versions, uploadMetadata, store, { pathFor, private: !PUBLIC_UPLOADS }),
57
+ uploadJobData(jobData, store, basePath),
58
+ uploadSnapshotMetadata(uploadMetadata, store, basePath),
59
+ ] as const);
60
+
61
+ const baseUrl = dirname(metadataUrl);
62
+ log.warn(`Uploaded epoch ${epochNumber} proof failure data to ${baseUrl}`, {
63
+ epochNumber,
64
+ location,
65
+ basePath,
66
+ metadataUrl,
67
+ dataUrl,
68
+ metadata,
69
+ jobId,
70
+ });
71
+ return baseUrl;
72
+ } finally {
73
+ log.info(`Cleaning up backup dir ${backupDir}`);
74
+ await tryRmDir(backupDir, log);
75
+ }
76
+ }
77
+
78
+ async function uploadJobData(jobData: EpochProvingJobData, store: FileStore, basePath: string) {
79
+ const data = serializeEpochProvingJobData(jobData);
80
+ const path = `${basePath}/data.bin`;
81
+ return await store.save(path, data, { compress: true, public: PUBLIC_UPLOADS });
82
+ }
83
+
84
+ async function uploadSnapshotMetadata(metadata: UploadSnapshotMetadata, store: FileStore, basePath: string) {
85
+ const data = Buffer.from(jsonStringify(metadata), 'utf-8');
86
+ const path = `${basePath}/metadata.json`;
87
+ return await store.save(path, data, { compress: false, public: PUBLIC_UPLOADS });
88
+ }
package/src/config.ts CHANGED
@@ -40,13 +40,14 @@ export type ProverNodeConfig = ArchiverConfig &
40
40
  SpecificProverNodeConfig &
41
41
  GenesisStateConfig;
42
42
 
43
- type SpecificProverNodeConfig = {
43
+ export type SpecificProverNodeConfig = {
44
44
  proverNodeMaxPendingJobs: number;
45
45
  proverNodePollingIntervalMs: number;
46
46
  proverNodeMaxParallelBlocksPerEpoch: number;
47
- txGatheringTimeoutMs: number;
47
+ proverNodeFailedEpochStore: string | undefined;
48
48
  txGatheringIntervalMs: number;
49
- txGatheringMaxParallelRequests: number;
49
+ txGatheringBatchSize: number;
50
+ txGatheringMaxParallelRequestsPerNode: number;
50
51
  };
51
52
 
52
53
  const specificProverNodeConfigMappings: ConfigMappingsType<SpecificProverNodeConfig> = {
@@ -65,19 +66,24 @@ const specificProverNodeConfigMappings: ConfigMappingsType<SpecificProverNodeCon
65
66
  description: 'The Maximum number of blocks to process in parallel while proving an epoch',
66
67
  ...numberConfigHelper(32),
67
68
  },
68
- txGatheringTimeoutMs: {
69
- env: 'PROVER_NODE_TX_GATHERING_TIMEOUT_MS',
70
- description: 'The maximum amount of time to wait for tx data to be available',
71
- ...numberConfigHelper(60_000),
69
+ proverNodeFailedEpochStore: {
70
+ env: 'PROVER_NODE_FAILED_EPOCH_STORE',
71
+ description: 'File store where to upload node state when an epoch fails to be proven',
72
+ defaultValue: undefined,
72
73
  },
73
74
  txGatheringIntervalMs: {
74
75
  env: 'PROVER_NODE_TX_GATHERING_INTERVAL_MS',
75
76
  description: 'How often to check that tx data is available',
76
77
  ...numberConfigHelper(1_000),
77
78
  },
78
- txGatheringMaxParallelRequests: {
79
- env: 'PROVER_NODE_TX_GATHERING_MAX_PARALLEL_REQUESTS',
80
- description: 'How many txs to load up a time',
79
+ txGatheringBatchSize: {
80
+ env: 'PROVER_NODE_TX_GATHERING_BATCH_SIZE',
81
+ description: 'How many transactions to gather from a node in a single request',
82
+ ...numberConfigHelper(10),
83
+ },
84
+ txGatheringMaxParallelRequestsPerNode: {
85
+ env: 'PROVER_NODE_TX_GATHERING_MAX_PARALLEL_REQUESTS_PER_NODE',
86
+ description: 'How many tx requests to make in parallel to each node',
81
87
  ...numberConfigHelper(100),
82
88
  },
83
89
  };
package/src/factory.ts CHANGED
@@ -1,22 +1,24 @@
1
1
  import { type Archiver, createArchiver } from '@aztec/archiver';
2
2
  import { type BlobSinkClientInterface, createBlobSinkClient } from '@aztec/blob-sink/client';
3
3
  import { EpochCache } from '@aztec/epoch-cache';
4
- import { L1TxUtils, RollupContract, createEthereumChain, createL1Clients } from '@aztec/ethereum';
4
+ import { L1TxUtils, RollupContract, createEthereumChain, createExtendedL1Client } from '@aztec/ethereum';
5
+ import { pick } from '@aztec/foundation/collection';
5
6
  import { type Logger, createLogger } from '@aztec/foundation/log';
6
7
  import type { DataStoreConfig } from '@aztec/kv-store/config';
7
8
  import { trySnapshotSync } from '@aztec/node-lib/actions';
8
9
  import { createProverClient } from '@aztec/prover-client';
9
10
  import { createAndStartProvingBroker } from '@aztec/prover-client/broker';
10
- import type { ProverCoordination, ProvingJobBroker } from '@aztec/stdlib/interfaces/server';
11
+ import type { ProvingJobBroker } from '@aztec/stdlib/interfaces/server';
11
12
  import type { PublicDataTreeLeaf } from '@aztec/stdlib/trees';
12
13
  import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
13
14
  import { createWorldStateSynchronizer } from '@aztec/world-state';
14
15
 
15
16
  import { type ProverNodeConfig, resolveConfig } from './config.js';
16
17
  import { EpochMonitor } from './monitors/epoch-monitor.js';
18
+ import type { TxSource } from './prover-coordination/combined-prover-coordination.js';
17
19
  import { createProverCoordination } from './prover-coordination/factory.js';
18
20
  import { ProverNodePublisher } from './prover-node-publisher.js';
19
- import { ProverNode, type ProverNodeOptions } from './prover-node.js';
21
+ import { ProverNode } from './prover-node.js';
20
22
 
21
23
  /** Creates a new prover node given a config. */
22
24
  export async function createProverNode(
@@ -24,7 +26,7 @@ export async function createProverNode(
24
26
  deps: {
25
27
  telemetry?: TelemetryClient;
26
28
  log?: Logger;
27
- aztecNodeTxProvider?: ProverCoordination;
29
+ aztecNodeTxProvider?: TxSource;
28
30
  archiver?: Archiver;
29
31
  publisher?: ProverNodePublisher;
30
32
  blobSinkClient?: BlobSinkClientInterface;
@@ -37,7 +39,8 @@ export async function createProverNode(
37
39
  ) {
38
40
  const config = resolveConfig(userConfig);
39
41
  const telemetry = deps.telemetry ?? getTelemetryClient();
40
- const blobSinkClient = deps.blobSinkClient ?? createBlobSinkClient(config);
42
+ const blobSinkClient =
43
+ deps.blobSinkClient ?? createBlobSinkClient(config, { logger: createLogger('prover-node:blob-sink:client') });
41
44
  const log = deps.log ?? createLogger('prover-node');
42
45
 
43
46
  await trySnapshotSync(config, log);
@@ -59,17 +62,17 @@ export async function createProverNode(
59
62
 
60
63
  const { l1RpcUrls: rpcUrls, l1ChainId: chainId, publisherPrivateKey } = config;
61
64
  const chain = createEthereumChain(rpcUrls, chainId);
62
- const { publicClient, walletClient } = createL1Clients(rpcUrls, publisherPrivateKey, chain.chainInfo);
65
+ const l1Client = createExtendedL1Client(rpcUrls, publisherPrivateKey, chain.chainInfo);
63
66
 
64
- const rollupContract = new RollupContract(publicClient, config.l1Contracts.rollupAddress.toString());
67
+ const rollupContract = new RollupContract(l1Client, config.l1Contracts.rollupAddress.toString());
65
68
 
66
- const l1TxUtils = deps.l1TxUtils ?? new L1TxUtils(publicClient, walletClient, log, config);
69
+ const l1TxUtils = deps.l1TxUtils ?? new L1TxUtils(l1Client, log, config);
67
70
  const publisher = deps.publisher ?? new ProverNodePublisher(config, { telemetry, rollupContract, l1TxUtils });
68
71
 
69
72
  const epochCache = await EpochCache.create(config.l1Contracts.rollupAddress, config);
70
73
 
71
74
  // If config.p2pEnabled is true, createProverCoordination will create a p2p client where txs are requested
72
- // If config.p2pEnabled is false, createProverCoordination request information from the AztecNode
75
+ // If config.proverCoordinationNodeUrls is not empty, createProverCoordination will create set of aztec node clients from which txs are requested
73
76
  const proverCoordination = await createProverCoordination(config, {
74
77
  aztecNodeTxProvider: deps.aztecNodeTxProvider,
75
78
  worldStateSynchronizer,
@@ -78,16 +81,27 @@ export async function createProverNode(
78
81
  telemetry,
79
82
  });
80
83
 
81
- const proverNodeConfig: ProverNodeOptions = {
82
- maxPendingJobs: config.proverNodeMaxPendingJobs,
83
- pollingIntervalMs: config.proverNodePollingIntervalMs,
84
- maxParallelBlocksPerEpoch: config.proverNodeMaxParallelBlocksPerEpoch,
85
- txGatheringMaxParallelRequests: config.txGatheringMaxParallelRequests,
86
- txGatheringIntervalMs: config.txGatheringIntervalMs,
87
- txGatheringTimeoutMs: config.txGatheringTimeoutMs,
84
+ const proverNodeConfig = {
85
+ ...pick(
86
+ config,
87
+ 'proverNodeMaxPendingJobs',
88
+ 'proverNodeMaxParallelBlocksPerEpoch',
89
+ 'proverNodePollingIntervalMs',
90
+ 'txGatheringMaxParallelRequests',
91
+ 'txGatheringIntervalMs',
92
+ 'txGatheringTimeoutMs',
93
+ 'proverNodeFailedEpochStore',
94
+ 'dataDirectory',
95
+ 'l1ChainId',
96
+ 'rollupVersion',
97
+ ),
88
98
  };
89
99
 
90
- const epochMonitor = await EpochMonitor.create(archiver, proverNodeConfig, telemetry);
100
+ const epochMonitor = await EpochMonitor.create(
101
+ archiver,
102
+ { pollingIntervalMs: config.proverNodePollingIntervalMs },
103
+ telemetry,
104
+ );
91
105
 
92
106
  return new ProverNode(
93
107
  prover,
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './actions/index.js';
1
2
  export * from './config.js';
2
3
  export * from './factory.js';
3
4
  export * from './http.js';
@@ -0,0 +1,68 @@
1
+ import { Fr } from '@aztec/foundation/fields';
2
+ import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
3
+ import { L2Block } from '@aztec/stdlib/block';
4
+ import { BlockHeader, Tx } from '@aztec/stdlib/tx';
5
+
6
+ /** All data from an epoch used in proving. */
7
+ export type EpochProvingJobData = {
8
+ epochNumber: bigint;
9
+ blocks: L2Block[];
10
+ txs: Tx[];
11
+ l1ToL2Messages: Record<number, Fr[]>;
12
+ previousBlockHeader: BlockHeader;
13
+ };
14
+
15
+ export function validateEpochProvingJobData(data: EpochProvingJobData) {
16
+ if (data.blocks.length > 0 && data.previousBlockHeader.getBlockNumber() + 1 !== data.blocks[0].number) {
17
+ throw new Error(
18
+ `Initial block number ${
19
+ data.blocks[0].number
20
+ } does not match previous block header ${data.previousBlockHeader.getBlockNumber()}`,
21
+ );
22
+ }
23
+
24
+ for (const blockNumber of data.blocks.map(block => block.number)) {
25
+ if (!(blockNumber in data.l1ToL2Messages)) {
26
+ throw new Error(`Missing L1 to L2 messages for block number ${blockNumber}`);
27
+ }
28
+ }
29
+ }
30
+
31
+ export function serializeEpochProvingJobData(data: EpochProvingJobData): Buffer {
32
+ const blocks = data.blocks.map(block => block.toBuffer());
33
+ const txs = data.txs.map(tx => tx.toBuffer());
34
+ const l1ToL2Messages = Object.entries(data.l1ToL2Messages).map(([blockNumber, messages]) => [
35
+ Number(blockNumber),
36
+ messages.length,
37
+ ...messages,
38
+ ]);
39
+
40
+ return serializeToBuffer(
41
+ Number(data.epochNumber),
42
+ data.previousBlockHeader,
43
+ blocks.length,
44
+ ...blocks,
45
+ txs.length,
46
+ ...txs,
47
+ l1ToL2Messages.length,
48
+ ...l1ToL2Messages,
49
+ );
50
+ }
51
+
52
+ export function deserializeEpochProvingJobData(buf: Buffer): EpochProvingJobData {
53
+ const reader = BufferReader.asReader(buf);
54
+ const epochNumber = BigInt(reader.readNumber());
55
+ const previousBlockHeader = reader.readObject(BlockHeader);
56
+ const blocks = reader.readVector(L2Block);
57
+ const txs = reader.readVector(Tx);
58
+
59
+ const l1ToL2MessageBlockCount = reader.readNumber();
60
+ const l1ToL2Messages: Record<number, Fr[]> = {};
61
+ for (let i = 0; i < l1ToL2MessageBlockCount; i++) {
62
+ const blockNumber = reader.readNumber();
63
+ const messages = reader.readVector(Fr);
64
+ l1ToL2Messages[blockNumber] = messages;
65
+ }
66
+
67
+ return { epochNumber, previousBlockHeader, blocks, txs, l1ToL2Messages };
68
+ }
@@ -10,14 +10,14 @@ import {
10
10
  EpochProvingJobTerminalState,
11
11
  type ForkMerkleTreeOperations,
12
12
  } from '@aztec/stdlib/interfaces/server';
13
- import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
14
13
  import type { ProcessedTx, Tx } from '@aztec/stdlib/tx';
15
14
  import { Attributes, type Traceable, type Tracer, trackSpan } from '@aztec/telemetry-client';
16
15
 
17
16
  import * as crypto from 'node:crypto';
18
17
 
19
- import type { ProverNodeMetrics } from '../metrics.js';
18
+ import type { ProverNodeJobMetrics } from '../metrics.js';
20
19
  import type { ProverNodePublisher } from '../prover-node-publisher.js';
20
+ import { type EpochProvingJobData, validateEpochProvingJobData } from './epoch-proving-job-data.js';
21
21
 
22
22
  /**
23
23
  * Job that grabs a range of blocks from the unfinalised chain from L1, gets their txs given their hashes,
@@ -36,21 +36,19 @@ export class EpochProvingJob implements Traceable {
36
36
  public readonly tracer: Tracer;
37
37
 
38
38
  constructor(
39
- private dbProvider: ForkMerkleTreeOperations,
40
- private epochNumber: bigint,
41
- private blocks: L2Block[],
42
- private txs: Tx[],
39
+ private data: EpochProvingJobData,
40
+ private dbProvider: Pick<ForkMerkleTreeOperations, 'fork'>,
43
41
  private prover: EpochProver,
44
42
  private publicProcessorFactory: PublicProcessorFactory,
45
- private publisher: ProverNodePublisher,
46
- private l2BlockSource: L2BlockSource,
47
- private l1ToL2MessageSource: L1ToL2MessageSource,
48
- private metrics: ProverNodeMetrics,
43
+ private publisher: Pick<ProverNodePublisher, 'submitEpochProof'>,
44
+ private l2BlockSource: L2BlockSource | undefined,
45
+ private metrics: ProverNodeJobMetrics,
49
46
  private deadline: Date | undefined,
50
47
  private config: { parallelBlockLimit: number } = { parallelBlockLimit: 32 },
51
48
  ) {
49
+ validateEpochProvingJobData(data);
52
50
  this.uuid = crypto.randomUUID();
53
- this.tracer = metrics.client.getTracer('EpochProvingJob');
51
+ this.tracer = metrics.tracer;
54
52
  }
55
53
 
56
54
  public getId(): string {
@@ -62,18 +60,34 @@ export class EpochProvingJob implements Traceable {
62
60
  }
63
61
 
64
62
  public getEpochNumber(): bigint {
65
- return this.epochNumber;
63
+ return this.data.epochNumber;
66
64
  }
67
65
 
68
66
  public getDeadline(): Date | undefined {
69
67
  return this.deadline;
70
68
  }
71
69
 
70
+ public getProvingData(): EpochProvingJobData {
71
+ return this.data;
72
+ }
73
+
74
+ private get epochNumber() {
75
+ return this.data.epochNumber;
76
+ }
77
+
78
+ private get blocks() {
79
+ return this.data.blocks;
80
+ }
81
+
82
+ private get txs() {
83
+ return this.data.txs;
84
+ }
85
+
72
86
  /**
73
87
  * Proves the given epoch and submits the proof to L1.
74
88
  */
75
89
  @trackSpan('EpochProvingJob.run', function () {
76
- return { [Attributes.EPOCH_NUMBER]: Number(this.epochNumber) };
90
+ return { [Attributes.EPOCH_NUMBER]: Number(this.data.epochNumber) };
77
91
  })
78
92
  public async run() {
79
93
  this.scheduleDeadlineStop();
@@ -105,8 +119,8 @@ export class EpochProvingJob implements Traceable {
105
119
 
106
120
  const globalVariables = block.header.globalVariables;
107
121
  const txs = await this.getTxs(block);
108
- const l1ToL2Messages = await this.getL1ToL2Messages(block);
109
- const previousHeader = (await this.getBlockHeader(block.number - 1))!;
122
+ const l1ToL2Messages = this.getL1ToL2Messages(block);
123
+ const previousHeader = this.getBlockHeader(block.number - 1)!;
110
124
 
111
125
  this.log.verbose(`Starting processing block ${block.number}`, {
112
126
  number: block.number,
@@ -221,10 +235,16 @@ export class EpochProvingJob implements Traceable {
221
235
  * If those change, stops the proving job with a `rerun` state, so the node re-enqueues it.
222
236
  */
223
237
  private async scheduleEpochCheck() {
224
- const intervalMs = Math.ceil((await this.l2BlockSource.getL1Constants()).ethereumSlotDuration / 2) * 1000;
238
+ const l2BlockSource = this.l2BlockSource;
239
+ if (!l2BlockSource) {
240
+ this.log.warn(`No L2 block source available, skipping epoch check`);
241
+ return;
242
+ }
243
+
244
+ const intervalMs = Math.ceil((await l2BlockSource.getL1Constants()).ethereumSlotDuration / 2) * 1000;
225
245
  this.epochCheckPromise = new RunningPromise(
226
246
  async () => {
227
- const blocks = await this.l2BlockSource.getBlockHeadersForEpoch(this.epochNumber);
247
+ const blocks = await l2BlockSource.getBlockHeadersForEpoch(this.epochNumber);
228
248
  const blockHashes = await Promise.all(blocks.map(block => block.hash()));
229
249
  const thisBlockHashes = await Promise.all(this.blocks.map(block => block.hash()));
230
250
  if (
@@ -246,12 +266,22 @@ export class EpochProvingJob implements Traceable {
246
266
  this.log.verbose(`Scheduled epoch check for epoch ${this.epochNumber} every ${intervalMs}ms`);
247
267
  }
248
268
 
249
- /* Returns the header for the given block number, or the genesis block for block zero. */
250
- private async getBlockHeader(blockNumber: number) {
251
- if (blockNumber === 0) {
252
- return (await this.dbProvider.fork()).getInitialHeader();
269
+ /* Returns the header for the given block number based on the epoch proving job data. */
270
+ private getBlockHeader(blockNumber: number) {
271
+ const block = this.blocks.find(b => b.number === blockNumber);
272
+ if (block) {
273
+ return block.header;
253
274
  }
254
- return this.l2BlockSource.getBlockHeader(blockNumber);
275
+
276
+ if (blockNumber === Number(this.data.previousBlockHeader.getBlockNumber())) {
277
+ return this.data.previousBlockHeader;
278
+ }
279
+
280
+ throw new Error(
281
+ `Block header not found for block number ${blockNumber} (got ${this.blocks
282
+ .map(b => b.number)
283
+ .join(', ')} and previous header ${this.data.previousBlockHeader.getBlockNumber()})`,
284
+ );
255
285
  }
256
286
 
257
287
  private async getTxs(block: L2Block): Promise<Tx[]> {
@@ -263,7 +293,7 @@ export class EpochProvingJob implements Traceable {
263
293
  }
264
294
 
265
295
  private getL1ToL2Messages(block: L2Block) {
266
- return this.l1ToL2MessageSource.getL1ToL2Messages(BigInt(block.number));
296
+ return this.data.l1ToL2Messages[block.number];
267
297
  }
268
298
 
269
299
  private async processTxs(publicProcessor: PublicProcessor, txs: Tx[]): Promise<ProcessedTx[]> {