Skip to content

Commit

Permalink
drill hashes and tokio sleep
Browse files Browse the repository at this point in the history
  • Loading branch information
miralandlabs committed Aug 23, 2024
1 parent 13aab4b commit a275fa2
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 28 deletions.
Binary file modified .DS_Store
Binary file not shown.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 14 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "more-cli"
version = "2.1.0"
version = "2.2.0"
edition = "2021"
license = "Apache-2.0"
description = "A command line interface for ORE cryptocurrency mining. Tailored by Miraland Labs."
Expand Down Expand Up @@ -28,7 +28,7 @@ clap = { version = "4.4.12", features = ["derive"] }
color-eyre = { version = "0.6" }
colored = "2.0"
core_affinity = "0.8.1"
drillx = "2.0.0"
drillx = "2.1.0"
# drillx = { git = "https://github.com/regolith-labs/drillx", branch = "master", features = ["solana"] }
futures = "0.3.30"
indicatif = "0.17.8"
Expand Down Expand Up @@ -63,3 +63,15 @@ url = "2.5"
# ore-api = { path = "../ore/api" }
# ore-utils = { path = "../ore/utils" }

[profile.release]
opt-level = 3 # Optimize for binary size. You can use "3" for full optimizations if binary size isn't an issue.
codegen-units = 1 # Better optimization with fewer codegen units
lto = true # Enable Link Time Optimization (LTO)
debug = false # Disable debug info to reduce binary size
panic = 'abort' # Reduces the binary size further by not including unwinding information
rpath = false
incremental = false
overflow-checks = false

[build]
rustflags = ["-C", "target-cpu=native"]
2 changes: 2 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use colored::Colorize;
use ore_api::consts::EPOCH_DURATION;

use crate::{utils, Miner};

Expand All @@ -13,5 +14,6 @@ impl Miner {
"Top stake".bold(),
utils::amount_u64_to_string(config.top_balance)
);
println!("{}: {} sec", "Epoch time".bold(), EPOCH_DURATION);
}
}
28 changes: 14 additions & 14 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ use std::sync::Arc;

use args::*;
use clap::{
builder::{
styling::{AnsiColor, Effects},
Styles,
},
command, Parser, Subcommand,
builder::{
styling::{AnsiColor, Effects},
Styles,
},
command, Parser, Subcommand,
};
use solana_client::nonblocking::rpc_client::RpcClient;
use solana_sdk::{
Expand Down Expand Up @@ -129,7 +129,7 @@ struct Args {
long,
value_name = "FEE_MICROLAMPORTS",
help = "Price to pay for compute units when dynamic fee flag is off, or dynamic fee is unavailable.",
default_value = "20000",
default_value = "10000",
global = true
)]
priority_fee: Option<u64>,
Expand All @@ -138,7 +138,7 @@ struct Args {
long,
value_name = "FEE_CAP_MICROLAMPORTS",
help = "Max price to pay for compute units when dynamic fees are enabled.",
default_value = "500000",
default_value = "100000",
global = true
)]
priority_fee_cap: Option<u64>,
Expand All @@ -153,7 +153,7 @@ struct Args {

#[arg(long, help = "Enable dynamic priority fees", global = true)]
dynamic_fee: bool,

/// Mine with sound notification on/off
#[arg(
long,
Expand All @@ -162,7 +162,7 @@ struct Args {
default_value = "false",
global = true
)]
no_sound_notification: bool,
no_sound_notification: bool,

#[command(subcommand)]
command: Commands,
Expand Down Expand Up @@ -288,9 +288,9 @@ impl Miner {
}

fn styles() -> Styles {
Styles::styled()
.header(AnsiColor::Red.on_default() | Effects::BOLD)
.usage(AnsiColor::Red.on_default() | Effects::BOLD)
.literal(AnsiColor::Blue.on_default() | Effects::BOLD)
.placeholder(AnsiColor::Green.on_default())
Styles::styled()
.header(AnsiColor::Red.on_default() | Effects::BOLD)
.usage(AnsiColor::Red.on_default() | Effects::BOLD)
.literal(AnsiColor::Blue.on_default() | Effects::BOLD)
.placeholder(AnsiColor::Green.on_default())
}
11 changes: 6 additions & 5 deletions src/mine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,23 +219,24 @@ impl Miner {
let mut best_difficulty = 0;
let mut best_hash = Hash::default();
loop {
// Create hash
if let Ok(hx) = drillx::hash_with_memory(
// Get hashes
let hxs = drillx::hashes_with_memory(
&mut memory,
&proof.challenge,
&nonce.to_le_bytes(),
) {
);

// Look for best difficulty score in all hashes
for hx in hxs {
let difficulty = hx.difficulty();
if difficulty.gt(&best_difficulty) {
best_nonce = nonce;
best_difficulty = difficulty;
best_hash = hx;
// {{ edit_1 }}
if best_difficulty.gt(&*global_best_difficulty.read().unwrap())
{
*global_best_difficulty.write().unwrap() = best_difficulty;
}
// {{ edit_1 }}
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/send_and_confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ impl Miner {
}) = difficulty_payload
{
if solution_difficulty > extra_fee_difficulty {
prio_fee = if let Some(priority_fee_cap) = self.priority_fee_cap {
prio_fee = if let Some(priority_fee_cap) = self.priority_fee_cap
{
priority_fee_cap.min(
prio_fee
.saturating_mul(
Expand Down Expand Up @@ -217,7 +218,7 @@ impl Miner {

// Confirm transaction
'confirm: for _ in 0..CONFIRM_RETRIES {
std::thread::sleep(Duration::from_millis(CONFIRM_DELAY));
tokio::time::sleep(Duration::from_millis(CONFIRM_DELAY)).await;
match client.get_signature_statuses(&[sig]).await {
Ok(signature_statuses) => {
for status in signature_statuses.value {
Expand Down Expand Up @@ -313,7 +314,7 @@ impl Miner {
}

// Retry
std::thread::sleep(Duration::from_millis(GATEWAY_DELAY));
tokio::time::sleep(Duration::from_millis(GATEWAY_DELAY)).await;
if attempts > GATEWAY_RETRIES {
log_error(&progress_bar, "Max retries", true);
return Err(ClientError {
Expand Down
2 changes: 1 addition & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub async fn get_updated_proof_with_authority(
if proof.last_hash_at.gt(&lash_hash_at) {
return proof;
}
std::thread::sleep(Duration::from_millis(1000));
tokio::time::sleep(Duration::from_millis(1_000)).await;
}
}

Expand Down

0 comments on commit a275fa2

Please sign in to comment.