mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-14 07:26:51 +00:00
rebased
This commit is contained in:
@@ -13,7 +13,7 @@ use ore_boost_api::{
|
||||
loaders::{load_any_boost, load_stake},
|
||||
state::{Boost, Stake},
|
||||
};
|
||||
use ore_utils::*;
|
||||
use ore_utils::{load_signer, load_sysvar};
|
||||
#[allow(deprecated)]
|
||||
use solana_program::{
|
||||
account_info::AccountInfo,
|
||||
@@ -56,7 +56,10 @@ pub fn process_mine(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
|
||||
|
||||
// Validate epoch is active.
|
||||
let config_data = config_info.data.borrow();
|
||||
let config = Config::try_from_bytes(&config_data)?;
|
||||
let config = {
|
||||
use ore_utils::AccountDeserialize;
|
||||
Config::try_from_bytes(&config_data)?
|
||||
};
|
||||
let clock = Clock::get().or(Err(ProgramError::InvalidAccountData))?;
|
||||
if config
|
||||
.last_reset_at
|
||||
@@ -71,7 +74,10 @@ pub fn process_mine(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
|
||||
// Here we use drillx to validate the provided solution is a valid hash of the challenge.
|
||||
// If invalid, we return an error.
|
||||
let mut proof_data = proof_info.data.borrow_mut();
|
||||
let proof = Proof::try_from_bytes_mut(&mut proof_data)?;
|
||||
let proof = {
|
||||
use ore_utils::AccountDeserialize;
|
||||
Proof::try_from_bytes_mut(&mut proof_data)?
|
||||
};
|
||||
let solution = Solution::new(args.digest, args.nonce);
|
||||
if !solution.is_valid(&proof.challenge) {
|
||||
return Err(OreError::HashInvalid.into());
|
||||
@@ -116,7 +122,10 @@ pub fn process_mine(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
|
||||
// Any stake less than this will receives between 1x and 2x multipler. The multipler is only active
|
||||
// if the miner's last stake deposit was more than one minute ago to protect against flash loan attacks.
|
||||
let mut bus_data = bus_info.data.borrow_mut();
|
||||
let bus = Bus::try_from_bytes_mut(&mut bus_data)?;
|
||||
let bus = {
|
||||
use ore_utils::AccountDeserialize;
|
||||
Bus::try_from_bytes_mut(&mut bus_data)?
|
||||
};
|
||||
if proof.balance.gt(&0) && proof.last_stake_at.saturating_add(ONE_MINUTE).lt(&t) {
|
||||
// Calculate staking reward.
|
||||
if config.top_balance.gt(&0) {
|
||||
@@ -158,9 +167,15 @@ pub fn process_mine(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
|
||||
|
||||
// Parse account data.
|
||||
let boost_data = boost_info.data.borrow();
|
||||
let boost = Boost::try_from_bytes(&boost_data)?;
|
||||
let boost = {
|
||||
use ore_boost_api::ore_utils::AccountDeserialize;
|
||||
Boost::try_from_bytes(&boost_data)?
|
||||
};
|
||||
let stake_data = stake_info.data.borrow();
|
||||
let stake = Stake::try_from_bytes(&stake_data)?;
|
||||
let stake = {
|
||||
use ore_boost_api::ore_utils::AccountDeserialize;
|
||||
Stake::try_from_bytes(&stake_data)?
|
||||
};
|
||||
|
||||
// Apply multiplier if boost is not expired and last stake at was more than one minute ago.
|
||||
if boost.expires_at.gt(&t) && stake.last_stake_at.saturating_add(ONE_MINUTE).le(&t) {
|
||||
|
||||
Reference in New Issue
Block a user