Skip to content

Commit

Permalink
More fixes for signing blocks.
Browse files Browse the repository at this point in the history
  • Loading branch information
Revertron committed Apr 18, 2021
1 parent d12ebf6 commit 214ef69
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/blockchain/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
}
Expand Down
7 changes: 5 additions & 2 deletions src/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down Expand Up @@ -230,8 +232,9 @@ fn find_hash(context: Arc<Mutex<Context>>, mut block: Block, running: Arc<Atomic
};

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
thread::sleep(Duration::from_millis(1000));
thread::sleep(Duration::from_millis(5000));
continue;
}
debug!("Mining block {}", serde_json::to_string(&block).unwrap());
Expand Down
12 changes: 10 additions & 2 deletions src/p2p/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
};
Expand Down Expand Up @@ -479,7 +483,9 @@ fn process_new_block(context: Arc<Mutex<Context>>, 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
Expand All @@ -506,7 +512,9 @@ fn process_new_block(context: Arc<Mutex<Context>>, 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 });
}
Expand Down
15 changes: 12 additions & 3 deletions src/web_ui.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -196,6 +196,11 @@ fn action_loaded(context: &Arc<Mutex<Context>>, 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);
Expand All @@ -215,6 +220,10 @@ fn action_loaded(context: &Arc<Mutex<Context>>, 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 => {
Expand Down

0 comments on commit 214ef69

Please sign in to comment.