Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: change status line #3610

Merged
merged 2 commits into from
Nov 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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