noise seed

This commit is contained in:
Hardhat Chad
2025-06-13 10:48:09 -07:00
parent 496a6cc476
commit ab04720ca2
8 changed files with 10 additions and 28 deletions

View File

@@ -29,6 +29,7 @@ pub struct Commit {
pub amount: [u8; 8], pub amount: [u8; 8],
pub executor: [u8; 32], pub executor: [u8; 32],
pub fee: [u8; 8], pub fee: [u8; 8],
pub seed: [u8; 32],
} }
#[repr(C)] #[repr(C)]

View File

@@ -16,11 +16,7 @@ pub struct Block {
/// The block number. /// The block number.
pub id: u64, pub id: u64,
/// The minimum difficulty required for payout. /// The reward configuration.
// pub min_difficulty: u64,
/// The reward rate per satisfying hash.
// pub reward_rate: u64,
pub reward: RewardConfig, pub reward: RewardConfig,
/// The hash of the starting slot. /// The hash of the starting slot.
@@ -34,9 +30,6 @@ pub struct Block {
/// The total amount of rewards paid out to miners. /// The total amount of rewards paid out to miners.
pub total_rewards: u64, pub total_rewards: u64,
/// The total number of hashes that resulted in a payout.
pub winning_hashes: u64,
} }
/// Configuration specifying how rewards are paid out. /// Configuration specifying how rewards are paid out.

View File

@@ -21,9 +21,6 @@ pub struct Miner {
/// The amount of ORE this miner has mined. /// The amount of ORE this miner has mined.
pub total_rewards: u64, pub total_rewards: u64,
/// The number of winning hashes this miner has submitted.
pub winning_hashes: u64,
} }
impl Miner { impl Miner {

View File

@@ -21,6 +21,9 @@ pub struct Permit {
/// The fee paid to the executor. /// The fee paid to the executor.
pub fee: u64, pub fee: u64,
/// A user-supplied seed for random number generation.
pub seed: [u8; 32],
} }
impl Permit { impl Permit {

View File

@@ -94,7 +94,6 @@ fn print_block(block: Block) {
println!(" Slot hash: {:?}", block.slot_hash); println!(" Slot hash: {:?}", block.slot_hash);
// println!(" Min difficulty: {:?}", block.min_difficulty); // println!(" Min difficulty: {:?}", block.min_difficulty);
println!(" Total hashes: {:?}", block.total_hashes); println!(" Total hashes: {:?}", block.total_hashes);
println!(" Winning hashes: {:?}", block.winning_hashes);
} }
async fn log_blocks(rpc: &RpcClient) -> Result<(), anyhow::Error> { async fn log_blocks(rpc: &RpcClient) -> Result<(), anyhow::Error> {
@@ -119,16 +118,6 @@ async fn get_clock(rpc: &RpcClient) -> Result<Clock, anyhow::Error> {
Ok(clock) Ok(clock)
} }
// async fn get_block_commits(rpc: &RpcClient) -> Result<Vec<(Pubkey, Commit)>, anyhow::Error> {
// let block = get_block(rpc).await?;
// let filter = RpcFilterType::Memcmp(Memcmp::new_base58_encoded(
// 56,
// &block.current_round.to_le_bytes(),
// ));
// let commits = get_program_accounts::<Commit>(rpc, ore_api::ID, vec![filter]).await?;
// Ok(commits)
// }
async fn get_blocks(rpc: &RpcClient) -> Result<Vec<(Pubkey, Block)>, anyhow::Error> { async fn get_blocks(rpc: &RpcClient) -> Result<Vec<(Pubkey, Block)>, anyhow::Error> {
let blocks = get_program_accounts::<Block>(rpc, ore_api::ID, vec![]).await?; let blocks = get_program_accounts::<Block>(rpc, ore_api::ID, vec![]).await?;
Ok(blocks) Ok(blocks)

View File

@@ -81,6 +81,7 @@ pub fn process_commit(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResul
// Update executor logic. // Update executor logic.
permit.executor = executor; permit.executor = executor;
permit.fee = fee; permit.fee = fee;
permit.seed = args.seed;
// Transfer hash tokens. // Transfer hash tokens.
transfer( transfer(

View File

@@ -87,12 +87,13 @@ pub fn process_mine(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
// Reset miner hash if mining new block. // Reset miner hash if mining new block.
if miner.block_id != block.id { if miner.block_id != block.id {
miner.block_id = block.id; let mut args = [0u8; 128];
let mut args = [0u8; 96];
args[..32].copy_from_slice(&block.id.to_le_bytes()); args[..32].copy_from_slice(&block.id.to_le_bytes());
args[32..64].copy_from_slice(&block.slot_hash); args[32..64].copy_from_slice(&block.slot_hash);
args[64..].copy_from_slice(&miner.authority.to_bytes()); args[64..96].copy_from_slice(&permit.authority.to_bytes());
args[96..].copy_from_slice(&permit.seed);
miner.hash = hash(&args); miner.hash = hash(&args);
miner.block_id = block.id;
} }
// Mine and accumulate rewards. // Mine and accumulate rewards.
@@ -108,8 +109,6 @@ pub fn process_mine(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
// Score and increment rewards. // Score and increment rewards.
let score = difficulty(miner.hash) as u64; let score = difficulty(miner.hash) as u64;
if score >= block.reward.nugget_threshold { if score >= block.reward.nugget_threshold {
block.winning_hashes += 1;
miner.winning_hashes += 1;
miner_reward += block.reward.nugget_reward; miner_reward += block.reward.nugget_reward;
} }

View File

@@ -79,7 +79,6 @@ pub fn process_open(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
block.slot_hash = [0; 32]; block.slot_hash = [0; 32];
block.start_slot = start_slot; block.start_slot = start_slot;
block.total_hashes = 0; block.total_hashes = 0;
block.winning_hashes = 0;
// Select reward strategy. // Select reward strategy.
let noise_seed = block.id.to_le_bytes(); let noise_seed = block.id.to_le_bytes();