From b0528d4c6f7c8980085fa1a2dbe9ef220cd5cf1e Mon Sep 17 00:00:00 2001 From: Brian Balser Date: Tue, 1 Jul 2025 09:22:27 -0400 Subject: [PATCH] Add new metrics to track poc, data transfer, and mapper rewards --- mobile_verifier/src/rewarder.rs | 11 ++++++++++- mobile_verifier/src/telemetry.rs | 15 +++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/mobile_verifier/src/rewarder.rs b/mobile_verifier/src/rewarder.rs index 1a066815d..fea127c79 100644 --- a/mobile_verifier/src/rewarder.rs +++ b/mobile_verifier/src/rewarder.rs @@ -492,20 +492,24 @@ async fn reward_poc( { // handle poc reward outputs let mut allocated_poc_rewards = 0_u64; + let mut count_rewarded_radios = 0; for (poc_reward_amount, mobile_reward_share_v2) in mobile_reward_shares { allocated_poc_rewards += poc_reward_amount; + count_rewarded_radios += 1; mobile_rewards .write(mobile_reward_share_v2, []) .await? // await the returned one shot to ensure that we wrote the file .await??; } + telemetry::poc_rewarded_radios(count_rewarded_radios); // calculate any unallocated poc reward ( total_poc_rewards - Decimal::from(allocated_poc_rewards), calculated_poc_rewards_per_share, ) } else { + telemetry::poc_rewarded_radios(0); // default unallocated poc reward to the total poc reward (total_poc_rewards, CalculatedPocRewardShares::default()) }; @@ -520,14 +524,17 @@ pub async fn reward_dc( ) -> anyhow::Result { // handle dc reward outputs let mut allocated_dc_rewards = 0_u64; + let mut count_rewarded_gateways = 0; for (dc_reward_amount, mobile_reward_share) in transfer_rewards.into_rewards(reward_info) { allocated_dc_rewards += dc_reward_amount; + count_rewarded_gateways += 1; mobile_rewards .write(mobile_reward_share, []) .await? // Await the returned one shot to ensure that we wrote the file .await??; } + telemetry::data_transfer_rewarded_gateways(count_rewarded_gateways); // for Dc we return the unallocated amount rather than writing it out to as an unallocated reward // it then gets added to the poc pool // we return the full decimal value just to ensure we allocate all to poc @@ -554,17 +561,19 @@ pub async fn reward_mappers( // translate discovery mapping shares into subscriber rewards let mut allocated_mapping_rewards = 0_u64; - + let mut count_mappers_rewarded = 0; for (reward_amount, mapping_share) in mapping_shares.into_subscriber_rewards(&reward_info.epoch_period, rewards_per_share) { allocated_mapping_rewards += reward_amount; + count_mappers_rewarded += 1; mobile_rewards .write(mapping_share.clone(), []) .await? // Await the returned one shot to ensure that we wrote the file .await??; } + telemetry::mappers_rewarded(count_mappers_rewarded); // write out any unallocated mapping rewards let unallocated_mapping_reward_amount = total_mappers_pool diff --git a/mobile_verifier/src/telemetry.rs b/mobile_verifier/src/telemetry.rs index 90ab7fc6c..c2a7e41d0 100644 --- a/mobile_verifier/src/telemetry.rs +++ b/mobile_verifier/src/telemetry.rs @@ -5,6 +5,9 @@ use sqlx::{Pool, Postgres}; const LAST_REWARDED_END_TIME: &str = "last_rewarded_end_time"; const DATA_TRANSFER_REWARDS_SCALE: &str = "data_transfer_rewards_scale"; +const POC_REWARDED_RADIOS: &str = "poc_rewarded_radios"; +const DATA_TRANSFER_REWARDED_GATEWAYS: &str = "data_transfer_rewarded_gateways"; +const MAPPERS_REWARDED: &str = "mappers_rewarded"; pub async fn initialize(db: &Pool) -> anyhow::Result<()> { let next_reward_epoch = rewarder::next_reward_epoch(db).await?; @@ -20,3 +23,15 @@ pub fn last_rewarded_end_time(timestamp: DateTime) { pub fn data_transfer_rewards_scale(scale: f64) { metrics::gauge!(DATA_TRANSFER_REWARDS_SCALE).set(scale); } + +pub fn poc_rewarded_radios(count: u64) { + metrics::gauge!(POC_REWARDED_RADIOS).set(count as f64); +} + +pub fn data_transfer_rewarded_gateways(count: u64) { + metrics::gauge!(DATA_TRANSFER_REWARDED_GATEWAYS).set(count as f64); +} + +pub fn mappers_rewarded(count: u64) { + metrics::gauge!(MAPPERS_REWARDED).set(count as f64); +}