From 8a8c2678ae3aaeef2ce30932f9a9855f7342146a Mon Sep 17 00:00:00 2001 From: Revertron Date: Mon, 24 May 2021 17:36:07 +0200 Subject: [PATCH] Small UI and log polishing. --- Cargo.toml | 2 +- src/event.rs | 2 +- src/miner.rs | 14 ++++++++------ src/web_ui.rs | 8 ++++---- src/webview/index.html | 2 +- src/webview/scripts.js | 11 ++++++++--- 6 files changed, 23 insertions(+), 16 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 68ee300..3cb27c5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "alfis" -version = "0.5.8" +version = "0.5.9" authors = ["Revertron "] edition = "2018" build = "build.rs" diff --git a/src/event.rs b/src/event.rs index db45dfd..b9a1848 100644 --- a/src/event.rs +++ b/src/event.rs @@ -2,7 +2,7 @@ pub enum Event { MinerStarted, MinerStopped { success: bool, full: bool }, - MinerStats { thread: usize, speed: u64, max_diff: u32, target_diff: u32 }, + MinerStats { thread: u32, speed: u64, max_diff: u32, target_diff: u32 }, KeyGeneratorStarted, KeyGeneratorStopped, KeyCreated { path: String, public: String, hash: String }, diff --git a/src/miner.rs b/src/miner.rs index 9b255b8..83dbeff 100644 --- a/src/miner.rs +++ b/src/miner.rs @@ -247,8 +247,9 @@ impl Miner { let threads = match threads { 0 => cpus, _ => threads - }; + } as u32; debug!("Starting {} threads for mining", threads); + debug!("Mining block {}", serde_json::to_string(&job.block).unwrap()); let thread_spawn_interval = Duration::from_millis(100); let live_threads = Arc::new(AtomicU32::new(0u32)); for cpu in 0..threads { @@ -259,12 +260,14 @@ impl Miner { thread::spawn(move || { live_threads.fetch_add(1, Ordering::SeqCst); if lower { - setup_miner_thread(cpu as u32); + setup_miner_thread(cpu); } let full = job.block.transaction.is_some(); match find_hash(Arc::clone(&context), job.block, Arc::clone(&mining), cpu) { None => { - debug!("Mining was cancelled"); + if live_threads.load(Ordering::Relaxed) >= threads { + debug!("Mining was cancelled"); + } let count = live_threads.fetch_sub(1, Ordering::SeqCst); // If this is the last thread, but mining was not stopped by another thread if count == 1 { @@ -303,7 +306,7 @@ impl Miner { } } -fn find_hash(context: Arc>, mut block: Block, running: Arc, thread: usize) -> Option { +fn find_hash(context: Arc>, mut block: Block, running: Arc, thread: u32) -> Option { let target_diff = block.difficulty; let full = block.transaction.is_some(); let mut digest = Blakeout::new(); @@ -329,7 +332,6 @@ fn find_hash(context: Arc>, mut block: Block, running: Arc>, mut block: Block, running: Arc= block.index { if !full { - info!("Blockchain changed while mining signing block, dropping work"); + //trace!("Blockchain changed while mining signing block, dropping work"); running.store(false, Ordering::SeqCst); return None; } diff --git a/src/web_ui.rs b/src/web_ui.rs index b340630..59fd535 100644 --- a/src/web_ui.rs +++ b/src/web_ui.rs @@ -255,7 +255,7 @@ fn action_loaded(context: &Arc>, web_view: &mut WebView<()>) { } false => { event_handle_info(&handle, "Mining finished without result."); - s.push_str(" showSuccess('Mining unsuccessful, sorry.')"); + s.push_str(" showWarning('Mining unsuccessful, sorry.')"); } } } @@ -354,7 +354,7 @@ fn load_domains(context: &mut MutexGuard, handle: &Handle<()>) { web_view.eval("clearMyDomains();") }); let domains = context.chain.get_my_domains(context.get_keystore()); - debug!("Domains: {:?}", &domains.values()); + //debug!("Domains: {:?}", &domains.values()); for (_identity, (domain, timestamp, data)) in domains { let d = serde_json::to_string(&data).unwrap(); let command = format!("addMyDomain('{}', {}, {}, '{}');", &domain, timestamp, timestamp + DOMAIN_LIFETIME, &d); @@ -608,8 +608,8 @@ impl Status { Status { mining: false, syncing: false, synced_blocks: 0, sync_height: 0, nodes_connected: 0, chain_height: 0, max_diff: 0, speed } } - fn set_thread_speed(&mut self, thread: usize, speed: u64) { - self.speed[thread] = speed; + fn set_thread_speed(&mut self, thread: u32, speed: u64) { + self.speed[thread as usize] = speed; } fn get_speed(&self) -> u64 { diff --git a/src/webview/index.html b/src/webview/index.html index f1294fe..c85382d 100644 --- a/src/webview/index.html +++ b/src/webview/index.html @@ -187,7 +187,7 @@