From 9bb6b476f4daae27e8e18456ef1baa044171ee79 Mon Sep 17 00:00:00 2001 From: Hardhat Chad Date: Mon, 12 May 2025 07:45:55 -0700 Subject: [PATCH] update solution --- api/src/state/config.rs | 2 +- program/src/initialize.rs | 5 ++++- program/src/mine.rs | 8 ++------ program/src/reset.rs | 29 ++++++++++++++++++++++++----- 4 files changed, 31 insertions(+), 13 deletions(-) diff --git a/api/src/state/config.rs b/api/src/state/config.rs index 035e6f9..d87d9f1 100644 --- a/api/src/state/config.rs +++ b/api/src/state/config.rs @@ -10,7 +10,7 @@ pub struct Config { pub last_reset_at: i64, /// The best difficulty score of this epoch. - pub best_difficulty: u64, + pub best_hash: [u8; 32], /// The proof of the best submitted hash of this epoch. pub best_proof: Pubkey, diff --git a/program/src/initialize.rs b/program/src/initialize.rs index c01579e..1d0ef3a 100644 --- a/program/src/initialize.rs +++ b/program/src/initialize.rs @@ -50,7 +50,10 @@ pub fn process_initialize(accounts: &[AccountInfo<'_>], _data: &[u8]) -> Program let config = config_info.as_account_mut::(&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::( diff --git a/program/src/mine.rs b/program/src/mine.rs index 28ed483..b6e720d 100644 --- a/program/src/mine.rs +++ b/program/src/mine.rs @@ -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; } diff --git a/program/src/reset.rs b/program/src/reset.rs index 0cbc55d..f0f2404 100644 --- a/program/src/reset.rs +++ b/program/src/reset.rs @@ -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::()], ]) .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(()) }