Merge github.com:paritytech/parity into block_header_rpc
This commit is contained in:
@@ -32,6 +32,7 @@ use ethcore::encoded;
|
||||
use io::IoChannel;
|
||||
|
||||
use util::{H256, Mutex, RwLock};
|
||||
use util::kvdb::{KeyValueDB, CompactionProfile};
|
||||
|
||||
use self::header_chain::{AncestryIter, HeaderChain};
|
||||
|
||||
@@ -45,6 +46,14 @@ mod service;
|
||||
pub struct Config {
|
||||
/// Verification queue 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,
|
||||
}
|
||||
|
||||
/// Trait for interacting with the header chain abstractly.
|
||||
@@ -113,18 +122,30 @@ pub struct Client {
|
||||
chain: HeaderChain,
|
||||
report: RwLock<ClientReport>,
|
||||
import_lock: Mutex<()>,
|
||||
db: Arc<KeyValueDB>,
|
||||
}
|
||||
|
||||
impl Client {
|
||||
/// Create a new `Client`.
|
||||
pub fn new(config: Config, spec: &Spec, io_channel: IoChannel<ClientIoMessage>) -> Self {
|
||||
Client {
|
||||
pub fn new(config: Config, db: Arc<KeyValueDB>, chain_col: Option<u32>, spec: &Spec, io_channel: IoChannel<ClientIoMessage>) -> Result<Self, String> {
|
||||
let gh = ::rlp::encode(&spec.genesis_header());
|
||||
|
||||
Ok(Client {
|
||||
queue: HeaderQueue::new(config.queue, spec.engine.clone(), io_channel, true),
|
||||
engine: spec.engine.clone(),
|
||||
chain: HeaderChain::new(&::rlp::encode(&spec.genesis_header())),
|
||||
chain: HeaderChain::new(db.clone(), chain_col, &gh)?,
|
||||
report: RwLock::new(ClientReport::default()),
|
||||
import_lock: Mutex::new(()),
|
||||
}
|
||||
db: db,
|
||||
})
|
||||
}
|
||||
|
||||
/// 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, io_channel: IoChannel<ClientIoMessage>) -> Self {
|
||||
let db = ::util::kvdb::in_memory(0);
|
||||
|
||||
Client::new(config, Arc::new(db), None, spec, io_channel).expect("New DB creation infallible; qed")
|
||||
}
|
||||
|
||||
/// Import a header to the queue for additional verification.
|
||||
@@ -208,15 +229,23 @@ impl Client {
|
||||
for verified_header in self.queue.drain(MAX) {
|
||||
let (num, hash) = (verified_header.number(), verified_header.hash());
|
||||
|
||||
match self.chain.insert(verified_header) {
|
||||
Ok(()) => {
|
||||
let mut tx = self.db.transaction();
|
||||
let pending = match self.chain.insert(&mut tx, verified_header) {
|
||||
Ok(pending) => {
|
||||
good.push(hash);
|
||||
self.report.write().blocks_imported += 1;
|
||||
pending
|
||||
}
|
||||
Err(e) => {
|
||||
debug!(target: "client", "Error importing header {:?}: {}", (num, hash), e);
|
||||
bad.push(hash);
|
||||
break;
|
||||
}
|
||||
};
|
||||
self.db.write_buffered(tx);
|
||||
self.chain.apply_pending(pending);
|
||||
if let Err(e) = self.db.flush() {
|
||||
panic!("Database flush failed: {}. Check disk health and space.", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user