Skip to content

Add 300Mbps speedtest validation with bounds checking #1031

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

kurotych
Copy link
Member

@kurotych kurotych commented Aug 15, 2025

Implements SpeedtestValueOutOfBounds validation to not count speedtests exceeding 300Mbps upload/download limits.

Implements SpeedtestValueOutOfBounds validation to reject speedtests
exceeding 300MB upload/download limits.
@kurotych kurotych marked this pull request as ready for review August 15, 2025 14:27
@michaeldjeffrey
Copy link
Contributor

[..] we have limits 150Mbit for download and 15Mbit for upload configured on the HMH [..]

@bbalser and I were reviewing this earlier, and believe we have a confusion between Mbps and MBps.

We should be checking these values against Megabits/ps.

Probably this constant in the coverage point calculator should be renamed. The value is correct, but the name is incorrect. Should be const BYTES_PER_MEGABIT: u64 = 125_000;.

I think all the tests should be using the mbps() helper rather than BYTES * 1024 * 1024.

@kurotych kurotych changed the title Add 300MB speedtest validation with bounds checking Add 300Mbps speedtest validation with bounds checking Aug 18, 2025
@kurotych kurotych requested a review from Copilot August 18, 2025 10:47
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements validation for speedtest data to prevent unrealistic values from affecting reward calculations. It adds bounds checking to reject speedtests exceeding 300 Mbps upload/download limits.

Key changes:

  • Adds SpeedtestValueOutOfBounds validation logic with 300 Mbps threshold
  • Extracts BYTES_PER_MEGABIT constant for reuse across modules
  • Updates proto dependency to include new verification result enum

Reviewed Changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 8 comments.

File Description
mobile_verifier/src/speedtests.rs Implements bounds checking logic in validate_speedtest method
mobile_verifier/tests/integrations/speedtests.rs Adds comprehensive test coverage for bounds validation scenarios
coverage_point_calculator/src/speedtest.rs Extracts BYTES_PER_MEGABIT as public constant
Cargo.toml Updates helium-proto dependency to branch with SpeedtestValueOutOfBounds enum

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

pubkey: hotspot.clone(),
serial: "test-serial".to_string(),
timestamp: Utc::now(),
upload_speed: mbps(400), // exceeds limit
Copy link
Preview

Copilot AI Aug 18, 2025

Choose a reason for hiding this comment

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

[nitpick] Comment contains inconsistent unit reference. The limit and description are for '300Mbps' but the comment says 'exceeds limit' without specifying the unit consistently with the PR description.

Suggested change
upload_speed: mbps(400), // exceeds limit
upload_speed: mbps(400), // exceeds 300Mbps limit

Copilot uses AI. Check for mistakes.

}

