From dce3b93aef240a36799c0b906518ba916d517b8a Mon Sep 17 00:00:00 2001 From: Cyrix126 Date: Sun, 6 Oct 2024 16:18:05 +0200 Subject: [PATCH] fix: detect when p2pool is synced even without restart --- src/helper/p2pool.rs | 18 ++---------------- src/utils/regex.rs | 8 +++----- 2 files changed, 5 insertions(+), 21 deletions(-) diff --git a/src/helper/p2pool.rs b/src/helper/p2pool.rs index da1e658..35f9239 100644 --- a/src/helper/p2pool.rs +++ b/src/helper/p2pool.rs @@ -812,23 +812,9 @@ impl PubP2poolApi { let (payouts_new, xmr_new) = Self::calc_payouts_and_xmr(&output_parse); // Check for "SYNCHRONIZED" only if we aren't already. if lock!(process).state == ProcessState::Syncing { - // How many times the word was captured. - let synchronized_captures = P2POOL_REGEX.synchronized.find_iter(&output_parse).count(); + // look for depth 0 - // If P2Pool receives shares before syncing, it will start mining on its own sidechain. - // In this instance, we technically are "synced" on block 1 and P2Pool will print "SYNCHRONIZED" - // although, that doesn't necessarily mean we're synced on main/mini-chain. - // - // So, if we find a `next block = 1`, that means we - // must look for at least 2 instances of "SYNCHRONIZED", - // one for the sidechain, one for main/mini. - if P2POOL_REGEX.next_height_1.is_match(&output_parse) { - if synchronized_captures > 1 { - lock!(process).state = ProcessState::Alive; - } - } else if synchronized_captures > 0 { - // if there is no `next block = 1`, fallback to - // just finding 1 instance of "SYNCHRONIZED". + if P2POOL_REGEX.depth_0.is_match(&output_parse) { lock!(process).state = ProcessState::Alive; } } diff --git a/src/utils/regex.rs b/src/utils/regex.rs index 130e674..dd968b7 100644 --- a/src/utils/regex.rs +++ b/src/utils/regex.rs @@ -90,8 +90,7 @@ pub struct P2poolRegex { pub block: Regex, pub block_int: Regex, pub block_comma: Regex, - pub synchronized: Regex, - pub next_height_1: Regex, + pub depth_0: Regex, } impl P2poolRegex { @@ -105,8 +104,7 @@ impl P2poolRegex { block: Regex::new("block [0-9]{7}").unwrap(), // Monero blocks will be 7 digits for... the next 10,379 years block_int: Regex::new("[0-9]{7}").unwrap(), block_comma: Regex::new("[0-9],[0-9]{3},[0-9]{3}").unwrap(), - synchronized: Regex::new("SYNCHRONIZED").unwrap(), - next_height_1: Regex::new("next height = 1").unwrap(), + depth_0: Regex::new("depth = 0").unwrap(), } } } @@ -305,7 +303,7 @@ mod test { assert_eq!(r.block.find(text).unwrap().as_str(), "block 1111111"); assert_eq!(r.block_int.find(text).unwrap().as_str(), "1111111"); assert_eq!(r.block_comma.find(text2).unwrap().as_str(), "1,111,111"); - assert_eq!(r.synchronized.find(text3).unwrap().as_str(), "SYNCHRONIZED"); + assert_eq!(r.depth_0.find(text3).unwrap().as_str(), "depth = 0"); } #[test]