Implemented right way to constrain zone difficulty.

This commit is contained in:
Revertron
2021-03-17 14:55:05 +01:00
parent d8ac1e3c32
commit 1d9833db0f
10 changed files with 95 additions and 36 deletions
+2 -4
View File
@@ -10,7 +10,7 @@ use log::{debug, error, info, trace, warn};
use num_cpus;
use crate::{Block, Bytes, Context, setup_miner_thread};
use crate::blockchain::{BLOCK_DIFFICULTY, CHAIN_VERSION, LOCKER_DIFFICULTY, KEYSTORE_DIFFICULTY};
use crate::blockchain::{CHAIN_VERSION, LOCKER_DIFFICULTY, KEYSTORE_DIFFICULTY};
use crate::blockchain::enums::BlockQuality;
use crate::blockchain::hash_utils::*;
use crate::keys::check_public_key_strength;
@@ -84,7 +84,7 @@ impl Miner {
}
Event::ActionMineLocker { index, hash } => {
if !mining.load(Ordering::SeqCst) {
let mut block = Block::new(None, Bytes::default(), hash);
let mut block = Block::new(None, Bytes::default(), hash, LOCKER_DIFFICULTY);
block.index = index;
blocks.lock().unwrap().push(block);
cond_var.notify_all();
@@ -109,7 +109,6 @@ impl Miner {
// If this block needs to be a locker
if block.index > 0 && !block.prev_block_hash.is_empty() {
info!("Mining locker block");
block.difficulty = LOCKER_DIFFICULTY;
block.pub_key = context.lock().unwrap().keystore.get_public();
if !check_public_key_strength(&block.pub_key, KEYSTORE_DIFFICULTY) {
warn!("Can not mine block with weak public key!");
@@ -131,7 +130,6 @@ impl Miner {
}
}
} else {
block.difficulty = BLOCK_DIFFICULTY;
block.index = context.lock().unwrap().chain.height() + 1;
block.prev_block_hash = match context.lock().unwrap().chain.last_block() {
None => { Bytes::default() }