Skip to content

Commit

Permalink
Merge branch 'main' into fix/orphan-chain-sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
brianp authored Nov 28, 2024
2 parents 0b631b2 + 97eac01 commit 1443cae
Show file tree
Hide file tree
Showing 41 changed files with 342 additions and 163 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

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

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.8.1",
"version": "0.8.2",
"type": "module",
"scripts": {
"dev": "vite dev --mode development",
Expand Down
1 change: 1 addition & 0 deletions public/locales/af/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"action-requires-restart": "Hierdie aksie vereis \"n herbegin om veranderinge toe te pas",
"action-restart-copy": "Jou voorkeur sal gestoor word en toegepas word die volgende keer as Tari Universe begin word.",
"app-restart-required": "App herbegin benodig",
"application-info": "Application Information",
"applyInviteCode": "Pas Uitnodigingskode Toe",
"cancel": "Cancel",
"change-language": "Verander taal",
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 @@ -2,6 +2,7 @@
"action-requires-restart": "此操作需要重启以应用更改",
"action-restart-copy": "您的偏好将被保存,并在下次启动 Tari 宇宙时应用。",
"app-restart-required": "需要重启应用",
"application-info": "Application Information",
"applyInviteCode": "应用邀请代码",
"cancel": "取消",
"change-language": "更改语言",
Expand Down
1 change: 1 addition & 0 deletions public/locales/de/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"action-requires-restart": "Diese Aktion erfordert einen Neustart, um Änderungen anzuwenden",
"action-restart-copy": "Ihre Einstellungen werden gespeichert und beim nächsten Start des Tari-Universums angewendet.",
"app-restart-required": "App-Neustart erforderlich",
"application-info": "Application Information",
"applyInviteCode": "Einladungscode anwenden",
"cancel": "Abbrechen",
"change-language": "Sprache",
Expand Down
1 change: 1 addition & 0 deletions public/locales/en/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"action-requires-restart": "This action requires restart to apply changes",
"action-restart-copy": "Your preference will be saved and applied the next time Tari Universe is started.",
"app-restart-required": "App restart required",
"application-info": "Application Information",
"applyInviteCode": "Apply Invite Code",
"cancel": "Cancel",
"change-language": "Language",
Expand Down
1 change: 1 addition & 0 deletions public/locales/fr/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"action-requires-restart": "Cette action nécessite un redémarrage pour appliquer les modifications",
"action-restart-copy": "Votre préférence sera enregistrée et appliquée lors du prochain démarrage de Tari Universe.",
"app-restart-required": "Redémarrage de l\"application requis",
"application-info": "Application Information",
"applyInviteCode": "Appliquer le code d\"invitation",
"cancel": "Cancel",
"change-language": "Langue",
Expand Down
1 change: 1 addition & 0 deletions public/locales/hi/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"action-requires-restart": "इस क्रिया के लिए परिवर्तनों को लागू करने हेतु पुनः आरंभ करना आवश्यक है",
"action-restart-copy": "आपकी पसंद को सहेजा जाएगा और अगली बार जब तारी यूनिवर्स शुरू होगा, तब लागू किया जाएगा।",
"app-restart-required": "ऐप पुनः प्रारंभ आवश्यक है",
"application-info": "Application Information",
"applyInviteCode": "आमंत्रण कोड लागू करें",
"cancel": "रद्द करें",
"change-language": "भाषा",
Expand Down
1 change: 1 addition & 0 deletions public/locales/id/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"action-requires-restart": "Tindakan ini memerlukan restart untuk menerapkan perubahan",
"action-restart-copy": "Preferensi Anda akan disimpan dan diterapkan saat Tari Universe dimulai berikutnya.",
"app-restart-required": "Diperlukan restart aplikasi",
"application-info": "Application Information",
"applyInviteCode": "Terapkan Kode Undangan",
"cancel": "Batal",
"change-language": "Bahasa",
Expand Down
1 change: 1 addition & 0 deletions public/locales/ja/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"action-requires-restart": "この操作には再起動が必要です。変更を適用します",
"action-restart-copy": "設定は保存され、次回Tari Universeを起動したときに適用されます。",
"app-restart-required": "アプリの再起動が必要です",
"application-info": "Application Information",
"applyInviteCode": "招待コードを適用",
"cancel": "キャンセル",
"change-language": "言語",
Expand Down
1 change: 1 addition & 0 deletions public/locales/ko/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"action-requires-restart": "이 작업은 변경 사항을 적용하기 위해 재시작이 필요합니다",
"action-restart-copy": "선호 설정이 저장되어 다음에 Tari Universe가 시작될 때 적용됩니다.",
"app-restart-required": "앱 재시작 필요",
"application-info": "Application Information",
"applyInviteCode": "초대 코드 적용",
"cancel": "취소",
"change-language": "언어",
Expand Down
1 change: 1 addition & 0 deletions public/locales/pl/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"action-requires-restart": "Ta akcja wymaga ponownego uruchomienia, aby wprowadzić zmiany",
"action-restart-copy": "Twoje preferencje zostaną zapisane i zastosowane przy następnym uruchomieniu Tari Universe.",
"app-restart-required": "Wymagany restart aplikacji",
"application-info": "Application Information",
"applyInviteCode": "Zastosuj Kod Zaproszenia",
"cancel": "Anuluj",
"change-language": "Zmień język",
Expand Down
1 change: 1 addition & 0 deletions public/locales/ru/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"action-requires-restart": "Для применения изменений требуется перезапуск",
"action-restart-copy": "Ваши предпочтения будут сохранены и применены при следующем запуске Tari Universe.",
"app-restart-required": "Требуется перезапуск приложения",
"application-info": "Application Information",
"applyInviteCode": "Применить код приглашения",
"cancel": "Отмена",
"change-language": "Язык",
Expand Down
1 change: 1 addition & 0 deletions public/locales/tr/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"action-requires-restart": "Bu işlem değişikliklerin uygulanması için yeniden başlatma gerektirir",
"action-restart-copy": "Tercihiniz kaydedilecek ve bir sonraki Tari Universe başlatıldığında uygulanacaktır.",
"app-restart-required": "Uygulama yeniden başlatılması gerekiyor",
"application-info": "Application Information",
"applyInviteCode": "Davet Kodunu Uygula",
"cancel": "İptal",
"change-language": "Dil Değiştir",
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 @@ description = "Tari Universe"
edition = "2021"
name = "tari-universe"
repository = "https://github.com/tari-project/universe"
version = "0.8.1"
version = "0.8.2"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
8 changes: 8 additions & 0 deletions src-tauri/src/app_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use sys_locale::get_locale;
use crate::credential_manager::CredentialManager;
use crate::{consts::DEFAULT_MONERO_ADDRESS, internal_wallet::generate_password};
use anyhow::anyhow;
use chrono::{DateTime, Utc};
use log::{debug, info, warn};
use monero_address_creator::network::Mainnet;
use monero_address_creator::Seed as MoneroSeed;
Expand Down Expand Up @@ -186,6 +187,7 @@ pub struct GpuThreads {
pub(crate) struct AppConfig {
config_version: u32,
config_file: Option<PathBuf>,
created_at: Option<DateTime<Utc>>,
mode: MiningMode,
display_mode: DisplayMode,
auto_mining: bool,
Expand Down Expand Up @@ -226,6 +228,7 @@ impl AppConfig {
Self {
config_version: default_version(),
config_file: None,
created_at: None,
mode: MiningMode::Eco,
display_mode: DisplayMode::Light,
auto_mining: true,
Expand Down Expand Up @@ -269,13 +272,18 @@ impl AppConfig {
if file.exists() {
debug!(target: LOG_TARGET, "Loading app config from file: {:?}", file);
let config = fs::read_to_string(&file).await?;
self.created_at = Some(file.clone().metadata()?.created()?.into());
self.apply_loaded_config(config);
} else {
info!(target: LOG_TARGET, "App config does not exist or is corrupt. Creating new one");
if let Ok(address) = create_monereo_address(config_path).await {
self.monero_address = address;
self.monero_address_is_generated = true;
}

if self.update_config_file().await.is_ok() {
self.created_at = Some(file.clone().metadata()?.created()?.into());
}
}
self.update_config_file().await?;
Ok(())
Expand Down
10 changes: 10 additions & 0 deletions src-tauri/src/cpu_miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@ impl CpuMiner {
Ok(())
}

pub async fn is_running(&self) -> bool {
let lock = self.watcher.read().await;
lock.is_running()
}

pub async fn is_pid_file_exists(&self, base_path: PathBuf) -> bool {
let lock = self.watcher.read().await;
lock.is_pid_file_exists(base_path)
}

pub async fn status(
&self,
network_hash_rate: u64,
Expand Down
10 changes: 10 additions & 0 deletions src-tauri/src/gpu_miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@ impl GpuMiner {
Ok(())
}

pub async fn is_running(&self) -> bool {
let process_watcher = self.watcher.read().await;
process_watcher.is_running()
}

pub async fn is_pid_file_exists(&self, base_path: PathBuf) -> bool {
let lock = self.watcher.read().await;
lock.is_pid_file_exists(base_path)
}

pub async fn status(
&self,
network_hash_rate: u64,
Expand Down
57 changes: 7 additions & 50 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use tokio::sync::{Mutex, RwLock};
use tokio::time;
use tor_adapter::TorConfig;
use utils::logging_utils::setup_logging;
use utils::shutdown_utils::stop_all_processes;
use wallet_adapter::TransactionInfo;

use app_config::{AppConfig, GpuThreads};
Expand Down Expand Up @@ -128,50 +129,6 @@ struct UpdateProgressRustEvent {
downloaded: u64,
}

async fn stop_all_miners(state: UniverseAppState, sleep_secs: u64) -> Result<(), String> {
state
.cpu_miner
.write()
.await
.stop()
.await
.map_err(|e| e.to_string())?;
state
.gpu_miner
.write()
.await
.stop()
.await
.map_err(|e| e.to_string())?;
let exit_code = state
.wallet_manager
.stop()
.await
.map_err(|e| e.to_string())?;
info!(target: LOG_TARGET, "Wallet manager stopped with exit code: {}", exit_code);
state
.mm_proxy_manager
.stop()
.await
.map_err(|e| e.to_string())?;
let exit_code = state.node_manager.stop().await.map_err(|e| e.to_string())?;
info!(target: LOG_TARGET, "Node manager stopped with exit code: {}", exit_code);
let exit_code = state
.p2pool_manager
.stop()
.await
.map_err(|e| e.to_string())?;
info!(target: LOG_TARGET, "P2Pool manager stopped with exit code: {}", exit_code);

let exit_code = state.tor_manager.stop().await.map_err(|e| e.to_string())?;
info!(target: LOG_TARGET, "Tor manager stopped with exit code: {}", exit_code);
state.shutdown.clone().trigger();

// TODO: Find a better way of knowing that all miners have stopped
sleep(std::time::Duration::from_secs(sleep_secs));
Ok(())
}

#[tauri::command]
async fn set_mode(
mode: String,
Expand Down Expand Up @@ -501,7 +458,7 @@ async fn restart_application(
app: tauri::AppHandle,
) -> Result<(), String> {
if should_stop_miners {
stop_all_miners(state.inner().clone(), 5).await?;
stop_all_processes(state.inner().clone(), true).await?;
}

app.restart();
Expand All @@ -514,7 +471,7 @@ async fn exit_application(
state: tauri::State<'_, UniverseAppState>,
app: tauri::AppHandle,
) -> Result<(), String> {
stop_all_miners(state.inner().clone(), 5).await?;
stop_all_processes(state.inner().clone(), true).await?;

app.exit(0);
Ok(())
Expand Down Expand Up @@ -1142,7 +1099,7 @@ async fn import_seed_words(
.app_local_data_dir()
.expect("Could not get data dir");

stop_all_miners(state.inner().clone(), 5).await?;
stop_all_processes(state.inner().clone(), false).await?;

tauri::async_runtime::spawn(async move {
match InternalWallet::create_from_seed(config_path, seed_words).await {
Expand Down Expand Up @@ -1867,7 +1824,7 @@ async fn reset_settings<'r>(
state: tauri::State<'_, UniverseAppState>,
app: tauri::AppHandle,
) -> Result<(), String> {
stop_all_miners(state.inner().clone(), 5).await?;
stop_all_processes(state.inner().clone(), true).await?;
let network = Network::get_current_or_user_setting_or_default().as_key_str();

let app_config_dir = app.path_resolver().app_config_dir();
Expand Down Expand Up @@ -2374,12 +2331,12 @@ fn main() {
tauri::RunEvent::ExitRequested { api: _, .. } => {
// api.prevent_exit();
info!(target: LOG_TARGET, "App shutdown caught");
let _unused = block_on(stop_all_miners(app_state.clone(), 2));
let _unused = block_on(stop_all_processes(app_state.clone(), true));
info!(target: LOG_TARGET, "App shutdown complete");
}
tauri::RunEvent::Exit => {
info!(target: LOG_TARGET, "App shutdown caught");
let _unused = block_on(stop_all_miners(app_state.clone(), 2));
let _unused = block_on(stop_all_processes(app_state.clone(), true));
info!(target: LOG_TARGET, "Tari Universe v{} shut down successfully", _app_handle.package_info().version);
}
RunEvent::MainEventsCleared => {
Expand Down
11 changes: 11 additions & 0 deletions src-tauri/src/mm_proxy_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ impl MmProxyManager {
let mut current_start_config = self.start_config.write().await;
*current_start_config = Some(config.clone());
let mut process_watcher = self.watcher.write().await;

let new_config = MergeMiningProxyConfig {
tari_address: config.tari_address.clone(),
base_node_grpc_port: config.base_node_grpc_port,
Expand Down Expand Up @@ -135,4 +136,14 @@ impl MmProxyManager {
process_watcher.stop().await?;
Ok(())
}

pub async fn is_running(&self) -> bool {
let lock = self.watcher.read().await;
lock.is_running()
}

pub async fn is_pid_file_exists(&self, base_path: PathBuf) -> bool {
let lock = self.watcher.read().await;
lock.is_pid_file_exists(base_path)
}
}
11 changes: 11 additions & 0 deletions src-tauri/src/node_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ impl NodeManager {
) -> Result<(), NodeManagerError> {
{
let mut process_watcher = self.watcher.write().await;

process_watcher.adapter.use_tor = use_tor;
process_watcher.adapter.tor_control_port = tor_control_port;
process_watcher.stop_on_exit_codes = vec![114];
Expand Down Expand Up @@ -207,6 +208,16 @@ impl NodeManager {
Ok(exit_code)
}

pub async fn is_running(&self) -> bool {
let process_watcher = self.watcher.read().await;
process_watcher.is_running()
}

pub async fn is_pid_file_exists(&self, base_path: PathBuf) -> bool {
let lock = self.watcher.read().await;
lock.is_pid_file_exists(base_path)
}

pub async fn check_if_is_orphan_chain(
&self,
report_to_sentry: bool,
Expand Down
Loading

0 comments on commit 1443cae

Please sign in to comment.