Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.

Commit 6c6c97e

Browse files
committed
Merge commit '72ec9366ad45526d16f6c78b5dfb32d16ba5aa6c' into js
* commit '72ec9366ad45526d16f6c78b5dfb32d16ba5aa6c': Handle reorganizations in the state cache (#2490) terminate after 30 seconds (#2513)
2 parents 06937c9 + 72ec936 commit 6c6c97e

File tree

7 files changed

+352
-76
lines changed

7 files changed

+352
-76
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ethcore/src/client/client.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,7 @@ impl Client {
304304
// Enact Verified Block
305305
let parent = chain_has_parent.unwrap();
306306
let last_hashes = self.build_last_hashes(header.parent_hash().clone());
307-
let is_canon = header.parent_hash() == &chain.best_block_hash();
308-
let db = if is_canon { self.state_db.lock().boxed_clone_canon() } else { self.state_db.lock().boxed_clone() };
307+
let db = self.state_db.lock().boxed_clone_canon(&header.parent_hash());
309308

310309
let enact_result = enact_verified(block, engine, self.tracedb.read().tracing_enabled(), db, &parent, last_hashes, self.factories.clone());
311310
if let Err(e) = enact_result {
@@ -459,6 +458,8 @@ impl Client {
459458
enacted: route.enacted.clone(),
460459
retracted: route.retracted.len()
461460
});
461+
let is_canon = route.enacted.last().map_or(false, |h| h == hash);
462+
state.sync_cache(&route.enacted, &route.retracted, is_canon);
462463
// Final commit to the DB
463464
self.db.read().write_buffered(batch);
464465
chain.commit();
@@ -533,9 +534,11 @@ impl Client {
533534

534535
/// Get a copy of the best block's state.
535536
pub fn state(&self) -> State {
537+
let header = self.best_block_header();
538+
let header = HeaderView::new(&header);
536539
State::from_existing(
537-
self.state_db.lock().boxed_clone(),
538-
HeaderView::new(&self.best_block_header()).state_root(),
540+
self.state_db.lock().boxed_clone_canon(&header.hash()),
541+
header.state_root(),
539542
self.engine.account_start_nonce(),
540543
self.factories.clone())
541544
.expect("State root of best block header always valid.")
@@ -1128,6 +1131,7 @@ impl MiningBlockChainClient for Client {
11281131
let block_data = block.rlp_bytes();
11291132
let route = self.commit_block(block, &h, &block_data);
11301133
trace!(target: "client", "Imported sealed block #{} ({})", number, h);
1134+
self.state_db.lock().sync_cache(&route.enacted, &route.retracted, false);
11311135

11321136
let (enacted, retracted) = self.calculate_enacted_retracted(&[route]);
11331137
self.miner.chain_new_blocks(self, &[h.clone()], &[], &enacted, &retracted);

ethcore/src/state/mod.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ impl AccountEntry {
164164
/// use that.
165165
/// ****************************************************************************
166166
///
167-
/// Upon destruction all the local cache data merged into the global cache.
168-
/// The merge might be rejected if current state is non-canonical.
167+
/// Upon destruction all the local cache data propagated into the global cache.
168+
/// Propagated items might be rejected if current state is non-canonical.
169169
///
170170
/// State snapshotting.
171171
///
@@ -318,7 +318,7 @@ impl State {
318318

319319
/// Destroy the current object and return root and database.
320320
pub fn drop(mut self) -> (H256, StateDB) {
321-
self.commit_cache();
321+
self.propagate_to_global_cache();
322322
(self.root, self.db)
323323
}
324324

@@ -533,11 +533,12 @@ impl State {
533533
Ok(())
534534
}
535535

536-
fn commit_cache(&mut self) {
536+
/// Propagate local cache into shared canonical state cache.
537+
fn propagate_to_global_cache(&mut self) {
537538
let mut addresses = self.cache.borrow_mut();
538539
trace!("Committing cache {:?} entries", addresses.len());
539540
for (address, a) in addresses.drain().filter(|&(_, ref a)| a.state == AccountState::Committed || a.state == AccountState::CleanFresh) {
540-
self.db.cache_account(address, a.account);
541+
self.db.add_to_account_cache(address, a.account, a.state == AccountState::Committed);
541542
}
542543
}
543544

0 commit comments

Comments
 (0)