Merge pull request #368 from ethcore/state
Panic on missing counters; Client cleanup
This commit is contained in:
commit
1b272051b9
4
.gitmodules
vendored
4
.gitmodules
vendored
@ -1,4 +1,4 @@
|
||||
[submodule "ethcore/res/ethereum/tests"]
|
||||
path = ethcore/res/ethereum/tests
|
||||
url = git@github.com:ethereum/tests
|
||||
branch = develop
|
||||
url = https://github.com/ethereum/tests.git
|
||||
branch = develop
|
||||
|
@ -67,7 +67,6 @@ impl fmt::Display for BlockChainInfo {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Blockchain database client. Owns and manages a blockchain and a block queue.
|
||||
pub trait BlockChainClient : Sync + Send {
|
||||
/// Get raw block header data by block header hash.
|
||||
@ -155,8 +154,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 +207,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 +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) {
|
||||
Ok(b) => b,
|
||||
Err(e) => {
|
||||
@ -302,7 +299,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) {
|
||||
*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);
|
||||
|
Loading…
Reference in New Issue
Block a user