Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Radios that earn 0 rewards should be removed from coverage map #912

Merged
merged 5 commits into from
Dec 17, 2024
Merged
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
2 changes: 1 addition & 1 deletion coverage_point_calculator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ use rust_decimal_macros::dec;
use service_provider_boosting::{MAX_AVERAGE_DISTANCE, MIN_WIFI_TRUST_MULTIPLIER};

mod hexes;
mod location;
pub mod location;
mod service_provider_boosting;
pub mod speedtest;

Expand Down
2 changes: 1 addition & 1 deletion coverage_point_calculator/src/location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub(crate) fn average_distance(radio_type: RadioType, trust_scores: &[LocationTr
sum / count
}

pub(crate) fn multiplier(radio_type: RadioType, trust_scores: &[LocationTrust]) -> Decimal {
pub fn multiplier(radio_type: RadioType, trust_scores: &[LocationTrust]) -> Decimal {
// CBRS radios are always trusted because they have internal GPS
if radio_type.is_cbrs() {
return dec!(1);
Expand Down
102 changes: 66 additions & 36 deletions mobile_verifier/src/reward_shares.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ use crate::{
unique_connections::{self, UniqueConnectionCounts},
};
use chrono::{DateTime, Duration, Utc};
use coverage_point_calculator::{OracleBoostingStatus, SPBoostedRewardEligibility};
use coverage_point_calculator::{
BytesPs, LocationTrust, OracleBoostingStatus, RadioType, SPBoostedRewardEligibility, Speedtest,
SpeedtestTier,
};
use file_store::traits::TimestampEncode;
use futures::{Stream, StreamExt};
use helium_crypto::PublicKeyBinary;
Expand Down Expand Up @@ -430,7 +433,29 @@ impl CoverageShares {
.fetch_seniority(heartbeat_key, reward_period.end)
.await?;

let is_indoor = {
let trust_scores: Vec<LocationTrust> = heartbeat
.iter_distances_and_scores()
.map(|(distance, trust_score)| LocationTrust {
meters_to_asserted: distance as u32,
trust_score,
})
.collect();

let speedtests = match speedtest_averages.get_average(&pubkey) {
Some(avg) => avg.speedtests,
None => vec![],
};
let speedtests: Vec<Speedtest> = speedtests
.iter()
.map(|test| Speedtest {
upload_speed: BytesPs::new(test.report.upload_speed),
download_speed: BytesPs::new(test.report.download_speed),
latency_millis: test.report.latency,
timestamp: test.report.timestamp,
})
.collect();

let (is_indoor, covered_hexes) = {
let mut is_indoor = false;

let covered_hexes_stream = hex_streams
Expand All @@ -448,16 +473,7 @@ impl CoverageShares {
assignments: hex_coverage.assignments,
});
}

coverage_map_builder.insert_coverage_object(coverage_map::CoverageObject {
indoor: is_indoor,
hotspot_key: pubkey.clone().into(),
cbsd_id: cbsd_id.clone(),
seniority_timestamp: seniority.seniority_ts,
coverage: covered_hexes,
});

is_indoor
(is_indoor, covered_hexes)
};

use coverage_point_calculator::RadioType;
Expand All @@ -468,21 +484,6 @@ impl CoverageShares {
(false, Some(_)) => RadioType::OutdoorCbrs,
};

use coverage_point_calculator::{BytesPs, Speedtest};
let speedtests = match speedtest_averages.get_average(&pubkey) {
Some(avg) => avg.speedtests,
None => vec![],
};
let speedtests = speedtests
.iter()
.map(|test| Speedtest {
upload_speed: BytesPs::new(test.report.upload_speed),
download_speed: BytesPs::new(test.report.download_speed),
latency_millis: test.report.latency,
timestamp: test.report.timestamp,
})
.collect();

let oracle_boosting_status =
if unique_connections::is_qualified(unique_connections, &pubkey, &radio_type) {
OracleBoostingStatus::Qualified
Expand All @@ -492,18 +493,24 @@ impl CoverageShares {
OracleBoostingStatus::Eligible
};

if eligible_for_coverage_map(
oracle_boosting_status,
&speedtests,
radio_type,
&trust_scores,
) {
coverage_map_builder.insert_coverage_object(coverage_map::CoverageObject {
indoor: is_indoor,
hotspot_key: pubkey.clone().into(),
cbsd_id: cbsd_id.clone(),
seniority_timestamp: seniority.seniority_ts,
coverage: covered_hexes,
});
}

let sp_boosted_reward_eligibility =
boosted_hex_eligibility.eligibility(pubkey, cbsd_id);

use coverage_point_calculator::LocationTrust;
let trust_scores = heartbeat
.iter_distances_and_scores()
.map(|(distance, trust_score)| LocationTrust {
meters_to_asserted: distance as u32,
trust_score,
})
.collect();

radio_infos.insert(
key,
RadioInfo {
Expand Down Expand Up @@ -770,6 +777,29 @@ pub fn get_scheduled_tokens_for_oracles(duration: Duration) -> Decimal {
get_total_scheduled_tokens(duration) * ORACLES_PERCENT
}

fn eligible_for_coverage_map(
oracle_boosting_status: OracleBoostingStatus,
speedtests: &[Speedtest],
radio_type: RadioType,
trust_scores: &[LocationTrust],
) -> bool {
if oracle_boosting_status == OracleBoostingStatus::Banned {
return false;
}

let avg_speedtest = Speedtest::avg(speedtests);
if avg_speedtest.tier() == SpeedtestTier::Fail {
return false;
}

let multiplier = coverage_point_calculator::location::multiplier(radio_type, trust_scores);
if multiplier <= dec!(0.0) {
return false;
}

true
}

#[cfg(test)]
mod test {

Expand Down