diff --git a/src/blockchain/chain.rs b/src/blockchain/chain.rs index 2a79a89..6f0c556 100644 --- a/src/blockchain/chain.rs +++ b/src/blockchain/chain.rs @@ -204,7 +204,7 @@ impl Chain { let block = self.last_block().unwrap(); if block.transaction.is_none() { - trace!("No need to sign signing block"); + trace!("No need to mine signing block"); return None; } let keystore = keystore.clone().unwrap().clone(); @@ -229,6 +229,7 @@ impl Chain { } block.index = self.height() + 1; block.prev_block_hash = self.last_block.clone().unwrap().hash; + return Some(block); } None } diff --git a/src/miner.rs b/src/miner.rs index 75bffdb..75a4d2d 100644 --- a/src/miner.rs +++ b/src/miner.rs @@ -191,7 +191,9 @@ impl Miner { } context.chain.add_block(block); let option = Some(job.keystore); - context.chain.update(&option); + if let Some(event) = context.chain.update(&option) { + context.bus.post(event); + } success = true; } context.bus.post(Event::MinerStopped { success, full }); @@ -230,8 +232,9 @@ fn find_hash(context: Arc>, mut block: Block, running: Arc block.index { + //trace!("Mining full block is not allowed until previous is not signed"); // We can't mine now, as we need to wait for block to be signed - thread::sleep(Duration::from_millis(1000)); + thread::sleep(Duration::from_millis(5000)); continue; } debug!("Mining block {}", serde_json::to_string(&block).unwrap()); diff --git a/src/p2p/network.rs b/src/p2p/network.rs index 5dee5ab..7ba001b 100644 --- a/src/p2p/network.rs +++ b/src/p2p/network.rs @@ -150,6 +150,10 @@ impl Network { if log_timer.elapsed().as_secs() > LOG_REFRESH_DELAY_SEC { info!("Active nodes count: {}, blocks count: {}", nodes, height); log_timer = Instant::now(); + let keystore = context.keystore.clone(); + if let Some(event) = context.chain.update(&keystore) { + context.bus.post(event); + } } (height, context.chain.last_hash()) }; @@ -479,7 +483,9 @@ fn process_new_block(context: Arc>, peers: &mut Peers, token: &To BlockQuality::Good => { context.chain.add_block(block); let keystore = context.keystore.clone(); - context.chain.update(&keystore); + if let Some(event) = context.chain.update(&keystore) { + context.bus.post(event); + } let my_height = context.chain.height(); context.bus.post(crate::event::Event::BlockchainChanged { index: my_height }); // If it was the last block to sync @@ -506,7 +512,9 @@ fn process_new_block(context: Arc>, peers: &mut Peers, token: &To if block.is_better_than(&last_block) { context.chain.replace_block(block.index, block).expect("Error replacing block with fork"); let keystore = context.keystore.clone(); - context.chain.update(&keystore); + if let Some(event) = context.chain.update(&keystore) { + context.bus.post(event); + } let index = context.chain.height(); context.bus.post(crate::event::Event::BlockchainChanged { index }); } diff --git a/src/web_ui.rs b/src/web_ui.rs index a74b280..6713023 100644 --- a/src/web_ui.rs +++ b/src/web_ui.rs @@ -1,8 +1,8 @@ -extern crate web_view; -extern crate tinyfiledialogs as tfd; +extern crate open; extern crate serde; extern crate serde_json; -extern crate open; +extern crate tinyfiledialogs as tfd; +extern crate web_view; use std::sync::{Arc, Mutex, MutexGuard}; use std::thread; @@ -196,6 +196,11 @@ fn action_loaded(context: &Arc>, web_view: &mut WebView<()>) { let context_copy = Arc::clone(&context); let mut c = context.lock().unwrap(); + let keystore = c.keystore.clone(); + if let Some(event) = c.chain.update(&keystore) { + c.bus.post(event); + } + c.bus.register(move |_uuid, e| { //debug!("Got event from bus {:?}", &e); let status = Arc::clone(&status); @@ -215,6 +220,10 @@ fn action_loaded(context: &Arc>, web_view: &mut WebView<()>) { Event::KeyLoaded { path, public, hash } | Event::KeySaved { path, public, hash } => { load_domains(&mut context, &handle); + let keystore = context.keystore.clone(); + if let Some(event) = context.chain.update(&keystore) { + context.bus.post(event); + } format!("keystoreChanged('{}', '{}', '{}');", &path, &public, &hash) } Event::MinerStarted | Event::KeyGeneratorStarted => {