Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Improve cache documentation/comments #4067

Merged
merged 1 commit into from Nov 9, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions core/client/db/src/storage_cache.rs
Expand Up @@ -155,13 +155,12 @@ impl<B: BlockT, H: Hasher> Cache<B, H> {

/// Synchronize the shared cache with the best block state.
/// This function updates the shared cache by removing entries
/// that are invalidated by chain reorganization. It should be
/// be called when chain reorg happens without importing a new block.
/// that are invalidated by chain reorganization. It should be called
/// externally when chain reorg happens without importing a new block.
pub fn sync(&mut self, enacted: &[B::Hash], retracted: &[B::Hash]) {
trace!("Syncing shared cache, enacted = {:?}, retracted = {:?}", enacted, retracted);

// Purge changes from re-enacted and retracted blocks.
// Filter out commiting block if any.
let mut clear = false;
for block in enacted {
clear = clear || {
Expand Down Expand Up @@ -313,6 +312,7 @@ impl<H: Hasher, B: BlockT> CacheChanges<H, B> {
let is_best = is_best();
trace!("Syncing cache, id = (#{:?}, {:?}), parent={:?}, best={}", commit_number, commit_hash, self.parent_hash, is_best);
let cache = &mut *cache;
// Filter out commiting block if any.
let enacted: Vec<_> = enacted
.iter()
.filter(|h| commit_hash.as_ref().map_or(true, |p| *h != p))
Expand Down Expand Up @@ -370,7 +370,7 @@ impl<H: Hasher, B: BlockT> CacheChanges<H, B> {
modifications.insert(k);
}

// Save modified storage. These are ordered by the block number.
// Save modified storage. These are ordered by the block number in reverse.
let block_changes = BlockChanges {
storage: modifications,
child_storage: child_modifications,
Expand Down Expand Up @@ -427,10 +427,10 @@ impl<H: Hasher, S: StateBackend<H>, B: BlockT> CachingState<H, S, B> {
}
Some(ref parent) => parent,
};
// Ignore all storage modified in later blocks
// Ignore all storage entries modified in later blocks.
// Modifications contains block ordered by the number
// We search for our parent in that list first and then for
// all its parent until we hit the canonical block,
// all its parents until we hit the canonical block,
// checking against all the intermediate modifications.
for m in modifications {
if &m.hash == parent {
Expand Down