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

fix(orhpan-chain): verify node is synced before checking if it's orphan chain #1091

Merged
merged 5 commits into from
Nov 20, 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
3 changes: 1 addition & 2 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1610,12 +1610,11 @@ async fn check_if_is_orphan_chain(app_handle: tauri::AppHandle) {
Ok(is_stuck) => {
if is_stuck {
error!(target: LOG_TARGET, "Miner is stuck on orphan chain");
drop(app_handle.emit_all("is_stuck", is_stuck));
}
drop(app_handle.emit_all("is_stuck", is_stuck));
}
Err(e) => {
error!(target: LOG_TARGET, "{}", e);
drop(app_handle.emit_all("is_stuck", true));
}
}
}
Expand Down
21 changes: 18 additions & 3 deletions src-tauri/src/node_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::sync::Arc;
use std::time::SystemTime;

use chrono::{NaiveDateTime, TimeZone, Utc};
use log::error;
use log::{error, info};
use minotari_node_grpc_client::grpc::Peer;
use tari_common::configuration::Network;
use tari_core::transactions::tari_amount::MicroMinotari;
Expand Down Expand Up @@ -206,11 +206,26 @@ impl NodeManager {
}

pub async fn check_if_is_orphan_chain(&self) -> Result<bool, anyhow::Error> {
let status_monitor_lock = self.watcher.read().await;
let mut status_monitor_lock = self.watcher.write().await;
let status_monitor = status_monitor_lock
.status_monitor
.as_ref()
.as_mut()
.ok_or_else(|| anyhow::anyhow!("Node not started"))?;
let (_, _, _, _, _, is_synced) = status_monitor
.get_network_hash_rate_and_block_reward()
.await
.map_err(|e| {
if matches!(e, MinotariNodeStatusMonitorError::NodeNotStarted) {
NodeManagerError::NodeNotStarted
} else {
NodeManagerError::UnknownError(e.into())
}
})?;
if !is_synced {
info!(target: LOG_TARGET, "Node is not synced, skipping orphan chain check");
return Ok(false);
}

let network = Network::get_current_or_user_setting_or_default();
let block_scan_tip = get_best_block_from_block_scan(network).await?;
let heights: Vec<u64> = vec![
Expand Down
8 changes: 3 additions & 5 deletions src/containers/main/SideBar/components/OrphanChainAlert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@ export const OrphanChainAlert = () => {
const { t } = useTranslation('settings', { useSuspense: false });

useEffect(() => {
const unlistenPromise = listen('is_stuck', (event) => {
if (event.payload) {
setIsOrphanChain(true);
}
const unlistenPromise = listen<boolean>('is_stuck', (event) => {
setIsOrphanChain(event.payload);
});
return () => {
unlistenPromise.then((unlisten) => unlisten());
};
});
}, [setIsOrphanChain]);

return isOrphanChain ? (
<Stack direction="row" justifyContent="space-between" alignItems="center">
Expand Down