This commit is contained in:
Hardhat Chad
2025-07-18 11:35:26 -07:00
parent 461505cd2c
commit 1c3b1246d3
6 changed files with 28 additions and 131 deletions

View File

@@ -10,7 +10,7 @@ pub fn process_mine(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
// Load accounts.
let clock = Clock::get()?;
let [signer_info, authority_info, block_info, miner_info, ore_program] = accounts else {
let [signer_info, authority_info, block_info, miner_info] = accounts else {
return Err(ProgramError::NotEnoughAccountKeys);
};
signer_info.is_signer()?;
@@ -23,24 +23,16 @@ pub fn process_mine(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
let miner = miner_info
.as_account_mut::<Miner>(&ore_api::ID)?
.assert_mut(|m| m.authority == *authority_info.key)? // Account belongs to authority
.assert_mut(|m| m.block_id <= block.id)?; // Only allow miner to submit hashes in forward bias
ore_program.is_program(&ore_api::ID)?;
// Reset miner hash if mining new block.
if miner.block_id != block.id {
let mut args = [0u8; 104];
args[..8].copy_from_slice(&block.id.to_le_bytes());
args[8..40].copy_from_slice(&block.slot_hash);
args[40..72].copy_from_slice(&miner.authority.to_bytes());
args[72..].copy_from_slice(&miner.seed);
miner.hash = hash(&args);
miner.block_id = block.id;
}
.assert_mut(|m| m.block_id == block.id)? // Only allow miner to submit hashes for their current block
.assert_mut(|m| m.hashpower > nonce)?; // Only allow miner to submit nonces for their hashpower range
// Generate secure hash with provided nonce.
let mut seed = [0u8; 40];
seed[..8].copy_from_slice(&miner.hash.as_ref());
seed[8..40].copy_from_slice(&nonce.to_le_bytes());
let mut seed = [0u8; 112];
seed[..8].copy_from_slice(&block.id.to_le_bytes());
seed[8..40].copy_from_slice(&block.slot_hash);
seed[40..72].copy_from_slice(&miner.authority.to_bytes());
seed[72..].copy_from_slice(&miner.seed);
seed[104..].copy_from_slice(&nonce.to_le_bytes());
let h = hash(&seed);
// If hash is best hash, update best hash.
@@ -49,21 +41,5 @@ pub fn process_mine(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
block.best_hash_miner = miner.authority;
}
// Emit event.
// program_log(
// block.id,
// &[block_info.clone(), ore_program.clone()],
// &MineEvent {
// disc: OreEvent::Mine as u64,
// authority: miner.authority,
// block_id: block.id,
// deployed: amount,
// total_deployed: block.total_deployed,
// remaining_commitment: 0,
// ts: clock.unix_timestamp,
// }
// .to_bytes(),
// )?;
Ok(())
}