diff --git a/spartan/aztec-network/templates/boot-node.yaml b/spartan/aztec-network/templates/boot-node.yaml index 6506d22bf304..ad0122920ae8 100644 --- a/spartan/aztec-network/templates/boot-node.yaml +++ b/spartan/aztec-network/templates/boot-node.yaml @@ -179,6 +179,8 @@ spec: valueFrom: fieldRef: fieldPath: metadata.name + - name: OTEL_SERVICE_NAME + value: boot-node - name: NODE_OPTIONS value: "--max-old-space-size={{ .Values.bootNode.maxOldSpaceSize}}" - name: AZTEC_PORT diff --git a/spartan/aztec-network/templates/faucet.yaml b/spartan/aztec-network/templates/faucet.yaml index 5053999d0a6a..ffeeb0e1e4c8 100644 --- a/spartan/aztec-network/templates/faucet.yaml +++ b/spartan/aztec-network/templates/faucet.yaml @@ -81,6 +81,16 @@ spec: value: "1" - name: LOG_LEVEL value: "{{ .Values.faucet.logLevel }}" + - name: K8S_POD_UID + valueFrom: + fieldRef: + fieldPath: metadata.uid + - name: K8S_POD_NAME + valueFrom: + fieldRef: + fieldPath: metadata.name + - name: OTEL_SERVICE_NAME + value: faucet ports: - name: http containerPort: {{ .Values.faucet.service.nodePort }} diff --git a/spartan/aztec-network/templates/prover-agent.yaml b/spartan/aztec-network/templates/prover-agent.yaml index ef7399d2e7ff..7f288af3bfbc 100644 --- a/spartan/aztec-network/templates/prover-agent.yaml +++ b/spartan/aztec-network/templates/prover-agent.yaml @@ -88,6 +88,8 @@ spec: valueFrom: fieldRef: fieldPath: metadata.name + - name: OTEL_SERVICE_NAME + value: prover-agent - name: AZTEC_PORT value: "{{ .Values.proverAgent.service.nodePort }}" - name: LOG_LEVEL diff --git a/spartan/aztec-network/templates/prover-broker.yaml b/spartan/aztec-network/templates/prover-broker.yaml index c1857eb40aa0..315caf21e8e0 100644 --- a/spartan/aztec-network/templates/prover-broker.yaml +++ b/spartan/aztec-network/templates/prover-broker.yaml @@ -87,6 +87,8 @@ spec: valueFrom: fieldRef: fieldPath: metadata.name + - name: OTEL_SERVICE_NAME + value: prover-broker - name: NODE_OPTIONS value: "--max-old-space-size={{ .Values.proverBroker.maxOldSpaceSize}}" - name: AZTEC_PORT diff --git a/spartan/aztec-network/templates/prover-node.yaml b/spartan/aztec-network/templates/prover-node.yaml index f33e483180db..7420fb920b1d 100644 --- a/spartan/aztec-network/templates/prover-node.yaml +++ b/spartan/aztec-network/templates/prover-node.yaml @@ -130,6 +130,8 @@ spec: valueFrom: fieldRef: fieldPath: metadata.name + - name: OTEL_SERVICE_NAME + value: prover-node - name: POD_IP valueFrom: fieldRef: diff --git a/spartan/aztec-network/templates/pxe.yaml b/spartan/aztec-network/templates/pxe.yaml index e91bbd2a10a4..be0d0321d3a5 100644 --- a/spartan/aztec-network/templates/pxe.yaml +++ b/spartan/aztec-network/templates/pxe.yaml @@ -89,6 +89,8 @@ spec: valueFrom: fieldRef: fieldPath: metadata.name + - name: OTEL_SERVICE_NAME + value: pxe - name: AZTEC_PORT value: "{{ .Values.pxe.service.nodePort }}" - name: LOG_JSON diff --git a/spartan/aztec-network/templates/transaction-bot.yaml b/spartan/aztec-network/templates/transaction-bot.yaml index 7d4837ad40f7..fc573dfb723c 100644 --- a/spartan/aztec-network/templates/transaction-bot.yaml +++ b/spartan/aztec-network/templates/transaction-bot.yaml @@ -83,6 +83,8 @@ spec: valueFrom: fieldRef: fieldPath: metadata.name + - name: OTEL_SERVICE_NAME + value: bot - name: AZTEC_PORT value: "{{ .Values.bot.service.nodePort }}" - name: LOG_JSON diff --git a/spartan/aztec-network/templates/validator.yaml b/spartan/aztec-network/templates/validator.yaml index 02331567b02c..17d25e6a3957 100644 --- a/spartan/aztec-network/templates/validator.yaml +++ b/spartan/aztec-network/templates/validator.yaml @@ -158,6 +158,8 @@ spec: valueFrom: fieldRef: fieldPath: metadata.name + - name: OTEL_SERVICE_NAME + value: validator - name: POD_IP valueFrom: fieldRef: diff --git a/yarn-project/archiver/src/archiver/archiver.test.ts b/yarn-project/archiver/src/archiver/archiver.test.ts index e79d48becd46..03d24c096a2e 100644 --- a/yarn-project/archiver/src/archiver/archiver.test.ts +++ b/yarn-project/archiver/src/archiver/archiver.test.ts @@ -8,7 +8,7 @@ import { Fr } from '@aztec/foundation/fields'; import { type Logger, createLogger } from '@aztec/foundation/log'; import { sleep } from '@aztec/foundation/sleep'; import { type InboxAbi, RollupAbi } from '@aztec/l1-artifacts'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; +import { getTelemetryClient } from '@aztec/telemetry-client'; import { jest } from '@jest/globals'; import { type MockProxy, mock } from 'jest-mock-extended'; @@ -96,7 +96,7 @@ describe('Archiver', () => { }); blobSinkClient = mock(); - const tracer = new NoopTelemetryClient().getTracer(); + const tracer = getTelemetryClient().getTracer(''); instrumentation = mock({ isEnabled: () => true, tracer }); archiverStore = new MemoryArchiverStore(1000); l1Constants = { diff --git a/yarn-project/archiver/src/factory.ts b/yarn-project/archiver/src/factory.ts index 15dc16a9bc6d..96556003117e 100644 --- a/yarn-project/archiver/src/factory.ts +++ b/yarn-project/archiver/src/factory.ts @@ -14,8 +14,7 @@ import { TokenContractArtifact } from '@aztec/noir-contracts.js/Token'; import { TokenBridgeContractArtifact } from '@aztec/noir-contracts.js/TokenBridge'; import { protocolContractNames } from '@aztec/protocol-contracts'; import { getCanonicalProtocolContract } from '@aztec/protocol-contracts/bundle'; -import { type TelemetryClient } from '@aztec/telemetry-client'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; +import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client'; import { Archiver } from './archiver/archiver.js'; import { type ArchiverConfig } from './archiver/config.js'; @@ -25,8 +24,8 @@ import { createArchiverClient } from './rpc/index.js'; export async function createArchiver( config: ArchiverConfig & DataStoreConfig, blobSinkClient: BlobSinkClientInterface, - telemetry: TelemetryClient = new NoopTelemetryClient(), opts: { blockUntilSync: boolean } = { blockUntilSync: true }, + telemetry: TelemetryClient = getTelemetryClient(), ): Promise> { if (!config.archiverUrl) { const store = await createStore('archiver', config, createLogger('archiver:lmdb')); diff --git a/yarn-project/aztec-node/src/aztec-node/server.test.ts b/yarn-project/aztec-node/src/aztec-node/server.test.ts index c2a290c8d500..57961c558e22 100644 --- a/yarn-project/aztec-node/src/aztec-node/server.test.ts +++ b/yarn-project/aztec-node/src/aztec-node/server.test.ts @@ -20,7 +20,7 @@ import { } from '@aztec/circuits.js'; import { type P2P } from '@aztec/p2p'; import { type GlobalVariableBuilder } from '@aztec/sequencer-client'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; +import { getTelemetryClient } from '@aztec/telemetry-client'; import { type MockProxy, mock } from 'jest-mock-extended'; @@ -97,7 +97,6 @@ describe('aztec node', () => { 1, globalVariablesBuilder, new TestCircuitVerifier(), - new NoopTelemetryClient(), ); }); diff --git a/yarn-project/aztec-node/src/aztec-node/server.ts b/yarn-project/aztec-node/src/aztec-node/server.ts index 67e96b8e77c7..ffb2fb1033ee 100644 --- a/yarn-project/aztec-node/src/aztec-node/server.ts +++ b/yarn-project/aztec-node/src/aztec-node/server.ts @@ -74,8 +74,14 @@ import { getDefaultAllowedSetupFunctions, } from '@aztec/sequencer-client'; import { PublicProcessorFactory } from '@aztec/simulator'; -import { Attributes, type TelemetryClient, type Traceable, type Tracer, trackSpan } from '@aztec/telemetry-client'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; +import { + Attributes, + type TelemetryClient, + type Traceable, + type Tracer, + getTelemetryClient, + trackSpan, +} from '@aztec/telemetry-client'; import { createValidatorClient } from '@aztec/validator-client'; import { createWorldStateSynchronizer } from '@aztec/world-state'; @@ -105,7 +111,7 @@ export class AztecNodeService implements AztecNode, Traceable { protected readonly version: number, protected readonly globalVariableBuilder: GlobalVariableBuilder, private proofVerifier: ClientProtocolCircuitVerifier, - private telemetry: TelemetryClient, + private telemetry: TelemetryClient = getTelemetryClient(), private log = createLogger('node'), ) { this.packageVersion = getPackageInfo().version; @@ -142,7 +148,7 @@ export class AztecNodeService implements AztecNode, Traceable { blobSinkClient?: BlobSinkClientInterface; } = {}, ): Promise { - const telemetry = deps.telemetry ?? new NoopTelemetryClient(); + const telemetry = deps.telemetry ?? getTelemetryClient(); const log = deps.logger ?? createLogger('node'); const dateProvider = deps.dateProvider ?? new DateProvider(); const blobSinkClient = deps.blobSinkClient ?? createBlobSinkClient(config.blobSinkUrl); @@ -154,7 +160,7 @@ export class AztecNodeService implements AztecNode, Traceable { ); } - const archiver = await createArchiver(config, blobSinkClient, telemetry, { blockUntilSync: true }); + const archiver = await createArchiver(config, blobSinkClient, { blockUntilSync: true }, telemetry); // we identify the P2P transaction protocol by using the rollup contract address. // this may well change in future diff --git a/yarn-project/aztec/src/cli/aztec_start_action.ts b/yarn-project/aztec/src/cli/aztec_start_action.ts index c45892eccc13..1b6b01f26d8b 100644 --- a/yarn-project/aztec/src/cli/aztec_start_action.ts +++ b/yarn-project/aztec/src/cli/aztec_start_action.ts @@ -7,12 +7,14 @@ import { } from '@aztec/foundation/json-rpc/server'; import { type LogFn, type Logger } from '@aztec/foundation/log'; import { fileURLToPath } from '@aztec/foundation/url'; +import { getTelemetryClient } from '@aztec/telemetry-client'; import { readFileSync } from 'fs'; import { dirname, resolve } from 'path'; import { createSandbox } from '../sandbox.js'; import { github, splash } from '../splash.js'; +import { jsonRpcTelemetryMiddleware } from './json_rpc_instrumentation.js'; import { createAccountLogs, extractNamespacedOptions, installSignalHandlers } from './util.js'; const packageJsonPath = resolve(dirname(fileURLToPath(import.meta.url)), '../../package.json'); @@ -102,7 +104,12 @@ export async function aztecStart(options: any, userLog: LogFn, debugLogger: Logg installSignalHandlers(debugLogger.info, signalHandlers); if (Object.entries(services).length > 0) { - const rpcServer = createNamespacedSafeJsonRpcServer(services, false, debugLogger); + const rpcServer = createNamespacedSafeJsonRpcServer( + services, + false, + jsonRpcTelemetryMiddleware(getTelemetryClient()), + debugLogger, + ); const { port } = await startHttpRpcServer(rpcServer, { port: options.port }); debugLogger.info(`Aztec Server listening on port ${port}`); } diff --git a/yarn-project/aztec/src/cli/aztec_start_options.ts b/yarn-project/aztec/src/cli/aztec_start_options.ts index 31e7901b1d92..b9e2c2992c0e 100644 --- a/yarn-project/aztec/src/cli/aztec_start_options.ts +++ b/yarn-project/aztec/src/cli/aztec_start_options.ts @@ -19,7 +19,7 @@ import { } from '@aztec/prover-client/broker'; import { proverNodeConfigMappings } from '@aztec/prover-node/config'; import { allPxeConfigMappings } from '@aztec/pxe/config'; -import { telemetryClientConfigMappings } from '@aztec/telemetry-client/start'; +import { telemetryClientConfigMappings } from '@aztec/telemetry-client'; import { DefaultMnemonic } from '../mnemonic.js'; diff --git a/yarn-project/aztec/src/cli/cmds/start_archiver.ts b/yarn-project/aztec/src/cli/cmds/start_archiver.ts index 3713a0e1aa34..7e1272b5148f 100644 --- a/yarn-project/aztec/src/cli/cmds/start_archiver.ts +++ b/yarn-project/aztec/src/cli/cmds/start_archiver.ts @@ -5,10 +5,7 @@ import { ArchiverApiSchema } from '@aztec/circuit-types'; import { type NamespacedApiHandlers } from '@aztec/foundation/json-rpc/server'; import { type DataStoreConfig, dataConfigMappings } from '@aztec/kv-store/config'; import { createStore } from '@aztec/kv-store/lmdb'; -import { - createAndStartTelemetryClient, - getConfigEnvVars as getTelemetryClientConfig, -} from '@aztec/telemetry-client/start'; +import { getConfigEnvVars as getTelemetryClientConfig, initTelemetryClient } from '@aztec/telemetry-client'; import { extractRelevantOptions } from '../util.js'; @@ -31,7 +28,7 @@ export async function startArchiver( const store = await createStore('archiver', archiverConfig, storeLog); const archiverStore = new KVArchiverDataStore(store, archiverConfig.maxLogs); - const telemetry = await createAndStartTelemetryClient(getTelemetryClientConfig()); + const telemetry = await initTelemetryClient(getTelemetryClientConfig()); // TODO(https://github.com/AztecProtocol/aztec-packages/issues/10056): place CL url in config here const blobSinkClient = createBlobSinkClient(); const archiver = await Archiver.createAndSync(archiverConfig, archiverStore, { telemetry, blobSinkClient }, true); diff --git a/yarn-project/aztec/src/cli/cmds/start_bot.ts b/yarn-project/aztec/src/cli/cmds/start_bot.ts index 635549c189f2..a7c94504926f 100644 --- a/yarn-project/aztec/src/cli/cmds/start_bot.ts +++ b/yarn-project/aztec/src/cli/cmds/start_bot.ts @@ -3,10 +3,7 @@ import { type AztecNode, type PXE } from '@aztec/circuit-types'; import { type NamespacedApiHandlers } from '@aztec/foundation/json-rpc/server'; import { type LogFn } from '@aztec/foundation/log'; import { type TelemetryClient } from '@aztec/telemetry-client'; -import { - createAndStartTelemetryClient, - getConfigEnvVars as getTelemetryClientConfig, -} from '@aztec/telemetry-client/start'; +import { getConfigEnvVars as getTelemetryClientConfig, initTelemetryClient } from '@aztec/telemetry-client'; import { extractRelevantOptions } from '../util.js'; @@ -30,7 +27,7 @@ export async function startBot( pxe = await addPXE(options, signalHandlers, services, userLog); } - const telemetry = await createAndStartTelemetryClient(getTelemetryClientConfig()); + const telemetry = await initTelemetryClient(getTelemetryClientConfig()); await addBot(options, signalHandlers, services, { pxe, telemetry }); } diff --git a/yarn-project/aztec/src/cli/cmds/start_node.ts b/yarn-project/aztec/src/cli/cmds/start_node.ts index 1d93fd1e4ad1..98e3bfa3069b 100644 --- a/yarn-project/aztec/src/cli/cmds/start_node.ts +++ b/yarn-project/aztec/src/cli/cmds/start_node.ts @@ -5,9 +5,9 @@ import { type NamespacedApiHandlers } from '@aztec/foundation/json-rpc/server'; import { type LogFn } from '@aztec/foundation/log'; import { type TelemetryClientConfig, - createAndStartTelemetryClient, + initTelemetryClient, telemetryClientConfigMappings, -} from '@aztec/telemetry-client/start'; +} from '@aztec/telemetry-client'; import { mnemonicToAccount, privateKeyToAccount } from 'viem/accounts'; @@ -88,7 +88,7 @@ export async function startNode( } const telemetryConfig = extractRelevantOptions(options, telemetryClientConfigMappings, 'tel'); - const telemetry = await createAndStartTelemetryClient(telemetryConfig); + const telemetry = await initTelemetryClient(telemetryConfig); // Create and start Aztec Node const node = await createAztecNode(nodeConfig, { telemetry }); diff --git a/yarn-project/aztec/src/cli/cmds/start_p2p_bootstrap.ts b/yarn-project/aztec/src/cli/cmds/start_p2p_bootstrap.ts index 975f339aef65..abf96682aa92 100644 --- a/yarn-project/aztec/src/cli/cmds/start_p2p_bootstrap.ts +++ b/yarn-project/aztec/src/cli/cmds/start_p2p_bootstrap.ts @@ -3,10 +3,7 @@ import { type NamespacedApiHandlers } from '@aztec/foundation/json-rpc/server'; import { type LogFn, createLogger } from '@aztec/foundation/log'; import { createStore } from '@aztec/kv-store/lmdb'; import { type BootnodeConfig, BootstrapNode, bootnodeConfigMappings } from '@aztec/p2p'; -import { - createAndStartTelemetryClient, - getConfigEnvVars as getTelemetryClientConfig, -} from '@aztec/telemetry-client/start'; +import { getConfigEnvVars as getTelemetryClientConfig, initTelemetryClient } from '@aztec/telemetry-client'; import { extractRelevantOptions } from '../util.js'; @@ -18,7 +15,7 @@ export async function startP2PBootstrap( ) { // Start a P2P bootstrap node. const config = extractRelevantOptions(options, bootnodeConfigMappings, 'p2p'); - const telemetryClient = await createAndStartTelemetryClient(getTelemetryClientConfig()); + const telemetryClient = await initTelemetryClient(getTelemetryClientConfig()); const store = await createStore('p2p-bootstrap', config, createLogger('p2p:bootstrap:store')); const node = new BootstrapNode(store, telemetryClient); await node.start(config); diff --git a/yarn-project/aztec/src/cli/cmds/start_proof_verifier.ts b/yarn-project/aztec/src/cli/cmds/start_proof_verifier.ts index 2aa5ce823f56..1e9120f48093 100644 --- a/yarn-project/aztec/src/cli/cmds/start_proof_verifier.ts +++ b/yarn-project/aztec/src/cli/cmds/start_proof_verifier.ts @@ -1,6 +1,6 @@ import { type LogFn } from '@aztec/foundation/log'; import { ProofVerifier, proofVerifierConfigMappings } from '@aztec/proof-verifier'; -import { createAndStartTelemetryClient, telemetryClientConfigMappings } from '@aztec/telemetry-client/start'; +import { initTelemetryClient, telemetryClientConfigMappings } from '@aztec/telemetry-client'; import { extractRelevantOptions } from '../util.js'; @@ -8,7 +8,7 @@ export async function startProofVerifier(options: any, signalHandlers: (() => Pr const config = extractRelevantOptions(options, proofVerifierConfigMappings, 'proofVerifier'); const telemetryConfig = extractRelevantOptions(options, telemetryClientConfigMappings, 'tel'); - const telemetry = await createAndStartTelemetryClient(telemetryConfig); + const telemetry = await initTelemetryClient(telemetryConfig); const proofVerifier = await ProofVerifier.new(config, telemetry); userLog('Starting proof verifier'); diff --git a/yarn-project/aztec/src/cli/cmds/start_prover_agent.ts b/yarn-project/aztec/src/cli/cmds/start_prover_agent.ts index 01ee05716d14..25ee9d236530 100644 --- a/yarn-project/aztec/src/cli/cmds/start_prover_agent.ts +++ b/yarn-project/aztec/src/cli/cmds/start_prover_agent.ts @@ -10,7 +10,7 @@ import { proverAgentConfigMappings, } from '@aztec/prover-client/broker'; import { getProverNodeAgentConfigFromEnv } from '@aztec/prover-node'; -import { createAndStartTelemetryClient, telemetryClientConfigMappings } from '@aztec/telemetry-client/start'; +import { initTelemetryClient, telemetryClientConfigMappings } from '@aztec/telemetry-client'; import { extractRelevantOptions } from '../util.js'; @@ -40,9 +40,7 @@ export async function startProverAgent( const broker = createProvingJobBrokerClient(config.proverBrokerUrl); - const telemetry = await createAndStartTelemetryClient( - extractRelevantOptions(options, telemetryClientConfigMappings, 'tel'), - ); + const telemetry = await initTelemetryClient(extractRelevantOptions(options, telemetryClientConfigMappings, 'tel')); const prover = await buildServerCircuitProver(config, telemetry); const proofStore = new InlineProofStore(); const agents = times( @@ -52,9 +50,9 @@ export async function startProverAgent( broker, proofStore, prover, - telemetry, config.proverAgentProofTypes, config.proverAgentPollIntervalMs, + telemetry, ), ); diff --git a/yarn-project/aztec/src/cli/cmds/start_prover_broker.ts b/yarn-project/aztec/src/cli/cmds/start_prover_broker.ts index ec0abcd36492..6ce6e8ebff57 100644 --- a/yarn-project/aztec/src/cli/cmds/start_prover_broker.ts +++ b/yarn-project/aztec/src/cli/cmds/start_prover_broker.ts @@ -8,10 +8,7 @@ import { proverBrokerConfigMappings, } from '@aztec/prover-client/broker'; import { getProverNodeBrokerConfigFromEnv } from '@aztec/prover-node'; -import { - createAndStartTelemetryClient, - getConfigEnvVars as getTelemetryClientConfig, -} from '@aztec/telemetry-client/start'; +import { getConfigEnvVars as getTelemetryClientConfig, initTelemetryClient } from '@aztec/telemetry-client'; import { extractRelevantOptions } from '../util.js'; @@ -31,7 +28,7 @@ export async function startProverBroker( ...extractRelevantOptions(options, proverBrokerConfigMappings, 'proverBroker'), // override with command line options }; - const client = await createAndStartTelemetryClient(getTelemetryClientConfig()); + const client = await initTelemetryClient(getTelemetryClientConfig()); const broker = await createAndStartProvingBroker(config, client); services.proverBroker = [broker, ProvingJobBrokerSchema]; signalHandlers.push(() => broker.stop()); diff --git a/yarn-project/aztec/src/cli/cmds/start_prover_node.ts b/yarn-project/aztec/src/cli/cmds/start_prover_node.ts index ceb4cc00ff52..a68a266027c3 100644 --- a/yarn-project/aztec/src/cli/cmds/start_prover_node.ts +++ b/yarn-project/aztec/src/cli/cmds/start_prover_node.ts @@ -9,7 +9,7 @@ import { getProverNodeConfigFromEnv, proverNodeConfigMappings, } from '@aztec/prover-node'; -import { createAndStartTelemetryClient, telemetryClientConfigMappings } from '@aztec/telemetry-client/start'; +import { initTelemetryClient, telemetryClientConfigMappings } from '@aztec/telemetry-client'; import { mnemonicToAccount } from 'viem/accounts'; @@ -58,9 +58,7 @@ export async function startProverNode( proverConfig.l1Contracts = await createAztecNodeClient(nodeUrl).getL1ContractAddresses(); } - const telemetry = await createAndStartTelemetryClient( - extractRelevantOptions(options, telemetryClientConfigMappings, 'tel'), - ); + const telemetry = await initTelemetryClient(extractRelevantOptions(options, telemetryClientConfigMappings, 'tel')); let broker: ProvingJobBroker; if (proverConfig.proverBrokerUrl) { diff --git a/yarn-project/aztec/src/cli/json_rpc_instrumentation.ts b/yarn-project/aztec/src/cli/json_rpc_instrumentation.ts new file mode 100644 index 000000000000..7740cd613b53 --- /dev/null +++ b/yarn-project/aztec/src/cli/json_rpc_instrumentation.ts @@ -0,0 +1,29 @@ +import { type DiagnosticsMiddleware } from '@aztec/foundation/json-rpc/server'; +import { type Span, SpanStatusCode, type TelemetryClient } from '@aztec/telemetry-client'; + +export function jsonRpcTelemetryMiddleware(client: TelemetryClient, name = 'SafeJsonRpcServer'): DiagnosticsMiddleware { + const tracer = client.getTracer(name); + + return async (ctx, next) => { + return tracer.startActiveSpan('JsonRpcCall', async (span: Span): Promise => { + if (ctx.id) { + span.setAttribute('jsonrpc_id', ctx.id); + } + span.setAttribute('jsonrpc_method', ctx.method); + + try { + await next(); + span.setStatus({ + code: SpanStatusCode.OK, + }); + } catch (err) { + span.setStatus({ + code: SpanStatusCode.ERROR, + message: String(err), + }); + } finally { + span.end(); + } + }); + }; +} diff --git a/yarn-project/aztec/src/sandbox.ts b/yarn-project/aztec/src/sandbox.ts index c6a7dd8363cc..7a66a499cd62 100644 --- a/yarn-project/aztec/src/sandbox.ts +++ b/yarn-project/aztec/src/sandbox.ts @@ -16,11 +16,12 @@ import { createLogger } from '@aztec/foundation/log'; import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vks'; import { ProtocolContractAddress, protocolContractTreeRoot } from '@aztec/protocol-contracts'; import { type PXEServiceConfig, createPXEService, getPXEServiceConfig } from '@aztec/pxe'; -import { type TelemetryClient } from '@aztec/telemetry-client'; import { - createAndStartTelemetryClient, + type TelemetryClient, + getTelemetryClient, getConfigEnvVars as getTelemetryClientConfig, -} from '@aztec/telemetry-client/start'; + initTelemetryClient, +} from '@aztec/telemetry-client'; import { type HDAccount, type PrivateKeyAccount, createPublicClient, http as httpViemTransport } from 'viem'; import { mnemonicToAccount } from 'viem/accounts'; @@ -144,7 +145,7 @@ export async function createSandbox(config: Partial = {}) { await watcher.start(); } - const telemetry = await createAndStartTelemetryClient(getTelemetryClientConfig()); + const telemetry = await initTelemetryClient(getTelemetryClientConfig()); // Create a local blob sink client inside the sandbox, no http connectivity const blobSinkClient = createBlobSinkClient(); const node = await createAztecNode(aztecNodeConfig, { telemetry, blobSinkClient }); diff --git a/yarn-project/bb-prover/src/prover/bb_prover.ts b/yarn-project/bb-prover/src/prover/bb_prover.ts index 28e7b7e36366..67b310abdbfc 100644 --- a/yarn-project/bb-prover/src/prover/bb_prover.ts +++ b/yarn-project/bb-prover/src/prover/bb_prover.ts @@ -70,7 +70,7 @@ import { convertSingleTxBlockRootRollupOutputsFromWitnessMap, } from '@aztec/noir-protocol-circuits-types/server'; import { NativeACVMSimulator } from '@aztec/simulator'; -import { Attributes, type TelemetryClient, trackSpan } from '@aztec/telemetry-client'; +import { Attributes, type TelemetryClient, getTelemetryClient, trackSpan } from '@aztec/telemetry-client'; import { type WitnessMap } from '@noir-lang/types'; import { assert } from 'console'; @@ -129,7 +129,7 @@ export class BBNativeRollupProver implements ServerCircuitProver { return this.instrumentation.tracer; } - static async new(config: BBProverConfig, telemetry: TelemetryClient) { + static async new(config: BBProverConfig, telemetry: TelemetryClient = getTelemetryClient()) { await fs.access(config.acvmBinaryPath, fs.constants.R_OK); await fs.mkdir(config.acvmWorkingDirectory, { recursive: true }); await fs.access(config.bbBinaryPath, fs.constants.R_OK); diff --git a/yarn-project/bb-prover/src/test/test_circuit_prover.ts b/yarn-project/bb-prover/src/test/test_circuit_prover.ts index 3cfbc0f5e748..9dfa1f3413fb 100644 --- a/yarn-project/bb-prover/src/test/test_circuit_prover.ts +++ b/yarn-project/bb-prover/src/test/test_circuit_prover.ts @@ -64,7 +64,7 @@ import { } from '@aztec/noir-protocol-circuits-types/server'; import { ProtocolCircuitVks } from '@aztec/noir-protocol-circuits-types/vks'; import { type SimulationProvider, WASMSimulatorWithBlobs, emitCircuitSimulationStats } from '@aztec/simulator'; -import { type TelemetryClient, trackSpan } from '@aztec/telemetry-client'; +import { type TelemetryClient, getTelemetryClient, trackSpan } from '@aztec/telemetry-client'; import { type WitnessMap } from '@noir-lang/types'; @@ -81,9 +81,9 @@ export class TestCircuitProver implements ServerCircuitProver { private logger = createLogger('bb-prover:test-prover'); constructor( - telemetry: TelemetryClient, private simulationProvider?: SimulationProvider, private opts: { proverTestDelayMs: number } = { proverTestDelayMs: 0 }, + telemetry: TelemetryClient = getTelemetryClient(), ) { this.instrumentation = new ProverInstrumentation(telemetry, 'TestCircuitProver'); } diff --git a/yarn-project/blob-sink/src/server/server.ts b/yarn-project/blob-sink/src/server/server.ts index 0727ba4a70f3..2103750bbd12 100644 --- a/yarn-project/blob-sink/src/server/server.ts +++ b/yarn-project/blob-sink/src/server/server.ts @@ -1,8 +1,7 @@ import { Blob } from '@aztec/foundation/blob'; import { type Logger, createLogger } from '@aztec/foundation/log'; import { type AztecKVStore } from '@aztec/kv-store'; -import { type TelemetryClient } from '@aztec/telemetry-client'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; +import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client'; import express, { type Express, type Request, type Response, json } from 'express'; import { type Server } from 'http'; @@ -32,7 +31,7 @@ export class BlobSinkServer { private metrics: BlobSinkMetrics; private log: Logger = createLogger('aztec:blob-sink'); - constructor(config?: BlobSinkConfig, store?: AztecKVStore, telemetry: TelemetryClient = new NoopTelemetryClient()) { + constructor(config?: BlobSinkConfig, store?: AztecKVStore, telemetry: TelemetryClient = getTelemetryClient()) { this.port = config?.port ?? 5052; // 5052 is beacon chain default http port this.app = express(); diff --git a/yarn-project/end-to-end/src/composed/integration_l1_publisher.test.ts b/yarn-project/end-to-end/src/composed/integration_l1_publisher.test.ts index 1a727d8f5553..1334d39aadf0 100644 --- a/yarn-project/end-to-end/src/composed/integration_l1_publisher.test.ts +++ b/yarn-project/end-to-end/src/composed/integration_l1_publisher.test.ts @@ -27,7 +27,6 @@ import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vks'; import { protocolContractTreeRoot } from '@aztec/protocol-contracts'; import { LightweightBlockBuilder } from '@aztec/prover-client/block-builder'; import { L1Publisher } from '@aztec/sequencer-client'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; import { type MerkleTreeAdminDatabase, NativeWorldStateService, @@ -171,20 +170,17 @@ describe('L1Publisher integration', () => { worldStateSynchronizer = new ServerWorldStateSynchronizer(builderDb, blockSource, worldStateConfig); await worldStateSynchronizer.start(); - publisher = new L1Publisher( - { - l1RpcUrl: config.l1RpcUrl, - requiredConfirmations: 1, - l1Contracts: l1ContractAddresses, - publisherPrivateKey: sequencerPK, - l1PublishRetryIntervalMS: 100, - l1ChainId: 31337, - viemPollingIntervalMS: 100, - ethereumSlotDuration: config.ethereumSlotDuration, - blobSinkUrl: BLOB_SINK_URL, - }, - { telemetry: new NoopTelemetryClient() }, - ); + publisher = new L1Publisher({ + l1RpcUrl: config.l1RpcUrl, + requiredConfirmations: 1, + l1Contracts: l1ContractAddresses, + publisherPrivateKey: sequencerPK, + l1PublishRetryIntervalMS: 100, + l1ChainId: 31337, + viemPollingIntervalMS: 100, + ethereumSlotDuration: config.ethereumSlotDuration, + blobSinkUrl: BLOB_SINK_URL, + }); coinbase = config.coinbase || EthAddress.random(); feeRecipient = config.feeRecipient || AztecAddress.random(); @@ -323,7 +319,7 @@ describe('L1Publisher integration', () => { const buildBlock = async (globalVariables: GlobalVariables, txs: ProcessedTx[], l1ToL2Messages: Fr[]) => { await worldStateSynchronizer.syncImmediate(); const tempFork = await worldStateSynchronizer.fork(); - const tempBuilder = new LightweightBlockBuilder(tempFork, new NoopTelemetryClient()); + const tempBuilder = new LightweightBlockBuilder(tempFork); await tempBuilder.startNewBlock(globalVariables, l1ToL2Messages); await tempBuilder.addTxs(txs); const block = await tempBuilder.setBlockCompleted(); diff --git a/yarn-project/end-to-end/src/e2e_block_building.test.ts b/yarn-project/end-to-end/src/e2e_block_building.test.ts index 148b090eab8a..ff1f18660818 100644 --- a/yarn-project/end-to-end/src/e2e_block_building.test.ts +++ b/yarn-project/end-to-end/src/e2e_block_building.test.ts @@ -33,7 +33,6 @@ import { type SequencerClient, SequencerState } from '@aztec/sequencer-client'; import { type TestSequencerClient } from '@aztec/sequencer-client/test'; import { PublicProcessorFactory, type PublicTxResult, PublicTxSimulator, type WorldStateDB } from '@aztec/simulator'; import { type TelemetryClient } from '@aztec/telemetry-client'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; import { jest } from '@jest/globals'; import 'jest-extended'; @@ -195,11 +194,7 @@ describe('e2e_block_building', () => { // We tweak the sequencer so it uses a fake simulator that adds a delay to every public tx. const archiver = (aztecNode as AztecNodeService).getContractDataSource(); - sequencer.sequencer.publicProcessorFactory = new TestPublicProcessorFactory( - archiver, - dateProvider!, - new NoopTelemetryClient(), - ); + sequencer.sequencer.publicProcessorFactory = new TestPublicProcessorFactory(archiver, dateProvider!); // We also cheat the sequencer's timetable so it allocates little time to processing. // This will leave the sequencer with just a few seconds to build the block, so it shouldn't @@ -622,18 +617,18 @@ class TestPublicProcessorFactory extends PublicProcessorFactory { protected override createPublicTxSimulator( db: MerkleTreeWriteOperations, worldStateDB: WorldStateDB, - telemetryClient: TelemetryClient, globalVariables: GlobalVariables, doMerkleOperations: boolean, enforceFeePayment: boolean, + telemetryClient?: TelemetryClient, ): PublicTxSimulator { return new TestPublicTxSimulator( db, worldStateDB, - telemetryClient, globalVariables, doMerkleOperations, enforceFeePayment, + telemetryClient, ); } } diff --git a/yarn-project/end-to-end/src/e2e_prover/e2e_prover_test.ts b/yarn-project/end-to-end/src/e2e_prover/e2e_prover_test.ts index 11a67f90b416..52dde592ce1b 100644 --- a/yarn-project/end-to-end/src/e2e_prover/e2e_prover_test.ts +++ b/yarn-project/end-to-end/src/e2e_prover/e2e_prover_test.ts @@ -28,7 +28,7 @@ import { RollupAbi, TestERC20Abi } from '@aztec/l1-artifacts'; import { TokenContract } from '@aztec/noir-contracts.js/Token'; import { type ProverNode, type ProverNodeConfig, createProverNode } from '@aztec/prover-node'; import { type PXEService } from '@aztec/pxe'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; +import { getTelemetryClient } from '@aztec/telemetry-client'; // TODO(#7373): Deploy honk solidity verifier // @ts-expect-error solc-js doesn't publish its types https://github.com/ethereum/solc-js/issues/689 @@ -254,7 +254,6 @@ export class FullProverTest { const archiver = await createArchiver( { ...this.context.aztecNodeConfig, dataDirectory: undefined }, blobSinkClient, - new NoopTelemetryClient(), { blockUntilSync: true }, ); diff --git a/yarn-project/end-to-end/src/e2e_synching.test.ts b/yarn-project/end-to-end/src/e2e_synching.test.ts index 24aeb10de9a3..f30ec1572414 100644 --- a/yarn-project/end-to-end/src/e2e_synching.test.ts +++ b/yarn-project/end-to-end/src/e2e_synching.test.ts @@ -57,7 +57,6 @@ import { SpamContract } from '@aztec/noir-contracts.js/Spam'; import { TokenContract } from '@aztec/noir-contracts.js/Token'; import { type PXEService } from '@aztec/pxe'; import { L1Publisher } from '@aztec/sequencer-client'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; import { createWorldStateSynchronizer } from '@aztec/world-state'; import * as fs from 'fs'; @@ -398,7 +397,7 @@ describe('e2e_synching', () => { ethereumSlotDuration: ETHEREUM_SLOT_DURATION, blobSinkUrl: `http://localhost:${blobSink?.port ?? 5052}`, }, - { telemetry: new NoopTelemetryClient(), blobSinkClient }, + { blobSinkClient }, ); const blocks = variant.loadBlocks(); @@ -502,12 +501,12 @@ describe('e2e_synching', () => { } const blobSinkClient = createBlobSinkClient(`http://localhost:${opts.blobSink?.port ?? 5052}`); - const archiver = await createArchiver(opts.config!, blobSinkClient, new NoopTelemetryClient(), { + const archiver = await createArchiver(opts.config!, blobSinkClient, { blockUntilSync: true, }); const pendingBlockNumber = await rollup.read.getPendingBlockNumber(); - const worldState = await createWorldStateSynchronizer(opts.config!, archiver, new NoopTelemetryClient()); + const worldState = await createWorldStateSynchronizer(opts.config!, archiver); await worldState.start(); expect(await worldState.getLatestBlockNumber()).toEqual(Number(pendingBlockNumber)); diff --git a/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts b/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts index 44e677aa46a3..e1af57d02b1f 100644 --- a/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts +++ b/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts @@ -24,7 +24,7 @@ import { resolver, reviver } from '@aztec/foundation/serialize'; import { TestDateProvider } from '@aztec/foundation/timer'; import { type ProverNode } from '@aztec/prover-node'; import { type PXEService, createPXEService, getPXEServiceConfig } from '@aztec/pxe'; -import { createAndStartTelemetryClient, getConfigEnvVars as getTelemetryConfig } from '@aztec/telemetry-client/start'; +import { getConfigEnvVars as getTelemetryConfig, initTelemetryClient } from '@aztec/telemetry-client'; import { type Anvil } from '@viem/anvil'; import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs'; @@ -490,7 +490,7 @@ async function setupFromState(statePath: string, logger: Logger): Promise { - const client = await telemetryPromise; - await client.stop(); + await getTelemetryClient().stop(); }); } @@ -456,12 +453,9 @@ export async function setup( } config.l1PublishRetryIntervalMS = 100; - const telemetry = await telemetryPromise; - const blobSinkClient = createBlobSinkClient(config.blobSinkUrl); - const publisher = new TestL1Publisher(config, { telemetry, blobSinkClient }); + const publisher = new TestL1Publisher(config, { blobSinkClient }); const aztecNode = await AztecNodeService.createAndSync(config, { - telemetry, publisher, dateProvider, blobSinkClient, @@ -738,8 +732,7 @@ export async function createAndSyncProverNode( const blobSinkClient = createBlobSinkClient(); // Creating temp store and archiver for simulated prover node const archiverConfig = { ...aztecNodeConfig, dataDirectory }; - const telemetry = new NoopTelemetryClient(); - const archiver = await createArchiver(archiverConfig, blobSinkClient, telemetry, { + const archiver = await createArchiver(archiverConfig, blobSinkClient, { blockUntilSync: true, }); @@ -765,7 +758,7 @@ export async function createAndSyncProverNode( }; // Use testing l1 publisher - const publisher = new TestL1Publisher(proverConfig, { telemetry, blobSinkClient }); + const publisher = new TestL1Publisher(proverConfig, { blobSinkClient }); const proverNode = await createProverNode(proverConfig, { aztecNodeTxProvider: aztecNodeWithoutStop, diff --git a/yarn-project/end-to-end/src/fixtures/with_telemetry_utils.ts b/yarn-project/end-to-end/src/fixtures/with_telemetry_utils.ts index aed13a14fde5..c8644816d53a 100644 --- a/yarn-project/end-to-end/src/fixtures/with_telemetry_utils.ts +++ b/yarn-project/end-to-end/src/fixtures/with_telemetry_utils.ts @@ -1,28 +1,18 @@ import { levels, registerLoggingStream } from '@aztec/foundation/log'; -import { type TelemetryClient } from '@aztec/telemetry-client'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; -import { OTelPinoStream } from '@aztec/telemetry-client/otel-pino-stream'; import { + type TelemetryClient, type TelemetryClientConfig, - createAndStartTelemetryClient, getConfigEnvVars as getTelemetryConfig, -} from '@aztec/telemetry-client/start'; + initTelemetryClient, +} from '@aztec/telemetry-client'; +import { OTelPinoStream } from '@aztec/telemetry-client/otel-pino-stream'; -let telemetryClient: Promise | undefined; export function getEndToEndTestTelemetryClient(metricsPort?: number): Promise { - if (!metricsPort) { - return Promise.resolve(new NoopTelemetryClient()); - } - if (!telemetryClient) { - telemetryClient = createEndToEndTestOtelClient(metricsPort); + if (metricsPort) { + const otelStream = new OTelPinoStream({ levels }); + registerLoggingStream(otelStream); } - return telemetryClient; -} - -function createEndToEndTestOtelClient(metricsPort: number): Promise { - const otelStream = new OTelPinoStream({ levels }); - registerLoggingStream(otelStream); - return createAndStartTelemetryClient(getEndToEndTestTelemetryConfig(metricsPort)); + return initTelemetryClient(getEndToEndTestTelemetryConfig(metricsPort)); } /** diff --git a/yarn-project/foundation/src/json-rpc/server/safe_json_rpc_server.ts b/yarn-project/foundation/src/json-rpc/server/safe_json_rpc_server.ts index 8d680cada320..dde6441e1235 100644 --- a/yarn-project/foundation/src/json-rpc/server/safe_json_rpc_server.ts +++ b/yarn-project/foundation/src/json-rpc/server/safe_json_rpc_server.ts @@ -14,6 +14,15 @@ import { type ApiSchema, type ApiSchemaFor, parseWithOptionals, schemaHasMethod import { jsonStringify } from '../convert.js'; import { assert } from '../js_utils.js'; +export type DiagnosticsData = { + id: number | string | null; + method: string; + params: any[]; + headers: http.IncomingHttpHeaders; +}; + +export type DiagnosticsMiddleware = (ctx: DiagnosticsData, next: () => Promise) => Promise; + export class SafeJsonRpcServer { /** * The HTTP server accepting remote requests. @@ -31,6 +40,8 @@ export class SafeJsonRpcServer { private http200OnError = false, /** Health check function */ private readonly healthCheck: StatusCheckFn = () => true, + /** Export diagnostics data */ + private diagnosticsMiddleware?: DiagnosticsMiddleware, /** Logger */ private log = createLogger('json-rpc:server'), ) {} @@ -84,11 +95,26 @@ export class SafeJsonRpcServer { this.log.error(`Error on API handler: ${error}`); }); - app.use(compress({ br: false } as any)); + app.use(compress({ br: false })); app.use(jsonResponse); app.use(exceptionHandler); app.use(bodyParser({ jsonLimit: '50mb', enableTypes: ['json'], detectJSON: () => true })); app.use(cors()); + app.use((ctx, next) => { + const { params = [], id, method } = (ctx.request.body as any) ?? {}; + if (!this.diagnosticsMiddleware || !method) { + return next(); + } + + const diagnosticsContext: DiagnosticsData = { + id, + params, + method, + headers: ctx.headers, + }; + + return this.diagnosticsMiddleware(diagnosticsContext, next); + }); app.use(router.routes()); app.use(router.allowedMethods()); @@ -108,7 +134,9 @@ export class SafeJsonRpcServer { // Fail if not a registered function in the proxy if (typeof method !== 'string' || method === 'constructor' || !this.proxy.hasMethod(method)) { ctx.status = 400; - ctx.body = { jsonrpc, id, error: { code: -32601, message: `Method not found: ${method}` } }; + const code = -32601; + const message = `Method not found: ${method}`; + ctx.body = { jsonrpc, id, error: { code, message } }; } else { ctx.status = 200; try { @@ -273,11 +301,12 @@ function makeAggregateHealthcheck(namedHandlers: NamespacedApiHandlers, log?: Lo export function createNamespacedSafeJsonRpcServer( handlers: NamespacedApiHandlers, http200OnError = false, + diagnostics?: DiagnosticsMiddleware, log = createLogger('json-rpc:server'), ): SafeJsonRpcServer { const proxy = new NamespacedSafeJsonProxy(handlers); const healthCheck = makeAggregateHealthcheck(handlers, log); - return new SafeJsonRpcServer(proxy, http200OnError, healthCheck, log); + return new SafeJsonRpcServer(proxy, http200OnError, healthCheck, diagnostics, log); } export function createSafeJsonRpcServer( diff --git a/yarn-project/foundation/src/json-rpc/server/telemetry.ts b/yarn-project/foundation/src/json-rpc/server/telemetry.ts new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/yarn-project/p2p-bootstrap/src/index.ts b/yarn-project/p2p-bootstrap/src/index.ts index 3ccc3ad325db..c3af829a460b 100644 --- a/yarn-project/p2p-bootstrap/src/index.ts +++ b/yarn-project/p2p-bootstrap/src/index.ts @@ -1,8 +1,7 @@ import { createLogger } from '@aztec/foundation/log'; import { createStore } from '@aztec/kv-store/lmdb'; import { type BootnodeConfig, BootstrapNode } from '@aztec/p2p'; -import { type TelemetryClient } from '@aztec/telemetry-client'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; +import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client'; import Koa from 'koa'; import Router from 'koa-router'; @@ -16,7 +15,7 @@ const { HTTP_PORT } = process.env; */ async function main( config: BootnodeConfig, - telemetryClient: TelemetryClient = new NoopTelemetryClient(), + telemetryClient: TelemetryClient = getTelemetryClient(), logger = debugLogger, ) { const store = await createStore('p2p-bootstrap', config, logger); diff --git a/yarn-project/p2p/src/client/factory.ts b/yarn-project/p2p/src/client/factory.ts index 926286c19bad..e29c4b952062 100644 --- a/yarn-project/p2p/src/client/factory.ts +++ b/yarn-project/p2p/src/client/factory.ts @@ -9,8 +9,7 @@ import { createLogger } from '@aztec/foundation/log'; import { type AztecKVStore } from '@aztec/kv-store'; import { type DataStoreConfig } from '@aztec/kv-store/config'; import { createStore } from '@aztec/kv-store/lmdb'; -import { type TelemetryClient } from '@aztec/telemetry-client'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; +import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client'; import { P2PClient } from '../client/p2p_client.js'; import { type P2PConfig } from '../config.js'; @@ -39,7 +38,7 @@ export const createP2PClient = async ( proofVerifier: ClientProtocolCircuitVerifier, worldStateSynchronizer: WorldStateSynchronizer, epochCache: EpochCache, - telemetry: TelemetryClient = new NoopTelemetryClient(), + telemetry: TelemetryClient = getTelemetryClient(), deps: P2PClientDeps = {}, ) => { let config = { ..._config }; diff --git a/yarn-project/p2p/src/client/p2p_client.ts b/yarn-project/p2p/src/client/p2p_client.ts index aeb51ae3fcdd..44010f75b07e 100644 --- a/yarn-project/p2p/src/client/p2p_client.ts +++ b/yarn-project/p2p/src/client/p2p_client.ts @@ -21,9 +21,9 @@ import { type TelemetryClient, TraceableL2BlockStream, WithTracer, + getTelemetryClient, trackSpan, } from '@aztec/telemetry-client'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; import { type ENR } from '@chainsafe/enr'; @@ -228,7 +228,7 @@ export class P2PClient mempools: MemPools, private p2pService: P2PService, private keepProvenTxsFor: number, - telemetry: TelemetryClient = new NoopTelemetryClient(), + telemetry: TelemetryClient = getTelemetryClient(), private log = createLogger('p2p'), ) { super(telemetry, 'P2PClient'); diff --git a/yarn-project/p2p/src/mem_pools/attestation_pool/kv_attestation_pool.test.ts b/yarn-project/p2p/src/mem_pools/attestation_pool/kv_attestation_pool.test.ts index 2832694784ce..2264715fa328 100644 --- a/yarn-project/p2p/src/mem_pools/attestation_pool/kv_attestation_pool.test.ts +++ b/yarn-project/p2p/src/mem_pools/attestation_pool/kv_attestation_pool.test.ts @@ -1,6 +1,5 @@ import { type AztecKVStore } from '@aztec/kv-store'; import { openTmpStore } from '@aztec/kv-store/lmdb'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; import { describeAttestationPool } from './attestation_pool_test_suite.js'; import { KvAttestationPool } from './kv_attestation_pool.js'; @@ -11,7 +10,7 @@ describe('KV Attestation Pool', () => { beforeEach(() => { store = openTmpStore(); - kvAttestationPool = new KvAttestationPool(store, new NoopTelemetryClient()); + kvAttestationPool = new KvAttestationPool(store); }); describeAttestationPool(() => kvAttestationPool); diff --git a/yarn-project/p2p/src/mem_pools/attestation_pool/kv_attestation_pool.ts b/yarn-project/p2p/src/mem_pools/attestation_pool/kv_attestation_pool.ts index 8de98828eed0..ea6f848e9fdb 100644 --- a/yarn-project/p2p/src/mem_pools/attestation_pool/kv_attestation_pool.ts +++ b/yarn-project/p2p/src/mem_pools/attestation_pool/kv_attestation_pool.ts @@ -2,7 +2,7 @@ import { BlockAttestation } from '@aztec/circuit-types'; import { Fr } from '@aztec/foundation/fields'; import { createLogger } from '@aztec/foundation/log'; import { type AztecKVStore, type AztecMapWithSize, type AztecMultiMap } from '@aztec/kv-store'; -import { type TelemetryClient } from '@aztec/telemetry-client'; +import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client'; import { PoolInstrumentation, PoolName } from '../instrumentation.js'; import { type AttestationPool } from './attestation_pool.js'; @@ -15,7 +15,7 @@ export class KvAttestationPool implements AttestationPool { constructor( private store: AztecKVStore, - telemetry: TelemetryClient, + telemetry: TelemetryClient = getTelemetryClient(), private log = createLogger('aztec:attestation_pool'), ) { this.attestations = store.openMultiMap('attestations'); diff --git a/yarn-project/p2p/src/mem_pools/attestation_pool/memory_attestation_pool.test.ts b/yarn-project/p2p/src/mem_pools/attestation_pool/memory_attestation_pool.test.ts index 5d2cd81b625c..69fd23a8a8f9 100644 --- a/yarn-project/p2p/src/mem_pools/attestation_pool/memory_attestation_pool.test.ts +++ b/yarn-project/p2p/src/mem_pools/attestation_pool/memory_attestation_pool.test.ts @@ -1,12 +1,10 @@ -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; - import { describeAttestationPool } from './attestation_pool_test_suite.js'; import { InMemoryAttestationPool } from './memory_attestation_pool.js'; describe('In-Memory Attestation Pool', () => { let inMemoryAttestationPool: InMemoryAttestationPool; beforeEach(() => { - inMemoryAttestationPool = new InMemoryAttestationPool(new NoopTelemetryClient()); + inMemoryAttestationPool = new InMemoryAttestationPool(); }); describeAttestationPool(() => inMemoryAttestationPool); diff --git a/yarn-project/p2p/src/mem_pools/attestation_pool/memory_attestation_pool.ts b/yarn-project/p2p/src/mem_pools/attestation_pool/memory_attestation_pool.ts index fe39a3fba186..35d94c7b11bf 100644 --- a/yarn-project/p2p/src/mem_pools/attestation_pool/memory_attestation_pool.ts +++ b/yarn-project/p2p/src/mem_pools/attestation_pool/memory_attestation_pool.ts @@ -1,6 +1,6 @@ import { type BlockAttestation } from '@aztec/circuit-types'; import { createLogger } from '@aztec/foundation/log'; -import { type TelemetryClient } from '@aztec/telemetry-client'; +import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client'; import { PoolInstrumentation, PoolName } from '../instrumentation.js'; import { type AttestationPool } from './attestation_pool.js'; @@ -10,7 +10,7 @@ export class InMemoryAttestationPool implements AttestationPool { private attestations: Map>>; - constructor(telemetry: TelemetryClient, private log = createLogger('p2p:attestation_pool')) { + constructor(telemetry: TelemetryClient = getTelemetryClient(), private log = createLogger('p2p:attestation_pool')) { this.attestations = new Map(); this.metrics = new PoolInstrumentation(telemetry, PoolName.ATTESTATION_POOL); } diff --git a/yarn-project/p2p/src/mem_pools/epoch_proof_quote_pool/memory_epoch_proof_quote_pool.test.ts b/yarn-project/p2p/src/mem_pools/epoch_proof_quote_pool/memory_epoch_proof_quote_pool.test.ts index 2358c833a755..2f5d82670585 100644 --- a/yarn-project/p2p/src/mem_pools/epoch_proof_quote_pool/memory_epoch_proof_quote_pool.test.ts +++ b/yarn-project/p2p/src/mem_pools/epoch_proof_quote_pool/memory_epoch_proof_quote_pool.test.ts @@ -1,5 +1,4 @@ import { type EpochProofQuote, mockEpochProofQuote } from '@aztec/circuit-types'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; import { type MockProxy, mock } from 'jest-mock-extended'; @@ -12,8 +11,7 @@ describe('MemoryEpochProofQuotePool', () => { let metricsMock: MockProxy>; beforeEach(() => { - const telemetry = new NoopTelemetryClient(); - pool = new MemoryEpochProofQuotePool(telemetry); + pool = new MemoryEpochProofQuotePool(); metricsMock = mock>(); (pool as any).metrics = metricsMock; diff --git a/yarn-project/p2p/src/mem_pools/epoch_proof_quote_pool/memory_epoch_proof_quote_pool.ts b/yarn-project/p2p/src/mem_pools/epoch_proof_quote_pool/memory_epoch_proof_quote_pool.ts index 568e5cbfc248..0896787892cb 100644 --- a/yarn-project/p2p/src/mem_pools/epoch_proof_quote_pool/memory_epoch_proof_quote_pool.ts +++ b/yarn-project/p2p/src/mem_pools/epoch_proof_quote_pool/memory_epoch_proof_quote_pool.ts @@ -1,5 +1,5 @@ import { type EpochProofQuote } from '@aztec/circuit-types'; -import { type TelemetryClient } from '@aztec/telemetry-client'; +import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client'; import { PoolInstrumentation, PoolName } from '../instrumentation.js'; import { type EpochProofQuotePool } from './epoch_proof_quote_pool.js'; @@ -8,7 +8,7 @@ export class MemoryEpochProofQuotePool implements EpochProofQuotePool { private quotes: Map; private metrics: PoolInstrumentation; - constructor(telemetry: TelemetryClient) { + constructor(telemetry: TelemetryClient = getTelemetryClient()) { this.quotes = new Map(); this.metrics = new PoolInstrumentation(telemetry, PoolName.EPOCH_PROOF_QUOTE_POOL); } diff --git a/yarn-project/p2p/src/mem_pools/tx_pool/aztec_kv_tx_pool.test.ts b/yarn-project/p2p/src/mem_pools/tx_pool/aztec_kv_tx_pool.test.ts index cb3abd077e3f..bc9f91329e3c 100644 --- a/yarn-project/p2p/src/mem_pools/tx_pool/aztec_kv_tx_pool.test.ts +++ b/yarn-project/p2p/src/mem_pools/tx_pool/aztec_kv_tx_pool.test.ts @@ -1,5 +1,4 @@ import { openTmpStore } from '@aztec/kv-store/lmdb'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; import { AztecKVTxPool } from './aztec_kv_tx_pool.js'; import { describeTxPool } from './tx_pool_test_suite.js'; @@ -7,7 +6,7 @@ import { describeTxPool } from './tx_pool_test_suite.js'; describe('KV TX pool', () => { let txPool: AztecKVTxPool; beforeEach(() => { - txPool = new AztecKVTxPool(openTmpStore(), new NoopTelemetryClient()); + txPool = new AztecKVTxPool(openTmpStore()); }); describeTxPool(() => txPool); diff --git a/yarn-project/p2p/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts b/yarn-project/p2p/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts index 58a924399573..da6ca6d526be 100644 --- a/yarn-project/p2p/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +++ b/yarn-project/p2p/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts @@ -2,7 +2,7 @@ import { Tx, TxHash } from '@aztec/circuit-types'; import { type TxAddedToPoolStats } from '@aztec/circuit-types/stats'; import { type Logger, createLogger } from '@aztec/foundation/log'; import { type AztecKVStore, type AztecMap, type AztecMultiMap } from '@aztec/kv-store'; -import { type TelemetryClient } from '@aztec/telemetry-client'; +import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client'; import { PoolInstrumentation, PoolName } from '../instrumentation.js'; import { getPendingTxPriority } from './priority.js'; @@ -32,7 +32,11 @@ export class AztecKVTxPool implements TxPool { * @param store - A KV store. * @param log - A logger. */ - constructor(store: AztecKVStore, telemetry: TelemetryClient, log = createLogger('p2p:tx_pool')) { + constructor( + store: AztecKVStore, + telemetry: TelemetryClient = getTelemetryClient(), + log = createLogger('p2p:tx_pool'), + ) { this.#txs = store.openMap('txs'); this.#minedTxHashToBlock = store.openMap('txHashToBlockMined'); this.#pendingTxPriorityToHash = store.openMultiMap('pendingTxFeeToHash'); diff --git a/yarn-project/p2p/src/mem_pools/tx_pool/memory_tx_pool.test.ts b/yarn-project/p2p/src/mem_pools/tx_pool/memory_tx_pool.test.ts index c4435a5613a5..fb910b4755cb 100644 --- a/yarn-project/p2p/src/mem_pools/tx_pool/memory_tx_pool.test.ts +++ b/yarn-project/p2p/src/mem_pools/tx_pool/memory_tx_pool.test.ts @@ -1,12 +1,10 @@ -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; - import { InMemoryTxPool } from './index.js'; import { describeTxPool } from './tx_pool_test_suite.js'; describe('In-Memory TX pool', () => { let inMemoryTxPool: InMemoryTxPool; beforeEach(() => { - inMemoryTxPool = new InMemoryTxPool(new NoopTelemetryClient()); + inMemoryTxPool = new InMemoryTxPool(); }); describeTxPool(() => inMemoryTxPool); diff --git a/yarn-project/p2p/src/mem_pools/tx_pool/memory_tx_pool.ts b/yarn-project/p2p/src/mem_pools/tx_pool/memory_tx_pool.ts index 485dd86b1b01..7d0d87df6759 100644 --- a/yarn-project/p2p/src/mem_pools/tx_pool/memory_tx_pool.ts +++ b/yarn-project/p2p/src/mem_pools/tx_pool/memory_tx_pool.ts @@ -1,7 +1,7 @@ import { Tx, TxHash } from '@aztec/circuit-types'; import { type TxAddedToPoolStats } from '@aztec/circuit-types/stats'; import { createLogger } from '@aztec/foundation/log'; -import { type TelemetryClient } from '@aztec/telemetry-client'; +import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client'; import { PoolInstrumentation, PoolName } from '../instrumentation.js'; import { getPendingTxPriority } from './priority.js'; @@ -24,7 +24,7 @@ export class InMemoryTxPool implements TxPool { * Class constructor for in-memory TxPool. Initiates our transaction pool as a JS Map. * @param log - A logger. */ - constructor(telemetry: TelemetryClient, private log = createLogger('p2p:tx_pool')) { + constructor(telemetry: TelemetryClient = getTelemetryClient(), private log = createLogger('p2p:tx_pool')) { this.txs = new Map(); this.minedTxs = new Map(); this.pendingTxs = new Set(); diff --git a/yarn-project/p2p/src/mocks/index.ts b/yarn-project/p2p/src/mocks/index.ts index ff5996d09082..74f7339d098b 100644 --- a/yarn-project/p2p/src/mocks/index.ts +++ b/yarn-project/p2p/src/mocks/index.ts @@ -8,8 +8,7 @@ import { import { type EpochCache } from '@aztec/epoch-cache'; import { type DataStoreConfig } from '@aztec/kv-store/config'; import { openTmpStore } from '@aztec/kv-store/lmdb'; -import { type TelemetryClient } from '@aztec/telemetry-client'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; +import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client'; import { gossipsub } from '@chainsafe/libp2p-gossipsub'; import { noise } from '@chainsafe/libp2p-noise'; @@ -247,7 +246,7 @@ export function createBootstrapNodeConfig(privateKey: string, port: number): Boo export function createBootstrapNodeFromPrivateKey( privateKey: string, port: number, - telemetry: TelemetryClient = new NoopTelemetryClient(), + telemetry: TelemetryClient = getTelemetryClient(), ): Promise { const config = createBootstrapNodeConfig(privateKey, port); return startBootstrapNode(config, telemetry); @@ -255,7 +254,7 @@ export function createBootstrapNodeFromPrivateKey( export async function createBootstrapNode( port: number, - telemetry: TelemetryClient = new NoopTelemetryClient(), + telemetry: TelemetryClient = getTelemetryClient(), ): Promise { const peerId = await createSecp256k1PeerId(); const config = createBootstrapNodeConfig(Buffer.from(peerId.privateKey!).toString('hex'), port); diff --git a/yarn-project/p2p/src/services/discv5/discV5_service.ts b/yarn-project/p2p/src/services/discv5/discV5_service.ts index b629f1807b20..3c8d135c47b5 100644 --- a/yarn-project/p2p/src/services/discv5/discV5_service.ts +++ b/yarn-project/p2p/src/services/discv5/discV5_service.ts @@ -1,6 +1,6 @@ import { createLogger } from '@aztec/foundation/log'; import { sleep } from '@aztec/foundation/sleep'; -import { OtelMetricsAdapter, type TelemetryClient } from '@aztec/telemetry-client'; +import { OtelMetricsAdapter, type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client'; import { Discv5, type Discv5EventEmitter } from '@chainsafe/discv5'; import { ENR, SignableENR } from '@chainsafe/enr'; @@ -38,7 +38,7 @@ export class DiscV5Service extends EventEmitter implements PeerDiscoveryService constructor( private peerId: PeerId, config: P2PConfig, - telemetry: TelemetryClient, + telemetry: TelemetryClient = getTelemetryClient(), private logger = createLogger('p2p:discv5_service'), ) { super(); diff --git a/yarn-project/p2p/src/services/discv5/discv5_service.test.ts b/yarn-project/p2p/src/services/discv5/discv5_service.test.ts index 552aa98e6dfa..0ab9005b8bb7 100644 --- a/yarn-project/p2p/src/services/discv5/discv5_service.test.ts +++ b/yarn-project/p2p/src/services/discv5/discv5_service.test.ts @@ -1,7 +1,7 @@ import { sleep } from '@aztec/foundation/sleep'; import { type AztecKVStore } from '@aztec/kv-store'; import { openTmpStore } from '@aztec/kv-store/lmdb'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; +import { getTelemetryClient } from '@aztec/telemetry-client'; import { jest } from '@jest/globals'; import type { PeerId } from '@libp2p/interface'; @@ -45,7 +45,7 @@ describe('Discv5Service', () => { }; beforeEach(async () => { - const telemetryClient = new NoopTelemetryClient(); + const telemetryClient = getTelemetryClient(); store = openTmpStore(true); bootNode = new BootstrapNode(store, telemetryClient); await bootNode.start(baseConfig); @@ -144,6 +144,6 @@ describe('Discv5Service', () => { keepProvenTxsInPoolFor: 0, l1ChainId: 31337, }; - return new DiscV5Service(peerId, config, new NoopTelemetryClient()); + return new DiscV5Service(peerId, config); }; }); diff --git a/yarn-project/p2p/src/services/peer_manager.test.ts b/yarn-project/p2p/src/services/peer_manager.test.ts index 2feba167ffd5..dda028e647d6 100644 --- a/yarn-project/p2p/src/services/peer_manager.test.ts +++ b/yarn-project/p2p/src/services/peer_manager.test.ts @@ -1,7 +1,7 @@ import { PeerErrorSeverity } from '@aztec/circuit-types'; import { createLogger } from '@aztec/foundation/log'; import { sleep } from '@aztec/foundation/sleep'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; +import { getTelemetryClient } from '@aztec/telemetry-client'; import { type ENR, SignableENR } from '@chainsafe/enr'; import { jest } from '@jest/globals'; @@ -57,7 +57,7 @@ describe('PeerManager', () => { mockLibP2PNode, mockPeerDiscoveryService, getP2PDefaultConfig(), - new NoopTelemetryClient(), + getTelemetryClient(), createLogger('test'), ); }); diff --git a/yarn-project/proof-verifier/src/config.ts b/yarn-project/proof-verifier/src/config.ts index a312bbddd595..a0d645b4b839 100644 --- a/yarn-project/proof-verifier/src/config.ts +++ b/yarn-project/proof-verifier/src/config.ts @@ -5,7 +5,7 @@ import { getConfigFromMappings, numberConfigHelper, } from '@aztec/foundation/config'; -import { type TelemetryClientConfig, telemetryClientConfigMappings } from '@aztec/telemetry-client/start'; +import { type TelemetryClientConfig, telemetryClientConfigMappings } from '@aztec/telemetry-client'; export type ProofVerifierConfig = { /** The URL to an L1 node */ diff --git a/yarn-project/prover-client/src/block_builder/light.test.ts b/yarn-project/prover-client/src/block_builder/light.test.ts index 99ee51bbd0b4..dcbf24c647a8 100644 --- a/yarn-project/prover-client/src/block_builder/light.test.ts +++ b/yarn-project/prover-client/src/block_builder/light.test.ts @@ -61,7 +61,7 @@ import { getVKTreeRoot, } from '@aztec/noir-protocol-circuits-types/vks'; import { protocolContractTreeRoot } from '@aztec/protocol-contracts'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; +import { getTelemetryClient } from '@aztec/telemetry-client'; import { type MerkleTreeAdminDatabase, NativeWorldStateService } from '@aztec/world-state'; import { jest } from '@jest/globals'; @@ -94,7 +94,7 @@ describe('LightBlockBuilder', () => { beforeAll(async () => { logger = createLogger('prover-client:test:block-builder'); - simulator = new TestCircuitProver(new NoopTelemetryClient()); + simulator = new TestCircuitProver(); vkTreeRoot = getVKTreeRoot(); emptyProof = makeEmptyRecursiveProof(NESTED_RECURSIVE_PROOF_LENGTH); emptyRollupProof = makeEmptyRecursiveProof(NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH); @@ -106,7 +106,7 @@ describe('LightBlockBuilder', () => { l1ToL2Messages = times(7, i => new Fr(i + 1)); fork = await db.fork(); expectsFork = await db.fork(); - builder = new LightweightBlockBuilder(fork, new NoopTelemetryClient()); + builder = new LightweightBlockBuilder(fork, getTelemetryClient()); }); afterEach(async () => { diff --git a/yarn-project/prover-client/src/block_builder/light.ts b/yarn-project/prover-client/src/block_builder/light.ts index 3446b603d03c..5099a6dbec6f 100644 --- a/yarn-project/prover-client/src/block_builder/light.ts +++ b/yarn-project/prover-client/src/block_builder/light.ts @@ -11,8 +11,7 @@ import { Fr, type GlobalVariables, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@ import { SpongeBlob } from '@aztec/circuits.js/blobs'; import { padArrayEnd } from '@aztec/foundation/collection'; import { createLogger } from '@aztec/foundation/log'; -import { type TelemetryClient } from '@aztec/telemetry-client'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; +import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client'; import { buildBaseRollupHints, @@ -32,7 +31,7 @@ export class LightweightBlockBuilder implements BlockBuilder { private readonly logger = createLogger('prover-client:block_builder'); - constructor(private db: MerkleTreeWriteOperations, private telemetry: TelemetryClient) {} + constructor(private db: MerkleTreeWriteOperations, private telemetry: TelemetryClient = getTelemetryClient()) {} async startNewBlock(globalVariables: GlobalVariables, l1ToL2Messages: Fr[]): Promise { this.logger.debug('Starting new block', { globalVariables: globalVariables.toInspect(), l1ToL2Messages }); @@ -83,10 +82,10 @@ export class LightweightBlockBuilder implements BlockBuilder { } export class LightweightBlockBuilderFactory { - constructor(private telemetry?: TelemetryClient) {} + constructor(private telemetry: TelemetryClient = getTelemetryClient()) {} create(db: MerkleTreeWriteOperations): BlockBuilder { - return new LightweightBlockBuilder(db, this.telemetry ?? new NoopTelemetryClient()); + return new LightweightBlockBuilder(db, this.telemetry); } } @@ -100,7 +99,7 @@ export async function buildBlock( globalVariables: GlobalVariables, l1ToL2Messages: Fr[], db: MerkleTreeWriteOperations, - telemetry: TelemetryClient = new NoopTelemetryClient(), + telemetry: TelemetryClient = getTelemetryClient(), ) { const builder = new LightweightBlockBuilder(db, telemetry); await builder.startNewBlock(globalVariables, l1ToL2Messages); diff --git a/yarn-project/prover-client/src/mocks/test_context.ts b/yarn-project/prover-client/src/mocks/test_context.ts index 41847b26e662..e44a09b97419 100644 --- a/yarn-project/prover-client/src/mocks/test_context.ts +++ b/yarn-project/prover-client/src/mocks/test_context.ts @@ -27,7 +27,7 @@ import { WASMSimulatorWithBlobs, type WorldStateDB, } from '@aztec/simulator'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; +import { getTelemetryClient } from '@aztec/telemetry-client'; import { type MerkleTreeAdminDatabase } from '@aztec/world-state'; import { NativeWorldStateService } from '@aztec/world-state/native'; @@ -69,14 +69,13 @@ export class TestContext { logger: Logger, proverCount = 4, createProver: (bbConfig: BBProverConfig) => Promise = _ => - Promise.resolve(new TestCircuitProver(new NoopTelemetryClient(), new WASMSimulatorWithBlobs())), + Promise.resolve(new TestCircuitProver(new WASMSimulatorWithBlobs())), blockNumber = 1, ) { const directoriesToCleanup: string[] = []; const globalVariables = makeGlobals(blockNumber); const worldStateDB = mock(); - const telemetry = new NoopTelemetryClient(); // Separated dbs for public processor and prover - see public_processor for context const ws = await NativeWorldStateService.tmp(); @@ -84,7 +83,7 @@ export class TestContext { worldStateDB.getMerkleInterface.mockReturnValue(publicDb); - const publicTxSimulator = new PublicTxSimulator(publicDb, worldStateDB, telemetry, globalVariables, true); + const publicTxSimulator = new PublicTxSimulator(publicDb, worldStateDB, globalVariables, true); const processor = new PublicProcessor( publicDb, globalVariables, @@ -92,7 +91,6 @@ export class TestContext { worldStateDB, publicTxSimulator, new TestDateProvider(), - telemetry, ); let localProver: ServerCircuitProver; @@ -102,7 +100,7 @@ export class TestContext { acvmBinaryPath: config?.expectedAcvmPath, }); if (!config) { - localProver = new TestCircuitProver(new NoopTelemetryClient(), simulationProvider); + localProver = new TestCircuitProver(simulationProvider); } else { const bbConfig: BBProverConfig = { acvmBinaryPath: config.expectedAcvmPath, @@ -118,9 +116,9 @@ export class TestContext { directoriesToCleanup.push(config.directoryToCleanup); } - const queue = new MemoryProvingQueue(telemetry); - const orchestrator = new TestProvingOrchestrator(ws, queue, telemetry, Fr.ZERO); - const agent = new ProverAgent(localProver, proverCount, undefined, telemetry); + const queue = new MemoryProvingQueue(getTelemetryClient()); + const orchestrator = new TestProvingOrchestrator(ws, queue, Fr.ZERO); + const agent = new ProverAgent(localProver, proverCount, undefined); queue.start(); agent.start(queue); diff --git a/yarn-project/prover-client/src/orchestrator/block-building-helpers.ts b/yarn-project/prover-client/src/orchestrator/block-building-helpers.ts index ed16c5bb7be6..845f2f78f7a0 100644 --- a/yarn-project/prover-client/src/orchestrator/block-building-helpers.ts +++ b/yarn-project/prover-client/src/orchestrator/block-building-helpers.ts @@ -53,6 +53,7 @@ import { computeUnbalancedMerkleRoot } from '@aztec/foundation/trees'; import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vks'; import { protocolContractTreeRoot } from '@aztec/protocol-contracts'; import { computeFeePayerBalanceLeafSlot } from '@aztec/simulator'; +import { Attributes, Span, runInSpan } from '@aztec/telemetry-client'; import { type MerkleTreeReadOperations } from '@aztec/world-state'; import { inspect } from 'util'; @@ -67,185 +68,191 @@ type BaseTreeNames = 'NoteHashTree' | 'ContractTree' | 'NullifierTree' | 'Public export type TreeNames = BaseTreeNames | 'L1ToL2MessageTree' | 'Archive'; // Builds the hints for base rollup. Updating the contract, nullifier, and data trees in the process. -export async function buildBaseRollupHints( - tx: ProcessedTx, - globalVariables: GlobalVariables, - db: MerkleTreeWriteOperations, - startSpongeBlob: SpongeBlob, -) { - // Get trees info before any changes hit - const constants = await getConstantRollupData(globalVariables, db); - const start = new PartialStateReference( - await getTreeSnapshot(MerkleTreeId.NOTE_HASH_TREE, db), - await getTreeSnapshot(MerkleTreeId.NULLIFIER_TREE, db), - await getTreeSnapshot(MerkleTreeId.PUBLIC_DATA_TREE, db), - ); - // Get the subtree sibling paths for the circuit - const noteHashSubtreeSiblingPathArray = await getSubtreeSiblingPath( - MerkleTreeId.NOTE_HASH_TREE, - NOTE_HASH_SUBTREE_HEIGHT, - db, - ); - - const noteHashSubtreeSiblingPath = makeTuple(NOTE_HASH_SUBTREE_SIBLING_PATH_LENGTH, i => - i < noteHashSubtreeSiblingPathArray.length ? noteHashSubtreeSiblingPathArray[i] : Fr.ZERO, - ); - - // Update the note hash trees with the new items being inserted to get the new roots - // that will be used by the next iteration of the base rollup circuit, skipping the empty ones - const noteHashes = padArrayEnd(tx.txEffect.noteHashes, Fr.ZERO, MAX_NOTE_HASHES_PER_TX); - await db.appendLeaves(MerkleTreeId.NOTE_HASH_TREE, noteHashes); - - // The read witnesses for a given TX should be generated before the writes of the same TX are applied. - // All reads that refer to writes in the same tx are transient and can be simplified out. - const txPublicDataUpdateRequestInfo = await processPublicDataUpdateRequests(tx, db); - - // Update the nullifier tree, capturing the low nullifier info for each individual operation - const { - lowLeavesWitnessData: nullifierWitnessLeaves, - newSubtreeSiblingPath: nullifiersSubtreeSiblingPath, - sortedNewLeaves: sortednullifiers, - sortedNewLeavesIndexes, - } = await db.batchInsert( - MerkleTreeId.NULLIFIER_TREE, - padArrayEnd(tx.txEffect.nullifiers, Fr.ZERO, MAX_NULLIFIERS_PER_TX).map(n => n.toBuffer()), - NULLIFIER_SUBTREE_HEIGHT, - ); - - if (nullifierWitnessLeaves === undefined) { - throw new Error(`Could not craft nullifier batch insertion proofs`); - } - - // Extract witness objects from returned data - const nullifierPredecessorMembershipWitnessesWithoutPadding: MembershipWitness[] = - nullifierWitnessLeaves.map(l => - MembershipWitness.fromBufferArray(l.index, assertLength(l.siblingPath.toBufferArray(), NULLIFIER_TREE_HEIGHT)), +export const buildBaseRollupHints = runInSpan( + 'BlockBuilderHelpers', + 'buildBaseRollupHints', + async ( + span: Span, + tx: ProcessedTx, + globalVariables: GlobalVariables, + db: MerkleTreeWriteOperations, + startSpongeBlob: SpongeBlob, + ) => { + span.setAttribute(Attributes.TX_HASH, tx.hash.toString()); + // Get trees info before any changes hit + const constants = await getConstantRollupData(globalVariables, db); + const start = new PartialStateReference( + await getTreeSnapshot(MerkleTreeId.NOTE_HASH_TREE, db), + await getTreeSnapshot(MerkleTreeId.NULLIFIER_TREE, db), + await getTreeSnapshot(MerkleTreeId.PUBLIC_DATA_TREE, db), + ); + // Get the subtree sibling paths for the circuit + const noteHashSubtreeSiblingPathArray = await getSubtreeSiblingPath( + MerkleTreeId.NOTE_HASH_TREE, + NOTE_HASH_SUBTREE_HEIGHT, + db, ); - const nullifierSubtreeSiblingPathArray = nullifiersSubtreeSiblingPath.toFields(); - - const nullifierSubtreeSiblingPath = makeTuple(NULLIFIER_SUBTREE_SIBLING_PATH_LENGTH, i => - i < nullifierSubtreeSiblingPathArray.length ? nullifierSubtreeSiblingPathArray[i] : Fr.ZERO, - ); - - // Append new data to startSpongeBlob - const inputSpongeBlob = startSpongeBlob.clone(); - startSpongeBlob.absorb(tx.txEffect.toBlobFields()); - - if (tx.avmProvingRequest) { - // Build public base rollup hints - const stateDiffHints = PublicBaseStateDiffHints.from({ - nullifierPredecessorPreimages: makeTuple(MAX_NULLIFIERS_PER_TX, i => - i < nullifierWitnessLeaves.length - ? (nullifierWitnessLeaves[i].leafPreimage as NullifierLeafPreimage) - : NullifierLeafPreimage.empty(), - ), - nullifierPredecessorMembershipWitnesses: makeTuple(MAX_NULLIFIERS_PER_TX, i => - i < nullifierPredecessorMembershipWitnessesWithoutPadding.length - ? nullifierPredecessorMembershipWitnessesWithoutPadding[i] - : makeEmptyMembershipWitness(NULLIFIER_TREE_HEIGHT), - ), - sortedNullifiers: makeTuple(MAX_NULLIFIERS_PER_TX, i => Fr.fromBuffer(sortednullifiers[i])), - sortedNullifierIndexes: makeTuple(MAX_NULLIFIERS_PER_TX, i => sortedNewLeavesIndexes[i]), - noteHashSubtreeSiblingPath, - nullifierSubtreeSiblingPath, - lowPublicDataWritesPreimages: padArrayEnd( - txPublicDataUpdateRequestInfo.lowPublicDataWritesPreimages, - PublicDataTreeLeafPreimage.empty(), - MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, - ), - lowPublicDataWritesMembershipWitnesses: padArrayEnd( - txPublicDataUpdateRequestInfo.lowPublicDataWritesMembershipWitnesses, - MembershipWitness.empty(PUBLIC_DATA_TREE_HEIGHT), - MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, - ), - publicDataTreeSiblingPaths: padArrayEnd( - txPublicDataUpdateRequestInfo.publicDataWritesSiblingPaths, - makeTuple(PUBLIC_DATA_TREE_HEIGHT, () => Fr.ZERO), - MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, - ), - }); + const noteHashSubtreeSiblingPath = makeTuple(NOTE_HASH_SUBTREE_SIBLING_PATH_LENGTH, i => + i < noteHashSubtreeSiblingPathArray.length ? noteHashSubtreeSiblingPathArray[i] : Fr.ZERO, + ); - const blockHash = tx.constants.historicalHeader.hash(); - const archiveRootMembershipWitness = await getMembershipWitnessFor( - blockHash, - MerkleTreeId.ARCHIVE, - ARCHIVE_HEIGHT, - db, + // Update the note hash trees with the new items being inserted to get the new roots + // that will be used by the next iteration of the base rollup circuit, skipping the empty ones + const noteHashes = padArrayEnd(tx.txEffect.noteHashes, Fr.ZERO, MAX_NOTE_HASHES_PER_TX); + await db.appendLeaves(MerkleTreeId.NOTE_HASH_TREE, noteHashes); + + // The read witnesses for a given TX should be generated before the writes of the same TX are applied. + // All reads that refer to writes in the same tx are transient and can be simplified out. + const txPublicDataUpdateRequestInfo = await processPublicDataUpdateRequests(tx, db); + + // Update the nullifier tree, capturing the low nullifier info for each individual operation + const { + lowLeavesWitnessData: nullifierWitnessLeaves, + newSubtreeSiblingPath: nullifiersSubtreeSiblingPath, + sortedNewLeaves: sortednullifiers, + sortedNewLeavesIndexes, + } = await db.batchInsert( + MerkleTreeId.NULLIFIER_TREE, + padArrayEnd(tx.txEffect.nullifiers, Fr.ZERO, MAX_NULLIFIERS_PER_TX).map(n => n.toBuffer()), + NULLIFIER_SUBTREE_HEIGHT, ); - return PublicBaseRollupHints.from({ - start, - startSpongeBlob: inputSpongeBlob, - stateDiffHints, - archiveRootMembershipWitness, - constants, - }); - } else { - if ( - txPublicDataUpdateRequestInfo.lowPublicDataWritesMembershipWitnesses.length > 1 || - txPublicDataUpdateRequestInfo.lowPublicDataWritesPreimages.length > 1 || - txPublicDataUpdateRequestInfo.publicDataWritesSiblingPaths.length > 1 - ) { - throw new Error(`More than one public data write in a private only tx`); + if (nullifierWitnessLeaves === undefined) { + throw new Error(`Could not craft nullifier batch insertion proofs`); } - // Create data hint for reading fee payer initial balance in Fee Juice - // If no fee payer is set, read hint should be empty - const leafSlot = computeFeePayerBalanceLeafSlot(tx.data.feePayer); - const feePayerFeeJuiceBalanceReadHint = tx.data.feePayer.isZero() - ? PublicDataHint.empty() - : await getPublicDataHint(db, leafSlot.toBigInt()); - - const feeWriteLowLeafPreimage = - txPublicDataUpdateRequestInfo.lowPublicDataWritesPreimages[0] || PublicDataTreeLeafPreimage.empty(); - const feeWriteLowLeafMembershipWitness = - txPublicDataUpdateRequestInfo.lowPublicDataWritesMembershipWitnesses[0] || - MembershipWitness.empty(PUBLIC_DATA_TREE_HEIGHT); - const feeWriteSiblingPath = - txPublicDataUpdateRequestInfo.publicDataWritesSiblingPaths[0] || - makeTuple(PUBLIC_DATA_TREE_HEIGHT, () => Fr.ZERO); - - const stateDiffHints = PrivateBaseStateDiffHints.from({ - nullifierPredecessorPreimages: makeTuple(MAX_NULLIFIERS_PER_TX, i => - i < nullifierWitnessLeaves.length - ? (nullifierWitnessLeaves[i].leafPreimage as NullifierLeafPreimage) - : NullifierLeafPreimage.empty(), - ), - nullifierPredecessorMembershipWitnesses: makeTuple(MAX_NULLIFIERS_PER_TX, i => - i < nullifierPredecessorMembershipWitnessesWithoutPadding.length - ? nullifierPredecessorMembershipWitnessesWithoutPadding[i] - : makeEmptyMembershipWitness(NULLIFIER_TREE_HEIGHT), - ), - sortedNullifiers: makeTuple(MAX_NULLIFIERS_PER_TX, i => Fr.fromBuffer(sortednullifiers[i])), - sortedNullifierIndexes: makeTuple(MAX_NULLIFIERS_PER_TX, i => sortedNewLeavesIndexes[i]), - noteHashSubtreeSiblingPath, - nullifierSubtreeSiblingPath, - feeWriteLowLeafPreimage, - feeWriteLowLeafMembershipWitness, - feeWriteSiblingPath, - }); + // Extract witness objects from returned data + const nullifierPredecessorMembershipWitnessesWithoutPadding: MembershipWitness[] = + nullifierWitnessLeaves.map(l => + MembershipWitness.fromBufferArray(l.index, assertLength(l.siblingPath.toBufferArray(), NULLIFIER_TREE_HEIGHT)), + ); - const blockHash = tx.constants.historicalHeader.hash(); - const archiveRootMembershipWitness = await getMembershipWitnessFor( - blockHash, - MerkleTreeId.ARCHIVE, - ARCHIVE_HEIGHT, - db, + const nullifierSubtreeSiblingPathArray = nullifiersSubtreeSiblingPath.toFields(); + + const nullifierSubtreeSiblingPath = makeTuple(NULLIFIER_SUBTREE_SIBLING_PATH_LENGTH, i => + i < nullifierSubtreeSiblingPathArray.length ? nullifierSubtreeSiblingPathArray[i] : Fr.ZERO, ); - return PrivateBaseRollupHints.from({ - start, - startSpongeBlob: inputSpongeBlob, - stateDiffHints, - feePayerFeeJuiceBalanceReadHint: feePayerFeeJuiceBalanceReadHint, - archiveRootMembershipWitness, - constants, - }); - } -} + // Append new data to startSpongeBlob + const inputSpongeBlob = startSpongeBlob.clone(); + startSpongeBlob.absorb(tx.txEffect.toBlobFields()); + + if (tx.avmProvingRequest) { + // Build public base rollup hints + const stateDiffHints = PublicBaseStateDiffHints.from({ + nullifierPredecessorPreimages: makeTuple(MAX_NULLIFIERS_PER_TX, i => + i < nullifierWitnessLeaves.length + ? (nullifierWitnessLeaves[i].leafPreimage as NullifierLeafPreimage) + : NullifierLeafPreimage.empty(), + ), + nullifierPredecessorMembershipWitnesses: makeTuple(MAX_NULLIFIERS_PER_TX, i => + i < nullifierPredecessorMembershipWitnessesWithoutPadding.length + ? nullifierPredecessorMembershipWitnessesWithoutPadding[i] + : makeEmptyMembershipWitness(NULLIFIER_TREE_HEIGHT), + ), + sortedNullifiers: makeTuple(MAX_NULLIFIERS_PER_TX, i => Fr.fromBuffer(sortednullifiers[i])), + sortedNullifierIndexes: makeTuple(MAX_NULLIFIERS_PER_TX, i => sortedNewLeavesIndexes[i]), + noteHashSubtreeSiblingPath, + nullifierSubtreeSiblingPath, + lowPublicDataWritesPreimages: padArrayEnd( + txPublicDataUpdateRequestInfo.lowPublicDataWritesPreimages, + PublicDataTreeLeafPreimage.empty(), + MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, + ), + lowPublicDataWritesMembershipWitnesses: padArrayEnd( + txPublicDataUpdateRequestInfo.lowPublicDataWritesMembershipWitnesses, + MembershipWitness.empty(PUBLIC_DATA_TREE_HEIGHT), + MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, + ), + publicDataTreeSiblingPaths: padArrayEnd( + txPublicDataUpdateRequestInfo.publicDataWritesSiblingPaths, + makeTuple(PUBLIC_DATA_TREE_HEIGHT, () => Fr.ZERO), + MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, + ), + }); + + const blockHash = tx.constants.historicalHeader.hash(); + const archiveRootMembershipWitness = await getMembershipWitnessFor( + blockHash, + MerkleTreeId.ARCHIVE, + ARCHIVE_HEIGHT, + db, + ); + + return PublicBaseRollupHints.from({ + start, + startSpongeBlob: inputSpongeBlob, + stateDiffHints, + archiveRootMembershipWitness, + constants, + }); + } else { + if ( + txPublicDataUpdateRequestInfo.lowPublicDataWritesMembershipWitnesses.length > 1 || + txPublicDataUpdateRequestInfo.lowPublicDataWritesPreimages.length > 1 || + txPublicDataUpdateRequestInfo.publicDataWritesSiblingPaths.length > 1 + ) { + throw new Error(`More than one public data write in a private only tx`); + } + + // Create data hint for reading fee payer initial balance in Fee Juice + // If no fee payer is set, read hint should be empty + const leafSlot = computeFeePayerBalanceLeafSlot(tx.data.feePayer); + const feePayerFeeJuiceBalanceReadHint = tx.data.feePayer.isZero() + ? PublicDataHint.empty() + : await getPublicDataHint(db, leafSlot.toBigInt()); + + const feeWriteLowLeafPreimage = + txPublicDataUpdateRequestInfo.lowPublicDataWritesPreimages[0] || PublicDataTreeLeafPreimage.empty(); + const feeWriteLowLeafMembershipWitness = + txPublicDataUpdateRequestInfo.lowPublicDataWritesMembershipWitnesses[0] || + MembershipWitness.empty(PUBLIC_DATA_TREE_HEIGHT); + const feeWriteSiblingPath = + txPublicDataUpdateRequestInfo.publicDataWritesSiblingPaths[0] || + makeTuple(PUBLIC_DATA_TREE_HEIGHT, () => Fr.ZERO); + + const stateDiffHints = PrivateBaseStateDiffHints.from({ + nullifierPredecessorPreimages: makeTuple(MAX_NULLIFIERS_PER_TX, i => + i < nullifierWitnessLeaves.length + ? (nullifierWitnessLeaves[i].leafPreimage as NullifierLeafPreimage) + : NullifierLeafPreimage.empty(), + ), + nullifierPredecessorMembershipWitnesses: makeTuple(MAX_NULLIFIERS_PER_TX, i => + i < nullifierPredecessorMembershipWitnessesWithoutPadding.length + ? nullifierPredecessorMembershipWitnessesWithoutPadding[i] + : makeEmptyMembershipWitness(NULLIFIER_TREE_HEIGHT), + ), + sortedNullifiers: makeTuple(MAX_NULLIFIERS_PER_TX, i => Fr.fromBuffer(sortednullifiers[i])), + sortedNullifierIndexes: makeTuple(MAX_NULLIFIERS_PER_TX, i => sortedNewLeavesIndexes[i]), + noteHashSubtreeSiblingPath, + nullifierSubtreeSiblingPath, + feeWriteLowLeafPreimage, + feeWriteLowLeafMembershipWitness, + feeWriteSiblingPath, + }); + + const blockHash = tx.constants.historicalHeader.hash(); + const archiveRootMembershipWitness = await getMembershipWitnessFor( + blockHash, + MerkleTreeId.ARCHIVE, + ARCHIVE_HEIGHT, + db, + ); + + return PrivateBaseRollupHints.from({ + start, + startSpongeBlob: inputSpongeBlob, + stateDiffHints, + feePayerFeeJuiceBalanceReadHint: feePayerFeeJuiceBalanceReadHint, + archiveRootMembershipWitness, + constants, + }); + } + }, +); -async function getPublicDataHint(db: MerkleTreeWriteOperations, leafSlot: bigint) { +export async function getPublicDataHint(db: MerkleTreeWriteOperations, leafSlot: bigint) { const { index } = (await db.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot)) ?? {}; if (index === undefined) { throw new Error(`Cannot find the previous value index for public data ${leafSlot}.`); @@ -265,111 +272,126 @@ async function getPublicDataHint(db: MerkleTreeWriteOperations, leafSlot: bigint return new PublicDataHint(new Fr(leafSlot), value, membershipWitness, leafPreimage); } -export function buildBlobHints(txEffects: TxEffect[]) { - const blobFields = txEffects.flatMap(tx => tx.toBlobFields()); - const blobs = Blob.getBlobs(blobFields); - const blobCommitments = blobs.map(b => b.commitmentToFields()); - const blobsHash = new Fr(getBlobsHashFromBlobs(blobs)); - return { blobFields, blobCommitments, blobs, blobsHash }; -} - -export function buildHeaderFromCircuitOutputs( - previousRollupData: BaseOrMergeRollupPublicInputs[], - parityPublicInputs: ParityPublicInputs, - rootRollupOutputs: BlockRootOrBlockMergePublicInputs, - endState: StateReference, - logger?: Logger, -) { - if (previousRollupData.length > 2) { - throw new Error(`There can't be more than 2 previous rollups. Received ${previousRollupData.length}.`); - } - - const blobsHash = rootRollupOutputs.blobPublicInputs[0].getBlobsHash(); - const numTxs = previousRollupData.reduce((sum, d) => sum + d.numTxs, 0); - const outHash = - previousRollupData.length === 0 - ? Fr.ZERO.toBuffer() - : previousRollupData.length === 1 - ? previousRollupData[0].outHash.toBuffer() - : sha256Trunc( - Buffer.concat([previousRollupData[0].outHash.toBuffer(), previousRollupData[1].outHash.toBuffer()]), - ); - const contentCommitment = new ContentCommitment( - new Fr(numTxs), - blobsHash, - parityPublicInputs.shaRoot.toBuffer(), - outHash, - ); +export const buildBlobHints = runInSpan( + 'BlockBuilderHelpers', + 'buildBlobHints', + (_span: Span, txEffects: TxEffect[]) => { + const blobFields = txEffects.flatMap(tx => tx.toBlobFields()); + const blobs = Blob.getBlobs(blobFields); + const blobCommitments = blobs.map(b => b.commitmentToFields()); + const blobsHash = new Fr(getBlobsHashFromBlobs(blobs)); + return { blobFields, blobCommitments, blobs, blobsHash }; + }, +); + +export const buildHeaderFromCircuitOutputs = runInSpan( + 'BlockBuilderHelpers', + 'buildHeaderFromCircuitOutputs', + ( + _span, + previousRollupData: BaseOrMergeRollupPublicInputs[], + parityPublicInputs: ParityPublicInputs, + rootRollupOutputs: BlockRootOrBlockMergePublicInputs, + endState: StateReference, + logger?: Logger, + ) => { + if (previousRollupData.length > 2) { + throw new Error(`There can't be more than 2 previous rollups. Received ${previousRollupData.length}.`); + } - const accumulatedFees = previousRollupData.reduce((sum, d) => sum.add(d.accumulatedFees), Fr.ZERO); - const accumulatedManaUsed = previousRollupData.reduce((sum, d) => sum.add(d.accumulatedManaUsed), Fr.ZERO); - const header = new BlockHeader( - rootRollupOutputs.previousArchive, - contentCommitment, - endState, - rootRollupOutputs.endGlobalVariables, - accumulatedFees, - accumulatedManaUsed, - ); - if (!header.hash().equals(rootRollupOutputs.endBlockHash)) { - logger?.error( - `Block header mismatch when building header from circuit outputs.` + - `\n\nHeader: ${inspect(header)}` + - `\n\nCircuit: ${toFriendlyJSON(rootRollupOutputs)}`, + const blobsHash = rootRollupOutputs.blobPublicInputs[0].getBlobsHash(); + const numTxs = previousRollupData.reduce((sum, d) => sum + d.numTxs, 0); + const outHash = + previousRollupData.length === 0 + ? Fr.ZERO.toBuffer() + : previousRollupData.length === 1 + ? previousRollupData[0].outHash.toBuffer() + : sha256Trunc( + Buffer.concat([previousRollupData[0].outHash.toBuffer(), previousRollupData[1].outHash.toBuffer()]), + ); + const contentCommitment = new ContentCommitment( + new Fr(numTxs), + blobsHash, + parityPublicInputs.shaRoot.toBuffer(), + outHash, ); - throw new Error(`Block header mismatch when building from circuit outputs`); - } - return header; -} -export async function buildHeaderAndBodyFromTxs( - txs: ProcessedTx[], - globalVariables: GlobalVariables, - l1ToL2Messages: Fr[], - db: MerkleTreeReadOperations, -) { - const stateReference = new StateReference( - await getTreeSnapshot(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, db), - new PartialStateReference( - await getTreeSnapshot(MerkleTreeId.NOTE_HASH_TREE, db), - await getTreeSnapshot(MerkleTreeId.NULLIFIER_TREE, db), - await getTreeSnapshot(MerkleTreeId.PUBLIC_DATA_TREE, db), - ), - ); + const accumulatedFees = previousRollupData.reduce((sum, d) => sum.add(d.accumulatedFees), Fr.ZERO); + const accumulatedManaUsed = previousRollupData.reduce((sum, d) => sum.add(d.accumulatedManaUsed), Fr.ZERO); + const header = new BlockHeader( + rootRollupOutputs.previousArchive, + contentCommitment, + endState, + rootRollupOutputs.endGlobalVariables, + accumulatedFees, + accumulatedManaUsed, + ); + if (!header.hash().equals(rootRollupOutputs.endBlockHash)) { + logger?.error( + `Block header mismatch when building header from circuit outputs.` + + `\n\nHeader: ${inspect(header)}` + + `\n\nCircuit: ${toFriendlyJSON(rootRollupOutputs)}`, + ); + throw new Error(`Block header mismatch when building from circuit outputs`); + } + return header; + }, +); + +export const buildHeaderAndBodyFromTxs = runInSpan( + 'BlockBuilderHelpers', + 'buildHeaderAndBodyFromTxs', + async ( + span, + txs: ProcessedTx[], + globalVariables: GlobalVariables, + l1ToL2Messages: Fr[], + db: MerkleTreeReadOperations, + ) => { + span.setAttribute(Attributes.BLOCK_NUMBER, globalVariables.blockNumber.toNumber()); + const stateReference = new StateReference( + await getTreeSnapshot(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, db), + new PartialStateReference( + await getTreeSnapshot(MerkleTreeId.NOTE_HASH_TREE, db), + await getTreeSnapshot(MerkleTreeId.NULLIFIER_TREE, db), + await getTreeSnapshot(MerkleTreeId.PUBLIC_DATA_TREE, db), + ), + ); - const previousArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, db); - - const txEffects = txs.map(tx => tx.txEffect); - const body = new Body(txEffects); - - const numTxs = body.txEffects.length; - const outHash = - numTxs === 0 - ? Fr.ZERO.toBuffer() - : numTxs === 1 - ? body.txEffects[0].txOutHash() - : computeUnbalancedMerkleRoot( - body.txEffects.map(tx => tx.txOutHash()), - TxEffect.empty().txOutHash(), - ); - - l1ToL2Messages = padArrayEnd(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP); - const hasher = (left: Buffer, right: Buffer) => sha256Trunc(Buffer.concat([left, right])); - const parityHeight = Math.ceil(Math.log2(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP)); - const parityShaRoot = new MerkleTreeCalculator(parityHeight, Fr.ZERO.toBuffer(), hasher).computeTreeRoot( - l1ToL2Messages.map(msg => msg.toBuffer()), - ); - const blobsHash = getBlobsHashFromBlobs(Blob.getBlobs(body.toBlobFields())); + const previousArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, db); + + const txEffects = txs.map(tx => tx.txEffect); + const body = new Body(txEffects); + + const numTxs = body.txEffects.length; + const outHash = + numTxs === 0 + ? Fr.ZERO.toBuffer() + : numTxs === 1 + ? body.txEffects[0].txOutHash() + : computeUnbalancedMerkleRoot( + body.txEffects.map(tx => tx.txOutHash()), + TxEffect.empty().txOutHash(), + ); + + l1ToL2Messages = padArrayEnd(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP); + const hasher = (left: Buffer, right: Buffer) => sha256Trunc(Buffer.concat([left, right])); + const parityHeight = Math.ceil(Math.log2(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP)); + const parityShaRoot = new MerkleTreeCalculator(parityHeight, Fr.ZERO.toBuffer(), hasher).computeTreeRoot( + l1ToL2Messages.map(msg => msg.toBuffer()), + ); + const blobsHash = getBlobsHashFromBlobs(Blob.getBlobs(body.toBlobFields())); - const contentCommitment = new ContentCommitment(new Fr(numTxs), blobsHash, parityShaRoot, outHash); + const contentCommitment = new ContentCommitment(new Fr(numTxs), blobsHash, parityShaRoot, outHash); - const fees = body.txEffects.reduce((acc, tx) => acc.add(tx.transactionFee), Fr.ZERO); - const manaUsed = txs.reduce((acc, tx) => acc.add(new Fr(tx.gasUsed.totalGas.l2Gas)), Fr.ZERO); + const fees = body.txEffects.reduce((acc, tx) => acc.add(tx.transactionFee), Fr.ZERO); + const manaUsed = txs.reduce((acc, tx) => acc.add(new Fr(tx.gasUsed.totalGas.l2Gas)), Fr.ZERO); - const header = new BlockHeader(previousArchive, contentCommitment, stateReference, globalVariables, fees, manaUsed); + const header = new BlockHeader(previousArchive, contentCommitment, stateReference, globalVariables, fees, manaUsed); - return { header, body }; -} + return { header, body }; + }, +); export function getBlobsHashFromBlobs(inputs: Blob[]): Buffer { const blobHashes = serializeToBuffer(inputs.map(b => b.getEthVersionedBlobHash())); @@ -388,22 +410,26 @@ export async function validateBlockRootOutput( ]); } -export async function validateState(state: StateReference, db: MerkleTreeReadOperations) { - const promises = [MerkleTreeId.NOTE_HASH_TREE, MerkleTreeId.NULLIFIER_TREE, MerkleTreeId.PUBLIC_DATA_TREE].map( - async (id: MerkleTreeId) => { - return { key: id, value: await getTreeSnapshot(id, db) }; - }, - ); - const snapshots: Map = new Map( - (await Promise.all(promises)).map(obj => [obj.key, obj.value]), - ); - validatePartialState(state.partial, snapshots); - validateSimulatedTree( - await getTreeSnapshot(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, db), - state.l1ToL2MessageTree, - 'L1ToL2MessageTree', - ); -} +export const validateState = runInSpan( + 'BlockBuilderHelpers', + 'validateState', + async (_span, state: StateReference, db: MerkleTreeReadOperations) => { + const promises = [MerkleTreeId.NOTE_HASH_TREE, MerkleTreeId.NULLIFIER_TREE, MerkleTreeId.PUBLIC_DATA_TREE].map( + async (id: MerkleTreeId) => { + return { key: id, value: await getTreeSnapshot(id, db) }; + }, + ); + const snapshots: Map = new Map( + (await Promise.all(promises)).map(obj => [obj.key, obj.value]), + ); + validatePartialState(state.partial, snapshots); + validateSimulatedTree( + await getTreeSnapshot(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, db), + state.l1ToL2MessageTree, + 'L1ToL2MessageTree', + ); + }, +); export async function getRootTreeSiblingPath(treeId: TID, db: MerkleTreeReadOperations) { const { size } = await db.getTreeInfo(treeId); @@ -411,17 +437,18 @@ export async function getRootTreeSiblingPath(treeId: T return padArrayEnd(path.toFields(), Fr.ZERO, getTreeHeight(treeId)); } -export async function getConstantRollupData( - globalVariables: GlobalVariables, - db: MerkleTreeReadOperations, -): Promise { - return ConstantRollupData.from({ - vkTreeRoot: getVKTreeRoot(), - protocolContractTreeRoot, - lastArchive: await getTreeSnapshot(MerkleTreeId.ARCHIVE, db), - globalVariables, - }); -} +export const getConstantRollupData = runInSpan( + 'BlockBuilderHelpers', + 'getConstantRollupData', + async (_span, globalVariables: GlobalVariables, db: MerkleTreeReadOperations): Promise => { + return ConstantRollupData.from({ + vkTreeRoot: getVKTreeRoot(), + protocolContractTreeRoot, + lastArchive: await getTreeSnapshot(MerkleTreeId.ARCHIVE, db), + globalVariables, + }); + }, +); export async function getTreeSnapshot(id: MerkleTreeId, db: MerkleTreeReadOperations): Promise { const treeInfo = await db.getTreeInfo(id); @@ -436,42 +463,47 @@ export function makeEmptyMembershipWitness(height: N) { ); } -async function processPublicDataUpdateRequests(tx: ProcessedTx, db: MerkleTreeWriteOperations) { - const allPublicDataWrites = tx.txEffect.publicDataWrites.map( - ({ leafSlot, value }) => new PublicDataTreeLeaf(leafSlot, value), - ); +const processPublicDataUpdateRequests = runInSpan( + 'BlockBuilderHelpers', + 'processPublicDataUpdateRequests', + async (span, tx: ProcessedTx, db: MerkleTreeWriteOperations) => { + span.setAttribute(Attributes.TX_HASH, tx.hash.toString()); + const allPublicDataWrites = tx.txEffect.publicDataWrites.map( + ({ leafSlot, value }) => new PublicDataTreeLeaf(leafSlot, value), + ); - const { lowLeavesWitnessData, insertionWitnessData } = await db.sequentialInsert( - MerkleTreeId.PUBLIC_DATA_TREE, - allPublicDataWrites.map(write => { - if (write.isEmpty()) { - throw new Error(`Empty public data write in tx: ${toFriendlyJSON(tx)}`); - } - return write.toBuffer(); - }), - ); + const { lowLeavesWitnessData, insertionWitnessData } = await db.sequentialInsert( + MerkleTreeId.PUBLIC_DATA_TREE, + allPublicDataWrites.map(write => { + if (write.isEmpty()) { + throw new Error(`Empty public data write in tx: ${toFriendlyJSON(tx)}`); + } + return write.toBuffer(); + }), + ); - const lowPublicDataWritesPreimages = lowLeavesWitnessData.map( - lowLeafWitness => lowLeafWitness.leafPreimage as PublicDataTreeLeafPreimage, - ); - const lowPublicDataWritesMembershipWitnesses = lowLeavesWitnessData.map(lowLeafWitness => - MembershipWitness.fromBufferArray( - lowLeafWitness.index, - assertLength(lowLeafWitness.siblingPath.toBufferArray(), PUBLIC_DATA_TREE_HEIGHT), - ), - ); - const publicDataWritesSiblingPaths = insertionWitnessData.map(w => { - const insertionSiblingPath = w.siblingPath.toFields(); - assertLength(insertionSiblingPath, PUBLIC_DATA_TREE_HEIGHT); - return insertionSiblingPath as Tuple; - }); - - return { - lowPublicDataWritesPreimages, - lowPublicDataWritesMembershipWitnesses, - publicDataWritesSiblingPaths, - }; -} + const lowPublicDataWritesPreimages = lowLeavesWitnessData.map( + lowLeafWitness => lowLeafWitness.leafPreimage as PublicDataTreeLeafPreimage, + ); + const lowPublicDataWritesMembershipWitnesses = lowLeavesWitnessData.map(lowLeafWitness => + MembershipWitness.fromBufferArray( + lowLeafWitness.index, + assertLength(lowLeafWitness.siblingPath.toBufferArray(), PUBLIC_DATA_TREE_HEIGHT), + ), + ); + const publicDataWritesSiblingPaths = insertionWitnessData.map(w => { + const insertionSiblingPath = w.siblingPath.toFields(); + assertLength(insertionSiblingPath, PUBLIC_DATA_TREE_HEIGHT); + return insertionSiblingPath as Tuple; + }); + + return { + lowPublicDataWritesPreimages, + lowPublicDataWritesMembershipWitnesses, + publicDataWritesSiblingPaths, + }; + }, +); export async function getSubtreeSiblingPath( treeId: MerkleTreeId, diff --git a/yarn-project/prover-client/src/orchestrator/orchestrator.ts b/yarn-project/prover-client/src/orchestrator/orchestrator.ts index 8190da2dd6ff..f7f896acd9d5 100644 --- a/yarn-project/prover-client/src/orchestrator/orchestrator.ts +++ b/yarn-project/prover-client/src/orchestrator/orchestrator.ts @@ -49,7 +49,14 @@ import { pushTestData } from '@aztec/foundation/testing'; import { elapsed } from '@aztec/foundation/timer'; import { type TreeNodeLocation } from '@aztec/foundation/trees'; import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vks'; -import { Attributes, type TelemetryClient, type Tracer, trackSpan, wrapCallbackInSpan } from '@aztec/telemetry-client'; +import { + Attributes, + type TelemetryClient, + type Tracer, + getTelemetryClient, + trackSpan, + wrapCallbackInSpan, +} from '@aztec/telemetry-client'; import { inspect } from 'util'; @@ -94,8 +101,8 @@ export class ProvingOrchestrator implements EpochProver { constructor( private dbProvider: ForkMerkleTreeOperations, private prover: ServerCircuitProver, - telemetryClient: TelemetryClient, private readonly proverId: Fr = Fr.ZERO, + telemetryClient: TelemetryClient = getTelemetryClient(), ) { this.metrics = new ProvingOrchestratorMetrics(telemetryClient, 'ProvingOrchestrator'); } diff --git a/yarn-project/prover-client/src/orchestrator/orchestrator_failures.test.ts b/yarn-project/prover-client/src/orchestrator/orchestrator_failures.test.ts index c5c88dd8ed00..4d8bb057e3f1 100644 --- a/yarn-project/prover-client/src/orchestrator/orchestrator_failures.test.ts +++ b/yarn-project/prover-client/src/orchestrator/orchestrator_failures.test.ts @@ -3,7 +3,6 @@ import { type ServerCircuitProver } from '@aztec/circuit-types'; import { timesAsync } from '@aztec/foundation/collection'; import { createLogger } from '@aztec/foundation/log'; import { WASMSimulatorWithBlobs } from '@aztec/simulator'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; import { jest } from '@jest/globals'; @@ -28,8 +27,8 @@ describe('prover/orchestrator/failures', () => { let mockProver: ServerCircuitProver; beforeEach(() => { - mockProver = new TestCircuitProver(new NoopTelemetryClient(), new WASMSimulatorWithBlobs()); - orchestrator = new ProvingOrchestrator(context.worldState, mockProver, new NoopTelemetryClient()); + mockProver = new TestCircuitProver(new WASMSimulatorWithBlobs()); + orchestrator = new ProvingOrchestrator(context.worldState, mockProver); }); const run = async (message: string) => { diff --git a/yarn-project/prover-client/src/orchestrator/orchestrator_lifecycle.test.ts b/yarn-project/prover-client/src/orchestrator/orchestrator_lifecycle.test.ts index 29537740bfb1..46533097beca 100644 --- a/yarn-project/prover-client/src/orchestrator/orchestrator_lifecycle.test.ts +++ b/yarn-project/prover-client/src/orchestrator/orchestrator_lifecycle.test.ts @@ -3,7 +3,6 @@ import { NUM_BASE_PARITY_PER_ROOT_PARITY } from '@aztec/circuits.js'; import { createLogger } from '@aztec/foundation/log'; import { type PromiseWithResolvers, promiseWithResolvers } from '@aztec/foundation/promise'; import { sleep } from '@aztec/foundation/sleep'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; import { jest } from '@jest/globals'; @@ -26,8 +25,8 @@ describe('prover/orchestrator/lifecycle', () => { describe('lifecycle', () => { it('cancels proving requests', async () => { - const prover: ServerCircuitProver = new TestCircuitProver(new NoopTelemetryClient()); - const orchestrator = new ProvingOrchestrator(context.worldState, prover, new NoopTelemetryClient()); + const prover: ServerCircuitProver = new TestCircuitProver(); + const orchestrator = new ProvingOrchestrator(context.worldState, prover); const spy = jest.spyOn(prover, 'getBaseParityProof'); const deferredPromises: PromiseWithResolvers[] = []; diff --git a/yarn-project/prover-client/src/prover-agent/agent-queue-integration.test.ts b/yarn-project/prover-client/src/prover-agent/agent-queue-integration.test.ts index f8992a35ffb5..a6fd9009c8cf 100644 --- a/yarn-project/prover-client/src/prover-agent/agent-queue-integration.test.ts +++ b/yarn-project/prover-client/src/prover-agent/agent-queue-integration.test.ts @@ -13,7 +13,7 @@ import { makeBaseParityInputs, makeParityPublicInputs } from '@aztec/circuits.js import { AbortError } from '@aztec/foundation/error'; import { promiseWithResolvers } from '@aztec/foundation/promise'; import { sleep } from '@aztec/foundation/sleep'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; +import { getTelemetryClient } from '@aztec/telemetry-client'; import { type MockProxy, mock } from 'jest-mock-extended'; @@ -33,7 +33,7 @@ describe('Prover agent <-> queue integration', () => { queueJobTimeout = 100; queuePollInterval = 10; - queue = new MemoryProvingQueue(new NoopTelemetryClient(), queueJobTimeout, queuePollInterval); + queue = new MemoryProvingQueue(getTelemetryClient(), queueJobTimeout, queuePollInterval); agentPollInterval = 10; agent = new ProverAgent(prover, 1, agentPollInterval); diff --git a/yarn-project/prover-client/src/prover-agent/agent-queue-rpc-integration.test.ts b/yarn-project/prover-client/src/prover-agent/agent-queue-rpc-integration.test.ts index 6be41a4bdecd..22791753473c 100644 --- a/yarn-project/prover-client/src/prover-agent/agent-queue-rpc-integration.test.ts +++ b/yarn-project/prover-client/src/prover-agent/agent-queue-rpc-integration.test.ts @@ -16,7 +16,7 @@ import { } from '@aztec/circuits.js/testing'; import { createSafeJsonRpcClient } from '@aztec/foundation/json-rpc/client'; import { type SafeJsonRpcServer } from '@aztec/foundation/json-rpc/server'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; +import { getTelemetryClient } from '@aztec/telemetry-client'; import getPort from 'get-port'; @@ -53,7 +53,7 @@ describe('Prover agent <-> queue integration', () => { beforeEach(async () => { prover = new MockProver(); - queue = new MemoryProvingQueue(new NoopTelemetryClient(), 100, 10); + queue = new MemoryProvingQueue(getTelemetryClient(), 100, 10); queue.start(); const port = await getPort(); queueRpcServer = createProvingJobSourceServer(queue); diff --git a/yarn-project/prover-client/src/prover-agent/memory-proving-queue.test.ts b/yarn-project/prover-client/src/prover-agent/memory-proving-queue.test.ts index aa971c116cef..9cf02f5457fe 100644 --- a/yarn-project/prover-client/src/prover-agent/memory-proving-queue.test.ts +++ b/yarn-project/prover-client/src/prover-agent/memory-proving-queue.test.ts @@ -9,7 +9,7 @@ import { } from '@aztec/circuits.js/testing'; import { AbortError } from '@aztec/foundation/error'; import { sleep } from '@aztec/foundation/sleep'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; +import { getTelemetryClient } from '@aztec/telemetry-client'; import { InlineProofStore, type ProofStore } from '../proving_broker/proof_store.js'; import { MemoryProvingQueue } from './memory-proving-queue.js'; @@ -25,7 +25,7 @@ describe('MemoryProvingQueue', () => { pollingIntervalMs = 10; proofStore = new InlineProofStore(); queue = new MemoryProvingQueue( - new NoopTelemetryClient(), + getTelemetryClient(), jobTimeoutMs, pollingIntervalMs, undefined, diff --git a/yarn-project/prover-client/src/prover-agent/prover-agent.test.ts b/yarn-project/prover-client/src/prover-agent/prover-agent.test.ts index 7c344a44c055..8af88de41cfb 100644 --- a/yarn-project/prover-client/src/prover-agent/prover-agent.test.ts +++ b/yarn-project/prover-client/src/prover-agent/prover-agent.test.ts @@ -1,7 +1,7 @@ import { type ServerCircuitProver, makePublicInputsAndRecursiveProof } from '@aztec/circuit-types'; import { RECURSIVE_PROOF_LENGTH, VerificationKeyData, makeRecursiveProof } from '@aztec/circuits.js'; import { makeBaseParityInputs, makeParityPublicInputs } from '@aztec/circuits.js/testing'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; +import { getTelemetryClient } from '@aztec/telemetry-client'; import { type MockProxy, mock } from 'jest-mock-extended'; @@ -15,7 +15,7 @@ describe('ProverAgent', () => { beforeEach(() => { prover = mock(); - queue = new MemoryProvingQueue(new NoopTelemetryClient()); + queue = new MemoryProvingQueue(getTelemetryClient()); agent = new ProverAgent(prover); }); diff --git a/yarn-project/prover-client/src/prover-agent/prover-agent.ts b/yarn-project/prover-client/src/prover-agent/prover-agent.ts index 4cc8f1e97023..cbf6484fd7a5 100644 --- a/yarn-project/prover-client/src/prover-agent/prover-agent.ts +++ b/yarn-project/prover-client/src/prover-agent/prover-agent.ts @@ -11,8 +11,14 @@ import { import { createLogger } from '@aztec/foundation/log'; import { RunningPromise } from '@aztec/foundation/running-promise'; import { elapsed } from '@aztec/foundation/timer'; -import { Attributes, type TelemetryClient, type Traceable, type Tracer, trackSpan } from '@aztec/telemetry-client'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; +import { + Attributes, + type TelemetryClient, + type Traceable, + type Tracer, + getTelemetryClient, + trackSpan, +} from '@aztec/telemetry-client'; import { InlineProofStore } from '../proving_broker/proof_store.js'; @@ -42,7 +48,7 @@ export class ProverAgent implements ProverAgentApi, Traceable { /** How long to wait between jobs */ private pollIntervalMs = 100, /** Telemetry client */ - private telemetry: TelemetryClient = new NoopTelemetryClient(), + telemetry: TelemetryClient = getTelemetryClient(), /** Logger */ private log = createLogger('prover-client:prover-agent'), ) { diff --git a/yarn-project/prover-client/src/prover-client/factory.ts b/yarn-project/prover-client/src/prover-client/factory.ts index 45e10ed630bf..164ff1104e50 100644 --- a/yarn-project/prover-client/src/prover-client/factory.ts +++ b/yarn-project/prover-client/src/prover-client/factory.ts @@ -1,6 +1,5 @@ import { type ForkMerkleTreeOperations, type ProvingJobBroker } from '@aztec/circuit-types'; -import { type TelemetryClient } from '@aztec/telemetry-client'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; +import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client'; import { type ProverClientConfig } from '../config.js'; import { ProverClient } from './prover-client.js'; @@ -9,7 +8,7 @@ export function createProverClient( config: ProverClientConfig, worldState: ForkMerkleTreeOperations, broker: ProvingJobBroker, - telemetry: TelemetryClient = new NoopTelemetryClient(), + telemetry: TelemetryClient = getTelemetryClient(), ) { return ProverClient.new(config, worldState, broker, telemetry); } diff --git a/yarn-project/prover-client/src/prover-client/prover-client.ts b/yarn-project/prover-client/src/prover-client/prover-client.ts index a7d7f645949e..fd416116e2a0 100644 --- a/yarn-project/prover-client/src/prover-client/prover-client.ts +++ b/yarn-project/prover-client/src/prover-client/prover-client.ts @@ -13,7 +13,7 @@ import { Fr } from '@aztec/circuits.js'; import { times } from '@aztec/foundation/collection'; import { createLogger } from '@aztec/foundation/log'; import { NativeACVMSimulator } from '@aztec/simulator'; -import { type TelemetryClient } from '@aztec/telemetry-client'; +import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client'; import { type ProverClientConfig } from '../config.js'; import { ProvingOrchestrator } from '../orchestrator/orchestrator.js'; @@ -30,9 +30,9 @@ export class ProverClient implements EpochProverManager { private constructor( private config: ProverClientConfig, private worldState: ForkMerkleTreeOperations, - private telemetry: TelemetryClient, private orchestratorClient: ProvingJobProducer, private agentClient?: ProvingJobConsumer, + private telemetry: TelemetryClient = getTelemetryClient(), private log = createLogger('prover-client:tx-prover'), ) { // TODO(palla/prover-node): Cache the paddingTx here, and not in each proving orchestrator, @@ -41,7 +41,7 @@ export class ProverClient implements EpochProverManager { public createEpochProver(): EpochProver { const facade = new BrokerCircuitProverFacade(this.orchestratorClient); - const orchestrator = new ProvingOrchestrator(this.worldState, facade, this.telemetry, this.config.proverId); + const orchestrator = new ProvingOrchestrator(this.worldState, facade, this.config.proverId, this.telemetry); return new ServerEpochProver(facade, orchestrator); } @@ -100,9 +100,9 @@ export class ProverClient implements EpochProverManager { config: ProverClientConfig, worldState: ForkMerkleTreeOperations, broker: ProvingJobBroker, - telemetry: TelemetryClient, + telemetry: TelemetryClient = getTelemetryClient(), ) { - const prover = new ProverClient(config, worldState, telemetry, broker, broker); + const prover = new ProverClient(config, worldState, broker, broker, telemetry); await prover.start(); return prover; } @@ -133,9 +133,9 @@ export class ProverClient implements EpochProverManager { this.agentClient!, proofStore, prover, - this.telemetry, [], this.config.proverAgentPollIntervalMs, + this.telemetry, ), ); @@ -159,5 +159,5 @@ export function buildServerCircuitProver( ? new NativeACVMSimulator(config.acvmWorkingDirectory, config.acvmBinaryPath) : undefined; - return Promise.resolve(new TestCircuitProver(telemetry, simulationProvider, config)); + return Promise.resolve(new TestCircuitProver(simulationProvider, config, telemetry)); } diff --git a/yarn-project/prover-client/src/proving_broker/factory.ts b/yarn-project/prover-client/src/proving_broker/factory.ts index aadd7558eaa5..22e86099e86f 100644 --- a/yarn-project/prover-client/src/proving_broker/factory.ts +++ b/yarn-project/prover-client/src/proving_broker/factory.ts @@ -11,11 +11,15 @@ export async function createAndStartProvingBroker( ): Promise { const database = config.dataDirectory ? await KVBrokerDatabase.new(config, client) : new InMemoryBrokerDatabase(); - const broker = new ProvingBroker(database, client, { - jobTimeoutMs: config.proverBrokerJobTimeoutMs, - maxRetries: config.proverBrokerJobMaxRetries, - timeoutIntervalMs: config.proverBrokerPollIntervalMs, - }); + const broker = new ProvingBroker( + database, + { + jobTimeoutMs: config.proverBrokerJobTimeoutMs, + maxRetries: config.proverBrokerJobMaxRetries, + timeoutIntervalMs: config.proverBrokerPollIntervalMs, + }, + client, + ); await broker.start(); return broker; diff --git a/yarn-project/prover-client/src/proving_broker/proving_agent.test.ts b/yarn-project/prover-client/src/proving_broker/proving_agent.test.ts index 405d16d5c1e4..aea11548e443 100644 --- a/yarn-project/prover-client/src/proving_broker/proving_agent.test.ts +++ b/yarn-project/prover-client/src/proving_broker/proving_agent.test.ts @@ -19,7 +19,6 @@ import { makeBaseParityInputs, makeParityPublicInputs } from '@aztec/circuits.js import { randomBytes } from '@aztec/foundation/crypto'; import { AbortError } from '@aztec/foundation/error'; import { promiseWithResolvers } from '@aztec/foundation/promise'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; import { jest } from '@jest/globals'; @@ -51,7 +50,7 @@ describe('ProvingAgent', () => { saveProofOutput: jest.fn(), }; - agent = new ProvingAgent(jobSource, proofDB, prover, new NoopTelemetryClient(), [ProvingRequestType.BASE_PARITY]); + agent = new ProvingAgent(jobSource, proofDB, prover, [ProvingRequestType.BASE_PARITY]); }); afterEach(async () => { diff --git a/yarn-project/prover-client/src/proving_broker/proving_agent.ts b/yarn-project/prover-client/src/proving_broker/proving_agent.ts index 3c099c8f1a56..68fcb4fb410d 100644 --- a/yarn-project/prover-client/src/proving_broker/proving_agent.ts +++ b/yarn-project/prover-client/src/proving_broker/proving_agent.ts @@ -12,7 +12,13 @@ import { createLogger } from '@aztec/foundation/log'; import { RunningPromise } from '@aztec/foundation/running-promise'; import { truncate } from '@aztec/foundation/string'; import { Timer } from '@aztec/foundation/timer'; -import { type TelemetryClient, type Traceable, type Tracer, trackSpan } from '@aztec/telemetry-client'; +import { + type TelemetryClient, + type Traceable, + type Tracer, + getTelemetryClient, + trackSpan, +} from '@aztec/telemetry-client'; import { type ProofStore } from './proof_store.js'; import { ProvingAgentInstrumentation } from './proving_agent_instrumentation.js'; @@ -36,12 +42,12 @@ export class ProvingAgent implements Traceable { private proofStore: ProofStore, /** The prover implementation to defer jobs to */ private circuitProver: ServerCircuitProver, - /** A telemetry client through which to emit metrics */ - client: TelemetryClient, /** Optional list of allowed proof types to build */ private proofAllowList: Array = [], /** How long to wait between jobs */ private pollIntervalMs = 1000, + /** A telemetry client through which to emit metrics */ + client: TelemetryClient = getTelemetryClient(), private log = createLogger('prover-client:proving-agent'), ) { this.tracer = client.getTracer('ProvingAgent'); diff --git a/yarn-project/prover-client/src/proving_broker/proving_broker.test.ts b/yarn-project/prover-client/src/proving_broker/proving_broker.test.ts index 6a9f2ae10256..14e2f7e06241 100644 --- a/yarn-project/prover-client/src/proving_broker/proving_broker.test.ts +++ b/yarn-project/prover-client/src/proving_broker/proving_broker.test.ts @@ -6,7 +6,6 @@ import { ProvingRequestType, } from '@aztec/circuit-types'; import { sleep } from '@aztec/foundation/sleep'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; import { jest } from '@jest/globals'; import { mkdtemp } from 'fs/promises'; @@ -31,7 +30,7 @@ describe.each([ proverBrokerJobTimeoutMs: 1000, proverBrokerPollIntervalMs: 1000, }; - const database = await KVBrokerDatabase.new(config, new NoopTelemetryClient()); + const database = await KVBrokerDatabase.new(config); const cleanup = () => {}; return { database, cleanup }; }, @@ -51,7 +50,7 @@ describe.each([ brokerIntervalMs = jobTimeoutMs / 4; ({ database, cleanup } = await createDb()); - broker = new ProvingBroker(database, new NoopTelemetryClient(), { + broker = new ProvingBroker(database, { jobTimeoutMs, timeoutIntervalMs: brokerIntervalMs, maxRetries, @@ -472,7 +471,7 @@ describe.each([ // time passes while the broker restarts await sleep(10 * jobTimeoutMs); - broker = new ProvingBroker(database, new NoopTelemetryClient()); + broker = new ProvingBroker(database); await broker.start(); await assertJobStatus(job1.id, 'in-queue'); @@ -533,7 +532,7 @@ describe.each([ // time passes while the broker restarts await sleep(10 * jobTimeoutMs); - broker = new ProvingBroker(database, new NoopTelemetryClient()); + broker = new ProvingBroker(database); await broker.start(); await assertJobStatus(job1.id, 'in-queue'); @@ -584,7 +583,7 @@ describe.each([ // time passes while the broker restarts await sleep(10 * jobTimeoutMs); - broker = new ProvingBroker(database, new NoopTelemetryClient()); + broker = new ProvingBroker(database); await broker.start(); await assertJobStatus(job1.id, 'in-queue'); diff --git a/yarn-project/prover-client/src/proving_broker/proving_broker.ts b/yarn-project/prover-client/src/proving_broker/proving_broker.ts index f4461a366d6d..5eabd41ea37c 100644 --- a/yarn-project/prover-client/src/proving_broker/proving_broker.ts +++ b/yarn-project/prover-client/src/proving_broker/proving_broker.ts @@ -13,7 +13,13 @@ import { createLogger } from '@aztec/foundation/log'; import { type PromiseWithResolvers, RunningPromise, promiseWithResolvers } from '@aztec/foundation/promise'; import { PriorityMemoryQueue, SerialQueue } from '@aztec/foundation/queue'; import { Timer } from '@aztec/foundation/timer'; -import { type TelemetryClient, type Traceable, type Tracer, trackSpan } from '@aztec/telemetry-client'; +import { + type TelemetryClient, + type Traceable, + type Tracer, + getTelemetryClient, + trackSpan, +} from '@aztec/telemetry-client'; import assert from 'assert'; @@ -108,13 +114,13 @@ export class ProvingBroker implements ProvingJobProducer, ProvingJobConsumer, Tr public constructor( private database: ProvingBrokerDatabase, - client: TelemetryClient, { jobTimeoutMs = 30_000, timeoutIntervalMs = 10_000, maxRetries = 3, maxEpochsToKeepResultsFor = 1, }: ProofRequestBrokerConfig = {}, + client: TelemetryClient = getTelemetryClient(), private logger = createLogger('prover-client:proving-broker'), ) { this.tracer = client.getTracer('ProvingBroker'); diff --git a/yarn-project/prover-client/src/proving_broker/proving_broker_database/broker_persisted_database.test.ts b/yarn-project/prover-client/src/proving_broker/proving_broker_database/broker_persisted_database.test.ts index 46154cf635c8..1672baf4d9d8 100644 --- a/yarn-project/prover-client/src/proving_broker/proving_broker_database/broker_persisted_database.test.ts +++ b/yarn-project/prover-client/src/proving_broker/proving_broker_database/broker_persisted_database.test.ts @@ -1,5 +1,4 @@ import { type ProofUri, type ProvingJob, type ProvingJobSettledResult, ProvingRequestType } from '@aztec/circuit-types'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; import { existsSync } from 'fs'; import { mkdir, mkdtemp, rm } from 'fs/promises'; @@ -24,7 +23,7 @@ describe('ProvingBrokerPersistedDatabase', () => { proverBrokerJobTimeoutMs: 1000, proverBrokerPollIntervalMs: 1000, }; - db = await KVBrokerDatabase.new(config, new NoopTelemetryClient()); + db = await KVBrokerDatabase.new(config); }); afterEach(async () => { @@ -259,7 +258,7 @@ describe('ProvingBrokerPersistedDatabase', () => { await mkdir(garbageDirectory, { recursive: true }); // Now create another instance - const secondDb = await KVBrokerDatabase.new(config, new NoopTelemetryClient()); + const secondDb = await KVBrokerDatabase.new(config); // All data should be restored const allJobs = Array.from(secondDb.allProvingJobs()); diff --git a/yarn-project/prover-client/src/proving_broker/proving_broker_database/persisted.ts b/yarn-project/prover-client/src/proving_broker/proving_broker_database/persisted.ts index 0c8b5029d6fe..39e0a74e46cd 100644 --- a/yarn-project/prover-client/src/proving_broker/proving_broker_database/persisted.ts +++ b/yarn-project/prover-client/src/proving_broker/proving_broker_database/persisted.ts @@ -9,7 +9,7 @@ import { jsonParseWithSchema, jsonStringify } from '@aztec/foundation/json-rpc'; import { type Logger, createLogger } from '@aztec/foundation/log'; import { type AztecMap } from '@aztec/kv-store'; import { AztecLmdbStore } from '@aztec/kv-store/lmdb'; -import { Attributes, LmdbMetrics, type TelemetryClient } from '@aztec/telemetry-client'; +import { Attributes, LmdbMetrics, type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client'; import { mkdir, readdir } from 'fs/promises'; import { join } from 'path'; @@ -68,7 +68,7 @@ export class KVBrokerDatabase implements ProvingBrokerDatabase { private constructor( private epochs: Map, private config: ProverBrokerConfig, - client: TelemetryClient, + client: TelemetryClient = getTelemetryClient(), private logger: Logger, ) { this.metrics = new LmdbMetrics( @@ -91,7 +91,7 @@ export class KVBrokerDatabase implements ProvingBrokerDatabase { public static async new( config: ProverBrokerConfig, - client: TelemetryClient, + client: TelemetryClient = getTelemetryClient(), logger = createLogger('prover-client:proving-broker-database'), ) { const epochs: Map = new Map(); diff --git a/yarn-project/prover-client/src/test/bb_prover_full_rollup.test.ts b/yarn-project/prover-client/src/test/bb_prover_full_rollup.test.ts index 263c0dfe9b65..d16d18e15f9b 100644 --- a/yarn-project/prover-client/src/test/bb_prover_full_rollup.test.ts +++ b/yarn-project/prover-client/src/test/bb_prover_full_rollup.test.ts @@ -7,7 +7,7 @@ import { type Logger, createLogger } from '@aztec/foundation/log'; import { getTestData, isGenerateTestDataEnabled } from '@aztec/foundation/testing'; import { writeTestData } from '@aztec/foundation/testing/files'; import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vks'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; +import { getTelemetryClient } from '@aztec/telemetry-client'; import { buildBlock } from '../block_builder/light.js'; import { makeGlobals } from '../mocks/fixtures.js'; @@ -20,7 +20,7 @@ describe('prover/bb_prover/full-rollup', () => { beforeEach(async () => { const buildProver = async (bbConfig: BBProverConfig) => { - prover = await BBNativeRollupProver.new(bbConfig, new NoopTelemetryClient()); + prover = await BBNativeRollupProver.new(bbConfig, getTelemetryClient()); return prover; }; log = createLogger('prover-client:test:bb-prover-full-rollup'); diff --git a/yarn-project/prover-client/src/test/bb_prover_parity.test.ts b/yarn-project/prover-client/src/test/bb_prover_parity.test.ts index 2db1248ac9df..1f65db5607f1 100644 --- a/yarn-project/prover-client/src/test/bb_prover_parity.test.ts +++ b/yarn-project/prover-client/src/test/bb_prover_parity.test.ts @@ -20,7 +20,6 @@ import { getVKSiblingPath, getVKTreeRoot, } from '@aztec/noir-protocol-circuits-types/vks'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; import { TestContext } from '../mocks/test_context.js'; @@ -33,7 +32,7 @@ describe('prover/bb_prover/parity', () => { beforeAll(async () => { const buildProver = async (bbConfig: BBProverConfig) => { bbConfig.circuitFilter = ['BaseParityArtifact', 'RootParityArtifact']; - bbProver = await BBNativeRollupProver.new(bbConfig, new NoopTelemetryClient()); + bbProver = await BBNativeRollupProver.new(bbConfig); return bbProver; }; context = await TestContext.new(logger, 1, buildProver); diff --git a/yarn-project/prover-client/src/test/mock_prover.ts b/yarn-project/prover-client/src/test/mock_prover.ts index 2618bbb9c2e9..35fa567f9214 100644 --- a/yarn-project/prover-client/src/test/mock_prover.ts +++ b/yarn-project/prover-client/src/test/mock_prover.ts @@ -43,7 +43,6 @@ import { makeRootRollupPublicInputs, } from '@aztec/circuits.js/testing'; import { times } from '@aztec/foundation/collection'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; import { InlineProofStore, type ProofStore } from '../proving_broker/proof_store.js'; import { ProvingAgent } from '../proving_broker/proving_agent.js'; @@ -51,7 +50,7 @@ import { ProvingBroker } from '../proving_broker/proving_broker.js'; import { InMemoryBrokerDatabase } from '../proving_broker/proving_broker_database/memory.js'; export class TestBroker implements ProvingJobProducer { - private broker = new ProvingBroker(new InMemoryBrokerDatabase(), new NoopTelemetryClient()); + private broker = new ProvingBroker(new InMemoryBrokerDatabase()); private agents: ProvingAgent[]; constructor( @@ -62,7 +61,7 @@ export class TestBroker implements ProvingJobProducer { ) { this.agents = times( agentCount, - () => new ProvingAgent(this.broker, proofStore, prover, new NoopTelemetryClient(), undefined, agentPollInterval), + () => new ProvingAgent(this.broker, proofStore, prover, undefined, agentPollInterval), ); } diff --git a/yarn-project/prover-node/src/factory.ts b/yarn-project/prover-node/src/factory.ts index 300fd6641382..c129933070d1 100644 --- a/yarn-project/prover-node/src/factory.ts +++ b/yarn-project/prover-node/src/factory.ts @@ -10,8 +10,7 @@ import { RollupAbi } from '@aztec/l1-artifacts'; import { createProverClient } from '@aztec/prover-client'; import { createAndStartProvingBroker } from '@aztec/prover-client/broker'; import { L1Publisher } from '@aztec/sequencer-client'; -import { type TelemetryClient } from '@aztec/telemetry-client'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; +import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client'; import { createWorldStateSynchronizer } from '@aztec/world-state'; import { createPublicClient, getAddress, getContract, http } from 'viem'; @@ -39,10 +38,10 @@ export async function createProverNode( broker?: ProvingJobBroker; } = {}, ) { - const telemetry = deps.telemetry ?? new NoopTelemetryClient(); + const telemetry = deps.telemetry ?? getTelemetryClient(); const blobSinkClient = deps.blobSinkClient ?? createBlobSinkClient(config.blobSinkUrl); const log = deps.log ?? createLogger('prover-node'); - const archiver = deps.archiver ?? (await createArchiver(config, blobSinkClient, telemetry, { blockUntilSync: true })); + const archiver = deps.archiver ?? (await createArchiver(config, blobSinkClient, { blockUntilSync: true }, telemetry)); log.verbose(`Created archiver and synced to block ${await archiver.getBlockNumber()}`); const worldStateConfig = { ...config, worldStateProvenBlocksOnly: false }; @@ -79,8 +78,8 @@ export async function createProverNode( txGatheringTimeoutMs: config.txGatheringTimeoutMs, }; - const claimsMonitor = new ClaimsMonitor(publisher, telemetry, proverNodeConfig); - const epochMonitor = new EpochMonitor(archiver, telemetry, proverNodeConfig); + const claimsMonitor = new ClaimsMonitor(publisher, proverNodeConfig, telemetry); + const epochMonitor = new EpochMonitor(archiver, proverNodeConfig, telemetry); const rollupContract = publisher.getRollupContract(); const walletClient = publisher.getClient(); @@ -99,8 +98,8 @@ export async function createProverNode( claimsMonitor, epochMonitor, bondManager, - telemetry, proverNodeConfig, + telemetry, ); } diff --git a/yarn-project/prover-node/src/job/epoch-proving-job.test.ts b/yarn-project/prover-node/src/job/epoch-proving-job.test.ts index 4576c377f2bc..b992dbbb7f57 100644 --- a/yarn-project/prover-node/src/job/epoch-proving-job.test.ts +++ b/yarn-project/prover-node/src/job/epoch-proving-job.test.ts @@ -14,7 +14,7 @@ import { times } from '@aztec/foundation/collection'; import { sleep } from '@aztec/foundation/sleep'; import { type L1Publisher } from '@aztec/sequencer-client'; import { type PublicProcessor, type PublicProcessorFactory } from '@aztec/simulator'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; +import { getTelemetryClient } from '@aztec/telemetry-client'; import { type MockProxy, mock } from 'jest-mock-extended'; @@ -74,7 +74,7 @@ describe('epoch-proving-job', () => { publicProcessorFactory = mock(); db = mock(); publicProcessor = mock(); - metrics = new ProverNodeMetrics(new NoopTelemetryClient()); + metrics = new ProverNodeMetrics(getTelemetryClient()); publicInputs = RootRollupPublicInputs.random(); proof = Proof.empty(); diff --git a/yarn-project/prover-node/src/monitors/claims-monitor.test.ts b/yarn-project/prover-node/src/monitors/claims-monitor.test.ts index 0771faaf161e..610284e3caa1 100644 --- a/yarn-project/prover-node/src/monitors/claims-monitor.test.ts +++ b/yarn-project/prover-node/src/monitors/claims-monitor.test.ts @@ -2,7 +2,6 @@ import { type EpochProofClaim } from '@aztec/circuit-types'; import { EthAddress } from '@aztec/circuits.js'; import { sleep } from '@aztec/foundation/sleep'; import { type L1Publisher } from '@aztec/sequencer-client'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; import { type MockProxy, mock } from 'jest-mock-extended'; @@ -22,7 +21,7 @@ describe('ClaimsMonitor', () => { publisherAddress = EthAddress.random(); l1Publisher.getSenderAddress.mockReturnValue(publisherAddress); - claimsMonitor = new ClaimsMonitor(l1Publisher, new NoopTelemetryClient(), { pollingIntervalMs: 10 }); + claimsMonitor = new ClaimsMonitor(l1Publisher, { pollingIntervalMs: 10 }); }); afterEach(async () => { diff --git a/yarn-project/prover-node/src/monitors/claims-monitor.ts b/yarn-project/prover-node/src/monitors/claims-monitor.ts index 9aecb95b6396..56cf77ea7a2b 100644 --- a/yarn-project/prover-node/src/monitors/claims-monitor.ts +++ b/yarn-project/prover-node/src/monitors/claims-monitor.ts @@ -3,7 +3,13 @@ import { type EthAddress } from '@aztec/circuits.js'; import { createLogger } from '@aztec/foundation/log'; import { RunningPromise } from '@aztec/foundation/running-promise'; import { type L1Publisher } from '@aztec/sequencer-client'; -import { type TelemetryClient, type Traceable, type Tracer, trackSpan } from '@aztec/telemetry-client'; +import { + type TelemetryClient, + type Traceable, + type Tracer, + getTelemetryClient, + trackSpan, +} from '@aztec/telemetry-client'; export interface ClaimsMonitorHandler { handleClaim(proofClaim: EpochProofClaim): Promise; @@ -20,8 +26,8 @@ export class ClaimsMonitor implements Traceable { constructor( private readonly l1Publisher: L1Publisher, - telemetry: TelemetryClient, private options: { pollingIntervalMs: number }, + telemetry: TelemetryClient = getTelemetryClient(), ) { this.tracer = telemetry.getTracer('ClaimsMonitor'); this.runningPromise = new RunningPromise(this.work.bind(this), this.log, this.options.pollingIntervalMs); diff --git a/yarn-project/prover-node/src/monitors/epoch-monitor.test.ts b/yarn-project/prover-node/src/monitors/epoch-monitor.test.ts index 033cc74d1b38..f7a0d7dc4067 100644 --- a/yarn-project/prover-node/src/monitors/epoch-monitor.test.ts +++ b/yarn-project/prover-node/src/monitors/epoch-monitor.test.ts @@ -1,6 +1,5 @@ import { type L2BlockSource } from '@aztec/circuit-types'; import { sleep } from '@aztec/foundation/sleep'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; import { type MockProxy, mock } from 'jest-mock-extended'; @@ -21,7 +20,7 @@ describe('EpochMonitor', () => { }, }); - epochMonitor = new EpochMonitor(l2BlockSource, new NoopTelemetryClient(), { pollingIntervalMs: 10 }); + epochMonitor = new EpochMonitor(l2BlockSource, { pollingIntervalMs: 10 }); }); afterEach(async () => { diff --git a/yarn-project/prover-node/src/monitors/epoch-monitor.ts b/yarn-project/prover-node/src/monitors/epoch-monitor.ts index 503429cf853e..a285162a6629 100644 --- a/yarn-project/prover-node/src/monitors/epoch-monitor.ts +++ b/yarn-project/prover-node/src/monitors/epoch-monitor.ts @@ -1,7 +1,13 @@ import { type L2BlockSource } from '@aztec/circuit-types'; import { createLogger } from '@aztec/foundation/log'; import { RunningPromise } from '@aztec/foundation/running-promise'; -import { type TelemetryClient, type Traceable, type Tracer, trackSpan } from '@aztec/telemetry-client'; +import { + type TelemetryClient, + type Traceable, + type Tracer, + getTelemetryClient, + trackSpan, +} from '@aztec/telemetry-client'; export interface EpochMonitorHandler { handleInitialEpochSync(epochNumber: bigint): Promise; @@ -19,8 +25,8 @@ export class EpochMonitor implements Traceable { constructor( private readonly l2BlockSource: L2BlockSource, - telemetry: TelemetryClient, private options: { pollingIntervalMs: number }, + telemetry: TelemetryClient = getTelemetryClient(), ) { this.tracer = telemetry.getTracer('EpochMonitor'); this.runningPromise = new RunningPromise(this.work.bind(this), this.log, this.options.pollingIntervalMs); diff --git a/yarn-project/prover-node/src/prover-node.test.ts b/yarn-project/prover-node/src/prover-node.test.ts index d784fbea92db..6bd9a6a62fc8 100644 --- a/yarn-project/prover-node/src/prover-node.test.ts +++ b/yarn-project/prover-node/src/prover-node.test.ts @@ -26,7 +26,7 @@ import { type BootstrapNode, InMemoryTxPool, MemoryEpochProofQuotePool, P2PClien import { createBootstrapNode, createTestLibP2PService } from '@aztec/p2p/mocks'; import { type L1Publisher } from '@aztec/sequencer-client'; import { type PublicProcessorFactory } from '@aztec/simulator'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; +import { getTelemetryClient } from '@aztec/telemetry-client'; import { jest } from '@jest/globals'; import { type MockProxy, mock } from 'jest-mock-extended'; @@ -52,7 +52,6 @@ describe('prover-node', () => { let quoteProvider: MockProxy; let quoteSigner: MockProxy; let bondManager: MockProxy; - let telemetryClient: NoopTelemetryClient; let config: ProverNodeOptions; // Subject under test @@ -101,7 +100,6 @@ describe('prover-node', () => { claimsMonitor, epochMonitor, bondManager, - telemetryClient, config, ); @@ -118,7 +116,6 @@ describe('prover-node', () => { quoteSigner = mock(); bondManager = mock(); - telemetryClient = new NoopTelemetryClient(); config = { maxPendingJobs: 3, pollingIntervalMs: 10, @@ -265,9 +262,8 @@ describe('prover-node', () => { let lastEpochComplete: bigint = 0n; beforeEach(() => { - const telemetry = new NoopTelemetryClient(); - claimsMonitor = new ClaimsMonitor(publisher, telemetry, config); - epochMonitor = new EpochMonitor(l2BlockSource, telemetry, config); + claimsMonitor = new ClaimsMonitor(publisher, config); + epochMonitor = new EpochMonitor(l2BlockSource, config); l2BlockSource.isEpochComplete.mockImplementation(epochNumber => Promise.resolve(epochNumber <= lastEpochComplete), @@ -373,8 +369,8 @@ describe('prover-node', () => { const createP2PClient = async (bootnodeAddr: string, port: number) => { const mempools = { - txPool: new InMemoryTxPool(telemetryClient), - epochProofQuotePool: new MemoryEpochProofQuotePool(telemetryClient), + txPool: new InMemoryTxPool(), + epochProofQuotePool: new MemoryEpochProofQuotePool(), }; epochCache = mock(); const libp2pService = await createTestLibP2PService( @@ -384,7 +380,7 @@ describe('prover-node', () => { worldState, epochCache, mempools, - telemetryClient, + getTelemetryClient(), port, ); const kvStore = openTmpStore(); diff --git a/yarn-project/prover-node/src/prover-node.ts b/yarn-project/prover-node/src/prover-node.ts index 3fc7e9a07ee4..c153c2ff6c62 100644 --- a/yarn-project/prover-node/src/prover-node.ts +++ b/yarn-project/prover-node/src/prover-node.ts @@ -28,7 +28,14 @@ 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 { Attributes, type TelemetryClient, type Traceable, type Tracer, trackSpan } from '@aztec/telemetry-client'; +import { + Attributes, + type TelemetryClient, + type Traceable, + type Tracer, + getTelemetryClient, + trackSpan, +} from '@aztec/telemetry-client'; import { type BondManager } from './bond/bond-manager.js'; import { EpochProvingJob, type EpochProvingJobState } from './job/epoch-proving-job.js'; @@ -78,8 +85,8 @@ export class ProverNode implements ClaimsMonitorHandler, EpochMonitorHandler, Pr protected readonly claimsMonitor: ClaimsMonitor, protected readonly epochsMonitor: EpochMonitor, protected readonly bondManager: BondManager, - protected readonly telemetryClient: TelemetryClient, options: Partial = {}, + protected readonly telemetryClient: TelemetryClient = getTelemetryClient(), ) { this.options = { pollingIntervalMs: 1_000, diff --git a/yarn-project/sequencer-client/src/client/sequencer-client.ts b/yarn-project/sequencer-client/src/client/sequencer-client.ts index 10119d98057d..489caab62d38 100644 --- a/yarn-project/sequencer-client/src/client/sequencer-client.ts +++ b/yarn-project/sequencer-client/src/client/sequencer-client.ts @@ -104,8 +104,8 @@ export class SequencerClient { contractDataSource, l1Constants, deps.dateProvider, - telemetryClient, { ...config, maxL1TxInclusionTimeIntoSlot }, + telemetryClient, ); await validatorClient?.start(); await sequencer.start(); diff --git a/yarn-project/sequencer-client/src/publisher/l1-publisher.test.ts b/yarn-project/sequencer-client/src/publisher/l1-publisher.test.ts index a000d6f80f59..5343df7a4827 100644 --- a/yarn-project/sequencer-client/src/publisher/l1-publisher.test.ts +++ b/yarn-project/sequencer-client/src/publisher/l1-publisher.test.ts @@ -12,7 +12,6 @@ import { Blob } from '@aztec/foundation/blob'; import { type ViemSignature } from '@aztec/foundation/eth-signature'; import { sleep } from '@aztec/foundation/sleep'; import { RollupAbi } from '@aztec/l1-artifacts'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; import { jest } from '@jest/globals'; import express, { json } from 'express'; @@ -139,7 +138,7 @@ describe('L1Publisher', () => { Pick & L1TxUtilsConfig; - publisher = new L1Publisher(config, { telemetry: new NoopTelemetryClient(), blobSinkClient }); + publisher = new L1Publisher(config, { blobSinkClient }); (publisher as any)['rollupContract'] = rollupContract; (publisher as any)['publicClient'] = publicClient; diff --git a/yarn-project/sequencer-client/src/publisher/l1-publisher.ts b/yarn-project/sequencer-client/src/publisher/l1-publisher.ts index f298bf6d6edf..f0ac1e39af5b 100644 --- a/yarn-project/sequencer-client/src/publisher/l1-publisher.ts +++ b/yarn-project/sequencer-client/src/publisher/l1-publisher.ts @@ -29,8 +29,7 @@ import { type Tuple, serializeToBuffer } from '@aztec/foundation/serialize'; import { InterruptibleSleep } from '@aztec/foundation/sleep'; import { Timer } from '@aztec/foundation/timer'; import { EmpireBaseAbi, RollupAbi, SlasherAbi } from '@aztec/l1-artifacts'; -import { type TelemetryClient } from '@aztec/telemetry-client'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; +import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client'; import pick from 'lodash.pick'; import { @@ -195,7 +194,7 @@ export class L1Publisher { this.sleepTimeMs = config?.l1PublishRetryIntervalMS ?? 60_000; this.ethereumSlotDuration = BigInt(config.ethereumSlotDuration); - const telemetry = deps.telemetry ?? new NoopTelemetryClient(); + const telemetry = deps.telemetry ?? getTelemetryClient(); this.blobSinkClient = deps.blobSinkClient ?? createBlobSinkClient(config.blobSinkUrl); this.metrics = new L1PublisherMetrics(telemetry, 'L1Publisher'); diff --git a/yarn-project/sequencer-client/src/sequencer/sequencer.test.ts b/yarn-project/sequencer-client/src/sequencer/sequencer.test.ts index 7a9c96e898ea..62adbe0499e5 100644 --- a/yarn-project/sequencer-client/src/sequencer/sequencer.test.ts +++ b/yarn-project/sequencer-client/src/sequencer/sequencer.test.ts @@ -39,7 +39,6 @@ import { TestDateProvider } from '@aztec/foundation/timer'; import { type P2P, P2PClientState } from '@aztec/p2p'; import { type BlockBuilderFactory } from '@aztec/prover-client/block-builder'; import { type PublicProcessor, type PublicProcessorFactory } from '@aztec/simulator'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; import { type ValidatorClient } from '@aztec/validator-client'; import { expect } from '@jest/globals'; @@ -245,7 +244,6 @@ describe('sequencer', () => { contractSource, l1Constants, new TestDateProvider(), - new NoopTelemetryClient(), { enforceTimeTable: true, maxTxsPerBlock: 4 }, ); }); diff --git a/yarn-project/sequencer-client/src/sequencer/sequencer.ts b/yarn-project/sequencer-client/src/sequencer/sequencer.ts index cbff50f2b1f9..1b3ae0c55ddc 100644 --- a/yarn-project/sequencer-client/src/sequencer/sequencer.ts +++ b/yarn-project/sequencer-client/src/sequencer/sequencer.ts @@ -32,7 +32,7 @@ import { type DateProvider, Timer, elapsed } from '@aztec/foundation/timer'; import { type P2P } from '@aztec/p2p'; import { type BlockBuilderFactory } from '@aztec/prover-client/block-builder'; import { type PublicProcessorFactory } from '@aztec/simulator'; -import { Attributes, type TelemetryClient, type Tracer, trackSpan } from '@aztec/telemetry-client'; +import { Attributes, type TelemetryClient, type Tracer, getTelemetryClient, trackSpan } from '@aztec/telemetry-client'; import { type ValidatorClient } from '@aztec/validator-client'; import { type GlobalVariableBuilder } from '../global_variable_builder/global_builder.js'; @@ -110,8 +110,8 @@ export class Sequencer { protected contractDataSource: ContractDataSource, protected l1Constants: SequencerRollupConstants, protected dateProvider: DateProvider, - telemetry: TelemetryClient, protected config: SequencerConfig = {}, + telemetry: TelemetryClient = getTelemetryClient(), protected log = createLogger('sequencer'), ) { this.updateConfig(config); diff --git a/yarn-project/sequencer-client/src/slasher/factory.ts b/yarn-project/sequencer-client/src/slasher/factory.ts index 85decb074ea7..c6fe4c624e04 100644 --- a/yarn-project/sequencer-client/src/slasher/factory.ts +++ b/yarn-project/sequencer-client/src/slasher/factory.ts @@ -4,8 +4,7 @@ import { createLogger } from '@aztec/foundation/log'; import { type AztecKVStore } from '@aztec/kv-store'; import { type DataStoreConfig } from '@aztec/kv-store/config'; import { createStore } from '@aztec/kv-store/lmdb'; -import { type TelemetryClient } from '@aztec/telemetry-client'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; +import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client'; import { SlasherClient } from './slasher_client.js'; import { type SlasherConfig } from './slasher_client.js'; @@ -13,7 +12,7 @@ import { type SlasherConfig } from './slasher_client.js'; export const createSlasherClient = async ( _config: SlasherConfig & DataStoreConfig & L1ContractsConfig & L1ReaderConfig, l2BlockSource: L2BlockSource, - telemetry: TelemetryClient = new NoopTelemetryClient(), + telemetry: TelemetryClient = getTelemetryClient(), deps: { store?: AztecKVStore } = {}, ) => { const config = { ..._config }; diff --git a/yarn-project/sequencer-client/src/slasher/slasher_client.ts b/yarn-project/sequencer-client/src/slasher/slasher_client.ts index cc5e60e25ead..f2022c9c55d1 100644 --- a/yarn-project/sequencer-client/src/slasher/slasher_client.ts +++ b/yarn-project/sequencer-client/src/slasher/slasher_client.ts @@ -12,8 +12,7 @@ import { EthAddress } from '@aztec/foundation/eth-address'; import { createLogger } from '@aztec/foundation/log'; import { type AztecKVStore, type AztecMap, type AztecSingleton } from '@aztec/kv-store'; import { SlashFactoryAbi } from '@aztec/l1-artifacts'; -import { type TelemetryClient, WithTracer } from '@aztec/telemetry-client'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; +import { type TelemetryClient, WithTracer, getTelemetryClient } from '@aztec/telemetry-client'; import { type Chain, @@ -113,7 +112,7 @@ export class SlasherClient extends WithTracer { private config: SlasherConfig & L1ContractsConfig & L1ReaderConfig, private store: AztecKVStore, private l2BlockSource: L2BlockSource, - telemetry: TelemetryClient = new NoopTelemetryClient(), + telemetry: TelemetryClient = getTelemetryClient(), private log = createLogger('slasher'), ) { super(telemetry, 'slasher'); diff --git a/yarn-project/simulator/src/avm/avm_simulator.test.ts b/yarn-project/simulator/src/avm/avm_simulator.test.ts index d6fff38670fc..447b5bcce135 100644 --- a/yarn-project/simulator/src/avm/avm_simulator.test.ts +++ b/yarn-project/simulator/src/avm/avm_simulator.test.ts @@ -23,7 +23,7 @@ import { keccak256, keccakf1600, pedersenCommit, pedersenHash, poseidon2Hash, sh import { Fq, Fr, Point } from '@aztec/foundation/fields'; import { type Fieldable } from '@aztec/foundation/serialize'; import { openTmpStore } from '@aztec/kv-store/lmdb'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; +import { getTelemetryClient } from '@aztec/telemetry-client'; import { MerkleTrees } from '@aztec/world-state'; import { randomInt } from 'crypto'; @@ -1119,7 +1119,7 @@ describe('AVM simulator: transpiled Noir contracts', () => { worldStateDB = mock(); const tmp = openTmpStore(); - const telemetryClient = new NoopTelemetryClient(); + const telemetryClient = getTelemetryClient(); merkleTrees = await (await MerkleTrees.new(tmp, telemetryClient)).fork(); (worldStateDB as jest.Mocked).getMerkleInterface.mockReturnValue(merkleTrees); ephemeralForest = await AvmEphemeralForest.create(worldStateDB.getMerkleInterface()); diff --git a/yarn-project/simulator/src/avm/avm_tree.test.ts b/yarn-project/simulator/src/avm/avm_tree.test.ts index 31c8c015e2a5..85b30629e13e 100644 --- a/yarn-project/simulator/src/avm/avm_tree.test.ts +++ b/yarn-project/simulator/src/avm/avm_tree.test.ts @@ -17,7 +17,7 @@ import { poseidon2Hash } from '@aztec/foundation/crypto'; import { Fr } from '@aztec/foundation/fields'; import { type IndexedTreeLeafPreimage } from '@aztec/foundation/trees'; import { openTmpStore } from '@aztec/kv-store/lmdb'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; +import { getTelemetryClient } from '@aztec/telemetry-client'; import { MerkleTrees, NativeWorldStateService } from '@aztec/world-state'; import { @@ -528,7 +528,7 @@ describe('Checking forking and merging', () => { describe('AVM Ephemeral Tree Sanity Test', () => { it('Should calculate the frontier correctly', async () => { const store = openTmpStore(true); - const worldStateTrees = await MerkleTrees.new(store, new NoopTelemetryClient()); + const worldStateTrees = await MerkleTrees.new(store, getTelemetryClient()); const leaves = []; const numLeaves = 6; for (let i = 0; i < numLeaves; i++) { diff --git a/yarn-project/simulator/src/public/fixtures/index.ts b/yarn-project/simulator/src/public/fixtures/index.ts index 17cca0600ce9..c13db7c4498e 100644 --- a/yarn-project/simulator/src/public/fixtures/index.ts +++ b/yarn-project/simulator/src/public/fixtures/index.ts @@ -39,7 +39,6 @@ import { PublicTxSimulator, WorldStateDB, } from '@aztec/simulator'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; import { MerkleTrees } from '@aztec/world-state'; import { strict as assert } from 'assert'; @@ -58,17 +57,11 @@ export async function simulateAvmTestContractGenerateCircuitInputs( const globals = GlobalVariables.empty(); globals.timestamp = TIMESTAMP; - const merkleTrees = await (await MerkleTrees.new(openTmpStore(), new NoopTelemetryClient())).fork(); + const merkleTrees = await (await MerkleTrees.new(openTmpStore())).fork(); await contractDataSource.deployContracts(merkleTrees); const worldStateDB = new WorldStateDB(merkleTrees, contractDataSource); - const simulator = new PublicTxSimulator( - merkleTrees, - worldStateDB, - new NoopTelemetryClient(), - globals, - /*doMerkleOperations=*/ true, - ); + const simulator = new PublicTxSimulator(merkleTrees, worldStateDB, globals, /*doMerkleOperations=*/ true); const sender = AztecAddress.random(); const functionSelector = getAvmTestContractFunctionSelector(functionName); @@ -109,7 +102,7 @@ export async function simulateAvmTestContractCall( const globals = GlobalVariables.empty(); globals.timestamp = TIMESTAMP; - const merkleTrees = await (await MerkleTrees.new(openTmpStore(), new NoopTelemetryClient())).fork(); + const merkleTrees = await (await MerkleTrees.new(openTmpStore())).fork(); await contractDataSource.deployContracts(merkleTrees); const worldStateDB = new WorldStateDB(merkleTrees, contractDataSource); diff --git a/yarn-project/simulator/src/public/public_processor.test.ts b/yarn-project/simulator/src/public/public_processor.test.ts index b2696cb860c7..aea53976bf4d 100644 --- a/yarn-project/simulator/src/public/public_processor.test.ts +++ b/yarn-project/simulator/src/public/public_processor.test.ts @@ -23,7 +23,7 @@ import { computePublicDataTreeLeafSlot } from '@aztec/circuits.js/hash'; import { times } from '@aztec/foundation/collection'; import { sleep } from '@aztec/foundation/sleep'; import { TestDateProvider } from '@aztec/foundation/timer'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; +import { getTelemetryClient } from '@aztec/telemetry-client'; import { type MockProxy, mock } from 'jest-mock-extended'; @@ -88,7 +88,7 @@ describe('public_processor', () => { worldStateDB, publicTxSimulator, new TestDateProvider(), - new NoopTelemetryClient(), + getTelemetryClient(), ); }); diff --git a/yarn-project/simulator/src/public/public_processor.ts b/yarn-project/simulator/src/public/public_processor.ts index b67d187cdaa8..920337c5299f 100644 --- a/yarn-project/simulator/src/public/public_processor.ts +++ b/yarn-project/simulator/src/public/public_processor.ts @@ -27,7 +27,14 @@ import { createLogger } from '@aztec/foundation/log'; import { type DateProvider, Timer, elapsed, executeTimeout } from '@aztec/foundation/timer'; import { ProtocolContractAddress } from '@aztec/protocol-contracts'; import { ContractClassRegisteredEvent } from '@aztec/protocol-contracts/class-registerer'; -import { Attributes, type TelemetryClient, type Traceable, type Tracer, trackSpan } from '@aztec/telemetry-client'; +import { + Attributes, + type TelemetryClient, + type Traceable, + type Tracer, + getTelemetryClient, + trackSpan, +} from '@aztec/telemetry-client'; import { computeFeePayerBalanceLeafSlot, computeFeePayerBalanceStorageSlot } from './fee_payment.js'; import { WorldStateDB } from './public_db_sources.js'; @@ -41,7 +48,7 @@ export class PublicProcessorFactory { constructor( private contractDataSource: ContractDataSource, private dateProvider: DateProvider, - private telemetryClient: TelemetryClient, + private telemetryClient: TelemetryClient = getTelemetryClient(), ) {} /** @@ -63,10 +70,10 @@ export class PublicProcessorFactory { const publicTxSimulator = this.createPublicTxSimulator( merkleTree, worldStateDB, - this.telemetryClient, globalVariables, /*doMerkleOperations=*/ true, enforceFeePayment, + this.telemetryClient, ); return new PublicProcessor( @@ -83,18 +90,18 @@ export class PublicProcessorFactory { protected createPublicTxSimulator( db: MerkleTreeWriteOperations, worldStateDB: WorldStateDB, - telemetryClient: TelemetryClient, globalVariables: GlobalVariables, doMerkleOperations: boolean, enforceFeePayment: boolean, + telemetryClient: TelemetryClient, ) { return new PublicTxSimulator( db, worldStateDB, - telemetryClient, globalVariables, doMerkleOperations, enforceFeePayment, + telemetryClient, ); } } @@ -119,7 +126,7 @@ export class PublicProcessor implements Traceable { protected worldStateDB: WorldStateDB, protected publicTxSimulator: PublicTxSimulator, private dateProvider: DateProvider, - telemetryClient: TelemetryClient, + telemetryClient: TelemetryClient = getTelemetryClient(), private log = createLogger('simulator:public-processor'), ) { this.metrics = new PublicProcessorMetrics(telemetryClient, 'PublicProcessor'); diff --git a/yarn-project/simulator/src/public/public_tx_simulator.test.ts b/yarn-project/simulator/src/public/public_tx_simulator.test.ts index 3029c1b1ee28..393a47a1568d 100644 --- a/yarn-project/simulator/src/public/public_tx_simulator.test.ts +++ b/yarn-project/simulator/src/public/public_tx_simulator.test.ts @@ -30,7 +30,6 @@ import { type AztecKVStore } from '@aztec/kv-store'; import { openTmpStore } from '@aztec/kv-store/lmdb'; import { type AppendOnlyTree, Poseidon, StandardTree, newTree } from '@aztec/merkle-tree'; import { ProtocolContractAddress } from '@aztec/protocol-contracts'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; import { MerkleTrees } from '@aztec/world-state'; import { jest } from '@jest/globals'; @@ -209,7 +208,6 @@ describe('public_tx_simulator', () => { const simulator = new PublicTxSimulator( db, worldStateDB, - new NoopTelemetryClient(), GlobalVariables.from({ ...GlobalVariables.empty(), gasFees }), doMerkleOperations, enforceFeePayment, @@ -243,8 +241,7 @@ describe('public_tx_simulator', () => { beforeEach(async () => { const tmp = openTmpStore(); - const telemetryClient = new NoopTelemetryClient(); - db = await (await MerkleTrees.new(tmp, telemetryClient)).fork(); + db = await (await MerkleTrees.new(tmp)).fork(); worldStateDB = new WorldStateDB(db, mock()); treeStore = openTmpStore(); diff --git a/yarn-project/simulator/src/public/public_tx_simulator.ts b/yarn-project/simulator/src/public/public_tx_simulator.ts index e973d28f654e..250601542843 100644 --- a/yarn-project/simulator/src/public/public_tx_simulator.ts +++ b/yarn-project/simulator/src/public/public_tx_simulator.ts @@ -14,7 +14,7 @@ import { type Fr, type Gas, type GlobalVariables, type PublicCallRequest, type R import { type Logger, createLogger } from '@aztec/foundation/log'; import { Timer } from '@aztec/foundation/timer'; import { ProtocolContractAddress } from '@aztec/protocol-contracts'; -import { Attributes, type TelemetryClient, type Tracer, trackSpan } from '@aztec/telemetry-client'; +import { Attributes, type TelemetryClient, type Tracer, getTelemetryClient, trackSpan } from '@aztec/telemetry-client'; import { strict as assert } from 'assert'; @@ -53,10 +53,10 @@ export class PublicTxSimulator { constructor( private db: MerkleTreeReadOperations, private worldStateDB: WorldStateDB, - telemetryClient: TelemetryClient, private globalVariables: GlobalVariables, private doMerkleOperations: boolean = false, private enforceFeePayment: boolean = true, + telemetryClient: TelemetryClient = getTelemetryClient(), ) { this.log = createLogger(`simulator:public_tx_simulator`); this.metrics = new ExecutorMetrics(telemetryClient, 'PublicTxSimulator'); diff --git a/yarn-project/telemetry-client/package.json b/yarn-project/telemetry-client/package.json index 7face42b10c4..a17e04f61c94 100644 --- a/yarn-project/telemetry-client/package.json +++ b/yarn-project/telemetry-client/package.json @@ -6,8 +6,6 @@ "type": "module", "exports": { ".": "./dest/index.js", - "./start": "./dest/start.js", - "./noop": "./dest/noop.js", "./otel-pino-stream": "./dest/vendor/otel-pino-stream.js" }, "scripts": { @@ -37,7 +35,7 @@ "@opentelemetry/exporter-trace-otlp-http": "^0.55.0", "@opentelemetry/host-metrics": "^0.35.4", "@opentelemetry/otlp-exporter-base": "^0.55.0", - "@opentelemetry/resource-detector-aws": "^1.8.0", + "@opentelemetry/resource-detector-gcp": "^0.32.0", "@opentelemetry/resources": "^1.28.0", "@opentelemetry/sdk-logs": "^0.55.0", "@opentelemetry/sdk-metrics": "^1.28.0", diff --git a/yarn-project/telemetry-client/src/attributes.ts b/yarn-project/telemetry-client/src/attributes.ts index 6fa7d7c32677..56b1105052b7 100644 --- a/yarn-project/telemetry-client/src/attributes.ts +++ b/yarn-project/telemetry-client/src/attributes.ts @@ -105,3 +105,5 @@ export const REVERTIBILITY = 'aztec.revertibility'; export const GAS_DIMENSION = 'aztec.gas_dimension'; export const WORLD_STATE_REQUEST_TYPE = 'aztec.world_state_request'; + +export const NODEJS_EVENT_LOOP_STATE = 'nodejs.eventloop.state'; diff --git a/yarn-project/telemetry-client/src/aztec_resource_detector.ts b/yarn-project/telemetry-client/src/aztec_resource_detector.ts index bb438dd49a91..a16ee9ca1ec7 100644 --- a/yarn-project/telemetry-client/src/aztec_resource_detector.ts +++ b/yarn-project/telemetry-client/src/aztec_resource_detector.ts @@ -1,7 +1,10 @@ import { type DetectorSync, type IResource, Resource } from '@opentelemetry/resources'; -import { ATTR_K8S_POD_NAME, ATTR_K8S_POD_UID } from '@opentelemetry/semantic-conventions/incubating'; +import { + ATTR_K8S_POD_NAME, + ATTR_K8S_POD_UID, + ATTR_SERVICE_INSTANCE_ID, +} from '@opentelemetry/semantic-conventions/incubating'; -import { NETWORK_NAME } from './attributes.js'; import { getConfigEnvVars } from './config.js'; /** @@ -12,9 +15,10 @@ class AztecDetector implements DetectorSync { const config = getConfigEnvVars(); return new Resource({ - [NETWORK_NAME]: config.networkName, [ATTR_K8S_POD_UID]: config.k8sPodUid, [ATTR_K8S_POD_NAME]: config.k8sPodName, + // this will get set by serviceInstanceIdDetector if not running in K8s + [ATTR_SERVICE_INSTANCE_ID]: config.k8sPodUid, }); } } diff --git a/yarn-project/telemetry-client/src/event_loop_monitor.ts b/yarn-project/telemetry-client/src/event_loop_monitor.ts index ee6f6a68b6c9..384a023712b7 100644 --- a/yarn-project/telemetry-client/src/event_loop_monitor.ts +++ b/yarn-project/telemetry-client/src/event_loop_monitor.ts @@ -1,49 +1,118 @@ -import { promiseWithResolvers } from '@aztec/foundation/promise'; -import { Timer } from '@aztec/foundation/timer'; +import { type EventLoopUtilization, type IntervalHistogram, monitorEventLoopDelay, performance } from 'node:perf_hooks'; -import { EVENT_LOOP_LAG } from './metrics.js'; -import { type Meter, type ObservableGauge, type ObservableResult, ValueType } from './telemetry.js'; +import { NODEJS_EVENT_LOOP_STATE } from './attributes.js'; +import * as Metrics from './metrics.js'; +import { + type BatchObservableResult, + type Meter, + type ObservableGauge, + type UpDownCounter, + ValueType, +} from './telemetry.js'; /** * Detector for custom Aztec attributes */ export class EventLoopMonitor { - private eventLoopLag: ObservableGauge; + private eventLoopDelayGauges: { + min: ObservableGauge; + max: ObservableGauge; + mean: ObservableGauge; + stddev: ObservableGauge; + p50: ObservableGauge; + p90: ObservableGauge; + p99: ObservableGauge; + }; + + private eventLoopUilization: ObservableGauge; + private eventLoopTime: UpDownCounter; + private started = false; - constructor(meter: Meter) { - this.eventLoopLag = meter.createObservableGauge(EVENT_LOOP_LAG, { - unit: 'us', + private lastELU: EventLoopUtilization | undefined; + private eventLoopDelay: IntervalHistogram; + + constructor(private meter: Meter) { + const nsObsGauge = (name: (typeof Metrics)[keyof typeof Metrics], description: string) => + meter.createObservableGauge(name, { + unit: 'ns', + valueType: ValueType.INT, + description, + }); + + this.eventLoopDelayGauges = { + min: nsObsGauge(Metrics.NODEJS_EVENT_LOOP_DELAY_MIN, 'Minimum delay of the event loop'), + mean: nsObsGauge(Metrics.NODEJS_EVENT_LOOP_DELAY_MEAN, 'Mean delay of the event loop'), + max: nsObsGauge(Metrics.NODEJS_EVENT_LOOP_DELAY_MAX, 'Max delay of the event loop'), + stddev: nsObsGauge(Metrics.NODEJS_EVENT_LOOP_DELAY_STDDEV, 'Stddev delay of the event loop'), + p50: nsObsGauge(Metrics.NODEJS_EVENT_LOOP_DELAY_P50, 'P50 delay of the event loop'), + p90: nsObsGauge(Metrics.NODEJS_EVENT_LOOP_DELAY_P90, 'P90 delay of the event loop'), + p99: nsObsGauge(Metrics.NODEJS_EVENT_LOOP_DELAY_P99, 'P99 delay of the event loop'), + }; + + this.eventLoopUilization = meter.createObservableGauge(Metrics.NODEJS_EVENT_LOOP_UTILIZATION, { + valueType: ValueType.DOUBLE, + description: 'How busy is the event loop', + }); + + this.eventLoopTime = meter.createUpDownCounter(Metrics.NODEJS_EVENT_LOOP_TIME, { + unit: 'ms', valueType: ValueType.INT, description: 'How busy is the event loop', }); + + this.eventLoopDelay = monitorEventLoopDelay(); } start(): void { if (this.started) { return; } - this.eventLoopLag.addCallback(this.measureLag); + + this.lastELU = performance.eventLoopUtilization(); + this.meter.addBatchObservableCallback(this.measure, [ + this.eventLoopUilization, + ...Object.values(this.eventLoopDelayGauges), + ]); + this.eventLoopDelay.enable(); } stop(): void { if (!this.started) { return; } - this.eventLoopLag.removeCallback(this.measureLag); + this.meter.removeBatchObservableCallback(this.measure, [ + this.eventLoopUilization, + ...Object.values(this.eventLoopDelayGauges), + ]); + this.eventLoopDelay.disable(); + this.eventLoopDelay.reset(); } - private measureLag = async (obs: ObservableResult): Promise => { - const timer = new Timer(); - const { promise, resolve } = promiseWithResolvers(); - // how long does it take to schedule the next macro task? - // if this number spikes then we're (1) either blocking the event loop with long running sync code - // or (2) spamming the event loop with micro tasks - setImmediate(() => { - resolve(timer.us()); - }); + private measure = (obs: BatchObservableResult): void => { + const newELU = performance.eventLoopUtilization(); + const delta = performance.eventLoopUtilization(newELU, this.lastELU); + this.lastELU = newELU; + + // `utilization` [0,1] represents how much the event loop is busy vs waiting for new events to come in + // This should be corelated with CPU usage to gauge the performance characteristics of services + // 100% utilization leads to high latency because the event loop is _always_ busy, there's no breathing room for events to be processed quickly. + // Docs and examples: + // - https://nodesource.com/blog/event-loop-utilization-nodejs + // - https://youtu.be/WetXnEPraYM + obs.observe(this.eventLoopUilization, delta.utilization); + + this.eventLoopTime.add(Math.floor(delta.idle), { [NODEJS_EVENT_LOOP_STATE]: 'idle' }); + this.eventLoopTime.add(Math.floor(delta.active), { [NODEJS_EVENT_LOOP_STATE]: 'active' }); + + obs.observe(this.eventLoopDelayGauges.min, Math.floor(this.eventLoopDelay.min)); + obs.observe(this.eventLoopDelayGauges.mean, Math.floor(this.eventLoopDelay.mean)); + obs.observe(this.eventLoopDelayGauges.max, Math.floor(this.eventLoopDelay.max)); + obs.observe(this.eventLoopDelayGauges.stddev, Math.floor(this.eventLoopDelay.stddev)); + obs.observe(this.eventLoopDelayGauges.p50, Math.floor(this.eventLoopDelay.percentile(50))); + obs.observe(this.eventLoopDelayGauges.p90, Math.floor(this.eventLoopDelay.percentile(90))); + obs.observe(this.eventLoopDelayGauges.p99, Math.floor(this.eventLoopDelay.percentile(99))); - const lag = await promise; - obs.observe(Math.floor(lag)); + this.eventLoopDelay.reset(); }; } diff --git a/yarn-project/telemetry-client/src/index.ts b/yarn-project/telemetry-client/src/index.ts index acd6b5363b49..e593b4575f47 100644 --- a/yarn-project/telemetry-client/src/index.ts +++ b/yarn-project/telemetry-client/src/index.ts @@ -4,3 +4,4 @@ export * from './with_tracer.js'; export * from './prom_otel_adapter.js'; export * from './lmdb_metrics.js'; export * from './wrappers/index.js'; +export * from './start.js'; diff --git a/yarn-project/telemetry-client/src/metrics.ts b/yarn-project/telemetry-client/src/metrics.ts index 1561d4a9b606..657bd7e0c043 100644 --- a/yarn-project/telemetry-client/src/metrics.ts +++ b/yarn-project/telemetry-client/src/metrics.ts @@ -126,4 +126,13 @@ export const PROOF_VERIFIER_COUNT = 'aztec.proof_verifier.count'; export const VALIDATOR_RE_EXECUTION_TIME = 'aztec.validator.re_execution_time'; export const VALIDATOR_FAILED_REEXECUTION_COUNT = 'aztec.validator.failed_reexecution_count'; -export const EVENT_LOOP_LAG = 'aztec.event_loop_lag'; +export const NODEJS_EVENT_LOOP_DELAY_MIN = 'nodejs.eventloop.delay.min'; +export const NODEJS_EVENT_LOOP_DELAY_MEAN = 'nodejs.eventloop.delay.mean'; +export const NODEJS_EVENT_LOOP_DELAY_MAX = 'nodejs.eventloop.delay.max'; +export const NODEJS_EVENT_LOOP_DELAY_STDDEV = 'nodejs.eventloop.delay.stddev'; +export const NODEJS_EVENT_LOOP_DELAY_P50 = 'nodejs.eventloop.delay.p50'; +export const NODEJS_EVENT_LOOP_DELAY_P90 = 'nodejs.eventloop.delay.p90'; +export const NODEJS_EVENT_LOOP_DELAY_P99 = 'nodejs.eventloop.delay.p99'; + +export const NODEJS_EVENT_LOOP_UTILIZATION = 'nodejs.eventloop.utilization'; +export const NODEJS_EVENT_LOOP_TIME = 'nodejs.eventloop.time'; diff --git a/yarn-project/telemetry-client/src/otel_resource.ts b/yarn-project/telemetry-client/src/otel_resource.ts index d0a8ec7677c2..83b14383b512 100644 --- a/yarn-project/telemetry-client/src/otel_resource.ts +++ b/yarn-project/telemetry-client/src/otel_resource.ts @@ -1,3 +1,4 @@ +import { gcpDetector } from '@opentelemetry/resource-detector-gcp'; import { type IResource, detectResourcesSync, @@ -11,7 +12,14 @@ import { aztecDetector } from './aztec_resource_detector.js'; export async function getOtelResource(): Promise { const resource = detectResourcesSync({ - detectors: [osDetectorSync, envDetectorSync, processDetectorSync, serviceInstanceIdDetectorSync, aztecDetector], + detectors: [ + osDetectorSync, + envDetectorSync, + processDetectorSync, + serviceInstanceIdDetectorSync, + gcpDetector, + aztecDetector, + ], }); if (resource.asyncAttributesPending) { diff --git a/yarn-project/telemetry-client/src/start.ts b/yarn-project/telemetry-client/src/start.ts index d33866c6c1b5..661fa6c6420a 100644 --- a/yarn-project/telemetry-client/src/start.ts +++ b/yarn-project/telemetry-client/src/start.ts @@ -7,13 +7,27 @@ import { type TelemetryClient } from './telemetry.js'; export * from './config.js'; -export async function createAndStartTelemetryClient(config: TelemetryClientConfig): Promise { +let initialised = false; +let telemetry: TelemetryClient = new NoopTelemetryClient(); + +export async function initTelemetryClient(config: TelemetryClientConfig): Promise { const log = createLogger('telemetry:client'); + if (initialised) { + log.warn('Telemetry client has already been initialized once'); + return telemetry; + } + + initialised = true; if (config.metricsCollectorUrl) { log.info('Using OpenTelemetry client'); - return await OpenTelemetryClient.createAndStart(config, log); + telemetry = await OpenTelemetryClient.createAndStart(config, log); } else { log.info('Using NoopTelemetryClient'); - return new NoopTelemetryClient(); } + + return telemetry; +} + +export function getTelemetryClient(): TelemetryClient { + return telemetry; } diff --git a/yarn-project/telemetry-client/src/telemetry.ts b/yarn-project/telemetry-client/src/telemetry.ts index 9fb8497fb212..1d2118a374dc 100644 --- a/yarn-project/telemetry-client/src/telemetry.ts +++ b/yarn-project/telemetry-client/src/telemetry.ts @@ -14,11 +14,13 @@ import { SpanStatusCode, Tracer, } from '@opentelemetry/api'; +import { isPromise } from 'node:util/types'; import * as Attributes from './attributes.js'; import * as Metrics from './metrics.js'; +import { getTelemetryClient } from './start.js'; -export { Span, ValueType } from '@opentelemetry/api'; +export { Span, SpanStatusCode, ValueType } from '@opentelemetry/api'; type ValuesOf = T extends Record ? U : never; @@ -221,3 +223,45 @@ export function wrapCallbackInSpan any>( } }) as F; } + +export function runInSpan( + tracer: Tracer | string, + spanName: string, + callback: (span: Span, ...args: A) => R, +): (...args: A) => R { + return (...args: A): R => { + const actualTracer = typeof tracer === 'string' ? getTelemetryClient().getTracer(tracer) : tracer; + return actualTracer.startActiveSpan(spanName, (span: Span): R => { + let deferSpanEnd = false; + try { + const res = callback(span, ...args); + if (isPromise(res)) { + deferSpanEnd = true; + return res + .catch(err => { + span.setStatus({ + code: SpanStatusCode.ERROR, + message: String(err), + }); + throw err; + }) + .finally(() => { + span.end(); + }) as R; + } else { + return res; + } + } catch (err) { + span.setStatus({ + code: SpanStatusCode.ERROR, + message: String(err), + }); + throw err; + } finally { + if (!deferSpanEnd) { + span.end(); + } + } + }); + }; +} diff --git a/yarn-project/txe/src/oracle/txe_oracle.ts b/yarn-project/txe/src/oracle/txe_oracle.ts index 07965dbce20e..5c6d74754926 100644 --- a/yarn-project/txe/src/oracle/txe_oracle.ts +++ b/yarn-project/txe/src/oracle/txe_oracle.ts @@ -82,7 +82,6 @@ import { witnessMapToFields, } from '@aztec/simulator'; import { createTxForPublicCall } from '@aztec/simulator/public/fixtures'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; import { MerkleTreeSnapshotOperationsFacade, type MerkleTrees } from '@aztec/world-state'; import { TXENode } from '../node/txe_node.js'; @@ -833,7 +832,6 @@ export class TXE implements TypedOracle { const simulator = new PublicTxSimulator( db, new TXEWorldStateDB(db, new TXEPublicContractDataSource(this)), - new NoopTelemetryClient(), globalVariables, ); diff --git a/yarn-project/txe/src/txe_service/txe_service.ts b/yarn-project/txe/src/txe_service/txe_service.ts index e0b46aa45b52..2f3d234ed191 100644 --- a/yarn-project/txe/src/txe_service/txe_service.ts +++ b/yarn-project/txe/src/txe_service/txe_service.ts @@ -19,7 +19,7 @@ import { protocolContractNames } from '@aztec/protocol-contracts'; import { getCanonicalProtocolContract } from '@aztec/protocol-contracts/bundle'; import { enrichPublicSimulationError } from '@aztec/pxe'; import { ExecutionNoteCache, PackedValuesCache, type TypedOracle } from '@aztec/simulator'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; +import { getTelemetryClient } from '@aztec/telemetry-client'; import { MerkleTrees } from '@aztec/world-state'; import { TXE } from '../oracle/txe_oracle.js'; @@ -41,7 +41,7 @@ export class TXEService { static async init(logger: Logger) { const store = openTmpStore(true); - const trees = await MerkleTrees.new(store, new NoopTelemetryClient(), logger); + const trees = await MerkleTrees.new(store, getTelemetryClient(), logger); const packedValuesCache = new PackedValuesCache(); const txHash = new Fr(1); // The txHash is used for computing the revertible nullifiers for non-revertible note hashes. It can be any value for testing. const noteCache = new ExecutionNoteCache(txHash); diff --git a/yarn-project/validator-client/src/validator.test.ts b/yarn-project/validator-client/src/validator.test.ts index 7b6fdca5a264..f9798cd402b1 100644 --- a/yarn-project/validator-client/src/validator.test.ts +++ b/yarn-project/validator-client/src/validator.test.ts @@ -8,7 +8,7 @@ import { Secp256k1Signer } from '@aztec/foundation/crypto'; import { EthAddress } from '@aztec/foundation/eth-address'; import { Fr } from '@aztec/foundation/fields'; import { type P2P } from '@aztec/p2p'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; +import { getTelemetryClient } from '@aztec/telemetry-client'; import { describe, expect, it } from '@jest/globals'; import { type MockProxy, mock } from 'jest-mock-extended'; @@ -46,12 +46,12 @@ describe('ValidationService', () => { disableValidator: false, validatorReexecute: false, }; - validatorClient = ValidatorClient.new(config, epochCache, p2pClient, new NoopTelemetryClient()); + validatorClient = ValidatorClient.new(config, epochCache, p2pClient, getTelemetryClient()); }); it('Should throw error if an invalid private key is provided', () => { config.validatorPrivateKey = '0x1234567890123456789'; - expect(() => ValidatorClient.new(config, epochCache, p2pClient, new NoopTelemetryClient())).toThrow( + expect(() => ValidatorClient.new(config, epochCache, p2pClient, getTelemetryClient())).toThrow( InvalidValidatorPrivateKeyError, ); }); diff --git a/yarn-project/validator-client/src/validator.ts b/yarn-project/validator-client/src/validator.ts index 09c19eac82b5..d11741952619 100644 --- a/yarn-project/validator-client/src/validator.ts +++ b/yarn-project/validator-client/src/validator.ts @@ -9,8 +9,7 @@ import { sleep } from '@aztec/foundation/sleep'; import { type Timer } from '@aztec/foundation/timer'; import { type P2P } from '@aztec/p2p'; import { BlockProposalValidator } from '@aztec/p2p/msg_validators'; -import { type TelemetryClient, WithTracer } from '@aztec/telemetry-client'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; +import { type TelemetryClient, WithTracer, getTelemetryClient } from '@aztec/telemetry-client'; import { type ValidatorClientConfig } from './config.js'; import { ValidationService } from './duties/validation_service.js'; @@ -72,7 +71,7 @@ export class ValidatorClient extends WithTracer implements Validator { private epochCache: EpochCache, private p2pClient: P2P, private config: ValidatorClientConfig, - telemetry: TelemetryClient = new NoopTelemetryClient(), + telemetry: TelemetryClient = getTelemetryClient(), private log = createLogger('validator'), ) { // Instantiate tracer @@ -111,7 +110,7 @@ export class ValidatorClient extends WithTracer implements Validator { config: ValidatorClientConfig, epochCache: EpochCache, p2pClient: P2P, - telemetry: TelemetryClient = new NoopTelemetryClient(), + telemetry: TelemetryClient = getTelemetryClient(), ) { if (!config.validatorPrivateKey) { throw new InvalidValidatorPrivateKeyError(); diff --git a/yarn-project/world-state/src/native/native_world_state.ts b/yarn-project/world-state/src/native/native_world_state.ts index 0d5d305b8b13..00cac321c79a 100644 --- a/yarn-project/world-state/src/native/native_world_state.ts +++ b/yarn-project/world-state/src/native/native_world_state.ts @@ -20,7 +20,7 @@ import { } from '@aztec/circuits.js'; import { padArrayEnd } from '@aztec/foundation/collection'; import { createLogger } from '@aztec/foundation/log'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; +import { getTelemetryClient } from '@aztec/telemetry-client'; import assert from 'assert/strict'; import { mkdir, mkdtemp, rm } from 'fs/promises'; @@ -68,7 +68,7 @@ export class NativeWorldStateService implements MerkleTreeDatabase { rollupAddress: EthAddress, dataDir: string, dbMapSizeKb: number, - instrumentation = new WorldStateInstrumentation(new NoopTelemetryClient()), + instrumentation = new WorldStateInstrumentation(getTelemetryClient()), log = createLogger('world-state:database'), cleanup = () => Promise.resolve(), ): Promise { @@ -107,7 +107,7 @@ export class NativeWorldStateService implements MerkleTreeDatabase { static async tmp( rollupAddress = EthAddress.ZERO, cleanupTmpDir = true, - instrumentation = new WorldStateInstrumentation(new NoopTelemetryClient()), + instrumentation = new WorldStateInstrumentation(getTelemetryClient()), ): Promise { const log = createLogger('world-state:database'); const dataDir = await mkdtemp(join(tmpdir(), 'aztec-world-state-')); diff --git a/yarn-project/world-state/src/native/native_world_state_cmp.test.ts b/yarn-project/world-state/src/native/native_world_state_cmp.test.ts index 356238204612..676d184fa609 100644 --- a/yarn-project/world-state/src/native/native_world_state_cmp.test.ts +++ b/yarn-project/world-state/src/native/native_world_state_cmp.test.ts @@ -10,7 +10,7 @@ import { type Logger, createLogger } from '@aztec/foundation/log'; import { elapsed } from '@aztec/foundation/timer'; import { type AztecKVStore } from '@aztec/kv-store'; import { AztecLmdbStore } from '@aztec/kv-store/lmdb'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; +import { getTelemetryClient } from '@aztec/telemetry-client'; import { jest } from '@jest/globals'; import { mkdtemp, rm } from 'fs/promises'; @@ -53,7 +53,7 @@ describe('NativeWorldState', () => { beforeAll(async () => { legacyStore = AztecLmdbStore.open(legacyDataDir); nativeWS = await NativeWorldStateService.new(EthAddress.random(), nativeDataDir, 1024 * 1024); - legacyWS = await MerkleTrees.new(legacyStore, new NoopTelemetryClient()); + legacyWS = await MerkleTrees.new(legacyStore, getTelemetryClient()); }); it('has to expected genesis archive tree root', async () => { diff --git a/yarn-project/world-state/src/synchronizer/factory.ts b/yarn-project/world-state/src/synchronizer/factory.ts index 690fcd03ce2d..cd0b2e3c5598 100644 --- a/yarn-project/world-state/src/synchronizer/factory.ts +++ b/yarn-project/world-state/src/synchronizer/factory.ts @@ -1,6 +1,6 @@ import { type L1ToL2MessageSource, type L2BlockSource } from '@aztec/circuit-types'; import { type DataStoreConfig } from '@aztec/kv-store/config'; -import { type TelemetryClient } from '@aztec/telemetry-client'; +import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client'; import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js'; import { NativeWorldStateService } from '../native/native_world_state.js'; @@ -10,7 +10,7 @@ import { ServerWorldStateSynchronizer } from './server_world_state_synchronizer. export async function createWorldStateSynchronizer( config: WorldStateConfig & DataStoreConfig, l2BlockSource: L2BlockSource & L1ToL2MessageSource, - client: TelemetryClient, + client: TelemetryClient = getTelemetryClient(), ) { const instrumentation = new WorldStateInstrumentation(client); const merkleTrees = await createWorldState(config, instrumentation); diff --git a/yarn-project/world-state/src/synchronizer/server_world_state_synchronizer.ts b/yarn-project/world-state/src/synchronizer/server_world_state_synchronizer.ts index b0d590c3b2a7..ff631287a65b 100644 --- a/yarn-project/world-state/src/synchronizer/server_world_state_synchronizer.ts +++ b/yarn-project/world-state/src/synchronizer/server_world_state_synchronizer.ts @@ -23,8 +23,7 @@ import { createLogger } from '@aztec/foundation/log'; import { promiseWithResolvers } from '@aztec/foundation/promise'; import { elapsed } from '@aztec/foundation/timer'; import { SHA256Trunc } from '@aztec/merkle-tree'; -import { TraceableL2BlockStream } from '@aztec/telemetry-client'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; +import { TraceableL2BlockStream, getTelemetryClient } from '@aztec/telemetry-client'; import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js'; import { type WorldStateStatusFull } from '../native/message.js'; @@ -53,7 +52,7 @@ export class ServerWorldStateSynchronizer private readonly merkleTreeDb: MerkleTreeAdminDatabase, private readonly l2BlockSource: L2BlockSource & L1ToL2MessageSource, private readonly config: WorldStateConfig, - private instrumentation = new WorldStateInstrumentation(new NoopTelemetryClient()), + private instrumentation = new WorldStateInstrumentation(getTelemetryClient()), private readonly log = createLogger('world_state'), ) { this.merkleTreeCommitted = this.merkleTreeDb.getCommitted(); diff --git a/yarn-project/world-state/src/test/integration.test.ts b/yarn-project/world-state/src/test/integration.test.ts index daa105e78516..1f60c0bafafa 100644 --- a/yarn-project/world-state/src/test/integration.test.ts +++ b/yarn-project/world-state/src/test/integration.test.ts @@ -4,7 +4,7 @@ import { EthAddress, type Fr } from '@aztec/circuits.js'; import { type Logger, createLogger } from '@aztec/foundation/log'; import { sleep } from '@aztec/foundation/sleep'; import { type DataStoreConfig } from '@aztec/kv-store/config'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; +import { getTelemetryClient } from '@aztec/telemetry-client'; import { jest } from '@jest/globals'; @@ -55,13 +55,13 @@ describe('world-state integration', () => { db = (await createWorldState( config, - new WorldStateInstrumentation(new NoopTelemetryClient()), + new WorldStateInstrumentation(getTelemetryClient()), )) as NativeWorldStateService; synchronizer = new TestWorldStateSynchronizer( db, archiver, config, - new WorldStateInstrumentation(new NoopTelemetryClient()), + new WorldStateInstrumentation(getTelemetryClient()), ); log.info(`Created synchronizer`); }, 30_000); @@ -159,7 +159,7 @@ describe('world-state integration', () => { db, archiver, config, - new WorldStateInstrumentation(new NoopTelemetryClient()), + new WorldStateInstrumentation(getTelemetryClient()), ); archiver.createBlocks(3); @@ -181,7 +181,7 @@ describe('world-state integration', () => { db, archiver, { ...config, worldStateProvenBlocksOnly: true }, - new WorldStateInstrumentation(new NoopTelemetryClient()), + new WorldStateInstrumentation(getTelemetryClient()), ); archiver.createBlocks(5); @@ -220,7 +220,7 @@ describe('world-state integration', () => { db, archiver, { ...config, worldStateBlockCheckIntervalMS: 1000 }, - new WorldStateInstrumentation(new NoopTelemetryClient()), + new WorldStateInstrumentation(getTelemetryClient()), ); }); diff --git a/yarn-project/world-state/src/world-state-db/merkle_trees.ts b/yarn-project/world-state/src/world-state-db/merkle_trees.ts index 0407fc4774ac..18e84758ef1c 100644 --- a/yarn-project/world-state/src/world-state-db/merkle_trees.ts +++ b/yarn-project/world-state/src/world-state-db/merkle_trees.ts @@ -47,8 +47,7 @@ import { loadTree, newTree, } from '@aztec/merkle-tree'; -import { type TelemetryClient } from '@aztec/telemetry-client'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; +import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client'; import { type Hasher } from '@aztec/types/interfaces'; import { @@ -123,7 +122,7 @@ export class MerkleTrees implements MerkleTreeAdminDatabase { */ public static async new( store: AztecKVStore, - client: TelemetryClient, + client: TelemetryClient = getTelemetryClient(), log = createLogger('world-state:merkle_trees'), ) { const merkleTrees = new MerkleTrees(store, client, log); @@ -136,7 +135,7 @@ export class MerkleTrees implements MerkleTreeAdminDatabase { */ public static tmp() { const store = openTmpStore(); - return MerkleTrees.new(store, new NoopTelemetryClient()); + return MerkleTrees.new(store, getTelemetryClient()); } /** diff --git a/yarn-project/yarn.lock b/yarn-project/yarn.lock index cf4a8c93dd9a..6fd514cc76bc 100644 --- a/yarn-project/yarn.lock +++ b/yarn-project/yarn.lock @@ -1286,7 +1286,7 @@ __metadata: "@opentelemetry/exporter-trace-otlp-http": "npm:^0.55.0" "@opentelemetry/host-metrics": "npm:^0.35.4" "@opentelemetry/otlp-exporter-base": "npm:^0.55.0" - "@opentelemetry/resource-detector-aws": "npm:^1.8.0" + "@opentelemetry/resource-detector-gcp": "npm:^0.32.0" "@opentelemetry/resources": "npm:^1.28.0" "@opentelemetry/sdk-logs": "npm:^0.55.0" "@opentelemetry/sdk-metrics": "npm:^1.28.0" @@ -4107,16 +4107,17 @@ __metadata: languageName: node linkType: hard -"@opentelemetry/resource-detector-aws@npm:^1.8.0": - version: 1.8.0 - resolution: "@opentelemetry/resource-detector-aws@npm:1.8.0" +"@opentelemetry/resource-detector-gcp@npm:^0.32.0": + version: 0.32.0 + resolution: "@opentelemetry/resource-detector-gcp@npm:0.32.0" dependencies: "@opentelemetry/core": "npm:^1.0.0" "@opentelemetry/resources": "npm:^1.10.0" "@opentelemetry/semantic-conventions": "npm:^1.27.0" + gcp-metadata: "npm:^6.0.0" peerDependencies: "@opentelemetry/api": ^1.0.0 - checksum: 10/077b37288659b441e958e73386696eef27a01ca1ba2f1f46706e0feef9e3f59976ce034d435198adacf6b2b6575f2ade115f05a30ddedd3a0d4b17811fcae5a0 + checksum: 10/d7c29b239462bb96bcb58a41dd70c0fa1a4766e08f8f4395e48dcc799b222c0bba6a7afe884d4a46d430b43ab6a9d5d33a63f7431f1fe29bb9f9cfaf1338898d languageName: node linkType: hard @@ -7323,6 +7324,13 @@ __metadata: languageName: node linkType: hard +"bignumber.js@npm:^9.0.0": + version: 9.1.2 + resolution: "bignumber.js@npm:9.1.2" + checksum: 10/d89b8800a987225d2c00dcbf8a69dc08e92aa0880157c851c287b307d31ceb2fc2acb0c62c3e3a3d42b6c5fcae9b004035f13eb4386e56d529d7edac18d5c9d8 + languageName: node + linkType: hard + "binary-extensions@npm:^2.0.0": version: 2.3.0 resolution: "binary-extensions@npm:2.3.0" @@ -10791,6 +10799,13 @@ __metadata: languageName: node linkType: hard +"extend@npm:^3.0.2": + version: 3.0.2 + resolution: "extend@npm:3.0.2" + checksum: 10/59e89e2dc798ec0f54b36d82f32a27d5f6472c53974f61ca098db5d4648430b725387b53449a34df38fd0392045434426b012f302b3cc049a6500ccf82877e4e + languageName: node + linkType: hard + "external-editor@npm:^3.1.0": version: 3.1.0 resolution: "external-editor@npm:3.1.0" @@ -11275,6 +11290,29 @@ __metadata: languageName: node linkType: hard +"gaxios@npm:^6.0.0": + version: 6.7.1 + resolution: "gaxios@npm:6.7.1" + dependencies: + extend: "npm:^3.0.2" + https-proxy-agent: "npm:^7.0.1" + is-stream: "npm:^2.0.0" + node-fetch: "npm:^2.6.9" + uuid: "npm:^9.0.1" + checksum: 10/c85599162208884eadee91215ebbfa1faa412551df4044626cb561300e15193726e8f23d63b486533e066dadad130f58ed872a23acab455238d8d48b531a0695 + languageName: node + linkType: hard + +"gcp-metadata@npm:^6.0.0": + version: 6.1.0 + resolution: "gcp-metadata@npm:6.1.0" + dependencies: + gaxios: "npm:^6.0.0" + json-bigint: "npm:^1.0.0" + checksum: 10/a0d12a9cb7499fdb9de0fff5406aa220310c1326b80056be8d9b747aae26414f99d14bd795c0ec52ef7d0473eef9d61bb657b8cd3d8186c8a84c4ddbff025fe9 + languageName: node + linkType: hard + "gensync@npm:^1.0.0-beta.2": version: 1.0.0-beta.2 resolution: "gensync@npm:1.0.0-beta.2" @@ -13638,6 +13676,15 @@ __metadata: languageName: node linkType: hard +"json-bigint@npm:^1.0.0": + version: 1.0.0 + resolution: "json-bigint@npm:1.0.0" + dependencies: + bignumber.js: "npm:^9.0.0" + checksum: 10/cd3973b88e5706f8f89d2a9c9431f206ef385bd5c584db1b258891a5e6642507c32316b82745239088c697f5ddfe967351e1731f5789ba7855aed56ad5f70e1f + languageName: node + linkType: hard + "json-buffer@npm:3.0.1": version: 3.0.1 resolution: "json-buffer@npm:3.0.1" @@ -15251,6 +15298,20 @@ __metadata: languageName: node linkType: hard +"node-fetch@npm:^2.6.9": + version: 2.7.0 + resolution: "node-fetch@npm:2.7.0" + dependencies: + whatwg-url: "npm:^5.0.0" + peerDependencies: + encoding: ^0.1.0 + peerDependenciesMeta: + encoding: + optional: true + checksum: 10/b24f8a3dc937f388192e59bcf9d0857d7b6940a2496f328381641cb616efccc9866e89ec43f2ec956bbd6c3d3ee05524ce77fe7b29ccd34692b3a16f237d6676 + languageName: node + linkType: hard + "node-forge@npm:^1, node-forge@npm:^1.1.0": version: 1.3.1 resolution: "node-forge@npm:1.3.1" @@ -18741,6 +18802,13 @@ __metadata: languageName: node linkType: hard +"tr46@npm:~0.0.3": + version: 0.0.3 + resolution: "tr46@npm:0.0.3" + checksum: 10/8f1f5aa6cb232f9e1bdc86f485f916b7aa38caee8a778b378ffec0b70d9307873f253f5cbadbe2955ece2ac5c83d0dc14a77513166ccd0a0c7fe197e21396695 + languageName: node + linkType: hard + "transform-ast@npm:^2.4.0": version: 2.4.4 resolution: "transform-ast@npm:2.4.4" @@ -19540,6 +19608,15 @@ __metadata: languageName: node linkType: hard +"uuid@npm:^9.0.1": + version: 9.0.1 + resolution: "uuid@npm:9.0.1" + bin: + uuid: dist/bin/uuid + checksum: 10/9d0b6adb72b736e36f2b1b53da0d559125ba3e39d913b6072f6f033e0c87835b414f0836b45bcfaf2bdf698f92297fea1c3cc19b0b258bc182c9c43cc0fab9f2 + languageName: node + linkType: hard + "v8-compile-cache-lib@npm:^3.0.1": version: 3.0.1 resolution: "v8-compile-cache-lib@npm:3.0.1" @@ -19708,6 +19785,13 @@ __metadata: languageName: node linkType: hard +"webidl-conversions@npm:^3.0.0": + version: 3.0.1 + resolution: "webidl-conversions@npm:3.0.1" + checksum: 10/b65b9f8d6854572a84a5c69615152b63371395f0c5dcd6729c45789052296df54314db2bc3e977df41705eacb8bc79c247cee139a63fa695192f95816ed528ad + languageName: node + linkType: hard + "webidl-conversions@npm:^7.0.0": version: 7.0.0 resolution: "webidl-conversions@npm:7.0.0" @@ -19930,6 +20014,16 @@ __metadata: languageName: node linkType: hard +"whatwg-url@npm:^5.0.0": + version: 5.0.0 + resolution: "whatwg-url@npm:5.0.0" + dependencies: + tr46: "npm:~0.0.3" + webidl-conversions: "npm:^3.0.0" + checksum: 10/f95adbc1e80820828b45cc671d97da7cd5e4ef9deb426c31bcd5ab00dc7103042291613b3ef3caec0a2335ed09e0d5ed026c940755dbb6d404e2b27f940fdf07 + languageName: node + linkType: hard + "wherearewe@npm:^2.0.1": version: 2.0.1 resolution: "wherearewe@npm:2.0.1"