Ci mode fixes (#86)

* playing around with changing cuckoo sizes on the fly
* modifying tests to use global cuckoo parameters, and checking results
* check for pow size
* Changing global function names, and removing length from POW serialization
This commit is contained in:
Yeastplume
2017-08-09 17:40:23 +01:00
committed by Ignotus Peverell
parent d32ab967f0
commit 131ea2f799
22 changed files with 508 additions and 357 deletions
+16 -15
View File
@@ -30,6 +30,9 @@ use pipe;
use store;
use types::*;
use core::global;
use core::global::{MiningParameterMode,MINING_PARAMETER_MODE};
const MAX_ORPHANS: usize = 20;
/// Helper macro to transform a Result into an Option with None in case
@@ -54,8 +57,6 @@ pub struct Chain {
head: Arc<Mutex<Tip>>,
block_process_lock: Arc<Mutex<bool>>,
orphans: Arc<Mutex<VecDeque<(Options, Block)>>>,
test_mode: bool,
}
unsafe impl Sync for Chain {}
@@ -68,7 +69,6 @@ impl Chain {
/// on
/// the genesis block if necessary.
pub fn init(
test_mode: bool,
db_root: String,
adapter: Arc<ChainAdapter>,
) -> Result<Chain, Error> {
@@ -81,13 +81,11 @@ impl Chain {
info!("No genesis block found, creating and saving one.");
let mut gen = genesis::genesis();
let diff = gen.header.difficulty.clone();
let sz = if test_mode {
consensus::TEST_SIZESHIFT
} else {
consensus::DEFAULT_SIZESHIFT
};
let mut internal_miner = pow::cuckoo::Miner::new(consensus::EASINESS, sz as u32);
pow::pow_size(&mut internal_miner, &mut gen.header, diff, sz as u32).unwrap();
let sz = global::sizeshift();
let proof_size = global::proofsize();
let mut internal_miner = pow::cuckoo::Miner::new(consensus::EASINESS, sz as u32, proof_size); pow::pow_size(&mut internal_miner, &mut gen.header, diff, sz as u32).unwrap();
chain_store.save_block(&gen)?;
// saving a new tip based on genesis
@@ -107,7 +105,6 @@ impl Chain {
head: Arc::new(Mutex::new(head)),
block_process_lock: Arc::new(Mutex::new(true)),
orphans: Arc::new(Mutex::new(VecDeque::with_capacity(MAX_ORPHANS + 1))),
test_mode: test_mode,
})
}
@@ -158,10 +155,14 @@ impl Chain {
}
fn ctx_from_head(&self, head: Tip, opts: Options) -> pipe::BlockContext {
let mut opts_in = opts;
if self.test_mode {
opts_in = opts_in | EASY_POW;
}
let opts_in = opts;
let param_ref=MINING_PARAMETER_MODE.read().unwrap();
let opts_in = match *param_ref {
MiningParameterMode::AutomatedTesting => opts_in | EASY_POW,
MiningParameterMode::UserTesting => opts_in | EASY_POW,
MiningParameterMode::Production => opts_in,
};
pipe::BlockContext {
opts: opts_in,
store: self.store.clone(),
+7 -4
View File
@@ -28,6 +28,8 @@ use core::pow;
use core::ser;
use types::*;
use store;
use core::global;
use core::global::{MiningParameterMode,MINING_PARAMETER_MODE};
/// Contextual information required to process a new block and either reject or
/// accept it.
@@ -119,9 +121,9 @@ fn validate_header(header: &BlockHeader, ctx: &mut BlockContext) -> Result<(), E
if header.height != prev.height + 1 {
return Err(Error::InvalidBlockHeight);
}
if header.timestamp <= prev.timestamp {
if header.timestamp <= prev.timestamp && !global::is_automated_testing_mode(){
// prevent time warp attacks and some timestamp manipulations by forcing strict
// time progression
// time progression (but not in CI mode)
return Err(Error::InvalidBlockTime);
}
if header.timestamp >
@@ -147,10 +149,11 @@ fn validate_header(header: &BlockHeader, ctx: &mut BlockContext) -> Result<(), E
return Err(Error::DifficultyTooLow);
}
let param_ref=MINING_PARAMETER_MODE.read().unwrap();
let cycle_size = if ctx.opts.intersects(EASY_POW) {
consensus::TEST_SIZESHIFT
global::sizeshift()
} else {
consensus::DEFAULT_SIZESHIFT
consensus::DEFAULT_SIZESHIFT
};
debug!("Validating block with cuckoo size {}", cycle_size);
if !pow::verify_size(header, cycle_size as u32) {