This commit is contained in:
alex
2024-09-23 23:54:24 -07:00
parent 4d66db69dc
commit 78ebb7a8d6
2 changed files with 36 additions and 9 deletions

18
Cargo.lock generated
View File

@@ -1294,7 +1294,7 @@ dependencies = [
"drillx",
"mpl-token-metadata",
"num_enum",
"ore-utils",
"ore-utils 2.1.9",
"solana-program",
"spl-associated-token-account",
"spl-token",
@@ -1310,7 +1310,7 @@ dependencies = [
"bytemuck",
"const-crypto",
"num_enum",
"ore-utils",
"ore-utils 2.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
"solana-program",
"spl-associated-token-account",
"spl-token",
@@ -1326,7 +1326,7 @@ dependencies = [
"mpl-token-metadata",
"ore-api",
"ore-boost-api",
"ore-utils",
"ore-utils 2.1.9",
"rand 0.8.5",
"solana-program",
"spl-associated-token-account",
@@ -1343,6 +1343,18 @@ dependencies = [
"spl-token",
]
[[package]]
name = "ore-utils"
version = "2.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a2d6933b14c84fb91ad7ab2e8fccff589884a81507c1a198dea4f03f3180ef4"
dependencies = [
"bytemuck",
"solana-program",
"spl-associated-token-account",
"spl-token",
]
[[package]]
name = "parking_lot"
version = "0.12.3"

View File

@@ -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) {