Skip to content

Commit

Permalink
Add device type to boosted hex info
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldjeffrey committed Sep 6, 2024
1 parent 3836e93 commit ed652e2
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 4 deletions.
7 changes: 6 additions & 1 deletion boost_manager/tests/integrations/activator_tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use boost_manager::{activator, db, OnChainStatus};
use chrono::{DateTime, Duration as ChronoDuration, Duration, Timelike, Utc};
use mobile_config::boosted_hex_info::{BoostedHex, BoostedHexInfo, BoostedHexes};
use mobile_config::boosted_hex_info::{
BoostedHex, BoostedHexDeviceType, BoostedHexInfo, BoostedHexes,
};
use solana_sdk::pubkey::Pubkey;
use sqlx::PgPool;
use std::{num::NonZeroU32, str::FromStr};
Expand Down Expand Up @@ -50,6 +52,7 @@ impl TestContext {
boosted_hex_pubkey: Pubkey::from_str(BOOST_HEX_PUBKEY).unwrap(),
boost_config_pubkey: Pubkey::from_str(BOOST_CONFIG_PUBKEY).unwrap(),
version: 0,
device_type: BoostedHexDeviceType::All,
},
BoostedHexInfo {
location: 0x8a1fb49642dffff_u64.try_into().expect("valid h3 cell"),
Expand All @@ -60,6 +63,7 @@ impl TestContext {
boosted_hex_pubkey: Pubkey::from_str(BOOST_HEX_PUBKEY).unwrap(),
boost_config_pubkey: Pubkey::from_str(BOOST_CONFIG_PUBKEY).unwrap(),
version: 0,
device_type: BoostedHexDeviceType::All,
},
BoostedHexInfo {
// hotspot 3's location
Expand All @@ -71,6 +75,7 @@ impl TestContext {
boosted_hex_pubkey: Pubkey::from_str(BOOST_HEX_PUBKEY).unwrap(),
boost_config_pubkey: Pubkey::from_str(BOOST_CONFIG_PUBKEY).unwrap(),
version: 0,
device_type: BoostedHexDeviceType::All,
},
];
Ok(Self {
Expand Down
7 changes: 6 additions & 1 deletion boost_manager/tests/integrations/watcher_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use crate::common::{self, MockFileSinkReceiver, MockHexBoostingClient};
use boost_manager::watcher::{self, Watcher};
use chrono::{Duration as ChronoDuration, Duration, Utc};
use helium_proto::BoostedHexInfoV1 as BoostedHexInfoProto;
use mobile_config::boosted_hex_info::BoostedHexInfo;
use mobile_config::{
boosted_hex_info::{BoostedHexDeviceType, BoostedHexInfo, BoostedHexInfoStream},
client::{hex_boosting_client::HexBoostingInfoResolver, ClientError},
};
use solana_sdk::pubkey::Pubkey;
use sqlx::PgPool;
use std::{num::NonZeroU32, str::FromStr};
Expand Down Expand Up @@ -45,6 +48,7 @@ async fn test_boosted_hex_updates_to_filestore(pool: PgPool) -> anyhow::Result<(
boosted_hex_pubkey: Pubkey::from_str(BOOST_HEX_PUBKEY).unwrap(),
boost_config_pubkey: Pubkey::from_str(BOOST_CONFIG_PUBKEY).unwrap(),
version: 0,
device_type: BoostedHexDeviceType::All,
},
BoostedHexInfo {
location: 0x8a1fb49642dffff_u64.try_into().expect("valid h3 cell"),
Expand All @@ -55,6 +59,7 @@ async fn test_boosted_hex_updates_to_filestore(pool: PgPool) -> anyhow::Result<(
boosted_hex_pubkey: Pubkey::from_str(BOOST_HEX_PUBKEY).unwrap(),
boost_config_pubkey: Pubkey::from_str(BOOST_CONFIG_PUBKEY).unwrap(),
version: 0,
device_type: BoostedHexDeviceType::All,
},
];

Expand Down
62 changes: 62 additions & 0 deletions mobile_config/src/boosted_hex_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use chrono::{DateTime, Duration, Utc};
use file_store::traits::TimestampDecode;
use futures::stream::{BoxStream, StreamExt};
use helium_proto::services::poc_mobile::BoostedHex as BoostedHexProto;
use helium_proto::BoostedHexDeviceTypeV1 as BoostedHexDeviceTypeProto;
use helium_proto::BoostedHexInfoV1 as BoostedHexInfoProto;
use hextree::Cell;
use solana_sdk::pubkey::Pubkey;
Expand All @@ -24,12 +25,14 @@ pub struct BoostedHexInfo {
pub boosted_hex_pubkey: Pubkey,
pub boost_config_pubkey: Pubkey,
pub version: u32,
pub device_type: BoostedHexDeviceType,
}

impl TryFrom<BoostedHexInfoProto> for BoostedHexInfo {
type Error = anyhow::Error;
fn try_from(v: BoostedHexInfoProto) -> anyhow::Result<Self> {
let period_length = Duration::seconds(v.period_length as i64);
let device_type = v.device_type();
let multipliers = v
.multipliers
.into_iter()
Expand All @@ -49,6 +52,7 @@ impl TryFrom<BoostedHexInfoProto> for BoostedHexInfo {
boosted_hex_pubkey,
boost_config_pubkey,
version: v.version,
device_type: device_type.into(),
})
}
}
Expand All @@ -73,6 +77,7 @@ impl TryFrom<BoostedHexInfo> for BoostedHexInfoProto {
boosted_hex_pubkey: v.boosted_hex_pubkey.to_bytes().into(),
boost_config_pubkey: v.boost_config_pubkey.to_bytes().into(),
version: v.version,
device_type: v.device_type.into(),
})
}
}
Expand Down Expand Up @@ -102,6 +107,53 @@ impl BoostedHexInfo {
}
}

