Skip to content

Commit

Permalink
Merge branch 'omega-servers' of github.com:aspectron/kaspa-ng into omega
Browse files Browse the repository at this point in the history
  • Loading branch information
aspect committed Sep 9, 2024
2 parents 8827e95 + c4511a0 commit 1a12191
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 96 deletions.
2 changes: 0 additions & 2 deletions core/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,6 @@ impl Core {
module.init(&mut this);
});

load_public_servers();

this.wallet_update_list();

cfg_if! {
Expand Down
1 change: 0 additions & 1 deletion core/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ pub use crate::primitives::{
};
pub use crate::result::Result;
pub use crate::runtime::{runtime, spawn, spawn_with_result, Payload, Runtime, Service};
pub use crate::servers::{load_public_servers, public_servers, Server};
pub use crate::settings::{
KaspadNodeKind, NetworkInterfaceConfig, NetworkInterfaceKind, NodeConnectionConfigKind,
NodeMemoryScale, NodeSettings, RpcConfig, RpcOptions, Settings, UserInterfaceSettings,
Expand Down
1 change: 0 additions & 1 deletion core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ pub mod notifications;
pub mod primitives;
pub mod result;
pub mod runtime;
pub mod servers;
pub mod settings;
pub mod state;
pub mod status;
Expand Down
10 changes: 1 addition & 9 deletions core/src/modules/settings/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::imports::*;
use crate::servers::render_public_server_selector;

pub struct Settings {
#[allow(dead_code)]
Expand Down Expand Up @@ -29,7 +28,7 @@ impl Settings {
self.settings.node.network = network;
}

pub fn render_remote_settings(core: &mut Core, ui: &mut Ui, settings : &mut NodeSettings) -> Option<&'static str> {
pub fn render_remote_settings(_core: &mut Core, ui: &mut Ui, settings : &mut NodeSettings) -> Option<&'static str> {

let mut node_settings_error = None;

Expand Down Expand Up @@ -90,13 +89,6 @@ impl Settings {

},
NodeConnectionConfigKind::PublicServerCustom => {
CollapsingHeader::new(i18n("Public Node"))
.default_open(true)
.show(ui, |ui| {
if let Some(error) = render_public_server_selector(core, ui, settings) {
node_settings_error = Some(error);
}
});
},
NodeConnectionConfigKind::PublicServerRandom => {
ui.label(i18n("A random node will be selected on startup"));
Expand Down
39 changes: 13 additions & 26 deletions core/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ impl KaspadNodeKind {
#[derive(Default)]
pub struct RpcOptions {
pub blacklist_servers: Vec<String>,
pub force_server: Option<Server>,
}

impl RpcOptions {
Expand All @@ -124,11 +123,6 @@ impl RpcOptions {
self.blacklist_servers.push(server);
self
}

pub fn force(mut self, server: Server) -> Self {
self.force_server = Some(server);
self
}
}

#[derive(Default, Debug, Clone, Serialize, Deserialize, Eq, PartialEq)]
Expand Down Expand Up @@ -240,7 +234,7 @@ impl NodeConnectionConfigKind {
pub fn iter() -> impl Iterator<Item = &'static NodeConnectionConfigKind> {
[
NodeConnectionConfigKind::PublicServerRandom,
NodeConnectionConfigKind::PublicServerCustom,
// NodeConnectionConfigKind::PublicServerCustom,
NodeConnectionConfigKind::Custom,
// NodeConnectionConfigKind::Local,
]
Expand Down Expand Up @@ -357,7 +351,6 @@ impl NodeMemoryScale {
#[serde(rename_all = "kebab-case")]
pub struct NodeSettings {
pub connection_config_kind: NodeConnectionConfigKind,
pub public_servers: HashMap<Network, Server>,
pub rpc_kind: RpcKind,
pub wrpc_url: String,
pub wrpc_encoding: WrpcEncoding,
Expand All @@ -383,7 +376,6 @@ impl Default for NodeSettings {
fn default() -> Self {
Self {
connection_config_kind: NodeConnectionConfigKind::default(),
public_servers: HashMap::default(),
rpc_kind: RpcKind::Wrpc,
wrpc_url: "127.0.0.1".to_string(),
wrpc_encoding: WrpcEncoding::Borsh,
Expand Down Expand Up @@ -416,7 +408,6 @@ impl NodeSettings {
} else if self.memory_scale != other.memory_scale {
Some(true)
} else if self.connection_config_kind != other.connection_config_kind
|| (other.connection_config_kind == NodeConnectionConfigKind::PublicServerCustom && !self.public_servers.compare(&other.public_servers))
{
Some(true)
} else if self.kaspad_daemon_storage_folder_enable != other.kaspad_daemon_storage_folder_enable
Expand Down Expand Up @@ -449,9 +440,7 @@ impl NodeSettings {
Some(true)
} else if self.node_kind != other.node_kind {
Some(true)
} else if self.connection_config_kind != other.connection_config_kind
|| (other.connection_config_kind == NodeConnectionConfigKind::PublicServerCustom && !self.public_servers.compare(&other.public_servers))
{
} else if self.connection_config_kind != other.connection_config_kind {
Some(true)
} else if self.rpc_kind != other.rpc_kind
|| self.wrpc_url != other.wrpc_url
Expand Down Expand Up @@ -480,18 +469,8 @@ impl RpcConfig {
url: Some(settings.grpc_network_interface.clone()),
},
},
NodeConnectionConfigKind::PublicServerCustom => {
if let Some(public_server) = settings.public_servers.get(&settings.network) {
RpcConfig::Wrpc {
url: Some(public_server.address()),
encoding: public_server.wrpc_encoding(),
resolver_urls: None,
}
} else {
RpcConfig::default()
}
}
NodeConnectionConfigKind::PublicServerRandom => RpcConfig::Wrpc {
NodeConnectionConfigKind::PublicServerCustom
| NodeConnectionConfigKind::PublicServerRandom => RpcConfig::Wrpc {
url: None,
encoding: settings.wrpc_encoding,
resolver_urls: None,
Expand Down Expand Up @@ -663,10 +642,18 @@ impl Settings {
let storage = storage()?;
if storage.exists().await.unwrap_or(false) {
match read_json::<Self>(storage.filename()).await {
Ok(settings) => {
Ok(mut settings) => {
if settings.revision != SETTINGS_REVISION {
Ok(Self::default())
} else {
if matches!(
settings.node.connection_config_kind,
NodeConnectionConfigKind::PublicServerCustom
) {
settings.node.connection_config_kind =
NodeConnectionConfigKind::PublicServerRandom;
}

Ok(settings)
}
}
Expand Down
59 changes: 2 additions & 57 deletions core/src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,6 @@ impl<'core> Status<'core> {
}

fn render_connection_selector(&mut self, ui: &mut Ui) {
use egui_phosphor::light::CHECK;

let connection_selector = !self.core.module().modal()
&& self.core.settings.node.connection_config_kind.is_public();

Expand All @@ -131,73 +129,20 @@ impl<'core> Status<'core> {
}
});
} else {
let mut response =
let response =
ui.add(Label::new(RichText::new(i18n("CONNECTED"))).sense(Sense::click()));

let popup_id = PopupPanel::id(ui, "node_connection_selector_popup");

if !PopupPanel::is_open(ui, popup_id) {
response = response.on_hover_ui(|ui| {
response.on_hover_ui(|ui| {
if let Some(wrpc_url) = runtime().kaspa_service().rpc_url() {
ui.horizontal(|ui| {
ui.label(wrpc_url);
});
}
});
}

// We should not allow node selection when we use a random server
if self.core.settings.node.connection_config_kind
== NodeConnectionConfigKind::PublicServerRandom
{
return;
}

PopupPanel::new(
popup_id,
|_ui| response,
|ui, close| {
set_menu_style(ui.style_mut());

let wrpc_url = runtime().kaspa_service().rpc_url();
let public_servers = public_servers(&self.settings().node.network);
for server in public_servers.into_iter() {
let name = if Some(server.address()) == wrpc_url {
format!("{server} {CHECK}")
} else {
server.to_string()
};

if ui.button(name).clicked() {
*close = true;

match self.core.settings.node.connection_config_kind {
NodeConnectionConfigKind::PublicServerCustom => {
self.core
.settings
.node
.public_servers
.insert(self.core.settings.node.network, server.clone());
self.core.settings.store_sync().ok();
runtime()
.kaspa_service()
.update_services(&self.core.settings.node, None);
}
NodeConnectionConfigKind::PublicServerRandom => {
let options = RpcOptions::new().force(server);
runtime()
.kaspa_service()
.update_services(&self.core.settings.node, Some(options));
}
_ => {}
}
}
}
},
)
.with_min_width(140.0)
.with_above_or_below(AboveOrBelow::Above)
.build(ui);
}
}

Expand Down

0 comments on commit 1a12191

Please sign in to comment.