Skip to content

Commit

Permalink
tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
andymck committed Jul 27, 2023
1 parent 6ef491b commit 090bcb1
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 11 deletions.
8 changes: 4 additions & 4 deletions mobile_verifier/src/reward_shares.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,14 @@ pub struct PocShares {
impl PocShares {
pub async fn aggregate<'a>(
heartbeats: impl Stream<Item = Result<HeartbeatReward, sqlx::Error>>,
averages: &SpeedtestAverages,
speedtest_averages: &SpeedtestAverages,
) -> Result<Self, sqlx::Error> {
let mut poc_shares = Self::default();
let mut heartbeats = std::pin::pin!(heartbeats);
while let Some(heartbeat) = heartbeats.next().await.transpose()? {
let speedmultiplier = averages
.averages
.get(&heartbeat.hotspot_key)
let speedmultiplier = speedtest_averages
.get_average(&heartbeat.hotspot_key)
.as_ref()
.map_or(Decimal::ZERO, SpeedtestAverage::reward_multiplier);
*poc_shares
.hotspot_shares
Expand Down
4 changes: 2 additions & 2 deletions mobile_verifier/src/rewarder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ impl Rewarder {
);

let heartbeats = HeartbeatReward::validated(&self.pool, reward_period);
let averages =
let speedtest_averages =
SpeedtestAverages::aggregate_epoch_averages(reward_period.end, &self.pool).await?;
let poc_rewards = PocShares::aggregate(heartbeats, &averages).await?;
let poc_rewards = PocShares::aggregate(heartbeats, &speedtest_averages).await?;
let mobile_price = self
.price_tracker
.price(&helium_proto::BlockchainTokenTypeV1::Mobile)
Expand Down
4 changes: 2 additions & 2 deletions mobile_verifier/src/speedtests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ pub async fn aggregate_epoch_speedtests<'a>(
exec: impl sqlx::PgExecutor<'a> + Copy + 'a,
) -> Result<EpochSpeedTests, sqlx::Error> {
let mut speedtests = EpochSpeedTests::new();

// pull the last N most recent speedtests up until the epoch end for each pubkey
let mut rows = sqlx::query_as::<_, Speedtest>(
"select * from (
SELECT distinct(pubkey), upload_speed, download_speed, latency, timestamp, row_number()
Expand All @@ -187,7 +187,7 @@ pub async fn aggregate_epoch_speedtests<'a>(
.bind(epoch_end)
.bind(SPEEDTEST_AVG_MAX_DATA_POINTS as i64)
.fetch(exec);

// iterate over the returned rows, collate the speedtest based on pubkey
while let Some(speedtest) = rows.try_next().await? {
speedtests
.entry(speedtest.pubkey.clone())
Expand Down
4 changes: 1 addition & 3 deletions mobile_verifier/src/speedtests_average.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ use crate::speedtests::{self, Speedtest};
use chrono::{DateTime, Duration, Utc};
use file_store::{file_sink::FileSinkClient, traits::TimestampEncode};
use helium_crypto::PublicKeyBinary;
use helium_proto::services::poc_mobile::SpeedtestAvgValidity;
use helium_proto::services::poc_mobile::{self as proto};
use helium_proto::services::poc_mobile::{self as proto, SpeedtestAvgValidity};
use rust_decimal::Decimal;
use rust_decimal_macros::dec;
use sqlx::FromRow;
Expand Down Expand Up @@ -224,7 +223,6 @@ impl SpeedtestAverages {
self.averages.into_values()
}

#[allow(dead_code)]
pub fn get_average(&self, pub_key: &PublicKeyBinary) -> Option<SpeedtestAverage> {
self.averages.get(pub_key).cloned()
}
Expand Down

0 comments on commit 090bcb1

Please sign in to comment.