mirror of
https://github.com/Cyrix126/gupaxx.git
synced 2024-12-22 22:59:27 +00:00
fix: update tests and fix bugs
This commit is contained in:
parent
783b3148c7
commit
cd7ed17f8b
2 changed files with 193 additions and 285 deletions
|
@ -1,12 +1,11 @@
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
|
|
||||||
|
use crate::helper::xrig::xmrig_proxy::PubXmrigProxyApi;
|
||||||
|
use crate::helper::xvb::algorithm::Algorithm;
|
||||||
use crate::helper::{
|
use crate::helper::{
|
||||||
p2pool::{PrivP2poolLocalApi, PrivP2poolNetworkApi},
|
p2pool::{PrivP2poolLocalApi, PrivP2poolNetworkApi},
|
||||||
xvb::{
|
xvb::{priv_stats::RuntimeDonationLevel, priv_stats::RuntimeMode, rounds::round_type},
|
||||||
algorithm::calcul_donated_time, priv_stats::RuntimeDonationLevel,
|
|
||||||
priv_stats::RuntimeMode, rounds::round_type,
|
|
||||||
},
|
|
||||||
Helper, Process, ProcessName, ProcessState,
|
Helper, Process, ProcessName, ProcessState,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -532,296 +531,209 @@ Uptime = 0h 2m 4s
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn algorithm_time_given() {
|
fn test_manual_xvb_mode() {
|
||||||
|
let client = reqwest::Client::new();
|
||||||
|
let pub_api = Arc::new(Mutex::new(PubXvbApi::new()));
|
||||||
let gui_api_xvb = Arc::new(Mutex::new(PubXvbApi::new()));
|
let gui_api_xvb = Arc::new(Mutex::new(PubXvbApi::new()));
|
||||||
let gui_api_p2pool = Arc::new(Mutex::new(PubP2poolApi::new()));
|
|
||||||
let gui_api_xmrig = Arc::new(Mutex::new(PubXmrigApi::new()));
|
let gui_api_xmrig = Arc::new(Mutex::new(PubXmrigApi::new()));
|
||||||
|
let gui_api_xp = Arc::new(Mutex::new(PubXmrigProxyApi::new()));
|
||||||
|
let gui_api_p2pool = Arc::new(Mutex::new(PubP2poolApi::new()));
|
||||||
|
let token_xmrig = "12345678";
|
||||||
let state_p2pool = P2pool::default();
|
let state_p2pool = P2pool::default();
|
||||||
lock!(gui_api_p2pool).p2pool_difficulty_u64 = 95000000;
|
let time_donated = Arc::new(Mutex::new(u32::default()));
|
||||||
|
let rig = "test_rig";
|
||||||
|
let xp_alive = false;
|
||||||
let share = 1;
|
let share = 1;
|
||||||
// verify that if one share found (enough for vip round) but not enough for donor round, no time will be given to xvb, except if in hero mode.
|
|
||||||
// 15mn average HR of xmrig is 5kH/s
|
lock!(gui_api_xmrig).hashrate_raw_15m = 10000.0;
|
||||||
lock!(gui_api_xvb).stats_priv.donor_1hr_avg = 0.0;
|
lock!(gui_api_xvb).stats_priv.runtime_mode = RuntimeMode::ManualXvb;
|
||||||
lock!(gui_api_xmrig).hashrate_raw_15m = 5000.0;
|
lock!(gui_api_xvb).stats_priv.runtime_manual_amount = 1000.0;
|
||||||
lock!(gui_api_xvb).stats_priv.runtime_mode = RuntimeMode::Auto;
|
|
||||||
let given_time = calcul_donated_time(
|
let algo = Algorithm::new(
|
||||||
lock!(gui_api_xmrig).hashrate_raw_15m,
|
&client,
|
||||||
&gui_api_p2pool,
|
&pub_api,
|
||||||
&gui_api_xvb,
|
&gui_api_xvb,
|
||||||
&state_p2pool,
|
&gui_api_xmrig,
|
||||||
);
|
&gui_api_xp,
|
||||||
// verify that default mode will give x seconds
|
|
||||||
assert_eq!(given_time, 0);
|
|
||||||
// given time should always be less than XVB_TIME_ALGO
|
|
||||||
assert!(given_time < XVB_TIME_ALGO);
|
|
||||||
// verify that right round should be detected.
|
|
||||||
lock!(gui_api_xvb).stats_priv.donor_1hr_avg = ((given_time as f32 / XVB_TIME_ALGO as f32)
|
|
||||||
* lock!(gui_api_xmrig).hashrate_raw_15m)
|
|
||||||
/ 1000.0;
|
|
||||||
lock!(gui_api_xvb).stats_priv.donor_24hr_avg = ((given_time as f32 / XVB_TIME_ALGO as f32)
|
|
||||||
* lock!(gui_api_xmrig).hashrate_raw_15m)
|
|
||||||
/ 1000.0;
|
|
||||||
assert_eq!(round_type(share, &gui_api_xvb), Some(XvbRound::Vip));
|
|
||||||
// verify that hero mode will give x seconds
|
|
||||||
lock!(gui_api_xvb).stats_priv.runtime_mode = RuntimeMode::Hero;
|
|
||||||
let given_time = calcul_donated_time(
|
|
||||||
lock!(gui_api_xmrig).hashrate_raw_15m,
|
|
||||||
&gui_api_p2pool,
|
&gui_api_p2pool,
|
||||||
&gui_api_xvb,
|
token_xmrig,
|
||||||
&state_p2pool,
|
&state_p2pool,
|
||||||
|
share,
|
||||||
|
&time_donated,
|
||||||
|
rig,
|
||||||
|
xp_alive,
|
||||||
);
|
);
|
||||||
assert_eq!(given_time, 45);
|
|
||||||
// verify that right round should be detected.
|
assert_eq!(algo.stats.target_donation_hashrate, 1000.0);
|
||||||
lock!(gui_api_xvb).stats_priv.donor_1hr_avg = ((given_time as f32 / XVB_TIME_ALGO as f32)
|
|
||||||
* lock!(gui_api_xmrig).hashrate_raw_15m)
|
|
||||||
/ 1000.0;
|
|
||||||
lock!(gui_api_xvb).stats_priv.donor_24hr_avg = ((given_time as f32 / XVB_TIME_ALGO as f32)
|
|
||||||
* lock!(gui_api_xmrig).hashrate_raw_15m)
|
|
||||||
/ 1000.0;
|
|
||||||
assert_eq!(round_type(share, &gui_api_xvb), Some(XvbRound::Vip));
|
|
||||||
// verify that if one share and not enough for donor vip round (should be in donor round), right amount of time will be given to xvb for default and hero mode
|
|
||||||
lock!(gui_api_xvb).stats_priv.donor_1hr_avg = 0.0;
|
|
||||||
lock!(gui_api_xmrig).hashrate_raw_15m = 8000.0;
|
|
||||||
lock!(gui_api_xvb).stats_priv.runtime_mode = RuntimeMode::Auto;
|
|
||||||
let given_time = calcul_donated_time(
|
|
||||||
lock!(gui_api_xmrig).hashrate_raw_15m,
|
|
||||||
&gui_api_p2pool,
|
|
||||||
&gui_api_xvb,
|
|
||||||
&state_p2pool,
|
|
||||||
);
|
|
||||||
// verify that default mode will give x seconds
|
|
||||||
assert_eq!(given_time, 75);
|
|
||||||
// given time should always be less than XVB_TIME_ALGO
|
|
||||||
assert!(given_time < XVB_TIME_ALGO);
|
|
||||||
// verify that right round should be detected.
|
|
||||||
lock!(gui_api_xvb).stats_priv.donor_1hr_avg = ((given_time as f32 / XVB_TIME_ALGO as f32)
|
|
||||||
* lock!(gui_api_xmrig).hashrate_raw_15m)
|
|
||||||
/ 1000.0;
|
|
||||||
lock!(gui_api_xvb).stats_priv.donor_24hr_avg = ((given_time as f32 / XVB_TIME_ALGO as f32)
|
|
||||||
* lock!(gui_api_xmrig).hashrate_raw_15m)
|
|
||||||
/ 1000.0;
|
|
||||||
assert_eq!(round_type(share, &gui_api_xvb), Some(XvbRound::Donor));
|
|
||||||
// verify that hero mode will give x seconds
|
|
||||||
lock!(gui_api_xvb).stats_priv.runtime_mode = RuntimeMode::Hero;
|
|
||||||
let given_time = calcul_donated_time(
|
|
||||||
lock!(gui_api_xmrig).hashrate_raw_15m,
|
|
||||||
&gui_api_p2pool,
|
|
||||||
&gui_api_xvb,
|
|
||||||
&state_p2pool,
|
|
||||||
);
|
|
||||||
assert_eq!(given_time, 253);
|
|
||||||
// verify that right round should be detected.
|
|
||||||
lock!(gui_api_xvb).stats_priv.donor_1hr_avg = ((given_time as f32 / XVB_TIME_ALGO as f32)
|
|
||||||
* lock!(gui_api_xmrig).hashrate_raw_15m)
|
|
||||||
/ 1000.0;
|
|
||||||
lock!(gui_api_xvb).stats_priv.donor_24hr_avg = ((given_time as f32 / XVB_TIME_ALGO as f32)
|
|
||||||
* lock!(gui_api_xmrig).hashrate_raw_15m)
|
|
||||||
/ 1000.0;
|
|
||||||
assert_eq!(round_type(share, &gui_api_xvb), Some(XvbRound::Donor));
|
|
||||||
// verify that if one share and not enough for donor whale round(should be in donor vip), right amount of time will be given to xvb for default and hero mode
|
|
||||||
lock!(gui_api_xvb).stats_priv.donor_1hr_avg = 0.0;
|
|
||||||
lock!(gui_api_xmrig).hashrate_raw_15m = 19000.0;
|
|
||||||
lock!(gui_api_xvb).stats_priv.runtime_mode = RuntimeMode::Auto;
|
|
||||||
let given_time = calcul_donated_time(
|
|
||||||
lock!(gui_api_xmrig).hashrate_raw_15m,
|
|
||||||
&gui_api_p2pool,
|
|
||||||
&gui_api_xvb,
|
|
||||||
&state_p2pool,
|
|
||||||
);
|
|
||||||
// verify that default mode will give x seconds
|
|
||||||
assert_eq!(given_time, 316);
|
|
||||||
// given time should always be less than XVB_TIME_ALGO
|
|
||||||
assert!(given_time < XVB_TIME_ALGO);
|
|
||||||
// verify that right round should be detected.
|
|
||||||
lock!(gui_api_xvb).stats_priv.donor_1hr_avg = ((given_time as f32 / XVB_TIME_ALGO as f32)
|
|
||||||
* lock!(gui_api_xmrig).hashrate_raw_15m)
|
|
||||||
/ 1000.0;
|
|
||||||
lock!(gui_api_xvb).stats_priv.donor_24hr_avg = ((given_time as f32 / XVB_TIME_ALGO as f32)
|
|
||||||
* lock!(gui_api_xmrig).hashrate_raw_15m)
|
|
||||||
/ 1000.0;
|
|
||||||
assert_eq!(round_type(share, &gui_api_xvb), Some(XvbRound::DonorVip));
|
|
||||||
// verify that hero mode will give x seconds
|
|
||||||
lock!(gui_api_xvb).stats_priv.runtime_mode = RuntimeMode::Hero;
|
|
||||||
let given_time = calcul_donated_time(
|
|
||||||
lock!(gui_api_xmrig).hashrate_raw_15m,
|
|
||||||
&gui_api_p2pool,
|
|
||||||
&gui_api_xvb,
|
|
||||||
&state_p2pool,
|
|
||||||
);
|
|
||||||
assert_eq!(given_time, 454);
|
|
||||||
// verify that right round should be detected.
|
|
||||||
lock!(gui_api_xvb).stats_priv.donor_1hr_avg = ((given_time as f32 / XVB_TIME_ALGO as f32)
|
|
||||||
* lock!(gui_api_xmrig).hashrate_raw_15m)
|
|
||||||
/ 1000.0;
|
|
||||||
lock!(gui_api_xvb).stats_priv.donor_24hr_avg = ((given_time as f32 / XVB_TIME_ALGO as f32)
|
|
||||||
* lock!(gui_api_xmrig).hashrate_raw_15m)
|
|
||||||
/ 1000.0;
|
|
||||||
assert_eq!(round_type(share, &gui_api_xvb), Some(XvbRound::DonorVip));
|
|
||||||
// verify that if one share and not enough for donor mega round, right amount of time will be given to xvb for default and hero mode
|
|
||||||
lock!(gui_api_xvb).stats_priv.donor_1hr_avg = 0.0;
|
|
||||||
lock!(gui_api_xmrig).hashrate_raw_15m = 105000.0;
|
|
||||||
lock!(gui_api_xvb).stats_priv.runtime_mode = RuntimeMode::Auto;
|
|
||||||
let given_time = calcul_donated_time(
|
|
||||||
lock!(gui_api_xmrig).hashrate_raw_15m,
|
|
||||||
&gui_api_p2pool,
|
|
||||||
&gui_api_xvb,
|
|
||||||
&state_p2pool,
|
|
||||||
);
|
|
||||||
// verify that default mode will give x seconds
|
|
||||||
assert_eq!(given_time, 572);
|
|
||||||
// given time should always be less than XVB_TIME_ALGO
|
|
||||||
assert!(given_time < XVB_TIME_ALGO);
|
|
||||||
// verify that right round should be detected.
|
|
||||||
lock!(gui_api_xvb).stats_priv.donor_1hr_avg = ((given_time as f32 / XVB_TIME_ALGO as f32)
|
|
||||||
* lock!(gui_api_xmrig).hashrate_raw_15m)
|
|
||||||
/ 1000.0;
|
|
||||||
lock!(gui_api_xvb).stats_priv.donor_24hr_avg = ((given_time as f32 / XVB_TIME_ALGO as f32)
|
|
||||||
* lock!(gui_api_xmrig).hashrate_raw_15m)
|
|
||||||
/ 1000.0;
|
|
||||||
assert_eq!(round_type(share, &gui_api_xvb), Some(XvbRound::DonorWhale));
|
|
||||||
// verify that hero mode will give x seconds
|
|
||||||
lock!(gui_api_xvb).stats_priv.runtime_mode = RuntimeMode::Hero;
|
|
||||||
let given_time = calcul_donated_time(
|
|
||||||
lock!(gui_api_xmrig).hashrate_raw_15m,
|
|
||||||
&gui_api_p2pool,
|
|
||||||
&gui_api_xvb,
|
|
||||||
&state_p2pool,
|
|
||||||
);
|
|
||||||
assert_eq!(given_time, 573);
|
|
||||||
// verify that right round should be detected.
|
|
||||||
lock!(gui_api_xvb).stats_priv.donor_1hr_avg = ((given_time as f32 / XVB_TIME_ALGO as f32)
|
|
||||||
* lock!(gui_api_xmrig).hashrate_raw_15m)
|
|
||||||
/ 1000.0;
|
|
||||||
lock!(gui_api_xvb).stats_priv.donor_24hr_avg = ((given_time as f32 / XVB_TIME_ALGO as f32)
|
|
||||||
* lock!(gui_api_xmrig).hashrate_raw_15m)
|
|
||||||
/ 1000.0;
|
|
||||||
assert_eq!(round_type(share, &gui_api_xvb), Some(XvbRound::DonorWhale));
|
|
||||||
// verify that if one share and enough for donor mega round, right amount of time will be given to xvb for default and hero mode
|
|
||||||
lock!(gui_api_xvb).stats_priv.donor_1hr_avg = 0.0;
|
|
||||||
lock!(gui_api_xmrig).hashrate_raw_15m = 1205000.0;
|
|
||||||
lock!(gui_api_xvb).stats_priv.runtime_mode = RuntimeMode::Auto;
|
|
||||||
let given_time = calcul_donated_time(
|
|
||||||
lock!(gui_api_xmrig).hashrate_raw_15m,
|
|
||||||
&gui_api_p2pool,
|
|
||||||
&gui_api_xvb,
|
|
||||||
&state_p2pool,
|
|
||||||
);
|
|
||||||
// verify that default mode will give x seconds
|
|
||||||
assert_eq!(given_time, 498);
|
|
||||||
// given time should always be less than XVB_TIME_ALGO
|
|
||||||
assert!(given_time < XVB_TIME_ALGO);
|
|
||||||
// verify that right round should be detected.
|
|
||||||
lock!(gui_api_xvb).stats_priv.donor_1hr_avg = ((given_time as f32 / XVB_TIME_ALGO as f32)
|
|
||||||
* lock!(gui_api_xmrig).hashrate_raw_15m)
|
|
||||||
/ 1000.0;
|
|
||||||
lock!(gui_api_xvb).stats_priv.donor_24hr_avg = ((given_time as f32 / XVB_TIME_ALGO as f32)
|
|
||||||
* lock!(gui_api_xmrig).hashrate_raw_15m)
|
|
||||||
/ 1000.0;
|
|
||||||
assert_eq!(round_type(share, &gui_api_xvb), Some(XvbRound::DonorMega));
|
|
||||||
// verify that hero mode will give x seconds
|
|
||||||
lock!(gui_api_xvb).stats_priv.runtime_mode = RuntimeMode::Hero;
|
|
||||||
let given_time = calcul_donated_time(
|
|
||||||
lock!(gui_api_xmrig).hashrate_raw_15m,
|
|
||||||
&gui_api_p2pool,
|
|
||||||
&gui_api_xvb,
|
|
||||||
&state_p2pool,
|
|
||||||
);
|
|
||||||
assert_eq!(given_time, 597);
|
|
||||||
// verify that right round should be detected.
|
|
||||||
lock!(gui_api_xvb).stats_priv.donor_1hr_avg = ((given_time as f32 / XVB_TIME_ALGO as f32)
|
|
||||||
* lock!(gui_api_xmrig).hashrate_raw_15m)
|
|
||||||
/ 1000.0;
|
|
||||||
lock!(gui_api_xvb).stats_priv.donor_24hr_avg = ((given_time as f32 / XVB_TIME_ALGO as f32)
|
|
||||||
* lock!(gui_api_xmrig).hashrate_raw_15m)
|
|
||||||
/ 1000.0;
|
|
||||||
assert_eq!(round_type(share, &gui_api_xvb), Some(XvbRound::DonorMega));
|
|
||||||
// verify that if one share and enough for donor vp round if XvB oHR is given, right amount of time will be given to xvb for default and hero mode
|
|
||||||
lock!(gui_api_xvb).output.clear();
|
|
||||||
lock!(gui_api_xmrig).hashrate_raw_15m = 12500.0;
|
|
||||||
lock!(gui_api_xvb).stats_priv.donor_1hr_avg = 5.0;
|
|
||||||
lock!(gui_api_xvb).stats_priv.runtime_mode = RuntimeMode::Auto;
|
|
||||||
let given_time = calcul_donated_time(
|
|
||||||
lock!(gui_api_xmrig).hashrate_raw_15m,
|
|
||||||
&gui_api_p2pool,
|
|
||||||
&gui_api_xvb,
|
|
||||||
&state_p2pool,
|
|
||||||
);
|
|
||||||
// verify that default mode will give x seconds
|
|
||||||
assert_eq!(given_time, 240);
|
|
||||||
// given time should always be less than XVB_TIME_ALGO
|
|
||||||
assert!(given_time < XVB_TIME_ALGO);
|
|
||||||
// verify that right round should be detected.
|
|
||||||
lock!(gui_api_xvb).stats_priv.donor_1hr_avg =
|
|
||||||
(((given_time as f32 / XVB_TIME_ALGO as f32) * lock!(gui_api_xmrig).hashrate_raw_15m)
|
|
||||||
+ 5000.0)
|
|
||||||
/ 1000.0;
|
|
||||||
lock!(gui_api_xvb).stats_priv.donor_24hr_avg =
|
|
||||||
(((given_time as f32 / XVB_TIME_ALGO as f32) * lock!(gui_api_xmrig).hashrate_raw_15m)
|
|
||||||
+ 5000.0)
|
|
||||||
/ 1000.0;
|
|
||||||
assert_eq!(round_type(share, &gui_api_xvb), Some(XvbRound::DonorVip));
|
|
||||||
// verify that hero mode will give x seconds
|
|
||||||
lock!(gui_api_xvb).stats_priv.donor_1hr_avg = 5.0;
|
|
||||||
lock!(gui_api_xvb).stats_priv.runtime_mode = RuntimeMode::Hero;
|
|
||||||
let given_time = calcul_donated_time(
|
|
||||||
lock!(gui_api_xmrig).hashrate_raw_15m,
|
|
||||||
&gui_api_p2pool,
|
|
||||||
&gui_api_xvb,
|
|
||||||
&state_p2pool,
|
|
||||||
);
|
|
||||||
assert_eq!(given_time, 378);
|
|
||||||
// verify that right round should be detected.
|
|
||||||
lock!(gui_api_xvb).stats_priv.donor_1hr_avg =
|
|
||||||
(((given_time as f32 / XVB_TIME_ALGO as f32) * lock!(gui_api_xmrig).hashrate_raw_15m)
|
|
||||||
+ 5000.0)
|
|
||||||
/ 1000.0;
|
|
||||||
lock!(gui_api_xvb).stats_priv.donor_24hr_avg =
|
|
||||||
(((given_time as f32 / XVB_TIME_ALGO as f32) * lock!(gui_api_xmrig).hashrate_raw_15m)
|
|
||||||
+ 5000.0)
|
|
||||||
/ 1000.0;
|
|
||||||
assert_eq!(round_type(share, &gui_api_xvb), Some(XvbRound::DonorVip));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_xvb_advanced_options() {
|
fn test_manual_p2pool_mode() {
|
||||||
|
let client = reqwest::Client::new();
|
||||||
|
let pub_api = Arc::new(Mutex::new(PubXvbApi::new()));
|
||||||
let gui_api_xvb = Arc::new(Mutex::new(PubXvbApi::new()));
|
let gui_api_xvb = Arc::new(Mutex::new(PubXvbApi::new()));
|
||||||
let gui_api_p2pool = Arc::new(Mutex::new(PubP2poolApi::new()));
|
|
||||||
let gui_api_xmrig = Arc::new(Mutex::new(PubXmrigApi::new()));
|
let gui_api_xmrig = Arc::new(Mutex::new(PubXmrigApi::new()));
|
||||||
|
let gui_api_xp = Arc::new(Mutex::new(PubXmrigProxyApi::new()));
|
||||||
|
let gui_api_p2pool = Arc::new(Mutex::new(PubP2poolApi::new()));
|
||||||
|
let token_xmrig = "12345678";
|
||||||
let state_p2pool = P2pool::default();
|
let state_p2pool = P2pool::default();
|
||||||
lock!(gui_api_p2pool).p2pool_difficulty_u64 = 95000000;
|
let time_donated = Arc::new(Mutex::new(u32::default()));
|
||||||
lock!(gui_api_xvb).stats_priv.donor_1hr_avg = 0.0;
|
let rig = "test_rig";
|
||||||
lock!(gui_api_xmrig).hashrate_raw_15m = 5000.0;
|
let xp_alive = false;
|
||||||
lock!(gui_api_xvb).stats_priv.runtime_mode = RuntimeMode::ManualXvb;
|
let share = 1;
|
||||||
lock!(gui_api_xvb).stats_priv.runtime_manual_amount = 500.0;
|
|
||||||
|
|
||||||
let given_time = calcul_donated_time(
|
|
||||||
lock!(gui_api_xmrig).hashrate_raw_15m,
|
|
||||||
&gui_api_p2pool,
|
|
||||||
&gui_api_xvb,
|
|
||||||
&state_p2pool,
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(given_time, 60);
|
|
||||||
|
|
||||||
|
lock!(gui_api_xmrig).hashrate_raw_15m = 10000.0;
|
||||||
lock!(gui_api_xvb).stats_priv.runtime_mode = RuntimeMode::ManualP2pool;
|
lock!(gui_api_xvb).stats_priv.runtime_mode = RuntimeMode::ManualP2pool;
|
||||||
|
lock!(gui_api_xvb).stats_priv.runtime_manual_amount = 1000.0;
|
||||||
|
|
||||||
let given_time = calcul_donated_time(
|
let algo = Algorithm::new(
|
||||||
lock!(gui_api_xmrig).hashrate_raw_15m,
|
&client,
|
||||||
&gui_api_p2pool,
|
&pub_api,
|
||||||
&gui_api_xvb,
|
&gui_api_xvb,
|
||||||
|
&gui_api_xmrig,
|
||||||
|
&gui_api_xp,
|
||||||
|
&gui_api_p2pool,
|
||||||
|
token_xmrig,
|
||||||
&state_p2pool,
|
&state_p2pool,
|
||||||
|
share,
|
||||||
|
&time_donated,
|
||||||
|
rig,
|
||||||
|
xp_alive,
|
||||||
);
|
);
|
||||||
assert_eq!(given_time, 540);
|
|
||||||
|
|
||||||
|
assert_eq!(algo.stats.target_donation_hashrate, 9000.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_manual_donor_level_mode_donor() {
|
||||||
|
let client = reqwest::Client::new();
|
||||||
|
let pub_api = Arc::new(Mutex::new(PubXvbApi::new()));
|
||||||
|
let gui_api_xvb = Arc::new(Mutex::new(PubXvbApi::new()));
|
||||||
|
let gui_api_xmrig = Arc::new(Mutex::new(PubXmrigApi::new()));
|
||||||
|
let gui_api_xp = Arc::new(Mutex::new(PubXmrigProxyApi::new()));
|
||||||
|
let gui_api_p2pool = Arc::new(Mutex::new(PubP2poolApi::new()));
|
||||||
|
let token_xmrig = "12345678";
|
||||||
|
let state_p2pool = P2pool::default();
|
||||||
|
let time_donated = Arc::new(Mutex::new(u32::default()));
|
||||||
|
let rig = "test_rig";
|
||||||
|
let xp_alive = false;
|
||||||
|
let share = 1;
|
||||||
|
|
||||||
|
lock!(gui_api_xmrig).hashrate_raw_15m = 10000.0;
|
||||||
lock!(gui_api_xvb).stats_priv.runtime_mode = RuntimeMode::ManualDonationLevel;
|
lock!(gui_api_xvb).stats_priv.runtime_mode = RuntimeMode::ManualDonationLevel;
|
||||||
|
lock!(gui_api_xvb).stats_priv.runtime_manual_amount = 1000.0;
|
||||||
lock!(gui_api_xvb).stats_priv.runtime_manual_donation_level = RuntimeDonationLevel::Donor;
|
lock!(gui_api_xvb).stats_priv.runtime_manual_donation_level = RuntimeDonationLevel::Donor;
|
||||||
|
|
||||||
let given_time = calcul_donated_time(
|
let algo = Algorithm::new(
|
||||||
lock!(gui_api_xmrig).hashrate_raw_15m,
|
&client,
|
||||||
&gui_api_p2pool,
|
&pub_api,
|
||||||
&gui_api_xvb,
|
&gui_api_xvb,
|
||||||
|
&gui_api_xmrig,
|
||||||
|
&gui_api_xp,
|
||||||
|
&gui_api_p2pool,
|
||||||
|
token_xmrig,
|
||||||
&state_p2pool,
|
&state_p2pool,
|
||||||
|
share,
|
||||||
|
&time_donated,
|
||||||
|
rig,
|
||||||
|
xp_alive,
|
||||||
);
|
);
|
||||||
assert_eq!(given_time, 120);
|
|
||||||
|
assert_eq!(algo.stats.target_donation_hashrate, 1000.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_auto_mode() {
|
||||||
|
let client = reqwest::Client::new();
|
||||||
|
let pub_api = Arc::new(Mutex::new(PubXvbApi::new()));
|
||||||
|
let gui_api_xvb = Arc::new(Mutex::new(PubXvbApi::new()));
|
||||||
|
let gui_api_xmrig = Arc::new(Mutex::new(PubXmrigApi::new()));
|
||||||
|
let gui_api_xp = Arc::new(Mutex::new(PubXmrigProxyApi::new()));
|
||||||
|
let gui_api_p2pool = Arc::new(Mutex::new(PubP2poolApi::new()));
|
||||||
|
let token_xmrig = "12345678";
|
||||||
|
let state_p2pool = P2pool::default();
|
||||||
|
let time_donated = Arc::new(Mutex::new(u32::default()));
|
||||||
|
let rig = "test_rig";
|
||||||
|
let xp_alive = false;
|
||||||
|
let share = 1;
|
||||||
|
|
||||||
|
lock!(gui_api_p2pool).p2pool_difficulty_u64 = 9_000_000;
|
||||||
|
lock!(gui_api_xmrig).hashrate_raw_15m = 20000.0;
|
||||||
|
lock!(gui_api_xvb).stats_priv.runtime_mode = RuntimeMode::Auto;
|
||||||
|
|
||||||
|
let algo = Algorithm::new(
|
||||||
|
&client,
|
||||||
|
&pub_api,
|
||||||
|
&gui_api_xvb,
|
||||||
|
&gui_api_xmrig,
|
||||||
|
&gui_api_xp,
|
||||||
|
&gui_api_p2pool,
|
||||||
|
token_xmrig,
|
||||||
|
&state_p2pool,
|
||||||
|
share,
|
||||||
|
&time_donated,
|
||||||
|
rig,
|
||||||
|
xp_alive,
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(algo.stats.target_donation_hashrate, 10000.0);
|
||||||
|
|
||||||
|
lock!(gui_api_p2pool).p2pool_difficulty_u64 = 9_000_000;
|
||||||
|
lock!(gui_api_xmrig).hashrate_raw_15m = 10000.0;
|
||||||
|
lock!(gui_api_xvb).stats_priv.runtime_mode = RuntimeMode::Auto;
|
||||||
|
|
||||||
|
let algo = Algorithm::new(
|
||||||
|
&client,
|
||||||
|
&pub_api,
|
||||||
|
&gui_api_xvb,
|
||||||
|
&gui_api_xmrig,
|
||||||
|
&gui_api_xp,
|
||||||
|
&gui_api_p2pool,
|
||||||
|
token_xmrig,
|
||||||
|
&state_p2pool,
|
||||||
|
share,
|
||||||
|
&time_donated,
|
||||||
|
rig,
|
||||||
|
xp_alive,
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(algo.stats.target_donation_hashrate, 1000.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_hero_mode() {
|
||||||
|
let client = reqwest::Client::new();
|
||||||
|
let pub_api = Arc::new(Mutex::new(PubXvbApi::new()));
|
||||||
|
let gui_api_xvb = Arc::new(Mutex::new(PubXvbApi::new()));
|
||||||
|
let gui_api_xmrig = Arc::new(Mutex::new(PubXmrigApi::new()));
|
||||||
|
let gui_api_xp = Arc::new(Mutex::new(PubXmrigProxyApi::new()));
|
||||||
|
let gui_api_p2pool = Arc::new(Mutex::new(PubP2poolApi::new()));
|
||||||
|
let token_xmrig = "12345678";
|
||||||
|
let state_p2pool = P2pool::default();
|
||||||
|
let time_donated = Arc::new(Mutex::new(u32::default()));
|
||||||
|
let rig = "test_rig";
|
||||||
|
let xp_alive = false;
|
||||||
|
let share = 1;
|
||||||
|
|
||||||
|
lock!(gui_api_p2pool).p2pool_difficulty_u64 = 9_000_000;
|
||||||
|
lock!(gui_api_xmrig).hashrate_raw_15m = 20000.0;
|
||||||
|
lock!(gui_api_xvb).stats_priv.runtime_mode = RuntimeMode::Hero;
|
||||||
|
|
||||||
|
let algo = Algorithm::new(
|
||||||
|
&client,
|
||||||
|
&pub_api,
|
||||||
|
&gui_api_xvb,
|
||||||
|
&gui_api_xmrig,
|
||||||
|
&gui_api_xp,
|
||||||
|
&gui_api_p2pool,
|
||||||
|
token_xmrig,
|
||||||
|
&state_p2pool,
|
||||||
|
share,
|
||||||
|
&time_donated,
|
||||||
|
rig,
|
||||||
|
xp_alive,
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(algo.stats.target_donation_hashrate, 10000.0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ pub(crate) async fn algorithm(
|
||||||
algorithm.run().await;
|
algorithm.run().await;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Algorithm<'a> {
|
pub struct Algorithm<'a> {
|
||||||
client: &'a Client,
|
client: &'a Client,
|
||||||
pub_api: &'a Arc<Mutex<PubXvbApi>>,
|
pub_api: &'a Arc<Mutex<PubXvbApi>>,
|
||||||
gui_api_xvb: &'a Arc<Mutex<PubXvbApi>>,
|
gui_api_xvb: &'a Arc<Mutex<PubXvbApi>>,
|
||||||
|
@ -73,14 +73,14 @@ struct Algorithm<'a> {
|
||||||
time_donated: &'a Arc<Mutex<u32>>,
|
time_donated: &'a Arc<Mutex<u32>>,
|
||||||
rig: &'a str,
|
rig: &'a str,
|
||||||
xp_alive: bool,
|
xp_alive: bool,
|
||||||
stats: Stats,
|
pub stats: Stats,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct Stats {
|
pub struct Stats {
|
||||||
share: u32,
|
share: u32,
|
||||||
hashrate_xmrig: f32,
|
hashrate_xmrig: f32,
|
||||||
target_donation_hashrate: f32,
|
pub target_donation_hashrate: f32,
|
||||||
xvb_24h_avg: f32,
|
xvb_24h_avg: f32,
|
||||||
xvb_1h_avg: f32,
|
xvb_1h_avg: f32,
|
||||||
address: String,
|
address: String,
|
||||||
|
@ -98,7 +98,7 @@ struct Stats {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Algorithm<'a> {
|
impl<'a> Algorithm<'a> {
|
||||||
fn new(
|
pub fn new(
|
||||||
client: &'a Client,
|
client: &'a Client,
|
||||||
pub_api: &'a Arc<Mutex<PubXvbApi>>,
|
pub_api: &'a Arc<Mutex<PubXvbApi>>,
|
||||||
gui_api_xvb: &'a Arc<Mutex<PubXvbApi>>,
|
gui_api_xvb: &'a Arc<Mutex<PubXvbApi>>,
|
||||||
|
@ -135,7 +135,6 @@ impl<'a> Algorithm<'a> {
|
||||||
let share_min_hashrate = Self::minimum_hashrate_share(
|
let share_min_hashrate = Self::minimum_hashrate_share(
|
||||||
lock!(gui_api_p2pool).p2pool_difficulty_u64,
|
lock!(gui_api_p2pool).p2pool_difficulty_u64,
|
||||||
state_p2pool.mini,
|
state_p2pool.mini,
|
||||||
p2pool_external_hashrate,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
let spareable_hashrate = hashrate_xmrig - share_min_hashrate;
|
let spareable_hashrate = hashrate_xmrig - share_min_hashrate;
|
||||||
|
@ -392,7 +391,7 @@ impl<'a> Algorithm<'a> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_target_donation_hashrate(&self) -> f32 {
|
pub fn get_target_donation_hashrate(&self) -> f32 {
|
||||||
let target_donation_hashrate = match self.stats.runtime_mode {
|
let target_donation_hashrate = match self.stats.runtime_mode {
|
||||||
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(),
|
||||||
|
@ -406,7 +405,7 @@ impl<'a> Algorithm<'a> {
|
||||||
}
|
}
|
||||||
RuntimeMode::ManualP2pool => {
|
RuntimeMode::ManualP2pool => {
|
||||||
let target_donation_hashrate =
|
let target_donation_hashrate =
|
||||||
(XVB_TIME_ALGO as f32) - (self.stats.runtime_amount as f32);
|
(self.stats.hashrate_xmrig as f32) - (self.stats.runtime_amount as f32);
|
||||||
|
|
||||||
info!("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,
|
||||||
|
@ -430,17 +429,15 @@ impl<'a> Algorithm<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_auto_mode_target_donation_hashrate(&self) -> f32 {
|
fn get_auto_mode_target_donation_hashrate(&self) -> f32 {
|
||||||
// TODO fix wrong target hashrate being selected
|
|
||||||
// TODO consider using xvb_24h_avg for calculations
|
|
||||||
// TODO consider using dynamic buffer size buffer gets smaller as gupaxx runs for longer to provide more stability
|
// TODO consider using dynamic buffer size buffer gets smaller as gupaxx runs for longer to provide more stability
|
||||||
|
|
||||||
let donation_level = match self.stats.spareable_hashrate {
|
let donation_level = match self.stats.spareable_hashrate {
|
||||||
x if x > (XVB_ROUND_DONOR_MIN_HR as f32) => Some(RuntimeDonationLevel::Donor),
|
x if x > (XVB_ROUND_DONOR_MEGA_MIN_HR as f32) => Some(RuntimeDonationLevel::DonorMega),
|
||||||
x if x > (XVB_ROUND_DONOR_VIP_MIN_HR as f32) => Some(RuntimeDonationLevel::DonorVIP),
|
|
||||||
x if x > (XVB_ROUND_DONOR_WHALE_MIN_HR as f32) => {
|
x if x > (XVB_ROUND_DONOR_WHALE_MIN_HR as f32) => {
|
||||||
Some(RuntimeDonationLevel::DonorWhale)
|
Some(RuntimeDonationLevel::DonorWhale)
|
||||||
}
|
}
|
||||||
x if x > (XVB_ROUND_DONOR_MEGA_MIN_HR as f32) => Some(RuntimeDonationLevel::DonorMega),
|
x if x > (XVB_ROUND_DONOR_VIP_MIN_HR as f32) => Some(RuntimeDonationLevel::DonorVIP),
|
||||||
|
x if x > (XVB_ROUND_DONOR_MIN_HR as f32) => Some(RuntimeDonationLevel::Donor),
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -481,18 +478,17 @@ impl<'a> Algorithm<'a> {
|
||||||
samples.0.iter().sum::<f32>() / samples.0.len() as f32
|
samples.0.iter().sum::<f32>() / samples.0.len() as f32
|
||||||
}
|
}
|
||||||
|
|
||||||
fn minimum_hashrate_share(difficulty: u64, mini: bool, p2pool_external_hashrate: f32) -> f32 {
|
fn minimum_hashrate_share(difficulty: u64, mini: bool) -> f32 {
|
||||||
let pws = if mini {
|
let pws = if mini {
|
||||||
BLOCK_PPLNS_WINDOW_MINI
|
BLOCK_PPLNS_WINDOW_MINI
|
||||||
} else {
|
} else {
|
||||||
BLOCK_PPLNS_WINDOW_MAIN
|
BLOCK_PPLNS_WINDOW_MAIN
|
||||||
};
|
};
|
||||||
let mut 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!("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() {
|
||||||
info!("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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue