Merge pull request #368 from ethcore/state

Panic on missing counters; Client cleanup
This commit is contained in:
Nikolay Volf 2016-02-08 03:04:21 +03:00
commit 1b272051b9
3 changed files with 9 additions and 14 deletions

4
.gitmodules vendored
View File

@ -1,4 +1,4 @@
[submodule "ethcore/res/ethereum/tests"] [submodule "ethcore/res/ethereum/tests"]
path = ethcore/res/ethereum/tests path = ethcore/res/ethereum/tests
url = git@github.com:ethereum/tests url = https://github.com/ethereum/tests.git
branch = develop branch = develop

View File

@ -67,7 +67,6 @@ impl fmt::Display for BlockChainInfo {
} }
} }
/// Blockchain database client. Owns and manages a blockchain and a block queue. /// Blockchain database client. Owns and manages a blockchain and a block queue.
pub trait BlockChainClient : Sync + Send { pub trait BlockChainClient : Sync + Send {
/// Get raw block header data by block header hash. /// Get raw block header data by block header hash.
@ -155,8 +154,7 @@ impl ClientReport {
pub struct Client { pub struct Client {
chain: Arc<RwLock<BlockChain>>, chain: Arc<RwLock<BlockChain>>,
engine: Arc<Box<Engine>>, engine: Arc<Box<Engine>>,
state_db: Arc<DB>, state_db: Mutex<JournalDB>,
state_journal: Mutex<JournalDB>,
block_queue: RwLock<BlockQueue>, block_queue: RwLock<BlockQueue>,
report: RwLock<ClientReport>, report: RwLock<ClientReport>,
import_lock: Mutex<()> import_lock: Mutex<()>
@ -209,8 +207,7 @@ impl Client {
Ok(Arc::new(Client { Ok(Arc::new(Client {
chain: chain, chain: chain,
engine: engine.clone(), engine: engine.clone(),
state_db: db.clone(), state_db: Mutex::new(state_db),
state_journal: Mutex::new(JournalDB::new_with_arc(db)),
block_queue: RwLock::new(BlockQueue::new(engine, message_channel)), block_queue: RwLock::new(BlockQueue::new(engine, message_channel)),
report: RwLock::new(Default::default()), report: RwLock::new(Default::default()),
import_lock: Mutex::new(()), import_lock: Mutex::new(()),
@ -265,7 +262,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) { let result = match enact_verified(&block, self.engine.deref().deref(), db, &parent, &last_hashes) {
Ok(b) => b, Ok(b) => b,
Err(e) => { Err(e) => {
@ -302,7 +299,7 @@ impl Client {
/// Get a copy of the best block's state. /// Get a copy of the best block's state.
pub fn state(&self) -> 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. /// Get info on the cache.

View File

@ -212,11 +212,9 @@ impl JournalDB {
fn decrease_counters(keys: &[H256], counters: &mut HashMap<H256, i32>) { fn decrease_counters(keys: &[H256], counters: &mut HashMap<H256, i32>) {
for i in keys.iter() { for i in keys.iter() {
let delete_counter = { 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 -= 1;
*cnt == 0 *cnt == 0
}
else { false }
}; };
if delete_counter { if delete_counter {
counters.remove(i); counters.remove(i);