mystery block reward, sniper fee

This commit is contained in:
Hardhat Chad
2025-07-18 11:09:06 -07:00
parent acbb1be65f
commit 461505cd2c
12 changed files with 303 additions and 94 deletions

View File

@@ -1,5 +1,4 @@
use ore_api::prelude::*;
use solana_nostd_keccak::hash;
use steel::*;
/// Opens a new block.
@@ -34,7 +33,7 @@ pub fn process_open(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
let block = block_info.as_account_mut::<Block>(&ore_api::ID)?;
block.id = id;
block.opener = *signer_info.key;
block.reward = calculate_reward(block.id);
block.reward = 0;
block.best_hash = [0; 32];
block.best_hash_miner = Pubkey::default();
block.start_slot = u64::MAX; // Set by reset
@@ -61,34 +60,3 @@ pub fn process_open(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
Ok(())
}
fn calculate_reward(block_id: u64) -> u64 {
// Generate noise.
let noise_seed = block_id.to_le_bytes();
let noise = hash(&noise_seed);
// Extract the first byte (0 to 255).
let byte_value = noise[0];
// Map to 1-10 using integer division
let n = (byte_value / 25) + 1;
// Ensure the value doesn't exceed 10
let n = n.min(10);
n as u64 * ONE_ORE
}
#[test]
fn test_lode_rewards() {
for i in 0u64..1000 {
let lode_reward = ONE_ORE * calculate_reward(i) as u64;
let target_block_reward = ONE_ORE * 10;
let expected_hashes_per_block = HASHPOWER_LIQUIDITY / 2;
let expected_qualifying_hashes =
expected_hashes_per_block / 2u64.pow(NUGGET_DIFFICULTY as u32);
let difficulty_reward = (target_block_reward - lode_reward) / expected_qualifying_hashes;
println!("{}: {} {}", i, lode_reward, difficulty_reward);
}
// assert!(false);
}