From 5c10d35581b260f19e09ff82ca2d010e750ad69d Mon Sep 17 00:00:00 2001 From: Boog900 <54e72d8a-345f-4599-bd90-c6b9bc7d0ec5@aleeas.com> Date: Wed, 18 Dec 2024 23:30:49 +0000 Subject: [PATCH] add more data to status --- binaries/cuprated/src/config.rs | 4 ++-- binaries/cuprated/src/config/rayon.rs | 2 -- binaries/cuprated/src/main.rs | 28 +++++++++++++++++++++++---- p2p/address-book/src/store.rs | 10 ++++------ 4 files changed, 30 insertions(+), 14 deletions(-) diff --git a/binaries/cuprated/src/config.rs b/binaries/cuprated/src/config.rs index f78abc74..8f151f03 100644 --- a/binaries/cuprated/src/config.rs +++ b/binaries/cuprated/src/config.rs @@ -20,17 +20,17 @@ use cuprate_p2p_core::{ClearNet, ClearNetServerCfg}; mod args; mod fs; mod p2p; +mod rayon; mod storage; mod tokio; mod tracing_config; -mod rayon; use crate::config::fs::FileSystemConfig; +use crate::config::rayon::RayonConfig; use crate::config::tokio::TokioConfig; use p2p::P2PConfig; use storage::StorageConfig; use tracing_config::TracingConfig; -use crate::config::rayon::RayonConfig; /// Reads the args & config file, returning a [`Config`]. pub fn read_config_and_args() -> Config { diff --git a/binaries/cuprated/src/config/rayon.rs b/binaries/cuprated/src/config/rayon.rs index 2b830bda..361c9573 100644 --- a/binaries/cuprated/src/config/rayon.rs +++ b/binaries/cuprated/src/config/rayon.rs @@ -13,5 +13,3 @@ impl Default for RayonConfig { } } } - - diff --git a/binaries/cuprated/src/main.rs b/binaries/cuprated/src/main.rs index 52349c0a..fd07d9aa 100644 --- a/binaries/cuprated/src/main.rs +++ b/binaries/cuprated/src/main.rs @@ -18,8 +18,13 @@ use crate::commands::Command; use crate::config::Config; +use crate::constants::PANIC_CRITICAL_SERVICE_ERROR; +use cuprate_consensus_context::{ + BlockChainContextRequest, BlockChainContextResponse, BlockChainContextService, +}; use cuprate_helper::time::secs_to_hms; use tokio::sync::mpsc; +use tower::{Service, ServiceExt}; use tracing::level_filters::LevelFilter; use tracing_subscriber::layer::SubscriberExt; use tracing_subscriber::reload::Handle; @@ -100,7 +105,7 @@ fn main() { blockchain_write_handle, blockchain_read_handle, txpool_write_handle, - context_svc, + context_svc.clone(), block_verifier, config.block_downloader_config(), ) @@ -109,7 +114,7 @@ fn main() { let (command_tx, command_rx) = mpsc::channel(1); std::thread::spawn(|| commands::command_listener(command_tx)); - io_loop(command_rx).await; + io_loop(command_rx, context_svc).await; }); } @@ -128,7 +133,10 @@ fn init_global_rayon_pool(config: &Config) { .unwrap() } -async fn io_loop(mut incoming_commands: mpsc::Receiver) -> ! { +async fn io_loop( + mut incoming_commands: mpsc::Receiver, + mut context_service: BlockChainContextService, +) -> ! { while let Some(command) = incoming_commands.recv().await { match command { Command::SetLog { level } => { @@ -137,10 +145,22 @@ async fn io_loop(mut incoming_commands: mpsc::Receiver) -> ! { println!("LOG LEVEL CHANGED: {level}"); } Command::Status => { + let BlockChainContextResponse::Context(blockchain_context) = context_service + .ready() + .await + .expect(PANIC_CRITICAL_SERVICE_ERROR) + .call(BlockChainContextRequest::Context) + .await + .expect(PANIC_CRITICAL_SERVICE_ERROR) + else { + unreachable!(); + }; + let context = blockchain_context.unchecked_blockchain_context(); + let uptime = statics::START_INSTANT.elapsed().unwrap_or_default(); let (hours, minutes, second) = secs_to_hms(uptime.as_secs()); - println!("STATUS:\n uptime: {hours}h {minutes}m {second}s"); + println!("STATUS:\n uptime: {hours}h {minutes}m {second}s,\n height: {},\n top_hash: {}", context.chain_height, hex::encode(context.top_hash)); } } } diff --git a/p2p/address-book/src/store.rs b/p2p/address-book/src/store.rs index e1da2b4a..666f3634 100644 --- a/p2p/address-book/src/store.rs +++ b/p2p/address-book/src/store.rs @@ -39,15 +39,13 @@ pub(crate) fn save_peers_to_disk( }) .unwrap(); - let dir = cfg - .peer_store_directory.clone(); - let file = dir - .join(format!("{}_p2p_state", Z::NAME)); + let dir = cfg.peer_store_directory.clone(); + let file = dir.join(format!("{}_p2p_state", Z::NAME)); spawn_blocking(move || { fs::create_dir_all(dir)?; - fs::write(&file, &data) } - ) + fs::write(&file, &data) + }) } pub(crate) async fn read_peers_from_disk(