diff --git a/src/metrics.rs b/src/metrics.rs index 9e62cd3..dcea450 100644 --- a/src/metrics.rs +++ b/src/metrics.rs @@ -55,6 +55,16 @@ const FLASHBOTS_SUBMISSION_DURATION_MS: &str = "signet.builder.flashbots.submiss const FLASHBOTS_SUBMISSION_DURATION_MS_HELP: &str = "Duration of Flashbots bundle submission requests in milliseconds"; +// -- Cache -- +const CACHE_BUNDLES_RECEIVED: &str = "signet.builder.cache.bundles_received"; +const CACHE_BUNDLES_RECEIVED_HELP: &str = "Number of bundles received by the cache"; + +const CACHE_BUNDLES_DROPPED: &str = "signet.builder.cache.bundles_dropped"; +const CACHE_BUNDLES_DROPPED_HELP: &str = "Number of bundles dropped due to add failures"; + +const CACHE_TXS_RECEIVED: &str = "signet.builder.cache.txs_received"; +const CACHE_TXS_RECEIVED_HELP: &str = "Number of transactions received by the cache"; + // -- Block Building -- const BUILT_BLOCKS: &str = "signet.builder.built_blocks"; const BUILT_BLOCKS_HELP: &str = "Number of blocks built by the simulator"; @@ -95,6 +105,11 @@ static DESCRIBE: LazyLock<()> = LazyLock::new(|| { describe_counter!(FLASHBOTS_SUBMISSIONS, FLASHBOTS_SUBMISSIONS_HELP); describe_histogram!(FLASHBOTS_SUBMISSION_DURATION_MS, FLASHBOTS_SUBMISSION_DURATION_MS_HELP); + // Cache + describe_counter!(CACHE_BUNDLES_RECEIVED, CACHE_BUNDLES_RECEIVED_HELP); + describe_counter!(CACHE_BUNDLES_DROPPED, CACHE_BUNDLES_DROPPED_HELP); + describe_counter!(CACHE_TXS_RECEIVED, CACHE_TXS_RECEIVED_HELP); + // Block building describe_counter!(BUILT_BLOCKS, BUILT_BLOCKS_HELP); describe_histogram!(BUILT_BLOCKS_TX_COUNT, BUILT_BLOCKS_TX_COUNT_HELP); @@ -173,6 +188,26 @@ pub fn flashbots_submission_duration_ms() -> Histogram { histogram!(FLASHBOTS_SUBMISSION_DURATION_MS) } +// -- Cache -- + +/// Counter for bundles received by the cache. +pub fn cache_bundles_received() -> Counter { + LazyLock::force(&DESCRIBE); + counter!(CACHE_BUNDLES_RECEIVED) +} + +/// Counter for bundles dropped due to add failures. +pub fn cache_bundles_dropped() -> Counter { + LazyLock::force(&DESCRIBE); + counter!(CACHE_BUNDLES_DROPPED) +} + +/// Counter for transactions received by the cache. +pub fn cache_txs_received() -> Counter { + LazyLock::force(&DESCRIBE); + counter!(CACHE_TXS_RECEIVED) +} + // -- Block Building -- /// Counter for blocks built by the simulator. diff --git a/src/tasks/cache/task.rs b/src/tasks/cache/task.rs index ad2d7ae..a6fd509 100644 --- a/src/tasks/cache/task.rs +++ b/src/tasks/cache/task.rs @@ -1,4 +1,4 @@ -use crate::tasks::env::SimEnv; +use crate::{metrics, tasks::env::SimEnv}; use alloy::consensus::TxEnvelope; use signet_sim::SimCache; use signet_tx_cache::types::TxCacheBundle; @@ -34,8 +34,8 @@ impl CacheTask { } async fn task_future(mut self, cache: SimCache) { + let mut basefee = 0; loop { - let mut basefee = 0; tokio::select! { biased; res = self.envs.changed() => { @@ -55,14 +55,17 @@ impl CacheTask { } } Some(bundle) = self.bundles.recv() => { + metrics::cache_bundles_received().increment(1); let res = cache.add_bundle(bundle.bundle, basefee); // Skip bundles that fail to be added to the cache if let Err(e) = res { + metrics::cache_bundles_dropped().increment(1); debug!(?e, "Failed to add bundle to cache"); continue; } } Some(txn) = self.txns.recv() => { + metrics::cache_txs_received().increment(1); cache.add_tx(txn, basefee); } }