Skip to content

Commit

Permalink
centralise emission values
Browse files Browse the repository at this point in the history
  • Loading branch information
andymck committed Dec 17, 2024
1 parent ff6c7eb commit c3f7591
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 45 deletions.
2 changes: 1 addition & 1 deletion mobile_config/src/sub_dao_epoch_reward_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
45 changes: 24 additions & 21 deletions mobile_verifier/src/reward_shares.rs
Original file line number Diff line number Diff line change
Expand Up @@ -793,8 +793,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 {
Expand Down Expand Up @@ -836,8 +836,7 @@ mod test {
}

fn default_price_info() -> PriceInfo {
let token = Token::Hnt;
PriceInfo::new(10000000000000000, token.decimals())
PriceInfo::new(10000000000000000, Token::Hnt.decimals())
}

#[test]
Expand Down Expand Up @@ -902,7 +901,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);
Expand Down Expand Up @@ -980,7 +980,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);

Expand Down Expand Up @@ -1044,7 +1044,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));
Expand Down Expand Up @@ -1259,7 +1260,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);
Expand Down Expand Up @@ -1661,7 +1663,7 @@ mod test {
// calculate the rewards for the sample group
let mut owner_rewards = HashMap::<PublicKeyBinary, u64>::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);
Expand Down Expand Up @@ -1847,7 +1849,7 @@ mod test {
// calculate the rewards for the group
let mut owner_rewards = HashMap::<PublicKeyBinary, u64>::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);
Expand Down Expand Up @@ -1984,7 +1986,7 @@ mod test {
// calculate the rewards for the group
let mut owner_rewards = HashMap::<PublicKeyBinary, u64>::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);
Expand Down Expand Up @@ -2121,7 +2123,7 @@ mod test {
// calculate the rewards for the group
let mut owner_rewards = HashMap::<PublicKeyBinary, u64>::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);
Expand Down Expand Up @@ -2252,7 +2254,7 @@ mod test {
let mut owner_rewards = HashMap::<PublicKeyBinary, u64>::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);
Expand Down Expand Up @@ -2311,7 +2313,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();
Expand Down Expand Up @@ -2426,7 +2428,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),
Expand All @@ -2446,7 +2448,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(
Expand Down Expand Up @@ -2486,7 +2488,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);
Expand Down Expand Up @@ -2529,11 +2531,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);

Expand Down Expand Up @@ -2573,11 +2575,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(
Expand Down
9 changes: 5 additions & 4 deletions mobile_verifier/tests/integrations/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -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,
};
Expand All @@ -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 {
Expand Down
16 changes: 8 additions & 8 deletions mobile_verifier/tests/integrations/hex_boosting.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down
8 changes: 5 additions & 3 deletions mobile_verifier/tests/integrations/rewarder_mappers.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down Expand Up @@ -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?;
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions mobile_verifier/tests/integrations/rewarder_poc_dc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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?;
Expand Down Expand Up @@ -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

Expand Down
12 changes: 7 additions & 5 deletions mobile_verifier/tests/integrations/rewarder_sp_rewards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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?;
Expand Down Expand Up @@ -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?;
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit c3f7591

Please sign in to comment.