Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(miner): clythor #456

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions public/locales/af/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
},
"last-block-added-time": "Tyd toe laaste blok by ketting gevoeg was",
"visual-mode": "Visuele modus",
"randomX-miner": "RandomX mynwerker",
"gpu-unavailable": "⚠️ GPU gedeaktiveer omdat jou hardeware dit nie ondersteun nie",
"reset-settings": "Reset Settings",
"reset-permanently": "Are you sure you want to reset all settings permanently?",
Expand Down
1 change: 1 addition & 0 deletions public/locales/af/setup-view.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"checking-latest-version-wallet": "Bepaal nuutste weergawe van beursie",
"checking-latest-version-xmrig": "Bepaal nuutste weergawe van xmrig",
"checking-latest-version-sha-p2pool": "Bepaal nuutste weergawe van sha-p2pool",
"checking-latest-version-clythor": "Bepaal nuutste weergawe van clythor",
"waiting-for-wallet": "Wag vir beursie",
"waiting-for-node": "Wag vir node om te sinkroniseer",
"preparing-for-initial-sync": "Gekoppel aan netwerk nodes {{initial_connected_peers}}/{{required_peers}}",
Expand Down
1 change: 1 addition & 0 deletions public/locales/cn/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"reset-wallet": "Reset wallet",
"experimental-title": "实验性功能",
"experimental-warning": "⚠️ 警告:这些功能正在积极开发中,可能会表现得不可预测。请谨慎操作。",
"randomX-miner": "RandomX 挖矿",
"connected-to-tari": "Connected to the Tari Network",
"not-connected-to-tari": "Not connected to the Tari Network",
"connected-peers": "Connected Peers",
Expand Down
3 changes: 2 additions & 1 deletion public/locales/cn/setup-view.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"checking-latest-version-wallet": "正在检查钱包的最新版本",
"checking-latest-version-xmrig": "正在检查 xmrig 的最新版本",
"checking-latest-version-sha-p2pool": "正在检查 sha-p2pool 的最新版本",
"checking-latest-version-clythor": "正在检查clythor的最新版本",
"waiting-for-wallet": "等待钱包",
"waiting-for-node": "等待节点同步",
"preparing-for-initial-sync": "连接到网络节点 {{initial_connected_peers}}/{{required_peers}}",
Expand All @@ -25,4 +26,4 @@
"would-you-like-to-install": "您想现在安装 Tari Universe {{version}} 吗?",
"yes": "是",
"no": "否"
}
}
1 change: 1 addition & 0 deletions public/locales/en/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"reset-permanently": "Are you sure you want to reset all settings permanently?",
"reset-wallet": "Reset wallet",
"experimental-title": "Experimental Features",
"randomX-miner": "RandomX miner",
"experimental-warning": "⚠️ Warning: These features are under active development and could behave unpredictably. Please proceed carefully.",
"connected-to-tari": "Connected to the Tari Network",
"not-connected-to-tari": "Not connected to the Tari Network",
Expand Down
3 changes: 2 additions & 1 deletion public/locales/en/setup-view.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"checking-latest-version-wallet": "Checking for latest version of wallet",
"checking-latest-version-xmrig": "Checking for latest version of xmrig",
"checking-latest-version-sha-p2pool": "Checking for latest version of sha-p2pool",
"checking-latest-version-clythor": "Checking for latest version of clythor",
"waiting-for-wallet": "Waiting for wallet",
"waiting-for-node": "Waiting for node to sync",
"preparing-for-initial-sync": "Connecting to network peers {{initial_connected_peers}}/{{required_peers}}",
Expand All @@ -25,4 +26,4 @@
"would-you-like-to-install": "Would you like to install Tari Universe {{version}} now?",
"yes": "Yes",
"no": "No"
}
}
1 change: 1 addition & 0 deletions public/locales/pl/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"reset-permanently": "Czy na pewno chcesz trwale zresetować ustawienia?",
"gpu-unavailable": "⚠️ Kopanie GPU niedostępne ponieważ Twój sprzęt go nie obsługuje",
"reset-wallet": "Resetuj porfel",
"randomX-miner": "Miner RandomX",
"connected-to-tari-network": "Połączono z siecią Tari",
"not-connected-to-tari-network": "Brak połączenia z siecią Tari",
"connected-peers": "Połączone węzły",
Expand Down
1 change: 1 addition & 0 deletions public/locales/pl/setup-view.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"checking-latest-version-wallet": "Sprawdzanie najnowszej wersji portfela",
"checking-latest-version-xmrig": "Sprawdzanie najnowszej wersji xmrig",
"checking-latest-version-sha-p2pool": "Sprawdzanie najnowszej wersji sha-p2pool",
"checking-latest-version-clythor": "Sprawdzanie najnowszej wersji clythor",
"waiting-for-wallet": "Oczekiwanie na portfel",
"waiting-for-node": "Oczekiwanie na synchronizację węzła",
"preparing-for-initial-sync": "Łączenie się z urządzeniami równorzędnymi w sieci {{initial_connected_peers}}/{{required_peers}}",
Expand Down
3 changes: 2 additions & 1 deletion public/locales/tr/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@
"reset-permanently": "Tüm ayarları kalıcı olarak sıfırlamak istediğinizden emin misiniz?",
"reset-wallet": "Reset wallet",
"experimental-title": "Deneysel Özellikler",
"randomX-miner": "RandomX madencisi",
"experimental-warning": "⚠️ Uyarı: Bu özellikler aktif geliştirme aşamasındadır ve öngörülemeyen şekilde davranabilir. Lütfen dikkatlice ilerleyin.",
"connected-to-tari": "Connected to the Tari Network",
"not-connected-to-tari": "Not connected to the Tari Network",
"connected-peers": "Connected Peers",
"should-use-system-language": "Use system language"
}
}
3 changes: 2 additions & 1 deletion public/locales/tr/setup-view.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"checking-latest-version-wallet": "Cüzdanın en son sürümü kontrol ediliyor",
"checking-latest-version-xmrig": "xmrig'in en son sürümü kontrol ediliyor",
"checking-latest-version-sha-p2pool": "sha-p2pool'un en son sürümü kontrol ediliyor",
"checking-latest-version-clythor": "clythor'un en son sürümü kontrol ediliyor",
"waiting-for-wallet": "Cüzdan bekleniyor",
"waiting-for-node": "Düğümün senkronize edilmesi bekleniyor",
"preparing-for-initial-sync": "İlk senkronizasyon için hazırlanıyor {{initial_connected_peers}}/{{required_peers}}",
Expand All @@ -25,4 +26,4 @@
"would-you-like-to-install": "Tari Universe'ü şimdi yüklemek ister misiniz {{version}} ?",
"yes": "Evet",
"no": "Hayır"
}
}
24 changes: 23 additions & 1 deletion src-tauri/src/app_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use log::{debug, info, warn};
use serde::{Deserialize, Serialize};
use tokio::fs;

