From 86f03e7956c53a030eca9a74951ce314c68a2e0e Mon Sep 17 00:00:00 2001 From: Hardhat Chad Date: Sun, 8 Jun 2025 09:27:45 -0700 Subject: [PATCH] block hashes --- cli/src/main.rs | 39 ++++++++++++++++++++++++++------------ ore/api/src/state/block.rs | 3 +++ ore/program/src/mine.rs | 1 + 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/cli/src/main.rs b/cli/src/main.rs index f4c2d44..53e1330 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -38,6 +38,9 @@ async fn main() { "block" => { log_block(&rpc).await.unwrap(); } + "blocks" => { + log_blocks(&rpc).await.unwrap(); + } _ => panic!("Invalid command"), }; } @@ -74,7 +77,26 @@ async fn log_block(rpc: &RpcClient) -> Result<(), anyhow::Error> { let id_str = std::env::var("ID").expect("Missing ID env var"); let id = id_str.parse::()?; let block = get_block(&rpc, id).await?; - println!("Block: {:?}", block); + print_block(block); + Ok(()) +} + +fn print_block(block: Block) { + let address = block_pda(block.id).0; + println!("Address: {:?}", address); + println!(" Id: {:?}", block.id); + println!(" Start slot: {:?}", block.start_slot); + println!(" Best miner: {:?}", block.best_miner); + println!(" Reward: {:?}", block.reward); + println!(" Slot hash: {:?}", block.slot_hash); + println!(" Best hash: {:?}\n", block.best_hash); +} + +async fn log_blocks(rpc: &RpcClient) -> Result<(), anyhow::Error> { + let blocks = get_blocks(&rpc).await?; + for (_, block) in blocks { + print_block(block); + } Ok(()) } @@ -101,17 +123,10 @@ async fn get_clock(rpc: &RpcClient) -> Result { // Ok(commits) // } -// async fn get_my_commits( -// rpc: &RpcClient, -// payer: &solana_sdk::signer::keypair::Keypair, -// ) -> Result, anyhow::Error> { -// let filter = RpcFilterType::Memcmp(Memcmp::new_base58_encoded( -// 16, -// &payer.pubkey().to_bytes().as_ref(), -// )); -// 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) +} async fn submit_transaction( rpc: &RpcClient, diff --git a/ore/api/src/state/block.rs b/ore/api/src/state/block.rs index d25db92..f057dd3 100644 --- a/ore/api/src/state/block.rs +++ b/ore/api/src/state/block.rs @@ -22,6 +22,9 @@ pub struct Block { /// The starting slot of the block. pub start_slot: u64, + + /// The total number of hashes submitted to the block. + pub total_hashes: u64, } account!(OreAccount, Block); diff --git a/ore/program/src/mine.rs b/ore/program/src/mine.rs index 06e577e..e305c30 100644 --- a/ore/program/src/mine.rs +++ b/ore/program/src/mine.rs @@ -84,6 +84,7 @@ pub fn process_mine(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult // Mine. for _ in 0..amount { + block.total_hashes += 1; miner.hash = hash(miner.hash.as_ref()); if miner.hash < block.best_hash { block.best_hash = miner.hash;