Skip to content

Commit

Permalink
small cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
HardhatChad committed Aug 8, 2024
1 parent 6024c91 commit 5c1d8eb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
12 changes: 8 additions & 4 deletions src/mine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::{

impl Miner {
pub async fn mine(&self, args: MineArgs) {
// Register, if needed.
// Open account, if needed.
let signer = self.signer();
self.open().await;

Expand All @@ -42,27 +42,31 @@ impl Miner {
calculate_multiplier(proof.balance, config.top_balance)
);

// Calc cutoff time
// Calculate cutoff time
let cutoff_time = self.get_cutoff(proof, args.buffer_time).await;

// Run drillx
let solution =
Self::find_hash_par(proof, cutoff_time, args.cores, config.min_difficulty as u32)
.await;

// Submit most difficult hash
let mut compute_budget = 500_000;
// Build instruction set
let mut ixs = vec![ore_api::instruction::auth(proof_pubkey(signer.pubkey()))];
let mut compute_budget = 500_000;
if self.should_reset(config).await && rand::thread_rng().gen_range(0..100).eq(&0) {
compute_budget += 100_000;
ixs.push(ore_api::instruction::reset(signer.pubkey()));
}

// Build mine ix
ixs.push(ore_api::instruction::mine(
signer.pubkey(),
signer.pubkey(),
self.find_bus().await,
solution,
));

// Submit transaction
self.send_and_confirm(&ixs, ComputeBudget::Fixed(compute_budget), false)
.await
.ok();
Expand Down
29 changes: 19 additions & 10 deletions src/send_and_confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,7 @@ impl Miner {
let fee_payer = self.fee_payer();

// Return error, if balance is zero
if let Ok(balance) = client.get_balance(&fee_payer.pubkey()).await {
if balance <= sol_to_lamports(MIN_SOL_BALANCE) {
panic!(
"{} Insufficient balance: {} SOL\nPlease top up with at least {} SOL",
"ERROR".bold().red(),
lamports_to_sol(balance),
MIN_SOL_BALANCE
);
}
}
self.check_balance().await;

// Set compute budget
let mut final_ixs = vec![];
Expand Down Expand Up @@ -196,6 +187,24 @@ impl Miner {
}
}

pub async fn check_balance(&self) {
// Throw error if balance is less than min
if let Ok(balance) = self
.rpc_client
.get_balance(&self.fee_payer().pubkey())
.await
{
if balance <= sol_to_lamports(MIN_SOL_BALANCE) {
panic!(
"{} Insufficient balance: {} SOL\nPlease top up with at least {} SOL",
"ERROR".bold().red(),
lamports_to_sol(balance),
MIN_SOL_BALANCE
);
}
}
}

// TODO
fn _simulate(&self) {

Expand Down

0 comments on commit 5c1d8eb

Please sign in to comment.