use crate::{consts::DEFAULT_MONERO_ADDRESS, internal_wallet::generate_password};
use crate::{
consts::DEFAULT_MONERO_ADDRESS, cpu_miner::RandomXMiner, internal_wallet::generate_password,
};

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

Expand All @@ -33,6 +35,8 @@ pub struct AppConfigFromFile {
gpu_mining_enabled: bool,
#[serde(default = "default_true")]
cpu_mining_enabled: bool,
#[serde(default = "default_randomx_miner")]
randomx_miner: RandomXMiner,
#[serde(default = "default_false")]
has_system_language_been_proposed: bool,
#[serde(default = "default_false")]
Expand All @@ -54,6 +58,7 @@ impl Default for AppConfigFromFile {
monero_address: default_monero_address(),
gpu_mining_enabled: true,
cpu_mining_enabled: true,
randomx_miner: default_randomx_miner(),
has_system_language_been_proposed: false,
should_always_use_system_language: false,
application_language: default_application_language(),
Expand Down Expand Up @@ -98,6 +103,7 @@ pub(crate) struct AppConfig {
monero_address: String,
gpu_mining_enabled: bool,
cpu_mining_enabled: bool,
randomx_miner: RandomXMiner,
has_system_language_been_proposed: bool,
should_always_use_system_language: bool,
application_language: String,
Expand All @@ -117,6 +123,7 @@ impl AppConfig {
monero_address: DEFAULT_MONERO_ADDRESS.to_string(),
gpu_mining_enabled: true,
cpu_mining_enabled: true,
randomx_miner: RandomXMiner::Clythor,
has_system_language_been_proposed: false,
should_always_use_system_language: false,
application_language: default_application_language(),
Expand Down Expand Up @@ -152,6 +159,7 @@ impl AppConfig {
self.monero_address = config.monero_address;
self.gpu_mining_enabled = config.gpu_mining_enabled;
self.cpu_mining_enabled = config.cpu_mining_enabled;
self.randomx_miner = config.randomx_miner;
self.has_system_language_been_proposed = config.has_system_language_been_proposed;
self.should_always_use_system_language = config.should_always_use_system_language;
self.application_language = config.application_language;
Expand Down Expand Up @@ -257,6 +265,15 @@ impl AppConfig {
Ok(())
}

pub fn randomx_miner(&self) -> RandomXMiner {
self.randomx_miner
}

pub async fn set_randomx_miner(&mut self, miner: RandomXMiner) -> Result<(), anyhow::Error> {
self.randomx_miner = miner;
self.update_config_file().await?;
Ok(())
}
pub fn application_language(&self) -> &str {
&self.application_language
}
Expand Down Expand Up @@ -310,6 +327,7 @@ impl AppConfig {
monero_address: self.monero_address.clone(),
gpu_mining_enabled: self.gpu_mining_enabled,
cpu_mining_enabled: self.cpu_mining_enabled,
randomx_miner: self.randomx_miner,
has_system_language_been_proposed: self.has_system_language_been_proposed,
should_always_use_system_language: self.should_always_use_system_language,
application_language: self.application_language.clone(),
Expand Down Expand Up @@ -351,6 +369,10 @@ fn default_monero_address() -> String {
DEFAULT_MONERO_ADDRESS.to_string()
}

fn default_randomx_miner() -> RandomXMiner {
RandomXMiner::Clythor
}

fn default_application_language() -> String {
"en".to_string()
}
8 changes: 8 additions & 0 deletions src-tauri/src/binaries/binaries_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub enum Binaries {
Wallet,
ShaP2pool,
GpuMiner,
Clythor,
}

impl Binaries {
Expand All @@ -21,6 +22,7 @@ impl Binaries {
Binaries::Wallet => "wallet",
Binaries::ShaP2pool => "sha-p2pool",
Binaries::GpuMiner => "xtrgpuminer",
Binaries::Clythor => "clythor",
}
}

Expand All @@ -32,6 +34,7 @@ impl Binaries {
"wallet" => Some(Binaries::Wallet),
"sha-p2pool" => Some(Binaries::ShaP2pool),
"xtrgpuminer" => Some(Binaries::GpuMiner),
"clythor" => Some(Binaries::Clythor),
_ => None,
}
}
Expand Down Expand Up @@ -62,6 +65,10 @@ impl Binaries {
let file_name = "xtrgpuminer";
PathBuf::from(file_name)
}
Binaries::Clythor => {
let file_name = "clythor";
PathBuf::from(file_name)
}
}
}

Expand All @@ -73,6 +80,7 @@ impl Binaries {
Binaries::Wallet,
Binaries::ShaP2pool,
Binaries::GpuMiner,
Binaries::Clythor,
]
.iter()
.copied()
Expand Down
13 changes: 13 additions & 0 deletions src-tauri/src/binaries/binaries_resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@ impl BinaryResolver {
_ => panic!("Unsupported network"),
};

binary_manager.insert(
Binaries::Clythor,
BinaryManager::new(
Binaries::Clythor.name().to_string(),
Box::new(GithubReleasesAdapter {
repo: "clythor".to_string(),
owner: "tari-project".to_string(),
specific_name: None,
}),
None,
true,
),
);
binary_manager.insert(
Binaries::Xmrig,
BinaryManager::new(
Expand Down
139 changes: 139 additions & 0 deletions src-tauri/src/clythor_adapter.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
use std::path::PathBuf;

use anyhow::Error;
use async_trait::async_trait;
use log::warn;
use tari_shutdown::Shutdown;

use crate::binaries::{Binaries, BinaryResolver};
use crate::process_adapter::{ProcessAdapter, ProcessInstance, StatusMonitor};
use crate::process_utils;
use crate::xmrig::http_api::XmrigHttpApiClient;

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

pub struct LocalMmproxy {
pub host_name: String,
pub port: u16,
}

pub struct ClythorAdapter {
node_connection: LocalMmproxy,
monero_address: String,
http_api_token: String,
http_api_port: u16,
mining_threads: usize,
pub client: XmrigHttpApiClient,
// TODO: secure
}

impl ClythorAdapter {
pub fn new(
node_connection: LocalMmproxy,
monero_address: String,
mining_threads: usize,
) -> Self {
let http_api_port = 18000;
let http_api_token = "pass".to_string();
Self {
node_connection,
monero_address,
http_api_token: http_api_token.clone(),
http_api_port,
mining_threads,
client: XmrigHttpApiClient::new(
format!("http://127.0.0.1:{}", http_api_port).clone(),
http_api_token.clone(),
),
}
}
}

impl ProcessAdapter for ClythorAdapter {
type StatusMonitor = ClythorStatusMonitor;

fn spawn_inner(
&self,
data_dir: PathBuf,
_config_dir: PathBuf,
log_dir: PathBuf,
) -> Result<(ProcessInstance, Self::StatusMonitor), anyhow::Error> {
self.kill_previous_instances(data_dir.clone())?;

let clythor_shutdown = Shutdown::new();
let mut shutdown_signal = clythor_shutdown.to_signal();
let clythor_log_file = log_dir.join("clythor.log");
std::fs::create_dir_all(clythor_log_file.parent().unwrap())?;
let clythor_data_dir = data_dir.join("clythor");
std::fs::create_dir_all(&clythor_data_dir)?;
let args = vec![
format!("-b {}", clythor_data_dir.to_str().unwrap()),
format!(
"--log-path={}",
&clythor_log_file.parent().unwrap().to_str().unwrap()
),
format!("--http-port={}", self.http_api_port),
format!("--access-token={}", self.http_api_token),
format!("--user={}", self.monero_address),
format!("--threads={}", self.mining_threads),
format!(
"--monero-base-node-address={}:{}",
self.node_connection.host_name, self.node_connection.port
),
];
let pid_file_path = data_dir.join(self.pid_file_name());

Ok((
ProcessInstance {
shutdown: clythor_shutdown,
handle: Some(tokio::spawn(async move {
let clythor_bin = BinaryResolver::current()
.read()
.await
.resolve_path_to_binary_files(Binaries::Clythor)
.await?;

crate::download_utils::set_permissions(&clythor_bin).await?;
let mut child = process_utils::launch_child_process(&clythor_bin, None, &args)?;

if let Some(id) = child.id() {
let pid_file_path = data_dir.join(&pid_file_path);
std::fs::write(pid_file_path, id.to_string())?;
}
shutdown_signal.wait().await;

child.kill().await?;

match std::fs::remove_file(data_dir.join(&pid_file_path)) {
Ok(_) => {}
Err(e) => {
warn!(target: LOG_TARGET, "Could not clear clythor's pid file - {e}");
}
}

Ok(0)
})),
},
ClythorStatusMonitor {},
))
}

fn name(&self) -> &str {
"clythor"
}

fn pid_file_name(&self) -> &str {
"clythor_pid"
}
}

pub struct ClythorStatusMonitor {}

#[async_trait]
impl StatusMonitor for ClythorStatusMonitor {
type Status = ();

async fn status(&self) -> Result<Self::Status, Error> {
todo!()
}
}
Loading
Loading