From a868abe57dfb734bd2f5bf6e22575b6fd4bcf02e Mon Sep 17 00:00:00 2001 From: EclesioMeloJunior Date: Sun, 23 Aug 2026 10:51:31 -0400 Subject: [PATCH] fix:(drand): `SizeTrackingCache` cache name per drand network name --- CHANGELOG.md | 2 ++ src/beacon/drand.rs | 8 ++++++-- src/beacon/tests/drand.rs | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b208bf8abe..2b5bff4d49a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,8 @@ ### Fixed +- [#7414](https://github.com/ChainSafe/forest/issues/7414): The drand entry cache metrics are now named per drand network (`cache_verified_beacons_quicknet_*` and so on). They previously all shared the name `cache_verified_beacons_*`, so a network with more than one drand point (such as mainnet) exported duplicate metric families in a single scrape. + - [#5795](https://github.com/ChainSafe/forest/issues/5795): `Filecoin.ChainNotify` now closes the subscription channel when a client falls too far behind instead of silently dropping head changes, matching Lotus, so clients can detect the gap and resubscribe. ## Forest v0.36.0 "bafy2bzacedpdckv7nsqfjwqnqwtgu7ipqbox4tfuuhwxhdox27uuznfyv3o2g" diff --git a/src/beacon/drand.rs b/src/beacon/drand.rs index 887b78d7759..fe76bd2f98d 100644 --- a/src/beacon/drand.rs +++ b/src/beacon/drand.rs @@ -37,7 +37,8 @@ pub static IGNORE_DRAND: LazyLock = LazyLock::new(|| is_env_truthy(IGNORE_ /// Type of the `drand` network. `mainnet` is chained and `quicknet` is unchained. /// For the details, see -#[derive(PartialEq, Eq, Copy, Clone, Debug, SerdeSerialize, SerdeDeserialize)] +#[derive(PartialEq, Eq, Copy, Clone, Debug, SerdeSerialize, SerdeDeserialize, strum::Display)] +#[strum(serialize_all = "snake_case")] pub enum DrandNetwork { Mainnet, Quicknet, @@ -271,7 +272,10 @@ impl DrandBeacon { drand_gen_time: config.chain_info.genesis_time as u64, fil_round_time: interval, fil_gen_time: genesis_ts, - verified_beacons: SizeTrackingCache::new_with_metrics("verified_beacons", CACHE_SIZE), + verified_beacons: SizeTrackingCache::new_with_metrics( + format!("verified_beacons_{}", config.network_type), + CACHE_SIZE, + ), } } diff --git a/src/beacon/tests/drand.rs b/src/beacon/tests/drand.rs index b5611b30fbf..f5a34e3658a 100644 --- a/src/beacon/tests/drand.rs +++ b/src/beacon/tests/drand.rs @@ -308,3 +308,36 @@ async fn beacon_entries_for_block_covers_null_rounds_quicknet() { ); } } + +#[test] +#[serial_test::serial] +fn verified_beacons_cache_metrics_are_uniquely_named() { + use crate::networks::ChainConfig; + + crate::metrics::reset_collector_registry(); + // Mainnet has three drand points: Incentinet, Mainnet and Quicknet. + let schedule = ChainConfig::mainnet().get_beacon_schedule(1598306400); + assert_eq!(schedule.0.len(), 3); + + let mut encoded = String::new(); + prometheus_client::encoding::text::encode_registry( + &mut encoded, + &crate::metrics::collector_registry(), + ) + .unwrap(); + + let families: Vec<_> = encoded + .lines() + .filter_map(|line| line.strip_prefix("# HELP ")) + .filter(|line| line.starts_with("cache_verified_beacons")) + .map(|line| line.split_whitespace().next().unwrap_or_default()) + .collect(); + + // Five metrics (size/len/cap/hits/misses) for each of the three beacons. + assert_eq!(families.len(), 15); + assert_eq!( + families.iter().unique().count(), + families.len(), + "duplicate cache metric families: {families:?}" + ); +}