From 9bce823e40a893f1c00193f6342cbaa867b7fbe1 Mon Sep 17 00:00:00 2001 From: Andrew McKenzie Date: Wed, 18 Dec 2024 15:04:39 +0000 Subject: [PATCH] misc tweaks --- iot_config/src/client/sub_dao_client.rs | 1 + iot_verifier/src/reward_share.rs | 40 +++++++++++-------- iot_verifier/src/rewarder.rs | 3 +- iot_verifier/tests/integrations/common/mod.rs | 12 ++++++ .../tests/integrations/rewarder_operations.rs | 6 ++- .../tests/integrations/rewarder_oracles.rs | 6 ++- .../tests/integrations/rewarder_poc_dc.rs | 11 +++-- mobile_config/src/client/sub_dao_client.rs | 1 + 8 files changed, 53 insertions(+), 27 deletions(-) diff --git a/iot_config/src/client/sub_dao_client.rs b/iot_config/src/client/sub_dao_client.rs index c079e8686..000be0d00 100644 --- a/iot_config/src/client/sub_dao_client.rs +++ b/iot_config/src/client/sub_dao_client.rs @@ -75,6 +75,7 @@ impl SubDaoEpochRewardInfoResolver for SubDaoClient { Err(status) if status.code() == tonic::Code::NotFound => None, Err(status) => Err(status)?, }; + tracing::debug!(?response, "fetched subdao epoch info"); Ok(response) } } diff --git a/iot_verifier/src/reward_share.rs b/iot_verifier/src/reward_share.rs index 7698a346f..9df9812fc 100644 --- a/iot_verifier/src/reward_share.rs +++ b/iot_verifier/src/reward_share.rs @@ -429,11 +429,14 @@ mod test { use super::*; use crate::{reward_share, PriceInfo}; use chrono::Duration; + use helium_lib::token::Token; use iot_config::sub_dao_epoch_reward_info::EpochRewardInfo; pub const EPOCH_ADDRESS: &str = "112E7TxoNHV46M6tiPA8N1MkeMeQxc9ztb4JQLXBVAAUfq1kJLoF"; pub const SUB_DAO_ADDRESS: &str = "112NqN2WWMwtK29PMzRby62fDydBJfsCLkCAf392stdok48ovNT6"; + const EMISSIONS_POOL_IN_BONES_10_MINUTES: u64 = 618_340_943_683; + fn reward_shares_in_dec( beacon_shares: Decimal, witness_shares: Decimal, @@ -452,7 +455,6 @@ mod test { /// returns the equiv dc value for a specified hnt bones amount pub fn hnt_bones_to_dc(hnt_amount: Decimal, hnt_bones_price: Decimal) -> Decimal { - // use the price per bones to get the value of our bones in DC let value = hnt_amount * hnt_bones_price; (value / (*DC_USD_PRICE)).round_dp_with_strategy(0, RoundingStrategy::ToNegativeInfinity) } @@ -510,6 +512,20 @@ mod test { assert_eq!(dec!(7_000_000_000_000), v); } + #[test] + fn test_price_conversion() { + let token = Token::Hnt; + let hnt_dollar_price = dec!(1.0); + let hnt_price_from_pricer = 100000000_u64; + let hnt_dollar_bone_price = dec!(0.00000001); + + let hnt_price = PriceInfo::new(hnt_price_from_pricer, token.decimals()); + + assert_eq!(hnt_dollar_bone_price, hnt_price.price_per_bone); + assert_eq!(hnt_price_from_pricer, hnt_price.price_in_bones); + assert_eq!(hnt_dollar_price, hnt_price.price_per_token); + } + #[tokio::test] // test reward distribution where there is a fixed dc spend per gateway // with the total dc spend across all gateways being significantly lower than the @@ -537,7 +553,8 @@ mod test { .parse() .expect("failed gw6 parse"); - let reward_info = default_rewards_info(618_340_943_683, Duration::minutes(10)); + let reward_info = + default_rewards_info(EMISSIONS_POOL_IN_BONES_10_MINUTES, Duration::minutes(10)); let total_data_transfer_tokens_for_period = get_scheduled_dc_tokens(reward_info.epoch_emissions); println!("total data transfer scheduled tokens: {total_data_transfer_tokens_for_period}"); @@ -751,7 +768,8 @@ mod test { .parse() .expect("failed gw6 parse"); - let reward_info = default_rewards_info(618_340_943_683, Duration::minutes(10)); + let reward_info = + default_rewards_info(EMISSIONS_POOL_IN_BONES_10_MINUTES, Duration::minutes(10)); let total_data_transfer_tokens_for_period = get_scheduled_dc_tokens(reward_info.epoch_emissions); println!("total data transfer scheduled tokens: {total_data_transfer_tokens_for_period}"); @@ -950,7 +968,8 @@ mod test { .parse() .expect("failed gw6 parse"); - let reward_info = default_rewards_info(618_340_943_683, Duration::minutes(10)); + let reward_info = + default_rewards_info(EMISSIONS_POOL_IN_BONES_10_MINUTES, Duration::minutes(10)); let total_data_transfer_tokens_for_period = get_scheduled_dc_tokens(reward_info.epoch_emissions); println!("total_data_transfer_tokens_for_period: {total_data_transfer_tokens_for_period}"); @@ -1131,17 +1150,4 @@ mod test { let hnt_dc_amt = hnt_bones_to_dc(dc_hnt_amt, hnt_bone_price); assert_eq!(hnt_dc_amt, dc_amount); } - - #[test] - fn test_price_conversion() { - let hnt_dollar_price = dec!(1.0); - let hnt_dollar_bone_price = dec!(0.00000001); - let hnt_price_from_pricer = 100000000_u64; - let pricer_decimals = 8; - let hnt_price = PriceInfo::new(hnt_price_from_pricer, pricer_decimals); - - assert_eq!(hnt_dollar_bone_price, hnt_price.price_per_bone); - assert_eq!(hnt_price_from_pricer, hnt_price.price_in_bones); - assert_eq!(hnt_dollar_price, hnt_price.price_per_token); - } } diff --git a/iot_verifier/src/rewarder.rs b/iot_verifier/src/rewarder.rs index 509ab31d0..fa833a6d1 100644 --- a/iot_verifier/src/rewarder.rs +++ b/iot_verifier/src/rewarder.rs @@ -7,8 +7,7 @@ use chrono::{DateTime, TimeZone, Utc}; use db_store::meta; use file_store::{file_sink, traits::TimestampEncode}; use futures::future::LocalBoxFuture; -use helium_lib::keypair::Pubkey; -use helium_lib::token::Token; +use helium_lib::{keypair::Pubkey, token::Token}; use helium_proto::{ reward_manifest::RewardData::IotRewardData, services::poc_lora::{ diff --git a/iot_verifier/tests/integrations/common/mod.rs b/iot_verifier/tests/integrations/common/mod.rs index 279305201..fc92800f6 100644 --- a/iot_verifier/tests/integrations/common/mod.rs +++ b/iot_verifier/tests/integrations/common/mod.rs @@ -24,17 +24,21 @@ use iot_verifier::{ last_beacon_reciprocity::LastBeaconReciprocity, last_witness::LastWitness, poc_report::{InsertBindings, IotStatus, Report, ReportType}, + PriceInfo, }; +use helium_lib::token::Token; use iot_config::sub_dao_epoch_reward_info::EpochRewardInfo; use prost::Message; use rust_decimal::Decimal; +use rust_decimal_macros::dec; use sqlx::{PgPool, Postgres, Transaction}; use std::{self, ops::DerefMut, str::FromStr}; use tokio::{sync::mpsc::error::TryRecvError, sync::Mutex, time::timeout}; pub const EPOCH_ADDRESS: &str = "112E7TxoNHV46M6tiPA8N1MkeMeQxc9ztb4JQLXBVAAUfq1kJLoF"; pub const SUB_DAO_ADDRESS: &str = "112NqN2WWMwtK29PMzRby62fDydBJfsCLkCAf392stdok48ovNT6"; +pub const EMISSIONS_POOL_IN_BONES_24_HOURS: u64 = 89_041_095_890_411; pub fn default_rewards_info(total_emissions: u64, epoch_duration: Duration) -> EpochRewardInfo { let now = Utc::now(); @@ -48,6 +52,14 @@ pub fn default_rewards_info(total_emissions: u64, epoch_duration: Duration) -> E } } +pub fn default_price_info() -> PriceInfo { + let token = Token::Hnt; + let price_info = PriceInfo::new(1, token.decimals()); + assert_eq!(price_info.price_per_token, dec!(0.00000001)); + assert_eq!(price_info.price_per_bone, dec!(0.0000000000000001)); + price_info +} + pub fn create_file_sink( ) -> (FileSinkClient, MockFileSinkReceiver) { let (tx, rx) = tokio::sync::mpsc::channel(10); diff --git a/iot_verifier/tests/integrations/rewarder_operations.rs b/iot_verifier/tests/integrations/rewarder_operations.rs index 4cafe70bc..c0326ccbb 100644 --- a/iot_verifier/tests/integrations/rewarder_operations.rs +++ b/iot_verifier/tests/integrations/rewarder_operations.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::Duration; use helium_proto::services::poc_lora::{IotRewardShare, OperationalReward}; use iot_verifier::{reward_share, rewarder}; @@ -9,7 +11,7 @@ use rust_decimal_macros::dec; async fn test_operations() -> anyhow::Result<()> { let (iot_rewards_client, mut iot_rewards) = common::create_file_sink(); - let reward_info = default_rewards_info(89_041_095_890_411, Duration::hours(24)); + let reward_info = default_rewards_info(EMISSIONS_POOL_IN_BONES_24_HOURS, Duration::hours(24)); let (_, rewards) = tokio::join!( rewarder::reward_operational(&iot_rewards_client, &reward_info), diff --git a/iot_verifier/tests/integrations/rewarder_oracles.rs b/iot_verifier/tests/integrations/rewarder_oracles.rs index fa24759f4..9aeb8766f 100644 --- a/iot_verifier/tests/integrations/rewarder_oracles.rs +++ b/iot_verifier/tests/integrations/rewarder_oracles.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::Duration; use helium_proto::services::poc_lora::{IotRewardShare, UnallocatedReward}; use iot_verifier::{reward_share, rewarder}; @@ -10,7 +12,7 @@ use sqlx::PgPool; async fn test_oracles(_pool: PgPool) -> anyhow::Result<()> { let (iot_rewards_client, mut iot_rewards) = common::create_file_sink(); - let reward_info = default_rewards_info(89_041_095_890_411, Duration::hours(24)); + let reward_info = default_rewards_info(EMISSIONS_POOL_IN_BONES_24_HOURS, Duration::hours(24)); let (_, rewards) = tokio::join!( rewarder::reward_oracles(&iot_rewards_client, &reward_info), diff --git a/iot_verifier/tests/integrations/rewarder_poc_dc.rs b/iot_verifier/tests/integrations/rewarder_poc_dc.rs index ce5ae7d36..1dffd7353 100644 --- a/iot_verifier/tests/integrations/rewarder_poc_dc.rs +++ b/iot_verifier/tests/integrations/rewarder_poc_dc.rs @@ -1,4 +1,7 @@ -use crate::common::{self, default_rewards_info, MockFileSinkReceiver}; +use crate::common::{ + self, default_price_info, default_rewards_info, MockFileSinkReceiver, + EMISSIONS_POOL_IN_BONES_24_HOURS, +}; use chrono::{DateTime, Duration as ChronoDuration, Duration, Utc}; use helium_crypto::PublicKeyBinary; use helium_proto::services::poc_lora::{ @@ -7,7 +10,7 @@ use helium_proto::services::poc_lora::{ use iot_verifier::{ poc_report::ReportType, reward_share::{self, GatewayDCShare, GatewayPocShare}, - rewarder, PriceInfo, + rewarder, }; use prost::Message; use rust_decimal::{prelude::ToPrimitive, Decimal, RoundingStrategy}; @@ -24,9 +27,9 @@ const HOTSPOT_4: &str = "11eX55faMbqZB7jzN4p67m6w7ScPMH6ubnvCjCPLh72J49PaJEL"; async fn test_poc_and_dc_rewards(pool: PgPool) -> anyhow::Result<()> { let (iot_rewards_client, mut iot_rewards) = common::create_file_sink(); - let reward_info = default_rewards_info(89_041_095_890_411, Duration::hours(24)); + let reward_info = default_rewards_info(EMISSIONS_POOL_IN_BONES_24_HOURS, Duration::hours(24)); - let price_info = PriceInfo::new(1, 8); + let price_info = default_price_info(); // seed all the things let mut txn = pool.clone().begin().await?; diff --git a/mobile_config/src/client/sub_dao_client.rs b/mobile_config/src/client/sub_dao_client.rs index b33bf5678..c14a105d3 100644 --- a/mobile_config/src/client/sub_dao_client.rs +++ b/mobile_config/src/client/sub_dao_client.rs @@ -70,6 +70,7 @@ impl SubDaoEpochRewardInfoResolver for SubDaoClient { Err(status) if status.code() == tonic::Code::NotFound => None, Err(status) => Err(status)?, }; + tracing::debug!(?response, "fetched subdao epoch info"); Ok(response) } }