From b4307d8e60b8d809d9ec88e60e6b402e3e785ffe Mon Sep 17 00:00:00 2001 From: Andrew McKenzie Date: Tue, 17 Dec 2024 16:11:13 +0000 Subject: [PATCH] centralise emission values --- .../src/sub_dao_epoch_reward_info.rs | 2 +- mobile_verifier/src/reward_shares.rs | 45 ++++++++++--------- .../tests/integrations/common/mod.rs | 9 ++-- .../tests/integrations/hex_boosting.rs | 16 +++---- .../tests/integrations/rewarder_mappers.rs | 8 ++-- .../tests/integrations/rewarder_poc_dc.rs | 6 +-- .../tests/integrations/rewarder_sp_rewards.rs | 12 ++--- 7 files changed, 53 insertions(+), 45 deletions(-) diff --git a/mobile_config/src/sub_dao_epoch_reward_info.rs b/mobile_config/src/sub_dao_epoch_reward_info.rs index ce81a9295..b356c9566 100644 --- a/mobile_config/src/sub_dao_epoch_reward_info.rs +++ b/mobile_config/src/sub_dao_epoch_reward_info.rs @@ -93,7 +93,7 @@ pub(crate) mod db { .bind(sub_dao_address) .fetch_optional(db) .await?; - tracing::info!("get_info: {:?}", res); + tracing::debug!("get_info: {:?}", res); Ok(res) } diff --git a/mobile_verifier/src/reward_shares.rs b/mobile_verifier/src/reward_shares.rs index ea8d4f727..a1d3c1414 100644 --- a/mobile_verifier/src/reward_shares.rs +++ b/mobile_verifier/src/reward_shares.rs @@ -823,8 +823,8 @@ mod test { const EPOCH_ADDRESS: &str = "112E7TxoNHV46M6tiPA8N1MkeMeQxc9ztb4JQLXBVAAUfq1kJLoF"; const SUB_DAO_ADDRESS: &str = "112NqN2WWMwtK29PMzRby62fDydBJfsCLkCAf392stdok48ovNT6"; - const EMISSIONS_POOL_24_HOURS: u64 = 82_191_780_821_917; - const EMISSIONS_POOL_1_HOUR: u64 = 3_424_657_534_247; + const EMISSIONS_POOL_IN_BONES_24_HOURS: u64 = 82_191_780_821_917; + const EMISSIONS_POOL_IN_BONES_1_HOUR: u64 = 3_424_657_534_247; fn hex_assignments_mock() -> HexAssignments { HexAssignments { @@ -866,8 +866,7 @@ mod test { } fn default_price_info() -> PriceInfo { - let token = Token::Hnt; - PriceInfo::new(10000000000000000, token.decimals()) + PriceInfo::new(10000000000000000, Token::Hnt.decimals()) } #[test] @@ -932,7 +931,8 @@ mod test { } // set our rewards info - let rewards_info = default_rewards_info(EMISSIONS_POOL_24_HOURS, Duration::hours(24)); + let rewards_info = + default_rewards_info(EMISSIONS_POOL_IN_BONES_24_HOURS, Duration::hours(24)); // translate location shares into shares let shares = MapperShares::new(location_shares, vsme_shares); @@ -1010,7 +1010,7 @@ mod test { }, ); - let rewards_info = default_rewards_info(EMISSIONS_POOL_1_HOUR, Duration::hours(1)); + let rewards_info = default_rewards_info(EMISSIONS_POOL_IN_BONES_1_HOUR, Duration::hours(1)); let total_rewards = get_scheduled_tokens_for_poc(rewards_info.epoch_emissions); @@ -1074,7 +1074,8 @@ mod test { .unwrap(); // set our rewards info - let rewards_info = default_rewards_info(EMISSIONS_POOL_24_HOURS, Duration::hours(24)); + let rewards_info = + default_rewards_info(EMISSIONS_POOL_IN_BONES_24_HOURS, Duration::hours(24)); let price_info = default_price_info(); assert_eq!(price_info.price_per_token, dec!(100000000)); @@ -1289,7 +1290,8 @@ mod test { let speedtest_avgs = SpeedtestAverages { averages }; - let rewards_info = default_rewards_info(EMISSIONS_POOL_24_HOURS, Duration::hours(24)); + let rewards_info = + default_rewards_info(EMISSIONS_POOL_IN_BONES_24_HOURS, Duration::hours(24)); let reward_shares = DataTransferAndPocAllocatedRewardBuckets::new_poc_only(rewards_info.epoch_emissions); @@ -1691,7 +1693,7 @@ mod test { // calculate the rewards for the sample group let mut owner_rewards = HashMap::::new(); - let rewards_info = default_rewards_info(EMISSIONS_POOL_1_HOUR, Duration::hours(1)); + let rewards_info = default_rewards_info(EMISSIONS_POOL_IN_BONES_1_HOUR, Duration::hours(1)); let reward_shares = DataTransferAndPocAllocatedRewardBuckets::new_poc_only(rewards_info.epoch_emissions); @@ -1877,7 +1879,7 @@ mod test { // calculate the rewards for the group let mut owner_rewards = HashMap::::new(); - let rewards_info = default_rewards_info(EMISSIONS_POOL_1_HOUR, Duration::hours(1)); + let rewards_info = default_rewards_info(EMISSIONS_POOL_IN_BONES_1_HOUR, Duration::hours(1)); let reward_shares = DataTransferAndPocAllocatedRewardBuckets::new_poc_only(rewards_info.epoch_emissions); @@ -2014,7 +2016,7 @@ mod test { // calculate the rewards for the group let mut owner_rewards = HashMap::::new(); - let rewards_info = default_rewards_info(EMISSIONS_POOL_1_HOUR, Duration::hours(1)); + let rewards_info = default_rewards_info(EMISSIONS_POOL_IN_BONES_1_HOUR, Duration::hours(1)); let reward_shares = DataTransferAndPocAllocatedRewardBuckets::new_poc_only(rewards_info.epoch_emissions); @@ -2151,7 +2153,7 @@ mod test { // calculate the rewards for the group let mut owner_rewards = HashMap::::new(); - let rewards_info = default_rewards_info(EMISSIONS_POOL_1_HOUR, Duration::hours(1)); + let rewards_info = default_rewards_info(EMISSIONS_POOL_IN_BONES_1_HOUR, Duration::hours(1)); let reward_shares = DataTransferAndPocAllocatedRewardBuckets::new_poc_only(rewards_info.epoch_emissions); @@ -2282,7 +2284,7 @@ mod test { let mut owner_rewards = HashMap::::new(); let duration = Duration::hours(1); let epoch = (now - duration)..now; - let rewards_info = default_rewards_info(EMISSIONS_POOL_1_HOUR, Duration::hours(1)); + let rewards_info = default_rewards_info(EMISSIONS_POOL_IN_BONES_1_HOUR, Duration::hours(1)); let reward_shares = DataTransferAndPocAllocatedRewardBuckets::new_poc_only(rewards_info.epoch_emissions); @@ -2341,7 +2343,7 @@ mod test { let now = Utc::now(); // We should never see any radio shares from owner2, since all of them are // less than or equal to zero. - let rewards_info = default_rewards_info(EMISSIONS_POOL_1_HOUR, Duration::hours(1)); + let rewards_info = default_rewards_info(EMISSIONS_POOL_IN_BONES_1_HOUR, Duration::hours(1)); let uuid_1 = Uuid::new_v4(); let uuid_2 = Uuid::new_v4(); @@ -2456,7 +2458,7 @@ mod test { #[tokio::test] async fn skip_empty_radio_rewards() { - let rewards_info = default_rewards_info(EMISSIONS_POOL_1_HOUR, Duration::hours(1)); + let rewards_info = default_rewards_info(EMISSIONS_POOL_IN_BONES_1_HOUR, Duration::hours(1)); let coverage_shares = CoverageShares { coverage_map: coverage_map::CoverageMapBuilder::default() .build(&BoostedHexes::default(), rewards_info.epoch_period.start), @@ -2476,7 +2478,7 @@ mod test { let sp1 = ServiceProvider::HeliumMobile; - let rewards_info = default_rewards_info(EMISSIONS_POOL_1_HOUR, Duration::hours(1)); + let rewards_info = default_rewards_info(EMISSIONS_POOL_IN_BONES_1_HOUR, Duration::hours(1)); let total_sp_rewards = service_provider::get_scheduled_tokens(rewards_info.epoch_emissions); let sp_reward_infos = ServiceProviderRewardInfos::new( @@ -2516,7 +2518,7 @@ mod test { let hnt_bone_price = dec!(1.0); let sp1 = ServiceProvider::HeliumMobile; - let rewards_info = default_rewards_info(EMISSIONS_POOL_1_HOUR, Duration::hours(1)); + let rewards_info = default_rewards_info(EMISSIONS_POOL_IN_BONES_1_HOUR, Duration::hours(1)); let total_sp_rewards_in_bones = dec!(1_0000_0000); let total_rewards_value_in_dc = hnt_bones_to_dc(total_sp_rewards_in_bones, hnt_bone_price); @@ -2559,11 +2561,11 @@ mod test { #[test] fn service_provider_reward_hip87_ex1() { - // hnt price from hip example and converted to bones + // price from hip example and converted to bones let hnt_bone_price = dec!(0.0001) / dec!(1_0000_0000); let sp1 = ServiceProvider::HeliumMobile; - let rewards_info = default_rewards_info(EMISSIONS_POOL_1_HOUR, Duration::hours(1)); + let rewards_info = default_rewards_info(EMISSIONS_POOL_IN_BONES_1_HOUR, Duration::hours(1)); let total_sp_rewards_in_bones = dec!(500_000_000) * dec!(1_0000_0000); @@ -2603,11 +2605,12 @@ mod test { #[test] fn service_provider_reward_hip87_ex2() { - // hnt price from hip example and converted to bones + // price from hip example and converted to bones let hnt_bone_price = dec!(0.0001) / dec!(1_0000_0000); let sp1 = ServiceProvider::HeliumMobile; - let rewards_info = default_rewards_info(EMISSIONS_POOL_1_HOUR, Duration::hours(24)); + let rewards_info = + default_rewards_info(EMISSIONS_POOL_IN_BONES_1_HOUR, Duration::hours(24)); let total_sp_rewards_in_bones = dec!(500_000_000) * dec!(1_0000_0000); let sp_reward_infos = ServiceProviderRewardInfos::new( diff --git a/mobile_verifier/tests/integrations/common/mod.rs b/mobile_verifier/tests/integrations/common/mod.rs index fcd53116b..aaeea9e60 100644 --- a/mobile_verifier/tests/integrations/common/mod.rs +++ b/mobile_verifier/tests/integrations/common/mod.rs @@ -5,6 +5,7 @@ use file_store::{ }; use futures::{stream, StreamExt}; use helium_crypto::PublicKeyBinary; +use helium_lib::token::Token; use helium_proto::services::{ mobile_config::NetworkKeyRole, poc_mobile::{ @@ -17,15 +18,13 @@ use helium_proto::services::{ use hex_assignments::{Assignment, HexAssignment, HexBoostData}; use mobile_config::{ boosted_hex_info::{BoostedHexInfo, BoostedHexInfoStream}, + client::sub_dao_client::SubDaoEpochRewardInfoResolver, client::{ authorization_client::AuthorizationVerifier, entity_client::EntityVerifier, hex_boosting_client::HexBoostingInfoResolver, ClientError, }, + sub_dao_epoch_reward_info::EpochRewardInfo, }; - -use helium_lib::token::Token; -use mobile_config::client::sub_dao_client::SubDaoEpochRewardInfoResolver; -use mobile_config::sub_dao_epoch_reward_info::EpochRewardInfo; use mobile_verifier::{ boosting_oracles::AssignedCoverageObjects, GatewayResolution, GatewayResolver, PriceInfo, }; @@ -39,6 +38,8 @@ use tonic::async_trait; pub const EPOCH_ADDRESS: &str = "112E7TxoNHV46M6tiPA8N1MkeMeQxc9ztb4JQLXBVAAUfq1kJLoF"; pub const SUB_DAO_ADDRESS: &str = "112NqN2WWMwtK29PMzRby62fDydBJfsCLkCAf392stdok48ovNT6"; +pub const EMISSIONS_POOL_IN_BONES_24_HOURS: u64 = 82_191_780_821_917; + #[derive(Debug, Clone)] #[allow(dead_code)] pub struct MockHexBoostingClient { diff --git a/mobile_verifier/tests/integrations/hex_boosting.rs b/mobile_verifier/tests/integrations/hex_boosting.rs index 54a56153c..4ebb0a0a9 100644 --- a/mobile_verifier/tests/integrations/hex_boosting.rs +++ b/mobile_verifier/tests/integrations/hex_boosting.rs @@ -1,6 +1,6 @@ use crate::common::{ self, default_price_info, default_rewards_info, MockFileSinkReceiver, MockHexBoostingClient, - RadioRewardV2Ext, + RadioRewardV2Ext, EMISSIONS_POOL_IN_BONES_24_HOURS, }; use chrono::{DateTime, Duration as ChronoDuration, Duration, Utc}; use file_store::{ @@ -57,7 +57,7 @@ async fn test_poc_with_boosted_hexes(pool: PgPool) -> anyhow::Result<()> { let (mobile_rewards_client, mut mobile_rewards) = common::create_file_sink(); let (speedtest_avg_client, _speedtest_avg_server) = common::create_file_sink(); - let reward_info = default_rewards_info(82_191_780_821_917, Duration::hours(24)); + let reward_info = default_rewards_info(EMISSIONS_POOL_IN_BONES_24_HOURS, Duration::hours(24)); let boost_period_length = Duration::days(30); @@ -327,7 +327,7 @@ async fn test_poc_boosted_hexes_thresholds_not_met(pool: PgPool) -> anyhow::Resu let hex_boosting_client = MockHexBoostingClient::new(boosted_hexes); - let reward_info = default_rewards_info(82_191_780_821_917, Duration::hours(24)); + let reward_info = default_rewards_info(EMISSIONS_POOL_IN_BONES_24_HOURS, Duration::hours(24)); let price_info = default_price_info(); @@ -395,7 +395,7 @@ async fn test_poc_with_multi_coverage_boosted_hexes(pool: PgPool) -> anyhow::Res let (mobile_rewards_client, mut mobile_rewards) = common::create_file_sink(); let (speedtest_avg_client, _speedtest_avg_server) = common::create_file_sink(); - let reward_info = default_rewards_info(82_191_780_821_917, Duration::hours(24)); + let reward_info = default_rewards_info(EMISSIONS_POOL_IN_BONES_24_HOURS, Duration::hours(24)); let boost_period_length = Duration::days(30); @@ -613,7 +613,7 @@ async fn test_expired_boosted_hex(pool: PgPool) -> anyhow::Result<()> { let (mobile_rewards_client, mut mobile_rewards) = common::create_file_sink(); let (speedtest_avg_client, _speedtest_avg_server) = common::create_file_sink(); - let reward_info = default_rewards_info(82_191_780_821_917, Duration::hours(24)); + let reward_info = default_rewards_info(EMISSIONS_POOL_IN_BONES_24_HOURS, Duration::hours(24)); let boost_period_length = Duration::days(30); // seed all the things @@ -736,7 +736,7 @@ async fn test_reduced_location_score_with_boosted_hexes(pool: PgPool) -> anyhow: let (mobile_rewards_client, mut mobile_rewards) = common::create_file_sink(); let (speedtest_avg_client, _speedtest_avg_server) = common::create_file_sink(); - let reward_info = default_rewards_info(82_191_780_821_917, Duration::hours(24)); + let reward_info = default_rewards_info(EMISSIONS_POOL_IN_BONES_24_HOURS, Duration::hours(24)); let boost_period_length = Duration::days(30); // seed all the things @@ -914,7 +914,7 @@ async fn test_distance_from_asserted_removes_boosting_but_not_location_trust( let (mobile_rewards_client, mut mobile_rewards) = common::create_file_sink(); let (speedtest_avg_client, _speedtest_avg_server) = common::create_file_sink(); - let reward_info = default_rewards_info(82_191_780_821_917, Duration::hours(24)); + let reward_info = default_rewards_info(EMISSIONS_POOL_IN_BONES_24_HOURS, Duration::hours(24)); let boost_period_length = Duration::days(30); // seed all the things @@ -1093,7 +1093,7 @@ async fn test_poc_with_cbrs_and_multi_coverage_boosted_hexes(pool: PgPool) -> an let (mobile_rewards_client, mut mobile_rewards) = common::create_file_sink(); let (speedtest_avg_client, _speedtest_avg_server) = common::create_file_sink(); - let reward_info = default_rewards_info(82_191_780_821_917, Duration::hours(24)); + let reward_info = default_rewards_info(EMISSIONS_POOL_IN_BONES_24_HOURS, Duration::hours(24)); let boost_period_length = Duration::days(30); diff --git a/mobile_verifier/tests/integrations/rewarder_mappers.rs b/mobile_verifier/tests/integrations/rewarder_mappers.rs index a7883da6c..6162fea78 100644 --- a/mobile_verifier/tests/integrations/rewarder_mappers.rs +++ b/mobile_verifier/tests/integrations/rewarder_mappers.rs @@ -1,4 +1,6 @@ -use crate::common::{self, default_rewards_info, MockFileSinkReceiver}; +use crate::common::{ + self, default_rewards_info, MockFileSinkReceiver, EMISSIONS_POOL_IN_BONES_24_HOURS, +}; use chrono::{DateTime, Duration as ChronoDuration, Duration, Utc}; use file_store::{ mobile_subscriber::{SubscriberLocationIngestReport, SubscriberLocationReq}, @@ -29,7 +31,7 @@ const HOTSPOT_1: &str = "112NqN2WWMwtK29PMzRby62fDydBJfsCLkCAf392stdok48ovNT6"; async fn test_mapper_rewards(pool: PgPool) -> anyhow::Result<()> { let (mobile_rewards_client, mut mobile_rewards) = common::create_file_sink(); - let reward_info = default_rewards_info(82_191_780_821_917, Duration::hours(24)); + let reward_info = default_rewards_info(EMISSIONS_POOL_IN_BONES_24_HOURS, Duration::hours(24)); // seed db let mut txn = pool.clone().begin().await?; @@ -108,7 +110,7 @@ async fn test_subscriber_can_only_earn_verification_mapping_if_earned_disco_mapp ) -> anyhow::Result<()> { let (mobile_rewards_client, mut mobile_rewards) = common::create_file_sink(); - let reward_info = default_rewards_info(82_191_780_821_917, Duration::hours(24)); + let reward_info = default_rewards_info(EMISSIONS_POOL_IN_BONES_24_HOURS, Duration::hours(24)); let mut txn = pool.begin().await?; let sub_loc_report = SubscriberLocationIngestReport { diff --git a/mobile_verifier/tests/integrations/rewarder_poc_dc.rs b/mobile_verifier/tests/integrations/rewarder_poc_dc.rs index 4addb3007..8a8ffb1c1 100644 --- a/mobile_verifier/tests/integrations/rewarder_poc_dc.rs +++ b/mobile_verifier/tests/integrations/rewarder_poc_dc.rs @@ -2,7 +2,7 @@ use std::ops::Range; use crate::common::{ self, default_price_info, default_rewards_info, MockFileSinkReceiver, MockHexBoostingClient, - RadioRewardV2Ext, + RadioRewardV2Ext, EMISSIONS_POOL_IN_BONES_24_HOURS, }; use chrono::{DateTime, Duration as ChronoDuration, Duration, Utc}; use file_store::{ @@ -48,7 +48,7 @@ async fn test_poc_and_dc_rewards(pool: PgPool) -> anyhow::Result<()> { let (mobile_rewards_client, mut mobile_rewards) = common::create_file_sink(); let (speedtest_avg_client, _speedtest_avg_server) = common::create_file_sink(); - let reward_info = default_rewards_info(82_191_780_821_917, Duration::hours(24)); + let reward_info = default_rewards_info(EMISSIONS_POOL_IN_BONES_24_HOURS, Duration::hours(24)); // seed all the things let mut txn = pool.clone().begin().await?; @@ -153,7 +153,7 @@ async fn test_qualified_wifi_poc_rewards(pool: PgPool) -> anyhow::Result<()> { let (mobile_rewards_client, mut mobile_rewards) = common::create_file_sink(); let (speedtest_avg_client, _speedtest_avg_server) = common::create_file_sink(); - let reward_info = default_rewards_info(82_191_780_821_917, Duration::hours(24)); + let reward_info = default_rewards_info(EMISSIONS_POOL_IN_BONES_24_HOURS, Duration::hours(24)); let pubkey: PublicKeyBinary = HOTSPOT_3.to_string().parse().unwrap(); // wifi hotspot diff --git a/mobile_verifier/tests/integrations/rewarder_sp_rewards.rs b/mobile_verifier/tests/integrations/rewarder_sp_rewards.rs index 0eecc8074..7c66ec444 100644 --- a/mobile_verifier/tests/integrations/rewarder_sp_rewards.rs +++ b/mobile_verifier/tests/integrations/rewarder_sp_rewards.rs @@ -14,7 +14,9 @@ use rust_decimal::prelude::*; use rust_decimal_macros::dec; use sqlx::{PgPool, Postgres, Transaction}; -use crate::common::{self, default_rewards_info, MockFileSinkReceiver}; +use crate::common::{ + self, default_rewards_info, MockFileSinkReceiver, EMISSIONS_POOL_IN_BONES_24_HOURS, +}; use mobile_config::client::{carrier_service_client::CarrierServiceVerifier, ClientError}; use mobile_verifier::{data_session, reward_shares, rewarder, service_provider}; @@ -75,7 +77,7 @@ async fn test_service_provider_rewards(pool: PgPool) -> anyhow::Result<()> { let carrier_client = MockCarrierServiceClient::new(valid_sps); let (mobile_rewards_client, mut mobile_rewards) = common::create_file_sink(); - let reward_info = default_rewards_info(82_191_780_821_917, Duration::hours(24)); + let reward_info = default_rewards_info(EMISSIONS_POOL_IN_BONES_24_HOURS, Duration::hours(24)); // seed db with test specific data let mut txn = pool.clone().begin().await?; @@ -140,7 +142,7 @@ async fn test_service_provider_rewards_halt_on_invalid_sp(pool: PgPool) -> anyho valid_sps.insert(PAYER_1.to_string(), SP_1.to_string()); let carrier_client = MockCarrierServiceClient::new(valid_sps); - let reward_info = default_rewards_info(82_191_780_821_917, Duration::hours(24)); + let reward_info = default_rewards_info(EMISSIONS_POOL_IN_BONES_24_HOURS, Duration::hours(24)); let mut txn = pool.clone().begin().await?; seed_hotspot_data_invalid_sp(reward_info.epoch_period.end, &mut txn).await?; @@ -187,7 +189,7 @@ async fn test_service_provider_promotion_rewards(pool: PgPool) -> anyhow::Result ], }]); - let reward_info = default_rewards_info(82_191_780_821_917, Duration::hours(24)); + let reward_info = default_rewards_info(EMISSIONS_POOL_IN_BONES_24_HOURS, Duration::hours(24)); let (mobile_rewards_client, mut mobile_rewards) = common::create_file_sink(); @@ -254,7 +256,7 @@ async fn test_service_provider_promotion_rewards(pool: PgPool) -> anyhow::Result - 50_999 // 85% service provider rewards rounded down - 8_998 // 15% service provider promotions - 8_998 // matched promotion - + 2; // unexpected rounding - TODO investigate + + 2; // rounding assert_eq!(unallocated.amount, expected_unallocated);