Panic on missing counters; Client cleanup

This commit is contained in:
arkpar 2016-02-07 23:07:36 +01:00
parent 63f2f42035
commit 0772cb6d42
2 changed files with 7 additions and 11 deletions

View File

@ -155,8 +155,7 @@ impl ClientReport {
pub struct Client {
chain: Arc<RwLock<BlockChain>>,
engine: Arc<Box<Engine>>,
state_db: Arc<DB>,
state_journal: Mutex<JournalDB>,
state_db: Mutex<JournalDB>,
block_queue: RwLock<BlockQueue>,
report: RwLock<ClientReport>,
import_lock: Mutex<()>
@ -209,8 +208,7 @@ impl Client {
Ok(Arc::new(Client {
chain: chain,
engine: engine.clone(),
state_db: db.clone(),
state_journal: Mutex::new(JournalDB::new_with_arc(db)),
state_db: Mutex::new(state_db),
block_queue: RwLock::new(BlockQueue::new(engine, message_channel)),
report: RwLock::new(Default::default()),
import_lock: Mutex::new(()),
@ -265,7 +263,7 @@ impl Client {
}
}
let db = self.state_journal.lock().unwrap().clone();
let db = self.state_db.lock().unwrap().clone();
let result = match enact_verified(&block, self.engine.deref().deref(), db, &parent, &last_hashes) {
Ok(b) => b,
Err(e) => {
@ -302,7 +300,7 @@ impl Client {
/// Get a copy of the best block's state.
pub fn state(&self) -> State {
State::from_existing(JournalDB::new_with_arc(self.state_db.clone()), HeaderView::new(&self.best_block_header()).state_root(), self.engine.account_start_nonce())
State::from_existing(self.state_db.lock().unwrap().clone(), HeaderView::new(&self.best_block_header()).state_root(), self.engine.account_start_nonce())
}
/// Get info on the cache.

View File

@ -212,11 +212,9 @@ impl JournalDB {
fn decrease_counters(keys: &[H256], counters: &mut HashMap<H256, i32>) {
for i in keys.iter() {
let delete_counter = {
if let Some(mut cnt) = counters.get_mut(i) {
*cnt -= 1;
*cnt == 0
}
else { false }
let cnt = counters.get_mut(i).expect("Missing key counter");
*cnt -= 1;
*cnt == 0
};
if delete_counter {
counters.remove(i);