From c913ee44eaf661a6d454111108c0cdc5a5da11fa Mon Sep 17 00:00:00 2001 From: Hardhat Chad Date: Fri, 18 Oct 2024 23:41:54 +0000 Subject: [PATCH 1/2] consolidate logs --- api/src/event.rs | 11 +++-------- program/src/mine.rs | 20 +++++++++----------- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/api/src/event.rs b/api/src/event.rs index 0fa55bf..8a2ecb2 100644 --- a/api/src/event.rs +++ b/api/src/event.rs @@ -7,14 +7,9 @@ pub struct MineEvent { pub reward: u64, pub timing: i64, pub balance: u64, -} - -#[repr(C)] -#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)] -pub struct BoostEvent { - pub mint: Pubkey, - pub reward: u64, + pub boost_1: u64, + pub boost_2: u64, + pub boost_3: u64, } event!(MineEvent); -event!(BoostEvent); diff --git a/program/src/mine.rs b/program/src/mine.rs index dabaf58..529497c 100644 --- a/program/src/mine.rs +++ b/program/src/mine.rs @@ -122,7 +122,7 @@ pub fn process_mine(accounts: &[AccountInfo], data: &[u8]) -> ProgramResult { // Boosts are staking incentives that can multiply a miner's rewards. Up to 3 boosts can be applied // on any given mine operation. let base_reward = reward; - let mut boost_events: Vec = vec![]; + let mut boost_rewards = [0u64; 3]; let mut applied_boosts = [Pubkey::new_from_array([0; 32]); 3]; for i in 0..3 { if optional_accounts.len().gt(&(i * 2)) { @@ -156,10 +156,7 @@ pub fn process_mine(accounts: &[AccountInfo], data: &[u8]) -> ProgramResult { reward = reward.checked_add(boost_reward).unwrap(); // Push boost event - boost_events.push(BoostEvent { - mint: boost.mint, - reward: boost_reward, - }); + boost_rewards[i] = boost_reward; } } } @@ -224,18 +221,16 @@ pub fn process_mine(accounts: &[AccountInfo], data: &[u8]) -> ProgramResult { proof.total_hashes = proof.total_hashes.saturating_add(1); proof.total_rewards = proof.total_rewards.saturating_add(reward_actual); - // Log events. + // Log data. // // The boost rewards are scaled down before logging to account for penalties and bus limits. - // These logs can be used by pool operators to calculate miner and staker rewards. - sol_log(format!("Base: {}", reward_actual).as_str()); - for mut e in boost_events.into_iter() { - e.reward = (e.reward as u128) + // This return data can be used by pool operators to calculate miner and staker rewards. + for i in 0..3 { + boost_rewards[i] = (boost_rewards[i] as u128) .checked_mul(reward_actual as u128) .unwrap() .checked_div(reward_pre_penalty as u128) .unwrap() as u64; - sol_log_data(&[e.to_bytes()]); } set_return_data( MineEvent { @@ -243,6 +238,9 @@ pub fn process_mine(accounts: &[AccountInfo], data: &[u8]) -> ProgramResult { reward: reward_actual, timing: t.saturating_sub(t_liveness), balance: proof.balance, + boost_1: boost_rewards[0], + boost_2: boost_rewards[1], + boost_3: boost_rewards[2], } .to_bytes(), ); From 4b9362048af3bd378480c850473ec48cfe74ad1b Mon Sep 17 00:00:00 2001 From: Hardhat Chad Date: Fri, 18 Oct 2024 23:48:07 +0000 Subject: [PATCH 2/2] last hash at --- api/src/event.rs | 7 ++++--- program/src/mine.rs | 10 +++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/api/src/event.rs b/api/src/event.rs index 8a2ecb2..b79abe5 100644 --- a/api/src/event.rs +++ b/api/src/event.rs @@ -3,10 +3,11 @@ use steel::*; #[repr(C)] #[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)] pub struct MineEvent { - pub difficulty: u64, - pub reward: u64, - pub timing: i64, pub balance: u64, + pub difficulty: u64, + pub last_hash_at: i64, + pub timing: i64, + pub reward: u64, pub boost_1: u64, pub boost_2: u64, pub boost_3: u64, diff --git a/program/src/mine.rs b/program/src/mine.rs index 529497c..b653d77 100644 --- a/program/src/mine.rs +++ b/program/src/mine.rs @@ -6,7 +6,6 @@ use ore_boost_api::state::{Boost, Stake}; #[allow(deprecated)] use solana_program::{ keccak::hashv, - log::{sol_log, sol_log_data}, program::set_return_data, sanitize::SanitizeError, serialize_utils::{read_pubkey, read_u16}, @@ -216,7 +215,7 @@ pub fn process_mine(accounts: &[AccountInfo], data: &[u8]) -> ProgramResult { .0; // Update stats. - sol_log(format!("Last hash at: {}", proof.last_hash_at).as_str()); + let prev_last_hash_at = proof.last_hash_at; proof.last_hash_at = t.max(t_target); proof.total_hashes = proof.total_hashes.saturating_add(1); proof.total_rewards = proof.total_rewards.saturating_add(reward_actual); @@ -234,10 +233,11 @@ pub fn process_mine(accounts: &[AccountInfo], data: &[u8]) -> ProgramResult { } set_return_data( MineEvent { - difficulty: difficulty as u64, - reward: reward_actual, - timing: t.saturating_sub(t_liveness), balance: proof.balance, + difficulty: difficulty as u64, + last_hash_at: prev_last_hash_at, + timing: t.saturating_sub(t_liveness), + reward: reward_actual, boost_1: boost_rewards[0], boost_2: boost_rewards[1], boost_3: boost_rewards[2],