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
5 changed files with 22 additions and 25 deletions
+1 -1
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};
+9 -6
View File
@@ -102,14 +102,17 @@ 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)
// TODO add warning in p2p code if local time is too different from peers
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);
}
}
let (diff_target, cuckoo_sz) = consensus::next_target(header.timestamp.to_timespec().sec,
prev.timestamp.to_timespec().sec,
@@ -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) {
+7 -6
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 })
}
}
@@ -48,10 +49,10 @@ impl ChainStore for ChainKVStore {
option_to_not_found(self.db.get_ser(&vec![HEAD_PREFIX]))
}
fn head_header(&self) -> Result<BlockHeader, Error> {
fn head_header(&self) -> Result<BlockHeader, Error> {
let head: Tip = try!(option_to_not_found(self.db.get_ser(&vec![HEAD_PREFIX])));
self.get_block_header(&head.last_block_h)
}
self.get_block_header(&head.last_block_h)
}
fn save_block(&self, b: &Block) -> Result<(), Error> {
try!(self.db
+3 -10
View File
@@ -131,20 +131,14 @@ 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>;
/// Block header for the chain head
fn head_header(&self) -> Result<BlockHeader, Error>;
/// Block header for the chain head
fn head_header(&self) -> Result<BlockHeader, Error>;
/// Gets a block header by hash
fn get_block_header(&self, h: &Hash) -> Result<BlockHeader, 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>;
}