Skip to content

Commit

Permalink
chore: change status line (#3610)
Browse files Browse the repository at this point in the history
Description
---
Added NodeId to status line.
And status line is printed with more info (currently RandomX) every 2 minutes.

How Has This Been Tested?
---
Manually.
  • Loading branch information
Cifko authored Nov 26, 2021
1 parent 1003f91 commit 086cd0c
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 102 deletions.
30 changes: 19 additions & 11 deletions applications/tari_base_node/src/command_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ pub struct CommandHandler {
mempool_service: LocalMempoolService,
state_machine_info: watch::Receiver<StatusInfo>,
software_updater: SoftwareUpdaterHandle,
last_time_full: Instant,
}

impl CommandHandler {
Expand All @@ -110,10 +111,11 @@ impl CommandHandler {
mempool_service: ctx.local_mempool(),
state_machine_info: ctx.get_state_machine_info_channel(),
software_updater: ctx.software_updater(),
last_time_full: Instant::now(),
}
}

pub fn status(&self, output: StatusOutput) {
pub fn status(&mut self, output: StatusOutput) {
let state_info = self.state_machine_info.clone();
let mut node = self.node_service.clone();
let mut mempool = self.mempool_service.clone();
Expand All @@ -123,12 +125,17 @@ impl CommandHandler {
let mut rpc_server = self.rpc_server.clone();
let config = self.config.clone();
let consensus_rules = self.consensus_rules.clone();
let mut full_log = false;
if self.last_time_full.elapsed() > Duration::from_secs(120) {
self.last_time_full = Instant::now();
full_log = true;
}

self.executor.spawn(async move {
let mut status_line = StatusLine::new();
status_line.add_field("", format!("v{}", consts::APP_VERSION_NUMBER));
status_line.add_field("", config.network);
status_line.add_field("State", state_info.borrow().state_info.short_desc());
status_line.add_field("State", state_info.borrow().state_info.short_desc(full_log));

let metadata = node.get_metadata().await.unwrap();
let height = metadata.height_of_longest_chain();
Expand Down Expand Up @@ -183,15 +190,16 @@ impl CommandHandler {
.unwrap_or_else(|| "∞".to_string()),
),
);

status_line.add_field(
"RandomX",
format!(
"#{} with flags {:?}",
state_info.borrow().randomx_vm_cnt,
state_info.borrow().randomx_vm_flags
),
);
if full_log {
status_line.add_field(
"RandomX",
format!(
"#{} with flags {:?}",
state_info.borrow().randomx_vm_cnt,
state_info.borrow().randomx_vm_flags
),
);
}

let target = "base_node::app::status";
match output {
Expand Down
18 changes: 12 additions & 6 deletions applications/tari_base_node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ use tari_core::chain_storage::ChainStorageError;
use tari_shutdown::{Shutdown, ShutdownSignal};
use tokio::{
runtime,
sync::Mutex,
task,
time::{self},
};
Expand Down Expand Up @@ -258,7 +259,7 @@ async fn run_node(node_config: Arc<GlobalConfig>, bootstrap: ConfigBootstrap) ->
}

// Run, node, run!
let command_handler = Arc::new(CommandHandler::new(runtime::Handle::current(), &ctx));
let command_handler = Arc::new(Mutex::new(CommandHandler::new(runtime::Handle::current(), &ctx)));
if bootstrap.non_interactive_mode {
task::spawn(status_loop(command_handler, shutdown));
println!("Node started in non-interactive mode (pid = {})", process::id());
Expand Down Expand Up @@ -367,7 +368,7 @@ fn status_interval(start_time: Instant) -> time::Sleep {
time::sleep(duration)
}

async fn status_loop(command_handler: Arc<CommandHandler>, shutdown: Shutdown) {
async fn status_loop(command_handler: Arc<Mutex<CommandHandler>>, shutdown: Shutdown) {
let start_time = Instant::now();
let mut shutdown_signal = shutdown.to_signal();
loop {
Expand All @@ -379,7 +380,7 @@ async fn status_loop(command_handler: Arc<CommandHandler>, shutdown: Shutdown) {
}

_ = interval => {
command_handler.status(StatusOutput::Log);
command_handler.lock().await.status(StatusOutput::Log);
},
}
}
Expand Down Expand Up @@ -407,15 +408,20 @@ async fn cli_loop(parser: Parser, mut shutdown: Shutdown) {

let mut shutdown_signal = shutdown.to_signal();
let start_time = Instant::now();
let mut software_update_notif = command_handler.get_software_updater().new_update_notifier().clone();
let mut software_update_notif = command_handler
.lock()
.await
.get_software_updater()
.new_update_notifier()
.clone();
loop {
let interval = status_interval(start_time);
tokio::select! {
res = &mut read_command_fut => {
match res {
Ok((line, mut rustyline)) => {
if let Some(p) = rustyline.helper_mut() {
p.handle_command(line.as_str(), &mut shutdown);
p.handle_command(line.as_str(), &mut shutdown).await;
}
if !shutdown.is_triggered() {
read_command_fut.set(read_command(rustyline).fuse());
Expand All @@ -440,7 +446,7 @@ async fn cli_loop(parser: Parser, mut shutdown: Shutdown) {
}
}
_ = interval => {
command_handler.status(StatusOutput::Full);
command_handler.lock().await.status(StatusOutput::Full);
},
_ = shutdown_signal.wait() => {
break;
Expand Down
Loading

0 comments on commit 086cd0c

Please sign in to comment.