Skip to content

Commit

Permalink
mor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
andymck committed Jul 27, 2023
1 parent 59508cf commit ee0a544
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 9 deletions.
9 changes: 6 additions & 3 deletions mobile_verifier/migrations/15_speedtests_one_to_one.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ CREATE TABLE speedtests_migration (
latency integer,
timestamp timestamptz NOT NULL
);
CREATE INDEX idx_speedtests_pubkey on speedtests_migration (pubkey);

insert into speedtests_migration (pubkey, upload_speed, download_speed, latency, timestamp)
select id, (st).upload_speed, (st).download_speed, (st).latency, (st).timestamp
from (select id, unnest(speedtests) as st from speedtests) as tmp;
INSERT INTO speedtests_migration (pubkey, upload_speed, download_speed, latency, timestamp)
SELECT id, (st).upload_speed, (st).download_speed, (st).latency, (st).timestamp
FROM (select id, unnest(speedtests) as st from speedtests) as tmp;

ALTER TABLE speedtests RENAME TO speedtests_old;
ALTER TABLE speedtests_migration RENAME TO speedtests;


7 changes: 4 additions & 3 deletions mobile_verifier/src/cli/reward_from_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ impl Cmd {
.await?;

let heartbeats = HeartbeatReward::validated(&pool, &epoch);
let averages = SpeedtestAverages::aggregate_epoch_averages(epoch.end, &pool).await?;
let reward_shares = PocShares::aggregate(heartbeats, &averages).await?;
let speedtest_averages =
SpeedtestAverages::aggregate_epoch_averages(epoch.end, &pool).await?;
let reward_shares = PocShares::aggregate(heartbeats, &speedtest_averages).await?;

let mut total_rewards = 0_u64;
let mut owner_rewards = HashMap::<_, u64>::new();
Expand All @@ -62,7 +63,7 @@ impl Cmd {
}
let rewards: Vec<_> = owner_rewards.into_iter().collect();
let mut multiplier_count = HashMap::<_, usize>::new();
let speedtest_multipliers: Vec<_> = averages
let speedtest_multipliers: Vec<_> = speedtest_averages
.averages
.into_iter()
.map(|(pub_key, average)| {
Expand Down
2 changes: 1 addition & 1 deletion mobile_verifier/src/reward_shares.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ pub struct PocShares {
}

impl PocShares {
pub async fn aggregate<'a>(
pub async fn aggregate(
heartbeats: impl Stream<Item = Result<HeartbeatReward, sqlx::Error>>,
speedtest_averages: &SpeedtestAverages,
) -> Result<Self, sqlx::Error> {
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 @@ -174,7 +174,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
// pull the last N most recent speedtests from prior to 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 @@ -185,7 +185,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
// collate the returned speedtests based on pubkey
while let Some(speedtest) = rows.try_next().await? {
speedtests
.entry(speedtest.pubkey.clone())
Expand Down
1 change: 1 addition & 0 deletions mobile_verifier/src/speedtests_average.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ impl SpeedtestAverage {
}

#[allow(dead_code)]
// function used by tests only
pub fn tier(&self) -> SpeedtestTier {
calculate_tier(
self.window_size,
Expand Down

0 comments on commit ee0a544

Please sign in to comment.