Skip to content

Commit

Permalink
reset cache when storage possibly change (fix init of tests). (parity…
Browse files Browse the repository at this point in the history
…tech#9665)

* reset cache when storage possibly change (fix init of tests).

* remove backend_storage_mut

* fix warn

* remove remaining backend_storage_mut
  • Loading branch information
cheme authored Sep 6, 2021
1 parent b799ee3 commit 60078b3
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 15 deletions.
5 changes: 3 additions & 2 deletions primitives/state-machine/src/in_memory_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ where

/// Apply the given transaction to this backend and set the root to the given value.
pub fn apply_transaction(&mut self, root: H::Out, transaction: MemoryDB<H>) {
self.backend_storage_mut().consolidate(transaction);
self.essence.set_root(root);
let mut storage = sp_std::mem::take(self).into_storage();
storage.consolidate(transaction);
*self = TrieBackend::new(storage, root);
}

/// Compare with another in-memory backend.
Expand Down
7 changes: 4 additions & 3 deletions primitives/state-machine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1619,7 +1619,7 @@ mod tests {
let child_info2 = ChildInfo::new_default(b"sub2");
// this root will be include in proof
let child_info3 = ChildInfo::new_default(b"sub");
let mut remote_backend = trie_backend::tests::test_trie();
let remote_backend = trie_backend::tests::test_trie();
let (remote_root, transaction) = remote_backend.full_storage_root(
std::iter::empty(),
vec![
Expand All @@ -1641,8 +1641,9 @@ mod tests {
]
.into_iter(),
);
remote_backend.backend_storage_mut().consolidate(transaction);
remote_backend.essence.set_root(remote_root.clone());
let mut remote_storage = remote_backend.into_storage();
remote_storage.consolidate(transaction);
let remote_backend = TrieBackend::new(remote_storage, remote_root);
let remote_proof = prove_child_read(remote_backend, &child_info1, &[b"key1"]).unwrap();
let remote_proof = test_compact(remote_proof, &remote_root);
let local_result1 = read_child_proof_check::<BlakeTwo256, _>(
Expand Down
5 changes: 0 additions & 5 deletions primitives/state-machine/src/trie_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ where
self.essence.backend_storage()
}

/// Get backend storage reference.
pub fn backend_storage_mut(&mut self) -> &mut S {
self.essence.backend_storage_mut()
}

/// Get trie root.
pub fn root(&self) -> &H::Out {
self.essence.root()
Expand Down
5 changes: 0 additions & 5 deletions primitives/state-machine/src/trie_backend_essence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,6 @@ where
&self.storage
}

/// Get backend storage reference.
pub fn backend_storage_mut(&mut self) -> &mut S {
&mut self.storage
}

/// Get trie root.
pub fn root(&self) -> &H::Out {
&self.root
Expand Down

0 comments on commit 60078b3

Please sign in to comment.