Skip to content

Commit

Permalink
ensure proof account has been updated
Browse files Browse the repository at this point in the history
  • Loading branch information
HardhatChad committed Aug 8, 2024
1 parent 80532c0 commit 3820cb3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/mine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand All @@ -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),
Expand Down
16 changes: 15 additions & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::io::Read;
use std::{io::Read, time::Duration};

use cached::proc_macro::cached;
use ore_api::{
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 3820cb3

Please sign in to comment.