diff --git a/src/cli/args.rs b/src/cli/args.rs index eadd9375..cbd5ac65 100644 --- a/src/cli/args.rs +++ b/src/cli/args.rs @@ -119,6 +119,11 @@ pub struct StartArgs { #[arg(long)] pub max_connections: Option, + + #[arg(long, default_value_t = false)] + pub randomx_disabled: bool, + #[arg(long, default_value_t = false)] + pub sha3x_disabled: bool, } #[derive(Clone, Parser, Debug)] diff --git a/src/cli/commands/util.rs b/src/cli/commands/util.rs index a45f1ddd..6fc4c158 100644 --- a/src/cli/commands/util.rs +++ b/src/cli/commands/util.rs @@ -3,7 +3,6 @@ use std::{collections::HashMap, env, fs, sync::Arc}; -use hickory_resolver::config; use libp2p::identity::Keypair; use log::info; use tari_common::{configuration::Network, initialize_logging}; @@ -72,6 +71,8 @@ pub async fn server( if let Some(max_connections) = args.max_connections { config_builder.with_max_connections(max_connections); } + config_builder.with_randomx_enabled(!args.randomx_disabled); + config_builder.with_sha3x_enabled(!args.sha3x_disabled); // try to extract env var based private key if let Ok(identity_cbor) = env::var("SHA_P2POOL_IDENTITY") { diff --git a/src/server/config.rs b/src/server/config.rs index c2d4371d..b266e41e 100644 --- a/src/server/config.rs +++ b/src/server/config.rs @@ -105,6 +105,16 @@ impl ConfigBuilder { self } + pub fn with_sha3x_enabled(&mut self, config: bool) -> &mut Self { + self.config.p2p_service.sha3x_enabled = config; + self + } + + pub fn with_randomx_enabled(&mut self, config: bool) -> &mut Self { + self.config.p2p_service.randomx_enabled = config; + self + } + pub fn with_private_key(&mut self, config: Option) -> &mut Self { self.config.p2p_service.private_key = config; self diff --git a/src/server/p2p/network.rs b/src/server/p2p/network.rs index 1374eba0..01d8c58b 100644 --- a/src/server/p2p/network.rs +++ b/src/server/p2p/network.rs @@ -176,6 +176,8 @@ pub struct Config { pub max_blocks_to_request: usize, pub sync_job_enabled: bool, pub peer_list_folder: PathBuf, + pub sha3x_enabled: bool, + pub randomx_enabled: bool, } impl Default for Config { @@ -199,6 +201,8 @@ impl Default for Config { num_peers_to_sync: 2, max_blocks_to_request: 20, sync_job_enabled: true, + sha3x_enabled: true, + randomx_enabled: true, } } } @@ -703,6 +707,14 @@ where S: ShareChain debug!(target: LOG_TARGET, squad = &self.config.squad; "Peer {} sent a notify message that is too old, skipping", source_peer); return Ok(MessageAcceptance::Ignore); } + if payload.algo() == PowAlgorithm::RandomX && !self.config.randomx_enabled { + debug!(target: LOG_TARGET, squad = &self.config.squad; "Peer {} sent a RandomX block but RandomX is disabled, skipping", source_peer); + return Ok(MessageAcceptance::Ignore); + } + if payload.algo() == PowAlgorithm::Sha3x && !self.config.sha3x_enabled { + debug!(target: LOG_TARGET, squad = &self.config.squad; "Peer {} sent a Sha3x block but Sha3x is disabled, skipping", source_peer); + return Ok(MessageAcceptance::Ignore); + } let payload = Arc::new(payload); let message_peer = payload.peer_id(); if message_peer.to_string() != source_peer.to_string() { @@ -1777,7 +1789,14 @@ where S: ShareChain } async fn try_sync_from_best_peer(&mut self) { - for algo in &[PowAlgorithm::RandomX, PowAlgorithm::Sha3x] { + let mut algos = vec![]; + if self.config.sha3x_enabled { + algos.push(PowAlgorithm::Sha3x); + } + if self.config.randomx_enabled { + algos.push(PowAlgorithm::RandomX); + } + for algo in &algos { // Find any blocks we are missing. let _chain = match algo { PowAlgorithm::RandomX => self.share_chain_random_x.clone(),