From 51aafa75a6ad58a69950ae8fac9eeda55d5a0aa1 Mon Sep 17 00:00:00 2001 From: Arkadiy Paronyan Date: Tue, 6 Apr 2021 14:04:32 +0300 Subject: [PATCH] Revert storage cache optimization (#8535) * Revert "Fixes `storage_hash` caching issue and enables better caching for Cumulus (#8518)" This reverts commit 85eef08bf23453a06758acbb4b17068ca982b8a2. * Fix reverting storage_hash * Restore test --- client/db/src/storage_cache.rs | 42 ++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/client/db/src/storage_cache.rs b/client/db/src/storage_cache.rs index 2dde8d5058220..26a62816adb53 100644 --- a/client/db/src/storage_cache.rs +++ b/client/db/src/storage_cache.rs @@ -198,6 +198,7 @@ impl Cache { 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); @@ -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::(256*1024, (0,1)); + let mut backend = InMemoryBackend::::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();