diff --git a/src/consts.rs b/src/consts.rs index 3aa7b38..bddd95a 100644 --- a/src/consts.rs +++ b/src/consts.rs @@ -20,6 +20,9 @@ pub const ONE_ORE: u64 = 10u64.pow(TOKEN_DECIMALS as u32); /// The duration of one minute, in seconds. pub const ONE_MINUTE: i64 = 60; +/// The duration of an Ore epoch, in seconds. +pub const EPOCH_DURATION: i64 = ONE_MINUTE.saturating_mul(3); + /// The duration of two years, in minutes. pub const TWO_YEARS: u64 = 60 * 24 * 365 * 2; diff --git a/src/processor/mine.rs b/src/processor/mine.rs index 6a75d42..a55132e 100644 --- a/src/processor/mine.rs +++ b/src/processor/mine.rs @@ -21,7 +21,7 @@ use crate::{ loaders::*, state::{Bus, Config, Proof}, utils::AccountDeserialize, - MIN_DIFFICULTY, ONE_MINUTE, TWO_YEARS, + EPOCH_DURATION, MIN_DIFFICULTY, ONE_MINUTE, TWO_YEARS, }; /// Mine is the primary workhorse instruction of the Ore program. Its responsibilities include: @@ -70,6 +70,7 @@ pub fn process_mine<'a, 'info>( return Err(OreError::IsPaused.into()); } + // TODO Is this really needed? // Validate the clock state let clock = Clock::get().or(Err(ProgramError::InvalidAccountData))?; let mut proof_data = proof_info.data.borrow_mut(); @@ -79,9 +80,10 @@ pub fn process_mine<'a, 'info>( } // Validate epoch is active - if clock - .unix_timestamp - .ge(&config.last_reset_at.saturating_add(ONE_MINUTE)) + if config + .last_reset_at + .saturating_add(EPOCH_DURATION) + .le(&clock.unix_timestamp) { return Err(OreError::NeedsReset.into()); } diff --git a/src/processor/reset.rs b/src/processor/reset.rs index a2fe824..ed385fb 100644 --- a/src/processor/reset.rs +++ b/src/processor/reset.rs @@ -12,7 +12,7 @@ use crate::{ }, state::{Bus, Config}, utils::AccountDeserialize, - BUS_COUNT, BUS_EPOCH_REWARDS, MAX_EPOCH_REWARDS, MAX_SUPPLY, MINT_ADDRESS, ONE_MINUTE, + BUS_COUNT, BUS_EPOCH_REWARDS, EPOCH_DURATION, MAX_EPOCH_REWARDS, MAX_SUPPLY, MINT_ADDRESS, SMOOTHING_FACTOR, TARGET_EPOCH_REWARDS, TREASURY, TREASURY_BUMP, }; @@ -79,8 +79,11 @@ pub fn process_reset<'a, 'info>( // Validate enough time has passed since last reset let clock = Clock::get().or(Err(ProgramError::InvalidAccountData))?; - let threshold = config.last_reset_at.saturating_add(ONE_MINUTE); - if clock.unix_timestamp.lt(&threshold) { + if config + .last_reset_at + .saturating_add(EPOCH_DURATION) + .gt(&clock.unix_timestamp) + { return Ok(()); }