mirror of
https://github.com/Cyrix126/gupaxx.git
synced 2024-11-16 15:27:46 +00:00
feat: add debug logs & other minor changes
This commit is contained in:
parent
004c380761
commit
709de3385f
2 changed files with 112 additions and 28 deletions
|
@ -1,7 +1,6 @@
|
|||
use crate::helper::xrig::xmrig_proxy::PubXmrigProxyApi;
|
||||
use crate::helper::xvb::api_url_xmrig;
|
||||
use crate::helper::xvb::current_controllable_hr;
|
||||
use crate::helper::ProcessName;
|
||||
use crate::miscs::output_console;
|
||||
use crate::miscs::output_console_without_time;
|
||||
use std::{
|
||||
|
@ -108,8 +107,6 @@ impl<'a> Algorithm<'a> {
|
|||
rig: &'a str,
|
||||
xp_alive: bool,
|
||||
) -> Self {
|
||||
info!("XvB Process | Starting Algorithm - Algorithm State:",);
|
||||
|
||||
let hashrate_xmrig = current_controllable_hr(xp_alive, gui_api_xp, gui_api_xmrig);
|
||||
|
||||
let address = state_p2pool.address.clone();
|
||||
|
@ -122,7 +119,7 @@ impl<'a> Algorithm<'a> {
|
|||
.stats_priv
|
||||
.runtime_manual_donation_level
|
||||
.clone();
|
||||
let runtime_amount = lock!(gui_api_xvb).stats_priv.runtime_manual_amount.clone();
|
||||
let runtime_amount = lock!(gui_api_xvb).stats_priv.runtime_manual_amount;
|
||||
|
||||
let p2pool_total_hashrate = lock!(gui_api_p2pool).sidechain_ehr;
|
||||
|
||||
|
@ -138,10 +135,6 @@ impl<'a> Algorithm<'a> {
|
|||
state_p2pool.mini,
|
||||
p2pool_external_hashrate,
|
||||
);
|
||||
if share_min_hashrate.is_sign_negative() {
|
||||
info!("XvB Process | if minimum HR is negative, it is 0.");
|
||||
share_min_hashrate = 0.0;
|
||||
}
|
||||
|
||||
let spareable_hashrate = hashrate_xmrig - share_min_hashrate;
|
||||
|
||||
|
@ -182,11 +175,11 @@ impl<'a> Algorithm<'a> {
|
|||
};
|
||||
|
||||
new_instace.stats.target_donation_hashrate = new_instace.get_target_donation_hashrate();
|
||||
new_instace.stats.spared_time = ((new_instace.stats.target_donation_hashrate as u32)
|
||||
/ (new_instace.stats.hashrate_xmrig as u32))
|
||||
* XVB_TIME_ALGO;
|
||||
|
||||
info!("{:#?}", new_instace.stats);
|
||||
new_instace.stats.spared_time = Self::get_spared_time(
|
||||
new_instace.stats.target_donation_hashrate,
|
||||
new_instace.stats.hashrate_xmrig,
|
||||
);
|
||||
|
||||
new_instace
|
||||
}
|
||||
|
@ -288,6 +281,10 @@ impl<'a> Algorithm<'a> {
|
|||
async fn send_all_p2pool(&self) {
|
||||
self.target_p2pool_node().await;
|
||||
|
||||
debug!(
|
||||
"Algorithm | algo sleep for {} while mining on P2pool",
|
||||
XVB_TIME_ALGO
|
||||
);
|
||||
sleep(Duration::from_secs(XVB_TIME_ALGO.into())).await;
|
||||
|
||||
lock!(self.gui_api_xvb)
|
||||
|
@ -303,6 +300,10 @@ impl<'a> Algorithm<'a> {
|
|||
async fn send_all_xvb(&self) {
|
||||
self.target_xvb_node().await;
|
||||
|
||||
debug!(
|
||||
"Algorithm | algo sleep for {} while mining on XvB",
|
||||
XVB_TIME_ALGO
|
||||
);
|
||||
sleep(Duration::from_secs(XVB_TIME_ALGO.into())).await;
|
||||
|
||||
lock!(self.gui_api_xvb)
|
||||
|
@ -317,7 +318,7 @@ impl<'a> Algorithm<'a> {
|
|||
|
||||
async fn sleep_then_update_node_xmrig(&self) {
|
||||
debug!(
|
||||
"Xvb Process | algo sleep for {} while mining on P2pool",
|
||||
"Algorithm | algo sleep for {} while mining on P2pool",
|
||||
XVB_TIME_ALGO - self.stats.spared_time
|
||||
);
|
||||
sleep(Duration::from_secs(
|
||||
|
@ -326,12 +327,17 @@ impl<'a> Algorithm<'a> {
|
|||
.await;
|
||||
|
||||
// only update xmrig config if it is actually mining.
|
||||
debug!("Xvb Process | request xmrig to mine on XvB");
|
||||
debug!("Algorithm | request xmrig to mine on XvB");
|
||||
|
||||
self.target_xvb_node().await;
|
||||
|
||||
// will not quit the process until it is really done.
|
||||
// xvb process watch this algo handle to see if process is finished or not.
|
||||
|
||||
debug!(
|
||||
"Algorithm | algo sleep for {} while mining on P2pool",
|
||||
self.stats.spared_time
|
||||
);
|
||||
sleep(Duration::from_secs(self.stats.spared_time.into())).await;
|
||||
|
||||
lock!(self.gui_api_xvb)
|
||||
|
@ -351,15 +357,40 @@ impl<'a> Algorithm<'a> {
|
|||
}
|
||||
|
||||
fn get_target_donation_hashrate(&self) -> f32 {
|
||||
match self.stats.runtime_mode {
|
||||
let target_donation_hashrate = match self.stats.runtime_mode {
|
||||
RuntimeMode::Auto => self.get_auto_mode_target_donation_hashrate(),
|
||||
RuntimeMode::Hero => self.get_hero_mode_target_donation_hashrate(),
|
||||
RuntimeMode::ManualXvb => self.stats.runtime_amount as f32,
|
||||
RuntimeMode::ManualP2pool => {
|
||||
(XVB_TIME_ALGO as f32) - (self.stats.runtime_amount as f32)
|
||||
RuntimeMode::ManualXvb => {
|
||||
debug!(
|
||||
"Algorithm | ManualXvBMode target_donation_hashrate=runtime_amount({})",
|
||||
self.stats.runtime_amount
|
||||
);
|
||||
|
||||
self.stats.runtime_amount as f32
|
||||
}
|
||||
RuntimeMode::ManualDonationLevel => self.stats.runtime_donation_level.get_hashrate(),
|
||||
}
|
||||
RuntimeMode::ManualP2pool => {
|
||||
let target_donation_hashrate =
|
||||
(XVB_TIME_ALGO as f32) - (self.stats.runtime_amount as f32);
|
||||
|
||||
debug!("Algorithm | ManualP2poolMode target_donation_hashrate({})=hashrate_xmrig({})-runtime_amount({})",
|
||||
target_donation_hashrate,
|
||||
self.stats.hashrate_xmrig,
|
||||
self.stats.runtime_amount);
|
||||
|
||||
target_donation_hashrate
|
||||
}
|
||||
RuntimeMode::ManualDonationLevel => {
|
||||
let target_donation_hashrate = self.stats.runtime_donation_level.get_hashrate();
|
||||
|
||||
debug!("Algorithm | ManualDonationLevelMode target_donation_hashrate({})={:#?}.get_hashrate()",
|
||||
target_donation_hashrate,
|
||||
self.stats.runtime_donation_level);
|
||||
|
||||
target_donation_hashrate
|
||||
}
|
||||
};
|
||||
|
||||
target_donation_hashrate
|
||||
}
|
||||
|
||||
fn get_auto_mode_target_donation_hashrate(&self) -> f32 {
|
||||
|
@ -377,11 +408,23 @@ impl<'a> Algorithm<'a> {
|
|||
_ => None,
|
||||
};
|
||||
|
||||
if let Some(level) = donation_level {
|
||||
debug!(
|
||||
"Algorithm | AutoMode target_donation_level detected ({:#?})",
|
||||
donation_level
|
||||
);
|
||||
|
||||
let target_donation_hashrate = if let Some(level) = donation_level {
|
||||
level.get_hashrate()
|
||||
} else {
|
||||
0.0
|
||||
}
|
||||
};
|
||||
|
||||
debug!(
|
||||
"Algorithm | AutoMode target_donation_hashrate ({})",
|
||||
target_donation_hashrate
|
||||
);
|
||||
|
||||
target_donation_hashrate
|
||||
}
|
||||
|
||||
fn get_hero_mode_target_donation_hashrate(&self) -> f32 {
|
||||
|
@ -389,6 +432,11 @@ impl<'a> Algorithm<'a> {
|
|||
// TODO consider using a large buffer size
|
||||
// TODO consider manually setting the share count to aim for on hero mode
|
||||
|
||||
debug!(
|
||||
"Algorithm | HeroMode target_donation_hashrate=spareable_hashrate({})",
|
||||
self.stats.spareable_hashrate
|
||||
);
|
||||
|
||||
self.stats.spareable_hashrate
|
||||
}
|
||||
|
||||
|
@ -403,29 +451,39 @@ impl<'a> Algorithm<'a> {
|
|||
} else {
|
||||
BLOCK_PPLNS_WINDOW_MAIN
|
||||
};
|
||||
let minimum_hr = ((difficulty / (pws * SECOND_PER_BLOCK_P2POOL)) as f32 * XVB_BUFFER)
|
||||
let mut minimum_hr = ((difficulty / (pws * SECOND_PER_BLOCK_P2POOL)) as f32 * XVB_BUFFER)
|
||||
- p2pool_external_hashrate;
|
||||
info!("XvB Process | (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() {
|
||||
debug!("Algorithm| if minimum HR is negative, it is 0.");
|
||||
minimum_hr = 0.0;
|
||||
}
|
||||
|
||||
minimum_hr
|
||||
}
|
||||
|
||||
async fn fulfill_share(&self) {
|
||||
output_console(
|
||||
&mut lock!(self.gui_api_xvb).output,
|
||||
"There are no shares in p2pool\nSending all hashrate to p2pool!",
|
||||
"There are no shares in p2pool. Sending all hashrate to p2pool!",
|
||||
crate::helper::ProcessName::Xvb,
|
||||
);
|
||||
|
||||
debug!("Algorithm | There are no shares in p2pool. Sending all hashrate to p2pool!");
|
||||
|
||||
self.send_all_p2pool().await
|
||||
}
|
||||
|
||||
async fn fulfill_xvb_24_avg(&self) {
|
||||
output_console(
|
||||
&mut lock!(self.gui_api_xvb).output,
|
||||
"24H avg XvB target not achieved.\nSending all hashrate to XvB!",
|
||||
"24H avg XvB target not achieved. Sending all hashrate to XvB!",
|
||||
crate::helper::ProcessName::Xvb,
|
||||
);
|
||||
|
||||
debug!("Algorithm | 24H avg XvB target not achieved. Sending all hashrate to XvB!");
|
||||
|
||||
*lock!(self.time_donated) = XVB_TIME_ALGO;
|
||||
|
||||
self.send_all_xvb().await
|
||||
|
@ -434,23 +492,27 @@ impl<'a> Algorithm<'a> {
|
|||
async fn fulfill_normal_cycles(&self) {
|
||||
output_console(
|
||||
&mut lock!(self.gui_api_xvb).output,
|
||||
"There is a share in p2pool and 24H avg XvB is achieved.\nSending {self.stats.spared_time} to XvB!",
|
||||
"There is a share in p2pool and 24H avg XvB is achieved. Sending {self.stats.spared_time} to 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);
|
||||
|
||||
*lock!(self.time_donated) = self.stats.spared_time;
|
||||
|
||||
self.target_p2pool_node().await;
|
||||
self.sleep_then_update_node_xmrig().await;
|
||||
}
|
||||
|
||||
async fn run(&mut self) {
|
||||
pub async fn run(&mut self) {
|
||||
output_console(
|
||||
&mut lock!(self.gui_api_xvb).output,
|
||||
"Algorithm of HR distribution started for the next 10 minutes.",
|
||||
crate::helper::ProcessName::Xvb,
|
||||
);
|
||||
|
||||
debug!("Algorithm | {:#?}", self.stats);
|
||||
|
||||
if !self.is_share_fulfilled() {
|
||||
self.fulfill_share().await
|
||||
} else if !self.is_xvb_24h_fulfilled() {
|
||||
|
@ -465,4 +527,18 @@ impl<'a> Algorithm<'a> {
|
|||
crate::helper::ProcessName::Xvb,
|
||||
)
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
debug!("Algorithm | Calculating... spared_time({})=target_donation_hashrate({})/hashrate_xmrig({})*XVB_TIME_ALGO({})",
|
||||
spared_time,
|
||||
target_donation_hashrate,
|
||||
hashrate_xmrig,
|
||||
XVB_TIME_ALGO);
|
||||
|
||||
spared_time as u32
|
||||
}
|
||||
}
|
||||
|
||||
// TODO fix XvB 24H avg and 1H avg not shwoing properly and add debug logs
|
||||
|
|
|
@ -827,6 +827,14 @@ fn update_indicator_algo(
|
|||
Some(XvbNode::P2pool) if time_donated > 0 => {
|
||||
// algo is mining on p2pool but will switch to XvB after
|
||||
// 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
|
||||
- last_algorithm.lock().unwrap().elapsed().as_secs() as u32
|
||||
- time_donated;
|
||||
|
|
Loading…
Reference in a new issue