Skip to content

Commit

Permalink
Revert storage cache optimization (paritytech#8535)
Browse files Browse the repository at this point in the history
* Revert "Fixes `storage_hash` caching issue and enables better caching for Cumulus (paritytech#8518)"

This reverts commit 85eef08.

* Fix reverting storage_hash

* Restore test
  • Loading branch information
arkpar authored and KalitaAlexey committed Jul 9, 2021
1 parent 11c7fdf commit 51aafa7
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions client/db/src/storage_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ impl<B: BlockT> Cache<B> {
for a in &m.storage {
trace!("Retracted key {:?}", HexDisplay::from(a));
self.lru_storage.remove(a);
self.lru_hashes.remove(a);
}
for a in &m.child_storage {
trace!("Retracted child key {:?}", a);
Expand Down Expand Up @@ -1185,6 +1186,47 @@ mod tests {
assert_eq!(s.storage(&key).unwrap().unwrap(), vec![2]);
}

#[test]
fn reverts_storage_hash() {
let root_parent = H256::random();
let key = H256::random()[..].to_vec();
let h1a = H256::random();
let h1b = H256::random();

let shared = new_shared_cache::<Block>(256*1024, (0,1));
let mut backend = InMemoryBackend::<BlakeTwo256>::default();
backend.insert(std::iter::once((None, vec![(key.clone(), Some(vec![1]))])));

let mut s = CachingState::new(
backend.clone(),
shared.clone(),
Some(root_parent),
);
s.cache.sync_cache(
&[],
&[],
vec![(key.clone(), Some(vec![2]))],
vec![],
Some(h1a),
Some(1),
true,
);

let mut s = CachingState::new(
backend.clone(),
shared.clone(),
Some(root_parent),
);
s.cache.sync_cache(&[], &[h1a], vec![], vec![], Some(h1b), Some(1), true);

let s = CachingState::new(
backend.clone(),
shared.clone(),
Some(h1b),
);
assert_eq!(s.storage_hash(&key).unwrap().unwrap(), BlakeTwo256::hash(&vec![1]));
}

#[test]
fn should_track_used_size_correctly() {
let root_parent = H256::random();
Expand Down

0 comments on commit 51aafa7

Please sign in to comment.