Skip to content

Commit

Permalink
Merge branch 'main' into fix/telemetry-data
Browse files Browse the repository at this point in the history
  • Loading branch information
Krakaw committed Sep 6, 2024
2 parents 4081174 + add156d commit 4a01209
Show file tree
Hide file tree
Showing 16 changed files with 243 additions and 176 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "tari-universe",
"private": true,
"version": "0.2.6",
"version": "0.2.7",
"type": "module",
"scripts": {
"dev": "vite dev --mode development",
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/Cargo.lock

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

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ authors = ["The Tari Development Community"]
description = "Tari Universe"
repository = "https://github.com/tari-project/universe"
license = "BSD-3-Clause"
version = "0.2.6"
version = "0.2.7"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
9 changes: 7 additions & 2 deletions src-tauri/log4rs_sample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ appenders:
pattern: "{d(%H:%M)} {h({l}):5} {m}{n}"
filters:
- kind: threshold
level: warn
level: info

# An appender named "web" that writes to a file with a custom pattern encoder
web:
Expand Down Expand Up @@ -73,17 +73,22 @@ appenders:

# Set the default logging level to "info"
root:
level: info
level: debug
appenders:
- other
- stdout

loggers:
# Route log events common to every application to all appenders
tari::universe:
level: debug
appenders:
- stdout
- default
additive: false

tari::universe::web:
level: info
appenders:
- web
additive: false
4 changes: 2 additions & 2 deletions src-tauri/src/cpu_miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ impl CpuMiner {
mut app_shutdown: ShutdownSignal,
cpu_miner_config: &CpuMinerConfig,
monero_address: String,
monero_port: u16,
base_path: PathBuf,
cache_dir: PathBuf,
config_path: PathBuf,
Expand All @@ -60,7 +61,7 @@ impl CpuMiner {
host_name: "127.0.0.1".to_string(),
// port: local_mm_proxy.try_get_listening_port().await?
// TODO: Replace with actual port
port: 18081,
port: monero_port,
}
}
};
Expand Down Expand Up @@ -93,7 +94,6 @@ impl CpuMiner {
self.api_client = Some(xmrig.client);

self.watcher_task = Some(tauri::async_runtime::spawn(async move {
println!("Starting process");
let mut watch_timer = tokio::time::interval(tokio::time::Duration::from_secs(1));
watch_timer.set_missed_tick_behavior(MissedTickBehavior::Skip);
// read events such as stdout
Expand Down
16 changes: 7 additions & 9 deletions src-tauri/src/gpu_miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use tari_core::transactions::tari_amount::MicroMinotari;
use tari_shutdown::ShutdownSignal;
use tokio::sync::RwLock;

use crate::p2pool_manager::P2poolConfig;
use crate::gpu_miner_adapter::GpuNodeSource;
use crate::{
app_config::MiningMode,
gpu_miner_adapter::{GpuMinerAdapter, GpuMinerStatus},
Expand All @@ -19,16 +19,14 @@ const LOG_TARGET: &str = "tari::universe::gpu_miner";

pub(crate) struct GpuMiner {
watcher: Arc<RwLock<ProcessWatcher<GpuMinerAdapter>>>,
p2pool_config: Arc<P2poolConfig>,
}

impl GpuMiner {
pub fn new(p2pool_config: Arc<P2poolConfig>) -> Self {
pub fn new() -> Self {
let adapter = GpuMinerAdapter::new();
let process_watcher = ProcessWatcher::new(adapter);
Self {
watcher: Arc::new(RwLock::new(process_watcher)),
p2pool_config,
}
}

Expand All @@ -37,30 +35,30 @@ impl GpuMiner {
&mut self,
app_shutdown: ShutdownSignal,
tari_address: TariAddress,
node_grpc_port: u16,
p2pool_enabled: bool,
node_source: GpuNodeSource,
base_path: PathBuf,
config_path: PathBuf,
log_path: PathBuf,
mining_mode: MiningMode,
) -> Result<(), anyhow::Error> {
let mut process_watcher = self.watcher.write().await;
process_watcher.adapter.tari_address = tari_address;
process_watcher.adapter.node_grpc_port = node_grpc_port;
process_watcher.adapter.set_mode(mining_mode);
process_watcher.adapter.p2pool_enabled = p2pool_enabled;
process_watcher.adapter.p2pool_grpc_port = self.p2pool_config.grpc_port;
process_watcher.adapter.node_source = Some(node_source);
info!(target: LOG_TARGET, "Starting xtrgpuminer");
process_watcher
.start(app_shutdown, base_path, config_path, log_path)
.await?;
info!(target: LOG_TARGET, "xtrgpuminer started");

Ok(())
}

pub async fn stop(&self) -> Result<(), anyhow::Error> {
info!(target: LOG_TARGET, "Stopping xtrgpuminer");
let mut process_watcher = self.watcher.write().await;
process_watcher.stop().await?;
info!(target: LOG_TARGET, "xtrgpuminer stopped");
Ok(())
}

Expand Down
37 changes: 23 additions & 14 deletions src-tauri/src/gpu_miner_adapter.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::process_utils;
use anyhow::anyhow;
use anyhow::Error;
use async_trait::async_trait;
use log::{debug, warn};
Expand All @@ -17,25 +18,27 @@ use crate::{

const LOG_TARGET: &str = "tari::universe::gpu_miner_adapter";

pub const ECO_MODE_GPU_PERCENTAGE: u8 = 1;
pub const LUDICROUS_MODE_GPU_PERCENTAGE: u8 = 80; // TODO: In future will allow user to configure this, but for now let's not burn the gpu too much
pub const ECO_MODE_GPU_PERCENTAGE: u16 = 1;
pub const LUDICROUS_MODE_GPU_PERCENTAGE: u16 = 800; // TODO: In future will allow user to configure this, but for now let's not burn the gpu too much

pub enum GpuNodeSource {
BaseNode { port: u16 },
P2Pool { port: u16 },
}

pub struct GpuMinerAdapter {
pub(crate) tari_address: TariAddress,
pub(crate) node_grpc_port: u16,
pub(crate) gpu_percentage: u8,
pub(crate) p2pool_enabled: bool,
pub(crate) p2pool_grpc_port: u16,
// Value ranges 1 - 1000
pub(crate) gpu_percentage: u16,
pub(crate) node_source: Option<GpuNodeSource>,
}

impl GpuMinerAdapter {
pub fn new() -> Self {
Self {
tari_address: TariAddress::default(),
node_grpc_port: 0,
gpu_percentage: ECO_MODE_GPU_PERCENTAGE,
p2pool_enabled: false,
p2pool_grpc_port: 0,
node_source: None,
}
}

Expand Down Expand Up @@ -64,10 +67,13 @@ impl ProcessAdapter for GpuMinerAdapter {
std::fs::create_dir_all(&working_dir)?;
std::fs::create_dir_all(config_dir.join("gpuminer"))?;

let tari_node_port = if self.p2pool_enabled {
self.p2pool_grpc_port
} else {
self.node_grpc_port
if self.node_source.is_none() {
return Err(anyhow!("GpuMinerAdapter node_source is not set"));
}

let tari_node_port = match self.node_source.as_ref().unwrap() {
GpuNodeSource::BaseNode { port } => port,
GpuNodeSource::P2Pool { port } => port,
};

let mut args: Vec<String> = vec![
Expand All @@ -87,7 +93,10 @@ impl ProcessAdapter for GpuMinerAdapter {
self.gpu_percentage.to_string(),
];

if self.p2pool_enabled {
if matches!(
self.node_source.as_ref(),
Some(GpuNodeSource::P2Pool { .. })
) {
args.push("--p2pool-enabled".to_string());
}

Expand Down
Loading

0 comments on commit 4a01209

Please sign in to comment.