Skip to content

Commit 3820cb3

Browse files
committed
ensure proof account has been updated
1 parent 80532c0 commit 3820cb3

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/mine.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ use solana_sdk::signer::Signer;
1818
use crate::{
1919
args::MineArgs,
2020
send_and_confirm::ComputeBudget,
21-
utils::{amount_u64_to_string, get_clock, get_config, get_proof_with_authority, proof_pubkey},
21+
utils::{
22+
amount_u64_to_string, get_clock, get_config, get_updated_proof_with_authority, proof_pubkey,
23+
},
2224
Miner,
2325
};
2426

@@ -32,10 +34,14 @@ impl Miner {
3234
self.check_num_cores(args.cores);
3335

3436
// Start mining loop
37+
let mut last_hash_at = 0;
3538
loop {
3639
// Fetch proof
3740
let config = get_config(&self.rpc_client).await;
38-
let proof = get_proof_with_authority(&self.rpc_client, signer.pubkey()).await;
41+
let proof =
42+
get_updated_proof_with_authority(&self.rpc_client, signer.pubkey(), last_hash_at)
43+
.await;
44+
last_hash_at = proof.last_hash_at;
3945
println!(
4046
"\nStake: {} ORE\n Multiplier: {:12}x",
4147
amount_u64_to_string(proof.balance),

src/utils.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::io::Read;
1+
use std::{io::Read, time::Duration};
22

33
use cached::proc_macro::cached;
44
use ore_api::{
@@ -34,6 +34,20 @@ pub async fn get_proof_with_authority(client: &RpcClient, authority: Pubkey) ->
3434
get_proof(client, proof_address).await
3535
}
3636

37+
pub async fn get_updated_proof_with_authority(
38+
client: &RpcClient,
39+
authority: Pubkey,
40+
lash_hash_at: i64,
41+
) -> Proof {
42+
loop {
43+
let proof = get_proof_with_authority(client, authority).await;
44+
if proof.last_hash_at.gt(&lash_hash_at) {
45+
return proof;
46+
}
47+
std::thread::sleep(Duration::from_millis(1000));
48+
}
49+
}
50+
3751
pub async fn get_proof(client: &RpcClient, address: Pubkey) -> Proof {
3852
let data = client
3953
.get_account_data(&address)

0 commit comments

Comments
 (0)