Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Copy Markdown
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"}
35 changes: 16 additions & 19 deletions mobile_verifier/src/rewarder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ where
);

// process rewards for poc and data transfer
let poc_dc_shares = reward_poc_and_dc(
let (poc_dc_shares, poc_unallocated_amount) = reward_poc_and_dc(
&self.pool,
&self.hex_service_client,
self.mobile_rewards.clone(),
Expand All @@ -282,7 +282,16 @@ where
.await?;

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

// write combined poc and sp unallocated reward
let total_unallocated_amount = (poc_unallocated_amount + sp_unallocated_amount).to_u64().unwrap_or(0);
write_unallocated_reward(
&self.mobile_rewards.clone(),
UnallocatedRewardType::PocAndServiceProvider,
total_unallocated_amount,
&reward_info
).await?;

self.speedtest_averages.commit().await?;
let written_files = self.mobile_rewards.commit().await?.await??;
Expand Down Expand Up @@ -355,7 +364,7 @@ pub async fn reward_poc_and_dc(
mobile_rewards: FileSinkClient<proto::MobileRewardShare>,
reward_info: &EpochRewardInfo,
price_info: PriceInfo,
) -> anyhow::Result<CalculatedPocRewardShares> {
) -> anyhow::Result<(CalculatedPocRewardShares, Decimal)> {
let mut reward_shares =
DataTransferAndPocAllocatedRewardBuckets::new(reward_info.epoch_emissions);

Expand Down Expand Up @@ -394,20 +403,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 +499,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 +508,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,7 +530,7 @@ pub async fn reward_service_providers(
)
.await?;

Ok(())
Ok(unallocated_reward)
}

async fn write_unallocated_reward(
Expand Down
35 changes: 21 additions & 14 deletions mobile_verifier/tests/integrations/hex_boosting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ async fn test_poc_with_boosted_hexes(pool: PgPool) -> anyhow::Result<()> {

let price_info = default_price_info();

rewarder::reward_poc_and_dc(
let (_, poc_unallocated_amount) = rewarder::reward_poc_and_dc(
&pool,
&hex_boosting_client,
mobile_rewards_client,
Expand All @@ -144,6 +144,7 @@ async fn test_poc_with_boosted_hexes(pool: PgPool) -> anyhow::Result<()> {
.await?;

let rewards = mobile_rewards.finish().await?;
let poc_unallocated_amount = poc_unallocated_amount.to_u64().unwrap_or(0);

let poc_rewards = rewards.radio_reward_v2s.as_keyed_map();
let hotspot_1 = poc_rewards.get(HOTSPOT_1).expect("hotspot 1");
Expand Down Expand Up @@ -193,7 +194,7 @@ async fn test_poc_with_boosted_hexes(pool: PgPool) -> anyhow::Result<()> {

// confirm the total rewards allocated matches emissions
// and the rewarded percentage amount matches percentage
let total = rewards.total_poc_rewards() + rewards.unallocated_amount_or_default();
let total = rewards.total_poc_rewards() + rewards.unallocated_amount_or_default() + poc_unallocated_amount;
assert_total_matches_emissions(total, &reward_info);

Ok(())
Expand Down Expand Up @@ -288,7 +289,7 @@ async fn test_poc_boosted_hexes_unique_connections_not_seeded(pool: PgPool) -> a
let price_info = default_price_info();

// run rewards for poc and dc
rewarder::reward_poc_and_dc(
let (_, poc_unallocated_amount) = rewarder::reward_poc_and_dc(
&pool,
&hex_boosting_client,
mobile_rewards_client,
Expand All @@ -298,6 +299,7 @@ async fn test_poc_boosted_hexes_unique_connections_not_seeded(pool: PgPool) -> a
.await?;

let rewards = mobile_rewards.finish().await?;
let poc_unallocated_amount = poc_unallocated_amount.to_u64().unwrap_or(0);

let poc_rewards = rewards.radio_reward_v2s.as_keyed_map();
let hotspot_1 = poc_rewards.get(HOTSPOT_1).expect("hotspot 1");
Expand All @@ -315,7 +317,7 @@ async fn test_poc_boosted_hexes_unique_connections_not_seeded(pool: PgPool) -> a

// confirm the total rewards allocated matches emissions
// and the rewarded percentage amount matches percentage
let total = rewards.total_poc_rewards() + rewards.unallocated_amount_or_default();
let total = rewards.total_poc_rewards() + rewards.unallocated_amount_or_default() + poc_unallocated_amount;
assert_total_matches_emissions(total, &reward_info);

Ok(())
Expand Down Expand Up @@ -417,7 +419,7 @@ async fn test_poc_with_multi_coverage_boosted_hexes(pool: PgPool) -> anyhow::Res
];

// run rewards for poc and dc
rewarder::reward_poc_and_dc(
let (_, poc_unallocated_amount) = rewarder::reward_poc_and_dc(
&pool,
&MockHexBoostingClient::new(boosted_hexes),
mobile_rewards_client,
Expand All @@ -427,6 +429,7 @@ async fn test_poc_with_multi_coverage_boosted_hexes(pool: PgPool) -> anyhow::Res
.await?;

let rewards = mobile_rewards.finish().await?;
let poc_unallocated_amount = poc_unallocated_amount.to_u64().unwrap_or(0);

let poc_rewards = rewards.radio_reward_v2s.as_keyed_map();
let hotspot_1 = poc_rewards.get(HOTSPOT_1).expect("hotspot 1");
Expand Down Expand Up @@ -487,7 +490,7 @@ async fn test_poc_with_multi_coverage_boosted_hexes(pool: PgPool) -> anyhow::Res

// confirm the total rewards allocated matches emissions
// and the rewarded percentage amount matches percentage
let total = rewards.total_poc_rewards() + rewards.unallocated_amount_or_default();
let total = rewards.total_poc_rewards() + rewards.unallocated_amount_or_default() + poc_unallocated_amount;
assert_total_matches_emissions(total, &reward_info);

Ok(())
Expand Down Expand Up @@ -552,7 +555,7 @@ async fn test_expired_boosted_hex(pool: PgPool) -> anyhow::Result<()> {
];

// run rewards for poc and dc
rewarder::reward_poc_and_dc(
let (_, poc_unallocated_amount) = rewarder::reward_poc_and_dc(
&pool,
&MockHexBoostingClient::new(boosted_hexes),
mobile_rewards_client,
Expand All @@ -562,6 +565,7 @@ async fn test_expired_boosted_hex(pool: PgPool) -> anyhow::Result<()> {
.await?;

let rewards = mobile_rewards.finish().await?;
let poc_unallocated_amount = poc_unallocated_amount.to_u64().unwrap_or(0);

let poc_rewards = rewards.radio_reward_v2s.as_keyed_map();
let hotspot_1 = poc_rewards.get(HOTSPOT_1).expect("hotspot 1");
Expand All @@ -583,7 +587,7 @@ async fn test_expired_boosted_hex(pool: PgPool) -> anyhow::Result<()> {

// confirm the total rewards allocated matches emissions
// and the rewarded percentage amount matches percentage
let total = rewards.total_poc_rewards() + rewards.unallocated_amount_or_default();
let total = rewards.total_poc_rewards() + rewards.unallocated_amount_or_default() + poc_unallocated_amount;
assert_total_matches_emissions(total, &reward_info);

Ok(())
Expand Down Expand Up @@ -654,7 +658,7 @@ async fn test_reduced_location_score_with_boosted_hexes(pool: PgPool) -> anyhow:
];

// run rewards for poc and dc
rewarder::reward_poc_and_dc(
let (_, poc_unallocated_amount) = rewarder::reward_poc_and_dc(
&pool,
&MockHexBoostingClient::new(boosted_hexes),
mobile_rewards_client,
Expand All @@ -664,6 +668,7 @@ async fn test_reduced_location_score_with_boosted_hexes(pool: PgPool) -> anyhow:
.await?;

let rewards = mobile_rewards.finish().await?;
let poc_unallocated_amount = poc_unallocated_amount.to_u64().unwrap_or(0);

let poc_rewards = rewards.radio_reward_v2s.as_keyed_map();
let hotspot_1 = poc_rewards.get(HOTSPOT_1).expect("hotspot 1"); // full location trust 1 boost
Expand Down Expand Up @@ -715,7 +720,7 @@ async fn test_reduced_location_score_with_boosted_hexes(pool: PgPool) -> anyhow:

// confirm the total rewards allocated matches emissions
// and the rewarded percentage amount matches percentage
let total = rewards.total_poc_rewards() + rewards.unallocated_amount_or_default();
let total = rewards.total_poc_rewards() + rewards.unallocated_amount_or_default() + poc_unallocated_amount;
assert_total_matches_emissions(total, &reward_info);

Ok(())
Expand Down Expand Up @@ -791,7 +796,7 @@ async fn test_distance_from_asserted_removes_boosting_but_not_location_trust(
];

// run rewards for poc and dc
rewarder::reward_poc_and_dc(
let (_, poc_unallocated_amount) = rewarder::reward_poc_and_dc(
&pool,
&MockHexBoostingClient::new(boosted_hexes),
mobile_rewards_client,
Expand All @@ -801,6 +806,7 @@ async fn test_distance_from_asserted_removes_boosting_but_not_location_trust(
.await?;

let rewards = mobile_rewards.finish().await?;
let poc_unallocated_amount = poc_unallocated_amount.to_u64().unwrap_or(0);

let poc_rewards = rewards.radio_reward_v2s.as_keyed_map();
let hotspot_1 = poc_rewards.get(HOTSPOT_1).expect("hotspot 1"); // full location trust 1 boost
Expand Down Expand Up @@ -855,7 +861,7 @@ async fn test_distance_from_asserted_removes_boosting_but_not_location_trust(

// confirm the total rewards allocated matches emissions
// and the rewarded percentage amount matches percentage
let total = rewards.total_poc_rewards() + rewards.unallocated_amount_or_default();
let total = rewards.total_poc_rewards() + rewards.unallocated_amount_or_default() + poc_unallocated_amount;
assert_total_matches_emissions(total, &reward_info);

Ok(())
Expand Down Expand Up @@ -954,7 +960,7 @@ async fn test_poc_with_wifi_and_multi_coverage_boosted_hexes(pool: PgPool) -> an
];

// run rewards for poc and dc
rewarder::reward_poc_and_dc(
let (_, poc_unallocated_reward) = rewarder::reward_poc_and_dc(
&pool,
&MockHexBoostingClient::new(boosted_hexes),
mobile_rewards_client,
Expand All @@ -964,6 +970,7 @@ async fn test_poc_with_wifi_and_multi_coverage_boosted_hexes(pool: PgPool) -> an
.await?;

let rewards = mobile_rewards.finish().await?;
let poc_unallocated_reward = poc_unallocated_reward.to_u64().unwrap_or(0);

let poc_rewards = rewards.radio_reward_v2s.as_keyed_map();
let hotspot_1 = poc_rewards.get(HOTSPOT_1).expect("hotspot 1"); // 2 boosts at 10x
Expand Down Expand Up @@ -1023,7 +1030,7 @@ async fn test_poc_with_wifi_and_multi_coverage_boosted_hexes(pool: PgPool) -> an

// confirm the total rewards allocated matches emissions
// and the rewarded percentage amount matches percentage
let total = rewards.total_poc_rewards() + rewards.unallocated_amount_or_default();
let total = rewards.total_poc_rewards() + rewards.unallocated_amount_or_default() + poc_unallocated_reward;
assert_total_matches_emissions(total, &reward_info);

Ok(())
Expand Down
Loading
Loading