#[sqlx::test]
async fn speedtest_download_exceeds_300mb_limit(pool: Pool<Postgres>) -> anyhow::Result<()> {
Copy link
Preview

Copilot AI Aug 18, 2025

Choose a reason for hiding this comment

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

Function name uses 'mb' but should use 'mbps' to be consistent with the speed measurement unit. The limit is 300 Mbps (megabits per second), not 300 MB (megabytes).

Suggested change
async fn speedtest_download_exceeds_300mb_limit(pool: Pool<Postgres>) -> anyhow::Result<()> {
async fn speedtest_download_exceeds_300mbps_limit(pool: Pool<Postgres>) -> anyhow::Result<()> {

Copilot uses AI. Check for mistakes.

}

#[sqlx::test]
async fn speedtest_both_speeds_exceed_300mb_limit(pool: Pool<Postgres>) -> anyhow::Result<()> {
Copy link
Preview

Copilot AI Aug 18, 2025

Choose a reason for hiding this comment

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

Function name uses 'mb' but should use 'mbps' to be consistent with the speed measurement unit. The limit is 300 Mbps (megabits per second), not 300 MB (megabytes).

Suggested change
async fn speedtest_both_speeds_exceed_300mb_limit(pool: Pool<Postgres>) -> anyhow::Result<()> {
async fn speedtest_both_speeds_exceed_300mbps_limit(pool: Pool<Postgres>) -> anyhow::Result<()> {

Copilot uses AI. Check for mistakes.

}

#[sqlx::test]
async fn speedtest_within_300mb_limit_should_be_valid(pool: Pool<Postgres>) -> anyhow::Result<()> {
Copy link
Preview

Copilot AI Aug 18, 2025

Choose a reason for hiding this comment

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

Function name uses 'mb' but should use 'mbps' to be consistent with the speed measurement unit. The limit is 300 Mbps (megabits per second), not 300 MB (megabytes).

Suggested change
async fn speedtest_within_300mb_limit_should_be_valid(pool: Pool<Postgres>) -> anyhow::Result<()> {
async fn speedtest_within_300mbps_limit_should_be_valid(pool: Pool<Postgres>) -> anyhow::Result<()> {

Copilot uses AI. Check for mistakes.

}

#[sqlx::test]
async fn speedtest_exactly_300mb_limit_should_be_valid(pool: Pool<Postgres>) -> anyhow::Result<()> {
Copy link
Preview

Copilot AI Aug 18, 2025

Choose a reason for hiding this comment

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

Function name uses 'mb' but should use 'mbps' to be consistent with the speed measurement unit. The limit is 300 Mbps (megabits per second), not 300 MB (megabytes).

Suggested change
async fn speedtest_exactly_300mb_limit_should_be_valid(pool: Pool<Postgres>) -> anyhow::Result<()> {
async fn speedtest_exactly_300mbps_limit_should_be_valid(pool: Pool<Postgres>) -> anyhow::Result<()> {

Copilot uses AI. Check for mistakes.

latency: 80, // Poor tier
},
},
// Invalid speedtest - upload exceeds 300MB, should NOT be included
Copy link
Preview

Copilot AI Aug 18, 2025

Choose a reason for hiding this comment

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

Comment uses 'MB' but should use 'Mbps' to be consistent with the speed measurement unit. The limit is 300 Mbps (megabits per second), not 300 MB (megabytes).

Suggested change
// Invalid speedtest - upload exceeds 300MB, should NOT be included
// Invalid speedtest - upload exceeds 300 Mbps, should NOT be included

Copilot uses AI. Check for mistakes.

latency: 90, // Poor tier
},
},
// Invalid speedtest - download exceeds 300MB, should NOT be included
Copy link
Preview

Copilot AI Aug 18, 2025

Choose a reason for hiding this comment

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

Comment uses 'MB' but should use 'Mbps' to be consistent with the speed measurement unit. The limit is 300 Mbps (megabits per second), not 300 MB (megabytes).

Suggested change
// Invalid speedtest - download exceeds 300MB, should NOT be included
// Invalid speedtest - download exceeds 300 Mbps, should NOT be included

Copilot uses AI. Check for mistakes.

let avgs = speedtest_avg_receiver.finish().await?;

// Should have 2 average entries (one for each valid speedtest)
// Invalid speedtests with speeds > 300MB should NOT generate averages
Copy link
Preview

Copilot AI Aug 18, 2025

Choose a reason for hiding this comment

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

Comment uses 'MB' but should use 'Mbps' to be consistent with the speed measurement unit. The limit is 300 Mbps (megabits per second), not 300 MB (megabytes).

Suggested change
// Invalid speedtests with speeds > 300MB should NOT generate averages
// Invalid speedtests with speeds > 300 Mbps should NOT generate averages

Copilot uses AI. Check for mistakes.

@kurotych
Copy link
Member Author

[..] we have limits 150Mbit for download and 15Mbit for upload configured on the HMH [..]

@bbalser and I were reviewing this earlier, and believe we have a confusion between Mbps and MBps.

We should be checking these values against Megabits/ps.

Probably this constant in the coverage point calculator should be renamed. The value is correct, but the name is incorrect. Should be const BYTES_PER_MEGABIT: u64 = 125_000;.

I think all the tests should be using the mbps() helper rather than BYTES * 1024 * 1024.

Good catch, thank you!
It should be fixed now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants