Skip to content

Commit

Permalink
UniqueConnections make radio eligible for boosted rewards (#920)
Browse files Browse the repository at this point in the history
* Update boosted hex eligibility so that if radio surpasses unique connections require it is eligible

* additional test
  • Loading branch information
bbalser authored Dec 18, 2024
1 parent 676590c commit b756ace
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 20 deletions.
2 changes: 1 addition & 1 deletion mobile_verifier/src/reward_shares.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ impl CoverageShares {
}

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

radio_infos.insert(
key,
Expand Down
5 changes: 3 additions & 2 deletions mobile_verifier/src/rewarder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,8 @@ async fn reward_poc(

let boosted_hexes = BoostedHexes::get_all(hex_service_client).await?;

let unique_connections = unique_connections::db::get(pool, reward_period).await?;

let boosted_hex_eligibility = BoostedHexEligibility::new(
radio_threshold::verified_radio_thresholds(pool, reward_period).await?,
sp_boosted_rewards_bans::db::get_banned_radios(
Expand All @@ -430,6 +432,7 @@ async fn reward_poc(
reward_period.end,
)
.await?,
unique_connections.clone(),
);

let poc_banned_radios = sp_boosted_rewards_bans::db::get_banned_radios(
Expand All @@ -439,8 +442,6 @@ async fn reward_poc(
)
.await?;

let unique_connections = unique_connections::db::get(pool, reward_period).await?;

let coverage_shares = CoverageShares::new(
pool,
heartbeats,
Expand Down
125 changes: 109 additions & 16 deletions mobile_verifier/src/rewarder/boosted_hex_eligibility.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,41 @@
use coverage_point_calculator::SPBoostedRewardEligibility;
use coverage_point_calculator::{RadioType, SPBoostedRewardEligibility};
use helium_crypto::PublicKeyBinary;

use crate::{radio_threshold::VerifiedRadioThresholds, sp_boosted_rewards_bans::BannedRadios};
use crate::{
radio_threshold::VerifiedRadioThresholds,
sp_boosted_rewards_bans::BannedRadios,
unique_connections::{self, UniqueConnectionCounts},
};

#[derive(Debug, Default)]
pub struct BoostedHexEligibility {
radio_thresholds: VerifiedRadioThresholds,
banned_radios: BannedRadios,
unique_connections: UniqueConnectionCounts,
}

impl BoostedHexEligibility {
pub fn new(radio_thresholds: VerifiedRadioThresholds, banned_radios: BannedRadios) -> Self {
pub fn new(
radio_thresholds: VerifiedRadioThresholds,
banned_radios: BannedRadios,
unique_connections: UniqueConnectionCounts,
) -> Self {
Self {
radio_thresholds,
banned_radios,
unique_connections,
}
}

pub fn eligibility(
&self,
radio_type: RadioType,
key: PublicKeyBinary,
cbsd_id_opt: Option<String>,
) -> SPBoostedRewardEligibility {
if self.banned_radios.contains(&key, cbsd_id_opt.as_deref()) {
if unique_connections::is_qualified(&self.unique_connections, &key, &radio_type) {
SPBoostedRewardEligibility::Eligible
} else if self.banned_radios.contains(&key, cbsd_id_opt.as_deref()) {
SPBoostedRewardEligibility::ServiceProviderBanned
} else if self.radio_thresholds.is_verified(key, cbsd_id_opt) {
SPBoostedRewardEligibility::Eligible
Expand All @@ -36,9 +49,74 @@ impl BoostedHexEligibility {
mod tests {
use helium_crypto::{KeyTag, Keypair};
use rand::rngs::OsRng;
use unique_connections::MINIMUM_UNIQUE_CONNECTIONS;

use super::*;

#[test]
fn wifi_eligible_with_unique_connections_even_if_banned() {
let keypair = generate_keypair();

let pub_key: PublicKeyBinary = keypair.public_key().to_vec().into();
let cbsd_id = "cbsd-id-1".to_string();

let mut banned_radios = BannedRadios::default();
banned_radios.insert_wifi(pub_key.clone());
banned_radios.insert_cbrs(cbsd_id.clone());

let mut unique_connections = UniqueConnectionCounts::default();
unique_connections.insert(pub_key.clone(), MINIMUM_UNIQUE_CONNECTIONS + 1);

let boosted_hex_eligibility = BoostedHexEligibility::new(
VerifiedRadioThresholds::default(),
banned_radios,
unique_connections,
);

let eligibility =
boosted_hex_eligibility.eligibility(RadioType::OutdoorWifi, pub_key.clone(), None);

assert_eq!(SPBoostedRewardEligibility::Eligible, eligibility);

let eligibility =
boosted_hex_eligibility.eligibility(RadioType::OutdoorCbrs, pub_key, Some(cbsd_id));

assert_eq!(
SPBoostedRewardEligibility::ServiceProviderBanned,
eligibility
);
}

#[test]
fn wifi_eligible_with_unique_connections_even_if_no_radio_threshold() {
let keypair = generate_keypair();

let pub_key: PublicKeyBinary = keypair.public_key().to_vec().into();
let cbsd_id = "cbsd-id-1".to_string();

let mut unique_connections = UniqueConnectionCounts::default();
unique_connections.insert(pub_key.clone(), MINIMUM_UNIQUE_CONNECTIONS + 1);

let boosted_hex_eligibility = BoostedHexEligibility::new(
VerifiedRadioThresholds::default(),
BannedRadios::default(),
unique_connections,
);

let eligibility =
boosted_hex_eligibility.eligibility(RadioType::OutdoorWifi, pub_key.clone(), None);

assert_eq!(SPBoostedRewardEligibility::Eligible, eligibility);

let eligibility =
boosted_hex_eligibility.eligibility(RadioType::OutdoorCbrs, pub_key, Some(cbsd_id));

assert_eq!(
SPBoostedRewardEligibility::RadioThresholdNotMet,
eligibility
);
}

#[test]
fn banned() {
let keypair = generate_keypair();
Expand All @@ -50,17 +128,22 @@ mod tests {
banned_radios.insert_wifi(pub_key.clone());
banned_radios.insert_cbrs(cbsd_id.clone());

let boosted_hex_eligibility =
BoostedHexEligibility::new(VerifiedRadioThresholds::default(), banned_radios);
let boosted_hex_eligibility = BoostedHexEligibility::new(
VerifiedRadioThresholds::default(),
banned_radios,
UniqueConnectionCounts::default(),
);

let eligibility = boosted_hex_eligibility.eligibility(pub_key.clone(), None);
let eligibility =
boosted_hex_eligibility.eligibility(RadioType::OutdoorWifi, pub_key.clone(), None);

assert_eq!(
SPBoostedRewardEligibility::ServiceProviderBanned,
eligibility
);

let eligibility = boosted_hex_eligibility.eligibility(pub_key, Some(cbsd_id));
let eligibility =
boosted_hex_eligibility.eligibility(RadioType::OutdoorCbrs, pub_key, Some(cbsd_id));

assert_eq!(
SPBoostedRewardEligibility::ServiceProviderBanned,
Expand All @@ -75,17 +158,22 @@ mod tests {
let pub_key: PublicKeyBinary = keypair.public_key().to_vec().into();
let cbsd_id = "cbsd-id-1".to_string();

let boosted_hex_eligibility =
BoostedHexEligibility::new(VerifiedRadioThresholds::default(), BannedRadios::default());
let boosted_hex_eligibility = BoostedHexEligibility::new(
VerifiedRadioThresholds::default(),
BannedRadios::default(),
UniqueConnectionCounts::default(),
);

let eligibility = boosted_hex_eligibility.eligibility(pub_key.clone(), None);
let eligibility =
boosted_hex_eligibility.eligibility(RadioType::OutdoorWifi, pub_key.clone(), None);

assert_eq!(
SPBoostedRewardEligibility::RadioThresholdNotMet,
eligibility
);

let eligibility = boosted_hex_eligibility.eligibility(pub_key, Some(cbsd_id));
let eligibility =
boosted_hex_eligibility.eligibility(RadioType::OutdoorCbrs, pub_key, Some(cbsd_id));

assert_eq!(
SPBoostedRewardEligibility::RadioThresholdNotMet,
Expand All @@ -104,14 +192,19 @@ mod tests {
verified_radio_thresholds.insert(pub_key.clone(), None);
verified_radio_thresholds.insert(pub_key.clone(), Some(cbsd_id.clone()));

let boosted_hex_eligibility =
BoostedHexEligibility::new(verified_radio_thresholds, BannedRadios::default());
let boosted_hex_eligibility = BoostedHexEligibility::new(
verified_radio_thresholds,
BannedRadios::default(),
UniqueConnectionCounts::default(),
);

let eligibility = boosted_hex_eligibility.eligibility(pub_key.clone(), None);
let eligibility =
boosted_hex_eligibility.eligibility(RadioType::OutdoorWifi, pub_key.clone(), None);

assert_eq!(SPBoostedRewardEligibility::Eligible, eligibility);

let eligibility = boosted_hex_eligibility.eligibility(pub_key, Some(cbsd_id));
let eligibility =
boosted_hex_eligibility.eligibility(RadioType::OutdoorCbrs, pub_key, Some(cbsd_id));

assert_eq!(SPBoostedRewardEligibility::Eligible, eligibility);
}
Expand Down
2 changes: 1 addition & 1 deletion mobile_verifier/src/unique_connections/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub type UniqueConnectionCounts = HashMap<PublicKeyBinary, u64>;
// hip-134:
// https://github.com/helium/HIP/blob/main/0134-reward-mobile-carrier-offload-hotspots.md
// A Hotspot serving >25 unique connections, as defined by the Carrier utlizing the hotspots for Carrier Offload, on a seven day rolling average.
const MINIMUM_UNIQUE_CONNECTIONS: u64 = 25;
pub const MINIMUM_UNIQUE_CONNECTIONS: u64 = 25;

pub fn is_qualified(
unique_connections: &UniqueConnectionCounts,
Expand Down

0 comments on commit b756ace

Please sign in to comment.