From 3820cb30b1e161ccace0e27f919e7a10a48b2e5b Mon Sep 17 00:00:00 2001 From: Hardhat Chad Date: Thu, 8 Aug 2024 18:00:46 +0000 Subject: [PATCH] ensure proof account has been updated --- src/mine.rs | 10 ++++++++-- src/utils.rs | 16 +++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/mine.rs b/src/mine.rs index 60df59fa..9dd2fcc5 100644 --- a/src/mine.rs +++ b/src/mine.rs @@ -18,7 +18,9 @@ use solana_sdk::signer::Signer; use crate::{ args::MineArgs, send_and_confirm::ComputeBudget, - utils::{amount_u64_to_string, get_clock, get_config, get_proof_with_authority, proof_pubkey}, + utils::{ + amount_u64_to_string, get_clock, get_config, get_updated_proof_with_authority, proof_pubkey, + }, Miner, }; @@ -32,10 +34,14 @@ impl Miner { self.check_num_cores(args.cores); // Start mining loop + let mut last_hash_at = 0; loop { // Fetch proof let config = get_config(&self.rpc_client).await; - let proof = get_proof_with_authority(&self.rpc_client, signer.pubkey()).await; + let proof = + get_updated_proof_with_authority(&self.rpc_client, signer.pubkey(), last_hash_at) + .await; + last_hash_at = proof.last_hash_at; println!( "\nStake: {} ORE\n Multiplier: {:12}x", amount_u64_to_string(proof.balance), diff --git a/src/utils.rs b/src/utils.rs index 0097c67f..0a7405a6 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,4 +1,4 @@ -use std::io::Read; +use std::{io::Read, time::Duration}; use cached::proc_macro::cached; use ore_api::{ @@ -34,6 +34,20 @@ pub async fn get_proof_with_authority(client: &RpcClient, authority: Pubkey) -> get_proof(client, proof_address).await } +pub async fn get_updated_proof_with_authority( + client: &RpcClient, + authority: Pubkey, + lash_hash_at: i64, +) -> Proof { + loop { + let proof = get_proof_with_authority(client, authority).await; + if proof.last_hash_at.gt(&lash_hash_at) { + return proof; + } + std::thread::sleep(Duration::from_millis(1000)); + } +} + pub async fn get_proof(client: &RpcClient, address: Pubkey) -> Proof { let data = client .get_account_data(&address)