diff --git a/NOTES_ALGORITHM.md b/NOTES_ALGORITHM.md index d305172..90d3a7c 100644 --- a/NOTES_ALGORITHM.md +++ b/NOTES_ALGORITHM.md @@ -59,7 +59,7 @@ So 1kH/s is given to XvB node so that the miner participate in the Donor round. P2pool node (PN) local API show only found shares and not current. It is not also showing the current height block of p2pool. Gupaxx process will check every minute when a new share is found, and how much time passed since the last. While verifying if mining on mini or main chain, it will calculate if the last share found is still valid. This way Gupaxx will know if a share is currently in the window. -This method is only an estimation, a better way would be to know at which block the share is found and which block height the network is currently at. But P2pool API doesn't offer these informations by API but by command. +This method is only an estimation, a better way would be to know at which block the share is found and which block height the network is currently at. But P2pool API doesn't offer these information by API but by command. ### Knowing the HR generated by Gupaxx diff --git a/TODO_XMRvsBeast.md b/TODO_XMRvsBeast.md index 75cc2a6..9f2d973 100644 --- a/TODO_XMRvsBeast.md +++ b/TODO_XMRvsBeast.md @@ -26,8 +26,8 @@ - [ ] distribute hashrate conforming to the algorithm. - [x] check every 10 minutes average Xmrig HR of last 15 minutes - [ ] ask Xmrig to mine on p2pool - - [ ] generate token for xmrig - - [ ] enable xmrig with remote access control + - [x] generate token for xmrig + - [x] enable xmrig with remote access control - [x] check if at least a share in pplns Window - [ ] calculate spared HR - [ ] calculate time to be spared diff --git a/src/disk/state.rs b/src/disk/state.rs index 6e377ba..42faac6 100644 --- a/src/disk/state.rs +++ b/src/disk/state.rs @@ -1,7 +1,5 @@ -use anyhow::{Result}; - - - +use anyhow::Result; +use rand::{distributions::Alphanumeric, thread_rng, Rng}; use super::*; use crate::{components::node::RemoteNode, disk::status::*}; @@ -242,6 +240,7 @@ pub struct Xmrig { pub selected_rig: String, pub selected_ip: String, pub selected_port: String, + pub token: String, } #[derive(Clone, Eq, PartialEq, Debug, Deserialize, Serialize, Default)] @@ -363,6 +362,11 @@ impl Default for Xmrig { keepalive: false, current_threads: 1, max_threads: 1, + token: thread_rng() + .sample_iter(Alphanumeric) + .take(16) + .map(char::from) + .collect(), } } } diff --git a/src/disk/tests.rs b/src/disk/tests.rs index 3511665..66fabeb 100644 --- a/src/disk/tests.rs +++ b/src/disk/tests.rs @@ -96,6 +96,7 @@ mod test { selected_rig = "Gupax" selected_ip = "192.168.1.122" selected_port = "3333" + token = "testtoken" [xvb] token = "" diff --git a/src/helper/xmrig.rs b/src/helper/xmrig.rs index 9f00239..cb1da5b 100644 --- a/src/helper/xmrig.rs +++ b/src/helper/xmrig.rs @@ -141,8 +141,18 @@ impl Helper { let gui_api = Arc::clone(&lock!(helper).gui_api_xmrig); let pub_api = Arc::clone(&lock!(helper).pub_api_xmrig); let path = path.to_path_buf(); + let token = state.token.clone(); thread::spawn(move || { - Self::spawn_xmrig_watchdog(process, gui_api, pub_api, args, path, sudo, api_ip_port); + Self::spawn_xmrig_watchdog( + process, + gui_api, + pub_api, + args, + path, + sudo, + api_ip_port, + &token, + ); }); } @@ -189,6 +199,8 @@ impl Helper { args.push("127.0.0.1".to_string()); // HTTP API IP args.push("--http-port".to_string()); args.push("18088".to_string()); // HTTP API Port + args.push(format!("--http-access-token={}", state.token)); // HTTP API Port + args.push("--http-no-restricted".to_string()); if state.pause != 0 { args.push("--pause-on-active".to_string()); args.push(state.pause.to_string()); @@ -313,6 +325,7 @@ impl Helper { path: std::path::PathBuf, sudo: Arc>, mut api_ip_port: String, + token: &str, ) { // 1a. Create PTY debug!("XMRig | Creating PTY..."); @@ -543,10 +556,11 @@ impl Helper { start.elapsed(), &process, ); - // Send an HTTP API request debug!("XMRig Watchdog | Attempting HTTP API request..."); - if let Ok(priv_api) = PrivXmrigApi::request_xmrig_api(client.clone(), &api_uri).await { + if let Ok(priv_api) = + PrivXmrigApi::request_xmrig_api(client.clone(), &api_uri, token).await + { debug!("XMRig Watchdog | HTTP API request OK, attempting [update_from_priv()]"); PubXmrigApi::update_from_priv(&pub_api, priv_api); } else { @@ -729,9 +743,11 @@ impl PrivXmrigApi { async fn request_xmrig_api( client: hyper::Client, api_uri: &str, + token: &str, ) -> std::result::Result { let request = hyper::Request::builder() .method("GET") + .header("Authorization", ["Bearer ", token].concat()) .uri(api_uri) .body(hyper::Body::empty())?; let response = tokio::time::timeout( diff --git a/src/helper/xvb.rs b/src/helper/xvb.rs index 27ebdcd..bcd15b6 100644 --- a/src/helper/xvb.rs +++ b/src/helper/xvb.rs @@ -244,9 +244,9 @@ impl Helper { break; } } - debug!("XvB Watchdog | Attempting HTTP private API request..."); - // only if private API is accessible, NotMining here means that the token and address is not registered on the XvB website. + // only if private API is accessible, NotMining here means that the token and address is not registered on the XvB website and Syncing means P2pool node is not running and so that some information for private info are not available. if lock!(process).state == ProcessState::Alive { + debug!("XvB Watchdog | Attempting HTTP private API request..."); // reload private stats match XvbPrivStats::request_api( &client, @@ -328,6 +328,22 @@ impl Helper { { lock!(pub_api).stats_priv.win_current = true } + // if 10 minutes passed since last check + if lock!(gui_api).tick_distribute_hr > (60 * 10) { + // request XMrig to mine on P2pool + } + // if share is in PW, + // check average HR of last 15 minutes from XMrig. + // if HR + buffer >= mHR, + // calculate how much time can be spared + // if not hero option + // calculate how much time needed to be spared to be in most round type minimum HR + buffer + // fi + // sleep 10m less spared time then request XMrig to mine on XvB + // fi + // fi + // instant saved for next check + // fi } lock!(gui_api).tick = 0; @@ -356,6 +372,7 @@ pub struct PubXvbApi { pub output: String, pub uptime: u64, pub tick: u8, + pub tick_distribute_hr: u16, pub stats_pub: XvbPubStats, pub stats_priv: XvbPrivStats, } @@ -479,9 +496,11 @@ impl PubXvbApi { output.push_str(&buf); } let tick = std::mem::take(&mut gui_api.tick); + let tick_distribute_hr = std::mem::take(&mut gui_api.tick_distribute_hr); *gui_api = Self { output, tick, + tick_distribute_hr, ..pub_api.clone() }; }