#[derive(Debug, Clone)]
pub enum BoostedHexDeviceType {
All,
CbrsIndoor,
CbrsOutdoor,
WifiIndoor,
WifiOutdoor,
}

impl From<BoostedHexDeviceTypeProto> for BoostedHexDeviceType {
fn from(device_type_proto: BoostedHexDeviceTypeProto) -> Self {
match device_type_proto {
BoostedHexDeviceTypeProto::All => Self::All,
BoostedHexDeviceTypeProto::CbrsIndoor => Self::CbrsIndoor,
BoostedHexDeviceTypeProto::CbrsOutdoor => Self::CbrsOutdoor,
BoostedHexDeviceTypeProto::WifiIndoor => Self::WifiIndoor,
BoostedHexDeviceTypeProto::WifiOutdoor => Self::WifiOutdoor,
}
}
}

impl From<BoostedHexDeviceType> for BoostedHexDeviceTypeProto {
fn from(device_type: BoostedHexDeviceType) -> Self {
match device_type {
BoostedHexDeviceType::All => Self::All,
BoostedHexDeviceType::CbrsIndoor => Self::CbrsIndoor,
BoostedHexDeviceType::CbrsOutdoor => Self::CbrsOutdoor,
BoostedHexDeviceType::WifiIndoor => Self::WifiIndoor,
BoostedHexDeviceType::WifiOutdoor => Self::WifiOutdoor,
}
}
}

impl From<BoostedHexDeviceType> for i32 {
fn from(device_type: BoostedHexDeviceType) -> Self {
BoostedHexDeviceTypeProto::from(device_type) as i32
}
}

impl TryFrom<i32> for BoostedHexDeviceType {
type Error = helium_proto::DecodeError;

fn try_from(db_value: i32) -> Result<Self, Self::Error> {
Ok(BoostedHexDeviceTypeProto::try_from(db_value)?.into())
}
}

