diff --git a/Cargo.lock b/Cargo.lock index 51c8b59cb..855b1adf2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1130,7 +1130,7 @@ checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" [[package]] name = "beacon" version = "0.1.0" -source = "git+https://github.com/helium/proto?branch=andymck/service-provider-rewards#5bf847d6cc9c5b3043f74bc2e1c802c495523864" +source = "git+https://github.com/helium/proto?branch=andymck/service-provider-rewards#e5d06ec55816c63fdb99dc820b7cb7668b567a5f" dependencies = [ "base64 0.21.0", "byteorder", @@ -1140,7 +1140,7 @@ dependencies = [ "rand_chacha 0.3.0", "rust_decimal", "serde", - "sha2 0.9.9", + "sha2 0.10.6", "thiserror", ] @@ -3003,7 +3003,7 @@ dependencies = [ [[package]] name = "helium-proto" version = "0.1.0" -source = "git+https://github.com/helium/proto?branch=andymck/service-provider-rewards#5bf847d6cc9c5b3043f74bc2e1c802c495523864" +source = "git+https://github.com/helium/proto?branch=andymck/service-provider-rewards#e5d06ec55816c63fdb99dc820b7cb7668b567a5f" dependencies = [ "bytes", "prost", @@ -8282,7 +8282,7 @@ dependencies = [ "rand 0.8.5", "serde", "serde_json", - "sha2 0.9.9", + "sha2 0.10.6", "thiserror", "twox-hash", "xorf", diff --git a/mobile_verifier/src/data_session.rs b/mobile_verifier/src/data_session.rs index 068fac8cc..072cb212e 100644 --- a/mobile_verifier/src/data_session.rs +++ b/mobile_verifier/src/data_session.rs @@ -16,7 +16,7 @@ pub struct DataSessionIngestor { #[derive(sqlx::FromRow, Debug)] pub struct ServiceProviderSession { - pub sp: PublicKeyBinary, + pub service_provider_id: Vec, pub total_dcs: Decimal, } diff --git a/mobile_verifier/src/reward_shares.rs b/mobile_verifier/src/reward_shares.rs index 77ea7c9a9..08840751a 100644 --- a/mobile_verifier/src/reward_shares.rs +++ b/mobile_verifier/src/reward_shares.rs @@ -201,21 +201,16 @@ impl MapperShares { #[derive(Default)] pub struct ServiceProviderShares { - pub service_provider_shares: Vec, + pub shares: Vec, } impl ServiceProviderShares { - pub fn new(service_provider_shares: Vec) -> Self { - Self { - service_provider_shares, - } + pub fn new(shares: Vec) -> Self { + Self { shares } } fn total_data_shares(&self) -> Decimal { - self.service_provider_shares - .iter() - .map(|v| v.total_dcs) - .sum() + self.shares.iter().map(|v| v.total_dcs).sum() } pub fn rewards_per_share( @@ -243,11 +238,11 @@ impl ServiceProviderShares { reward_period: &'_ Range>, reward_per_share: Decimal, ) -> impl Iterator + '_ { - self.service_provider_shares + self.shares .into_iter() - .map(move |sp| proto::ServiceProviderReward { - service_provider: sp.sp.into(), - amount: (sp.total_dcs * reward_per_share) + .map(move |share| proto::ServiceProviderReward { + service_provider_id: share.service_provider_id, + amount: (share.total_dcs * reward_per_share) .round_dp_with_strategy(0, RoundingStrategy::ToZero) .to_u64() .unwrap_or(0), @@ -498,12 +493,12 @@ mod test { #[tokio::test] async fn service_provider_reward_amount() { - let payer1: PublicKeyBinary = "112NqN2WWMwtK29PMzRby62fDydBJfsCLkCAf392stdok48ovNT6" - .parse() - .expect("failed payer1 parse"); - let payer2: PublicKeyBinary = "11sctWiP9r5wDJVuDe1Th4XSL2vaawaLLSQF8f8iokAoMAJHxqp" - .parse() - .expect("failed payer2 parse"); + let payer1: Vec = "112NqN2WWMwtK29PMzRby62fDydBJfsCLkCAf392stdok48ovNT6" + .as_bytes() + .to_vec(); + let payer2 = "11sctWiP9r5wDJVuDe1Th4XSL2vaawaLLSQF8f8iokAoMAJHxqp" + .as_bytes() + .to_vec(); let now = Utc::now(); let epoch = (now - Duration::hours(1))..now; @@ -511,11 +506,11 @@ mod test { let service_provider_sessions = vec![ ServiceProviderSession { - sp: payer1.clone(), + service_provider_id: payer1.clone(), total_dcs: dec!(1000), }, ServiceProviderSession { - sp: payer2.clone(), + service_provider_id: payer2.clone(), total_dcs: dec!(5000), }, ]; @@ -534,7 +529,7 @@ mod test { let mut sp_rewards = HashMap::new(); for sp_reward in sp_shares.into_service_provider_rewards(&epoch, rewards_per_share) { if let Some(MobileReward::ServiceProviderReward(r)) = sp_reward.reward { - sp_rewards.insert(PublicKeyBinary::from(r.service_provider), r.amount); + sp_rewards.insert(r.service_provider_id, r.amount); } } println!("sp_rewards: {:?}", sp_rewards); @@ -553,12 +548,12 @@ mod test { #[tokio::test] async fn service_provider_reward_amount_capped() { let mobile_bone_price = dec!(1.0); - let payer1: PublicKeyBinary = "112NqN2WWMwtK29PMzRby62fDydBJfsCLkCAf392stdok48ovNT6" - .parse() - .expect("failed payer1 parse"); - let payer2: PublicKeyBinary = "11sctWiP9r5wDJVuDe1Th4XSL2vaawaLLSQF8f8iokAoMAJHxqp" - .parse() - .expect("failed payer2 parse"); + let payer1: Vec = "112NqN2WWMwtK29PMzRby62fDydBJfsCLkCAf392stdok48ovNT6" + .as_bytes() + .to_vec(); + let payer2 = "11sctWiP9r5wDJVuDe1Th4XSL2vaawaLLSQF8f8iokAoMAJHxqp" + .as_bytes() + .to_vec(); let now = Utc::now(); let epoch = (now - Duration::hours(1))..now; @@ -568,11 +563,11 @@ mod test { println!("total_rewards_value_in_dc: {total_rewards_value_in_dc}"); let service_provider_sessions = vec![ ServiceProviderSession { - sp: payer1.clone(), + service_provider_id: payer1.clone(), total_dcs: total_rewards_value_in_dc, }, ServiceProviderSession { - sp: payer2.clone(), + service_provider_id: payer2.clone(), total_dcs: total_rewards_value_in_dc .checked_div(dec!(2)) .expect("failed to assign rewards"), @@ -594,7 +589,7 @@ mod test { let mut sp_rewards = HashMap::new(); for sp_reward in sp_shares.into_service_provider_rewards(&epoch, rewards_per_share) { if let Some(MobileReward::ServiceProviderReward(r)) = sp_reward.reward { - sp_rewards.insert(PublicKeyBinary::from(r.service_provider), r.amount); + sp_rewards.insert(r.service_provider_id, r.amount); } } let payer1_reward_amount = *sp_rewards diff --git a/reward_index/src/indexer.rs b/reward_index/src/indexer.rs index e576cf3dc..18b3407ba 100644 --- a/reward_index/src/indexer.rs +++ b/reward_index/src/indexer.rs @@ -150,6 +150,13 @@ impl Indexer { }, r.discovery_location_amount, )), + Some(MobileReward::ServiceProviderReward(r)) => Ok(( + RewardKey { + key: bs58::encode(&r.service_provider_id).into_string(), + reward_type: RewardType::MobileSubscriber, + }, + r.amount, + )), _ => bail!("got an invalid reward share"), } }