mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-14 07:26:51 +00:00
tolerance to config
This commit is contained in:
@@ -8,6 +8,9 @@ pub const INITIAL_BASE_REWARD_RATE: u64 = 10u64.pow(3u32);
|
||||
/// The minimum difficulty to initialize the program with.
|
||||
pub const INITIAL_MIN_DIFFICULTY: u32 = 12;
|
||||
|
||||
/// The spam/liveness tolerance to initialize the program with.
|
||||
pub const INITIAL_TOLERANCE: i64 = 5;
|
||||
|
||||
/// The decimal precision of the ORE token.
|
||||
pub const TOKEN_DECIMALS: u8 = 11;
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ use solana_program::{
|
||||
};
|
||||
|
||||
// TODO Admin fn for min difficulty?
|
||||
// TODO Admin fn for spam/liveness tolerances?
|
||||
// TODO Is downgrade necessary?
|
||||
|
||||
declare_id!("mineRHF5r6S7HyD9SppBfVMXMavDkJsxwGesEvxZr2A");
|
||||
|
||||
@@ -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,
|
||||
));
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ pub struct Bus {
|
||||
/// The ID of the bus account.
|
||||
pub id: u64,
|
||||
|
||||
// TODO Update logic to count up rather than down
|
||||
/// The quantity of rewards this bus can issue in the current epoch epoch.
|
||||
pub rewards: u64,
|
||||
|
||||
|
||||
@@ -27,6 +27,12 @@ pub struct Config {
|
||||
|
||||
/// Is mining paused.
|
||||
pub paused: u32,
|
||||
|
||||
/// Seconds prior to a miner's target time during which their hashes will not be penalized.
|
||||
pub tolerance_spam: i64,
|
||||
|
||||
/// Seconds after a miner's target time during which their hashes will not be penalized.
|
||||
pub tolerance_liveness: i64,
|
||||
}
|
||||
|
||||
impl Discriminator for Config {
|
||||
|
||||
Reference in New Issue
Block a user