Skip to content

Commit

Permalink
feat: track spans
Browse files Browse the repository at this point in the history
  • Loading branch information
alexghr committed Jun 21, 2024
1 parent 4974c23 commit 2a64aa8
Show file tree
Hide file tree
Showing 31 changed files with 648 additions and 158 deletions.
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@
"rushstack",
"schnorr",
"secp",
"SEMRESATTRS",
"sigchld",
"Signerless",
"siloes",
Expand Down
15 changes: 15 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ services:
- source: grafana-sources
target: /etc/grafana/provisioning/datasources/default.yml

jaeger:
image: jaegertracing/all-in-one
ports:
- 16686:16686
profiles:
- metrics

volumes:
aztec:
grafana:
Expand Down Expand Up @@ -171,9 +178,17 @@ configs:
prometheus:
endpoint: 0.0.0.0:8889
metric_expiration: 5m
otlp/jaeger:
endpoint: "jaeger:4317"
tls:
insecure: true
service:
pipelines:
traces:
receivers: [otlp]
processors: [batch]
exporters: [otlp/jaeger]
metrics:
receivers: [otlp]
processors: [batch]
Expand Down
2 changes: 2 additions & 0 deletions yarn-project/aztec-node/src/aztec-node/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ export class AztecNodeService implements AztecNode {
archiver,
prover!,
simulationProvider,
telemetry,
);

return new AztecNodeService(
Expand Down Expand Up @@ -760,6 +761,7 @@ export class AztecNodeService implements AztecNode {
merkleTrees.asLatest(),
this.contractDataSource,
new WASMSimulator(),
this.telemetry,
);
const processor = await publicProcessorFactory.create(prevHeader, newGlobalVariables);
// REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
Expand Down
4 changes: 4 additions & 0 deletions yarn-project/bb-prover/src/instrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
type Histogram,
Metrics,
type TelemetryClient,
type Tracer,
ValueType,
} from '@aztec/telemetry-client';

