From 6f1454a895eb5fcc68035a29c274fede7fc3592e Mon Sep 17 00:00:00 2001 From: Hardhat Chad Date: Fri, 3 May 2024 16:49:28 +0000 Subject: [PATCH] one minute stake requirement --- src/processor/mine.rs | 13 ++++++++----- src/processor/register.rs | 2 +- src/state/proof.rs | 6 +++--- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/processor/mine.rs b/src/processor/mine.rs index e994e8e..6a75d42 100644 --- a/src/processor/mine.rs +++ b/src/processor/mine.rs @@ -91,23 +91,27 @@ pub fn process_mine<'a, 'info>( // Validate hash satisfies the minimnum difficulty let difficulty = drillx::difficulty(hx); + sol_log(&format!("Diff {}", difficulty)); if difficulty.lt(&MIN_DIFFICULTY) { return Err(OreError::HashTooEasy.into()); } // Calculate base reward rate let difficulty = difficulty.saturating_sub(MIN_DIFFICULTY); - sol_log(&format!("Diff {}", difficulty)); let mut reward = config .base_reward_rate .saturating_mul(2u64.saturating_pow(difficulty)); sol_log(&format!("Base {}", reward)); // Apply staking multiplier. - // To prevent flash loan attacks, only apply if the last deposit was at least 1 block ago. // The multiplier can range 1x to 2x. To receive the maximum multiplier, the stake balance must be - // greater than or equal to two years worth of rewards at the selected difficulty. - if clock.slot.gt(&proof.last_deposit_slot) { + // greater than or equal to two years worth of rewards at the selected difficulty. Miners are only + // eligable for a multipler if their last stake deposit was more than one minute ago. + if proof + .last_stake_at + .saturating_add(ONE_MINUTE) + .le(&clock.unix_timestamp) + { let upper_bound = reward.saturating_mul(TWO_YEARS); let staking_reward = proof .balance @@ -165,7 +169,6 @@ pub fn process_mine<'a, 'info>( .0; // Update time trackers - proof.last_deposit_slot = clock.slot; proof.last_hash_at = clock.unix_timestamp; // Update lifetime stats diff --git a/src/processor/register.rs b/src/processor/register.rs index 550ee24..cfed8ed 100644 --- a/src/processor/register.rs +++ b/src/processor/register.rs @@ -64,8 +64,8 @@ pub fn process_register<'a, 'info>( &slot_hashes_info.data.borrow()[0..size_of::()], ]) .0; - proof.last_deposit_slot = 0; proof.last_hash_at = 0; + proof.last_stake_at = 0; proof.total_hashes = 0; proof.total_rewards = 0; diff --git a/src/state/proof.rs b/src/state/proof.rs index e2913d1..902fc14 100644 --- a/src/state/proof.rs +++ b/src/state/proof.rs @@ -21,12 +21,12 @@ pub struct Proof { /// The current mining challenge. pub challenge: [u8; 32], - /// The last slot ore was deposited into this account. - pub last_deposit_slot: u64, - /// The last time this account provided a hash. pub last_hash_at: i64, + /// The last time stake was deposited into this account. + pub last_stake_at: i64, + /// The total lifetime hashes provided by this miner. pub total_hashes: u64,