#[derive(Debug, Clone, Default)]
pub struct BoostedHexes {
hexes: HashMap<Cell, BoostedHexInfo>,
Expand Down Expand Up @@ -280,6 +332,12 @@ pub(crate) mod db {
let location = Cell::try_from(row.get::<i64, &str>("location"))
.map_err(|e| sqlx::Error::Decode(Box::new(e)))?;

let device_type = match row.get::<Option<i32>, &str>("device_type") {
None => super::BoostedHexDeviceType::All,
Some(val) => super::BoostedHexDeviceType::try_from(val)
.map_err(|e| sqlx::Error::Decode(Box::new(e)))?,
};

Ok(Self {
location,
start_ts,
Expand All @@ -289,6 +347,7 @@ pub(crate) mod db {
boosted_hex_pubkey,
boost_config_pubkey,
version,
device_type,
})
}
}
Expand Down Expand Up @@ -337,6 +396,7 @@ mod tests {
.to_bytes()
.to_vec(),
version: 1,
device_type: BoostedHexDeviceTypeProto::All.into(),
};

let msg = BoostedHexInfo::try_from(proto)?;
Expand Down Expand Up @@ -378,6 +438,7 @@ mod tests {
.to_bytes()
.to_vec(),
version: 1,
device_type: BoostedHexDeviceTypeProto::All.into(),
};

let msg = BoostedHexInfo::try_from(proto)?;
Expand Down Expand Up @@ -413,6 +474,7 @@ mod tests {
boosted_hex_pubkey: BOOST_HEX_PUBKEY.as_bytes().to_vec(),
boost_config_pubkey: BOOST_HEX_CONFIG_PUBKEY.as_bytes().to_vec(),
version: 1,
device_type: BoostedHexDeviceTypeProto::All.into(),
};
assert_eq!(
"multipliers cannot contain values of 0",
Expand Down
23 changes: 22 additions & 1 deletion mobile_verifier/tests/integrations/hex_boosting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ use helium_proto::services::{
},
};
use hextree::Cell;
use mobile_config::boosted_hex_info::BoostedHexInfo;
use mobile_config::{
boosted_hex_info::{BoostedHexDeviceType, BoostedHexInfo, BoostedHexInfoStream},
client::{hex_boosting_client::HexBoostingInfoResolver, ClientError},
};
use mobile_verifier::{
cell_type::CellType,
coverage::CoverageObject,
Expand Down Expand Up @@ -106,6 +109,7 @@ async fn test_poc_with_boosted_hexes(pool: PgPool) -> anyhow::Result<()> {
boosted_hex_pubkey: Pubkey::from_str(BOOST_HEX_PUBKEY).unwrap(),
boost_config_pubkey: Pubkey::from_str(BOOST_CONFIG_PUBKEY).unwrap(),
version: 0,
device_type: BoostedHexDeviceType::All,
},
BoostedHexInfo {
// hotspot 2's location
Expand All @@ -117,6 +121,7 @@ async fn test_poc_with_boosted_hexes(pool: PgPool) -> anyhow::Result<()> {
boosted_hex_pubkey: Pubkey::from_str(BOOST_HEX_PUBKEY).unwrap(),
boost_config_pubkey: Pubkey::from_str(BOOST_CONFIG_PUBKEY).unwrap(),
version: 0,
device_type: BoostedHexDeviceType::All,
},
BoostedHexInfo {
// hotspot 3's location
Expand All @@ -128,6 +133,7 @@ async fn test_poc_with_boosted_hexes(pool: PgPool) -> anyhow::Result<()> {
boosted_hex_pubkey: Pubkey::from_str(BOOST_HEX_PUBKEY).unwrap(),
boost_config_pubkey: Pubkey::from_str(BOOST_CONFIG_PUBKEY).unwrap(),
version: 0,
device_type: BoostedHexDeviceType::All,
},
];

Expand Down Expand Up @@ -294,6 +300,7 @@ async fn test_poc_boosted_hexes_thresholds_not_met(pool: PgPool) -> anyhow::Resu
boosted_hex_pubkey: Pubkey::from_str(BOOST_HEX_PUBKEY).unwrap(),
boost_config_pubkey: Pubkey::from_str(BOOST_CONFIG_PUBKEY).unwrap(),
version: 0,
device_type: BoostedHexDeviceType::All,
},
BoostedHexInfo {
// hotspot 2's location
Expand All @@ -305,6 +312,7 @@ async fn test_poc_boosted_hexes_thresholds_not_met(pool: PgPool) -> anyhow::Resu
boosted_hex_pubkey: Pubkey::from_str(BOOST_HEX_PUBKEY).unwrap(),
boost_config_pubkey: Pubkey::from_str(BOOST_CONFIG_PUBKEY).unwrap(),
version: 0,
device_type: BoostedHexDeviceType::All,
},
BoostedHexInfo {
// hotspot 3's location
Expand All @@ -316,6 +324,7 @@ async fn test_poc_boosted_hexes_thresholds_not_met(pool: PgPool) -> anyhow::Resu
boosted_hex_pubkey: Pubkey::from_str(BOOST_HEX_PUBKEY).unwrap(),
boost_config_pubkey: Pubkey::from_str(BOOST_CONFIG_PUBKEY).unwrap(),
version: 0,
device_type: BoostedHexDeviceType::All,
},
];

Expand Down Expand Up @@ -442,6 +451,7 @@ async fn test_poc_with_multi_coverage_boosted_hexes(pool: PgPool) -> anyhow::Res
boosted_hex_pubkey: Pubkey::from_str(BOOST_HEX_PUBKEY).unwrap(),
boost_config_pubkey: Pubkey::from_str(BOOST_CONFIG_PUBKEY).unwrap(),
version: 0,
device_type: BoostedHexDeviceType::All,
},
BoostedHexInfo {
// hotspot 1's second covered location
Expand All @@ -453,6 +463,7 @@ async fn test_poc_with_multi_coverage_boosted_hexes(pool: PgPool) -> anyhow::Res
boosted_hex_pubkey: Pubkey::from_str(BOOST_HEX_PUBKEY).unwrap(),
boost_config_pubkey: Pubkey::from_str(BOOST_CONFIG_PUBKEY).unwrap(),
version: 0,
device_type: BoostedHexDeviceType::All,
},
BoostedHexInfo {
// hotspot 2's location
Expand All @@ -464,6 +475,7 @@ async fn test_poc_with_multi_coverage_boosted_hexes(pool: PgPool) -> anyhow::Res
boosted_hex_pubkey: Pubkey::from_str(BOOST_HEX_PUBKEY).unwrap(),
boost_config_pubkey: Pubkey::from_str(BOOST_CONFIG_PUBKEY).unwrap(),
version: 0,
device_type: BoostedHexDeviceType::All,
},
BoostedHexInfo {
// hotspot 3's location
Expand All @@ -475,6 +487,7 @@ async fn test_poc_with_multi_coverage_boosted_hexes(pool: PgPool) -> anyhow::Res
boosted_hex_pubkey: Pubkey::from_str(BOOST_HEX_PUBKEY).unwrap(),
boost_config_pubkey: Pubkey::from_str(BOOST_CONFIG_PUBKEY).unwrap(),
version: 0,
device_type: BoostedHexDeviceType::All,
},
];

