From e9edb2eaeeaff33ca67cf685e7a3e17b0134400b Mon Sep 17 00:00:00 2001 From: Andrew McKenzie Date: Wed, 18 Dec 2024 11:38:55 +0000 Subject: [PATCH] resolve subdao address via helium lib --- Cargo.lock | 1 + iot_config/Cargo.toml | 1 + iot_config/src/client/sub_dao_client.rs | 7 ++++--- iot_verifier/src/lib.rs | 7 +++++-- iot_verifier/src/rewarder.rs | 13 +++++++++---- 5 files changed, 20 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9c8023203..4afbd1fbe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4377,6 +4377,7 @@ dependencies = [ "futures", "futures-util", "helium-crypto", + "helium-lib", "helium-proto 0.1.0 (git+https://github.com/helium/proto?branch=andymck%2Fsub-dao-epoch-support)", "hextree", "http 0.2.11", diff --git a/iot_config/Cargo.toml b/iot_config/Cargo.toml index 887d2e75b..a16da50c9 100644 --- a/iot_config/Cargo.toml +++ b/iot_config/Cargo.toml @@ -21,6 +21,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 } hextree = { workspace = true } http = { workspace = true } diff --git a/iot_config/src/client/sub_dao_client.rs b/iot_config/src/client/sub_dao_client.rs index 952224084..c079e8686 100644 --- a/iot_config/src/client/sub_dao_client.rs +++ b/iot_config/src/client/sub_dao_client.rs @@ -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}, @@ -39,7 +40,7 @@ pub trait SubDaoEpochRewardInfoResolver: Clone + Send + Sync + 'static { async fn resolve_info( &self, - sub_dao: &str, + sub_dao: &Pubkey, epoch: u64, ) -> Result, Self::Error>; } @@ -50,11 +51,11 @@ impl SubDaoEpochRewardInfoResolver for SubDaoClient { async fn resolve_info( &self, - sub_dao: &str, + sub_dao: &Pubkey, epoch: u64, ) -> Result, 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![], diff --git a/iot_verifier/src/lib.rs b/iot_verifier/src/lib.rs index 54e446584..48c44261c 100644 --- a/iot_verifier/src/lib.rs +++ b/iot_verifier/src/lib.rs @@ -21,11 +21,10 @@ pub mod telemetry; pub mod tx_scaler; pub mod witness_updater; +use helium_lib::keypair::Pubkey; use rust_decimal::Decimal; pub use settings::Settings; -pub const IOT_SUB_DAO_ONCHAIN_ADDRESS: &str = "Gm9xDCJawDEKDrrQW6haw94gABaYzQwCq4ZQU8h8bd22"; - #[derive(Clone, Debug)] pub struct PriceInfo { pub price_in_bones: u64, @@ -47,3 +46,7 @@ impl PriceInfo { } } } + +pub fn resolve_subdao_pubkey() -> Pubkey { + helium_lib::dao::SubDao::Iot.key() +} diff --git a/iot_verifier/src/rewarder.rs b/iot_verifier/src/rewarder.rs index c1d5ffe68..509ab31d0 100644 --- a/iot_verifier/src/rewarder.rs +++ b/iot_verifier/src/rewarder.rs @@ -1,11 +1,13 @@ use crate::{ + resolve_subdao_pubkey, reward_share::{self, GatewayShares}, - telemetry, PriceInfo, IOT_SUB_DAO_ONCHAIN_ADDRESS, + telemetry, PriceInfo, }; use chrono::{DateTime, TimeZone, Utc}; use db_store::meta; use file_store::{file_sink, traits::TimestampEncode}; use futures::future::LocalBoxFuture; +use helium_lib::keypair::Pubkey; use helium_lib::token::Token; use helium_proto::{ reward_manifest::RewardData::IotRewardData, @@ -33,7 +35,7 @@ use tokio::time::sleep; const REWARDS_NOT_CURRENT_DELAY_PERIOD: Duration = Duration::from_secs(5 * 60); pub struct Rewarder { - sub_dao_address: String, + sub_dao: Pubkey, pub pool: Pool, pub rewards_sink: file_sink::FileSinkClient, pub reward_manifests_sink: file_sink::FileSinkClient, @@ -74,8 +76,11 @@ where price_tracker: PriceTracker, sub_dao_epoch_reward_client: A, ) -> anyhow::Result { + // get the subdao address + let sub_dao = resolve_subdao_pubkey(); + tracing::info!("Iot SubDao pubkey: {}", sub_dao); Ok(Self { - sub_dao_address: IOT_SUB_DAO_ONCHAIN_ADDRESS.to_string(), + sub_dao, pool, rewards_sink, reward_manifests_sink, @@ -132,7 +137,7 @@ where pub async fn reward(&mut 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 {}",