Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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.
Expand Down
7 changes: 5 additions & 2 deletions src/tasks/cache/task.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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() => {
Expand All @@ -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);
}
}
Expand Down
Loading