Skip to content

Commit

Permalink
tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
andymck committed Nov 19, 2024
1 parent 2142ab7 commit 721b20b
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 41 deletions.
6 changes: 4 additions & 2 deletions mobile_config/src/client/sub_dao_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ use super::{call_with_retry, ClientError, Settings};
use crate::sub_dao_epoch_reward_info::ResolvedSubDaoEpochRewardInfo;
use file_store::traits::MsgVerify;
use helium_crypto::{Keypair, PublicKey, PublicKeyBinary, Sign};
use helium_proto::services::mobile_config::SubDaoEpochRewardInfoReqV1;
use helium_proto::{
services::{mobile_config, Channel},
services::{
mobile_config::{self, SubDaoEpochRewardInfoReqV1},
Channel,
},
Message,
};
use std::{error::Error, sync::Arc, time::Duration};
Expand Down
18 changes: 13 additions & 5 deletions mobile_verifier/src/cli/reward_from_db.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
use crate::{heartbeats::HeartbeatReward, reward_shares::{
get_scheduled_tokens_for_poc, CoverageShares, DataTransferAndPocAllocatedRewardBuckets,
}, rewarder::boosted_hex_eligibility::BoostedHexEligibility, sp_boosted_rewards_bans::BannedRadios, speedtests_average::SpeedtestAverages, Settings, MOBILE_SUB_DAO_ONCHAIN_ADDRESS};
use crate::{
heartbeats::HeartbeatReward,
reward_shares::{
get_scheduled_tokens_for_poc, CoverageShares, DataTransferAndPocAllocatedRewardBuckets,
},
rewarder::boosted_hex_eligibility::BoostedHexEligibility,
sp_boosted_rewards_bans::BannedRadios,
speedtests_average::SpeedtestAverages,
Settings, MOBILE_SUB_DAO_ONCHAIN_ADDRESS,
};
use anyhow::Result;
use helium_crypto::{PublicKey, PublicKeyBinary};
use helium_proto::services::poc_mobile as proto;
Expand All @@ -24,7 +31,7 @@ impl Cmd {

let reward_epoch = self.reward_epoch;

let sub_dao_pubkey = PublicKeyBinary::from_str(&MOBILE_SUB_DAO_ONCHAIN_ADDRESS)?;
let sub_dao_pubkey = PublicKeyBinary::from_str(MOBILE_SUB_DAO_ONCHAIN_ADDRESS)?;
let sub_dao_rewards_client = SubDaoClient::from_settings(&settings.config_client)?;
let reward_info = sub_dao_rewards_client
.resolve_info(&sub_dao_pubkey, reward_epoch)
Expand All @@ -46,7 +53,8 @@ impl Cmd {

let heartbeats = HeartbeatReward::validated(&pool, &reward_info.epoch_period);
let speedtest_averages =
SpeedtestAverages::aggregate_epoch_averages(reward_info.epoch_period.end, &pool).await?;
SpeedtestAverages::aggregate_epoch_averages(reward_info.epoch_period.end, &pool)
.await?;

let reward_shares = CoverageShares::new(
&pool,
Expand Down
10 changes: 6 additions & 4 deletions mobile_verifier/src/reward_shares.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,11 @@ impl TransferRewards {
hotspot_key: hotspot_key.into(),
dc_transfer_reward,
rewardable_bytes: reward.bytes_rewarded,
price: (self.hnt_bone_price * dec!(1_0000_0000) * dec!(1_0000_0000))
.to_u64()
.unwrap_or_default(),
price: (self.hnt_bone_price
* dec!(1_0000_0000)
* dec!(1_0000_0000))
.to_u64()
.unwrap_or_default(),
},
)),
},
Expand Down Expand Up @@ -2345,7 +2347,7 @@ mod test {
.round_dp_with_strategy(0, RoundingStrategy::ToZero)
.to_u64()
.unwrap_or(0);
assert_eq!(unallocated_sp_reward_amount, 490_00_000_000_000_000);
assert_eq!(unallocated_sp_reward_amount, 49_000_000_000_000_000);
}

