From d777c1b300015dbf21ac155c23611a5a21c004af Mon Sep 17 00:00:00 2001 From: brianp Date: Fri, 31 Jan 2025 10:16:40 +0100 Subject: [PATCH 1/4] Revert "chore: update squad number to 3" This reverts commit a75b0173449b4bf21f9defe41dffe83cfeeec004. --- src-tauri/src/p2pool_adapter.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src-tauri/src/p2pool_adapter.rs b/src-tauri/src/p2pool_adapter.rs index edc4920a1..d0863a1ef 100644 --- a/src-tauri/src/p2pool_adapter.rs +++ b/src-tauri/src/p2pool_adapter.rs @@ -111,7 +111,7 @@ impl ProcessAdapter for P2poolAdapter { args.push("--squad-prefix".to_string()); args.push("default".to_string()); args.push("--num-squads".to_string()); - args.push("3".to_string()); + args.push("2".to_string()); let mut envs = HashMap::new(); match Network::get_current_or_user_setting_or_default() { Network::Esmeralda => { From 54afae0a5e7fba5bc03855221fb6e95211cc9180 Mon Sep 17 00:00:00 2001 From: stringhandler Date: Fri, 31 Jan 2025 11:15:22 +0200 Subject: [PATCH 2/4] feat: enable p2pool tiers (#1455) Adds a benchmarking step to setup where it runs xmrig with 1 thread and then multiplies it by the number of threads used in Custom Levels. This is not entirely accurate, but using all threads to get an accurate read makes the app unresponsive. If the number is less than 1000, it will put the node in a "mini_x" pool instead of the "default_x" pool. --- src-tauri/src/cpu_miner.rs | 78 +++++++++++++++++++++++++++++++++ src-tauri/src/main.rs | 29 +++++++++++- src-tauri/src/p2pool_adapter.rs | 8 +++- src-tauri/src/p2pool_manager.rs | 11 +++++ src-tauri/src/xmrig_adapter.rs | 12 ++--- 5 files changed, 130 insertions(+), 8 deletions(-) diff --git a/src-tauri/src/cpu_miner.rs b/src-tauri/src/cpu_miner.rs index 796b4e9ef..bf56e388c 100644 --- a/src-tauri/src/cpu_miner.rs +++ b/src-tauri/src/cpu_miner.rs @@ -32,9 +32,11 @@ use log::{debug, error, warn}; use std::path::PathBuf; use std::sync::Arc; use std::thread; +use std::time::{Duration, Instant}; use tari_core::transactions::tari_amount::MicroMinotari; use tari_shutdown::ShutdownSignal; use tokio::sync::RwLock; +use tokio::time::{sleep, timeout}; const LOG_TARGET: &str = "tari::universe::cpu_miner"; const ECO_MODE_CPU_USAGE: u32 = 30; @@ -125,6 +127,82 @@ impl CpuMiner { Ok(()) } + pub async fn start_benchmarking( + &mut self, + app_shutdown: ShutdownSignal, + duration: Duration, + base_path: PathBuf, + config_path: PathBuf, + log_dir: PathBuf, + ) -> Result { + let mut lock = self.watcher.write().await; + + let xmrig_node_connection = XmrigNodeConnection::Benchmark; + let max_cpu_available = thread::available_parallelism(); + let max_cpu_available = match max_cpu_available { + Ok(available_cpus) => u32::try_from(available_cpus.get()).unwrap_or(1), + Err(_) => 1, + }; + + lock.adapter.node_connection = Some(xmrig_node_connection); + // We're going to use benchmarking, so the address isn't used + lock.adapter.monero_address = Some("44AFFq5kSiGBoZ4NMDwYtN18obc8AemS33DBLWs3H7otXft3XjrpDtQGv7SqSsaBYBb98uNbr2VBBEt7f2wfn3RVGQBEP3A".to_string()); + lock.adapter.cpu_threads = Some(Some(1)); // Use one thread so that the machine doesn't lock up + lock.adapter.extra_options = vec![]; + + let timeout_duration = duration + Duration::from_secs(10); + let res = match timeout(timeout_duration, async move { + lock.start( + app_shutdown.clone(), + base_path.clone(), + config_path.clone(), + log_dir.clone(), + Binaries::Xmrig, + ) + .await?; + let mut status = None; + for _ in 0..10 { + if let Some(s) = lock.status_monitor.as_ref() { + status = Some(s.clone()); + break; + } + sleep(Duration::from_secs(1)).await; + } + if status.is_none() { + error!(target: LOG_TARGET, "Failed to get status for xmrig for benchmarking"); + return Ok(0); + } + let status = status.expect("Can't fail"); + let start_time = Instant::now(); + let mut max_hashrate = 0f64; + loop { + if app_shutdown.is_triggered() { + break; + } + sleep(Duration::from_secs(1)).await; + if let Ok(stats) = status.summary().await { + let hash_rate = stats.hashrate.total[0].unwrap_or_default(); + if hash_rate > max_hashrate { + max_hashrate = hash_rate; + } + if start_time.elapsed() > duration { + break; + } + } + } // wait until we have stats from xmrig, so its started + #[allow(clippy::cast_possible_truncation)] + Ok::(max_hashrate.floor() as u64) + }) + .await + { + Ok(res) => Ok(res? * u64::from(max_cpu_available)), + Err(_) => Ok(0), + }; + let mut lock2 = self.watcher.write().await; + lock2.stop().await?; + res + } + pub async fn stop(&mut self) -> Result<(), anyhow::Error> { let mut lock = self.watcher.write().await; lock.stop().await?; diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 14a8dd141..9bc287228 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -593,13 +593,39 @@ async fn setup_inner( telemetry_id = "unknown_miner_tari_universe".to_string(); } + // Benchmark if needed. + progress.set_max(77).await; + // let mut cpu_miner_config = state.cpu_miner_config.read().await.clone(); + // Clear out so we use default. + let _unused = telemetry_service + .send( + "starting-benchmarking".to_string(), + json!({ + "service": "starting_benchmarking", + "percentage":75, + }), + ) + .await; + + let mut cpu_miner = state.cpu_miner.write().await; + let benchmarked_hashrate = cpu_miner + .start_benchmarking( + state.shutdown.to_signal(), + Duration::from_secs(30), + data_dir.clone(), + config_dir.clone(), + log_dir.clone(), + ) + .await?; + drop(cpu_miner); + if p2pool_enabled { let _unused = telemetry_service .send( "starting-p2pool".to_string(), json!({ "service": "starting_p2pool", - "percentage":75, + "percentage":77, }), ) .await; @@ -612,6 +638,7 @@ async fn setup_inner( let p2pool_config = P2poolConfig::builder() .with_base_node(base_node_grpc) .with_stats_server_port(state.config.read().await.p2pool_stats_server_port()) + .with_cpu_benchmark_hashrate(Some(benchmarked_hashrate)) .build()?; state diff --git a/src-tauri/src/p2pool_adapter.rs b/src-tauri/src/p2pool_adapter.rs index d0863a1ef..76aa195bd 100644 --- a/src-tauri/src/p2pool_adapter.rs +++ b/src-tauri/src/p2pool_adapter.rs @@ -109,7 +109,13 @@ impl ProcessAdapter for P2poolAdapter { let pid_file_name = self.pid_file_name().to_string(); args.push("--squad-prefix".to_string()); - args.push("default".to_string()); + let mut squad_prefix = "default"; + if let Some(benchmark) = config.cpu_benchmark_hashrate { + if benchmark < 1000 { + squad_prefix = "mini"; + } + } + args.push(squad_prefix.to_string()); args.push("--num-squads".to_string()); args.push("2".to_string()); let mut envs = HashMap::new(); diff --git a/src-tauri/src/p2pool_manager.rs b/src-tauri/src/p2pool_manager.rs index 01819001c..34ab4514c 100644 --- a/src-tauri/src/p2pool_manager.rs +++ b/src-tauri/src/p2pool_manager.rs @@ -44,6 +44,7 @@ pub struct P2poolConfig { pub grpc_port: u16, pub stats_server_port: u16, pub base_node_address: String, + pub cpu_benchmark_hashrate: Option, } pub struct P2poolConfigBuilder { @@ -70,6 +71,14 @@ impl P2poolConfigBuilder { self } + pub fn with_cpu_benchmark_hashrate( + &mut self, + cpu_benchmark_hashrate: Option, + ) -> &mut Self { + self.config.cpu_benchmark_hashrate = cpu_benchmark_hashrate; + self + } + pub fn build(&self) -> Result { let grpc_port = PortAllocator::new().assign_port_with_fallback(); @@ -77,6 +86,7 @@ impl P2poolConfigBuilder { grpc_port, stats_server_port: self.config.stats_server_port, base_node_address: self.config.base_node_address.clone(), + cpu_benchmark_hashrate: self.config.cpu_benchmark_hashrate, }) } } @@ -93,6 +103,7 @@ impl Default for P2poolConfig { grpc_port: 18145, stats_server_port: 19000, base_node_address: String::from("http://127.0.0.1:18142"), + cpu_benchmark_hashrate: None, } } } diff --git a/src-tauri/src/xmrig_adapter.rs b/src-tauri/src/xmrig_adapter.rs index 2ac591188..bc278f6c0 100644 --- a/src-tauri/src/xmrig_adapter.rs +++ b/src-tauri/src/xmrig_adapter.rs @@ -37,6 +37,7 @@ const LOG_TARGET: &str = "tari::universe::xmrig_adapter"; pub enum XmrigNodeConnection { LocalMmproxy { host_name: String, port: u16 }, + Benchmark, } impl XmrigNodeConnection { @@ -50,6 +51,9 @@ impl XmrigNodeConnection { "--coin=monero".to_string(), ] } + XmrigNodeConnection::Benchmark => { + vec!["--benchmark=1m".to_string()] + } } } } @@ -128,13 +132,9 @@ impl ProcessAdapter for XmrigAdapter { .as_ref() .ok_or(anyhow::anyhow!("Monero address not set"))? )); - #[allow(clippy::collapsible_match)] // don't specify threads for ludicrous mode - #[allow(clippy::collapsible_match)] - if let Some(cpu_threads) = self.cpu_threads { - if let Some(cpu_threads) = cpu_threads { - args.push(format!("--threads={}", cpu_threads)); - } + if let Some(Some(cpu_threads)) = self.cpu_threads { + args.push(format!("--threads={}", cpu_threads)); } args.push("--verbose".to_string()); for extra_option in &self.extra_options { From b4df999f0de615d8c5c7496e8c9d1118586a6946 Mon Sep 17 00:00:00 2001 From: brianp Date: Fri, 31 Jan 2025 10:24:44 +0100 Subject: [PATCH 3/4] chore: update binary versions --- src-tauri/binaries_versions_esmeralda.json | 8 ++++---- src-tauri/binaries_versions_nextnet.json | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src-tauri/binaries_versions_esmeralda.json b/src-tauri/binaries_versions_esmeralda.json index 92daa7275..5655e8d33 100644 --- a/src-tauri/binaries_versions_esmeralda.json +++ b/src-tauri/binaries_versions_esmeralda.json @@ -1,10 +1,10 @@ { "binaries": { "xmrig": "=6.22.0", - "mmproxy": "=1.11.0-pre.0", - "minotari_node": "=1.11.0-pre.0", - "wallet": "=1.11.0-pre.0", - "sha-p2pool": "=0.21.0", + "mmproxy": "=1.11.1-pre.1", + "minotari_node": "=1.11.1-pre.1", + "wallet": "=1.11.1-pre.1", + "sha-p2pool": "=0.21.1", "xtrgpuminer": "=0.2.12", "tor": "=13.5.7" } diff --git a/src-tauri/binaries_versions_nextnet.json b/src-tauri/binaries_versions_nextnet.json index 2bf72a004..3e034a4f8 100644 --- a/src-tauri/binaries_versions_nextnet.json +++ b/src-tauri/binaries_versions_nextnet.json @@ -1,10 +1,10 @@ { "binaries": { "xmrig": "=6.22.0", - "mmproxy": "=1.11.0-rc.0", - "minotari_node": "=1.11.0-rc.0", - "wallet": "=1.11.0-rc.0", - "sha-p2pool": "=0.21.0", + "mmproxy": "=1.11.1-rc.1", + "minotari_node": "=1.11.1-rc.1", + "wallet": "=1.11.1-rc.1", + "sha-p2pool": "=0.21.1", "xtrgpuminer": "=0.2.12", "tor": "=13.5.7" } From 29e6b40cf810db87ac0f99a41cd7cca8336e3844 Mon Sep 17 00:00:00 2001 From: brianp Date: Fri, 31 Jan 2025 10:25:01 +0100 Subject: [PATCH 4/4] chore: version bump to v0.9.2 --- package-lock.json | 4 ++-- package.json | 2 +- src-tauri/Cargo.lock | 2 +- src-tauri/Cargo.toml | 2 +- src-tauri/tauri.conf.json | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4af76baac..6b2994c47 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "tari-universe", - "version": "0.9.1", + "version": "0.9.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "tari-universe", - "version": "0.9.1", + "version": "0.9.2", "dependencies": { "@floating-ui/react": "^0.26.28", "@lottiefiles/dotlottie-react": "^0.12.0", diff --git a/package.json b/package.json index a6e149ba4..cc0af8589 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "tari-universe", "private": true, - "version": "0.9.1", + "version": "0.9.2", "type": "module", "scripts": { "dev": "vite dev --mode development", diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 37fbac8b5..5a787d6a8 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -6981,7 +6981,7 @@ dependencies = [ [[package]] name = "tari-universe" -version = "0.9.1" +version = "0.9.2" dependencies = [ "anyhow", "async-trait", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index c14fec0cc..a7296dd66 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -4,7 +4,7 @@ description = "Tari Universe" edition = "2021" name = "tari-universe" repository = "https://github.com/tari-project/universe" -version = "0.9.1" +version = "0.9.2" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 9ef54ac6b..4c0c1a397 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -1,5 +1,5 @@ { - "version": "0.9.1", + "version": "0.9.2", "productName": "Tari Universe (Alpha)", "mainBinaryName": "Tari Universe (Alpha)", "identifier": "com.tari.universe.alpha",