diff --git a/core/src/core.rs b/core/src/core.rs index 7b0b2c2..bcaac9b 100644 --- a/core/src/core.rs +++ b/core/src/core.rs @@ -332,7 +332,6 @@ impl Core { .expect("Unknown module"); if self.module.type_id() != module.type_id() { - let next = module.clone(); self.stack.push_back(self.module.clone()); diff --git a/core/src/modules/block_dag.rs b/core/src/modules/block_dag.rs index a46f84e..03a89af 100644 --- a/core/src/modules/block_dag.rs +++ b/core/src/modules/block_dag.rs @@ -9,11 +9,15 @@ use egui_plot::{ pub struct BlockDag { #[allow(dead_code)] runtime: Runtime, + daa_cursor: f64, + last_daa_score : u64, + running : bool, + } impl BlockDag { pub fn new(runtime: Runtime) -> Self { - Self { runtime } + Self { runtime, daa_cursor : 0.0, last_daa_score : 0, running : false } } } @@ -36,6 +40,24 @@ impl ModuleT for BlockDag { ui.separator(); let current_daa_score = core.state().current_daa_score().unwrap_or_default(); + if self.last_daa_score != current_daa_score { + + if !self.running { + self.running = true; + self.daa_cursor = current_daa_score as f64; + } + + self.last_daa_score = current_daa_score; + } + + let delta = 0.005; + let diff = current_daa_score as f64 - self.daa_cursor; + let step = diff * delta; + self.daa_cursor += step; + if diff > 0.01 { + crate::runtime::try_runtime().unwrap().request_repaint(); + } + let graph_width = ui.available_width(); let graph_height = ui.available_height(); @@ -43,13 +65,17 @@ impl ModuleT for BlockDag { .legend(Legend::default()) .width(graph_width) .height(graph_height) - .include_x(current_daa_score as f64 + 10.) - .include_x(current_daa_score as f64 - 70.) - .include_y(100.) - .include_y(-100.) + .include_x(self.daa_cursor + 8.) + .include_x(self.daa_cursor - 20.) + // .include_x(self.daa_cursor + 30.) + // .include_x(self.daa_cursor - 150.) + .include_y(15.) + .include_y(-15.) + // .include_y(100.) + // .include_y(-100.) // .auto_bounds_x() // .auto_bounds_y() - .data_aspect(1.) + .data_aspect(0.3) .y_axis_width(4) .show_axes(true) .show_grid(true) @@ -106,10 +132,10 @@ impl ModuleT for BlockDag { let d = 1.5; let points: PlotPoints = [ - [x+d, y+d], - [x-d, y+d], - [x-d, y-d], - [x+d, y-d], + [x+d*0.3, y+d], + [x-d*0.3, y+d], + [x-d*0.3, y-d], + [x+d*0.3, y-d], ].to_vec().into(); Polygon::new(points) diff --git a/core/src/modules/mod.rs b/core/src/modules/mod.rs index 0b35e75..1b6b3bd 100644 --- a/core/src/modules/mod.rs +++ b/core/src/modules/mod.rs @@ -8,7 +8,6 @@ kaspa_ng_macros::register_modules!( about, account_create, account_manager, - block_dag, changelog, deposit, export, @@ -26,7 +25,7 @@ kaspa_ng_macros::register_modules!( ); #[cfg(not(target_arch = "wasm32"))] -kaspa_ng_macros::register_modules!(register_native_modules, [logs, metrics, node,]); +kaspa_ng_macros::register_modules!(register_native_modules, [logs, metrics, node, block_dag,]); pub enum ModuleStyle { Large, diff --git a/core/src/runtime/mod.rs b/core/src/runtime/mod.rs index f377451..e5f7d7e 100644 --- a/core/src/runtime/mod.rs +++ b/core/src/runtime/mod.rs @@ -47,7 +47,10 @@ impl Runtime { settings, )); let metrics_service = Arc::new(MetricsService::new(application_events.clone(), settings)); - let block_dag_monitor_service = Arc::new(BlockDagMonitorService::new(application_events.clone(), settings)); + let block_dag_monitor_service = Arc::new(BlockDagMonitorService::new( + application_events.clone(), + settings, + )); let plugin_manager_service = Arc::new(PluginManagerService::new( application_events.clone(), settings, diff --git a/core/src/runtime/services/blockdag_monitor.rs b/core/src/runtime/services/blockdag_monitor.rs index e5131a1..1a2c59d 100644 --- a/core/src/runtime/services/blockdag_monitor.rs +++ b/core/src/runtime/services/blockdag_monitor.rs @@ -1,8 +1,8 @@ use crate::imports::*; -use kaspa_rpc_core::RpcBlock; -use kaspa_rpc_core::notify::connection::{ChannelConnection, ChannelType}; +use kaspa_notify::{listener::ListenerId, scope::*}; use kaspa_rpc_core::api::notifications::Notification; -use kaspa_notify::{scope::*, listener::ListenerId}; +use kaspa_rpc_core::notify::connection::{ChannelConnection, ChannelType}; +use kaspa_rpc_core::RpcBlock; pub enum BlockDagMonitorEvents { Exit, @@ -35,12 +35,22 @@ impl BlockDagMonitorService { pub async fn register_notification_listener(&self) -> Result<()> { if let Some(rpc_api) = self.rpc_api() { - let listener_id = - rpc_api - .register_new_listener(ChannelConnection::new(self.notification_channel.sender.clone(), ChannelType::Persistent)); - *self.listener_id.lock().unwrap() = Some(listener_id); - rpc_api.start_notify(listener_id, Scope::BlockAdded(BlockAddedScope { })).await?; - rpc_api.start_notify(listener_id, Scope::VirtualChainChanged(VirtualChainChangedScope { include_accepted_transaction_ids: false })).await?; + let listener_id = rpc_api.register_new_listener(ChannelConnection::new( + self.notification_channel.sender.clone(), + ChannelType::Persistent, + )); + *self.listener_id.lock().unwrap() = Some(listener_id); + rpc_api + .start_notify(listener_id, Scope::BlockAdded(BlockAddedScope {})) + .await?; + rpc_api + .start_notify( + listener_id, + Scope::VirtualChainChanged(VirtualChainChangedScope { + include_accepted_transaction_ids: false, + }), + ) + .await?; } Ok(()) @@ -48,7 +58,7 @@ impl BlockDagMonitorService { pub async fn unregister_notification_listener(&self) -> Result<()> { if let Some(rpc_api) = self.rpc_api() { - let listener_id = self.listener_id.lock().unwrap().take(); + let listener_id = self.listener_id.lock().unwrap().take(); if let Some(id) = listener_id { // we do not need this as we are unregister the entire listener here... rpc_api.unregister_listener(id).await?; @@ -57,11 +67,9 @@ impl BlockDagMonitorService { Ok(()) } - pub fn rpc_api(&self) -> Option> { self.rpc_api.lock().unwrap().clone() } - } #[async_trait] @@ -70,18 +78,18 @@ impl Service for BlockDagMonitorService { self.rpc_api.lock().unwrap().replace(rpc_api.clone()); Ok(()) } - + async fn detach_rpc(self: Arc) -> Result<()> { self.rpc_api.lock().unwrap().take(); - + Ok(()) } - + async fn connect_rpc(self: Arc) -> Result<()> { self.register_notification_listener().await?; Ok(()) } - + async fn disconnect_rpc(self: Arc) -> Result<()> { self.unregister_notification_listener().await?; Ok(()) @@ -91,7 +99,7 @@ impl Service for BlockDagMonitorService { let this = self.clone(); let _application_events_sender = self.application_events.sender.clone(); - let mut chain : VecDeque> = Default::default(); + let mut chain: VecDeque> = Default::default(); loop { select! { diff --git a/core/src/runtime/services/mod.rs b/core/src/runtime/services/mod.rs index b8cebf1..8f7530b 100644 --- a/core/src/runtime/services/mod.rs +++ b/core/src/runtime/services/mod.rs @@ -28,7 +28,7 @@ pub trait Service: Sync + Send { /// Block until the service is terminated async fn join(self: Arc) -> Result<()>; - /// Called when Kaspa RPC API has been created (but node is not + /// Called when Kaspa RPC API has been created (but node is not /// connected yet, see [`connect_rpc`](Service::connect_rpc)) /// for connectivity signalling. async fn attach_rpc(self: Arc, _rpc_api: &Arc) -> Result<()> {