feat: improve logs & fix xvb_24h_avg not working

- Move algorithm logs to info level
- Add new logs
- get xvb_24h_avg from pub_api instead of gui_api
This commit is contained in:
mostafaei2002 2024-07-21 16:36:25 +03:30
parent 53edeff791
commit 1617882f29
3 changed files with 60 additions and 40 deletions

1
.gitignore vendored
View file

@ -2,3 +2,4 @@
/feature /feature
.DS_Store .DS_Store
rustc-ice-* rustc-ice-*
.vscode/

View file

@ -8,7 +8,7 @@ use std::{
time::Duration, time::Duration,
}; };
use log::{debug, info, warn}; use log::{info, warn};
use reqwest::Client; use reqwest::Client;
use tokio::time::sleep; use tokio::time::sleep;
@ -32,6 +32,7 @@ use super::{priv_stats::RuntimeDonationLevel, PubXvbApi, SamplesAverageHour};
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
pub(crate) async fn algorithm( pub(crate) async fn algorithm(
client: &Client, client: &Client,
pub_api: &Arc<Mutex<PubXvbApi>>,
gui_api_xvb: &Arc<Mutex<PubXvbApi>>, gui_api_xvb: &Arc<Mutex<PubXvbApi>>,
gui_api_xmrig: &Arc<Mutex<PubXmrigApi>>, gui_api_xmrig: &Arc<Mutex<PubXmrigApi>>,
gui_api_xp: &Arc<Mutex<PubXmrigProxyApi>>, gui_api_xp: &Arc<Mutex<PubXmrigProxyApi>>,
@ -45,6 +46,7 @@ pub(crate) async fn algorithm(
) { ) {
let mut algorithm = Algorithm::new( let mut algorithm = Algorithm::new(
client, client,
pub_api,
gui_api_xvb, gui_api_xvb,
gui_api_xmrig, gui_api_xmrig,
gui_api_xp, gui_api_xp,
@ -61,6 +63,7 @@ pub(crate) async fn algorithm(
struct Algorithm<'a> { struct Algorithm<'a> {
client: &'a Client, client: &'a Client,
pub_api: &'a Arc<Mutex<PubXvbApi>>,
gui_api_xvb: &'a Arc<Mutex<PubXvbApi>>, gui_api_xvb: &'a Arc<Mutex<PubXvbApi>>,
gui_api_xmrig: &'a Arc<Mutex<PubXmrigApi>>, gui_api_xmrig: &'a Arc<Mutex<PubXmrigApi>>,
gui_api_xp: &'a Arc<Mutex<PubXmrigProxyApi>>, gui_api_xp: &'a Arc<Mutex<PubXmrigProxyApi>>,
@ -97,6 +100,7 @@ struct Stats {
impl<'a> Algorithm<'a> { impl<'a> Algorithm<'a> {
fn new( fn new(
client: &'a Client, client: &'a Client,
pub_api: &'a Arc<Mutex<PubXvbApi>>,
gui_api_xvb: &'a Arc<Mutex<PubXvbApi>>, gui_api_xvb: &'a Arc<Mutex<PubXvbApi>>,
gui_api_xmrig: &'a Arc<Mutex<PubXmrigApi>>, gui_api_xmrig: &'a Arc<Mutex<PubXmrigApi>>,
gui_api_xp: &'a Arc<Mutex<PubXmrigProxyApi>>, gui_api_xp: &'a Arc<Mutex<PubXmrigProxyApi>>,
@ -112,9 +116,6 @@ impl<'a> Algorithm<'a> {
let address = state_p2pool.address.clone(); let address = state_p2pool.address.clone();
let xvb_24h_avg = lock!(gui_api_xvb).stats_priv.donor_24hr_avg * 1000.0;
let xvb_1h_avg = lock!(gui_api_xvb).stats_priv.donor_1hr_avg * 1000.0;
let runtime_mode = lock!(gui_api_xvb).stats_priv.runtime_mode.clone(); let runtime_mode = lock!(gui_api_xvb).stats_priv.runtime_mode.clone();
let runtime_donation_level = lock!(gui_api_xvb) let runtime_donation_level = lock!(gui_api_xvb)
.stats_priv .stats_priv
@ -144,6 +145,9 @@ impl<'a> Algorithm<'a> {
let msg_xmrig_or_xp = (if xp_alive { "XMRig-Proxy" } else { "XMRig" }).to_string(); let msg_xmrig_or_xp = (if xp_alive { "XMRig-Proxy" } else { "XMRig" }).to_string();
info!("xp alive: {:?}", xp_alive); info!("xp alive: {:?}", xp_alive);
let xvb_24h_avg = lock!(pub_api).stats_priv.donor_24hr_avg * 1000.0;
let xvb_1h_avg = lock!(pub_api).stats_priv.donor_1hr_avg * 1000.0;
// TODO consider printing algorithm stats instead of spreadout print statements // TODO consider printing algorithm stats instead of spreadout print statements
let stats = Stats { let stats = Stats {
share, share,
@ -167,6 +171,7 @@ impl<'a> Algorithm<'a> {
let mut new_instace = Self { let mut new_instace = Self {
client, client,
pub_api,
gui_api_xvb, gui_api_xvb,
gui_api_xmrig, gui_api_xmrig,
gui_api_xp, gui_api_xp,
@ -190,21 +195,40 @@ impl<'a> Algorithm<'a> {
} }
fn is_share_fulfilled(&self) -> bool { fn is_share_fulfilled(&self) -> bool {
self.stats.share > 0 let is_criteria_fulfilled = self.stats.share > 0;
info!(
"Algorithm | shares({}) > 0 : {}",
self.stats.share, is_criteria_fulfilled,
);
is_criteria_fulfilled
} }
fn is_xvb_24h_fulfilled(&self) -> bool { fn is_xvb_24h_fulfilled(&self) -> bool {
self.stats.xvb_24h_avg > self.stats.target_donation_hashrate let is_criteria_fulfilled = self.stats.xvb_24h_avg > self.stats.target_donation_hashrate;
info!(
"Algorithm | xvb_24h_avg({}) > target_donation_hashrate({}) : {}",
self.stats.xvb_24h_avg, self.stats.target_donation_hashrate, is_criteria_fulfilled
);
is_criteria_fulfilled
} }
fn xvb_1h_fulfilled(&self) -> bool { fn xvb_1h_fulfilled(&self) -> bool {
self.stats.xvb_1h_avg > self.stats.target_donation_hashrate let is_criteria_fulfilled = self.stats.xvb_1h_avg > self.stats.target_donation_hashrate;
info!(
"Algorithm | xvb_1h_avg({}) > target_donation_hashrate({}) : {}",
self.stats.xvb_1h_avg, self.stats.target_donation_hashrate, is_criteria_fulfilled
);
is_criteria_fulfilled
} }
async fn target_p2pool_node(&self) { async fn target_p2pool_node(&self) {
if lock!(self.gui_api_xvb).current_node != Some(XvbNode::P2pool) { if lock!(self.gui_api_xvb).current_node != Some(XvbNode::P2pool) {
info!( info!(
"Xvb Process | request {} to mine on p2pool", "Algorithm | request {} to mine on p2pool",
self.stats.msg_xmrig_or_xp self.stats.msg_xmrig_or_xp
); );
@ -219,7 +243,7 @@ impl<'a> Algorithm<'a> {
.await .await
{ {
warn!( warn!(
"Xvb Process | Failed request HTTP API {}", "Algorithm | Failed request HTTP API {}",
self.stats.msg_xmrig_or_xp self.stats.msg_xmrig_or_xp
); );
output_console( output_console(
@ -231,8 +255,8 @@ impl<'a> Algorithm<'a> {
crate::helper::ProcessName::Xvb, crate::helper::ProcessName::Xvb,
); );
} else { } else {
debug!( info!(
"Xvb Process | {} mining on p2pool pool", "Algorithm | {} mining on p2pool pool",
self.stats.msg_xmrig_or_xp self.stats.msg_xmrig_or_xp
); );
} }
@ -242,8 +266,8 @@ impl<'a> Algorithm<'a> {
async fn target_xvb_node(&self) { async fn target_xvb_node(&self) {
let node = lock!(self.gui_api_xvb).stats_priv.node; let node = lock!(self.gui_api_xvb).stats_priv.node;
debug!( info!(
"Xvb Process | request {} to mine on XvB", "Algorithm | request {} to mine on XvB",
self.stats.msg_xmrig_or_xp self.stats.msg_xmrig_or_xp
); );
@ -265,7 +289,7 @@ impl<'a> Algorithm<'a> {
{ {
// show to console error about updating xmrig config // show to console error about updating xmrig config
warn!( warn!(
"Xvb Process | Failed request HTTP API {}", "Algorithm | Failed request HTTP API {}",
self.stats.msg_xmrig_or_xp self.stats.msg_xmrig_or_xp
); );
output_console( output_console(
@ -282,8 +306,8 @@ impl<'a> Algorithm<'a> {
} else { } else {
lock!(self.gui_api_xmrig).node = node.to_string(); lock!(self.gui_api_xmrig).node = node.to_string();
} }
debug!( info!(
"Xvb Process | {} mining on XvB pool", "Algorithm | {} mining on XvB pool",
self.stats.msg_xmrig_or_xp self.stats.msg_xmrig_or_xp
); );
} }
@ -293,7 +317,7 @@ impl<'a> Algorithm<'a> {
async fn send_all_p2pool(&self) { async fn send_all_p2pool(&self) {
self.target_p2pool_node().await; self.target_p2pool_node().await;
debug!( info!(
"Algorithm | algo sleep for {} while mining on P2pool", "Algorithm | algo sleep for {} while mining on P2pool",
XVB_TIME_ALGO XVB_TIME_ALGO
); );
@ -312,7 +336,7 @@ impl<'a> Algorithm<'a> {
async fn send_all_xvb(&self) { async fn send_all_xvb(&self) {
self.target_xvb_node().await; self.target_xvb_node().await;
debug!( info!(
"Algorithm | algo sleep for {} while mining on XvB", "Algorithm | algo sleep for {} while mining on XvB",
XVB_TIME_ALGO XVB_TIME_ALGO
); );
@ -329,7 +353,7 @@ impl<'a> Algorithm<'a> {
} }
async fn sleep_then_update_node_xmrig(&self) { async fn sleep_then_update_node_xmrig(&self) {
debug!( info!(
"Algorithm | algo sleep for {} while mining on P2pool", "Algorithm | algo sleep for {} while mining on P2pool",
XVB_TIME_ALGO - self.stats.spared_time XVB_TIME_ALGO - self.stats.spared_time
); );
@ -339,14 +363,14 @@ impl<'a> Algorithm<'a> {
.await; .await;
// only update xmrig config if it is actually mining. // only update xmrig config if it is actually mining.
debug!("Algorithm | request xmrig to mine on XvB"); info!("Algorithm | request xmrig to mine on XvB");
self.target_xvb_node().await; self.target_xvb_node().await;
// will not quit the process until it is really done. // will not quit the process until it is really done.
// xvb process watch this algo handle to see if process is finished or not. // xvb process watch this algo handle to see if process is finished or not.
debug!( info!(
"Algorithm | algo sleep for {} while mining on P2pool", "Algorithm | algo sleep for {} while mining on P2pool",
self.stats.spared_time self.stats.spared_time
); );
@ -373,7 +397,7 @@ impl<'a> Algorithm<'a> {
RuntimeMode::Auto => self.get_auto_mode_target_donation_hashrate(), RuntimeMode::Auto => self.get_auto_mode_target_donation_hashrate(),
RuntimeMode::Hero => self.get_hero_mode_target_donation_hashrate(), RuntimeMode::Hero => self.get_hero_mode_target_donation_hashrate(),
RuntimeMode::ManualXvb => { RuntimeMode::ManualXvb => {
debug!( info!(
"Algorithm | ManualXvBMode target_donation_hashrate=runtime_amount({})", "Algorithm | ManualXvBMode target_donation_hashrate=runtime_amount({})",
self.stats.runtime_amount self.stats.runtime_amount
); );
@ -384,7 +408,7 @@ impl<'a> Algorithm<'a> {
let target_donation_hashrate = let target_donation_hashrate =
(XVB_TIME_ALGO as f32) - (self.stats.runtime_amount as f32); (XVB_TIME_ALGO as f32) - (self.stats.runtime_amount as f32);
debug!("Algorithm | ManualP2poolMode target_donation_hashrate({})=hashrate_xmrig({})-runtime_amount({})", info!("Algorithm | ManualP2poolMode target_donation_hashrate({})=hashrate_xmrig({})-runtime_amount({})",
target_donation_hashrate, target_donation_hashrate,
self.stats.hashrate_xmrig, self.stats.hashrate_xmrig,
self.stats.runtime_amount); self.stats.runtime_amount);
@ -394,7 +418,7 @@ impl<'a> Algorithm<'a> {
RuntimeMode::ManualDonationLevel => { RuntimeMode::ManualDonationLevel => {
let target_donation_hashrate = self.stats.runtime_donation_level.get_hashrate(); let target_donation_hashrate = self.stats.runtime_donation_level.get_hashrate();
debug!("Algorithm | ManualDonationLevelMode target_donation_hashrate({})={:#?}.get_hashrate()", info!("Algorithm | ManualDonationLevelMode target_donation_hashrate({})={:#?}.get_hashrate()",
target_donation_hashrate, target_donation_hashrate,
self.stats.runtime_donation_level); self.stats.runtime_donation_level);
@ -420,7 +444,7 @@ impl<'a> Algorithm<'a> {
_ => None, _ => None,
}; };
debug!( info!(
"Algorithm | AutoMode target_donation_level detected ({:#?})", "Algorithm | AutoMode target_donation_level detected ({:#?})",
donation_level donation_level
); );
@ -431,7 +455,7 @@ impl<'a> Algorithm<'a> {
0.0 0.0
}; };
debug!( info!(
"Algorithm | AutoMode target_donation_hashrate ({})", "Algorithm | AutoMode target_donation_hashrate ({})",
target_donation_hashrate target_donation_hashrate
); );
@ -444,7 +468,7 @@ impl<'a> Algorithm<'a> {
// TODO consider using a large buffer size // TODO consider using a large buffer size
// TODO consider manually setting the share count to aim for on hero mode // TODO consider manually setting the share count to aim for on hero mode
debug!( info!(
"Algorithm | HeroMode target_donation_hashrate=spareable_hashrate({})", "Algorithm | HeroMode target_donation_hashrate=spareable_hashrate({})",
self.stats.spareable_hashrate self.stats.spareable_hashrate
); );
@ -468,7 +492,7 @@ impl<'a> Algorithm<'a> {
info!("Algorithm | (difficulty / (window pplns blocks * seconds per p2pool block) * BUFFER) - outside HR = minimum HR to keep a share\n({difficulty} / ({pws} * {SECOND_PER_BLOCK_P2POOL}) * {XVB_BUFFER}) - {p2pool_external_hashrate} = {minimum_hr}"); info!("Algorithm | (difficulty / (window pplns blocks * seconds per p2pool block) * BUFFER) - outside HR = minimum HR to keep a share\n({difficulty} / ({pws} * {SECOND_PER_BLOCK_P2POOL}) * {XVB_BUFFER}) - {p2pool_external_hashrate} = {minimum_hr}");
if minimum_hr.is_sign_negative() { if minimum_hr.is_sign_negative() {
debug!("Algorithm| if minimum HR is negative, it is 0."); info!("Algorithm| if minimum HR is negative, it is 0.");
minimum_hr = 0.0; minimum_hr = 0.0;
} }
@ -482,7 +506,7 @@ impl<'a> Algorithm<'a> {
crate::helper::ProcessName::Xvb, crate::helper::ProcessName::Xvb,
); );
debug!("Algorithm | There are no shares in p2pool. Sending all hashrate to p2pool!"); info!("Algorithm | There are no shares in p2pool. Sending all hashrate to p2pool!");
self.send_all_p2pool().await self.send_all_p2pool().await
} }
@ -494,7 +518,7 @@ impl<'a> Algorithm<'a> {
crate::helper::ProcessName::Xvb, crate::helper::ProcessName::Xvb,
); );
debug!("Algorithm | 24H avg XvB target not achieved. Sending all hashrate to XvB!"); info!("Algorithm | 24H avg XvB target not achieved. Sending all hashrate to XvB!");
*lock!(self.time_donated) = XVB_TIME_ALGO; *lock!(self.time_donated) = XVB_TIME_ALGO;
@ -508,7 +532,7 @@ impl<'a> Algorithm<'a> {
crate::helper::ProcessName::Xvb, crate::helper::ProcessName::Xvb,
); );
debug!("Algorithm | There is a share in p2pool and 24H avg XvB is achieved. Sending {} to XvB!", self.stats.spared_time); info!("Algorithm | There is a share in p2pool and 24H avg XvB is achieved. Sending {} to XvB!", self.stats.spared_time);
*lock!(self.time_donated) = self.stats.spared_time; *lock!(self.time_donated) = self.stats.spared_time;
@ -523,7 +547,8 @@ impl<'a> Algorithm<'a> {
crate::helper::ProcessName::Xvb, crate::helper::ProcessName::Xvb,
); );
debug!("Algorithm | {:#?}", self.stats); info!("Algorithm | Starting...");
info!("Algorithm | {:#?}", self.stats);
if !self.is_share_fulfilled() { if !self.is_share_fulfilled() {
self.fulfill_share().await self.fulfill_share().await
@ -543,7 +568,7 @@ impl<'a> Algorithm<'a> {
fn get_spared_time(target_donation_hashrate: f32, hashrate_xmrig: f32) -> u32 { fn get_spared_time(target_donation_hashrate: f32, hashrate_xmrig: f32) -> u32 {
let spared_time = target_donation_hashrate / hashrate_xmrig * (XVB_TIME_ALGO as f32); let spared_time = target_donation_hashrate / hashrate_xmrig * (XVB_TIME_ALGO as f32);
debug!("Algorithm | Calculating... spared_time({})=target_donation_hashrate({})/hashrate_xmrig({})*XVB_TIME_ALGO({})", info!("Algorithm | Calculating... spared_time({})=target_donation_hashrate({})/hashrate_xmrig({})*XVB_TIME_ALGO({})",
spared_time, spared_time,
target_donation_hashrate, target_donation_hashrate,
hashrate_xmrig, hashrate_xmrig,

View file

@ -328,6 +328,7 @@ impl Helper {
}; };
algorithm( algorithm(
&client, &client,
&pub_api,
&gui_api, &gui_api,
&gui_api_xmrig, &gui_api_xmrig,
&gui_api_xp, &gui_api_xp,
@ -828,13 +829,6 @@ fn update_indicator_algo(
// algo is mining on p2pool but will switch to XvB after // algo is mining on p2pool but will switch to XvB after
// show time remaining on p2pool // show time remaining on p2pool
debug!(
"Crash | XVB_TIME_ALGO({})-last_algorithm({})-time_donated({})",
XVB_TIME_ALGO,
last_algorithm.lock().unwrap().elapsed().as_secs() as u32,
time_donated
);
lock!(pub_api).stats_priv.time_switch_node = XVB_TIME_ALGO lock!(pub_api).stats_priv.time_switch_node = XVB_TIME_ALGO
.checked_sub(last_algorithm.lock().unwrap().elapsed().as_secs() as u32) .checked_sub(last_algorithm.lock().unwrap().elapsed().as_secs() as u32)
.unwrap_or_default() .unwrap_or_default()