long epochs

This commit is contained in:
Hardhat Chad
2024-05-04 13:59:14 +00:00
parent 06779be532
commit 28e24322dd
3 changed files with 15 additions and 7 deletions

View File

@@ -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;

View File

@@ -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());
}

View File

@@ -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(());
}