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

feat: fix base node shutdown #6697

Merged
merged 1 commit into from
Nov 22, 2024
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
29 changes: 25 additions & 4 deletions applications/minotari_node/src/commands/cli_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use tokio::{signal, time};
use crate::{
commands::{
cli,
command::{CommandContext, WatchCommand},
command::{Args, CommandContext, WatchCommand},
parser::Parser,
reader::CommandReader,
},
Expand Down Expand Up @@ -87,7 +87,9 @@ impl CliLoop {
} else {
while !self.done {
self.watch_loop().await;
self.execute_command().await;
if !self.done {
self.execute_command().await;
}
}
}
}
Expand Down Expand Up @@ -129,12 +131,19 @@ impl CliLoop {
println!("Wrong command to watch `{}`. Failed with: {}", line, err);
} else {
let mut events = EventStream::new();
loop {
while !self.done {
let interval = time::sleep(interval);
tokio::select! {
_ = interval => {
if let Err(err) = self.context.handle_command_str(line).await {
println!("Watched command `{}` failed: {}", line, err);
} else {
let args: Result<Args, _> = line.parse();
if let Ok(command) = args {
if command.is_quit() {
self.done = true;
}
}
}
continue;
},
Expand All @@ -158,7 +167,9 @@ impl CliLoop {
}
}
}
crossterm::execute!(io::stdout(), cursor::MoveToNextLine(1)).ok();
if !self.done {
crossterm::execute!(io::stdout(), cursor::MoveToNextLine(1)).ok();
}
}
terminal::disable_raw_mode().ok();
}
Expand All @@ -183,6 +194,13 @@ impl CliLoop {
_ = interval => {
if let Err(err) = self.context.handle_command_str(line).await {
println!("Watched command `{}` failed: {}", line, err);
} else {
let args: Result<Args, _> = line.parse();
if let Ok(command) = args {
if command.is_quit() {
self.done = true;
}
}
}
continue;
},
Expand Down Expand Up @@ -242,6 +260,9 @@ impl CliLoop {
} else {
self.done = true;
}
if self.done && !self.shutdown_signal.is_triggered() {
self.context.shutdown.trigger();
}
},
_ = self.shutdown_signal.wait() => {
self.done = true;
Expand Down
6 changes: 6 additions & 0 deletions applications/minotari_node/src/commands/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ pub struct Args {
pub command: Command,
}

impl Args {
pub fn is_quit(&self) -> bool {
matches!(self.command, Command::Quit(_) | Command::Exit(_))
}
}

#[derive(Debug, Subcommand, EnumVariantNames)]
#[strum(serialize_all = "kebab-case")]
pub enum Command {
Expand Down
3 changes: 2 additions & 1 deletion applications/minotari_node/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ pub struct BaseNodeConfig {
pub state_machine: BaseNodeStateMachineConfig,
/// Obscure GRPC error responses
pub report_grpc_error: bool,
// Interval to check if the base node is still in sync with the network
/// Interval to check if the base node is still in sync with the network
#[serde(with = "serializers::seconds")]
pub tari_pulse_interval: Duration,
}

Expand Down
2 changes: 1 addition & 1 deletion base_layer/core/src/base_node/tari_pulse_service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ impl TariPulseService {
let mut interval = time::interval(self.config.check_interval);
let mut interval_failed = time::interval(Duration::from_millis(100));
loop {
interval.tick().await;
let passed_checkpoints = match self.passed_checkpoints(&mut base_node_service).await {
Ok(passed) => passed,
Err(err) => {
Expand All @@ -130,7 +131,6 @@ impl TariPulseService {
notify_passed_checkpoints
.send(!passed_checkpoints)
.expect("Channel should be open");
interval.tick().await;
}
}

Expand Down
Loading