Skip to content

Commit

Permalink
resolve subdao address via helium lib
Browse files Browse the repository at this point in the history
  • Loading branch information
andymck committed Dec 18, 2024
1 parent c3f7591 commit dbb6576
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 13 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions mobile_config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ file-store = { path = "../file_store" }
futures = { workspace = true }
futures-util = { workspace = true }
helium-crypto = { workspace = true, features = ["sqlx-postgres"] }
helium-lib = { workspace = true }
helium-proto = { workspace = true }
humantime = { workspace = true }
humantime-serde = { workspace = true }
Expand Down
7 changes: 4 additions & 3 deletions mobile_config/src/client/sub_dao_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use super::{call_with_retry, ClientError, Settings};
use crate::sub_dao_epoch_reward_info::EpochRewardInfo;
use file_store::traits::MsgVerify;
use helium_crypto::{Keypair, PublicKey, Sign};
use helium_lib::keypair::Pubkey;
use helium_proto::{
services::{
sub_dao::{self, SubDaoEpochRewardInfoReqV1},
Expand Down Expand Up @@ -34,7 +35,7 @@ pub trait SubDaoEpochRewardInfoResolver: Clone + Send + Sync + 'static {

async fn resolve_info(
&self,
sub_dao: &str,
sub_dao: &Pubkey,
epoch: u64,
) -> Result<Option<EpochRewardInfo>, Self::Error>;
}
Expand All @@ -45,11 +46,11 @@ impl SubDaoEpochRewardInfoResolver for SubDaoClient {

async fn resolve_info(
&self,
sub_dao: &str,
sub_dao: &Pubkey,
epoch: u64,
) -> Result<Option<EpochRewardInfo>, Self::Error> {
let mut request = SubDaoEpochRewardInfoReqV1 {
sub_dao_address: sub_dao.into(),
sub_dao_address: sub_dao.to_string(),
epoch,
signer: self.signing_key.public_key().into(),
signature: vec![],
Expand Down
7 changes: 5 additions & 2 deletions mobile_verifier/src/cli/reward_from_db.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use crate::{
heartbeats::HeartbeatReward,
resolve_subdao_pubkey,
reward_shares::{
get_scheduled_tokens_for_poc, CoverageShares, DataTransferAndPocAllocatedRewardBuckets,
},
rewarder::boosted_hex_eligibility::BoostedHexEligibility,
sp_boosted_rewards_bans::BannedRadios,
speedtests_average::SpeedtestAverages,
unique_connections, Settings, MOBILE_SUB_DAO_ONCHAIN_ADDRESS,
unique_connections, Settings,
};
use anyhow::Result;
use helium_crypto::PublicKey;
Expand All @@ -32,8 +33,10 @@ impl Cmd {
let reward_epoch = self.reward_epoch;

let sub_dao_rewards_client = SubDaoClient::from_settings(&settings.config_client)?;
let sub_dao = resolve_subdao_pubkey();

let reward_info = sub_dao_rewards_client
.resolve_info(MOBILE_SUB_DAO_ONCHAIN_ADDRESS, reward_epoch)
.resolve_info(&sub_dao, reward_epoch)
.await?
.ok_or(anyhow::anyhow!(
"No reward info found for epoch {}",
Expand Down
7 changes: 5 additions & 2 deletions mobile_verifier/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ pub mod unique_connections;
pub use settings::Settings;

use async_trait::async_trait;
use helium_lib::keypair::Pubkey;
use rust_decimal::Decimal;
use std::error::Error;

pub const MOBILE_SUB_DAO_ONCHAIN_ADDRESS: &str = "39Lw1RH6zt8AJvKn3BTxmUDofzduCM2J3kSaGDZ8L7Sk";

pub enum GatewayResolution {
GatewayNotFound,
GatewayNotAsserted,
Expand Down Expand Up @@ -122,3 +121,7 @@ impl PriceInfo {
}
}
}

pub fn resolve_subdao_pubkey() -> Pubkey {
helium_lib::dao::SubDao::Mobile.key()
}
15 changes: 10 additions & 5 deletions mobile_verifier/src/rewarder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
boosting_oracles::db::check_for_unprocessed_data_sets,
coverage, data_session,
heartbeats::{self, HeartbeatReward},
radio_threshold,
radio_threshold, resolve_subdao_pubkey,
reward_shares::{
self, CalculatedPocRewardShares, CoverageShares, DataTransferAndPocAllocatedRewardBuckets,
MapperShares, TransferRewards,
Expand All @@ -11,7 +11,7 @@ use crate::{
sp_boosted_rewards_bans, speedtests,
speedtests_average::SpeedtestAverages,
subscriber_location, subscriber_verified_mapping_event, telemetry, unique_connections,
PriceInfo, Settings, MOBILE_SUB_DAO_ONCHAIN_ADDRESS,
PriceInfo, Settings,
};
use anyhow::bail;
use chrono::{DateTime, TimeZone, Utc};
Expand All @@ -24,6 +24,7 @@ use file_store::{
use futures_util::TryFutureExt;

use self::boosted_hex_eligibility::BoostedHexEligibility;
use helium_lib::keypair::Pubkey;
use helium_lib::token::Token;
use helium_proto::{
reward_manifest::RewardData::MobileRewardData,
Expand Down Expand Up @@ -58,7 +59,7 @@ mod db;
const REWARDS_NOT_CURRENT_DELAY_PERIOD: i64 = 5;

pub struct Rewarder<A, B, C> {
sub_dao_address: String,
sub_dao: Pubkey,
pool: Pool<Postgres>,
carrier_client: A,
hex_service_client: B,
Expand Down Expand Up @@ -140,8 +141,12 @@ where
price_tracker: PriceTracker,
speedtest_averages: FileSinkClient<proto::SpeedtestAvg>,
) -> anyhow::Result<Self> {
// get the subdao address
let sub_dao = resolve_subdao_pubkey();
tracing::info!("Mobile SubDao pubkey: {}", sub_dao);

Ok(Self {
sub_dao_address: MOBILE_SUB_DAO_ONCHAIN_ADDRESS.into(),
sub_dao,
pool,
carrier_client,
hex_service_client,
Expand Down Expand Up @@ -246,7 +251,7 @@ where
pub async fn reward(&self, next_reward_epoch: u64) -> anyhow::Result<()> {
let reward_info = self
.sub_dao_epoch_reward_client
.resolve_info(&self.sub_dao_address, next_reward_epoch)
.resolve_info(&self.sub_dao, next_reward_epoch)
.await?
.ok_or(anyhow::anyhow!(
"No reward info found for epoch {}",
Expand Down
3 changes: 2 additions & 1 deletion mobile_verifier/tests/integrations/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use file_store::{
};
use futures::{stream, StreamExt};
use helium_crypto::PublicKeyBinary;
use helium_lib::keypair::Pubkey;
use helium_lib::token::Token;
use helium_proto::services::{
mobile_config::NetworkKeyRole,
Expand Down Expand Up @@ -79,7 +80,7 @@ impl SubDaoEpochRewardInfoResolver for MockSubDaoRewardsClient {

async fn resolve_info(
&self,
_sub_dao: &str,
_sub_dao: &Pubkey,
_epoch: u64,
) -> Result<Option<EpochRewardInfo>, Self::Error> {
Ok(self.info.clone())
Expand Down

0 comments on commit dbb6576

Please sign in to comment.