@aztec/prover-node 0.0.1-commit.2448fdb → 0.0.1-commit.2606882
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.
- package/dest/actions/download-epoch-proving-job.js +1 -1
- package/dest/actions/rerun-epoch-proving-job.d.ts +4 -3
- package/dest/actions/rerun-epoch-proving-job.d.ts.map +1 -1
- package/dest/actions/rerun-epoch-proving-job.js +8 -6
- package/dest/actions/upload-epoch-proof-failure.d.ts +2 -2
- package/dest/actions/upload-epoch-proof-failure.d.ts.map +1 -1
- package/dest/bin/run-failed-epoch.js +1 -3
- package/dest/config.d.ts +2 -2
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +1 -1
- package/dest/factory.d.ts +1 -1
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +21 -2
- package/dest/job/epoch-proving-job.d.ts +6 -2
- package/dest/job/epoch-proving-job.d.ts.map +1 -1
- package/dest/job/epoch-proving-job.js +186 -36
- package/dest/metrics.d.ts +11 -1
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +22 -0
- package/dest/monitors/epoch-monitor.js +6 -2
- package/dest/prover-node-publisher.d.ts +20 -1
- package/dest/prover-node-publisher.d.ts.map +1 -1
- package/dest/prover-node-publisher.js +200 -5
- package/dest/prover-node.d.ts +7 -7
- package/dest/prover-node.d.ts.map +1 -1
- package/dest/prover-node.js +77 -32
- package/dest/prover-publisher-factory.d.ts +2 -2
- package/dest/prover-publisher-factory.d.ts.map +1 -1
- package/dest/prover-publisher-factory.js +3 -3
- package/package.json +23 -23
- package/src/actions/download-epoch-proving-job.ts +1 -1
- package/src/actions/rerun-epoch-proving-job.ts +17 -6
- package/src/actions/upload-epoch-proof-failure.ts +1 -1
- package/src/bin/run-failed-epoch.ts +1 -2
- package/src/config.ts +1 -1
- package/src/factory.ts +18 -2
- package/src/job/epoch-proving-job.ts +102 -36
- package/src/metrics.ts +37 -0
- package/src/monitors/epoch-monitor.ts +2 -2
- package/src/prover-node-publisher.ts +232 -9
- package/src/prover-node.ts +82 -45
- package/src/prover-publisher-factory.ts +3 -3
package/src/prover-node.ts
CHANGED
|
@@ -7,7 +7,6 @@ import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
|
7
7
|
import { memoize } from '@aztec/foundation/decorators';
|
|
8
8
|
import { createLogger } from '@aztec/foundation/log';
|
|
9
9
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
10
|
-
import type { DataStoreConfig } from '@aztec/kv-store/config';
|
|
11
10
|
import { PublicProcessorFactory } from '@aztec/simulator/server';
|
|
12
11
|
import type { L2BlockSource } from '@aztec/stdlib/block';
|
|
13
12
|
import type { Checkpoint } from '@aztec/stdlib/checkpoint';
|
|
@@ -16,7 +15,6 @@ import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
|
16
15
|
import { getProofSubmissionDeadlineTimestamp } from '@aztec/stdlib/epoch-helpers';
|
|
17
16
|
import {
|
|
18
17
|
type EpochProverManager,
|
|
19
|
-
EpochProvingJobTerminalState,
|
|
20
18
|
type ITxProvider,
|
|
21
19
|
type ProverNodeApi,
|
|
22
20
|
type Service,
|
|
@@ -24,6 +22,7 @@ import {
|
|
|
24
22
|
type WorldStateSynchronizer,
|
|
25
23
|
tryStop,
|
|
26
24
|
} from '@aztec/stdlib/interfaces/server';
|
|
25
|
+
import type { DataStoreConfig } from '@aztec/stdlib/kv-store';
|
|
27
26
|
import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
|
|
28
27
|
import type { Tx } from '@aztec/stdlib/tx';
|
|
29
28
|
import {
|
|
@@ -39,7 +38,7 @@ import {
|
|
|
39
38
|
import { uploadEpochProofFailure } from './actions/upload-epoch-proof-failure.js';
|
|
40
39
|
import type { SpecificProverNodeConfig } from './config.js';
|
|
41
40
|
import type { EpochProvingJobData } from './job/epoch-proving-job-data.js';
|
|
42
|
-
import { EpochProvingJob, type EpochProvingJobState } from './job/epoch-proving-job.js';
|
|
41
|
+
import { EpochProvingJob, type EpochProvingJobOptions, type EpochProvingJobState } from './job/epoch-proving-job.js';
|
|
43
42
|
import { ProverNodeJobMetrics, ProverNodeRewardsMetrics } from './metrics.js';
|
|
44
43
|
import type { EpochMonitor, EpochMonitorHandler } from './monitors/epoch-monitor.js';
|
|
45
44
|
import type { ProverNodePublisher } from './prover-node-publisher.js';
|
|
@@ -60,6 +59,7 @@ export class ProverNode implements EpochMonitorHandler, ProverNodeApi, Traceable
|
|
|
60
59
|
private config: ProverNodeOptions;
|
|
61
60
|
private jobMetrics: ProverNodeJobMetrics;
|
|
62
61
|
private rewardsMetrics: ProverNodeRewardsMetrics;
|
|
62
|
+
private startingProofEpochs: Set<EpochNumber> = new Set();
|
|
63
63
|
|
|
64
64
|
public readonly tracer: Tracer;
|
|
65
65
|
|
|
@@ -127,15 +127,7 @@ export class ProverNode implements EpochMonitorHandler, ProverNodeApi, Traceable
|
|
|
127
127
|
this.log.debug(`Running jobs as ${epochNumber} is ready to prove`, {
|
|
128
128
|
jobs: Array.from(this.jobs.values()).map(job => `${job.getEpochNumber()}:${job.getId()}`),
|
|
129
129
|
});
|
|
130
|
-
|
|
131
|
-
if (activeJobs.length > 0) {
|
|
132
|
-
this.log.warn(`Not starting proof for ${epochNumber} since there are active jobs for the epoch`, {
|
|
133
|
-
activeJobs: activeJobs.map(job => job.uuid),
|
|
134
|
-
});
|
|
135
|
-
return true;
|
|
136
|
-
}
|
|
137
|
-
await this.startProof(epochNumber);
|
|
138
|
-
return true;
|
|
130
|
+
return await this.startProofIfNeeded(epochNumber);
|
|
139
131
|
} catch (err) {
|
|
140
132
|
if (err instanceof EmptyEpochError) {
|
|
141
133
|
this.log.info(`Not starting proof for ${epochNumber} since no blocks were found`);
|
|
@@ -166,10 +158,10 @@ export class ProverNode implements EpochMonitorHandler, ProverNodeApi, Traceable
|
|
|
166
158
|
async stop() {
|
|
167
159
|
this.log.info('Stopping ProverNode');
|
|
168
160
|
await this.epochsMonitor.stop();
|
|
169
|
-
await this.prover.stop();
|
|
170
|
-
await tryStop(this.publisherFactory);
|
|
171
161
|
this.publisher?.interrupt();
|
|
172
162
|
await Promise.all(Array.from(this.jobs.values()).map(job => job.stop()));
|
|
163
|
+
await this.prover.stop();
|
|
164
|
+
await tryStop(this.publisherFactory);
|
|
173
165
|
this.rewardsMetrics.stop();
|
|
174
166
|
this.l1Metrics.stop();
|
|
175
167
|
await this.telemetryClient.stop();
|
|
@@ -191,7 +183,38 @@ export class ProverNode implements EpochMonitorHandler, ProverNodeApi, Traceable
|
|
|
191
183
|
* Starts a proving process and returns immediately.
|
|
192
184
|
*/
|
|
193
185
|
public async startProof(epochNumber: EpochNumber) {
|
|
194
|
-
|
|
186
|
+
await this.startProofIfNeeded(epochNumber, { skipEpochCheck: true });
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
private async startProofIfNeeded(epochNumber: EpochNumber, opts: EpochProvingJobOptions = {}): Promise<boolean> {
|
|
190
|
+
if (this.startingProofEpochs.has(epochNumber)) {
|
|
191
|
+
this.log.warn(`Not starting proof for ${epochNumber} since a proof is already being started for the epoch`, {
|
|
192
|
+
epochNumber,
|
|
193
|
+
});
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
this.startingProofEpochs.add(epochNumber);
|
|
198
|
+
|
|
199
|
+
try {
|
|
200
|
+
const activeJobs = await this.activeJobsCoverEpoch(epochNumber);
|
|
201
|
+
if (activeJobs.length > 0) {
|
|
202
|
+
this.log.warn(`Not starting proof for ${epochNumber} since an active job already covers the epoch`, {
|
|
203
|
+
epochNumber,
|
|
204
|
+
activeJobs,
|
|
205
|
+
});
|
|
206
|
+
return true;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
await this.startProofInternal(epochNumber, opts);
|
|
210
|
+
return true;
|
|
211
|
+
} finally {
|
|
212
|
+
this.startingProofEpochs.delete(epochNumber);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
private async startProofInternal(epochNumber: EpochNumber, opts: EpochProvingJobOptions = {}) {
|
|
217
|
+
const job = await this.createProvingJob(epochNumber, opts);
|
|
195
218
|
void this.runJob(job);
|
|
196
219
|
}
|
|
197
220
|
|
|
@@ -245,20 +268,42 @@ export class ProverNode implements EpochMonitorHandler, ProverNodeApi, Traceable
|
|
|
245
268
|
* Returns an array of jobs being processed.
|
|
246
269
|
*/
|
|
247
270
|
public getJobs(): Promise<{ uuid: string; status: EpochProvingJobState; epochNumber: EpochNumber }[]> {
|
|
248
|
-
return Promise.resolve(
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
271
|
+
return Promise.resolve(this.getJobsInternal());
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
private getJobsInternal(): { uuid: string; status: EpochProvingJobState; epochNumber: EpochNumber }[] {
|
|
275
|
+
return Array.from(this.jobs.entries()).map(([uuid, job]) => ({
|
|
276
|
+
uuid,
|
|
277
|
+
status: job.getState(),
|
|
278
|
+
epochNumber: job.getEpochNumber(),
|
|
279
|
+
}));
|
|
255
280
|
}
|
|
256
281
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
282
|
+
private async activeJobsCoverEpoch(epochNumber: EpochNumber): Promise<string[]> {
|
|
283
|
+
const checkpoints = await this.l2BlockSource.getCheckpointsData({ epoch: epochNumber });
|
|
284
|
+
if (checkpoints.length === 0) {
|
|
285
|
+
return [];
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
const firstCheckpoint = checkpoints.at(0)!.checkpointNumber;
|
|
289
|
+
const latestCheckpoint = checkpoints.at(-1)!.checkpointNumber;
|
|
290
|
+
|
|
291
|
+
const jobs: string[] = [];
|
|
292
|
+
for (const job of this.jobs.values()) {
|
|
293
|
+
if (job.getEpochNumber() !== epochNumber) {
|
|
294
|
+
continue;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
const jobCheckpoints = job.getProvingData().checkpoints;
|
|
298
|
+
const checkpointOverlap =
|
|
299
|
+
jobCheckpoints.at(0)!.number <= firstCheckpoint && jobCheckpoints.at(-1)!.number >= latestCheckpoint;
|
|
300
|
+
|
|
301
|
+
if (checkpointOverlap && !['failed', 'stopped', 'timed-out'].includes(job.getState())) {
|
|
302
|
+
jobs.push(job.getId());
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
return jobs;
|
|
262
307
|
}
|
|
263
308
|
|
|
264
309
|
private checkMaximumPendingJobs() {
|
|
@@ -312,26 +357,21 @@ export class ProverNode implements EpochMonitorHandler, ProverNodeApi, Traceable
|
|
|
312
357
|
|
|
313
358
|
@trackSpan('ProverNode.gatherEpochData', epochNumber => ({ [Attributes.EPOCH_NUMBER]: epochNumber }))
|
|
314
359
|
private async gatherEpochData(epochNumber: EpochNumber): Promise<EpochProvingJobData> {
|
|
315
|
-
const
|
|
360
|
+
const publishedCheckpoints = await this.l2BlockSource.getCheckpoints({ epoch: epochNumber });
|
|
361
|
+
if (publishedCheckpoints.length === 0) {
|
|
362
|
+
throw new EmptyEpochError(epochNumber);
|
|
363
|
+
}
|
|
364
|
+
const checkpoints = publishedCheckpoints.map(p => p.checkpoint);
|
|
365
|
+
const attestations = publishedCheckpoints.at(-1)?.attestations ?? [];
|
|
316
366
|
const txArray = await this.gatherTxs(epochNumber, checkpoints);
|
|
317
367
|
const txs = new Map<string, Tx>(txArray.map(tx => [tx.getTxHash().toString(), tx]));
|
|
318
368
|
const l1ToL2Messages = await this.gatherMessages(epochNumber, checkpoints);
|
|
319
369
|
const [firstBlock] = checkpoints[0].blocks;
|
|
320
370
|
const previousBlockHeader = await this.gatherPreviousBlockHeader(epochNumber, firstBlock.number - 1);
|
|
321
|
-
const [lastPublishedCheckpoint] = await this.l2BlockSource.getCheckpoints(checkpoints.at(-1)!.number, 1);
|
|
322
|
-
const attestations = lastPublishedCheckpoint?.attestations ?? [];
|
|
323
371
|
|
|
324
372
|
return { checkpoints, txs, l1ToL2Messages, epochNumber, previousBlockHeader, attestations };
|
|
325
373
|
}
|
|
326
374
|
|
|
327
|
-
private async gatherCheckpoints(epochNumber: EpochNumber) {
|
|
328
|
-
const checkpoints = await this.l2BlockSource.getCheckpointsForEpoch(epochNumber);
|
|
329
|
-
if (checkpoints.length === 0) {
|
|
330
|
-
throw new EmptyEpochError(epochNumber);
|
|
331
|
-
}
|
|
332
|
-
return checkpoints;
|
|
333
|
-
}
|
|
334
|
-
|
|
335
375
|
private async gatherTxs(epochNumber: EpochNumber, checkpoints: Checkpoint[]) {
|
|
336
376
|
const deadline = new Date(this.dateProvider.now() + this.config.txGatheringTimeoutMs);
|
|
337
377
|
const txProvider = this.p2pClient.getTxProvider();
|
|
@@ -360,16 +400,13 @@ export class ProverNode implements EpochMonitorHandler, ProverNodeApi, Traceable
|
|
|
360
400
|
}
|
|
361
401
|
|
|
362
402
|
private async gatherPreviousBlockHeader(epochNumber: EpochNumber, previousBlockNumber: number) {
|
|
363
|
-
const
|
|
364
|
-
|
|
365
|
-
: this.l2BlockSource.getBlockHeader(BlockNumber(previousBlockNumber)));
|
|
366
|
-
|
|
367
|
-
if (!header) {
|
|
403
|
+
const data = await this.l2BlockSource.getBlockData({ number: BlockNumber(previousBlockNumber) });
|
|
404
|
+
if (!data?.header) {
|
|
368
405
|
throw new Error(`Previous block header ${previousBlockNumber} not found for proving epoch ${epochNumber}`);
|
|
369
406
|
}
|
|
370
407
|
|
|
371
|
-
this.log.verbose(`Gathered previous block header ${header.getBlockNumber()} for epoch ${epochNumber}`);
|
|
372
|
-
return header;
|
|
408
|
+
this.log.verbose(`Gathered previous block header ${data.header.getBlockNumber()} for epoch ${epochNumber}`);
|
|
409
|
+
return data.header;
|
|
373
410
|
}
|
|
374
411
|
|
|
375
412
|
/** Extracted for testing purposes. */
|
|
@@ -19,11 +19,11 @@ export class ProverPublisherFactory {
|
|
|
19
19
|
) {}
|
|
20
20
|
|
|
21
21
|
public async start() {
|
|
22
|
-
await this.deps.publisherManager.
|
|
22
|
+
await this.deps.publisherManager.start();
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
public stop() {
|
|
26
|
-
this.deps.publisherManager.
|
|
25
|
+
public async stop() {
|
|
26
|
+
await this.deps.publisherManager.stop();
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
/**
|