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

hip138 - mobile verifier #898

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
62 changes: 40 additions & 22 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 = "andymck/sub-dao-epoch-support", features = [
"services",
] }
beacon = { git = "https://github.com/helium/proto", branch = "master" }
beacon = { git = "https://github.com/helium/proto", branch = "andymck/sub-dao-epoch-support" }
solana-client = "1.18"
solana-sdk = "1.18"
solana-program = "1.18"
Expand Down Expand Up @@ -133,5 +133,5 @@ sqlx = { git = "https://github.com/launchbadge/sqlx.git", rev = "42dd78fe931df65
# repo for sibling crates.
#
# [patch.'https://github.com/helium/proto']
# helium-proto = { path = "../proto" }
# beacon = { path = "../proto/beacon" }
# helium-proto = { path = "../../proto" }
# beacon = { path = "../../proto" }
2 changes: 2 additions & 0 deletions file_store/src/cli/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
pub mod bucket;
pub mod dump;
pub mod dump_mobile_rewards;
pub mod import_iot_rewards;
pub mod import_mobile_rewards;
pub mod info;

use crate::Result;
Expand Down
2 changes: 2 additions & 0 deletions file_store/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ pub enum Error {
//Not recommended for internal use!
#[error("external error")]
ExternalError(#[from] Box<dyn std::error::Error + Send + Sync>),
#[error("general error")]
Anyhow(#[from] anyhow::Error),
}

#[derive(Error, Debug)]
Expand Down
5 changes: 5 additions & 0 deletions file_store/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use clap::Parser;
use file_store::cli::{import_iot_rewards, import_mobile_rewards};
use file_store::{
cli::{bucket, dump, dump_mobile_rewards, info},
Result, Settings,
Expand Down Expand Up @@ -30,6 +31,8 @@ pub enum Cmd {
Dump(dump::Cmd),
Bucket(Box<bucket::Cmd>),
DumpMobileRewards(dump_mobile_rewards::Cmd),
ImportMobileRewards(import_mobile_rewards::Cmd),
ImportIotRewards(import_iot_rewards::Cmd),
}

impl Cmd {
Expand All @@ -39,6 +42,8 @@ impl Cmd {
Cmd::Dump(cmd) => cmd.run(&settings).await,
Cmd::Bucket(cmd) => cmd.run(&settings).await,
Cmd::DumpMobileRewards(cmd) => cmd.run(&settings).await,
Cmd::ImportMobileRewards(cmd) => cmd.run(&settings).await,
Cmd::ImportIotRewards(cmd) => cmd.run(&settings).await,
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions file_store/src/traits/msg_verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use helium_proto::services::{
iot_config, mobile_config,
poc_lora::{LoraBeaconReportReqV1, LoraStreamSessionInitV1, LoraWitnessReportReqV1},
poc_mobile::{self, ServiceProviderBoostedRewardsBannedRadioReqV1},
sub_dao,
};
use helium_proto::{
services::poc_mobile::{
Expand Down Expand Up @@ -96,6 +97,8 @@ 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!(sub_dao::SubDaoEpochRewardInfoReqV1, signature);
impl_msg_verify!(sub_dao::SubDaoEpochRewardInfoResV1, signature);
impl_msg_verify!(poc_mobile::SubscriberVerifiedMappingEventReqV1, signature);

#[cfg(test)]
Expand Down
1 change: 1 addition & 0 deletions iot_verifier/src/reward_share.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ impl GatewayShares {
start_period: reward_period.start.encode_timestamp(),
end_period: reward_period.end.encode_timestamp(),
reward: Some(ProtoReward::GatewayReward(gateway_reward)),
epoch: 0, // placeholder, todo: remove
},
)
})
Expand Down
24 changes: 14 additions & 10 deletions iot_verifier/src/rewarder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,16 @@ impl Rewarder {
self.reward_offset,
);

let sleep_duration = if scheduler.should_reward(now) {
let sleep_duration = if scheduler.should_trigger(now) {
let iot_price = self
.price_tracker
.price(&helium_proto::BlockchainTokenTypeV1::Iot)
.await?;
tracing::info!(
"Rewarding for period: {:?} with iot_price: {iot_price}",
scheduler.reward_period
scheduler.schedule_period
);
if self.data_current_check(&scheduler.reward_period).await? {
if self.data_current_check(&scheduler.schedule_period).await? {
self.reward(&scheduler, Decimal::from(iot_price)).await?;
scheduler.sleep_duration(Utc::now())?
} else {
Expand Down Expand Up @@ -123,7 +123,7 @@ impl Rewarder {
scheduler: &Scheduler,
iot_price: Decimal,
) -> anyhow::Result<()> {
let reward_period = &scheduler.reward_period;
let reward_period = &scheduler.schedule_period;

// process rewards for poc and dc
let poc_dc_shares =
Expand All @@ -139,17 +139,17 @@ impl Rewarder {
// purge db
let mut transaction = self.pool.begin().await?;
// Clear gateway shares table period to end of reward period
GatewayShares::clear_rewarded_shares(&mut transaction, scheduler.reward_period.start)
GatewayShares::clear_rewarded_shares(&mut transaction, scheduler.schedule_period.start)
.await?;
save_rewarded_timestamp(
"last_rewarded_end_time",
&scheduler.reward_period.end,
&scheduler.schedule_period.end,
&mut transaction,
)
.await?;
save_rewarded_timestamp(
"next_rewarded_end_time",
&scheduler.next_reward_period().end,
&scheduler.next_trigger_period().end,
&mut transaction,
)
.await?;
Expand All @@ -170,17 +170,19 @@ impl Rewarder {
self.reward_manifests_sink
.write(
RewardManifest {
start_timestamp: scheduler.reward_period.start.encode_timestamp(),
end_timestamp: scheduler.reward_period.end.encode_timestamp(),
start_timestamp: scheduler.schedule_period.start.encode_timestamp(),
end_timestamp: scheduler.schedule_period.end.encode_timestamp(),
written_files,
reward_data: Some(IotRewardData(reward_data)),
epoch: 0, // TODO: replace placeholder value
price: 0, // TODO: replace placeholder value
},
[],
)
.await?
.await??;
self.reward_manifests_sink.commit().await?;
telemetry::last_rewarded_end_time(scheduler.reward_period.end);
telemetry::last_rewarded_end_time(scheduler.schedule_period.end);
Ok(())
}

Expand Down Expand Up @@ -302,6 +304,7 @@ pub async fn reward_operational(
start_period: reward_period.start.encode_timestamp(),
end_period: reward_period.end.encode_timestamp(),
reward: Some(ProtoReward::OperationalReward(op_fund_reward)),
epoch: 0, // placeholder, todo: remove
},
[],
)
Expand Down Expand Up @@ -365,6 +368,7 @@ async fn write_unallocated_reward(
reward_type: unallocated_type as i32,
amount: unallocated_amount,
})),
epoch: 0, // placeholder, todo: remove
};
rewards_sink.write(unallocated_reward, []).await?.await??;
};
Expand Down
Loading