From 9092b5cd91a0fc1fa7b58a86f9e99d0194fbb80a Mon Sep 17 00:00:00 2001 From: Cyrix126 Date: Fri, 27 Dec 2024 17:25:47 +0100 Subject: [PATCH] fix: green status p2pool when node offline limit minimum log verbosity of P2Pool to 2 The user could always set log_level 1 or 0 in command args in advanced tab and break detection of errors. --- src/app/panels/middle/p2pool/advanced.rs | 4 ++-- src/helper/p2pool.rs | 21 +++++++++++++++++++-- src/utils/regex.rs | 15 +++++++++++++++ 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/app/panels/middle/p2pool/advanced.rs b/src/app/panels/middle/p2pool/advanced.rs index 619dcc4..72f8993 100644 --- a/src/app/panels/middle/p2pool/advanced.rs +++ b/src/app/panels/middle/p2pool/advanced.rs @@ -107,10 +107,10 @@ impl P2pool { ui.add_space(SPACE); slider_state_field( ui, - "Log level [ 0-6 ]:", + "Log level [ 2-6 ]:", P2POOL_LOG, &mut self.log_level, - 0..=6, + 2..=6, ); }) }); diff --git a/src/helper/p2pool.rs b/src/helper/p2pool.rs index a20ef52..6a7dff1 100644 --- a/src/helper/p2pool.rs +++ b/src/helper/p2pool.rs @@ -12,9 +12,11 @@ use crate::helper::signal_end; use crate::helper::sleep_end_loop; use crate::regex::P2POOL_REGEX; use crate::regex::contains_end_status; +use crate::regex::contains_newchain_tip; use crate::regex::contains_statuscommand; use crate::regex::contains_yourhashrate; use crate::regex::contains_yourshare; +use crate::regex::contains_zmq_failure; use crate::regex::estimated_hr; use crate::regex::nb_current_shares; use crate::{ @@ -370,6 +372,12 @@ impl Helper { } else { &state.ip }; + // log level of p2pool must be minimum 2 so Gupaxx works correctly. + let log_level = if state.log_level < 2 { + 2 + } else { + state.log_level + }; args.push("--wallet".to_string()); args.push(state.address.clone()); // Wallet args.push("--host".to_string()); @@ -379,7 +387,7 @@ impl Helper { args.push("--zmq-port".to_string()); args.push(state.zmq.to_string()); // ZMQ args.push("--loglevel".to_string()); - args.push(state.log_level.to_string()); // Log Level + args.push(log_level.to_string()); // Log Level args.push("--out-peers".to_string()); args.push(state.out_peers.to_string()); // Out Peers args.push("--in-peers".to_string()); @@ -859,7 +867,7 @@ impl PubP2poolApi { // 2. Parse the full STDOUT let mut output_parse = output_parse.lock().unwrap(); let (payouts_new, xmr_new) = Self::calc_payouts_and_xmr(&output_parse); - // Check for "SYNCHRONIZED" only if we aren't already. + // Check for "SYNCHRONIZED" only if we aren't already. Works at level 0 and above. if process.state == ProcessState::Syncing { // How many times the word was captured. let synchronized_captures = P2POOL_REGEX.synchronized.find_iter(&output_parse).count(); @@ -880,6 +888,15 @@ impl PubP2poolApi { // just finding 1 instance of "SYNCHRONIZED". process.state = ProcessState::Alive; } + // if the p2pool node was synced but is not anymore due to faulty monero node and is synced again, the status must be alive again + // required log level 2 minimum + if contains_newchain_tip(&output_parse) { + process.state = ProcessState::Alive; + } + } + // if the node is offline, p2pool can not function properly. Requires at least p2pool log level 1 + if process.state == ProcessState::Alive && contains_zmq_failure(&output_parse) { + process.state = ProcessState::Syncing; } // 3. Throw away [output_parse] diff --git a/src/utils/regex.rs b/src/utils/regex.rs index c7bb7b2..5196eb0 100644 --- a/src/utils/regex.rs +++ b/src/utils/regex.rs @@ -277,6 +277,21 @@ pub fn contains_end_status(l: &str) -> bool { static LINE_SHARE: Lazy = Lazy::new(|| Regex::new(r"^Uptime ").unwrap()); LINE_SHARE.is_match(l) } +// P2Pool +/// if the node is disconnected +/// this error will be present if log > 1 and Node is disconnected +pub fn contains_zmq_failure(l: &str) -> bool { + static LINE_SHARE: Lazy = Lazy::new(|| { + Regex::new(r"(p2pool with offline node: failed: error Error (empty response)|ZMQReader failed to connect to|P2Pool Couldn't restart ZMQ reader: exception Operation cannot be accomplished in current state)").unwrap() + }); + LINE_SHARE.is_match(l) +} +/// a way to detect that p2pool is alive +pub fn contains_newchain_tip(l: &str) -> bool { + static LINE_SHARE: Lazy = Lazy::new(|| Regex::new(r"new chain tip").unwrap()); + LINE_SHARE.is_match(l) +} + //---------------------------------------------------------------------------------------------------- TEST #[cfg(test)] mod test {