Skip to content
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

Verification Mapping #839

Merged
merged 44 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
d55b419
Add verification_mapping proto
macpie Jul 9, 2024
ef2ecea
Add ingest for subscriber_mapping_event
macpie Jul 11, 2024
7b11193
Add SubscriberMappingEventDeamon
macpie Jul 12, 2024
d06dc85
- First pass at rewards for verifier mapping events
macpie Jul 15, 2024
1d46bae
String to Vec<u8>
macpie Jul 15, 2024
fcc9fb1
Fix reward test
macpie Jul 16, 2024
e9ebcb8
Clippy fix
macpie Jul 16, 2024
36cebd5
Add ingestor test
macpie Jul 17, 2024
dba0873
Add mobile verifier test
macpie Jul 17, 2024
b88cc65
Add more testing
macpie Jul 17, 2024
581651b
Updgrade to support report
macpie Jul 18, 2024
20089df
- Do not make report an option
macpie Jul 18, 2024
6ce923e
Fix rewards_per_share
macpie Jul 19, 2024
b60c862
Update from proto
macpie Jul 29, 2024
e6e98a3
Do not impl from_row just for test
macpie Jul 29, 2024
5b5c5f8
Fix rebase
macpie Jul 29, 2024
5fbf7ea
Fix msg type name
macpie Jul 30, 2024
f6ab8e0
Simplify test further
macpie Aug 1, 2024
68dd915
Update mobile_verifier/src/reward_shares.rs
macpie Aug 1, 2024
8771358
Fix var name
macpie Aug 1, 2024
adbd484
Add verification_mapping_amount to subscriber_reward
macpie Aug 1, 2024
303b52f
Use git+https://github.com/helium/proto?branch=macpie%2Fverification…
macpie Aug 2, 2024
2dfaf8e
Do not acc rewards
macpie Aug 2, 2024
45afaf6
Improve tests
macpie Aug 2, 2024
a0a7743
Add timeout to test client
macpie Aug 2, 2024
b0384a1
The moogey commit
macpie Aug 2, 2024
860bf33
Cleanup (txh moogey)
macpie Aug 2, 2024
6ad41c9
Fix tests
macpie Aug 2, 2024
a5cb80f
Add some println
macpie Aug 5, 2024
e82fd93
Fix timestamp issue
macpie Aug 5, 2024
36459f4
Remove unused fn
macpie Aug 5, 2024
ae4e192
Rename for consistency
macpie Aug 7, 2024
8a8c653
Add verified ingest report and rename
macpie Aug 7, 2024
4234177
Fix proto
macpie Aug 7, 2024
83bee39
Clear older events
macpie Aug 7, 2024
2dc6162
Update table name and use `reward_period.start`
macpie Aug 9, 2024
8f02efa
requirements originating from verification mapping verifier
andymck Aug 2, 2024
d91967b
revert proto/beacon to master branch
jeffgrunewald Aug 13, 2024
3c6b24a
fix proto master branch ref
jeffgrunewald Aug 13, 2024
461caed
review tweaks
jeffgrunewald Aug 13, 2024
867dbfb
typo nit
jeffgrunewald Aug 13, 2024
b2540a9
fix reward aggregation to single period
jeffgrunewald Aug 13, 2024
5983704
fix test
jeffgrunewald Aug 13, 2024
14258ae
fix sum type for output decoding
jeffgrunewald Aug 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion coverage_point_calculator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ use service_provider_boosting::{MAX_AVERAGE_DISTANCE, MIN_WIFI_TRUST_MULTIPLIER}
mod hexes;
mod location;
mod service_provider_boosting;
mod speedtest;
pub mod speedtest;

pub type Result<T = ()> = std::result::Result<T, Error>;

Expand Down
12 changes: 7 additions & 5 deletions coverage_point_calculator/src/speedtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use chrono::{DateTime, Utc};
use rust_decimal::Decimal;
use rust_decimal_macros::dec;

const MIN_REQUIRED_SPEEDTEST_SAMPLES: usize = 2;
const MAX_ALLOWED_SPEEDTEST_SAMPLES: usize = 6;
pub const MIN_REQUIRED_SPEEDTEST_SAMPLES: usize = 2;
pub const MAX_ALLOWED_SPEEDTEST_SAMPLES: usize = 6;

type Millis = u32;

Expand Down Expand Up @@ -86,12 +86,14 @@ impl Speedtest {
}

pub fn multiplier(&self) -> Decimal {
self.tier().multiplier()
}

