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

Commit d6480e3

Browse files
committed
Updated cache on sealed block
1 parent 79bbc26 commit d6480e3

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

ethcore/src/client/client.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,7 @@ impl MiningBlockChainClient for Client {
11311131
let block_data = block.rlp_bytes();
11321132
let route = self.commit_block(block, &h, &block_data);
11331133
trace!(target: "client", "Imported sealed block #{} ({})", number, h);
1134+
self.state_db.lock().sync_cache(&route.enacted, &route.retracted, false);
11341135

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

ethcore/src/state_db.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -180,17 +180,18 @@ impl StateDB {
180180
/// Apply buffered cache changes and synchronize canonical
181181
/// state cache with the best block state.
182182
/// This function updates the cache by removing entries that are
183-
/// invalidated by chain reorganization. `update_cache` should be
183+
/// invalidated by chain reorganization. `sync_cache` should be
184184
/// called after the block has been commited and the blockchain
185185
/// route has ben calculated.
186186
pub fn sync_cache(&mut self, enacted: &[H256], retracted: &[H256], is_best: bool) {
187187
trace!("sync_cache id = (#{:?}, {:?}), parent={:?}, best={}", self.commit_number, self.commit_hash, self.parent_hash, is_best);
188188
let mut cache = self.account_cache.lock();
189189
let mut cache = &mut *cache;
190190

191-
// Clean changes from re-enacted and retracted blocks
191+
// Clean changes from re-enacted and retracted blocks.
192+
// Filter out commiting block if any.
192193
let mut clear = false;
193-
for block in enacted.iter().filter(|h| self.commit_hash.as_ref().map_or(false, |p| *h != p)) {
194+
for block in enacted.iter().filter(|h| self.commit_hash.as_ref().map_or(true, |p| *h != p)) {
194195
clear = clear || {
195196
if let Some(ref mut m) = cache.modifications.iter_mut().find(|ref m| &m.hash == block) {
196197
trace!("Reverting enacted block {:?}", block);

0 commit comments

Comments
 (0)