Skip to content

Commit

Permalink
Add new base node gRPC call
Browse files Browse the repository at this point in the history
Added the new base node gRPC call 'get_network_state' to `fn get_network_hash_rate_and_block_reward`
that returns all required base node statuses in a single call.

'MinerMetrics' now has additional members
- 'initial_sync_achieved' (previously 'is_synced')
- 'failed_checkpoints'
- 'base_node_state'
and also provides a method 'MinerMetrics::is_synced()' that will return the is-synced status
based on the 'base_node_state'.
  • Loading branch information
hansieodendaal committed Jan 18, 2025
1 parent 71b0d19 commit 866b7a0
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 167 deletions.
84 changes: 42 additions & 42 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ libsqlite3-sys = { version = "0.25.1", features = [
] } # Required for tari_wallet
log = "0.4.22"
log4rs = "1.3.0"
minotari_node_grpc_client = { git = "https://github.com/tari-project/tari.git", tag = "v1.9.1-rc.1" }
minotari_wallet_grpc_client = { git = "https://github.com/tari-project/tari.git", tag = "v1.9.1-rc.1" }
minotari_node_grpc_client = { git = "https://github.com/tari-project/tari.git", tag = "v1.10.0-rc.0" }
minotari_wallet_grpc_client = { git = "https://github.com/tari-project/tari.git", tag = "v1.10.0-rc.0" }
monero-address-creator = { git = "https://github.com/tari-project/monero-address-creator.git", rev = "6129ca0" }
nix = { version = "0.29.0", features = ["signal"] }
nvml-wrapper = "0.10.0"
Expand All @@ -58,15 +58,15 @@ sha2 = "0.10.8"
sys-locale = "0.3.1"
sysinfo = "0.31.2"
tar = "0.4.26"
tari_common = { git = "https://github.com/tari-project/tari.git", tag = "v1.9.1-rc.1" }
tari_common_types = { git = "https://github.com/tari-project/tari.git", tag = "v1.9.1-rc.1" }
tari_core = { git = "https://github.com/tari-project/tari.git", tag = "v1.9.1-rc.1", features = [
tari_common = { git = "https://github.com/tari-project/tari.git", tag = "v1.10.0-rc.0" }
tari_common_types = { git = "https://github.com/tari-project/tari.git", tag = "v1.10.0-rc.0" }
tari_core = { git = "https://github.com/tari-project/tari.git", tag = "v1.10.0-rc.0", features = [
"transactions",
] }
tauri-plugin-single-instance = '2'
tari_crypto = "0.21.0"
tari_key_manager = { git = "https://github.com/tari-project/tari.git", tag = "v1.9.1-rc.1" }
tari_shutdown = { git = "https://github.com/tari-project/tari.git", tag = "v1.9.1-rc.1" }
tari_key_manager = { git = "https://github.com/tari-project/tari.git", tag = "v1.10.0-rc.0" }
tari_shutdown = { git = "https://github.com/tari-project/tari.git", tag = "v1.10.0-rc.0" }
tari_utilities = "0.8.0"
tauri = { version = "2", features = [
"isolation",
Expand Down
30 changes: 19 additions & 11 deletions src-tauri/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ use crate::wallet_adapter::{TransactionInfo, WalletBalance};
use crate::wallet_manager::WalletManagerError;
use crate::{node_adapter, UniverseAppState, APPLICATION_FOLDER_ID};

use crate::node_adapter::BaseNodeState;
use base64::prelude::*;
use keyring::Entry;
use log::{debug, error, info, warn};
Expand Down Expand Up @@ -102,6 +103,14 @@ pub struct MinerMetrics {
base_node: BaseNodeStatus,
}

impl MinerMetrics {
/// Returns `true` if the base node has state `BaseNodeState::Listening`
#[allow(dead_code)]
pub fn is_synced(&self) -> bool {
self.base_node.base_node_state == BaseNodeState::Listening
}
}

#[derive(Debug, Serialize, Clone)]
pub struct TariWalletDetails {
wallet_balance: Option<WalletBalance>,
Expand All @@ -113,10 +122,13 @@ pub struct TariWalletDetails {
pub struct BaseNodeStatus {
block_height: u64,
block_time: u64,
is_synced: bool,
initial_sync_achieved: bool,
base_node_state: BaseNodeState,
failed_checkpoints: bool,
is_connected: bool,
connected_peers: Vec<String>,
}

#[derive(Debug, Serialize, Clone)]
pub struct CpuMinerStatus {
pub is_mining: bool,
Expand Down Expand Up @@ -401,17 +413,11 @@ pub async fn get_miner_metrics(
randomx_network_hashrate,
block_height,
block_time,
is_synced,
initial_sync_achieved,
block_reward,
base_node_state,
failed_checkpoints,
} = node_status;
// let (sha_hash_rate, randomx_hash_rate, block_reward, block_height, block_time, is_synced) = state.node_manager
// .get_network_hash_rate_and_block_reward().await
// .unwrap_or_else(|e| {
// if !matches!(e, NodeManagerError::NodeNotStarted) {
// warn!(target: LOG_TARGET, "Error getting network hash rate and block reward: {}", e);
// }
// (0, 0, MicroMinotari(0), 0, 0, false)
// });

let cpu_miner = state.cpu_miner.read().await;
let cpu_mining_status = match cpu_miner
Expand Down Expand Up @@ -461,7 +467,9 @@ pub async fn get_miner_metrics(
base_node: BaseNodeStatus {
block_height,
block_time,
is_synced,
initial_sync_achieved,
base_node_state,
failed_checkpoints,
is_connected: !connected_peers.is_empty(),
connected_peers,
},
Expand Down
Loading

0 comments on commit 866b7a0

Please sign in to comment.