Extract the hard dependency on rocksdb from the light client (#8034)

* Extract the hard dependency on rocksdb from the light client

* Remove TODO
This commit is contained in:
Pierre Krieger
2018-03-01 19:53:15 +01:00
committed by Rando
parent ca0d1f5eb7
commit d4205da484
11 changed files with 59 additions and 78 deletions

View File

@@ -36,7 +36,6 @@ use ethereum_types::{H256, U256};
use futures::{IntoFuture, Future};
use kvdb::{self, KeyValueDB};
use kvdb_rocksdb::CompactionProfile;
use self::fetch::ChainDataFetcher;
use self::header_chain::{AncestryIter, HeaderChain};
@@ -57,12 +56,6 @@ pub struct Config {
pub queue: queue::Config,
/// Chain column in database.
pub chain_column: Option<u32>,
/// Database cache size. `None` => rocksdb default.
pub db_cache_size: Option<usize>,
/// State db compaction profile
pub db_compaction: CompactionProfile,
/// Should db have WAL enabled?
pub db_wal: bool,
/// Should it do full verification of blocks?
pub verify_full: bool,
/// Should it check the seal of blocks?
@@ -74,9 +67,6 @@ impl Default for Config {
Config {
queue: Default::default(),
chain_column: None,
db_cache_size: None,
db_compaction: CompactionProfile::default(),
db_wal: true,
verify_full: true,
check_seal: true,
}
@@ -205,28 +195,6 @@ impl<T: ChainDataFetcher> Client<T> {
self.listeners.write().push(listener);
}
/// Create a new `Client` backed purely in-memory.
/// This will ignore all database options in the configuration.
pub fn in_memory(
config: Config,
spec: &Spec,
fetcher: T,
io_channel: IoChannel<ClientIoMessage>,
cache: Arc<Mutex<Cache>>
) -> Self {
let db = ::kvdb_memorydb::create(0);
Client::new(
config,
Arc::new(db),
None,
spec,
fetcher,
io_channel,
cache
).expect("New DB creation infallible; qed")
}
/// Import a header to the queue for additional verification.
pub fn import_header(&self, header: Header) -> Result<H256, BlockImportError> {
self.queue.import(header).map_err(Into::into)

View File

@@ -18,15 +18,13 @@
//! Just handles block import messages and passes them to the client.
use std::fmt;
use std::path::Path;
use std::sync::Arc;
use ethcore::db;
use ethcore::service::ClientIoMessage;
use ethcore::spec::Spec;
use io::{IoContext, IoError, IoHandler, IoService};
use kvdb;
use kvdb_rocksdb::{Database, DatabaseConfig};
use kvdb::{self, KeyValueDB};
use cache::Cache;
use parking_lot::Mutex;
@@ -59,19 +57,7 @@ pub struct Service<T> {
impl<T: ChainDataFetcher> Service<T> {
/// Start the service: initialize I/O workers and client itself.
pub fn start(config: ClientConfig, spec: &Spec, fetcher: T, path: &Path, cache: Arc<Mutex<Cache>>) -> Result<Self, Error> {
// initialize database.
let mut db_config = DatabaseConfig::with_columns(db::NUM_COLUMNS);
db_config.memory_budget = config.db_cache_size;
db_config.compaction = config.db_compaction;
db_config.wal = config.db_wal;
let db = Arc::new(Database::open(
&db_config,
&path.to_str().expect("DB path could not be converted to string.")
).map_err(Error::Database)?);
pub fn start(config: ClientConfig, spec: &Spec, fetcher: T, db: Arc<KeyValueDB>, cache: Arc<Mutex<Cache>>) -> Result<Self, Error> {
let io_service = IoService::<ClientIoMessage>::start().map_err(Error::Io)?;
let client = Arc::new(Client::new(config,
@@ -123,14 +109,15 @@ mod tests {
use client::fetch;
use time::Duration;
use parking_lot::Mutex;
use tempdir::TempDir;
use kvdb_memorydb;
use ethcore::db::NUM_COLUMNS;
#[test]
fn it_works() {
let tempdir = TempDir::new("").unwrap();
let db = Arc::new(kvdb_memorydb::create(NUM_COLUMNS.unwrap_or(0)));
let spec = Spec::new_test();
let cache = Arc::new(Mutex::new(Cache::new(Default::default(), Duration::hours(6))));
Service::start(Default::default(), &spec, fetch::unavailable(), tempdir.path(), cache).unwrap();
Service::start(Default::default(), &spec, fetch::unavailable(), db, cache).unwrap();
}
}