Skip to content

Commit

Permalink
chore: Add spans to proving job (#10794)
Browse files Browse the repository at this point in the history
Related to #10124
  • Loading branch information
spalladino authored Dec 17, 2024
1 parent 421fb65 commit df3c51b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
9 changes: 8 additions & 1 deletion yarn-project/prover-node/src/job/epoch-proving-job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { promiseWithResolvers } from '@aztec/foundation/promise';
import { Timer } from '@aztec/foundation/timer';
import { type L1Publisher } from '@aztec/sequencer-client';
import { type PublicProcessor, type PublicProcessorFactory } from '@aztec/simulator';
import { Attributes, type Traceable, type Tracer, trackSpan } from '@aztec/telemetry-client';

import * as crypto from 'node:crypto';

Expand All @@ -27,13 +28,15 @@ import { type ProverNodeMetrics } from '../metrics.js';
* re-executes their public calls, generates a rollup proof, and submits it to L1. This job will update the
* world state as part of public call execution via the public processor.
*/
export class EpochProvingJob {
export class EpochProvingJob implements Traceable {
private state: EpochProvingJobState = 'initialized';
private log = createLogger('prover-node:epoch-proving-job');
private uuid: string;

private runPromise: Promise<void> | undefined;

public readonly tracer: Tracer;

constructor(
private dbProvider: ForkMerkleTreeOperations,
private epochNumber: bigint,
Expand All @@ -49,6 +52,7 @@ export class EpochProvingJob {
private cleanUp: (job: EpochProvingJob) => Promise<void> = () => Promise.resolve(),
) {
this.uuid = crypto.randomUUID();
this.tracer = metrics.client.getTracer('EpochProvingJob');
}

public getId(): string {
Expand All @@ -62,6 +66,9 @@ export class EpochProvingJob {
/**
* Proves the given epoch and submits the proof to L1.
*/
@trackSpan('EpochProvingJob.run', function () {
return { [Attributes.EPOCH_NUMBER]: Number(this.epochNumber) };
})
public async run() {
const epochNumber = Number(this.epochNumber);
const epochSize = this.blocks.length;
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/prover-node/src/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { type Histogram, Metrics, type TelemetryClient, ValueType } from '@aztec
export class ProverNodeMetrics {
provingJobDuration: Histogram;

constructor(client: TelemetryClient, name = 'ProverNode') {
constructor(public readonly client: TelemetryClient, name = 'ProverNode') {
const meter = client.getMeter(name);
this.provingJobDuration = meter.createHistogram(Metrics.PROVER_NODE_JOB_DURATION, {
description: 'Duration of proving job',
Expand Down
8 changes: 6 additions & 2 deletions yarn-project/prover-node/src/prover-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { type Maybe } from '@aztec/foundation/types';
import { type P2P } from '@aztec/p2p';
import { type L1Publisher } from '@aztec/sequencer-client';
import { PublicProcessorFactory } from '@aztec/simulator';
import { type TelemetryClient } from '@aztec/telemetry-client';
import { Attributes, type TelemetryClient, type Traceable, type Tracer, trackSpan } from '@aztec/telemetry-client';

import { type BondManager } from './bond/bond-manager.js';
import { EpochProvingJob, type EpochProvingJobState } from './job/epoch-proving-job.js';
Expand All @@ -42,14 +42,16 @@ export type ProverNodeOptions = {
* from a tx source in the p2p network or an external node, re-executes their public functions, creates a rollup
* proof for the epoch, and submits it to L1.
*/
export class ProverNode implements ClaimsMonitorHandler, EpochMonitorHandler, ProverNodeApi {
export class ProverNode implements ClaimsMonitorHandler, EpochMonitorHandler, ProverNodeApi, Traceable {
private log = createLogger('prover-node');

private latestEpochWeAreProving: bigint | undefined;
private jobs: Map<string, EpochProvingJob> = new Map();
private options: ProverNodeOptions;
private metrics: ProverNodeMetrics;

public readonly tracer: Tracer;

constructor(
private readonly prover: EpochProverManager,
private readonly publisher: L1Publisher,
Expand All @@ -74,6 +76,7 @@ export class ProverNode implements ClaimsMonitorHandler, EpochMonitorHandler, Pr
};

this.metrics = new ProverNodeMetrics(telemetryClient, 'ProverNode');
this.tracer = telemetryClient.getTracer('ProverNode');
}

public getP2P() {
Expand Down Expand Up @@ -242,6 +245,7 @@ export class ProverNode implements ClaimsMonitorHandler, EpochMonitorHandler, Pr
return maxPendingJobs === 0 || this.jobs.size < maxPendingJobs;
}

@trackSpan('ProverNode.createProvingJob', epochNumber => ({ [Attributes.EPOCH_NUMBER]: Number(epochNumber) }))
private async createProvingJob(epochNumber: bigint) {
if (!this.checkMaximumPendingJobs()) {
throw new Error(`Maximum pending proving jobs ${this.options.maxPendingJobs} reached. Cannot create new job.`);
Expand Down

0 comments on commit df3c51b

Please sign in to comment.