diff --git a/applications/tari_base_node/src/command_handler.rs b/applications/tari_base_node/src/command_handler.rs index a807e02133..e4c1105015 100644 --- a/applications/tari_base_node/src/command_handler.rs +++ b/applications/tari_base_node/src/command_handler.rs @@ -187,6 +187,15 @@ impl CommandHandler { ), ); + 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 { StatusOutput::Full => { @@ -230,6 +239,10 @@ impl CommandHandler { pub fn print_version(&self) { println!("Version: {}", consts::APP_VERSION); println!("Author: {}", consts::APP_AUTHOR); + println!("Avx2: {}", match cfg!(feature = "avx2") { + true => "enabled", + false => "disabled", + }); if let Some(ref update) = *self.software_updater.new_update_notifier().borrow() { println!( diff --git a/applications/tari_console_wallet/Cargo.toml b/applications/tari_console_wallet/Cargo.toml index 6b837e947c..87644d84e0 100644 --- a/applications/tari_console_wallet/Cargo.toml +++ b/applications/tari_console_wallet/Cargo.toml @@ -54,3 +54,6 @@ features = ["transactions", "mempool_proto", "base_node_proto"] version = "^0.12" default-features = false features = ["crossterm"] + +[features] +avx2 = [] \ No newline at end of file diff --git a/applications/tari_console_wallet/src/ui/components/menu.rs b/applications/tari_console_wallet/src/ui/components/menu.rs index 5134b2f969..e1b105da97 100644 --- a/applications/tari_console_wallet/src/ui/components/menu.rs +++ b/applications/tari_console_wallet/src/ui/components/menu.rs @@ -3,7 +3,7 @@ use tari_app_utilities::consts; use tui::{ backend::Backend, layout::{Constraint, Direction, Layout, Rect}, - style::{Color, Style}, + style::{Color, Modifier, Style}, text::{Span, Spans}, widgets::{Block, Paragraph}, Frame, @@ -35,6 +35,14 @@ impl Component for Menu { let version = Spans::from(vec![ Span::styled(" Version: ", Style::default().fg(Color::White)), Span::styled(consts::APP_VERSION_NUMBER, Style::default().fg(Color::Magenta)), + Span::raw(" "), + match cfg!(feature = "avx2") { + true => Span::styled("Avx2", Style::default().fg(Color::LightGreen)), + false => Span::styled( + "Avx2", + Style::default().fg(Color::LightRed).add_modifier(Modifier::CROSSED_OUT), + ), + }, ]); let tabs = Spans::from(vec![ Span::styled("LeftArrow: ", Style::default().fg(Color::White)), diff --git a/base_layer/core/src/base_node/state_machine_service/state_machine.rs b/base_layer/core/src/base_node/state_machine_service/state_machine.rs index ec99ccc989..133d0bd335 100644 --- a/base_layer/core/src/base_node/state_machine_service/state_machine.rs +++ b/base_layer/core/src/base_node/state_machine_service/state_machine.rs @@ -35,6 +35,7 @@ use crate::{ }; use futures::{future, future::Either}; use log::*; +use randomx_rs::RandomXFlag; use std::{future::Future, sync::Arc}; use tari_comms::{connectivity::ConnectivityRequester, PeerManager}; use tari_shutdown::ShutdownSignal; @@ -157,6 +158,8 @@ impl BaseNodeStateMachine { let status = StatusInfo { bootstrapped: self.is_bootstrapped(), state_info: self.info.clone(), + randomx_vm_cnt: self.randomx_factory.get_count(), + randomx_vm_flags: self.randomx_factory.get_flags(), }; if let Err(e) = self.status_event_sender.send(status) { @@ -178,6 +181,14 @@ impl BaseNodeStateMachine { self.is_bootstrapped } + pub fn get_randomx_vm_cnt(&self) -> usize { + self.randomx_factory.get_count() + } + + pub fn get_randomx_vm_flags(&self) -> RandomXFlag { + self.randomx_factory.get_flags() + } + /// Start the base node runtime. pub async fn run(mut self) { use BaseNodeState::*; diff --git a/base_layer/core/src/base_node/state_machine_service/states/block_sync.rs b/base_layer/core/src/base_node/state_machine_service/states/block_sync.rs index 5c7710c371..16977db92d 100644 --- a/base_layer/core/src/base_node/state_machine_service/states/block_sync.rs +++ b/base_layer/core/src/base_node/state_machine_service/states/block_sync.rs @@ -30,6 +30,7 @@ use crate::{ chain_storage::{BlockAddResult, BlockchainBackend}, }; use log::*; +use randomx_rs::RandomXFlag; use std::time::Instant; use tari_comms::PeerConnection; @@ -70,8 +71,12 @@ impl BlockSync { let _ = status_event_sender.send(StatusInfo { bootstrapped, state_info: StateInfo::BlockSyncStarting, + randomx_vm_cnt: 0, + randomx_vm_flags: RandomXFlag::FLAG_DEFAULT, }); let local_nci = shared.local_node_interface.clone(); + let randomx_vm_cnt = shared.get_randomx_vm_cnt(); + let randomx_vm_flags = shared.get_randomx_vm_flags(); synchronizer.on_progress(move |block, remote_tip_height, sync_peers| { let local_height = block.height(); local_nci.publish_block_event(BlockEvent::ValidBlockAdded( @@ -87,6 +92,8 @@ impl BlockSync { local_height, sync_peers: sync_peers.to_vec(), }), + randomx_vm_cnt, + randomx_vm_flags, }); }); diff --git a/base_layer/core/src/base_node/state_machine_service/states/events_and_states.rs b/base_layer/core/src/base_node/state_machine_service/states/events_and_states.rs index 0ef1f6e99b..1aaa384f80 100644 --- a/base_layer/core/src/base_node/state_machine_service/states/events_and_states.rs +++ b/base_layer/core/src/base_node/state_machine_service/states/events_and_states.rs @@ -33,6 +33,7 @@ use crate::base_node::{ }, sync::SyncPeers, }; +use randomx_rs::RandomXFlag; use std::fmt::{Display, Error, Formatter}; use tari_common_types::chain_metadata::ChainMetadata; use tari_comms::{peer_manager::NodeId, PeerConnection}; @@ -239,6 +240,8 @@ impl Display for StateInfo { pub struct StatusInfo { pub bootstrapped: bool, pub state_info: StateInfo, + pub randomx_vm_cnt: usize, + pub randomx_vm_flags: RandomXFlag, } impl StatusInfo { @@ -246,6 +249,8 @@ impl StatusInfo { Self { bootstrapped: false, state_info: StateInfo::StartUp, + randomx_vm_cnt: 0, + randomx_vm_flags: RandomXFlag::FLAG_DEFAULT, } } } diff --git a/base_layer/core/src/base_node/state_machine_service/states/header_sync.rs b/base_layer/core/src/base_node/state_machine_service/states/header_sync.rs index 68f663d71f..f94af095ae 100644 --- a/base_layer/core/src/base_node/state_machine_service/states/header_sync.rs +++ b/base_layer/core/src/base_node/state_machine_service/states/header_sync.rs @@ -74,6 +74,8 @@ impl HeaderSync { let status_event_sender = shared.status_event_sender.clone(); let bootstrapped = shared.is_bootstrapped(); + let randomx_vm_cnt = shared.get_randomx_vm_cnt(); + let randomx_vm_flags = shared.get_randomx_vm_flags(); synchronizer.on_progress(move |details, sync_peers| { let details = details.map(|(current_height, remote_tip_height)| BlockSyncInfo { tip_height: remote_tip_height, @@ -83,6 +85,8 @@ impl HeaderSync { let _ = status_event_sender.send(StatusInfo { bootstrapped, state_info: StateInfo::HeaderSync(details), + randomx_vm_cnt, + randomx_vm_flags, }); }); diff --git a/base_layer/core/src/proof_of_work/randomx_factory.rs b/base_layer/core/src/proof_of_work/randomx_factory.rs index 001d454608..f087e1661a 100644 --- a/base_layer/core/src/proof_of_work/randomx_factory.rs +++ b/base_layer/core/src/proof_of_work/randomx_factory.rs @@ -87,6 +87,16 @@ impl RandomXFactory { } Ok(res) } + + pub fn get_count(&self) -> usize { + let inner = self.inner.read().unwrap(); + inner.get_count() + } + + pub fn get_flags(&self) -> RandomXFlag { + let inner = self.inner.read().unwrap(); + inner.get_flags() + } } struct RandomXFactoryInner { @@ -136,6 +146,14 @@ impl RandomXFactoryInner { Ok(vm) } + + pub fn get_count(&self) -> usize { + self.vms.len() + } + + pub fn get_flags(&self) -> RandomXFlag { + self.flags + } } #[cfg(test)] diff --git a/base_layer/core/tests/base_node_rpc.rs b/base_layer/core/tests/base_node_rpc.rs index e8b627dd57..5ebbaa3144 100644 --- a/base_layer/core/tests/base_node_rpc.rs +++ b/base_layer/core/tests/base_node_rpc.rs @@ -46,6 +46,7 @@ use std::convert::TryFrom; use tempfile::{tempdir, TempDir}; +use randomx_rs::RandomXFlag; use tari_common::configuration::Network; use tari_comms::protocol::rpc::mock::RpcRequestMock; use tari_core::{ @@ -112,6 +113,8 @@ async fn setup() -> ( base_node.mock_base_node_state_machine.publish_status(StatusInfo { bootstrapped: true, state_info: StateInfo::Listening(ListeningInfo::new(true)), + randomx_vm_cnt: 0, + randomx_vm_flags: RandomXFlag::FLAG_DEFAULT, }); let request_mock = RpcRequestMock::new(base_node.comms.peer_manager()); diff --git a/base_layer/core/tests/mempool.rs b/base_layer/core/tests/mempool.rs index ae79003806..9830a8282e 100644 --- a/base_layer/core/tests/mempool.rs +++ b/base_layer/core/tests/mempool.rs @@ -38,6 +38,7 @@ use helpers::{ nodes::{create_network_with_2_base_nodes_with_config, create_network_with_3_base_nodes_with_config}, sample_blockchains::{create_new_blockchain, create_new_blockchain_with_constants}, }; +use randomx_rs::RandomXFlag; use tari_common::configuration::Network; use tari_common_types::types::{Commitment, PrivateKey, PublicKey, Signature}; use tari_comms_dht::domain_message::OutboundDomainMessage; @@ -860,14 +861,20 @@ async fn receive_and_propagate_transaction() { alice_node.mock_base_node_state_machine.publish_status(StatusInfo { bootstrapped: true, state_info: StateInfo::Listening(ListeningInfo::new(true)), + randomx_vm_cnt: 0, + randomx_vm_flags: RandomXFlag::FLAG_DEFAULT, }); bob_node.mock_base_node_state_machine.publish_status(StatusInfo { bootstrapped: true, state_info: StateInfo::Listening(ListeningInfo::new(true)), + randomx_vm_cnt: 0, + randomx_vm_flags: RandomXFlag::FLAG_DEFAULT, }); carol_node.mock_base_node_state_machine.publish_status(StatusInfo { bootstrapped: true, state_info: StateInfo::Listening(ListeningInfo::new(true)), + randomx_vm_cnt: 0, + randomx_vm_flags: RandomXFlag::FLAG_DEFAULT, }); let (tx, _, _) = spend_utxos(txn_schema!(from: vec![utxo], to: vec![2 * T, 2 * T, 2 * T])); @@ -1092,6 +1099,8 @@ async fn block_event_and_reorg_event_handling() { alice.mock_base_node_state_machine.publish_status(StatusInfo { bootstrapped: true, state_info: StateInfo::Listening(ListeningInfo::new(true)), + randomx_vm_cnt: 0, + randomx_vm_flags: RandomXFlag::FLAG_DEFAULT, }); // Bob creates Block 1 and sends it to Alice. Alice adds it to her chain and creates a block event that the Mempool diff --git a/base_layer/core/tests/node_service.rs b/base_layer/core/tests/node_service.rs index af128e5966..c6e8fc3e1b 100644 --- a/base_layer/core/tests/node_service.rs +++ b/base_layer/core/tests/node_service.rs @@ -40,6 +40,7 @@ use helpers::{ BaseNodeBuilder, }, }; +use randomx_rs::RandomXFlag; use std::{sync::Arc, time::Duration}; use tari_common::configuration::Network; use tari_comms::protocol::messaging::MessagingEvent; @@ -274,18 +275,26 @@ async fn propagate_and_forward_many_valid_blocks() { alice_node.mock_base_node_state_machine.publish_status(StatusInfo { bootstrapped: true, state_info: StateInfo::Listening(ListeningInfo::new(true)), + randomx_vm_cnt: 0, + randomx_vm_flags: RandomXFlag::FLAG_DEFAULT, }); bob_node.mock_base_node_state_machine.publish_status(StatusInfo { bootstrapped: true, state_info: StateInfo::Listening(ListeningInfo::new(true)), + randomx_vm_cnt: 0, + randomx_vm_flags: RandomXFlag::FLAG_DEFAULT, }); carol_node.mock_base_node_state_machine.publish_status(StatusInfo { bootstrapped: true, state_info: StateInfo::Listening(ListeningInfo::new(true)), + randomx_vm_cnt: 0, + randomx_vm_flags: RandomXFlag::FLAG_DEFAULT, }); dan_node.mock_base_node_state_machine.publish_status(StatusInfo { bootstrapped: true, state_info: StateInfo::Listening(ListeningInfo::new(true)), + randomx_vm_cnt: 0, + randomx_vm_flags: RandomXFlag::FLAG_DEFAULT, }); let mut bob_block_event_stream = bob_node.local_nci.get_block_event_stream(); @@ -374,14 +383,20 @@ async fn propagate_and_forward_invalid_block_hash() { alice_node.mock_base_node_state_machine.publish_status(StatusInfo { bootstrapped: true, state_info: StateInfo::Listening(ListeningInfo::new(true)), + randomx_vm_cnt: 0, + randomx_vm_flags: RandomXFlag::FLAG_DEFAULT, }); bob_node.mock_base_node_state_machine.publish_status(StatusInfo { bootstrapped: true, state_info: StateInfo::Listening(ListeningInfo::new(true)), + randomx_vm_cnt: 0, + randomx_vm_flags: RandomXFlag::FLAG_DEFAULT, }); carol_node.mock_base_node_state_machine.publish_status(StatusInfo { bootstrapped: true, state_info: StateInfo::Listening(ListeningInfo::new(true)), + randomx_vm_cnt: 0, + randomx_vm_flags: RandomXFlag::FLAG_DEFAULT, }); let block1 = append_block(&alice_node.blockchain_db, &block0, vec![], &rules, 1.into()).unwrap(); @@ -488,18 +503,26 @@ async fn propagate_and_forward_invalid_block() { alice_node.mock_base_node_state_machine.publish_status(StatusInfo { bootstrapped: true, state_info: StateInfo::Listening(ListeningInfo::new(true)), + randomx_vm_cnt: 0, + randomx_vm_flags: RandomXFlag::FLAG_DEFAULT, }); bob_node.mock_base_node_state_machine.publish_status(StatusInfo { bootstrapped: true, state_info: StateInfo::Listening(ListeningInfo::new(true)), + randomx_vm_cnt: 0, + randomx_vm_flags: RandomXFlag::FLAG_DEFAULT, }); carol_node.mock_base_node_state_machine.publish_status(StatusInfo { bootstrapped: true, state_info: StateInfo::Listening(ListeningInfo::new(true)), + randomx_vm_cnt: 0, + randomx_vm_flags: RandomXFlag::FLAG_DEFAULT, }); dan_node.mock_base_node_state_machine.publish_status(StatusInfo { bootstrapped: true, state_info: StateInfo::Listening(ListeningInfo::new(true)), + randomx_vm_cnt: 0, + randomx_vm_flags: RandomXFlag::FLAG_DEFAULT, }); // This is a valid block, however Bob, Carol and Dan's block validator is set to always reject the block