diff --git a/change_difficulty.sh b/change_difficulty.sh new file mode 100644 index 00000000..c8ca6185 --- /dev/null +++ b/change_difficulty.sh @@ -0,0 +1,3 @@ +perl -pi -e "s|const MIN_DIFFICULTY: u32 =.*|const MIN_DIFFICULTY: u32 = $1;|g" src/mine.rs +cargo build --release +cp target/release/ore ~/.cargo/bin \ No newline at end of file diff --git a/change_gateway_retry.sh b/change_gateway_retry.sh new file mode 100644 index 00000000..fd6f86fe --- /dev/null +++ b/change_gateway_retry.sh @@ -0,0 +1,3 @@ +perl -pi -e "s|const GATEWAY_RETRIES: usize =.*|const GATEWAY_RETRIES: usize = $1;|g" src/send_and_confirm.rs +cargo build --release +cp target/release/ore ~/.cargo/bin diff --git a/src/mine.rs b/src/mine.rs index 46cf1da1..9a8ddb65 100644 --- a/src/mine.rs +++ b/src/mine.rs @@ -13,6 +13,7 @@ use rand::Rng; use solana_program::pubkey::Pubkey; use solana_rpc_client::spinner; use solana_sdk::signer::Signer; +use std::time::{SystemTime, UNIX_EPOCH}; use crate::{ args::MineArgs, @@ -21,6 +22,8 @@ use crate::{ Miner, }; +const MIN_DIFFICULTY: u32 = 16; + impl Miner { pub async fn mine(&self, args: MineArgs) { // Register, if needed. @@ -33,24 +36,31 @@ impl Miner { // Start mining loop loop { // Fetch proof + let config = get_config(&self.rpc_client).await; let proof = get_proof_with_authority(&self.rpc_client, signer.pubkey()).await; println!( - "\nStake balance: {} ORE", - amount_u64_to_string(proof.balance) + "\nStake: {} ORE\n Multiplier: {:12}x", + amount_u64_to_string(proof.balance), + calculate_multiplier(proof.balance, config.top_balance) ); // Calc cutoff time let cutoff_time = self.get_cutoff(proof, args.buffer_time).await; // Run drillx - let config = get_config(&self.rpc_client).await; let solution = Self::find_hash_par( proof, cutoff_time, args.threads, config.min_difficulty as u32, - ) - .await; + ).await; + + // Check if the solution is "default" (indicating it was skipped) + if solution.d == [0u8; 16] && solution.n == [0u8; 8] { + // Print a skip message and continue to the next loop iteration + println!("Skipped: got a default solution."); + continue; + } // Submit most difficult hash let mut compute_budget = 500_000; @@ -69,6 +79,7 @@ impl Miner { .await .ok(); } + } async fn find_hash_par( @@ -88,7 +99,11 @@ impl Miner { let mut memory = equix::SolverMemory::new(); move || { let timer = Instant::now(); + let time_now = SystemTime::now().duration_since(UNIX_EPOCH) + .expect("SystemTime before UNIX EPOCH") + .as_micros() as u64; let mut nonce = u64::MAX.saturating_div(threads).saturating_mul(i); + nonce = time_now ^ nonce; let mut best_nonce = nonce; let mut best_difficulty = 0; let mut best_hash = Hash::default(); @@ -110,7 +125,7 @@ impl Miner { // Exit if time has elapsed if nonce % 100 == 0 { if timer.elapsed().as_secs().ge(&cutoff_time) { - if best_difficulty.gt(&min_difficulty) { + if best_difficulty.ge(&min_difficulty) { // Mine until min difficulty has been met break; } @@ -147,6 +162,12 @@ impl Miner { } } + // Check if the best difficulty meets the minimum requirement + if best_difficulty < MIN_DIFFICULTY { + progress_bar.finish_with_message(format!("Skipped: (difficulty: {} < {})", best_difficulty, MIN_DIFFICULTY)); + return Solution::new([0u8; 16], [0u8; 8]); // Return a "default" Solution + } + // Update log progress_bar.finish_with_message(format!( "Best hash: {} (difficulty: {})", @@ -190,8 +211,12 @@ impl Miner { } } +fn calculate_multiplier(balance: u64, top_balance: u64) -> f64 { + 1.0 + (balance as f64 / top_balance as f64).min(1.0f64) +} + // TODO Pick a better strategy (avoid draining bus) fn find_bus() -> Pubkey { let i = rand::thread_rng().gen_range(0..BUS_COUNT); BUS_ADDRESSES[i] -} +} \ No newline at end of file diff --git a/src/send_and_confirm.rs b/src/send_and_confirm.rs index b18eb3e8..6d0a3e84 100644 --- a/src/send_and_confirm.rs +++ b/src/send_and_confirm.rs @@ -94,7 +94,7 @@ impl Miner { // Submit tx let mut attempts = 0; loop { - progress_bar.set_message(format!("Submitting transaction... (attempt {})", attempts)); + progress_bar.set_message(format!("Submitting transaction... (attempt {}, max {})", attempts, GATEWAY_RETRIES)); match client.send_transaction_with_config(&tx, send_cfg).await { Ok(sig) => { // Skip confirmation