From 8bcd3c1c8887bd9ea5b4cb57afad3a8e9c0be926 Mon Sep 17 00:00:00 2001 From: Anton Yemelyanov Date: Fri, 13 Sep 2024 05:45:37 +0300 Subject: [PATCH] node info --- core/resources/i18n/i18n.json | 1 + core/src/core.rs | 5 + core/src/events.rs | 3 + core/src/modules/overview.rs | 172 +++++++++++-------- core/src/runtime/services/kaspa/mod.rs | 2 + core/src/runtime/services/metrics_monitor.rs | 39 +++++ 6 files changed, 151 insertions(+), 71 deletions(-) diff --git a/core/resources/i18n/i18n.json b/core/resources/i18n/i18n.json index 8648840..326822f 100644 --- a/core/resources/i18n/i18n.json +++ b/core/resources/i18n/i18n.json @@ -3218,6 +3218,7 @@ "Export Wallet Data": "Export Wallet Data", "FIRST": "FIRST", "Faucet": "Faucet", + "Fee Market": "Fee Market", "Fee Market & Network Pressure": "Fee Market & Network Pressure", "Fee Market Only": "Fee Market Only", "Fee Rate Estimates": "Fee Rate Estimates", diff --git a/core/src/core.rs b/core/src/core.rs index a947d97..81928a5 100644 --- a/core/src/core.rs +++ b/core/src/core.rs @@ -61,6 +61,7 @@ pub struct Core { pub storage: Storage, // pub feerate : Option>, pub feerate: Option, + pub node_info: Option>, } impl Core { @@ -223,6 +224,7 @@ impl Core { notifications: Notifications::default(), storage, feerate: None, + node_info: None, // daemon_storage_root: Mutex::new(daemon_storage_root), }; @@ -783,6 +785,9 @@ impl Core { self.notifications.push(notification); } } + Events::NodeInfo { node_info } => { + self.node_info = node_info; + } Events::Close { .. } => {} Events::UnlockSuccess => {} Events::UnlockFailure { .. } => {} diff --git a/core/src/events.rs b/core/src/events.rs index e5c468a..c4a04ee 100644 --- a/core/src/events.rs +++ b/core/src/events.rs @@ -45,6 +45,9 @@ pub enum Events { Notify { user_notification: UserNotification, }, + NodeInfo { + node_info: Option>, + }, Close, Exit, } diff --git a/core/src/modules/overview.rs b/core/src/modules/overview.rs index 79b98f1..a4272bd 100644 --- a/core/src/modules/overview.rs +++ b/core/src/modules/overview.rs @@ -84,16 +84,22 @@ impl Overview { #[cfg(not(feature = "lean"))] fn render_stats(&mut self, core: &mut Core, ui : &mut Ui) { - CollapsingHeader::new(i18n("Kaspa p2p Node")) - .default_open(true) - .show(ui, |ui| { - - if core.state().is_connected() { - self.render_graphs(core,ui); - } else { - ui.label(i18n("Not connected")); - } - }); + let node_info = if let Some(node_info) = &core.node_info { + format!(" - {}", node_info) + } else { + "".to_string() + }; + + CollapsingHeader::new(format!("{}{}",i18n("Kaspa p2p Node"), node_info)) + .default_open(true) + .show(ui, |ui| { + + if core.state().is_connected() { + self.render_graphs(core,ui); + } else { + ui.label(i18n("Not connected")); + } + }); ui.add_space(48.); } @@ -182,68 +188,82 @@ impl Overview { format!("• {CLOUD} {}",i18n("Kaspa NG online")), "https://kaspa-ng.org" ); - }); - - CollapsingHeader::new(i18n("Mainnet")) - .default_open(true) - .show(ui, |ui| { - #[allow(unused_imports)] - use egui_phosphor::light::{YOUTUBE_LOGO,DISCORD_LOGO,TELEGRAM_LOGO,REDDIT_LOGO,CHART_SCATTER,NEWSPAPER_CLIPPING,DATABASE}; - - ui.hyperlink_to_tab( - format!("• {DATABASE} {}",i18n("Explorer")), - "https://explorer.kaspa.org/", - ); - ui.hyperlink_to_tab( - format!("• {CHART_SCATTER} {}",i18n("Statistics")), - "https://kas.fyi", - ); - // ui.hyperlink_to_tab( - // format!("• {DISCORD_LOGO} {}",i18n("Discord")), - // "https://discord.com/invite/kS3SK5F36R", - // ); - - if core.settings.node.network == Network::Mainnet { - self.render_fee_rate(core, ui); - } }); - if core.settings.node.network == Network::Testnet10 { - CollapsingHeader::new(i18n("Testnet 10")) - .default_open(true) - .show(ui, |ui| { - use egui_phosphor::light::{HAND_COINS,DATABASE}; - - ui.hyperlink_to_tab( - format!("• {DATABASE} {}",i18n("Explorer")), - "https://explorer-tn10.kaspa.org/", - ); - ui.hyperlink_to_tab( - format!("• {HAND_COINS} {}",i18n("Faucet")), - "https://faucet-testnet.kaspanet.io", - ); - - self.render_fee_rate(core, ui); - }); - } - - if core.settings.node.network == Network::Testnet11 { - CollapsingHeader::new(i18n("Testnet 11")) - .default_open(true) - .show(ui, |ui| { - use egui_phosphor::light::{HAND_COINS,DATABASE}; - - ui.hyperlink_to_tab( - format!("• {DATABASE} {}",i18n("Explorer")), - "https://explorer-tn11.kaspa.org/", - ); - ui.hyperlink_to_tab( - format!("• {HAND_COINS} {}",i18n("Faucet")), - "https://faucet-t11.kaspanet.io", - ); - - self.render_fee_rate(core, ui); - }); + match core.settings.node.network { + Network::Mainnet => { + CollapsingHeader::new(i18n("Mainnet")) + .default_open(true) + .show(ui, |ui| { + CollapsingHeader::new(i18n("Resources")) + .default_open(true) + .show(ui, |ui| { + #[allow(unused_imports)] + use egui_phosphor::light::{YOUTUBE_LOGO,DISCORD_LOGO,TELEGRAM_LOGO,REDDIT_LOGO,CHART_SCATTER,NEWSPAPER_CLIPPING,DATABASE}; + + ui.hyperlink_to_tab( + format!("• {DATABASE} {}",i18n("Explorer")), + "https://explorer.kaspa.org/", + ); + ui.hyperlink_to_tab( + format!("• {CHART_SCATTER} {}",i18n("Statistics")), + "https://kas.fyi", + ); + // ui.hyperlink_to_tab( + // format!("• {DISCORD_LOGO} {}",i18n("Discord")), + // "https://discord.com/invite/kS3SK5F36R", + // ); + + }); + self.render_network_info(core, ui); + self.render_fee_rate(core, ui); + }); + } + Network::Testnet10 => { + CollapsingHeader::new(i18n("Testnet 10")) + .default_open(true) + .show(ui, |ui| { + CollapsingHeader::new(i18n("Resources")) + .default_open(true) + .show(ui, |ui| { + use egui_phosphor::light::{HAND_COINS,DATABASE}; + + ui.hyperlink_to_tab( + format!("• {DATABASE} {}",i18n("Explorer")), + "https://explorer-tn10.kaspa.org/", + ); + ui.hyperlink_to_tab( + format!("• {HAND_COINS} {}",i18n("Faucet")), + "https://faucet-testnet.kaspanet.io", + ); + + }); + self.render_network_info(core, ui); + self.render_fee_rate(core, ui); + }); + } + Network::Testnet11 => { + CollapsingHeader::new(i18n("Testnet 11")) + .default_open(true) + .show(ui, |ui| { + CollapsingHeader::new(i18n("Resources")) + .default_open(true) + .show(ui, |ui| { + use egui_phosphor::light::{HAND_COINS,DATABASE}; + + ui.hyperlink_to_tab( + format!("• {DATABASE} {}",i18n("Explorer")), + "https://explorer-tn11.kaspa.org/", + ); + ui.hyperlink_to_tab( + format!("• {HAND_COINS} {}",i18n("Faucet")), + "https://faucet-t11.kaspanet.io", + ); + }); + self.render_network_info(core, ui); + self.render_fee_rate(core, ui); + }); + } } CollapsingHeader::new(i18n("Developer Resources")) @@ -394,12 +414,22 @@ impl Overview { }); } + fn render_network_info(&self, core: &Core, ui : &mut Ui) { + + CollapsingHeader::new(i18n("Statistics")) + .default_open(true) + .show(ui, |ui| { + ui.label(format!("Network Pressure: ~{}%", core.network_pressure.capacity())); + }); + } + fn render_fee_rate(&self, core: &Core, ui : &mut Ui) { + if let Some(fees) = core.feerate.as_ref() { let low = fees.low.value().feerate; let med = fees.economic.value().feerate; let high = fees.priority.value().feerate; - CollapsingHeader::new(i18n("Fee Rate Estimates")) + CollapsingHeader::new(i18n("Fee Market")) .default_open(true) .show(ui, |ui| { ui.label(format!("Low: {:.2} SOMPI/g", low)); diff --git a/core/src/runtime/services/kaspa/mod.rs b/core/src/runtime/services/kaspa/mod.rs index 7a4db2e..bc0ee39 100644 --- a/core/src/runtime/services/kaspa/mod.rs +++ b/core/src/runtime/services/kaspa/mod.rs @@ -604,6 +604,8 @@ impl KaspaService { CoreWalletEvents::DaaScoreChange { .. } => {} CoreWalletEvents::Connect { .. } => { self.connect_all_services().await?; + + // self.wallet(). } CoreWalletEvents::Disconnect { .. } => { self.disconnect_all_services().await?; diff --git a/core/src/runtime/services/metrics_monitor.rs b/core/src/runtime/services/metrics_monitor.rs index dbb656d..0528667 100644 --- a/core/src/runtime/services/metrics_monitor.rs +++ b/core/src/runtime/services/metrics_monitor.rs @@ -2,6 +2,7 @@ use crate::imports::*; use crate::runtime::Service; pub use futures::{future::FutureExt, select, Future}; use kaspa_metrics_core::{Metric, Metrics, MetricsSnapshot}; +use kaspa_rpc_core::GetSystemInfoResponse; #[allow(unused_imports)] use kaspa_wallet_core::rpc::{NotificationMode, Rpc, RpcCtl, WrpcEncoding}; @@ -14,6 +15,7 @@ pub struct MetricsService { pub metrics: Arc, pub metrics_data: Mutex>>, pub samples_since_connection: Arc, + pub rpc_api: Mutex>>, } impl MetricsService { @@ -29,9 +31,14 @@ impl MetricsService { metrics, metrics_data: Mutex::new(metrics_data), samples_since_connection: Arc::new(AtomicUsize::new(0)), + rpc_api: Mutex::new(None), } } + pub fn rpc_api(&self) -> Option> { + self.rpc_api.lock().unwrap().clone() + } + pub fn metrics_data(&self) -> MutexGuard<'_, HashMap>> { self.metrics_data.lock().unwrap() } @@ -111,6 +118,8 @@ impl Service for MetricsService { } async fn attach_rpc(self: Arc, rpc_api: &Arc) -> Result<()> { + self.rpc_api.lock().unwrap().replace(rpc_api.clone()); + let this = self.clone(); self.metrics .register_sink(Arc::new(Box::new(move |snapshot: MetricsSnapshot| { @@ -126,6 +135,8 @@ impl Service for MetricsService { Ok(()) } async fn detach_rpc(self: Arc) -> Result<()> { + self.rpc_api.lock().unwrap().take(); + self.metrics.unregister_sink(); self.metrics.stop_task().await?; self.metrics.bind_rpc(None); @@ -135,6 +146,34 @@ impl Service for MetricsService { async fn connect_rpc(self: Arc) -> Result<()> { self.samples_since_connection.store(0, Ordering::SeqCst); + + if let Some(rpc_api) = self.rpc_api() { + if let Ok(system_info) = rpc_api.get_system_info().await { + let GetSystemInfoResponse { + version, system_id, .. + } = system_info; + + let system_id = system_id + .map(|id| format!(" - {}", id[0..8].to_vec().to_hex())) + .unwrap_or_else(|| "".to_string()); + + self.application_events + .sender + .try_send(crate::events::Events::NodeInfo { + node_info: Some(Box::new(format!("{}{}", version, system_id))), + }) + .unwrap(); + } + } + + Ok(()) + } + + async fn disconnect_rpc(self: Arc) -> Result<()> { + self.application_events + .sender + .try_send(crate::events::Events::NodeInfo { node_info: None }) + .unwrap(); Ok(()) }