Skip to content

Commit

Permalink
fill out service provider reward allocations in reward_manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldjeffrey committed Sep 30, 2024
1 parent 03e0350 commit 998cf2c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
2 changes: 1 addition & 1 deletion mobile_verifier/src/rewarder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ where
boosted_poc_bones_per_reward_share: Some(helium_proto::Decimal {
value: poc_dc_shares.boost.to_string(),
}),
sp_allocations: service_provider::reward_data_sp_allocations(),
sp_allocations: service_provider::reward_data_sp_allocations(&self.pool).await?,
};
self.reward_manifests
.write(
Expand Down
18 changes: 15 additions & 3 deletions mobile_verifier/src/service_provider/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use chrono::{DateTime, Utc};
use helium_proto::ServiceProviderAllocation;
pub use promotions::daemon::PromotionDaemon;
pub use reward::ServiceProviderRewardInfos;
use sqlx::PgPool;

pub mod dc_sessions;
pub mod promotions;
Expand All @@ -25,7 +26,18 @@ pub fn get_scheduled_tokens(reward_period: &Range<DateTime<Utc>>) -> rust_decima
crate::reward_shares::get_scheduled_tokens_for_service_providers(duration)
}

pub fn reward_data_sp_allocations() -> Vec<ServiceProviderAllocation> {
// TODO: How do you go from a service provider id to the payer key?
vec![]
pub async fn reward_data_sp_allocations(
pool: &PgPool,
) -> anyhow::Result<Vec<ServiceProviderAllocation>> {
let funds = db::fetch_promotion_funds(pool).await?;
let mut sp_allocations = vec![];

for (sp_id, bps) in funds.0.into_iter() {
sp_allocations.push(ServiceProviderAllocation {
service_provider: sp_id,
incentive_escrow_fund_bps: bps as u32,
});
}

Ok(sp_allocations)
}
13 changes: 11 additions & 2 deletions mobile_verifier/tests/integrations/rewarder_sp_rewards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,17 +236,26 @@ async fn test_service_provider_promotion_rewards(pool: PgPool) -> anyhow::Result
// Ensure the cleanup job can run
let mut txn = pool.begin().await?;

service_provider::promotions::rewards::clear_promotion_rewards(&mut txn, &Utc::now()).await?;
service_provider::db::clear_promotion_rewards(&mut txn, &Utc::now()).await?;
txn.commit().await?;

let promos = service_provider::promotions::rewards::fetch_promotion_rewards(
let promos = service_provider::db::fetch_promotion_rewards(
&pool,
&carrier_client,
&(epoch.start..Utc::now()),
)
.await?;
assert!(promos.is_empty());

let sp_allocations = service_provider::reward_data_sp_allocations(&pool).await?;
assert_eq!(
vec![helium_proto::ServiceProviderAllocation {
service_provider: 0,
incentive_escrow_fund_bps: 1500
}],
sp_allocations
);

Ok(())
}

Expand Down

0 comments on commit 998cf2c

Please sign in to comment.