Skip to content

Commit

Permalink
feat: show status avx2 feature and randomx count and flags (#3261)
Browse files Browse the repository at this point in the history
Description
---
- Add new info into wallet:
  - Avx2 enabled/disabled status.
- Add new info into base node
  - Avxs2 enabled/disabled
  - number of randomx vm, and flags
  • Loading branch information
Cifko authored Sep 6, 2021
1 parent 969b306 commit e2d8d1f
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 1 deletion.
13 changes: 13 additions & 0 deletions applications/tari_base_node/src/command_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -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!(
Expand Down
3 changes: 3 additions & 0 deletions applications/tari_console_wallet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,6 @@ features = ["transactions", "mempool_proto", "base_node_proto"]
version = "^0.12"
default-features = false
features = ["crossterm"]

[features]
avx2 = []
10 changes: 9 additions & 1 deletion applications/tari_console_wallet/src/ui/components/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -35,6 +35,14 @@ impl<B: Backend> Component<B> 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)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -157,6 +158,8 @@ impl<B: BlockchainBackend + 'static> BaseNodeStateMachine<B> {
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) {
Expand All @@ -178,6 +181,14 @@ impl<B: BlockchainBackend + 'static> BaseNodeStateMachine<B> {
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::*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use crate::{
chain_storage::{BlockAddResult, BlockchainBackend},
};
use log::*;
use randomx_rs::RandomXFlag;
use std::time::Instant;
use tari_comms::PeerConnection;

Expand Down Expand Up @@ -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(
Expand All @@ -87,6 +92,8 @@ impl BlockSync {
local_height,
sync_peers: sync_peers.to_vec(),
}),
randomx_vm_cnt,
randomx_vm_flags,
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -239,13 +240,17 @@ 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 {
pub fn new() -> Self {
Self {
bootstrapped: false,
state_info: StateInfo::StartUp,
randomx_vm_cnt: 0,
randomx_vm_flags: RandomXFlag::FLAG_DEFAULT,
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -83,6 +85,8 @@ impl HeaderSync {
let _ = status_event_sender.send(StatusInfo {
bootstrapped,
state_info: StateInfo::HeaderSync(details),
randomx_vm_cnt,
randomx_vm_flags,
});
});

Expand Down
18 changes: 18 additions & 0 deletions base_layer/core/src/proof_of_work/randomx_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)]
Expand Down
3 changes: 3 additions & 0 deletions base_layer/core/tests/base_node_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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());
Expand Down
9 changes: 9 additions & 0 deletions base_layer/core/tests/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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]));
Expand Down Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions base_layer/core/tests/node_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e2d8d1f

Please sign in to comment.