Expand All @@ -21,7 +22,10 @@ export class ProverInstrumentation {
private circuitSize: Gauge;
private circuitPublicInputCount: Gauge;

public readonly tracer: Tracer;

constructor(telemetry: TelemetryClient, name: string = 'bb-prover') {
this.tracer = telemetry.getTracer(name);
const meter = telemetry.getMeter(name);
const msBuckets = [100, 250, 500, 1_000, 2_500, 5_000, 10_000, 30_000, 60_000, 90_000];
this.simulationDuration = meter.createHistogram(Metrics.CIRCUIT_SIMULATION_DURATION, {
Expand Down
16 changes: 15 additions & 1 deletion yarn-project/bb-prover/src/prover/bb_prover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import {
convertRootRollupOutputsFromWitnessMap,
} from '@aztec/noir-protocol-circuits-types';
import { NativeACVMSimulator } from '@aztec/simulator';
import { type TelemetryClient } from '@aztec/telemetry-client';
import { Attributes, type TelemetryClient, trackSpan } from '@aztec/telemetry-client';

import { abiEncode } from '@noir-lang/noirc_abi';
import { type Abi, type WitnessMap } from '@noir-lang/types';
Expand Down Expand Up @@ -110,6 +110,10 @@ export class BBNativeRollupProver implements ServerCircuitProver {
this.instrumentation = new ProverInstrumentation(telemetry);
}

get tracer() {
return this.instrumentation.tracer;
}

static async new(config: BBProverConfig, telemetry: TelemetryClient) {
await fs.access(config.acvmBinaryPath, fs.constants.R_OK);
await fs.mkdir(config.acvmWorkingDirectory, { recursive: true });
Expand All @@ -126,6 +130,7 @@ export class BBNativeRollupProver implements ServerCircuitProver {
* @param inputs - Inputs to the circuit.
* @returns The public inputs of the parity circuit.
*/
@trackSpan('BBNativeRollupProver.getBaseParityProof', { [Attributes.PROTOCOL_CIRCUIT_NAME]: 'base-parity' })
public async getBaseParityProof(inputs: BaseParityInputs): Promise<RootParityInput<typeof RECURSIVE_PROOF_LENGTH>> {
const { circuitOutput, proof } = await this.createRecursiveProof(
inputs,
Expand All @@ -147,6 +152,7 @@ export class BBNativeRollupProver implements ServerCircuitProver {
* @param inputs - Inputs to the circuit.
* @returns The public inputs of the parity circuit.
*/
@trackSpan('BBNativeRollupProver.getBaseParityProof', { [Attributes.PROTOCOL_CIRCUIT_NAME]: 'root-parity' })
public async getRootParityProof(
inputs: RootParityInputs,
): Promise<RootParityInput<typeof NESTED_RECURSIVE_PROOF_LENGTH>> {
Expand All @@ -170,6 +176,9 @@ export class BBNativeRollupProver implements ServerCircuitProver {
* @param inputs - The inputs to the AVM circuit.
* @returns The proof.
*/
@trackSpan('BBNativeRollupProver.getAvmProof', inputs => ({
[Attributes.APP_CIRCUIT_NAME]: inputs.functionName,
}))
public async getAvmProof(inputs: AvmCircuitInputs): Promise<ProofAndVerificationKey> {
const proofAndVk = await this.createAvmProof(inputs);
await this.verifyAvmProof(proofAndVk.proof, proofAndVk.verificationKey);
Expand All @@ -181,6 +190,11 @@ export class BBNativeRollupProver implements ServerCircuitProver {
* @param kernelRequest - The object encapsulating the request for a proof
* @returns The requested circuit's public inputs and proof
*/
@trackSpan('BBNativeRollupProver.getPublicKernelProof', kernelReq => ({
[Attributes.PROTOCOL_CIRCUIT_NAME]: mapProtocolArtifactNameToCircuitName(
PublicKernelArtifactMapping[kernelReq.type]!.artifact,
),
}))
public async getPublicKernelProof(
kernelRequest: PublicKernelNonTailRequest,
): Promise<PublicInputsAndRecursiveProof<PublicKernelCircuitPublicInputs>> {
Expand Down
16 changes: 1 addition & 15 deletions yarn-project/bb-prover/src/stats.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,7 @@
import { type PublicKernelRequest, PublicKernelType } from '@aztec/circuit-types';
import type { CircuitName } from '@aztec/circuit-types/stats';
import { type ClientProtocolArtifact, type ServerProtocolArtifact } from '@aztec/noir-protocol-circuits-types';

export function mapPublicKernelToCircuitName(kernelType: PublicKernelRequest['type']): CircuitName {
switch (kernelType) {
case PublicKernelType.SETUP:
return 'public-kernel-setup';
case PublicKernelType.APP_LOGIC:
return 'public-kernel-app-logic';
case PublicKernelType.TEARDOWN:
return 'public-kernel-teardown';
case PublicKernelType.TAIL:
return 'public-kernel-tail';
default:
throw new Error(`Unknown kernel type: ${kernelType}`);
}
}
export { mapPublicKernelToCircuitName } from '@aztec/circuit-types';

export function mapProtocolArtifactNameToCircuitName(
artifact: ServerProtocolArtifact | ClientProtocolArtifact,
Expand Down
13 changes: 12 additions & 1 deletion yarn-project/bb-prover/src/test/test_circuit_prover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import {
convertSimulatedPublicTailOutputFromWitnessMap,
} from '@aztec/noir-protocol-circuits-types';
import { type SimulationProvider, WASMSimulator, emitCircuitSimulationStats } from '@aztec/simulator';
import { type TelemetryClient } from '@aztec/telemetry-client';
import { type TelemetryClient, trackSpan } from '@aztec/telemetry-client';

import { ProverInstrumentation } from '../instrumentation.js';
import { SimulatedPublicKernelArtifactMapping } from '../mappings/mappings.js';
Expand Down Expand Up @@ -93,6 +93,10 @@ export class TestCircuitProver implements ServerCircuitProver {
this.instrumentation = new ProverInstrumentation(telemetry);
}

get tracer() {
return this.instrumentation.tracer;
}

public async getEmptyPrivateKernelProof(
inputs: PrivateKernelEmptyInputData,
): Promise<PublicInputsAndRecursiveProof<KernelCircuitPublicInputs>> {
Expand All @@ -117,6 +121,7 @@ export class TestCircuitProver implements ServerCircuitProver {
* @param inputs - Inputs to the circuit.
* @returns The public inputs of the parity circuit.
*/
@trackSpan('TestCircuitProver.getBaseParityProof')
public async getBaseParityProof(inputs: BaseParityInputs): Promise<RootParityInput<typeof RECURSIVE_PROOF_LENGTH>> {
const timer = new Timer();
const witnessMap = convertBaseParityInputsToWitnessMap(inputs);
Expand Down Expand Up @@ -149,6 +154,7 @@ export class TestCircuitProver implements ServerCircuitProver {
* @param inputs - Inputs to the circuit.
* @returns The public inputs of the parity circuit.
*/
@trackSpan('TestCircuitProver.getRootParityProof')
public async getRootParityProof(
inputs: RootParityInputs,
): Promise<RootParityInput<typeof NESTED_RECURSIVE_PROOF_LENGTH>> {
Expand Down Expand Up @@ -183,6 +189,7 @@ export class TestCircuitProver implements ServerCircuitProver {
* @param input - Inputs to the circuit.
* @returns The public inputs as outputs of the simulation.
*/
@trackSpan('TestCircuitProver.getBaseRollupProof')
public async getBaseRollupProof(
input: BaseRollupInputs,
): Promise<PublicInputsAndRecursiveProof<BaseOrMergeRollupPublicInputs>> {
Expand Down Expand Up @@ -213,6 +220,7 @@ export class TestCircuitProver implements ServerCircuitProver {
* @param input - Inputs to the circuit.
* @returns The public inputs as outputs of the simulation.
*/
@trackSpan('TestCircuitProver.getMergeRollupProof')
public async getMergeRollupProof(
input: MergeRollupInputs,
): Promise<PublicInputsAndRecursiveProof<BaseOrMergeRollupPublicInputs>> {
Expand Down Expand Up @@ -244,6 +252,7 @@ export class TestCircuitProver implements ServerCircuitProver {
* @param input - Inputs to the circuit.
* @returns The public inputs as outputs of the simulation.
*/
@trackSpan('TestCircuitProver.getRootRollupProof')
public async getRootRollupProof(
input: RootRollupInputs,
): Promise<PublicInputsAndRecursiveProof<RootRollupPublicInputs>> {
Expand All @@ -270,6 +279,7 @@ export class TestCircuitProver implements ServerCircuitProver {
);
}

@trackSpan('TestCircuitProver.getPublicKernelProof')
public async getPublicKernelProof(
kernelRequest: PublicKernelNonTailRequest,
): Promise<PublicInputsAndRecursiveProof<PublicKernelCircuitPublicInputs>> {
Expand Down Expand Up @@ -303,6 +313,7 @@ export class TestCircuitProver implements ServerCircuitProver {
);
}

@trackSpan('TestCircuitProver.getPublicTailProof')
public async getPublicTailProof(
kernelRequest: PublicKernelTailRequest,
): Promise<PublicInputsAndRecursiveProof<KernelCircuitPublicInputs>> {
Expand Down
17 changes: 17 additions & 0 deletions yarn-project/circuit-types/src/tx/processed_tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import {
makeEmptyProof,
} from '@aztec/circuits.js';

import { type CircuitName } from '../stats/stats.js';

/**
* Used to communicate to the prover which type of circuit to prove
*/
Expand Down Expand Up @@ -304,3 +306,18 @@ export function validateProcessedTx(tx: ProcessedTx): void {
validateProcessedTxLogs(tx);
// TODO: validate other fields
}

export function mapPublicKernelToCircuitName(kernelType: PublicKernelRequest['type']): CircuitName {
switch (kernelType) {
case PublicKernelType.SETUP:
return 'public-kernel-setup';
case PublicKernelType.APP_LOGIC:
return 'public-kernel-app-logic';
case PublicKernelType.TEARDOWN:
return 'public-kernel-teardown';
case PublicKernelType.TAIL:
return 'public-kernel-tail';
default:
throw new Error(`Unknown kernel type: ${kernelType}`);
}
}
7 changes: 5 additions & 2 deletions yarn-project/end-to-end/src/fixtures/snapshot_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { type Logger, createDebugLogger } from '@aztec/foundation/log';
import { makeBackoff, retry } from '@aztec/foundation/retry';
import { resolver, reviver } from '@aztec/foundation/serialize';
import { type PXEService, createPXEService, getPXEServiceConfig } from '@aztec/pxe';
import { createAndStartTelemetryClient, getConfigEnvVars as getTelemetryConfig } from '@aztec/telemetry-client/start';

import { type Anvil, createAnvil } from '@viem/anvil';
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
Expand Down Expand Up @@ -270,8 +271,9 @@ async function setupFromFresh(statePath: string | undefined, logger: Logger): Pr
aztecNodeConfig.bbWorkingDirectory = bbConfig.bbWorkingDirectory;
}

const telemetry = createAndStartTelemetryClient(getTelemetryConfig(), 'aztec-test');
logger.verbose('Creating and synching an aztec node...');
const aztecNode = await AztecNodeService.createAndSync(aztecNodeConfig);
const aztecNode = await AztecNodeService.createAndSync(aztecNodeConfig, telemetry);

logger.verbose('Creating pxe...');
const pxeConfig = getPXEServiceConfig();
Expand Down Expand Up @@ -343,7 +345,8 @@ async function setupFromState(statePath: string, logger: Logger): Promise<Subsys
const { publicClient, walletClient } = createL1Clients(aztecNodeConfig.rpcUrl, mnemonicToAccount(MNEMONIC));

logger.verbose('Creating aztec node...');
const aztecNode = await AztecNodeService.createAndSync(aztecNodeConfig);
const telemetry = createAndStartTelemetryClient(getTelemetryConfig(), 'aztec-test');
const aztecNode = await AztecNodeService.createAndSync(aztecNodeConfig, telemetry);

logger.verbose('Creating pxe...');
const pxeConfig = getPXEServiceConfig();
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/foundation/.prettierrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"importOrder": ["^@aztec/(.*)$", "<THIRD_PARTY_MODULES>", "^\\./|\\.\\./"],
"importOrderSeparation": true,
"importOrderSortSpecifiers": true,
"importOrderParserPlugins": ["importAssertions", "typescript"]
"importOrderParserPlugins": ["importAssertions", "typescript", "decorators"]
}
4 changes: 3 additions & 1 deletion yarn-project/prover-client/src/mocks/test_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export class TestContext {
const publicWorldStateDB = mock<WorldStatePublicDB>();
const publicKernel = new RealPublicKernelCircuitSimulator(new WASMSimulator());
const actualDb = await MerkleTrees.new(openTmpStore()).then(t => t.asLatest());
const telemetry = new NoopTelemetryClient();
const processor = new PublicProcessor(
actualDb,
publicExecutor,
Expand All @@ -104,6 +105,7 @@ export class TestContext {
Header.empty(),
publicContractsDB,
publicWorldStateDB,
telemetry,
);

let localProver: ServerCircuitProver;
Expand All @@ -125,7 +127,7 @@ export class TestContext {
}

const queue = new MemoryProvingQueue();
const orchestrator = new ProvingOrchestrator(actualDb, queue);
const orchestrator = new ProvingOrchestrator(actualDb, queue, telemetry);
const agent = new ProverAgent(localProver, proverCount);

queue.start();
Expand Down
Loading

0 comments on commit 2a64aa8

Please sign in to comment.