#[test]
Expand Down
19 changes: 15 additions & 4 deletions mobile_verifier/src/rewarder.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
use crate::{boosting_oracles::db::check_for_unprocessed_data_sets, coverage, data_session, heartbeats::{self, HeartbeatReward}, radio_threshold, reward_shares::{
self, CalculatedPocRewardShares, CoverageShares, DataTransferAndPocAllocatedRewardBuckets,
MapperShares, TransferRewards,
}, service_provider::{self, ServiceProviderDCSessions, ServiceProviderPromotions}, sp_boosted_rewards_bans, speedtests, speedtests_average::SpeedtestAverages, subscriber_location, subscriber_verified_mapping_event, telemetry, Settings, MOBILE_SUB_DAO_ONCHAIN_ADDRESS};
use crate::{
boosting_oracles::db::check_for_unprocessed_data_sets,
coverage, data_session,
heartbeats::{self, HeartbeatReward},
radio_threshold,
reward_shares::{
self, CalculatedPocRewardShares, CoverageShares, DataTransferAndPocAllocatedRewardBuckets,
MapperShares, TransferRewards,
},
service_provider::{self, ServiceProviderDCSessions, ServiceProviderPromotions},
sp_boosted_rewards_bans, speedtests,
speedtests_average::SpeedtestAverages,
subscriber_location, subscriber_verified_mapping_event, telemetry, Settings,
MOBILE_SUB_DAO_ONCHAIN_ADDRESS,
};
use anyhow::bail;
use chrono::{DateTime, TimeZone, Utc};
use db_store::meta;
Expand Down
24 changes: 1 addition & 23 deletions mobile_verifier/src/service_provider/mod.rs
Original file line number Diff line number Diff line change
@@ -1,39 +1,17 @@
use chrono::{Duration, Utc};
pub use dc_sessions::{get_dc_sessions, ServiceProviderDCSessions};
use helium_crypto::PublicKeyBinary;
use mobile_config::sub_dao_epoch_reward_info::ResolvedSubDaoEpochRewardInfo;
pub use promotions::{get_promotions, ServiceProviderPromotions};
pub use reward::ServiceProviderRewardInfos;
use rust_decimal::Decimal;
use std::str::FromStr;

mod dc_sessions;
mod promotions;
mod reward;

pub const EPOCH_ADDRESS: &str = "112E7TxoNHV46M6tiPA8N1MkeMeQxc9ztb4JQLXBVAAUfq1kJLoF";
pub const SUB_DAO_ADDRESS: &str = "112NqN2WWMwtK29PMzRby62fDydBJfsCLkCAf392stdok48ovNT6";

// This type is used in lieu of the helium_proto::ServiceProvider enum so we can
// handle more than a single value without adding a hard deploy dependency to
// mobile-verifier when a new carrier is added..
pub type ServiceProviderId = i32;

pub fn get_scheduled_tokens(total_emission_pool: Decimal) -> rust_decimal::Decimal {
pub fn get_scheduled_tokens(total_emission_pool: Decimal) -> Decimal {
crate::reward_shares::get_scheduled_tokens_for_service_providers(total_emission_pool)
}

pub fn default_rewards_info(
total_emissions: u64,
epoch_duration: Duration,
) -> ResolvedSubDaoEpochRewardInfo {
let now = Utc::now();
ResolvedSubDaoEpochRewardInfo {
epoch: 1,
epoch_address: PublicKeyBinary::from_str(EPOCH_ADDRESS).unwrap(),
sub_dao_address: PublicKeyBinary::from_str(SUB_DAO_ADDRESS).unwrap(),
epoch_period: (now - epoch_duration)..now,
epoch_emissions: Decimal::from(total_emissions),
rewards_issued_at: now,
}
}
21 changes: 20 additions & 1 deletion mobile_verifier/src/service_provider/reward.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,32 @@ impl DecimalRoundingExt for Decimal {
#[cfg(test)]
mod tests {
use chrono::{Duration, Utc};
use helium_crypto::PublicKeyBinary;
use helium_proto::services::poc_mobile::{MobileRewardShare, PromotionReward};
use std::str::FromStr;

use crate::service_provider;

use super::*;

pub const EPOCH_ADDRESS: &str = "112E7TxoNHV46M6tiPA8N1MkeMeQxc9ztb4JQLXBVAAUfq1kJLoF";
pub const SUB_DAO_ADDRESS: &str = "112NqN2WWMwtK29PMzRby62fDydBJfsCLkCAf392stdok48ovNT6";

pub fn default_rewards_info(
total_emissions: u64,
epoch_duration: Duration,
) -> ResolvedSubDaoEpochRewardInfo {
let now = Utc::now();
ResolvedSubDaoEpochRewardInfo {
epoch: 1,
epoch_address: PublicKeyBinary::from_str(EPOCH_ADDRESS).unwrap(),
sub_dao_address: PublicKeyBinary::from_str(SUB_DAO_ADDRESS).unwrap(),
epoch_period: (now - epoch_duration)..now,
epoch_emissions: Decimal::from(total_emissions),
rewards_issued_at: now,
}
}

#[test]
fn no_promotions() {
let reward_info = default_rewards_info(82_191_780_821_917, Duration::hours(24));
Expand Down Expand Up @@ -653,7 +673,6 @@ mod tests {
assert_eq!(unallocated, 2);
}

use crate::service_provider::default_rewards_info;
use proptest::prelude::*;

prop_compose! {
Expand Down
4 changes: 2 additions & 2 deletions mobile_verifier/src/telemetry.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{rewarder,};
use crate::rewarder;
use chrono::{DateTime, Utc};
use sqlx::{Pool, Postgres};
use mobile_config::EpochPeriod;
use sqlx::{Pool, Postgres};

const LAST_REWARDED_END_TIME: &str = "last_rewarded_end_time";
const DATA_TRANSFER_REWARDS_SCALE: &str = "data_transfer_rewards_scale";
Expand Down

0 comments on commit 721b20b

Please sign in to comment.