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

Implementation of HIP-131 #858

Merged
merged 12 commits into from
Sep 4, 2024
50 changes: 31 additions & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ helium-lib = { git = "https://github.com/helium/helium-wallet-rs.git", branch =
hextree = { git = "https://github.com/jaykickliter/HexTree", branch = "main", features = [
"disktree",
] }
helium-proto = { git = "https://github.com/helium/proto", branch = "master", features = [
helium-proto = { git = "https://github.com/helium/proto", branch = "bbalser/ban_type", features = [
"services",
] }
beacon = { git = "https://github.com/helium/proto", branch = "master" }
beacon = { git = "https://github.com/helium/proto", branch = "bbalser/ban_type" }
solana-client = "1.18"
solana-sdk = "1.18"
solana-program = "1.18"
Expand Down
54 changes: 47 additions & 7 deletions coverage_point_calculator/src/hexes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use hex_assignments::assignment::HexAssignments;
use rust_decimal::Decimal;
use rust_decimal_macros::dec;

use crate::{BoostedHexStatus, RadioType, Result};
use crate::{OracleBoostingStatus, RadioType, Result, SpBoostedHexStatus};

/// Breakdown of points for a hex.
///
Expand Down Expand Up @@ -58,8 +58,9 @@ pub struct CoveredHex {

pub(crate) fn clean_covered_hexes(
radio_type: RadioType,
boosted_hex_status: BoostedHexStatus,
boosted_hex_status: SpBoostedHexStatus,
ranked_coverage: Vec<RankedCoverage>,
oracle_boosting_status: OracleBoostingStatus,
) -> Result<Vec<CoveredHex>> {
// verify all hexes can obtain a base coverage point
let covered_hexes = ranked_coverage
Expand All @@ -74,9 +75,12 @@ pub(crate) fn clean_covered_hexes(
None
};

// hip-131: if the radio is banned, it automatically gets an assignment_multiplier of 0.0
// hip-103: if a hex is boosted by a service provider >=1x, the oracle
// multiplier will automatically be 1x, regardless of boosted_hex_status.
let assignment_multiplier = if ranked.boosted.is_some() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

above comment needs an update

let assignment_multiplier = if oracle_boosting_status == OracleBoostingStatus::Banned {
dec!(0)
} else if ranked.boosted.is_some() {
dec!(1)
} else {
ranked.assignments.boosting_multiplier()
Expand Down Expand Up @@ -132,11 +136,11 @@ mod tests {
use super::*;

#[rstest]
#[case(BoostedHexStatus::Eligible)]
#[case(BoostedHexStatus::WifiLocationScoreBelowThreshold(dec!(999)))]
#[case(BoostedHexStatus::RadioThresholdNotMet)]
#[case(SpBoostedHexStatus::Eligible)]
#[case(SpBoostedHexStatus::WifiLocationScoreBelowThreshold(dec!(999)))]
#[case(SpBoostedHexStatus::RadioThresholdNotMet)]
fn hip_103_provider_boosted_hex_receives_maximum_oracle_boost(
#[case] boost_status: BoostedHexStatus,
#[case] boost_status: SpBoostedHexStatus,
) {
// Regardless of the radio's eligibility to receive provider boosted
// rewards, a boosted hex increases the oracle assignment.
Expand All @@ -162,6 +166,7 @@ mod tests {
RadioType::IndoorWifi,
boost_status,
vec![unboosted_coverage, boosted_coverage],
OracleBoostingStatus::Eligible,
)
.unwrap();

Expand All @@ -174,4 +179,39 @@ mod tests {
// provider boosted gets oracle assignment bumped to 1x
assert_eq!(dec!(1), boosted.assignment_multiplier);
}

#[rstest]
fn hip131_banned_radio() {
let unboosted_coverage = RankedCoverage {
hotspot_key: vec![1],
cbsd_id: None,
hex: hextree::Cell::from_raw(0x8c2681a3064edff).unwrap(),
rank: 1,
signal_level: SignalLevel::High,
assignments: HexAssignments {
footfall: Assignment::A,
landtype: Assignment::A,
urbanized: Assignment::A,
},
boosted: NonZeroU32::new(0),
};

let boosted_coverage = RankedCoverage {
boosted: NonZeroU32::new(5),
..unboosted_coverage.clone()
};

let covered_hexes = clean_covered_hexes(
RadioType::IndoorWifi,
SpBoostedHexStatus::Eligible,
vec![unboosted_coverage, boosted_coverage],
OracleBoostingStatus::Banned,
)
.unwrap();

dbg!(&covered_hexes);

assert_eq!(dec!(0), covered_hexes[0].assignment_multiplier);
assert_eq!(dec!(0), covered_hexes[1].assignment_multiplier);
}
}
Loading