update solution

This commit is contained in:
Hardhat Chad
2025-05-12 07:45:55 -07:00
parent 3b1e0c42ef
commit 9bb6b476f4
4 changed files with 31 additions and 13 deletions

View File

@@ -50,7 +50,10 @@ pub fn process_initialize(accounts: &[AccountInfo<'_>], _data: &[u8]) -> Program
let config = config_info.as_account_mut::<Config>(&ore_api::ID)?;
// config.base_reward_rate = INITIAL_BASE_REWARD_RATE;
config.last_reset_at = 0;
// config.min_difficulty = INITIAL_MIN_DIFFICULTY as u64;
config.best_hash = [u8::MAX; 32];
config.best_proof = Pubkey::default();
config.challenge = [0; 32];
config.block_reward = 0;
// Initialize treasury.
create_program_account::<Treasury>(

View File

@@ -1,4 +1,3 @@
use drillx::difficulty;
use ore_api::prelude::*;
use solana_program::hash;
use steel::*;
@@ -35,12 +34,9 @@ pub fn process_mine(accounts: &[AccountInfo], data: &[u8]) -> ProgramResult {
proof.authority.to_bytes().as_slice(),
]);
// Get the difficulty score.
let difficulty = difficulty(solution.to_bytes());
// Update the best solution.
if difficulty as u64 > config.best_difficulty {
config.best_difficulty = difficulty as u64;
if solution.to_bytes() < config.best_hash {
config.best_hash = solution.to_bytes();
config.best_proof = *proof_info.key;
}

View File

@@ -1,3 +1,4 @@
use drillx::difficulty;
use ore_api::prelude::*;
use ore_boost_api::state::Config as BoostConfig;
use solana_program::{hash::hashv, slot_hashes::SlotHash};
@@ -47,17 +48,22 @@ pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
return Ok(());
}
// Process epoch.
config.block_reward = get_block_reward(mint.supply());
config.best_proof = Pubkey::default();
config.best_difficulty = 0;
config.last_reset_at = clock.unix_timestamp;
// Record difficulty.
let difficulty = difficulty(config.best_hash) as u64;
// Reset the challenge.
config.challenge = hashv(&[
config.challenge.as_slice(),
&slot_hashes_sysvar.data.borrow()[0..size_of::<SlotHash>()],
])
.to_bytes();
// Reset the config.
config.block_reward = get_block_reward(mint.supply());
config.best_proof = Pubkey::default();
config.best_hash = [u8::MAX; 32];
config.last_reset_at = clock.unix_timestamp;
// Calculate boost reward.
let take_rate = boost_config.take_rate.min(9900); // Cap at 99%
let boost_reward = config.block_reward * take_rate / ore_boost_api::consts::DENOMINATOR_BPS;
@@ -77,6 +83,19 @@ pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
&[TREASURY],
)?;
// Emit event.
MineEvent {
balance: proof.balance,
difficulty,
last_hash_at: 0,
timing: 0,
net_reward: config.block_reward,
net_base_reward: miner_reward,
net_miner_boost_reward: boost_reward,
net_staker_boost_reward: 0,
}
.log_return();
Ok(())
}