Panic on missing counters; Client cleanup
This commit is contained in:
parent
63f2f42035
commit
0772cb6d42
@ -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.
|
||||
|
@ -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) {
|
||||
let cnt = counters.get_mut(i).expect("Missing key counter");
|
||||
*cnt -= 1;
|
||||
*cnt == 0
|
||||
}
|
||||
else { false }
|
||||
};
|
||||
if delete_counter {
|
||||
counters.remove(i);
|
||||
|
Loading…
Reference in New Issue
Block a user