diff --git a/src/app/mod.rs b/src/app/mod.rs index 697e538..645cf1b 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -527,13 +527,7 @@ impl App { // Set saved Hero mode to runtime. debug!("Setting runtime_mode & runtime_manual_amount"); app.xvb_api.lock().unwrap().stats_priv.runtime_mode = app.state.xvb.mode.clone().into(); - app.xvb_api.lock().unwrap().stats_priv.runtime_manual_amount = match app.state.xvb.amount.parse::() { - Ok(n) => n, - Err(_) => { - error!("Cannot parse [amount] to u64, defaulting to 1"); - 1 - } - }; + app.xvb_api.lock().unwrap().stats_priv.runtime_manual_amount = app.state.xvb.amount.parse().unwrap(); // Check if [P2pool.node] exists info!("App Init | Checking if saved remote node still exists..."); diff --git a/src/helper/xvb/algorithm.rs b/src/helper/xvb/algorithm.rs index 50b54ab..ea28a8e 100644 --- a/src/helper/xvb/algorithm.rs +++ b/src/helper/xvb/algorithm.rs @@ -1,9 +1,10 @@ use std::{ - mem::ManuallyDrop, sync::{Arc, Mutex}, thread::current, time::Duration + sync::{Arc, Mutex}, + time::Duration, }; use log::{debug, info, warn}; -use readable::{num::Float, run::Runtime}; +use readable::num::Float; use reqwest::Client; use tokio::time::sleep; @@ -11,10 +12,13 @@ use crate::{ helper::{ p2pool::PubP2poolApi, xmrig::{PrivXmrigApi, PubXmrigApi}, - xvb::{nodes::XvbNode, output_console, output_console_without_time}, - }, macros::lock, BLOCK_PPLNS_WINDOW_MAIN, BLOCK_PPLNS_WINDOW_MINI, SECOND_PER_BLOCK_P2POOL, XMRIG_CONFIG_URI, XVB_BUFFER, XVB_MINING_ON_FIELD, XVB_ROUND_DONOR_MEGA_MIN_HR, XVB_ROUND_DONOR_MIN_HR, XVB_ROUND_DONOR_VIP_MIN_HR, XVB_ROUND_DONOR_WHALE_MIN_HR, XVB_TIME_ALGO + xvb::{nodes::XvbNode, output_console, output_console_without_time, priv_stats::RuntimeMode}, + }, + macros::lock, + BLOCK_PPLNS_WINDOW_MAIN, BLOCK_PPLNS_WINDOW_MINI, SECOND_PER_BLOCK_P2POOL, XMRIG_CONFIG_URI, + XVB_BUFFER, XVB_ROUND_DONOR_MEGA_MIN_HR, XVB_ROUND_DONOR_MIN_HR, XVB_ROUND_DONOR_VIP_MIN_HR, + XVB_ROUND_DONOR_WHALE_MIN_HR, XVB_TIME_ALGO, }; -use crate::helper::xvb::priv_stats::RuntimeMode; use super::{PubXvbApi, SamplesAverageHour}; @@ -60,39 +64,46 @@ pub(crate) fn calcul_donated_time( output_console(gui_api_xvb, &msg_mhr); output_console(gui_api_xvb, &msg_ehr); // calculate how much time can be spared - - let current_mode = &lock!(gui_api_xvb).stats_priv.runtime_mode; - let spared_time = match *current_mode { + + let mode = lock!(gui_api_xvb).stats_priv.runtime_mode.clone(); + + let default_spared_time = time_that_could_be_spared(lhr, min_hr); + let spared_time = match mode { RuntimeMode::Auto => { info!("RuntimeMode::Auto - calculating spared_time"); - let mut spared_time = time_that_could_be_spared(lhr, min_hr); let xvb_chr = lock!(gui_api_xvb).stats_priv.donor_1hr_avg * 1000.0; info!("current HR on XvB (last hour): {xvb_chr}"); let shr = calc_last_hour_avg_hash_rate(&lock!(gui_api_xvb).xvb_sent_last_hour_samples); // calculate how much time needed to be spared to be in most round type minimum HR + buffer - spared_time = minimum_time_for_highest_accessible_round(spared_time, lhr, xvb_chr, shr); - spared_time + minimum_time_for_highest_accessible_round(default_spared_time, lhr, xvb_chr, shr) }, RuntimeMode::Hero => { - info!("RuntimeMode::Hero - calculating spared_time"); - time_that_could_be_spared(lhr, min_hr) + info!("RuntimeMode::Hero - calculating spared_time lhr:{lhr} min_hr:{min_hr}"); + output_console(gui_api_xvb, "Hero mode is enabled for this decision"); + default_spared_time }, RuntimeMode::ManuallyDonante => { - info!("RuntimeMode::ManuallyDonate - calculating spared_time"); - let manual_amount = lock!(gui_api_xvb).stats_priv.runtime_manual_amount as u32; - let spared_time = XVB_TIME_ALGO * manual_amount / (avg_hr as u32); - info!("spared_time = {XVB_TIME_ALGO} * {manual_amount} / {avg_hr} = {spared_time}"); - spared_time + let donate_hr = lock!(gui_api_xvb).stats_priv.runtime_manual_amount; + info!("RuntimeMode::ManuallyDonate - lhr:{lhr} donate_hr:{donate_hr}"); + if lhr < 1.0 { + default_spared_time + } else { + XVB_TIME_ALGO * (donate_hr as u32) / (lhr as u32) + } }, RuntimeMode::ManuallyKeep => { - info!("RuntimeMode::ManuallyKeep - calculating spared_time"); - let manual_amount = lock!(gui_api_xvb).stats_priv.runtime_manual_amount as u32; - let spared_time = XVB_TIME_ALGO - (XVB_TIME_ALGO * manual_amount / (avg_hr as u32)); - info!("spared_time = {XVB_TIME_ALGO} * {manual_amount} / {avg_hr} = {spared_time}"); - spared_time + let keep_hr = lock!(gui_api_xvb).stats_priv.runtime_manual_amount; + info!("RuntimeMode::ManuallyDonate - lhr:{lhr} keep_hr:{keep_hr}"); + if lhr < 1.0 { + default_spared_time + } else { + XVB_TIME_ALGO - (XVB_TIME_ALGO * (keep_hr as u32) / (lhr as u32)) + } } }; - + + info!("Final spared_time is {spared_time}"); + spared_time } fn minimum_hashrate_share(difficulty: u64, mini: bool, ohr: f32) -> f32 { diff --git a/src/helper/xvb/mod.rs b/src/helper/xvb/mod.rs index a4db001..782dd79 100644 --- a/src/helper/xvb/mod.rs +++ b/src/helper/xvb/mod.rs @@ -401,11 +401,14 @@ impl PubXvbApi { output.push_str(&buf); } let runtime_mode = std::mem::take(&mut gui_api.stats_priv.runtime_mode); + let runtime_manual_amount = std::mem::take(&mut gui_api.stats_priv.runtime_manual_amount); + *gui_api = Self { output, stats_priv: XvbPrivStats { runtime_mode, + runtime_manual_amount, ..pub_api.stats_priv.clone() }, p2pool_sent_last_hour_samples: std::mem::take( @@ -696,6 +699,7 @@ fn signal_interrupt( fn reset_data_xvb(pub_api: &Arc>, gui_api: &Arc>) { let current_node = mem::take(&mut lock!(pub_api).current_node.clone()); let runtime_mode = mem::take(&mut lock!(gui_api).stats_priv.runtime_mode); + let runtime_manual_amount = mem::take(&mut lock!(gui_api).stats_priv.runtime_manual_amount); // let output = mem::take(&mut lock!(gui_api).output); *lock!(pub_api) = PubXvbApi::new(); @@ -704,6 +708,7 @@ fn reset_data_xvb(pub_api: &Arc>, gui_api: &Arc