Expand Down Expand Up @@ -643,6 +656,7 @@ async fn test_expired_boosted_hex(pool: PgPool) -> anyhow::Result<()> {
boosted_hex_pubkey: Pubkey::from_str(BOOST_HEX_PUBKEY).unwrap(),
boost_config_pubkey: Pubkey::from_str(BOOST_CONFIG_PUBKEY).unwrap(),
version: 0,
device_type: BoostedHexDeviceType::All,
},
BoostedHexInfo {
location: Cell::from_raw(0x8a1fb49642dffff_u64)?,
Expand All @@ -653,6 +667,7 @@ async fn test_expired_boosted_hex(pool: PgPool) -> anyhow::Result<()> {
boosted_hex_pubkey: Pubkey::from_str(BOOST_HEX_PUBKEY).unwrap(),
boost_config_pubkey: Pubkey::from_str(BOOST_CONFIG_PUBKEY).unwrap(),
version: 0,
device_type: BoostedHexDeviceType::All,
},
];

Expand Down Expand Up @@ -771,6 +786,7 @@ async fn test_reduced_location_score_with_boosted_hexes(pool: PgPool) -> anyhow:
boosted_hex_pubkey: Pubkey::from_str(BOOST_HEX_PUBKEY).unwrap(),
boost_config_pubkey: Pubkey::from_str(BOOST_CONFIG_PUBKEY).unwrap(),
version: 0,
device_type: BoostedHexDeviceType::All,
},
BoostedHexInfo {
// hotspot 3's location
Expand All @@ -782,6 +798,7 @@ async fn test_reduced_location_score_with_boosted_hexes(pool: PgPool) -> anyhow:
boosted_hex_pubkey: Pubkey::from_str(BOOST_HEX_PUBKEY).unwrap(),
boost_config_pubkey: Pubkey::from_str(BOOST_CONFIG_PUBKEY).unwrap(),
version: 0,
device_type: BoostedHexDeviceType::All,
},
];

