More fixes for signing blocks.

This commit is contained in:
Revertron
2021-04-18 16:55:10 +02:00
parent d12ebf6ede
commit 214ef69927
4 changed files with 29 additions and 8 deletions
+2 -1
View File
@@ -204,7 +204,7 @@ impl Chain {
let block = self.last_block().unwrap(); let block = self.last_block().unwrap();
if block.transaction.is_none() { if block.transaction.is_none() {
trace!("No need to sign signing block"); trace!("No need to mine signing block");
return None; return None;
} }
let keystore = keystore.clone().unwrap().clone(); let keystore = keystore.clone().unwrap().clone();
@@ -229,6 +229,7 @@ impl Chain {
} }
block.index = self.height() + 1; block.index = self.height() + 1;
block.prev_block_hash = self.last_block.clone().unwrap().hash; block.prev_block_hash = self.last_block.clone().unwrap().hash;
return Some(block);
} }
None None
} }
+5 -2
View File
@@ -191,7 +191,9 @@ impl Miner {
} }
context.chain.add_block(block); context.chain.add_block(block);
let option = Some(job.keystore); let option = Some(job.keystore);
context.chain.update(&option); if let Some(event) = context.chain.update(&option) {
context.bus.post(event);
}
success = true; success = true;
} }
context.bus.post(Event::MinerStopped { success, full }); context.bus.post(Event::MinerStopped { success, full });
@@ -230,8 +232,9 @@ fn find_hash(context: Arc<Mutex<Context>>, mut block: Block, running: Arc<Atomic
}; };
if full && next_allowed_block > block.index { if full && next_allowed_block > 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 // 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; continue;
} }
debug!("Mining block {}", serde_json::to_string(&block).unwrap()); debug!("Mining block {}", serde_json::to_string(&block).unwrap());
+10 -2
View File
@@ -150,6 +150,10 @@ impl Network {
if log_timer.elapsed().as_secs() > LOG_REFRESH_DELAY_SEC { if log_timer.elapsed().as_secs() > LOG_REFRESH_DELAY_SEC {
info!("Active nodes count: {}, blocks count: {}", nodes, height); info!("Active nodes count: {}, blocks count: {}", nodes, height);
log_timer = Instant::now(); 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()) (height, context.chain.last_hash())
}; };
@@ -479,7 +483,9 @@ fn process_new_block(context: Arc<Mutex<Context>>, peers: &mut Peers, token: &To
BlockQuality::Good => { BlockQuality::Good => {
context.chain.add_block(block); context.chain.add_block(block);
let keystore = context.keystore.clone(); 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(); let my_height = context.chain.height();
context.bus.post(crate::event::Event::BlockchainChanged { index: my_height }); context.bus.post(crate::event::Event::BlockchainChanged { index: my_height });
// If it was the last block to sync // If it was the last block to sync
@@ -506,7 +512,9 @@ fn process_new_block(context: Arc<Mutex<Context>>, peers: &mut Peers, token: &To
if block.is_better_than(&last_block) { if block.is_better_than(&last_block) {
context.chain.replace_block(block.index, block).expect("Error replacing block with fork"); context.chain.replace_block(block.index, block).expect("Error replacing block with fork");
let keystore = context.keystore.clone(); 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(); let index = context.chain.height();
context.bus.post(crate::event::Event::BlockchainChanged { index }); context.bus.post(crate::event::Event::BlockchainChanged { index });
} }
+12 -3
View File
@@ -1,8 +1,8 @@
extern crate web_view; extern crate open;
extern crate tinyfiledialogs as tfd;
extern crate serde; extern crate serde;
extern crate serde_json; extern crate serde_json;
extern crate open; extern crate tinyfiledialogs as tfd;
extern crate web_view;
use std::sync::{Arc, Mutex, MutexGuard}; use std::sync::{Arc, Mutex, MutexGuard};
use std::thread; use std::thread;
@@ -196,6 +196,11 @@ fn action_loaded(context: &Arc<Mutex<Context>>, web_view: &mut WebView<()>) {
let context_copy = Arc::clone(&context); let context_copy = Arc::clone(&context);
let mut c = context.lock().unwrap(); 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| { c.bus.register(move |_uuid, e| {
//debug!("Got event from bus {:?}", &e); //debug!("Got event from bus {:?}", &e);
let status = Arc::clone(&status); let status = Arc::clone(&status);
@@ -215,6 +220,10 @@ fn action_loaded(context: &Arc<Mutex<Context>>, web_view: &mut WebView<()>) {
Event::KeyLoaded { path, public, hash } | Event::KeyLoaded { path, public, hash } |
Event::KeySaved { path, public, hash } => { Event::KeySaved { path, public, hash } => {
load_domains(&mut context, &handle); 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) format!("keystoreChanged('{}', '{}', '{}');", &path, &public, &hash)
} }
Event::MinerStarted | Event::KeyGeneratorStarted => { Event::MinerStarted | Event::KeyGeneratorStarted => {