mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-16 07:26:51 +00:00
return data
This commit is contained in:
@@ -6,7 +6,6 @@ use solana_program::{
|
||||
clock::Clock,
|
||||
entrypoint::ProgramResult,
|
||||
keccak::hashv,
|
||||
log::sol_log,
|
||||
program_error::ProgramError,
|
||||
pubkey::Pubkey,
|
||||
sanitize::SanitizeError,
|
||||
@@ -21,7 +20,7 @@ use crate::{
|
||||
instruction::{MineArgs, OreInstruction},
|
||||
loaders::*,
|
||||
state::{Bus, Config, Proof},
|
||||
utils::AccountDeserialize,
|
||||
utils::{AccountDeserialize, MineEvent},
|
||||
MIN_DIFFICULTY, ONE_MINUTE, TWO_YEARS,
|
||||
};
|
||||
|
||||
@@ -92,7 +91,6 @@ pub fn process_mine<'a, 'info>(
|
||||
|
||||
// Validate hash satisfies the minimnum difficulty
|
||||
let difficulty = drillx::difficulty(hx);
|
||||
sol_log(&format!("Diff {}", difficulty));
|
||||
if difficulty.lt(&MIN_DIFFICULTY) {
|
||||
return Err(OreError::HashTooEasy.into());
|
||||
}
|
||||
@@ -102,12 +100,12 @@ pub fn process_mine<'a, 'info>(
|
||||
let mut reward = config
|
||||
.base_reward_rate
|
||||
.saturating_mul(2u64.saturating_pow(difficulty));
|
||||
sol_log(&format!("Base {}", reward));
|
||||
|
||||
// Apply staking multiplier.
|
||||
// To prevent flash loan attacks, only apply if the last deposit was at least 1 block ago.
|
||||
// The multiplier can range 1x to 2x. To receive the maximum multiplier, the stake balance must be
|
||||
// greater than or equal to two years worth of rewards at the selected difficulty.
|
||||
let mut multiplier = 1f32;
|
||||
if clock.slot.gt(&proof.last_deposit_slot) {
|
||||
let upper_bound = reward.saturating_mul(TWO_YEARS);
|
||||
let staking_reward = proof
|
||||
@@ -115,9 +113,10 @@ pub fn process_mine<'a, 'info>(
|
||||
.min(upper_bound)
|
||||
.saturating_mul(reward)
|
||||
.saturating_div(upper_bound);
|
||||
reward = reward.saturating_add(staking_reward);
|
||||
sol_log(&format!("Staking {}", staking_reward));
|
||||
}
|
||||
let multiplied_reward = reward.saturating_add(staking_reward);
|
||||
multiplier = ((multiplied_reward as f64) / (reward as f64)) as f32;
|
||||
reward = multiplied_reward;
|
||||
};
|
||||
|
||||
// Apply spam penalty
|
||||
let t = clock.unix_timestamp;
|
||||
@@ -125,7 +124,6 @@ pub fn process_mine<'a, 'info>(
|
||||
let t_spam = t_target.saturating_sub(config.tolerance_spam);
|
||||
if t.lt(&t_spam) {
|
||||
reward = 0;
|
||||
sol_log("Spam penalty");
|
||||
}
|
||||
|
||||
// Apply liveness penalty
|
||||
@@ -136,11 +134,6 @@ pub fn process_mine<'a, 'info>(
|
||||
.saturating_mul(t.saturating_sub(t_liveness) as u64)
|
||||
.saturating_div(ONE_MINUTE as u64),
|
||||
);
|
||||
sol_log(&format!(
|
||||
"Liveness penalty ({} sec) {}",
|
||||
t.saturating_sub(t_liveness),
|
||||
reward,
|
||||
));
|
||||
}
|
||||
|
||||
// Limit payout amount to whatever is left in the bus
|
||||
@@ -149,8 +142,6 @@ pub fn process_mine<'a, 'info>(
|
||||
let reward_actual = reward.min(bus.rewards);
|
||||
|
||||
// Update balances
|
||||
sol_log(&format!("Total {}", reward));
|
||||
sol_log(&format!("Bus {}", bus.rewards));
|
||||
bus.theoretical_rewards = bus.theoretical_rewards.saturating_add(reward);
|
||||
bus.rewards = bus
|
||||
.rewards
|
||||
@@ -174,7 +165,13 @@ pub fn process_mine<'a, 'info>(
|
||||
proof.total_rewards = proof.total_rewards.saturating_add(reward);
|
||||
|
||||
// Log the mined rewards
|
||||
set_return_data(reward_actual.to_le_bytes().as_slice());
|
||||
set_return_data(bytemuck::bytes_of(&MineEvent {
|
||||
difficulty,
|
||||
multiplier,
|
||||
reward,
|
||||
reward_actual,
|
||||
timing: t.saturating_sub(t_target),
|
||||
}));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user