From a749dc1656c0b4d1b0715dae90883b800be591ca Mon Sep 17 00:00:00 2001 From: Alex Gherghisan Date: Thu, 16 Jan 2025 15:28:24 +0000 Subject: [PATCH] feat: track block building helpers (#11190) This PR refactors the telemetry client so that it's a global instance that can be used to measure free functions as well and adds spans the block building helpers in the orchestrator Stacked on top of #11160 Fix #11184 --- .../archiver/src/archiver/archiver.test.ts | 4 +- yarn-project/archiver/src/factory.ts | 5 +- .../aztec-node/src/aztec-node/server.test.ts | 2 - .../aztec-node/src/aztec-node/server.ts | 16 +- .../aztec/src/cli/aztec_start_options.ts | 2 +- .../aztec/src/cli/cmds/start_archiver.ts | 7 +- yarn-project/aztec/src/cli/cmds/start_bot.ts | 7 +- yarn-project/aztec/src/cli/cmds/start_node.ts | 6 +- .../aztec/src/cli/cmds/start_p2p_bootstrap.ts | 7 +- .../src/cli/cmds/start_proof_verifier.ts | 4 +- .../aztec/src/cli/cmds/start_prover_agent.ts | 8 +- .../aztec/src/cli/cmds/start_prover_broker.ts | 7 +- .../aztec/src/cli/cmds/start_prover_node.ts | 6 +- yarn-project/aztec/src/sandbox.ts | 8 +- .../bb-prover/src/prover/bb_prover.ts | 4 +- .../bb-prover/src/test/test_circuit_prover.ts | 4 +- yarn-project/blob-sink/src/server/server.ts | 5 +- .../composed/integration_l1_publisher.test.ts | 28 +- .../end-to-end/src/e2e_block_building.test.ts | 11 +- .../end-to-end/src/e2e_p2p/p2p_network.ts | 2 +- .../src/e2e_prover/e2e_prover_test.ts | 2 - .../end-to-end/src/e2e_synching.test.ts | 7 +- .../end-to-end/src/fixtures/setup_p2p_test.ts | 2 +- .../src/fixtures/snapshot_manager.ts | 6 +- yarn-project/end-to-end/src/fixtures/utils.ts | 31 +- .../src/fixtures/with_telemetry_utils.ts | 28 +- yarn-project/p2p-bootstrap/src/index.ts | 5 +- yarn-project/p2p/src/client/factory.ts | 5 +- yarn-project/p2p/src/client/p2p_client.ts | 4 +- .../kv_attestation_pool.test.ts | 3 +- .../attestation_pool/kv_attestation_pool.ts | 4 +- .../memory_attestation_pool.test.ts | 4 +- .../memory_attestation_pool.ts | 4 +- .../memory_epoch_proof_quote_pool.test.ts | 4 +- .../memory_epoch_proof_quote_pool.ts | 4 +- .../tx_pool/aztec_kv_tx_pool.test.ts | 3 +- .../src/mem_pools/tx_pool/aztec_kv_tx_pool.ts | 8 +- .../mem_pools/tx_pool/memory_tx_pool.test.ts | 4 +- .../src/mem_pools/tx_pool/memory_tx_pool.ts | 4 +- yarn-project/p2p/src/mocks/index.ts | 7 +- .../p2p/src/services/discv5/discV5_service.ts | 4 +- .../services/discv5/discv5_service.test.ts | 6 +- .../p2p/src/services/peer_manager.test.ts | 4 +- yarn-project/proof-verifier/src/config.ts | 2 +- .../src/block_builder/light.test.ts | 6 +- .../prover-client/src/block_builder/light.ts | 11 +- .../prover-client/src/mocks/test_context.ts | 16 +- .../orchestrator/block-building-helpers.ts | 684 +++++++++--------- .../src/orchestrator/orchestrator.ts | 11 +- .../orchestrator_failures.test.ts | 5 +- .../orchestrator_lifecycle.test.ts | 5 +- .../agent-queue-integration.test.ts | 4 +- .../agent-queue-rpc-integration.test.ts | 4 +- .../prover-agent/memory-proving-queue.test.ts | 4 +- .../src/prover-agent/prover-agent.test.ts | 4 +- .../src/prover-agent/prover-agent.ts | 12 +- .../src/prover-client/factory.ts | 5 +- .../src/prover-client/prover-client.ts | 14 +- .../src/proving_broker/factory.ts | 14 +- .../src/proving_broker/proving_agent.test.ts | 3 +- .../src/proving_broker/proving_agent.ts | 12 +- .../src/proving_broker/proving_broker.test.ts | 11 +- .../src/proving_broker/proving_broker.ts | 10 +- .../broker_persisted_database.test.ts | 5 +- .../proving_broker_database/persisted.ts | 6 +- .../src/test/bb_prover_full_rollup.test.ts | 4 +- .../src/test/bb_prover_parity.test.ts | 3 +- .../prover-client/src/test/mock_prover.ts | 5 +- yarn-project/prover-node/src/factory.ts | 13 +- .../src/job/epoch-proving-job.test.ts | 4 +- .../src/monitors/claims-monitor.test.ts | 3 +- .../src/monitors/claims-monitor.ts | 10 +- .../src/monitors/epoch-monitor.test.ts | 3 +- .../prover-node/src/monitors/epoch-monitor.ts | 10 +- .../prover-node/src/prover-node.test.ts | 16 +- yarn-project/prover-node/src/prover-node.ts | 11 +- .../src/client/sequencer-client.ts | 2 +- .../src/publisher/l1-publisher.test.ts | 3 +- .../src/publisher/l1-publisher.ts | 5 +- .../src/sequencer/sequencer.test.ts | 2 - .../src/sequencer/sequencer.ts | 4 +- .../sequencer-client/src/slasher/factory.ts | 5 +- .../src/slasher/slasher_client.ts | 5 +- .../simulator/src/avm/avm_simulator.test.ts | 4 +- .../simulator/src/avm/avm_tree.test.ts | 4 +- .../simulator/src/public/fixtures/index.ts | 13 +- .../src/public/public_processor.test.ts | 4 +- .../simulator/src/public/public_processor.ts | 19 +- .../src/public/public_tx_simulator.test.ts | 5 +- .../src/public/public_tx_simulator.ts | 4 +- yarn-project/telemetry-client/package.json | 2 - yarn-project/telemetry-client/src/index.ts | 1 + yarn-project/telemetry-client/src/otel.ts | 4 +- .../telemetry-client/src/otel_resource.ts | 6 +- yarn-project/telemetry-client/src/start.ts | 20 +- .../telemetry-client/src/telemetry.ts | 44 ++ .../src/vendor/otel-pino-stream.ts | 4 +- yarn-project/txe/src/oracle/txe_oracle.ts | 2 - .../txe/src/txe_service/txe_service.ts | 4 +- .../validator-client/src/validator.ts | 7 +- .../src/native/native_world_state.ts | 6 +- .../src/native/native_world_state_cmp.test.ts | 4 +- .../world-state/src/synchronizer/factory.ts | 4 +- .../server_world_state_synchronizer.ts | 5 +- .../world-state/src/test/integration.test.ts | 12 +- .../src/world-state-db/merkle_trees.ts | 7 +- 106 files changed, 745 insertions(+), 692 deletions(-) diff --git a/yarn-project/archiver/src/archiver/archiver.test.ts b/yarn-project/archiver/src/archiver/archiver.test.ts index e79d48becd4..03d24c096a2 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 15dc16a9bc6..96556003117 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 c2a290c8d50..df982353430 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,6 @@ 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 { type MockProxy, mock } from 'jest-mock-extended'; @@ -97,7 +96,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 647cf72f49d..ef4bc47c0da 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/server'; -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_options.ts b/yarn-project/aztec/src/cli/aztec_start_options.ts index 31e7901b1d9..b9e2c2992c0 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 3713a0e1aa3..a6d9fd8e994 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 = 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 635549c189f..4e5af62d1bc 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 = 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 1d93fd1e4ad..a68b6a5b6e0 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 = 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 975f339aef6..ae9181f6841 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 = 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 2aa5ce823f5..8ce25e1b299 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 = 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 01ee05716d1..23919f407d0 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 = 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 ec0abcd3649..ad53dea8fa2 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 = 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 ceb4cc00ff5..275be3eeea3 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 = initTelemetryClient(extractRelevantOptions(options, telemetryClientConfigMappings, 'tel')); let broker: ProvingJobBroker; if (proverConfig.proverBrokerUrl) { diff --git a/yarn-project/aztec/src/sandbox.ts b/yarn-project/aztec/src/sandbox.ts index c6a7dd8363c..1cfb2178e07 100644 --- a/yarn-project/aztec/src/sandbox.ts +++ b/yarn-project/aztec/src/sandbox.ts @@ -16,11 +16,11 @@ 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, 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 +144,7 @@ export async function createSandbox(config: Partial = {}) { await watcher.start(); } - const telemetry = await createAndStartTelemetryClient(getTelemetryClientConfig()); + const telemetry = 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 b983ccc18bb..ea6b4fe4633 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/server'; -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 756ef24ff9b..04b4a77bfa0 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/server'; -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 0727ba4a70f..2103750bbd1 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 1a727d8f555..1334d39aadf 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 91be2b9f950..4a6f9c8573e 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 @@ -38,7 +38,6 @@ import { type WorldStateDB, } from '@aztec/simulator/server'; import { type TelemetryClient } from '@aztec/telemetry-client'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; import { jest } from '@jest/globals'; import 'jest-extended'; @@ -204,11 +203,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 @@ -629,18 +624,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_p2p/p2p_network.ts b/yarn-project/end-to-end/src/e2e_p2p/p2p_network.ts index 8331c217261..ce7d27170c6 100644 --- a/yarn-project/end-to-end/src/e2e_p2p/p2p_network.ts +++ b/yarn-project/end-to-end/src/e2e_p2p/p2p_network.ts @@ -114,7 +114,7 @@ export class P2PNetworkTest { }) { const port = basePort || (await getPort()); - const telemetry = await getEndToEndTestTelemetryClient(metricsPort); + const telemetry = getEndToEndTestTelemetryClient(metricsPort); const bootstrapNode = await createBootstrapNodeFromPrivateKey(BOOTSTRAP_NODE_PRIVATE_KEY, port, telemetry); const bootstrapNodeEnr = bootstrapNode.getENR().encodeTxt(); 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 4f971207761..38fd15d980b 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,6 @@ 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'; // 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 +253,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 24aeb10de9a..f30ec157241 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/setup_p2p_test.ts b/yarn-project/end-to-end/src/fixtures/setup_p2p_test.ts index cfdfc1fd544..5cb5ba6e60f 100644 --- a/yarn-project/end-to-end/src/fixtures/setup_p2p_test.ts +++ b/yarn-project/end-to-end/src/fixtures/setup_p2p_test.ts @@ -86,7 +86,7 @@ export async function createNode( ) { const createNode = async () => { const validatorConfig = await createValidatorConfig(config, bootstrapNode, tcpPort, accountIndex, dataDirectory); - const telemetry = await getEndToEndTestTelemetryClient(metricsPort); + const telemetry = getEndToEndTestTelemetryClient(metricsPort); return await AztecNodeService.createAndSync(validatorConfig, { telemetry, dateProvider }); }; return loggerIdStorage ? await loggerIdStorage.run(tcpPort.toString(), createNode) : createNode(); 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 f3a34aab523..791476559a6 100644 --- a/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts +++ b/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts @@ -26,7 +26,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'; @@ -386,7 +386,7 @@ async function setupFromFresh( aztecNodeConfig.bbWorkingDirectory = bbConfig.bbWorkingDirectory; } - const telemetry = await getEndToEndTestTelemetryClient(opts.metricsPort); + const telemetry = getEndToEndTestTelemetryClient(opts.metricsPort); logger.verbose('Creating and synching an aztec node...'); const dateProvider = new TestDateProvider(); @@ -492,7 +492,7 @@ async function setupFromState(statePath: string, logger: Logger): Promise PXE_URL; -let telemetryPromise: Promise | undefined = undefined; +let telemetry: TelemetryClient | undefined = undefined; function getTelemetryClient(partialConfig: Partial & { benchmark?: boolean } = {}) { - if (!telemetryPromise) { + if (!telemetry) { const config = { ...getTelemetryConfig(), ...partialConfig }; - telemetryPromise = config.benchmark - ? Promise.resolve(new BenchmarkTelemetryClient()) - : createAndStartTelemetryClient(config); + telemetry = config.benchmark ? new BenchmarkTelemetryClient() : initTelemetryClient(config); } - return telemetryPromise; + return telemetry; } if (typeof afterAll === 'function') { afterAll(async () => { - await (await telemetryPromise)?.stop(); + await telemetry?.stop(); }); } @@ -472,12 +469,11 @@ export async function setup( } config.l1PublishRetryIntervalMS = 100; - const telemetry = await getTelemetryClient(opts.telemetryConfig); + const telemetry = getTelemetryClient(opts.telemetryConfig); 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, @@ -755,8 +751,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, }); @@ -782,7 +777,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 aed13a14fde..9b93b644486 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); +export function getEndToEndTestTelemetryClient(metricsPort?: number): TelemetryClient { + 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/p2p-bootstrap/src/index.ts b/yarn-project/p2p-bootstrap/src/index.ts index 3ccc3ad325d..c3af829a460 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 926286c19ba..e29c4b95206 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 aeb51ae3fcd..44010f75b07 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 2832694784c..2264715fa32 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 8de98828eed..ea6f848e9fd 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 5d2cd81b625..69fd23a8a8f 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 fe39a3fba18..35d94c7b11b 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 2358c833a75..2f5d8267058 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 568e5cbfc24..0896787892c 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 cb3abd077e3..bc9f91329e3 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 58a92439957..da6ca6d526b 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 c4435a5613a..fb910b4755c 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 485dd86b1b0..7d0d87df675 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 ff5996d0908..74f7339d098 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 b629f1807b2..3c8d135c47b 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 552aa98e6df..0ab9005b8bb 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 2feba167ffd..dda028e647d 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 a312bbddd59..a0d645b4b83 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 99ee51bbd0b..dcbf24c647a 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 3446b603d03..5099a6dbec6 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 a00642bb55f..0350f2e8927 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/server'; -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 9b7a68ab4a8..20ca0b92c4e 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/server'; +import { Attributes, type 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 8190da2dd6f..f7f896acd9d 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 7d09489a01f..26151a1ae5f 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/server'; -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 29537740bfb..46533097bec 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 f8992a35ffb..a6fd9009c8c 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 6be41a4bdec..22791753473 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 aa971c116ce..9cf02f5457f 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 7c344a44c05..8af88de41cf 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 4cc8f1e9702..cbf6484fd7a 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 45e10ed630b..164ff1104e5 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 f179ba758d0..7ba94e9f102 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/server'; -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 aadd7558eaa..22e86099e86 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 405d16d5c1e..aea11548e44 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 3c099c8f1a5..68fcb4fb410 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 6a9f2ae1025..14e2f7e0624 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 f4461a366d6..5eabd41ea37 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 46154cf635c..1672baf4d9d 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 0c8b5029d6f..39e0a74e46c 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 263c0dfe9b6..d16d18e15f9 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 2db1248ac9d..1f65db5607f 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 2618bbb9c2e..35fa567f921 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 300fd664138..c129933070d 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 80240ae2b5a..3f12c2e0166 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/server'; -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 0771faaf161..610284e3caa 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 9aecb95b639..56cf77ea7a2 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 033cc74d1b3..f7a0d7dc406 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 503429cf853..a285162a662 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 0d555b8efe7..2a167b24a2e 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/server'; -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 a3fca249f99..80b0f5b19d3 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/server'; -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 7bc7a5ad786..211b8f8f9b0 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 b638f3a5fb0..7f6e178fb82 100644 --- a/yarn-project/sequencer-client/src/publisher/l1-publisher.test.ts +++ b/yarn-project/sequencer-client/src/publisher/l1-publisher.test.ts @@ -13,7 +13,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'; @@ -140,7 +139,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 22f42f2f9fe..537a74b8176 100644 --- a/yarn-project/sequencer-client/src/publisher/l1-publisher.ts +++ b/yarn-project/sequencer-client/src/publisher/l1-publisher.ts @@ -36,8 +36,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 { @@ -209,7 +208,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 784d40d5edb..88074ba1157 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/server'; -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 c5e8c291776..bef15067f58 100644 --- a/yarn-project/sequencer-client/src/sequencer/sequencer.ts +++ b/yarn-project/sequencer-client/src/sequencer/sequencer.ts @@ -33,7 +33,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/server'; -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'; @@ -94,8 +94,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 85decb074ea..c6fe4c624e0 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 cc5e60e25ea..f2022c9c55d 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 d6fff38670f..447b5bcce13 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 31c8c015e2a..85b30629e13 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 f87b4fb36b7..b7da98b72bc 100644 --- a/yarn-project/simulator/src/public/fixtures/index.ts +++ b/yarn-project/simulator/src/public/fixtures/index.ts @@ -32,7 +32,6 @@ import { AztecAddress } from '@aztec/foundation/aztec-address'; import { Fr, Point } from '@aztec/foundation/fields'; import { openTmpStore } from '@aztec/kv-store/lmdb'; import { AvmTestContractArtifact } from '@aztec/noir-contracts.js/AvmTest'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; import { MerkleTrees } from '@aztec/world-state'; import { strict as assert } from 'assert'; @@ -59,17 +58,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 callContext = new CallContext( @@ -128,7 +121,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 b2696cb860c..aea53976bf4 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 b67d187cdaa..920337c5299 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 3029c1b1ee2..393a47a1568 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 50394b00ede..b5886d93347 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 7686730c0bd..48cbd579392 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", "./bench": "./dest/bench.js", "./otel-pino-stream": "./dest/vendor/otel-pino-stream.js" }, diff --git a/yarn-project/telemetry-client/src/index.ts b/yarn-project/telemetry-client/src/index.ts index acd6b5363b4..e593b4575f4 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/otel.ts b/yarn-project/telemetry-client/src/otel.ts index 56377a966b7..b0a509239cd 100644 --- a/yarn-project/telemetry-client/src/otel.ts +++ b/yarn-project/telemetry-client/src/otel.ts @@ -281,8 +281,8 @@ export class OpenTelemetryClient implements TelemetryClient { }; } - public static async createAndStart(config: TelemetryClientConfig, log: Logger): Promise { - const resource = await getOtelResource(); + public static createAndStart(config: TelemetryClientConfig, log: Logger): OpenTelemetryClient { + const resource = getOtelResource(); const factory = config.useGcloudObservability ? OpenTelemetryClient.getGcloudClientFactory(config) : OpenTelemetryClient.getCustomClientFactory(config); diff --git a/yarn-project/telemetry-client/src/otel_resource.ts b/yarn-project/telemetry-client/src/otel_resource.ts index 6a41d95c992..a91dbd94434 100644 --- a/yarn-project/telemetry-client/src/otel_resource.ts +++ b/yarn-project/telemetry-client/src/otel_resource.ts @@ -10,7 +10,7 @@ import { import { aztecDetector } from './aztec_resource_detector.js'; -export async function getOtelResource(): Promise { +export function getOtelResource(): IResource { const resource = detectResourcesSync({ detectors: [ osDetectorSync, @@ -22,9 +22,5 @@ export async function getOtelResource(): Promise { ], }); - if (resource.asyncAttributesPending) { - await resource.waitForAsyncAttributes!(); - } - return resource; } diff --git a/yarn-project/telemetry-client/src/start.ts b/yarn-project/telemetry-client/src/start.ts index fe8a40dabec..e9985305205 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 function initTelemetryClient(config: TelemetryClientConfig): TelemetryClient { const log = createLogger('telemetry:client'); + if (initialised) { + log.warn('Telemetry client has already been initialized once'); + return telemetry; + } + if (config.metricsCollectorUrl || config.useGcloudObservability) { log.info(`Using OpenTelemetry client ${config.useGcloudObservability ? 'with GCP' : 'with custom collector'}`); - return await OpenTelemetryClient.createAndStart(config, log); + telemetry = OpenTelemetryClient.createAndStart(config, log); } else { log.info('Using NoopTelemetryClient'); - return new NoopTelemetryClient(); } + + initialised = true; + 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 9fb8497fb21..6672ce17659 100644 --- a/yarn-project/telemetry-client/src/telemetry.ts +++ b/yarn-project/telemetry-client/src/telemetry.ts @@ -14,9 +14,11 @@ 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'; @@ -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/telemetry-client/src/vendor/otel-pino-stream.ts b/yarn-project/telemetry-client/src/vendor/otel-pino-stream.ts index 88610f15e76..3f10df35289 100644 --- a/yarn-project/telemetry-client/src/vendor/otel-pino-stream.ts +++ b/yarn-project/telemetry-client/src/vendor/otel-pino-stream.ts @@ -273,9 +273,9 @@ export class OTelPinoStream extends Writable { // Invoked by pino when creating a transport in a worker thread out of this stream. // Note that the original open-telemetry/opentelemetry-js-contrib was set up to run on the main // nodejs loop, as opposed to in a worker as pino recommends. -export default async function (options: OTelPinoStreamOptions) { +export default function (options: OTelPinoStreamOptions): OTelPinoStream { const url = process.env.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT; - const resource = await getOtelResource(); + const resource = getOtelResource(); // We re-register here because this runs on a worker thread registerOtelLoggerProvider(resource, url ? new URL(url) : undefined); return new OTelPinoStream(options); diff --git a/yarn-project/txe/src/oracle/txe_oracle.ts b/yarn-project/txe/src/oracle/txe_oracle.ts index ee5a3d457f6..565f1a8578b 100644 --- a/yarn-project/txe/src/oracle/txe_oracle.ts +++ b/yarn-project/txe/src/oracle/txe_oracle.ts @@ -84,7 +84,6 @@ import { createSimulationError, resolveAssertionMessageFromError, } from '@aztec/simulator/server'; -import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; import { MerkleTreeSnapshotOperationsFacade, type MerkleTrees } from '@aztec/world-state'; import { TXENode } from '../node/txe_node.js'; @@ -830,7 +829,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 a97eafe7903..9b27a2b5fe9 100644 --- a/yarn-project/txe/src/txe_service/txe_service.ts +++ b/yarn-project/txe/src/txe_service/txe_service.ts @@ -20,7 +20,7 @@ import { getCanonicalProtocolContract } from '@aztec/protocol-contracts/bundle'; import { enrichPublicSimulationError } from '@aztec/pxe'; import { type TypedOracle } from '@aztec/simulator/client'; import { HashedValuesCache } from '@aztec/simulator/server'; -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'; @@ -42,7 +42,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 executionCache = new HashedValuesCache(); const keyStore = new KeyStore(store); const txeDatabase = new TXEDatabase(store); diff --git a/yarn-project/validator-client/src/validator.ts b/yarn-project/validator-client/src/validator.ts index 2dcd79d346b..0379696ee40 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 { DateProvider, 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'; @@ -81,7 +80,7 @@ export class ValidatorClient extends WithTracer implements Validator { private p2pClient: P2P, private config: ValidatorClientConfig, private dateProvider: DateProvider = new DateProvider(), - telemetry: TelemetryClient = new NoopTelemetryClient(), + telemetry: TelemetryClient = getTelemetryClient(), private log = createLogger('validator'), ) { // Instantiate tracer @@ -121,7 +120,7 @@ export class ValidatorClient extends WithTracer implements Validator { epochCache: EpochCache, p2pClient: P2P, dateProvider: DateProvider = new DateProvider(), - 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 092adb69dc3..dd926aadcea 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 35623820461..676d184fa60 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 690fcd03ce2..cd0b2e3c559 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 b0d590c3b2a..ff631287a65 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 daa105e7851..1f60c0bafaf 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 0407fc4774a..18e84758ef1 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()); } /**