Configurable path for chain db. Lowered test cuckoo size.

This commit is contained in:
Ignotus Peverell 2016-11-29 18:45:39 -08:00
parent d11c85dae1
commit 08f2f38098
No known key found for this signature in database
GPG key ID: 99CD25F39F8F8211
5 changed files with 22 additions and 25 deletions

View file

@ -35,5 +35,5 @@ pub mod types;
// Re-export the base interface
pub use types::{ChainStore, State, Tip};
pub use types::{ChainStore, Tip};
pub use pipe::{NONE, process_block};

View file

@ -102,11 +102,14 @@ fn validate_header(b: &Block, ctx: &mut BlockContext) -> Result<(), Error> {
let prev = try!(ctx.store.get_block_header(&header.previous).map_err(&Error::StoreErr));
if header.timestamp <= prev.timestamp {
// prevent time warp attacks and some timestamp manipulations by forcing strict time progression
// prevent time warp attacks and some timestamp manipulations by forcing strict
// time progression
return Err(Error::InvalidBlockTime);
}
if header.timestamp > time::now() + time::Duration::seconds(12*(consensus::BLOCK_TIME_SEC as i64)) {
// refuse blocks too far in future, constant of 12 comes from bitcoin (2h worth of blocks)
if header.timestamp >
time::now() + time::Duration::seconds(12 * (consensus::BLOCK_TIME_SEC as i64)) {
// refuse blocks too far in future, constant of 12 comes from bitcoin (2h worth
// of blocks)
// TODO add warning in p2p code if local time is too different from peers
return Err(Error::InvalidBlockTime);
}
@ -120,7 +123,7 @@ fn validate_header(b: &Block, ctx: &mut BlockContext) -> Result<(), Error> {
}
if ctx.opts.intersects(EASY_POW) {
if !pow::verify20(b) {
if !pow::verify_size(b, 15) {
return Err(Error::InvalidPow);
}
} else if !pow::verify_size(b, cuckoo_sz as u32) {

View file

@ -21,7 +21,7 @@ use core::core::hash::Hash;
use core::core::{Block, BlockHeader};
use grin_store;
const STORE_PATH: &'static str = ".grin/chain";
const STORE_SUBPATH: &'static str = "chain";
const SEP: u8 = ':' as u8;
@ -37,8 +37,9 @@ pub struct ChainKVStore {
}
impl ChainKVStore {
pub fn new() -> Result<ChainKVStore, Error> {
let db = try!(grin_store::Store::open(STORE_PATH).map_err(to_store_err));
pub fn new(root_path: String) -> Result<ChainKVStore, Error> {
let db = try!(grin_store::Store::open(format!("{}/{}", root_path, STORE_SUBPATH).as_str())
.map_err(to_store_err));
Ok(ChainKVStore { db: db })
}
}

View file

@ -131,15 +131,9 @@ pub enum Error {
StorageErr(String),
}
#[derive(Debug, Clone)]
pub struct State {
pub head: Tip,
pub forks: Vec<Tip>,
}
/// Trait the chain pipeline requires an implementor for in order to process
/// blocks.
pub trait ChainStore {
pub trait ChainStore: Send {
/// Get the tip that's also the head of the chain
fn head(&self) -> Result<Tip, Error>;
@ -158,4 +152,3 @@ pub trait ChainStore {
/// Save the provided tip without setting it as head
fn save_tip(&self, t: &Tip) -> Result<(), Error>;
}

View file

@ -28,7 +28,7 @@ use grin_core::consensus;
fn mine_empty_chain() {
let curve = secp::Secp256k1::with_caps(secp::ContextFlag::Commit);
let mut rng = OsRng::new().unwrap();
let store = grin_chain::store::ChainKVStore::new().unwrap();
let store = grin_chain::store::ChainKVStore::new(".grin".to_string()).unwrap();
// save a genesis block
let gen = grin_core::genesis::genesis();
@ -47,7 +47,7 @@ fn mine_empty_chain() {
let mut b = core::Block::new(prev.header, vec![], reward_key).unwrap();
println!("=> {} {:?}", b.header.height, b.verify(&curve));
let (proof, nonce) = pow::pow20(&b, consensus::MAX_TARGET).unwrap();
let (proof, nonce) = pow::pow_size(&b, consensus::MAX_TARGET, 15).unwrap();
b.header.pow = proof;
b.header.nonce = nonce;
grin_chain::pipe::process_block(&b, &store, grin_chain::pipe::EASY_POW).unwrap();