Skip to content

Commit

Permalink
extra hash time
Browse files Browse the repository at this point in the history
  • Loading branch information
miralandlabs committed Aug 9, 2024
1 parent 779865e commit f1c7a61
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/claim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl Miner {

// Send and confirm
ixs.push(ore_api::instruction::claim(pubkey, beneficiary, amount));
self.send_and_confirm(&ixs, ComputeBudget::Fixed(CU_LIMIT_CLAIM), false)
self.send_and_confirm(&ixs, ComputeBudget::Fixed(CU_LIMIT_CLAIM), false, None)
.await
.ok();
}
Expand All @@ -99,7 +99,7 @@ impl Miner {
&ore_api::consts::MINT_ADDRESS,
&spl_token::id(),
);
self.send_and_confirm(&[ix], ComputeBudget::Dynamic, false)
self.send_and_confirm(&[ix], ComputeBudget::Dynamic, false, None)
.await
.ok();

Expand Down
2 changes: 1 addition & 1 deletion src/close.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl Miner {

// Submit close transaction
let ix = ore_api::instruction::close(signer.pubkey());
self.send_and_confirm(&[ix], ComputeBudget::Dynamic, false)
self.send_and_confirm(&[ix], ComputeBudget::Dynamic, false, None)
.await
.ok();
}
Expand Down
47 changes: 41 additions & 6 deletions src/mine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,12 @@ impl Miner {
// .await
// .ok();
if self
.send_and_confirm(&ixs, ComputeBudget::Fixed(compute_budget), false)
.send_and_confirm(
&ixs,
ComputeBudget::Fixed(compute_budget),
false,
Some(solution.to_hash().difficulty()),
)
.await
.is_ok()
{
Expand Down Expand Up @@ -180,9 +185,24 @@ impl Miner {
if nonce % 100 == 0 {
if timer.elapsed().as_secs().ge(&cutoff_time) {
if best_difficulty.ge(&min_difficulty) {
// Mine until min difficulty has been met
break;
}
if best_difficulty >= 18 {
// Mine until min difficulty has been met
break;
} else {
// delay extra 30 secs
progress_bar.set_message(format!(
"Mining... ({} sec surpassed)",
timer.elapsed().as_secs().saturating_sub(cutoff_time),
));
if timer
.elapsed()
.as_secs()
.ge(&cutoff_time.saturating_add(29))
{
break;
}
}
}
} else if i.id == 0 {
progress_bar.set_message(format!(
"Mining... ({} sec remaining)",
Expand Down Expand Up @@ -267,8 +287,23 @@ impl Miner {
if nonce % 100 == 0 {
if timer.elapsed().as_secs().ge(&cutoff_time) {
if best_difficulty.ge(&min_difficulty) {
// Mine until min difficulty has been met
break;
if best_difficulty >= 18 {
// Mine until min difficulty has been met
break;
} else {
// delay extra 30 secs
progress_bar.set_message(format!(
"Mining... ({} sec surpassed)",
timer.elapsed().as_secs().saturating_sub(cutoff_time),
));
if timer
.elapsed()
.as_secs()
.ge(&cutoff_time.saturating_add(29))
{
break;
}
}
}
} else if i == 0 {
progress_bar.set_message(format!(
Expand Down
2 changes: 1 addition & 1 deletion src/open.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl Miner {
// Sign and send transaction.
println!("Generating challenge...");
let ix = ore_api::instruction::open(signer.pubkey(), signer.pubkey(), fee_payer.pubkey());
self.send_and_confirm(&[ix], ComputeBudget::Dynamic, false)
self.send_and_confirm(&[ix], ComputeBudget::Dynamic, false, None)
.await
.ok();
}
Expand Down
16 changes: 14 additions & 2 deletions src/send_and_confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ impl Miner {
ixs: &[Instruction],
compute_budget: ComputeBudget,
skip_confirm: bool,
difficulty: Option<u32>, // MI
) -> ClientResult<Signature> {
let signer = self.signer();
let client = self.rpc_client.clone();
Expand Down Expand Up @@ -90,8 +91,19 @@ impl Miner {
// Reset the compute unit price
if self.dynamic_fee {
let fee = if let Some(fee) = self.dynamic_fee().await {
progress_bar.println(format!(" Priority fee: {} microlamports", fee));
fee
let mut prio_fee = fee;
// MI: upbound 300K for diff > 21
if let Some(difficulty) = difficulty {
if difficulty > 21 {
prio_fee =
300_000.min(prio_fee.saturating_mul(15).saturating_div(10));
} else if difficulty < 18 {
// prio_fee = 5000.max(prio_fee.saturating_mul(2).saturating_div(3));
// keep priority fee recommendation
}
}
progress_bar.println(format!(" Priority fee: {} microlamports", prio_fee));
prio_fee
} else {
let fee = self.priority_fee.unwrap_or(0);
progress_bar.println(format!(" {} Dynamic fees not supported by this RPC. Falling back to static value: {} microlamports", "WARNING".bold().yellow(), fee));
Expand Down
2 changes: 1 addition & 1 deletion src/stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl Miner {

// Send tx
let ix = ore_api::instruction::stake(signer.pubkey(), sender, amount);
self.send_and_confirm(&[ix], ComputeBudget::Fixed(CU_LIMIT_CLAIM), false)
self.send_and_confirm(&[ix], ComputeBudget::Fixed(CU_LIMIT_CLAIM), false, None)
.await
.ok();
}
Expand Down
4 changes: 2 additions & 2 deletions src/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl Miner {

let ix = ore_api::instruction::upgrade(signer.pubkey(), beneficiary, sender, amount);
match self
.send_and_confirm(&[ix], ComputeBudget::Fixed(CU_LIMIT_UPGRADE), false)
.send_and_confirm(&[ix], ComputeBudget::Fixed(CU_LIMIT_UPGRADE), false, None)
.await
{
Ok(_sig) => {}
Expand Down Expand Up @@ -105,7 +105,7 @@ impl Miner {
&ore_api::consts::MINT_ADDRESS,
&spl_token::id(),
);
self.send_and_confirm(&[ix], ComputeBudget::Dynamic, false)
self.send_and_confirm(&[ix], ComputeBudget::Dynamic, false, None)
.await
.ok();
}
Expand Down

0 comments on commit f1c7a61

Please sign in to comment.