From ab04720ca2c0f080f2725ed1b885fdd9c6acff96 Mon Sep 17 00:00:00 2001 From: Hardhat Chad Date: Fri, 13 Jun 2025 10:48:09 -0700 Subject: [PATCH] noise seed --- api/src/instruction.rs | 1 + api/src/state/block.rs | 9 +-------- api/src/state/miner.rs | 3 --- api/src/state/permit.rs | 3 +++ cli/src/main.rs | 11 ----------- program/src/commit.rs | 1 + program/src/mine.rs | 9 ++++----- program/src/open.rs | 1 - 8 files changed, 10 insertions(+), 28 deletions(-) diff --git a/api/src/instruction.rs b/api/src/instruction.rs index e5e8574..63d713f 100644 --- a/api/src/instruction.rs +++ b/api/src/instruction.rs @@ -29,6 +29,7 @@ pub struct Commit { pub amount: [u8; 8], pub executor: [u8; 32], pub fee: [u8; 8], + pub seed: [u8; 32], } #[repr(C)] diff --git a/api/src/state/block.rs b/api/src/state/block.rs index ab12675..415d439 100644 --- a/api/src/state/block.rs +++ b/api/src/state/block.rs @@ -16,11 +16,7 @@ pub struct Block { /// The block number. pub id: u64, - /// The minimum difficulty required for payout. - // pub min_difficulty: u64, - - /// The reward rate per satisfying hash. - // pub reward_rate: u64, + /// The reward configuration. pub reward: RewardConfig, /// The hash of the starting slot. @@ -34,9 +30,6 @@ pub struct Block { /// The total amount of rewards paid out to miners. 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. diff --git a/api/src/state/miner.rs b/api/src/state/miner.rs index db9bdc5..e6558eb 100644 --- a/api/src/state/miner.rs +++ b/api/src/state/miner.rs @@ -21,9 +21,6 @@ pub struct Miner { /// The amount of ORE this miner has mined. pub total_rewards: u64, - - /// The number of winning hashes this miner has submitted. - pub winning_hashes: u64, } impl Miner { diff --git a/api/src/state/permit.rs b/api/src/state/permit.rs index 5d664b8..6ba9f09 100644 --- a/api/src/state/permit.rs +++ b/api/src/state/permit.rs @@ -21,6 +21,9 @@ pub struct Permit { /// The fee paid to the executor. pub fee: u64, + + /// A user-supplied seed for random number generation. + pub seed: [u8; 32], } impl Permit { diff --git a/cli/src/main.rs b/cli/src/main.rs index 6ce85c9..f26cb03 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -94,7 +94,6 @@ fn print_block(block: Block) { println!(" Slot hash: {:?}", block.slot_hash); // println!(" Min difficulty: {:?}", block.min_difficulty); println!(" Total hashes: {:?}", block.total_hashes); - println!(" Winning hashes: {:?}", block.winning_hashes); } async fn log_blocks(rpc: &RpcClient) -> Result<(), anyhow::Error> { @@ -119,16 +118,6 @@ async fn get_clock(rpc: &RpcClient) -> Result { Ok(clock) } -// async fn get_block_commits(rpc: &RpcClient) -> Result, 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::(rpc, ore_api::ID, vec![filter]).await?; -// Ok(commits) -// } - async fn get_blocks(rpc: &RpcClient) -> Result, anyhow::Error> { let blocks = get_program_accounts::(rpc, ore_api::ID, vec![]).await?; Ok(blocks) diff --git a/program/src/commit.rs b/program/src/commit.rs index 38356c8..387a19d 100644 --- a/program/src/commit.rs +++ b/program/src/commit.rs @@ -81,6 +81,7 @@ pub fn process_commit(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResul // Update executor logic. permit.executor = executor; permit.fee = fee; + permit.seed = args.seed; // Transfer hash tokens. transfer( diff --git a/program/src/mine.rs b/program/src/mine.rs index 5ca27c9..e91402a 100644 --- a/program/src/mine.rs +++ b/program/src/mine.rs @@ -87,12 +87,13 @@ pub fn process_mine(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult // Reset miner hash if mining new block. if miner.block_id != block.id { - miner.block_id = block.id; - let mut args = [0u8; 96]; + let mut args = [0u8; 128]; args[..32].copy_from_slice(&block.id.to_le_bytes()); 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.block_id = block.id; } // Mine and accumulate rewards. @@ -108,8 +109,6 @@ pub fn process_mine(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult // Score and increment rewards. let score = difficulty(miner.hash) as u64; if score >= block.reward.nugget_threshold { - block.winning_hashes += 1; - miner.winning_hashes += 1; miner_reward += block.reward.nugget_reward; } diff --git a/program/src/open.rs b/program/src/open.rs index 89f5333..b916c6c 100644 --- a/program/src/open.rs +++ b/program/src/open.rs @@ -79,7 +79,6 @@ pub fn process_open(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult block.slot_hash = [0; 32]; block.start_slot = start_slot; block.total_hashes = 0; - block.winning_hashes = 0; // Select reward strategy. let noise_seed = block.id.to_le_bytes();