Skip to content

Commit

Permalink
node info
Browse files Browse the repository at this point in the history
  • Loading branch information
aspect committed Sep 13, 2024
1 parent dc1aab7 commit 8bcd3c1
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 71 deletions.
1 change: 1 addition & 0 deletions core/resources/i18n/i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions core/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ pub struct Core {
pub storage: Storage,
// pub feerate : Option<Arc<RpcFeeEstimate>>,
pub feerate: Option<FeerateEstimate>,
pub node_info: Option<Box<String>>,
}

impl Core {
Expand Down Expand Up @@ -223,6 +224,7 @@ impl Core {
notifications: Notifications::default(),
storage,
feerate: None,
node_info: None,
// daemon_storage_root: Mutex::new(daemon_storage_root),
};

Expand Down Expand Up @@ -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 { .. } => {}
Expand Down
3 changes: 3 additions & 0 deletions core/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ pub enum Events {
Notify {
user_notification: UserNotification,
},
NodeInfo {
node_info: Option<Box<String>>,
},
Close,
Exit,
}
172 changes: 101 additions & 71 deletions core/src/modules/overview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.);
}
Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -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));
Expand Down
2 changes: 2 additions & 0 deletions core/src/runtime/services/kaspa/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,8 @@ impl KaspaService {
CoreWalletEvents::DaaScoreChange { .. } => {}
CoreWalletEvents::Connect { .. } => {
self.connect_all_services().await?;

// self.wallet().
}
CoreWalletEvents::Disconnect { .. } => {
self.disconnect_all_services().await?;
Expand Down
39 changes: 39 additions & 0 deletions core/src/runtime/services/metrics_monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -14,6 +15,7 @@ pub struct MetricsService {
pub metrics: Arc<Metrics>,
pub metrics_data: Mutex<HashMap<Metric, Vec<PlotPoint>>>,
pub samples_since_connection: Arc<AtomicUsize>,
pub rpc_api: Mutex<Option<Arc<dyn RpcApi>>>,
}

impl MetricsService {
Expand All @@ -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<Arc<dyn RpcApi>> {
self.rpc_api.lock().unwrap().clone()
}

pub fn metrics_data(&self) -> MutexGuard<'_, HashMap<Metric, Vec<PlotPoint>>> {
self.metrics_data.lock().unwrap()
}
Expand Down Expand Up @@ -111,6 +118,8 @@ impl Service for MetricsService {
}

async fn attach_rpc(self: Arc<Self>, rpc_api: &Arc<dyn RpcApi>) -> 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| {
Expand All @@ -126,6 +135,8 @@ impl Service for MetricsService {
Ok(())
}
async fn detach_rpc(self: Arc<Self>) -> Result<()> {
self.rpc_api.lock().unwrap().take();

self.metrics.unregister_sink();
self.metrics.stop_task().await?;
self.metrics.bind_rpc(None);
Expand All @@ -135,6 +146,34 @@ impl Service for MetricsService {

async fn connect_rpc(self: Arc<Self>) -> 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<Self>) -> Result<()> {
self.application_events
.sender
.try_send(crate::events::Events::NodeInfo { node_info: None })
.unwrap();
Ok(())
}

Expand Down

0 comments on commit 8bcd3c1

Please sign in to comment.