Skip to content

Commit

Permalink
Update mobile-verifier rewarder to incorporate sp bans
Browse files Browse the repository at this point in the history
  • Loading branch information
bbalser committed Jul 1, 2024
1 parent a0501ab commit e9d9468
Show file tree
Hide file tree
Showing 9 changed files with 188 additions and 91 deletions.
84 changes: 50 additions & 34 deletions coverage_point_calculator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ pub struct CoveragePoints {
/// Input Radio Type
pub radio_type: RadioType,
/// Input RadioThreshold
pub radio_threshold: RadioThreshold,
pub service_provider_boosted_reward_eligibility: ServiceProviderBoostedRewardEligibility,
/// Derived Eligibility for Boosted Hex Rewards
pub boosted_hex_eligibility: BoostedHexStatus,
/// Speedtests used in calculcation
Expand All @@ -129,16 +129,19 @@ pub struct CoveragePoints {
impl CoveragePoints {
pub fn new(
radio_type: RadioType,
radio_threshold: RadioThreshold,
service_provider_boosted_reward_eligibility: ServiceProviderBoostedRewardEligibility,
speedtests: Vec<Speedtest>,
trust_scores: Vec<LocationTrust>,
ranked_coverage: Vec<coverage_map::RankedCoverage>,
) -> Result<CoveragePoints> {
let location_trust_scores = location::clean_trust_scores(trust_scores, &ranked_coverage);
let location_trust_multiplier = location::multiplier(radio_type, &location_trust_scores);

let boost_eligibility =
BoostedHexStatus::new(&radio_type, location_trust_multiplier, &radio_threshold);
let boost_eligibility = BoostedHexStatus::new(
&radio_type,
location_trust_multiplier,
&service_provider_boosted_reward_eligibility,
);

let covered_hexes =
hexes::clean_covered_hexes(radio_type, boost_eligibility, ranked_coverage)?;
Expand All @@ -157,7 +160,7 @@ impl CoveragePoints {
location_trust_multiplier,
speedtest_multiplier,
radio_type,
radio_threshold,
service_provider_boosted_reward_eligibility,
boosted_hex_eligibility: boost_eligibility,
speedtests,
location_trust_scores,
Expand All @@ -171,25 +174,30 @@ pub enum BoostedHexStatus {
Eligible,
WifiLocationScoreBelowThreshold(Decimal),
RadioThresholdNotMet,
ServiceProviderBanned,
}

impl BoostedHexStatus {
fn new(
radio_type: &RadioType,
location_trust_score: Decimal,
radio_threshold: &RadioThreshold,
service_provider_boosted_reward_eligibility: &ServiceProviderBoostedRewardEligibility,
) -> Self {
// hip-93: if radio is wifi & location_trust score multiplier < 0.75, no boosting
if radio_type.is_wifi() && location_trust_score < dec!(0.75) {
return Self::WifiLocationScoreBelowThreshold(location_trust_score);
}

// hip-84: if radio has not met minimum data and subscriber thresholds, no boosting
if !radio_threshold.is_met() {
return Self::RadioThresholdNotMet;
match service_provider_boosted_reward_eligibility {
ServiceProviderBoostedRewardEligibility::Eligible => Self::Eligible,
ServiceProviderBoostedRewardEligibility::ServiceProviderBanned => {
Self::ServiceProviderBanned
}
ServiceProviderBoostedRewardEligibility::RadioThresholdNotMet => {
Self::RadioThresholdNotMet
}
}

Self::Eligible
}

fn is_eligible(&self) -> bool {
Expand Down Expand Up @@ -262,16 +270,23 @@ impl RadioType {
}

#[derive(Debug, Clone, Copy, PartialEq)]
pub enum RadioThreshold {
Verified,
Unverified,
pub enum ServiceProviderBoostedRewardEligibility {
Eligible,
ServiceProviderBanned,
RadioThresholdNotMet,
}

impl RadioThreshold {
fn is_met(&self) -> bool {
matches!(self, Self::Verified)
}
}
// #[derive(Debug, Clone, Copy, PartialEq)]
// pub enum RadioThreshold {
// Verified,
// Unverified,
// }

// impl RadioThreshold {
// fn is_met(&self) -> bool {
// matches!(self, Self::Verified)
// }
// }

#[cfg(test)]
mod tests {
Expand All @@ -297,7 +312,7 @@ mod tests {
) {
let wifi = CoveragePoints::new(
RadioType::IndoorWifi,
RadioThreshold::Verified,
ServiceProviderBoostedRewardEligibility::Eligible,
speedtest_maximum(),
location_trust_maximum(),
vec![RankedCoverage {
Expand All @@ -319,10 +334,10 @@ mod tests {

#[test]
fn hip_84_radio_meets_minimum_subscriber_threshold_for_boosted_hexes() {
let calculate_wifi = |radio_verified: RadioThreshold| {
let calculate_wifi = |eligibility: ServiceProviderBoostedRewardEligibility| {
CoveragePoints::new(
RadioType::IndoorWifi,
radio_verified,
eligibility,
speedtest_maximum(),
location_trust_maximum(),
vec![RankedCoverage {
Expand All @@ -344,12 +359,13 @@ mod tests {

// Radio meeting the threshold is eligible for boosted hexes.
// Boosted hex provides radio with more than base_points.
let verified_wifi = calculate_wifi(RadioThreshold::Verified);
let verified_wifi = calculate_wifi(ServiceProviderBoostedRewardEligibility::Eligible);
assert_eq!(base_points * dec!(5), verified_wifi.total_coverage_points);

// Radio not meeting the threshold is not eligible for boosted hexes.
// Boost from hex is not applied, radio receives base points.
let unverified_wifi = calculate_wifi(RadioThreshold::Unverified);
let unverified_wifi =
calculate_wifi(ServiceProviderBoostedRewardEligibility::RadioThresholdNotMet);
assert_eq!(base_points, unverified_wifi.total_coverage_points);
}

Expand All @@ -358,7 +374,7 @@ mod tests {
let calculate_wifi = |location_trust_scores: Vec<LocationTrust>| {
CoveragePoints::new(
RadioType::IndoorWifi,
RadioThreshold::Verified,
ServiceProviderBoostedRewardEligibility::Eligible,
speedtest_maximum(),
location_trust_scores,
vec![RankedCoverage {
Expand Down Expand Up @@ -396,7 +412,7 @@ mod tests {
let calculate_indoor_cbrs = |speedtests: Vec<Speedtest>| {
CoveragePoints::new(
RadioType::IndoorCbrs,
RadioThreshold::Verified,
ServiceProviderBoostedRewardEligibility::Eligible,
speedtests,
location_trust_maximum(),
vec![RankedCoverage {
Expand Down Expand Up @@ -484,7 +500,7 @@ mod tests {
use Assignment::*;
let indoor_cbrs = CoveragePoints::new(
RadioType::IndoorCbrs,
RadioThreshold::Verified,
ServiceProviderBoostedRewardEligibility::Eligible,
speedtest_maximum(),
location_trust_maximum(),
vec![
Expand Down Expand Up @@ -541,7 +557,7 @@ mod tests {
) {
let outdoor_wifi = CoveragePoints::new(
radio_type,
RadioThreshold::Verified,
ServiceProviderBoostedRewardEligibility::Eligible,
speedtest_maximum(),
location_trust_maximum(),
vec![RankedCoverage {
Expand Down Expand Up @@ -570,7 +586,7 @@ mod tests {
) {
let indoor_wifi = CoveragePoints::new(
radio_type,
RadioThreshold::Verified,
ServiceProviderBoostedRewardEligibility::Eligible,
speedtest_maximum(),
location_trust_maximum(),
vec![
Expand Down Expand Up @@ -613,7 +629,7 @@ mod tests {
// Location scores are averaged together
let indoor_wifi = CoveragePoints::new(
RadioType::IndoorWifi,
RadioThreshold::Verified,
ServiceProviderBoostedRewardEligibility::Eligible,
speedtest_maximum(),
location_trust_with_scores(&[dec!(0.1), dec!(0.2), dec!(0.3), dec!(0.4)]),
vec![RankedCoverage {
Expand Down Expand Up @@ -657,7 +673,7 @@ mod tests {
];
let indoor_wifi = CoveragePoints::new(
RadioType::IndoorWifi,
RadioThreshold::Verified,
ServiceProviderBoostedRewardEligibility::Eligible,
speedtest_maximum(),
location_trust_maximum(),
covered_hexes.clone(),
Expand All @@ -680,7 +696,7 @@ mod tests {
) {
let outdoor_cbrs = CoveragePoints::new(
RadioType::OutdoorCbrs,
RadioThreshold::Verified,
ServiceProviderBoostedRewardEligibility::Eligible,
speedtest_maximum(),
location_trust_maximum(),
vec![RankedCoverage {
Expand All @@ -707,7 +723,7 @@ mod tests {
) {
let indoor_cbrs = CoveragePoints::new(
RadioType::IndoorCbrs,
RadioThreshold::Verified,
ServiceProviderBoostedRewardEligibility::Eligible,
speedtest_maximum(),
location_trust_maximum(),
vec![RankedCoverage {
Expand Down Expand Up @@ -736,7 +752,7 @@ mod tests {
) {
let outdoor_wifi = CoveragePoints::new(
RadioType::OutdoorWifi,
RadioThreshold::Verified,
ServiceProviderBoostedRewardEligibility::Eligible,
speedtest_maximum(),
location_trust_maximum(),
vec![RankedCoverage {
Expand All @@ -763,7 +779,7 @@ mod tests {
) {
let indoor_wifi = CoveragePoints::new(
RadioType::IndoorWifi,
RadioThreshold::Verified,
ServiceProviderBoostedRewardEligibility::Eligible,
speedtest_maximum(),
location_trust_maximum(),
vec![RankedCoverage {
Expand Down
14 changes: 7 additions & 7 deletions coverage_point_calculator/tests/coverage_point_calculator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::num::NonZeroU32;
use chrono::Utc;
use coverage_map::{BoostedHexMap, RankedCoverage, SignalLevel, UnrankedCoverage};
use coverage_point_calculator::{
BytesPs, CoveragePoints, LocationTrust, RadioThreshold, RadioType, Result, Speedtest,
SpeedtestTier,
BytesPs, CoveragePoints, LocationTrust, RadioType, Result,
ServiceProviderBoostedRewardEligibility, Speedtest, SpeedtestTier,
};
use hex_assignments::{assignment::HexAssignments, Assignment};
use rust_decimal_macros::dec;
Expand Down Expand Up @@ -52,7 +52,7 @@ fn base_radio_coverage_points() {
] {
let coverage_points = CoveragePoints::new(
radio_type,
RadioThreshold::Verified,
ServiceProviderBoostedRewardEligibility::Eligible,
speedtests.clone(),
location_trust_scores.clone(),
hexes.clone(),
Expand Down Expand Up @@ -113,7 +113,7 @@ fn radios_with_coverage() {
] {
let coverage_points = CoveragePoints::new(
radio_type,
RadioThreshold::Verified,
ServiceProviderBoostedRewardEligibility::Eligible,
default_speedtests.clone(),
default_location_trust_scores.clone(),
base_hex_iter.clone().take(num_hexes).collect(),
Expand Down Expand Up @@ -240,7 +240,7 @@ fn cbrs_outdoor_with_mixed_signal_level_coverage() -> Result {

let radio = CoveragePoints::new(
RadioType::OutdoorCbrs,
RadioThreshold::Verified,
ServiceProviderBoostedRewardEligibility::Eligible,
Speedtest::mock(SpeedtestTier::Good),
vec![], // Location Trust is ignored for Cbrs
vec![
Expand Down Expand Up @@ -372,7 +372,7 @@ fn indoor_cbrs_radio(
) -> Result<CoveragePoints> {
CoveragePoints::new(
RadioType::IndoorCbrs,
RadioThreshold::Verified,
ServiceProviderBoostedRewardEligibility::Eligible,
Speedtest::mock(speedtest_tier),
vec![],
coverage.to_owned(),
Expand All @@ -385,7 +385,7 @@ fn outdoor_cbrs_radio(
) -> Result<CoveragePoints> {
CoveragePoints::new(
RadioType::OutdoorCbrs,
RadioThreshold::Verified,
ServiceProviderBoostedRewardEligibility::Eligible,
Speedtest::mock(speedtest_tier),
vec![],
coverage.to_owned(),
Expand Down
4 changes: 2 additions & 2 deletions mobile_verifier/src/cli/reward_from_db.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
heartbeats::HeartbeatReward,
radio_threshold::VerifiedRadioThresholds,
reward_shares::{get_scheduled_tokens_for_poc, CoverageShares},
rewarder::boosted_hex_eligibility::BoostedHexEligibility,
speedtests_average::SpeedtestAverages,
Settings,
};
Expand Down Expand Up @@ -46,7 +46,7 @@ impl Cmd {
heartbeats,
&speedtest_averages,
&BoostedHexes::default(),
&VerifiedRadioThresholds::default(),
&BoostedHexEligibility::default(),
&epoch,
)
.await?;
Expand Down
Loading

0 comments on commit e9d9468

Please sign in to comment.