diff --git a/src-tauri/binaries_versions_esmeralda.json b/src-tauri/binaries_versions_esmeralda.json index f92dc82a3..81fcba127 100644 --- a/src-tauri/binaries_versions_esmeralda.json +++ b/src-tauri/binaries_versions_esmeralda.json @@ -1,10 +1,10 @@ { "binaries": { "xmrig": "=6.22.0", - "mmproxy": "=1.9.1-pre.2", - "minotari_node": "=1.9.1-pre.2", - "wallet": "=1.9.1-pre.2", - "sha-p2pool": "=0.19.0", + "mmproxy": "=1.9.2-pre.0", + "minotari_node": "=1.9.2-pre.0", + "wallet": "=1.9.2-pre.0", + "sha-p2pool": "=0.20.0", "xtrgpuminer": "=0.2.10", "tor": "=13.5.7" } diff --git a/src-tauri/binaries_versions_nextnet.json b/src-tauri/binaries_versions_nextnet.json index 46626f7a3..880b0c72b 100644 --- a/src-tauri/binaries_versions_nextnet.json +++ b/src-tauri/binaries_versions_nextnet.json @@ -1,10 +1,10 @@ { "binaries": { "xmrig": "=6.22.0", - "mmproxy": "=1.9.1-rc.3", - "minotari_node": "=1.9.1-rc.3", - "wallet": "=1.9.1-rc.3", - "sha-p2pool": "=0.19.0", + "mmproxy": "=1.9.2-rc.0", + "minotari_node": "=1.9.2-rc.0", + "wallet": "=1.9.2-rc.0", + "sha-p2pool": "=0.20.0", "xtrgpuminer": "=0.2.10", "tor": "=13.5.7" } diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index 586bf330f..c2c082deb 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -33,7 +33,7 @@ use crate::external_dependencies::{ use crate::gpu_miner_adapter::{GpuMinerStatus, GpuNodeSource}; use crate::hardware::hardware_status_monitor::{HardwareStatusMonitor, PublicDeviceProperties}; use crate::internal_wallet::{InternalWallet, PaperWalletConfig}; -use crate::p2pool::models::{Connections, Stats}; +use crate::p2pool::models::{Connections, P2poolStats}; use crate::progress_tracker::ProgressTracker; use crate::tor_adapter::TorConfig; use crate::utils::shutdown_utils::stop_all_processes; @@ -523,29 +523,13 @@ pub async fn get_monero_seed_words( #[tauri::command] pub async fn get_p2pool_stats( state: tauri::State<'_, UniverseAppState>, -) -> Result, String> { +) -> Result, String> { let timer = Instant::now(); - if state.is_getting_p2pool_stats.load(Ordering::SeqCst) { - let read = state.cached_p2pool_stats.read().await; - if let Some(stats) = &*read { - warn!(target: LOG_TARGET, "Already getting p2pool stats, returning cached value"); - return Ok(stats.clone()); - } - warn!(target: LOG_TARGET, "Already getting p2pool stats"); - return Err("Already getting p2pool stats".to_string()); - } - state.is_getting_p2pool_stats.store(true, Ordering::SeqCst); - let p2pool_stats = state.p2pool_manager.get_stats().await.unwrap_or_else(|e| { - warn!(target: LOG_TARGET, "Error getting p2pool stats: {}", e); - None - }); + let p2pool_stats = state.p2pool_latest_status.borrow().clone(); if timer.elapsed() > MAX_ACCEPTABLE_COMMAND_TIME { warn!(target: LOG_TARGET, "get_p2pool_stats took too long: {:?}", timer.elapsed()); } - let mut lock = state.cached_p2pool_stats.write().await; - *lock = Some(p2pool_stats.clone()); - state.is_getting_p2pool_stats.store(false, Ordering::SeqCst); Ok(p2pool_stats) } diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 1f2cda715..6b9f2657b 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -72,7 +72,7 @@ use crate::gpu_miner::GpuMiner; use crate::internal_wallet::InternalWallet; use crate::mm_proxy_manager::{MmProxyManager, StartConfig}; use crate::node_manager::NodeManager; -use crate::p2pool::models::Stats; +use crate::p2pool::models::P2poolStats; use crate::p2pool_manager::{P2poolConfig, P2poolManager}; use crate::tor_manager::TorManager; use crate::utils::auto_rollback::AutoRollback; @@ -578,7 +578,7 @@ struct UniverseAppState { base_node_latest_status: Arc>, wallet_latest_balance: Arc>>, gpu_latest_status: Arc>, - is_getting_p2pool_stats: Arc, + p2pool_latest_status: Arc>>, is_getting_p2pool_connections: Arc, is_getting_miner_metrics: Arc, is_getting_transaction_history: Arc, @@ -599,7 +599,6 @@ struct UniverseAppState { p2pool_manager: P2poolManager, tor_manager: TorManager, updates_manager: UpdatesManager, - cached_p2pool_stats: Arc>>>, cached_p2pool_connections: Arc>>>, cached_miner_metrics: Arc>>, setup_counter: Arc>>, @@ -637,7 +636,8 @@ fn main() { let (wallet_watch_tx, wallet_watch_rx) = watch::channel::>(None); let wallet_manager = WalletManager::new(node_manager.clone(), wallet_watch_tx); let wallet_manager2 = wallet_manager.clone(); - let p2pool_manager = P2poolManager::new(); + let (p2pool_stats_tx, p2pool_stats_rx) = watch::channel(None); + let p2pool_manager = P2poolManager::new(p2pool_stats_tx); let cpu_config = Arc::new(RwLock::new(CpuMinerConfig { node_connection: CpuMinerConnection::BuiltInProxy, @@ -664,9 +664,9 @@ fn main() { app_config.clone(), app_in_memory_config.clone(), Some(Network::default()), - p2pool_manager.clone(), gpu_status_rx.clone(), base_node_watch_rx.clone(), + p2pool_stats_rx.clone(), ); let updates_manager = UpdatesManager::new(app_config.clone(), shutdown.to_signal()); @@ -677,11 +677,11 @@ fn main() { let app_state = UniverseAppState { stop_start_mutex: Arc::new(Mutex::new(())), is_getting_miner_metrics: Arc::new(AtomicBool::new(false)), - is_getting_p2pool_stats: Arc::new(AtomicBool::new(false)), is_getting_p2pool_connections: Arc::new(AtomicBool::new(false)), base_node_latest_status: Arc::new(base_node_watch_rx), wallet_latest_balance: Arc::new(wallet_watch_rx), gpu_latest_status: Arc::new(gpu_status_rx), + p2pool_latest_status: Arc::new(p2pool_stats_rx), is_setup_finished: Arc::new(RwLock::new(false)), is_getting_transaction_history: Arc::new(AtomicBool::new(false)), config: app_config.clone(), @@ -700,7 +700,6 @@ fn main() { airdrop_access_token: Arc::new(RwLock::new(None)), tor_manager: TorManager::new(), updates_manager, - cached_p2pool_stats: Arc::new(RwLock::new(None)), cached_p2pool_connections: Arc::new(RwLock::new(None)), cached_miner_metrics: Arc::new(RwLock::new(None)), setup_counter: Arc::new(RwLock::new(AutoRollback::new(false))), diff --git a/src-tauri/src/p2pool/models.rs b/src-tauri/src/p2pool/models.rs index 17dd4ff63..c2475a445 100644 --- a/src-tauri/src/p2pool/models.rs +++ b/src-tauri/src/p2pool/models.rs @@ -66,12 +66,14 @@ pub(crate) struct ConnectionCounters { } #[derive(Debug, Serialize, Deserialize, Clone)] -pub struct Stats { +pub struct P2poolStats { pub connection_info: ConnectionInfo, pub connected_since: Option, pub randomx_stats: ChainStats, pub sha3x_stats: ChainStats, pub last_gossip_message: EpochTime, + pub peer_id: String, + pub squad: String, } #[derive(Debug, Serialize, Deserialize, Clone)] diff --git a/src-tauri/src/p2pool/stats_client.rs b/src-tauri/src/p2pool/stats_client.rs index 6c6966282..9cdff008a 100644 --- a/src-tauri/src/p2pool/stats_client.rs +++ b/src-tauri/src/p2pool/stats_client.rs @@ -20,7 +20,7 @@ // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE // USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -use crate::p2pool::models::{Connections, Stats}; +use crate::p2pool::models::{Connections, P2poolStats}; use anyhow::Error; use log::warn; @@ -37,10 +37,10 @@ impl Client { } } - pub async fn stats(&self) -> Result { + pub async fn stats(&self) -> Result { let stats = reqwest::get(format!("{}/stats", self.stats_server_address)) .await? - .json::() + .json::() .await .inspect_err(|e| warn!(target: LOG_TARGET, "P2pool stats error: {:?}", e))?; Ok(stats) diff --git a/src-tauri/src/p2pool_adapter.rs b/src-tauri/src/p2pool_adapter.rs index b826319a7..d0863a1ef 100644 --- a/src-tauri/src/p2pool_adapter.rs +++ b/src-tauri/src/p2pool_adapter.rs @@ -28,9 +28,10 @@ use std::collections::HashMap; use std::path::PathBuf; use tari_common::configuration::Network; use tari_shutdown::Shutdown; +use tokio::sync::watch; use crate::p2pool; -use crate::p2pool::models::{Connections, Stats}; +use crate::p2pool::models::{Connections, P2poolStats}; use crate::p2pool_manager::P2poolConfig; use crate::process_adapter::HealthStatus; use crate::process_adapter::ProcessStartupSpec; @@ -45,11 +46,15 @@ const LOG_TARGET: &str = "tari::universe::p2pool_adapter"; pub struct P2poolAdapter { pub(crate) config: Option, + stats_broadcast: watch::Sender>, } impl P2poolAdapter { - pub fn new() -> Self { - Self { config: None } + pub fn new(stats_broadcast: watch::Sender>) -> Self { + Self { + config: None, + stats_broadcast, + } } #[allow(dead_code)] @@ -136,7 +141,10 @@ impl ProcessAdapter for P2poolAdapter { name: "P2pool".to_string(), }, }, - P2poolStatusMonitor::new(format!("http://127.0.0.1:{}", config.stats_server_port)), + P2poolStatusMonitor::new( + format!("http://127.0.0.1:{}", config.stats_server_port), + self.stats_broadcast.clone(), + ), )) } @@ -152,12 +160,17 @@ impl ProcessAdapter for P2poolAdapter { #[derive(Clone)] pub struct P2poolStatusMonitor { stats_client: p2pool::stats_client::Client, + latest_status_broadcast: watch::Sender>, } impl P2poolStatusMonitor { - pub fn new(stats_server_addr: String) -> Self { + pub fn new( + stats_server_addr: String, + stats_broadcast: watch::Sender>, + ) -> Self { Self { stats_client: p2pool::stats_client::Client::new(stats_server_addr), + latest_status_broadcast: stats_broadcast, } } } @@ -166,7 +179,7 @@ impl P2poolStatusMonitor { impl StatusMonitor for P2poolStatusMonitor { async fn check_health(&self) -> HealthStatus { match self.stats_client.stats().await { - Ok(_stats) => { + Ok(stats) => { // if stats // .connection_info // .network_info @@ -187,6 +200,7 @@ impl StatusMonitor for P2poolStatusMonitor { // warn!(target: LOG_TARGET, "P2pool last gossip message was more than 60 seconds ago, health check warning"); // return HealthStatus::Warning; // } + let _unused = self.latest_status_broadcast.send(Some(stats)); HealthStatus::Healthy } @@ -199,7 +213,7 @@ impl StatusMonitor for P2poolStatusMonitor { } impl P2poolStatusMonitor { - pub async fn status(&self) -> Result { + pub async fn status(&self) -> Result { self.stats_client.stats().await } diff --git a/src-tauri/src/p2pool_manager.rs b/src-tauri/src/p2pool_manager.rs index 1277e98c3..6e8096662 100644 --- a/src-tauri/src/p2pool_manager.rs +++ b/src-tauri/src/p2pool_manager.rs @@ -27,10 +27,10 @@ use std::time::Duration; use futures_util::future::FusedFuture; use log::warn; use tari_shutdown::ShutdownSignal; -use tokio::sync::RwLock; +use tokio::sync::{watch, RwLock}; use tokio::time::sleep; -use crate::p2pool::models::{Connections, Stats}; +use crate::p2pool::models::{Connections, P2poolStats}; use crate::p2pool_adapter::P2poolAdapter; use crate::port_allocator::PortAllocator; use crate::process_watcher::ProcessWatcher; @@ -109,8 +109,8 @@ pub struct P2poolManager { } impl P2poolManager { - pub fn new() -> Self { - let adapter = P2poolAdapter::new(); + pub fn new(stats_broadcast: watch::Sender>) -> Self { + let adapter = P2poolAdapter::new(stats_broadcast); let mut process_watcher = ProcessWatcher::new(adapter); process_watcher.expected_startup_time = Duration::from_secs(30); @@ -119,15 +119,6 @@ impl P2poolManager { } } - pub async fn get_stats(&self) -> Result, anyhow::Error> { - let process_watcher = self.watcher.read().await; - if let Some(status_monitor) = &process_watcher.status_monitor { - Ok(Some(status_monitor.status().await?)) - } else { - Ok(None) - } - } - pub async fn get_connections(&self) -> Result, anyhow::Error> { let process_watcher = self.watcher.read().await; if let Some(status_monitor) = &process_watcher.status_monitor { diff --git a/src-tauri/src/telemetry_manager.rs b/src-tauri/src/telemetry_manager.rs index 0639fd919..592ed5c6c 100644 --- a/src-tauri/src/telemetry_manager.rs +++ b/src-tauri/src/telemetry_manager.rs @@ -24,6 +24,7 @@ use crate::app_in_memory_config::AppInMemoryConfig; use crate::gpu_miner_adapter::GpuMinerStatus; use crate::hardware::hardware_status_monitor::HardwareStatusMonitor; use crate::node_adapter::BaseNodeStatus; +use crate::p2pool::models::P2poolStats; use crate::p2pool_manager::{self, P2poolManager}; use crate::{ app_config::{AppConfig, MiningMode}, @@ -203,10 +204,10 @@ pub struct TelemetryManager { in_memory_config: Arc>, pub cancellation_token: CancellationToken, node_network: Option, - p2pool_manager: P2poolManager, airdrop_access_token: Arc>>, gpu_status: watch::Receiver, node_status: watch::Receiver, + p2pool_status: watch::Receiver>, } impl TelemetryManager { @@ -215,9 +216,9 @@ impl TelemetryManager { config: Arc>, in_memory_config: Arc>, network: Option, - p2pool_manager: P2poolManager, gpu_status: watch::Receiver, node_status: watch::Receiver, + p2pool_status: watch::Receiver>, ) -> Self { let cancellation_token = CancellationToken::new(); Self { @@ -226,10 +227,10 @@ impl TelemetryManager { cancellation_token, node_network: network, in_memory_config, - p2pool_manager, airdrop_access_token: Arc::new(RwLock::new(None)), gpu_status, node_status, + p2pool_status, } } @@ -298,12 +299,12 @@ impl TelemetryManager { let cpu_miner = self.cpu_miner.clone(); let gpu_status = self.gpu_status.clone(); let node_status = self.node_status.clone(); + let p2pool_status = self.p2pool_status.clone(); let config = self.config.clone(); let cancellation_token: CancellationToken = self.cancellation_token.clone(); let network = self.node_network; let config_cloned = self.config.clone(); let in_memory_config_cloned = self.in_memory_config.clone(); - let p2pool_manager_cloned = self.p2pool_manager.clone(); let airdrop_access_token = self.airdrop_access_token.clone(); tokio::spawn(async move { tokio::select! { @@ -313,7 +314,7 @@ impl TelemetryManager { let telemetry_collection_enabled = config_cloned.read().await.allow_telemetry(); if telemetry_collection_enabled { let airdrop_access_token_validated = validate_jwt(airdrop_access_token.clone()).await; - let telemetry_data = get_telemetry_data(&cpu_miner, &gpu_status, &node_status, &p2pool_manager_cloned, &config, network).await; + let telemetry_data = get_telemetry_data(&cpu_miner, &gpu_status, &node_status, &p2pool_status, &config, network).await; let airdrop_api_url = in_memory_config_cloned.read().await.airdrop_api_url.clone(); handle_telemetry_data(telemetry_data, airdrop_api_url, airdrop_access_token_validated, window.clone()).await; } @@ -372,7 +373,7 @@ async fn get_telemetry_data( cpu_miner: &RwLock, gpu_latest_miner_stats: &watch::Receiver, node_latest_status: &watch::Receiver, - p2pool_manager: &p2pool_manager::P2poolManager, + p2pool_latest_status: &watch::Receiver>, config: &RwLock, network: Option, ) -> Result { @@ -406,10 +407,7 @@ async fn get_telemetry_data( .await .ok(); - let p2pool_stats = p2pool_manager.get_stats().await.inspect_err(|e| { - warn!(target: LOG_TARGET, "Error getting p2pool stats: {:?}", e); - }); - let p2pool_stats = p2pool_stats.unwrap_or_default(); + let p2pool_stats = p2pool_latest_status.borrow().clone(); let config_guard = config.read().await; let is_mining_active = is_synced && (cpu.hash_rate > 0.0 || gpu_status.hash_rate > 0); @@ -484,7 +482,7 @@ async fn get_telemetry_data( // let p2pool_gpu_stats_sha3 = p2pool_stats.as_ref().map(|s| s.sha3x_stats.clone()); // let p2pool_cpu_stats_randomx = p2pool_stats.as_ref().map(|s| s.randomx_stats.clone()); - let p2pool_enabled = config_guard.p2pool_enabled() && p2pool_manager.is_running().await; + let p2pool_enabled = config_guard.p2pool_enabled() && p2pool_stats.is_some(); // let (cpu_tribe_name, cpu_tribe_id) = if p2pool_enabled { // if let Some(randomx_stats) = p2pool_cpu_stats_randomx { // ( @@ -528,6 +526,7 @@ async fn get_telemetry_data( "config_tor_enabled".to_string(), config_guard.use_tor().to_string(), ); + let mut squad = None; if let Some(stats) = p2pool_stats.as_ref() { extra_data.insert( "p2pool_connected_peers".to_string(), @@ -541,6 +540,8 @@ async fn get_telemetry_data( "p2pool_sha3_height".to_string(), stats.sha3x_stats.height.to_string(), ); + extra_data.insert("p2pool_squad".to_string(), stats.squad.clone()); + squad = Some(stats.squad.clone()); } if !all_cpus.is_empty() { @@ -565,9 +566,9 @@ async fn get_telemetry_data( resource_used, version, p2pool_enabled, - cpu_tribe_name: None, + cpu_tribe_name: squad.clone(), cpu_tribe_id: None, - gpu_tribe_name: None, + gpu_tribe_name: squad.clone(), gpu_tribe_id: None, extra_data, current_os: std::env::consts::OS.to_string(),