mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-14 15:10:13 +00:00
tolerance to config
This commit is contained in:
@@ -17,9 +17,9 @@ use crate::{
|
||||
utils::create_pda,
|
||||
utils::AccountDeserialize,
|
||||
utils::Discriminator,
|
||||
BUS, BUS_COUNT, CONFIG, INITIAL_BASE_REWARD_RATE, INITIAL_MIN_DIFFICULTY, METADATA,
|
||||
METADATA_NAME, METADATA_SYMBOL, METADATA_URI, MINT, MINT_ADDRESS, MINT_NOISE, TOKEN_DECIMALS,
|
||||
TREASURY,
|
||||
BUS, BUS_COUNT, CONFIG, INITIAL_BASE_REWARD_RATE, INITIAL_MIN_DIFFICULTY, INITIAL_TOLERANCE,
|
||||
METADATA, METADATA_NAME, METADATA_SYMBOL, METADATA_URI, MINT, MINT_ADDRESS, MINT_NOISE,
|
||||
TOKEN_DECIMALS, TREASURY,
|
||||
};
|
||||
|
||||
/// Initialize sets up the Ore program. Its responsibilities include:
|
||||
@@ -137,6 +137,8 @@ pub fn process_initialize<'a, 'info>(
|
||||
config.last_reset_at = 0;
|
||||
config.min_difficulty = INITIAL_MIN_DIFFICULTY;
|
||||
config.paused = 0;
|
||||
config.tolerance_liveness = INITIAL_TOLERANCE;
|
||||
config.tolerance_spam = INITIAL_TOLERANCE;
|
||||
|
||||
// Initialize treasury
|
||||
create_pda(
|
||||
|
||||
@@ -114,28 +114,26 @@ pub fn process_mine<'a, 'info>(
|
||||
}
|
||||
|
||||
// Apply spam/liveness penalty
|
||||
let tolerance_early = 5i64; // TODO Get from config
|
||||
let tolerance_late = 5i64; // TODO Get from config
|
||||
let t = clock.unix_timestamp;
|
||||
let t_target = proof.last_hash_at.saturating_add(EPOCH_DURATION);
|
||||
let t_early = t_target.saturating_sub(tolerance_early);
|
||||
let t_late = t_target.saturating_add(tolerance_late);
|
||||
if t.lt(&t_early) {
|
||||
let t_spam = t_target.saturating_sub(config.tolerance_spam);
|
||||
let t_liveness = t_target.saturating_add(config.tolerance_liveness);
|
||||
if t.lt(&t_spam) {
|
||||
reward = 0;
|
||||
sol_log("Spam penalty");
|
||||
} else if t.gt(&t_late) {
|
||||
} else if t.gt(&t_liveness) {
|
||||
reward = reward.saturating_sub(
|
||||
reward
|
||||
.saturating_mul(t.saturating_sub(t_late) as u64)
|
||||
.saturating_mul(t.saturating_sub(t_liveness) as u64)
|
||||
.saturating_div(
|
||||
t_target
|
||||
.saturating_add(EPOCH_DURATION)
|
||||
.saturating_sub(t_late) as u64,
|
||||
.saturating_sub(t_liveness) as u64,
|
||||
),
|
||||
);
|
||||
sol_log(&format!(
|
||||
"Liveness penalty ({} sec) {}",
|
||||
t.saturating_sub(t_late),
|
||||
t.saturating_sub(t_liveness),
|
||||
reward,
|
||||
));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user