Expand Down Expand Up @@ -1134,6 +1151,7 @@ async fn test_poc_with_cbrs_and_multi_coverage_boosted_hexes(pool: PgPool) -> an
boosted_hex_pubkey: Pubkey::from_str(BOOST_HEX_PUBKEY).unwrap(),
boost_config_pubkey: Pubkey::from_str(BOOST_CONFIG_PUBKEY).unwrap(),
version: 0,
device_type: BoostedHexDeviceType::All,
},
BoostedHexInfo {
// hotspot 1's second covered location
Expand All @@ -1145,6 +1163,7 @@ async fn test_poc_with_cbrs_and_multi_coverage_boosted_hexes(pool: PgPool) -> an
boosted_hex_pubkey: Pubkey::from_str(BOOST_HEX_PUBKEY).unwrap(),
boost_config_pubkey: Pubkey::from_str(BOOST_CONFIG_PUBKEY).unwrap(),
version: 0,
device_type: BoostedHexDeviceType::All,
},
BoostedHexInfo {
// hotspot 2's location
Expand All @@ -1156,6 +1175,7 @@ async fn test_poc_with_cbrs_and_multi_coverage_boosted_hexes(pool: PgPool) -> an
boosted_hex_pubkey: Pubkey::from_str(BOOST_HEX_PUBKEY).unwrap(),
boost_config_pubkey: Pubkey::from_str(BOOST_CONFIG_PUBKEY).unwrap(),
version: 0,
device_type: BoostedHexDeviceType::All,
},
BoostedHexInfo {
// hotspot 3's location
Expand All @@ -1167,6 +1187,7 @@ async fn test_poc_with_cbrs_and_multi_coverage_boosted_hexes(pool: PgPool) -> an
boosted_hex_pubkey: Pubkey::from_str(BOOST_HEX_PUBKEY).unwrap(),
boost_config_pubkey: Pubkey::from_str(BOOST_CONFIG_PUBKEY).unwrap(),
version: 0,
device_type: BoostedHexDeviceType::All,
},
];

Expand Down
5 changes: 4 additions & 1 deletion mobile_verifier/tests/integrations/modeled_coverage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use helium_proto::services::{
poc_mobile::{CoverageObjectValidity, LocationSource, SignalLevel},
};
use hextree::Cell;
use mobile_config::boosted_hex_info::{BoostedHexInfo, BoostedHexes};
use mobile_config::boosted_hex_info::{BoostedHexDeviceType, BoostedHexInfo, BoostedHexes};

use mobile_verifier::{
coverage::{CoverageClaimTimeCache, CoverageObject, CoverageObjectCache},
Expand Down Expand Up @@ -850,6 +850,7 @@ async fn scenario_three(pool: PgPool) -> anyhow::Result<()> {
boosted_hex_pubkey: Pubkey::from_str(BOOST_HEX_PUBKEY).unwrap(),
boost_config_pubkey: Pubkey::from_str(BOOST_CONFIG_PUBKEY).unwrap(),
version: 0,
device_type: BoostedHexDeviceType::All,
});
boosted_hexes.insert(BoostedHexInfo {
location: Cell::from_raw(0x8a1fb49642dffff)?,
Expand All @@ -860,6 +861,7 @@ async fn scenario_three(pool: PgPool) -> anyhow::Result<()> {
boosted_hex_pubkey: Pubkey::from_str(BOOST_HEX_PUBKEY).unwrap(),
boost_config_pubkey: Pubkey::from_str(BOOST_CONFIG_PUBKEY).unwrap(),
version: 0,
device_type: BoostedHexDeviceType::All,
});
boosted_hexes.insert(BoostedHexInfo {
// hotspot 1's location
Expand All @@ -871,6 +873,7 @@ async fn scenario_three(pool: PgPool) -> anyhow::Result<()> {
boosted_hex_pubkey: Pubkey::from_str(BOOST_HEX_PUBKEY).unwrap(),
boost_config_pubkey: Pubkey::from_str(BOOST_CONFIG_PUBKEY).unwrap(),
version: 0,
device_type: BoostedHexDeviceType::All,
});

let reward_period = start..end;
Expand Down

0 comments on commit ed652e2

Please sign in to comment.