node: handle errors, random p2p and api ports, optimize rwlock

This commit is contained in:
ardocrat
2024-05-14 17:36:49 +03:00
parent ad3bcd2e0a
commit ae5631a717
14 changed files with 301 additions and 178 deletions
+72 -2
View File
@@ -13,15 +13,16 @@
// limitations under the License.
use egui::{Margin, RichText, ScrollArea, Stroke};
use grin_servers::common::types::Error;
use crate::AppConfig;
use crate::gui::Colors;
use crate::gui::icons::{BRIEFCASE, DATABASE, DOTS_THREE_OUTLINE_VERTICAL, FACTORY, FADERS, GAUGE, POWER};
use crate::gui::icons::{ARROWS_COUNTER_CLOCKWISE, BRIEFCASE, DATABASE, DOTS_THREE_OUTLINE_VERTICAL, FACTORY, FADERS, GAUGE, POWER};
use crate::gui::platform::PlatformCallbacks;
use crate::gui::views::{ConnectionsContent, NetworkMetrics, NetworkMining, NetworkNode, NetworkSettings, Root, TitlePanel, View};
use crate::gui::views::network::types::{NetworkTab, NetworkTabType};
use crate::gui::views::types::{TitleContentType, TitleType};
use crate::node::Node;
use crate::node::{Node, NodeError};
use crate::wallet::ExternalConnection;
/// Network content.
@@ -267,4 +268,73 @@ impl NetworkContent {
AppConfig::toggle_node_autostart();
});
}
/// Draw integrated node error content.
pub fn node_error_ui(ui: &mut egui::Ui, e: NodeError) {
match e {
NodeError::Storage => {
View::center_content(ui, 156.0, |ui| {
ui.label(RichText::new(t!("network_node.error_clean"))
.size(16.0)
.color(Colors::RED)
);
ui.add_space(8.0);
let btn_txt = format!("{} {}",
ARROWS_COUNTER_CLOCKWISE,
t!("network_node.resync"));
View::button(ui, btn_txt, Colors::GOLD, || {
Node::clean_up_data();
Node::start();
});
ui.add_space(2.0);
});
return;
}
NodeError::P2P | NodeError::API => {
let msg_type = match e {
NodeError::API => "API",
_ => "P2P"
};
View::center_content(ui, 106.0, |ui| {
let text = t!(
"network_node.error_p2p_api",
"p2p_api" => msg_type,
"settings" => FADERS
);
ui.label(RichText::new(text)
.size(16.0)
.color(Colors::RED)
);
ui.add_space(2.0);
});
return;
}
NodeError::Configuration => {
View::center_content(ui, 106.0, |ui| {
ui.label(RichText::new(t!("network_node.error_config", "settings" => FADERS))
.size(16.0)
.color(Colors::RED)
);
ui.add_space(2.0);
});
}
NodeError::Unknown => {
View::center_content(ui, 156.0, |ui| {
ui.label(RichText::new(t!("network_node.error_unknown", "settings" => FADERS))
.size(16.0)
.color(Colors::RED)
);
ui.add_space(8.0);
let btn_txt = format!("{} {}",
ARROWS_COUNTER_CLOCKWISE,
t!("network_node.resync"));
View::button(ui, btn_txt, Colors::GOLD, || {
Node::clean_up_data();
Node::start();
});
ui.add_space(2.0);
});
}
}
}
}
+8 -1
View File
@@ -36,7 +36,13 @@ impl NetworkTab for NetworkMetrics {
}
fn ui(&mut self, ui: &mut egui::Ui, _: &mut eframe::Frame, _: &dyn PlatformCallbacks) {
let server_stats = Node::get_stats();
// Show an error content when available.
let node_err = Node::get_error();
if node_err.is_some() {
NetworkContent::node_error_ui(ui, node_err.unwrap());
return;
}
// Show message to enable node when it's not running.
if !Node::is_running() {
NetworkContent::disabled_node_ui(ui);
@@ -50,6 +56,7 @@ impl NetworkTab for NetworkMetrics {
}
// Show message when metrics are not available.
let server_stats = Node::get_stats();
if server_stats.is_none() || Node::is_restarting()
|| server_stats.as_ref().unwrap().diff_stats.height == 0 {
NetworkContent::loading_ui(ui, Some(t!("network_metrics.loading")));
+7 -1
View File
@@ -44,7 +44,12 @@ impl NetworkTab for NetworkMining {
}
fn ui(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame, cb: &dyn PlatformCallbacks) {
let server_stats = Node::get_stats();
// Show an error content when available.
let node_err = Node::get_error();
if node_err.is_some() {
NetworkContent::node_error_ui(ui, node_err.unwrap());
return;
}
// Show message to enable node when it's not running.
if !Node::is_running() {
@@ -59,6 +64,7 @@ impl NetworkTab for NetworkMining {
}
// Show message when mining is not available.
let server_stats = Node::get_stats();
if server_stats.is_none() || Node::is_restarting()
|| Node::get_sync_status().unwrap() != SyncStatus::NoSync {
NetworkContent::loading_ui(ui, Some(t!("network_mining.loading")));
+10 -2
View File
@@ -13,10 +13,11 @@
// limitations under the License.
use egui::{RichText, Rounding, ScrollArea};
use grin_servers::common::types::Error;
use grin_servers::PeerStats;
use crate::gui::Colors;
use crate::gui::icons::{AT, CUBE, DEVICES, FLOW_ARROW, HANDSHAKE, PACKAGE, PLUGS_CONNECTED, SHARE_NETWORK};
use crate::gui::icons::{ARROWS_COUNTER_CLOCKWISE, AT, CUBE, DEVICES, FLOW_ARROW, HANDSHAKE, PACKAGE, PLUGS_CONNECTED, SHARE_NETWORK};
use crate::gui::platform::PlatformCallbacks;
use crate::gui::views::{NetworkContent, Root, View};
use crate::gui::views::network::types::{NetworkTab, NetworkTabType};
@@ -32,7 +33,13 @@ impl NetworkTab for NetworkNode {
}
fn ui(&mut self, ui: &mut egui::Ui, _: &mut eframe::Frame, _: &dyn PlatformCallbacks) {
let server_stats = Node::get_stats();
// Show an error content when available.
let node_err = Node::get_error();
if node_err.is_some() {
NetworkContent::node_error_ui(ui, node_err.unwrap());
return;
}
// Show message to enable node when it's not running.
if !Node::is_running() {
NetworkContent::disabled_node_ui(ui);
@@ -40,6 +47,7 @@ impl NetworkTab for NetworkNode {
}
// Show loading spinner when stats are not available.
let server_stats = Node::get_stats();
if server_stats.is_none() || Node::is_restarting() || Node::is_stopping() {
NetworkContent::loading_ui(ui, None);
return;