Merge branch 'master' of github.com:ethcore/parity into sync

This commit is contained in:
arkpar
2016-02-26 13:55:42 +01:00
13 changed files with 308 additions and 111 deletions

View File

@@ -10,7 +10,6 @@ authors = ["Ethcore <admin@ethcore.io>"]
log = "0.3"
env_logger = "0.3"
rustc-serialize = "0.3"
rocksdb = "0.3"
heapsize = "0.3"
rust-crypto = "0.2.34"
time = "0.1"

View File

@@ -17,7 +17,6 @@
//! Blockchain database.
use util::*;
use rocksdb::{DB, WriteBatch, Writable};
use header::*;
use extras::*;
use transaction::*;
@@ -118,7 +117,7 @@ struct ExtrasUpdate {
/// Block hash.
hash: H256,
/// DB update batch.
batch: WriteBatch,
batch: DBTransaction,
/// Inserted block familial details.
details: BlockDetails,
/// New best block (if it has changed).
@@ -248,8 +247,8 @@ pub struct BlockChain {
blocks_blooms: RwLock<HashMap<H256, BlocksBlooms>>,
block_receipts: RwLock<HashMap<H256, BlockReceipts>>,
extras_db: DB,
blocks_db: DB,
extras_db: Database,
blocks_db: Database,
cache_man: RwLock<CacheManager>,
@@ -331,12 +330,12 @@ impl BlockChain {
// open extras db
let mut extras_path = path.to_path_buf();
extras_path.push("extras");
let extras_db = DB::open_default(extras_path.to_str().unwrap()).unwrap();
let extras_db = Database::open_default(extras_path.to_str().unwrap()).unwrap();
// open blocks db
let mut blocks_path = path.to_path_buf();
blocks_path.push("blocks");
let blocks_db = DB::open_default(blocks_path.to_str().unwrap()).unwrap();
let blocks_db = Database::open_default(blocks_path.to_str().unwrap()).unwrap();
let mut cache_man = CacheManager{cache_usage: VecDeque::new(), in_use: HashSet::new()};
(0..COLLECTION_QUEUE_SIZE).foreach(|_| cache_man.cache_usage.push_back(HashSet::new()));
@@ -377,7 +376,7 @@ impl BlockChain {
bc.blocks_db.put(&hash, genesis).unwrap();
let batch = WriteBatch::new();
let batch = DBTransaction::new();
batch.put_extras(&hash, &details);
batch.put_extras(&header.number(), &hash);
batch.put(b"best", &hash).unwrap();
@@ -571,7 +570,7 @@ impl BlockChain {
};
// prepare the batch
let batch = WriteBatch::new();
let batch = DBTransaction::new();
// insert new block details
batch.put_extras(&hash, &details);

View File

@@ -18,7 +18,6 @@
use util::*;
use util::panics::*;
use rocksdb::{Options, DB, DBCompactionStyle};
use blockchain::{BlockChain, BlockProvider};
use views::BlockView;
use error::*;
@@ -197,7 +196,7 @@ pub struct Client {
}
const HISTORY: u64 = 1000;
const CLIENT_DB_VER_STR: &'static str = "3";
const CLIENT_DB_VER_STR: &'static str = "4.0";
impl Client {
/// Create a new client with given spec and DB path.
@@ -209,34 +208,11 @@ impl Client {
let path = dir.as_path();
let gb = spec.genesis_block();
let chain = Arc::new(RwLock::new(BlockChain::new(config.blockchain, &gb, path)));
let mut opts = Options::new();
opts.set_max_open_files(256);
opts.create_if_missing(true);
opts.set_use_fsync(false);
opts.set_compaction_style(DBCompactionStyle::DBUniversalCompaction);
/*
opts.set_bytes_per_sync(8388608);
opts.set_disable_data_sync(false);
opts.set_block_cache_size_mb(1024);
opts.set_table_cache_num_shard_bits(6);
opts.set_max_write_buffer_number(32);
opts.set_write_buffer_size(536870912);
opts.set_target_file_size_base(1073741824);
opts.set_min_write_buffer_number_to_merge(4);
opts.set_level_zero_stop_writes_trigger(2000);
opts.set_level_zero_slowdown_writes_trigger(0);
opts.set_compaction_style(DBUniversalCompaction);
opts.set_max_background_compactions(4);
opts.set_max_background_flushes(4);
opts.set_filter_deletes(false);
opts.set_disable_auto_compactions(false);*/
let mut state_path = path.to_path_buf();
state_path.push("state");
let db = Arc::new(DB::open(&opts, state_path.to_str().unwrap()).unwrap());
let engine = Arc::new(try!(spec.to_engine()));
let mut state_db = JournalDB::new_with_arc(db.clone());
let mut state_db = JournalDB::new(state_path.to_str().unwrap());
if state_db.is_empty() && engine.spec().ensure_db_good(&mut state_db) {
state_db.commit(0, &engine.spec().genesis_header().hash(), None).expect("Error commiting genesis state to state DB");
}

View File

@@ -16,7 +16,6 @@
//! Blockchain DB extras.
use rocksdb::{DB, Writable};
use util::*;
use header::BlockNumber;
use receipt::Receipt;
@@ -59,7 +58,7 @@ pub trait ExtrasReadable {
K: ExtrasSliceConvertable;
}
impl<W> ExtrasWritable for W where W: Writable {
impl ExtrasWritable for DBTransaction {
fn put_extras<K, T>(&self, hash: &K, value: &T) where
T: ExtrasIndexable + Encodable,
K: ExtrasSliceConvertable {
@@ -68,7 +67,7 @@ impl<W> ExtrasWritable for W where W: Writable {
}
}
impl ExtrasReadable for DB {
impl ExtrasReadable for Database {
fn get_extras<K, T>(&self, hash: &K) -> Option<T> where
T: ExtrasIndexable + Decodable,
K: ExtrasSliceConvertable {

View File

@@ -84,7 +84,6 @@
#[macro_use] extern crate ethcore_util as util;
#[macro_use] extern crate lazy_static;
extern crate rustc_serialize;
extern crate rocksdb;
#[macro_use] extern crate heapsize;
extern crate crypto;
extern crate time;

View File

@@ -19,7 +19,6 @@ use common::*;
use spec::*;
use blockchain::{BlockChain, BlockChainConfig};
use state::*;
use rocksdb::*;
use evm::{Schedule, Factory};
use engine::*;
use ethereum;
@@ -226,8 +225,7 @@ pub fn generate_dummy_empty_blockchain() -> GuardedTempResult<BlockChain> {
pub fn get_temp_journal_db() -> GuardedTempResult<JournalDB> {
let temp = RandomTempPath::new();
let db = DB::open_default(temp.as_str()).unwrap();
let journal_db = JournalDB::new(db);
let journal_db = JournalDB::new(temp.as_str());
GuardedTempResult {
_temp: temp,
result: Some(journal_db)
@@ -244,8 +242,7 @@ pub fn get_temp_state() -> GuardedTempResult<State> {
}
pub fn get_temp_journal_db_in(path: &Path) -> JournalDB {
let db = DB::open_default(path.to_str().unwrap()).unwrap();
JournalDB::new(db)
JournalDB::new(path.to_str().unwrap())
}
pub fn get_temp_state_in(path: &Path) -> State {