Skip to content

Commit

Permalink
testing related tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
andymck committed Jan 7, 2025
1 parent 9c04f2a commit 2c9c56e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
4 changes: 3 additions & 1 deletion iot_config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ pub struct EpochInfo {

impl From<u64> for EpochInfo {
fn from(next_reward_epoch: u64) -> Self {
let start_time = DateTime::<Utc>::UNIX_EPOCH + Duration::days(next_reward_epoch as i64);
let start_time = DateTime::<Utc>::UNIX_EPOCH
+ Duration::days(next_reward_epoch as i64)
+ Duration::hours(1);
let end_time = start_time + Duration::days(1);
EpochInfo {
period: start_time..end_time,
Expand Down
11 changes: 9 additions & 2 deletions iot_config/src/sub_dao_epoch_reward_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub(crate) mod db {
address AS epoch_address,
sub_dao AS sub_dao_address,
epoch::BIGINT,
hnt_rewards_issued::BIGINT,
delegation_rewards_issued::BIGINT as hnt_rewards_issued,
delegation_rewards_issued::BIGINT,
rewards_issued_at::BIGINT
FROM sub_dao_epoch_infos
Expand Down Expand Up @@ -105,11 +105,18 @@ pub(crate) mod db {
.to_timestamp()
.map_err(|err| sqlx::Error::Decode(Box::new(err)))?;

let hnt_rewards_issued = row.get::<i64, &str>("hnt_rewards_issued") as u64;
if hnt_rewards_issued == 0 {
return Err(sqlx::Error::Decode(Box::new(sqlx::Error::Decode(
Box::from("hnt_rewards_issued is 0"),
))));
};

Ok(Self {
epoch: row.try_get::<i64, &str>("epoch")? as u64,
epoch_address: row.try_get::<String, &str>("epoch_address")?,
sub_dao_address: row.try_get::<String, &str>("sub_dao_address")?,
hnt_rewards_issued: row.try_get::<i64, &str>("hnt_rewards_issued")? as u64,
hnt_rewards_issued,
delegation_rewards_issued: row.try_get::<i64, &str>("delegation_rewards_issued")?
as u64,
rewards_issued_at,
Expand Down
12 changes: 10 additions & 2 deletions iot_verifier/src/rewarder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,16 @@ where
let now = Utc::now();
let sleep_duration = if scheduler.should_trigger(now) {
if self.data_current_check(&scheduler.schedule_period).await? {
self.reward(next_reward_epoch).await?;
scheduler.sleep_duration(Utc::now())?
match self.reward(next_reward_epoch).await {
Ok(()) => {
tracing::info!("Successfully rewarded for epoch {}", next_reward_epoch);
scheduler.sleep_duration(Utc::now())?
}
Err(e) => {
tracing::error!("Failed to reward: {}", e);
REWARDS_NOT_CURRENT_DELAY_PERIOD
}
}
} else {
REWARDS_NOT_CURRENT_DELAY_PERIOD
}
Expand Down

0 comments on commit 2c9c56e

Please sign in to comment.