bug fixes

This commit is contained in:
Hardhat Chad
2024-07-12 16:54:31 +00:00
parent 1d50cafc8c
commit f4b2fb8f42
4 changed files with 7 additions and 10 deletions

View File

@@ -10,7 +10,7 @@ use super::AccountDiscriminator;
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, ShankAccount, Zeroable)]
pub struct Config {
/// The admin authority with permission to update the difficulty.
// TODO Remove this
pub admin: Pubkey,
/// The base reward rate paid out for a hash of minimum difficulty.

View File

@@ -40,11 +40,11 @@ pub fn process_crown<'a, 'info>(
// If top staker is the default null address, skip this.
let mut config_data = config_info.data.borrow_mut();
let config = Config::try_from_bytes_mut(&mut config_data)?;
let proof_data = proof_info.data.borrow();
let proof = Proof::try_from_bytes(&proof_data)?;
if config.top_staker.ne(&Pubkey::new_from_array([0; 32])) {
// Load current top staker
load_any_proof(proof_info, false)?;
let proof_data = proof_info.data.borrow();
let proof = Proof::try_from_bytes(&proof_data)?;
if proof_info.key.ne(&config.top_staker) {
return Ok(());
}

View File

@@ -138,7 +138,6 @@ pub fn process_initialize<'a, 'info>(
let mut config_data = config_info.data.borrow_mut();
config_data[0] = Config::discriminator() as u8;
let config = Config::try_from_bytes_mut(&mut config_data)?;
config.admin = *signer.key;
config.base_reward_rate = INITIAL_BASE_REWARD_RATE;
config.last_reset_at = 0;
config.max_stake = 0;

View File

@@ -104,13 +104,11 @@ pub fn process_mine<'a, 'info>(
// if the miner's last stake deposit was more than one minute ago.
let t = clock.unix_timestamp;
if config.max_stake.gt(&0) && proof.last_stake_at.saturating_add(ONE_MINUTE).le(&t) {
let staking_reward = proof
.balance
.min(config.max_stake)
.checked_mul(reward)
let staking_reward = (reward as u128)
.checked_mul(proof.balance.min(config.max_stake) as u128)
.unwrap()
.checked_div(config.max_stake)
.unwrap();
.checked_div(config.max_stake as u128)
.unwrap() as u64;
reward = reward.checked_add(staking_reward).unwrap();
}