Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -170,5 +170,6 @@ anchor-lang = { git = "https://github.com/madninja/anchor.git", branch = "madnin
# helium-proto = { path = "../proto" }
# beacon = { path = "../proto/beacon" }

# [patch.'https://github.com/helium/proto']
# helium-proto = { git = "https://www.github.com/helium/proto.git", branch = "dcyoung/radio-usage-stats-req-v2" }
[patch.'https://github.com/helium/proto']
helium-proto = { git = "https://www.github.com/helium/proto.git", branch = "connor/missing-bones-sp-rewards" }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert

msg-signature = {git = "https://www.github.com/helium/proto.git", branch = "connor/missing-bones-sp-rewards"}
6 changes: 3 additions & 3 deletions mobile_verifier/src/reward_shares.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ mod radio_reward_v2;

/// Maximum amount of the total emissions pool allocated for data transfer
/// rewards
const MAX_DATA_TRANSFER_REWARDS_PERCENT: Decimal = dec!(0.7);
pub const MAX_DATA_TRANSFER_REWARDS_PERCENT: Decimal = dec!(0.7);

/// Percentage of total emissions pool allocated for proof of coverage
const POC_REWARDS_PERCENT: Decimal = dec!(0.0);
pub const POC_REWARDS_PERCENT: Decimal = dec!(0.0);

/// The fixed price of a mobile data credit
const DC_USD_PRICE: Decimal = dec!(0.00001);
Expand All @@ -42,7 +42,7 @@ const DC_USD_PRICE: Decimal = dec!(0.00001);
pub const DEFAULT_PREC: u32 = 15;

// Percent of total emissions allocated for service provider rewards
const SERVICE_PROVIDER_PERCENT: Decimal = dec!(0.24);
pub const SERVICE_PROVIDER_PERCENT: Decimal = dec!(0.24);

// Fixed price of service provider rewards to be given to Helium Mobile Service Rewards
pub const HELIUM_MOBILE_SERVICE_REWARD_BONES: u64 = 45_000_000_000;
Expand Down
68 changes: 45 additions & 23 deletions mobile_verifier/src/rewarder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,7 @@ where
reward_info.epoch_emissions,
);

// process rewards for poc and data transfer
let poc_dc_shares = reward_poc_and_dc(
let poc_dc_shares = distribute_rewards(
&self.pool,
&self.hex_service_client,
self.mobile_rewards.clone(),
Expand All @@ -281,9 +280,6 @@ where
)
.await?;

// process rewards for service providers
reward_service_providers(self.mobile_rewards.clone(), &reward_info).await?;

self.speedtest_averages.commit().await?;
let written_files = self.mobile_rewards.commit().await?.await??;

Expand Down Expand Up @@ -349,13 +345,51 @@ where
}
}

pub async fn reward_poc_and_dc(
pub async fn distribute_rewards(
pool: &Pool<Postgres>,
hex_service_client: &impl HexBoostingInfoResolver,
mobile_rewards: FileSinkClient<proto::MobileRewardShare>,
reward_info: &EpochRewardInfo,
price_info: PriceInfo,
) -> anyhow::Result<CalculatedPocRewardShares> {
// process rewards for poc and data transfer
let (poc_dc_shares, poc_unallocated_amount) = reward_poc_and_dc(
pool,
hex_service_client,
mobile_rewards.clone(),
reward_info,
price_info.clone(),
)
.await?;

// process rewards for service providers
let sp_unallocated_amount =
reward_service_providers(mobile_rewards.clone(), reward_info).await?;

// write combined poc and sp unallocated reward
let total_unallocated_amount = (poc_unallocated_amount + sp_unallocated_amount)
.round_dp_with_strategy(0, RoundingStrategy::ToZero)
.to_u64()
.unwrap_or(0);

write_unallocated_reward(
mobile_rewards,
UnallocatedRewardType::PocAndServiceProvider,
total_unallocated_amount,
reward_info,
)
.await?;

Ok(poc_dc_shares)
}

pub async fn reward_poc_and_dc(
pool: &Pool<Postgres>,
hex_service_client: &impl HexBoostingInfoResolver,
mobile_rewards: FileSinkClient<proto::MobileRewardShare>,
reward_info: &EpochRewardInfo,
price_info: PriceInfo,
) -> anyhow::Result<(CalculatedPocRewardShares, Decimal)> {
let mut reward_shares =
DataTransferAndPocAllocatedRewardBuckets::new(reward_info.epoch_emissions);

Expand Down Expand Up @@ -394,20 +428,7 @@ pub async fn reward_poc_and_dc(
)
.await?;

let poc_unallocated_amount = poc_unallocated_amount
.round_dp_with_strategy(0, RoundingStrategy::ToZero)
.to_u64()
.unwrap_or(0);

write_unallocated_reward(
&mobile_rewards,
UnallocatedRewardType::Poc,
poc_unallocated_amount,
reward_info,
)
.await?;

Ok(calculated_poc_reward_shares)
Ok((calculated_poc_reward_shares, poc_unallocated_amount))
}

pub async fn reward_poc(
Expand Down Expand Up @@ -503,7 +524,7 @@ pub async fn reward_dc(
pub async fn reward_service_providers(
mobile_rewards: FileSinkClient<proto::MobileRewardShare>,
reward_info: &EpochRewardInfo,
) -> anyhow::Result<()> {
) -> anyhow::Result<Decimal> {
let total_sp_rewards = get_scheduled_tokens_for_service_providers(reward_info.epoch_emissions);
let sp_reward_amount = total_sp_rewards
.round_dp_with_strategy(0, RoundingStrategy::ToZero)
Expand All @@ -512,6 +533,7 @@ pub async fn reward_service_providers(

let subscriber_reward = std::cmp::min(sp_reward_amount, HELIUM_MOBILE_SERVICE_REWARD_BONES);
let network_reward = sp_reward_amount.saturating_sub(subscriber_reward);
let unallocated_reward = total_sp_rewards - Decimal::from(subscriber_reward + network_reward);

// Write a ServiceProviderReward for HeliumMobile Subscriber Wallet for 450 HNT
write_service_provider_reward(
Expand All @@ -533,11 +555,11 @@ pub async fn reward_service_providers(
)
.await?;

Ok(())
Ok(unallocated_reward)
}

async fn write_unallocated_reward(
mobile_rewards: &FileSinkClient<proto::MobileRewardShare>,
mobile_rewards: FileSinkClient<proto::MobileRewardShare>,
unallocated_type: UnallocatedRewardType,
unallocated_amount: u64,
reward_info: &'_ EpochRewardInfo,
Expand Down
2 changes: 2 additions & 0 deletions mobile_verifier/tests/integrations/common/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pub mod seed;

use chrono::{DateTime, Duration, Utc};
use file_store::{
file_sink::{FileSinkClient, Message as SinkMessage},
Expand Down
Loading
Loading