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

HIP 109 boost by device type #798

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
52 changes: 32 additions & 20 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ helium-lib = { git = "https://github.com/helium/helium-wallet-rs.git", branch =
hextree = { git = "https://github.com/jaykickliter/HexTree", branch = "main", features = [
"disktree",
] }
helium-proto = { git = "https://github.com/helium/proto", branch = "master", features = [
helium-proto = { git = "https://github.com/helium/proto", branch = "mj/hip-109-boost-by-device-type", features = [
"services",
] }
beacon = { git = "https://github.com/helium/proto", branch = "master" }
beacon = { git = "https://github.com/helium/proto", branch = "mj/hip-109-boost-by-device-type" }
solana-client = "1.18"
solana-sdk = "1.18"
solana-program = "1.18"
Expand Down Expand Up @@ -126,10 +126,10 @@ sqlx = { git = "https://github.com/helium/sqlx.git", rev = "92a2268f02e0cac6fccb

# When attempting to test proto changes without needing to push a branch you can
# patch the github url to point to your local proto repo.
#
#
# Patching for beacon must point directly to the crate, it will not look in the
# repo for sibling crates.
#
#
# [patch.'https://github.com/helium/proto']
# helium-proto = { path = "../proto" }
# beacon = { path = "../proto/beacon" }
33 changes: 17 additions & 16 deletions boost_manager/src/activator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ where
txn: &mut Transaction<'_, Postgres>,
manifest: RewardManifest,
) -> Result<()> {
// get latest boosted hexes info from mobile config
let boosted_hexes = BoostedHexes::get_all(&self.hex_boosting_client).await?;
let boosted_hexes = BoostedHexes::get_active(&self.hex_boosting_client).await?;

// get the rewards file from the manifest
let manifest_time = manifest.end_timestamp;
Expand All @@ -114,9 +113,9 @@ where
while let Some(msg) = reward_shares.try_next().await? {
let share = MobileRewardShare::decode(msg)?;
if let Some(MobileReward::RadioReward(r)) = share.reward {
for hex in r.boosted_hexes.into_iter() {
process_boosted_hex(txn, manifest_time, &boosted_hexes, &hex.try_into()?)
.await?
for hex_proto in r.boosted_hexes.into_iter() {
let boosted_hex = hex_proto.try_into()?;
process_boosted_hex(txn, manifest_time, &boosted_hexes, &boosted_hex).await?
}
}
}
Expand All @@ -130,17 +129,19 @@ pub async fn process_boosted_hex(
boosted_hexes: &BoostedHexes,
hex: &BoostedHex,
) -> Result<()> {
match boosted_hexes.hexes.get(&hex.location) {
Some(info) => {
if info.start_ts.is_none() {
db::insert_activated_hex(
txn,
hex.location.into_raw(),
&info.boosted_hex_pubkey.to_string(),
&info.boost_config_pubkey.to_string(),
manifest_time,
)
.await?;
match boosted_hexes.get(&hex.location) {
Some(hexes) => {
for info in hexes {
if info.start_ts.is_none() {
db::insert_activated_hex(
txn,
hex.location.into_raw(),
&info.boosted_hex_pubkey.to_string(),
&info.boost_config_pubkey.to_string(),
manifest_time,
)
.await?;
}
}
}
None => {
Expand Down
4 changes: 2 additions & 2 deletions boost_manager/src/watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ where
tracing::info!(
"modified hexes count since {}: {} ",
last_processed_ts,
boosted_hexes.hexes.len()
boosted_hexes.count()
);
for info in boosted_hexes.hexes.values() {
for info in boosted_hexes.iter_hexes() {
let proto: BoostedHexUpdateProto = BoostedHexUpdateProto {
timestamp: now.encode_timestamp(),
update: Some(info.clone().try_into()?),
Expand Down
36 changes: 10 additions & 26 deletions boost_manager/tests/integrations/activator_tests.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
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::{collections::HashMap, num::NonZeroU32, str::FromStr};
use std::{num::NonZeroU32, str::FromStr};

const BOOST_HEX_PUBKEY: &str = "J9JiLTpjaShxL8eMvUs8txVw6TZ36E38SiJ89NxnMbLU";
const BOOST_CONFIG_PUBKEY: &str = "BZM1QTud72B2cpTW7PhEnFmRX7ZWzvY7DpPpNJJuDrWG";
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 All @@ -82,14 +87,7 @@ impl TestContext {
async fn test_activated_hex_insert(pool: PgPool) -> anyhow::Result<()> {
let now = Utc::now();
let ctx = TestContext::setup(now)?;
let boosted_hexes_map = ctx
.boosted_hexes
.iter()
.map(|info| (info.location, info.clone()))
.collect::<HashMap<_, _>>();
let boosted_hexes = BoostedHexes {
hexes: boosted_hexes_map,
};
let boosted_hexes = BoostedHexes::test_new_active(ctx.boosted_hexes)?;

// test a boosted hex derived from radio rewards
// with a non set start date, will result in a row being
Expand Down Expand Up @@ -119,14 +117,7 @@ async fn test_activated_hex_insert(pool: PgPool) -> anyhow::Result<()> {
async fn test_activated_hex_no_insert(pool: PgPool) -> anyhow::Result<()> {
let now = Utc::now();
let ctx = TestContext::setup(now)?;
let boosted_hexes_map = ctx
.boosted_hexes
.iter()
.map(|info| (info.location, info.clone()))
.collect::<HashMap<_, _>>();
let boosted_hexes = BoostedHexes {
hexes: boosted_hexes_map,
};
let boosted_hexes = BoostedHexes::test_new_active(ctx.boosted_hexes)?;

// test a boosted hex derived from radio rewards
// with an active start date, will result in no row being
Expand All @@ -152,14 +143,7 @@ async fn test_activated_hex_no_insert(pool: PgPool) -> anyhow::Result<()> {
async fn test_activated_dup_hex_insert(pool: PgPool) -> anyhow::Result<()> {
let now = Utc::now().with_second(0).unwrap();
let ctx = TestContext::setup(now)?;
let boosted_hexes_map = ctx
.boosted_hexes
.iter()
.map(|info| (info.location, info.clone()))
.collect::<HashMap<_, _>>();
let boosted_hexes = BoostedHexes {
hexes: boosted_hexes_map,
};
let boosted_hexes = BoostedHexes::test_new_active(ctx.boosted_hexes)?;

// test with DUPLICATE boosted hexes derived from radio rewards
// with a non set start date, will result in a single row being
Expand Down
4 changes: 3 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,7 @@ 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};
use solana_sdk::pubkey::Pubkey;
use sqlx::PgPool;
use std::{num::NonZeroU32, str::FromStr};
Expand Down Expand Up @@ -45,6 +45,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 +56,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
Loading