Skip to content

Commit

Permalink
Address feedback, move oracle_boosting_status into RadioInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
bbalser committed Aug 29, 2024
1 parent 28510bd commit 73a0c61
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 25 deletions.
2 changes: 1 addition & 1 deletion mobile_verifier/src/cli/reward_from_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ impl Cmd {
&speedtest_averages,
&BoostedHexes::default(),
&BoostedHexEligibility::default(),
&BannedRadios::default(),
&epoch,
)
.await?;
Expand All @@ -59,7 +60,6 @@ impl Cmd {
.into_rewards(
DataTransferAndPocAllocatedRewardBuckets::new(&epoch),
&epoch,
BannedRadios::default(),
)
.ok_or(anyhow::anyhow!("no rewardable events"))?
.1;
Expand Down
40 changes: 24 additions & 16 deletions mobile_verifier/src/reward_shares.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ struct RadioInfo {
trust_scores: Vec<coverage_point_calculator::LocationTrust>,
sp_boosted_reward_eligibility: SPBoostedRewardEligibility,
speedtests: Vec<coverage_point_calculator::Speedtest>,
oracle_boosting_status: OracleBoostingStatus,
}

#[derive(Debug)]
Expand All @@ -537,6 +538,7 @@ impl CoverageShares {
speedtest_averages: &SpeedtestAverages,
boosted_hexes: &BoostedHexes,
boosted_hex_eligibility: &BoostedHexEligibility,
banned_radios: &BannedRadios,
reward_period: &Range<DateTime<Utc>>,
) -> anyhow::Result<Self> {
let mut radio_infos: HashMap<RadioId, RadioInfo> = HashMap::new();
Expand Down Expand Up @@ -607,6 +609,12 @@ impl CoverageShares {
})
.collect();

let oracle_boosting_status = if banned_radios.contains(&pubkey, cbsd_id.as_deref()) {
OracleBoostingStatus::Banned
} else {
OracleBoostingStatus::Eligible
};

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

Expand All @@ -628,6 +636,7 @@ impl CoverageShares {
trust_scores,
sp_boosted_reward_eligibility,
speedtests,
oracle_boosting_status,
},
);
}
Expand Down Expand Up @@ -672,7 +681,6 @@ impl CoverageShares {
self,
reward_shares: DataTransferAndPocAllocatedRewardBuckets,
epoch: &'_ Range<DateTime<Utc>>,
banned_radios: BannedRadios,
) -> Option<(
CalculatedPocRewardShares,
impl Iterator<Item = (u64, proto::MobileRewardShare, proto::MobileRewardShare)> + '_,
Expand All @@ -686,14 +694,7 @@ impl CoverageShares {

let mut processed_radios = vec![];
for (radio_id, radio_info) in self.radio_infos.iter() {
let (pubkey, cbsd_id) = radio_id;
let oracle_boosting_status = if banned_radios.contains(pubkey, cbsd_id.as_deref()) {
OracleBoostingStatus::Banned
} else {
OracleBoostingStatus::Eligible
};

let points = match self.coverage_points(radio_id, oracle_boosting_status) {
let points = match self.coverage_points(radio_id, radio_info.oracle_boosting_status) {
Ok(points) => points,
Err(err) => {
tracing::error!(
Expand Down Expand Up @@ -1317,11 +1318,12 @@ mod test {
&speedtest_avgs,
&BoostedHexes::default(),
&BoostedHexEligibility::default(),
&BannedRadios::default(),
&epoch,
)
.await
.unwrap()
.into_rewards(reward_shares, &epoch, BannedRadios::default())
.into_rewards(reward_shares, &epoch)
.unwrap()
.1
.next()
Expand Down Expand Up @@ -1719,11 +1721,12 @@ mod test {
&speedtest_avgs,
&BoostedHexes::default(),
&BoostedHexEligibility::default(),
&BannedRadios::default(),
&epoch,
)
.await
.unwrap()
.into_rewards(reward_shares, &epoch, BannedRadios::default())
.into_rewards(reward_shares, &epoch)
.unwrap()
.1
{
Expand Down Expand Up @@ -1899,11 +1902,12 @@ mod test {
&speedtest_avgs,
&BoostedHexes::default(),
&BoostedHexEligibility::default(),
&BannedRadios::default(),
&epoch,
)
.await
.unwrap()
.into_rewards(reward_shares, &epoch, BannedRadios::default())
.into_rewards(reward_shares, &epoch)
.unwrap()
.1
{
Expand Down Expand Up @@ -2032,11 +2036,12 @@ mod test {
&speedtest_avgs,
&BoostedHexes::default(),
&BoostedHexEligibility::default(),
&BannedRadios::default(),
&epoch,
)
.await
.unwrap()
.into_rewards(reward_shares, &epoch, BannedRadios::default())
.into_rewards(reward_shares, &epoch)
.unwrap()
.1
{
Expand Down Expand Up @@ -2166,11 +2171,12 @@ mod test {
&speedtest_avgs,
&BoostedHexes::default(),
&BoostedHexEligibility::default(),
&BannedRadios::default(),
&epoch,
)
.await
.unwrap()
.into_rewards(reward_shares, &epoch, BannedRadios::default())
.into_rewards(reward_shares, &epoch)
.unwrap()
.1
{
Expand Down Expand Up @@ -2280,6 +2286,7 @@ mod test {
timestamp: now,
},
],
oracle_boosting_status: OracleBoostingStatus::Eligible,
},
);
radio_infos.insert(
Expand All @@ -2300,6 +2307,7 @@ mod test {
},
sp_boosted_reward_eligibility: SPBoostedRewardEligibility::Eligible,
speedtests: vec![],
oracle_boosting_status: OracleBoostingStatus::Eligible,
},
);

Expand All @@ -2312,7 +2320,7 @@ mod test {
// gw2 does not have enough speedtests for a mulitplier
let expected_hotspot = gw1;
for (_reward_amount, _mobile_reward_v1, mobile_reward_v2) in coverage_shares
.into_rewards(reward_shares, &epoch, BannedRadios::default())
.into_rewards(reward_shares, &epoch)
.expect("rewards output")
.1
{
Expand All @@ -2337,7 +2345,7 @@ mod test {

let reward_shares = DataTransferAndPocAllocatedRewardBuckets::new_poc_only(&epoch);
assert!(coverage_shares
.into_rewards(reward_shares, &epoch, BannedRadios::default())
.into_rewards(reward_shares, &epoch)
.is_none());
}

Expand Down
17 changes: 9 additions & 8 deletions mobile_verifier/src/rewarder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,28 +434,29 @@ async fn reward_poc(
.await?,
);

let poc_banned_radios = sp_boosted_rewards_bans::db::get_banned_radios(
pool,
SpBoostedRewardsBannedRadioBanType::Poc,
reward_period.end,
)
.await?;

let coverage_shares = CoverageShares::new(
pool,
heartbeats,
&speedtest_averages,
&boosted_hexes,
&boosted_hex_eligibility,
&poc_banned_radios,
reward_period,
)
.await?;

let poc_banned_radios = sp_boosted_rewards_bans::db::get_banned_radios(
pool,
SpBoostedRewardsBannedRadioBanType::Poc,
reward_period.end,
)
.await?;

let total_poc_rewards = reward_shares.total_poc();

let (unallocated_poc_amount, calculated_poc_rewards_per_share) =
if let Some((calculated_poc_rewards_per_share, mobile_reward_shares)) =
coverage_shares.into_rewards(reward_shares, reward_period, poc_banned_radios)
coverage_shares.into_rewards(reward_shares, reward_period)
{
// handle poc reward outputs
let mut allocated_poc_rewards = 0_u64;
Expand Down
2 changes: 2 additions & 0 deletions mobile_verifier/tests/integrations/boosting_oracles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use mobile_verifier::{
reward_shares::CoverageShares,
rewarder::boosted_hex_eligibility::BoostedHexEligibility,
seniority::{Seniority, SeniorityUpdate},
sp_boosted_rewards_bans::BannedRadios,
speedtests::Speedtest,
speedtests_average::{SpeedtestAverage, SpeedtestAverages},
GatewayResolution, GatewayResolver,
Expand Down Expand Up @@ -402,6 +403,7 @@ async fn test_footfall_and_urbanization_and_landtype(pool: PgPool) -> anyhow::Re
&speedtest_avgs,
&BoostedHexes::default(),
&BoostedHexEligibility::default(),
&BannedRadios::default(),
&epoch,
)
.await
Expand Down
7 changes: 7 additions & 0 deletions mobile_verifier/tests/integrations/modeled_coverage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use mobile_verifier::{
reward_shares::CoverageShares,
rewarder::boosted_hex_eligibility::BoostedHexEligibility,
seniority::{Seniority, SeniorityUpdate},
sp_boosted_rewards_bans::BannedRadios,
speedtests::Speedtest,
speedtests_average::{SpeedtestAverage, SpeedtestAverages},
GatewayResolution, GatewayResolver, IsAuthorized,
Expand Down Expand Up @@ -497,6 +498,7 @@ async fn scenario_one(pool: PgPool) -> anyhow::Result<()> {
&speedtest_avgs,
&BoostedHexes::default(),
&BoostedHexEligibility::default(),
&BannedRadios::default(),
&reward_period,
)
.await?;
Expand Down Expand Up @@ -599,6 +601,7 @@ async fn scenario_two(pool: PgPool) -> anyhow::Result<()> {
&speedtest_avgs,
&BoostedHexes::default(),
&BoostedHexEligibility::default(),
&BannedRadios::default(),
&reward_period,
)
.await?;
Expand Down Expand Up @@ -887,6 +890,7 @@ async fn scenario_three(pool: PgPool) -> anyhow::Result<()> {
&speedtest_avgs,
&boosted_hexes,
&BoostedHexEligibility::default(),
&BannedRadios::default(),
&reward_period,
)
.await?;
Expand Down Expand Up @@ -976,6 +980,7 @@ async fn scenario_four(pool: PgPool) -> anyhow::Result<()> {
&speedtest_avgs,
&BoostedHexes::default(),
&BoostedHexEligibility::default(),
&BannedRadios::default(),
&reward_period,
)
.await?;
Expand Down Expand Up @@ -1077,6 +1082,7 @@ async fn scenario_five(pool: PgPool) -> anyhow::Result<()> {
&speedtest_avgs,
&BoostedHexes::default(),
&BoostedHexEligibility::default(),
&BannedRadios::default(),
&reward_period,
)
.await?;
Expand Down Expand Up @@ -1326,6 +1332,7 @@ async fn scenario_six(pool: PgPool) -> anyhow::Result<()> {
&speedtest_avgs,
&BoostedHexes::default(),
&BoostedHexEligibility::default(),
&BannedRadios::default(),
&reward_period,
)
.await?;
Expand Down

0 comments on commit 73a0c61

Please sign in to comment.