mirror of
https://github.com/Cyrix126/gupaxx.git
synced 2024-12-22 22:59:27 +00:00
feat: add xvb modes
This commit is contained in:
parent
800e36345a
commit
101f4f6886
7 changed files with 104 additions and 21 deletions
7
Dockerfile
Normal file
7
Dockerfile
Normal file
|
@ -0,0 +1,7 @@
|
|||
FROM rust:latest
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY . .
|
||||
|
||||
RUN cargo build --release
|
|
@ -525,7 +525,14 @@ impl App {
|
|||
app.tab = app.state.gupax.tab;
|
||||
|
||||
// Set saved Hero mode to runtime.
|
||||
app.xvb_api.lock().unwrap().stats_priv.runtime_hero_mode = app.state.xvb.hero;
|
||||
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(_) => {
|
||||
warn!("Cannot parse [amount] to u64, defaulting to 0");
|
||||
0
|
||||
}
|
||||
};
|
||||
|
||||
// Check if [P2pool.node] exists
|
||||
info!("App Init | Checking if saved remote node still exists...");
|
||||
|
|
|
@ -6,11 +6,12 @@ use log::debug;
|
|||
use readable::num::Float;
|
||||
use readable::up::Uptime;
|
||||
|
||||
use crate::disk::state::XvbMode;
|
||||
use crate::helper::xvb::PubXvbApi;
|
||||
use crate::regex::num_lines;
|
||||
use crate::utils::constants::{
|
||||
GREEN, LIGHT_GRAY, ORANGE, RED, XVB_DONATED_1H_FIELD, XVB_DONATED_24H_FIELD, XVB_FAILURE_FIELD,
|
||||
XVB_HELP, XVB_HERO_SELECT, XVB_ROUND_TYPE_FIELD, XVB_TOKEN_FIELD, XVB_TOKEN_LEN, XVB_URL_RULES,
|
||||
XVB_HELP, XVB_ROUND_TYPE_FIELD, XVB_TOKEN_FIELD, XVB_TOKEN_LEN, XVB_URL_RULES,
|
||||
XVB_WINNER_FIELD,
|
||||
};
|
||||
use crate::utils::macros::lock;
|
||||
|
@ -114,10 +115,29 @@ impl crate::disk::state::Xvb {
|
|||
ui.style_mut().spacing.icon_width_inner = width / 45.0;
|
||||
ui.style_mut().spacing.icon_width = width / 35.0;
|
||||
ui.style_mut().spacing.icon_spacing = space_h;
|
||||
if ui.checkbox(&mut self.hero, "Hero Mode").on_hover_text(XVB_HERO_SELECT).clicked() {
|
||||
// also change hero mode of runtime.
|
||||
lock!(api).stats_priv.runtime_hero_mode = self.hero;
|
||||
}
|
||||
|
||||
egui::ComboBox::from_label("")
|
||||
.selected_text(format!("{:?}", self.mode))
|
||||
.show_ui(ui, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.selectable_value(&mut self.mode, XvbMode::Auto, "Automatic");
|
||||
ui.selectable_value(&mut self.mode, XvbMode::Hero, "Hero Mode");
|
||||
ui.selectable_value(&mut self.mode, XvbMode::ManuallyDonante, "Manually Donate");
|
||||
ui.selectable_value(&mut self.mode, XvbMode::ManuallyKeep, "Manually Keep");
|
||||
})
|
||||
});
|
||||
if self.mode == XvbMode::ManuallyDonante || self.mode == XvbMode::ManuallyKeep {
|
||||
ui.horizontal(|ui| {
|
||||
ui.add(
|
||||
TextEdit::singleline(&mut self.amount)
|
||||
)
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// need to warn the user if no address is set in p2pool tab
|
||||
if !Regexes::addr_ok(address) {
|
||||
|
|
|
@ -243,10 +243,19 @@ pub struct Xmrig {
|
|||
pub token: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Eq, PartialEq, Debug, Deserialize, Serialize)]
|
||||
pub enum XvbMode {
|
||||
Auto,
|
||||
ManuallyDonante,
|
||||
ManuallyKeep,
|
||||
Hero,
|
||||
}
|
||||
|
||||
#[derive(Clone, Eq, PartialEq, Debug, Deserialize, Serialize, Default)]
|
||||
pub struct Xvb {
|
||||
pub token: String,
|
||||
pub hero: bool,
|
||||
pub mode: XvbMode,
|
||||
pub amount: String
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
|
@ -375,3 +384,9 @@ impl Default for Version {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for XvbMode {
|
||||
fn default() -> Self {
|
||||
Self::Auto
|
||||
}
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
use std::{
|
||||
sync::{Arc, Mutex},
|
||||
time::Duration,
|
||||
mem::ManuallyDrop, sync::{Arc, Mutex}, time::Duration
|
||||
};
|
||||
|
||||
use log::{debug, info, warn};
|
||||
|
@ -13,12 +12,9 @@ use crate::{
|
|||
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_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,
|
||||
}, 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
|
||||
};
|
||||
use crate::helper::xvb::priv_stats::RuntimeMode;
|
||||
|
||||
use super::{PubXvbApi, SamplesAverageHour};
|
||||
|
||||
|
@ -68,15 +64,25 @@ pub(crate) fn calcul_donated_time(
|
|||
|
||||
if spared_time > 0 {
|
||||
// if not hero option
|
||||
if !lock!(gui_api_xvb).stats_priv.runtime_hero_mode {
|
||||
if lock!(gui_api_xvb).stats_priv.runtime_mode == RuntimeMode::Auto {
|
||||
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);
|
||||
}
|
||||
|
||||
let manual_amount = lock!(gui_api_xvb).stats_priv.runtime_manual_amount as u32;
|
||||
if lock!(gui_api_xvb).stats_priv.runtime_mode == RuntimeMode::ManuallyDonante {
|
||||
spared_time = XVB_TIME_ALGO * manual_amount / (avg_hr as u32);
|
||||
}
|
||||
|
||||
if lock!(gui_api_xvb).stats_priv.runtime_mode == RuntimeMode::ManuallyKeep {
|
||||
spared_time = XVB_TIME_ALGO - (XVB_TIME_ALGO * manual_amount / (avg_hr as u32));
|
||||
}
|
||||
|
||||
}
|
||||
if lock!(gui_api_xvb).stats_priv.runtime_hero_mode {
|
||||
if lock!(gui_api_xvb).stats_priv.runtime_mode == RuntimeMode::Hero {
|
||||
output_console(gui_api_xvb, "Hero mode is enabled for this decision");
|
||||
}
|
||||
spared_time
|
||||
|
|
|
@ -400,11 +400,11 @@ impl PubXvbApi {
|
|||
if !buf.is_empty() {
|
||||
output.push_str(&buf);
|
||||
}
|
||||
let runtime_hero_mode = std::mem::take(&mut gui_api.stats_priv.runtime_hero_mode);
|
||||
let runtime_mode = std::mem::take(&mut gui_api.stats_priv.runtime_mode);
|
||||
*gui_api = Self {
|
||||
output,
|
||||
stats_priv: XvbPrivStats {
|
||||
runtime_hero_mode,
|
||||
runtime_mode,
|
||||
..pub_api.stats_priv.clone()
|
||||
},
|
||||
p2pool_sent_last_hour_samples: std::mem::take(
|
||||
|
@ -694,14 +694,14 @@ fn signal_interrupt(
|
|||
}
|
||||
fn reset_data_xvb(pub_api: &Arc<Mutex<PubXvbApi>>, gui_api: &Arc<Mutex<PubXvbApi>>) {
|
||||
let current_node = mem::take(&mut lock!(pub_api).current_node.clone());
|
||||
let runtime_hero_mode = mem::take(&mut lock!(gui_api).stats_priv.runtime_hero_mode);
|
||||
let runtime_mode = mem::take(&mut lock!(gui_api).stats_priv.runtime_mode);
|
||||
// let output = mem::take(&mut lock!(gui_api).output);
|
||||
*lock!(pub_api) = PubXvbApi::new();
|
||||
*lock!(gui_api) = PubXvbApi::new();
|
||||
// to keep the value modified by xmrig even if xvb is dead.
|
||||
lock!(pub_api).current_node = current_node;
|
||||
// to not loose the information of runtime hero mode between restart
|
||||
lock!(gui_api).stats_priv.runtime_hero_mode = runtime_hero_mode;
|
||||
lock!(gui_api).stats_priv.runtime_mode = runtime_mode;
|
||||
// message while starting must be preserved.
|
||||
// lock!(pub_api).output = output;
|
||||
}
|
||||
|
|
|
@ -14,9 +14,19 @@ use crate::{
|
|||
macros::lock,
|
||||
XVB_URL,
|
||||
};
|
||||
use crate::disk::state::XvbMode;
|
||||
|
||||
use super::{nodes::XvbNode, rounds::XvbRound, PubXvbApi};
|
||||
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, PartialEq, Eq)]
|
||||
pub enum RuntimeMode {
|
||||
Auto,
|
||||
ManuallyDonante,
|
||||
ManuallyKeep,
|
||||
Hero,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Deserialize)]
|
||||
pub struct XvbPrivStats {
|
||||
pub fails: u8,
|
||||
|
@ -36,7 +46,8 @@ pub struct XvbPrivStats {
|
|||
pub msg_indicator: String,
|
||||
#[serde(skip)]
|
||||
// so the hero mode can change between two decision of algorithm without restarting XvB.
|
||||
pub runtime_hero_mode: bool,
|
||||
pub runtime_mode: RuntimeMode,
|
||||
pub runtime_manual_amount: u64
|
||||
}
|
||||
|
||||
impl XvbPrivStats {
|
||||
|
@ -106,3 +117,20 @@ impl XvbPrivStats {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<XvbMode> for RuntimeMode {
|
||||
fn from(mode: XvbMode) -> Self {
|
||||
match mode {
|
||||
XvbMode::Auto => Self::Auto,
|
||||
XvbMode::ManuallyDonante => Self::ManuallyDonante,
|
||||
XvbMode::ManuallyKeep => Self::ManuallyKeep,
|
||||
XvbMode::Hero => Self::Hero,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for RuntimeMode {
|
||||
fn default() -> Self {
|
||||
Self::Auto
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue