Fixed wait for signing mode in miner.
This commit is contained in:
+14
-1
@@ -13,7 +13,7 @@ use crate::blockchain::enums::BlockQuality::*;
|
|||||||
use crate::blockchain::hash_utils::*;
|
use crate::blockchain::hash_utils::*;
|
||||||
use crate::settings::Settings;
|
use crate::settings::Settings;
|
||||||
use crate::keys::check_public_key_strength;
|
use crate::keys::check_public_key_strength;
|
||||||
use std::cmp::min;
|
use std::cmp::{min, max};
|
||||||
|
|
||||||
const DB_NAME: &str = "blockchain.db";
|
const DB_NAME: &str = "blockchain.db";
|
||||||
const SQL_CREATE_TABLES: &str = "CREATE TABLE blocks (
|
const SQL_CREATE_TABLES: &str = "CREATE TABLE blocks (
|
||||||
@@ -329,6 +329,19 @@ impl Chain {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn next_minable_block(&self) -> u64 {
|
||||||
|
match self.last_full_block {
|
||||||
|
None => { self.height() + 1 }
|
||||||
|
Some(ref block) => {
|
||||||
|
if block.index < LOCKER_BLOCK_START {
|
||||||
|
self.height() + 1
|
||||||
|
} else {
|
||||||
|
max(block.index, self.height()) + LOCKER_BLOCK_SIGNS
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn max_height(&self) -> u64 {
|
pub fn max_height(&self) -> u64 {
|
||||||
self.max_height
|
self.max_height
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-6
@@ -209,15 +209,11 @@ fn find_hash(context: Arc<Mutex<Context>>, digest: &mut dyn Digest, mut block: B
|
|||||||
loop {
|
loop {
|
||||||
block.random = rand::random();
|
block.random = rand::random();
|
||||||
block.index = context.lock().unwrap().chain.height() + 1;
|
block.index = context.lock().unwrap().chain.height() + 1;
|
||||||
if let Some(last_block) = context.lock().unwrap().chain.last_block() {
|
if context.lock().unwrap().chain.next_minable_block() > block.index {
|
||||||
block.prev_block_hash = last_block.hash;
|
// We can't mine now, as we need to wait for block to be signed
|
||||||
if block.transaction.is_some() && last_block.transaction.is_some() {
|
|
||||||
// We can't mine our domain block over a block with domain
|
|
||||||
// TODO make a method in Chain to get next available to mine block index
|
|
||||||
thread::sleep(Duration::from_millis(1000));
|
thread::sleep(Duration::from_millis(1000));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
debug!("Mining block {}", serde_json::to_string(&block).unwrap());
|
debug!("Mining block {}", serde_json::to_string(&block).unwrap());
|
||||||
for nonce in 0..std::u64::MAX {
|
for nonce in 0..std::u64::MAX {
|
||||||
if !running.load(Ordering::Relaxed) {
|
if !running.load(Ordering::Relaxed) {
|
||||||
|
|||||||
Reference in New Issue
Block a user