pub fn tier(&self) -> SpeedtestTier {
let upload = SpeedtestTier::from_upload(self.upload_speed);
let download = SpeedtestTier::from_download(self.download_speed);
let latency = SpeedtestTier::from_latency(self.latency_millis);

let tier = upload.min(download).min(latency);
tier.multiplier()
upload.min(download).min(latency)
}

pub fn avg(speedtests: &[Self]) -> Self {
Expand Down
1 change: 1 addition & 0 deletions file_store/src/cli/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ impl Cmd {
Some(Reward::SubscriberReward(reward)) => print_json(&json!({
"subscriber_id": reward.subscriber_id,
"discovery_location_amount": reward.discovery_location_amount,
"verification_mapping_amount": reward.verification_mapping_amount,
}))?,
Some(Reward::ServiceProviderReward(reward)) => print_json(&json!({
"service_provider": reward.service_provider_id,
Expand Down
1 change: 1 addition & 0 deletions file_store/src/cli/dump_mobile_rewards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ impl Cmd {
SubscriberReward(reward) => subscriber_reward.push(json!({
"subscriber_id": uuid::Uuid::from_slice(&reward.subscriber_id).unwrap(),
"discovery_location_amount": reward.discovery_location_amount,
"verification_mapping_amount": reward.verification_mapping_amount,
})),
ServiceProviderReward(reward) => service_provider_reward.push(json!({
"service_provider": reward.service_provider_id,
Expand Down
24 changes: 24 additions & 0 deletions file_store/src/file_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ pub const LANDTYPE_DATA_SET: &str = "landtype";
pub const SP_BOOSTED_REWARDS_BANNED_RADIO: &str = "service_provider_boosted_rewards_banned_radio";
pub const VERIFIED_SP_BOOSTED_REWARDS_BANNED_RADIO: &str =
"verified_service_provider_boosted_rewards_banned_radio";
pub const SUBSCRIBER_VERIFIED_MAPPING_INGEST_REPORT: &str =
"subscriber_verified_mapping_ingest_report";
pub const VERIFIED_SUBSCRIBER_VERIFIED_MAPPING_INGEST_REPORT: &str =
"verified_subscriber_verified_mapping_ingest_report";

#[derive(Debug, PartialEq, Eq, Clone, Serialize, Copy, strum::EnumCount)]
#[serde(rename_all = "snake_case")]
Expand Down Expand Up @@ -214,6 +218,8 @@ pub enum FileType {
VerifiedInvalidatedRadioThresholdIngestReport,
SPBoostedRewardsBannedRadioIngestReport,
VerifiedSPBoostedRewardsBannedRadioIngestReport,
SubscriberVerifiedMappingEventIngestReport,
VerifiedSubscriberVerifiedMappingEventIngestReport,
}

impl fmt::Display for FileType {
Expand Down Expand Up @@ -279,6 +285,12 @@ impl fmt::Display for FileType {
Self::VerifiedSPBoostedRewardsBannedRadioIngestReport => {
VERIFIED_SP_BOOSTED_REWARDS_BANNED_RADIO
}
Self::SubscriberVerifiedMappingEventIngestReport => {
SUBSCRIBER_VERIFIED_MAPPING_INGEST_REPORT
}
Self::VerifiedSubscriberVerifiedMappingEventIngestReport => {
VERIFIED_SUBSCRIBER_VERIFIED_MAPPING_INGEST_REPORT
}
};
f.write_str(s)
}
Expand Down Expand Up @@ -347,6 +359,12 @@ impl FileType {
Self::VerifiedSPBoostedRewardsBannedRadioIngestReport => {
VERIFIED_SP_BOOSTED_REWARDS_BANNED_RADIO
}
Self::SubscriberVerifiedMappingEventIngestReport => {
SUBSCRIBER_VERIFIED_MAPPING_INGEST_REPORT
}
Self::VerifiedSubscriberVerifiedMappingEventIngestReport => {
VERIFIED_SUBSCRIBER_VERIFIED_MAPPING_INGEST_REPORT
}
}
}
}
Expand Down Expand Up @@ -415,6 +433,12 @@ impl FromStr for FileType {
VERIFIED_SP_BOOSTED_REWARDS_BANNED_RADIO => {
Self::VerifiedSPBoostedRewardsBannedRadioIngestReport
}
SUBSCRIBER_VERIFIED_MAPPING_INGEST_REPORT => {
Self::SubscriberVerifiedMappingEventIngestReport
}
VERIFIED_SUBSCRIBER_VERIFIED_MAPPING_INGEST_REPORT => {
Self::VerifiedSubscriberVerifiedMappingEventIngestReport
}
_ => return Err(Error::from(io::Error::from(io::ErrorKind::InvalidInput))),
};
Ok(result)
Expand Down
3 changes: 3 additions & 0 deletions file_store/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ pub mod mobile_transfer;
pub mod reward_manifest;
mod settings;
pub mod speedtest;
pub mod subscriber_verified_mapping_event;
pub mod subscriber_verified_mapping_event_ingest_report;
pub mod traits;
pub mod verified_subscriber_verified_mapping_event_ingest_report;
pub mod wifi_heartbeat;

pub use crate::file_store::FileStore;
Expand Down
53 changes: 53 additions & 0 deletions file_store/src/speedtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use chrono::{DateTime, TimeZone, Utc};
use helium_crypto::PublicKeyBinary;
use helium_proto::services::poc_mobile::{
Speedtest, SpeedtestAvg, SpeedtestAvgValidity, SpeedtestIngestReportV1, SpeedtestReqV1,
SpeedtestVerificationResult, VerifiedSpeedtest as VerifiedSpeedtestProto,
};
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -34,6 +35,10 @@ impl MsgDecode for CellSpeedtestIngestReport {
type Msg = SpeedtestIngestReportV1;
}

impl MsgDecode for VerifiedSpeedtest {
type Msg = VerifiedSpeedtestProto;
}

impl MsgTimestamp<Result<DateTime<Utc>>> for SpeedtestReqV1 {
fn timestamp(&self) -> Result<DateTime<Utc>> {
self.timestamp.to_timestamp()
Expand All @@ -58,6 +63,18 @@ impl MsgTimestamp<u64> for CellSpeedtestIngestReport {
}
}

impl MsgTimestamp<u64> for VerifiedSpeedtest {
fn timestamp(&self) -> u64 {
self.timestamp.encode_timestamp_millis()
}
}

impl MsgTimestamp<Result<DateTime<Utc>>> for VerifiedSpeedtestProto {
fn timestamp(&self) -> Result<DateTime<Utc>> {
self.timestamp.to_timestamp_millis()
}
}

impl From<CellSpeedtest> for SpeedtestReqV1 {
fn from(v: CellSpeedtest) -> Self {
let timestamp = v.timestamp();
Expand Down Expand Up @@ -112,6 +129,42 @@ impl From<CellSpeedtestIngestReport> for SpeedtestIngestReportV1 {
}
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct VerifiedSpeedtest {
pub timestamp: DateTime<Utc>,
pub report: CellSpeedtestIngestReport,
pub result: SpeedtestVerificationResult,
}

impl TryFrom<VerifiedSpeedtestProto> for VerifiedSpeedtest {
type Error = Error;
fn try_from(v: VerifiedSpeedtestProto) -> Result<Self> {
let result = SpeedtestVerificationResult::try_from(v.result).map_err(|_| {
DecodeError::unsupported_status_reason("verified_speedtest_proto", v.result)
})?;
Ok(Self {
timestamp: v.timestamp()?,
report: v
.report
.ok_or_else(|| Error::not_found("ingest verified speedtest report"))?
.try_into()?,
result,
})
}
}

impl From<VerifiedSpeedtest> for VerifiedSpeedtestProto {
fn from(v: VerifiedSpeedtest) -> Self {
let timestamp = v.timestamp();
let report: SpeedtestIngestReportV1 = v.report.into();
Self {
timestamp,
report: Some(report),
result: v.result as i32,
}
}
}

pub mod cli {
use super::*;

Expand Down
58 changes: 58 additions & 0 deletions file_store/src/subscriber_verified_mapping_event.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
use crate::{
traits::{MsgDecode, MsgTimestamp, TimestampDecode, TimestampEncode},
Error, Result,
};
use chrono::{DateTime, Utc};
use helium_crypto::PublicKeyBinary;
use helium_proto::services::poc_mobile::SubscriberVerifiedMappingEventReqV1;
use serde::{Deserialize, Serialize};

#[derive(Clone, Deserialize, Serialize, Debug, PartialEq)]
pub struct SubscriberVerifiedMappingEvent {
pub subscriber_id: Vec<u8>,
pub total_reward_points: u64,
pub timestamp: DateTime<Utc>,
pub carrier_mapping_key: PublicKeyBinary,
}

impl MsgDecode for SubscriberVerifiedMappingEvent {
type Msg = SubscriberVerifiedMappingEventReqV1;
}

impl MsgTimestamp<Result<DateTime<Utc>>> for SubscriberVerifiedMappingEventReqV1 {
fn timestamp(&self) -> Result<DateTime<Utc>> {
self.timestamp.to_timestamp()
}
}

impl MsgTimestamp<u64> for SubscriberVerifiedMappingEvent {
fn timestamp(&self) -> u64 {
self.timestamp.encode_timestamp()
}
}

impl From<SubscriberVerifiedMappingEvent> for SubscriberVerifiedMappingEventReqV1 {
fn from(v: SubscriberVerifiedMappingEvent) -> Self {
let timestamp = v.timestamp();
SubscriberVerifiedMappingEventReqV1 {
subscriber_id: v.subscriber_id,
total_reward_points: v.total_reward_points,
timestamp,
carrier_mapping_key: v.carrier_mapping_key.into(),
signature: vec![],
}
}
}

impl TryFrom<SubscriberVerifiedMappingEventReqV1> for SubscriberVerifiedMappingEvent {
type Error = Error;
fn try_from(v: SubscriberVerifiedMappingEventReqV1) -> Result<Self> {
let timestamp = v.timestamp()?;
Ok(Self {
subscriber_id: v.subscriber_id,
total_reward_points: v.total_reward_points,
timestamp,
carrier_mapping_key: v.carrier_mapping_key.into(),
})
}
}
62 changes: 62 additions & 0 deletions file_store/src/subscriber_verified_mapping_event_ingest_report.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
use crate::{
subscriber_verified_mapping_event::SubscriberVerifiedMappingEvent,
traits::{MsgDecode, MsgTimestamp, TimestampDecode, TimestampEncode},
Error, Result,
};
use chrono::{DateTime, Utc};
use helium_proto::services::poc_mobile::{
SubscriberVerifiedMappingEventIngestReportV1, SubscriberVerifiedMappingEventReqV1,
};
use serde::{Deserialize, Serialize};

#[derive(Clone, Deserialize, Serialize, Debug, PartialEq)]
pub struct SubscriberVerifiedMappingEventIngestReport {
pub received_timestamp: DateTime<Utc>,
pub report: SubscriberVerifiedMappingEvent,
}

impl MsgDecode for SubscriberVerifiedMappingEventIngestReport {
type Msg = SubscriberVerifiedMappingEventIngestReportV1;
}

impl MsgTimestamp<Result<DateTime<Utc>>> for SubscriberVerifiedMappingEventIngestReportV1 {
fn timestamp(&self) -> Result<DateTime<Utc>> {
self.received_timestamp.to_timestamp()
}
}

impl MsgTimestamp<u64> for SubscriberVerifiedMappingEventIngestReport {
fn timestamp(&self) -> u64 {
self.received_timestamp.encode_timestamp()
}
}

impl From<SubscriberVerifiedMappingEventIngestReport>
for SubscriberVerifiedMappingEventIngestReportV1
{
fn from(v: SubscriberVerifiedMappingEventIngestReport) -> Self {
let received_timestamp = v.timestamp();
let report: SubscriberVerifiedMappingEventReqV1 = v.report.into();
Self {
received_timestamp,
report: Some(report),
}
}
}

impl TryFrom<SubscriberVerifiedMappingEventIngestReportV1>
for SubscriberVerifiedMappingEventIngestReport
{
type Error = Error;
fn try_from(v: SubscriberVerifiedMappingEventIngestReportV1) -> Result<Self> {
Ok(Self {
received_timestamp: v.timestamp()?,
report: v
.report
.ok_or_else(|| {
Error::not_found("ingest SubscriberVerifiedMappingEventIngestReport report")
})?
.try_into()?,
})
}
}
3 changes: 2 additions & 1 deletion file_store/src/traits/msg_verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use helium_crypto::{PublicKey, Verify};
use helium_proto::services::{
iot_config, mobile_config,
poc_lora::{LoraBeaconReportReqV1, LoraStreamSessionInitV1, LoraWitnessReportReqV1},
poc_mobile::ServiceProviderBoostedRewardsBannedRadioReqV1,
poc_mobile::{self, ServiceProviderBoostedRewardsBannedRadioReqV1},
};
use helium_proto::{
services::poc_mobile::{
Expand Down Expand Up @@ -94,6 +94,7 @@ impl_msg_verify!(mobile_config::GatewayInfoStreamResV1, signature);
impl_msg_verify!(mobile_config::BoostedHexInfoStreamReqV1, signature);
impl_msg_verify!(mobile_config::BoostedHexModifiedInfoStreamReqV1, signature);
impl_msg_verify!(mobile_config::BoostedHexInfoStreamResV1, signature);
impl_msg_verify!(poc_mobile::SubscriberVerifiedMappingEventReqV1, signature);

#[cfg(test)]
mod test {
Expand Down
Loading