Rework the trie cache (#12982)

* Rework the trie cache

* Align `state-machine` tests

* Bump `schnellru` to 0.1.1

* Fix off-by-one

* Align to review comments

* Bump `ahash` to 0.8.2

* Bump `schnellru` to 0.2.0

* Bump `schnellru` to 0.2.1

* Remove unnecessary bound

* Remove unnecessary loop when calculating maximum memory usage

* Remove unnecessary `mut`s
This commit is contained in:
Koute
2023-01-26 14:38:00 +09:00
committed by GitHub
parent 451a13c642
commit 96ca4bed0e
9 changed files with 1015 additions and 549 deletions
@@ -412,19 +412,19 @@ pub mod tests {
fn $name() {
let parameters = vec![
(StateVersion::V0, None, None),
(StateVersion::V0, Some(SharedCache::new(CacheSize::Unlimited)), None),
(StateVersion::V0, Some(SharedCache::new(CacheSize::unlimited())), None),
(StateVersion::V0, None, Some(Recorder::default())),
(
StateVersion::V0,
Some(SharedCache::new(CacheSize::Unlimited)),
Some(SharedCache::new(CacheSize::unlimited())),
Some(Recorder::default()),
),
(StateVersion::V1, None, None),
(StateVersion::V1, Some(SharedCache::new(CacheSize::Unlimited)), None),
(StateVersion::V1, Some(SharedCache::new(CacheSize::unlimited())), None),
(StateVersion::V1, None, Some(Recorder::default())),
(
StateVersion::V1,
Some(SharedCache::new(CacheSize::Unlimited)),
Some(SharedCache::new(CacheSize::unlimited())),
Some(Recorder::default()),
),
];
@@ -760,7 +760,7 @@ pub mod tests {
.clone()
.for_each(|i| assert_eq!(trie.storage(&[i]).unwrap().unwrap(), vec![i; size_content]));
for cache in [Some(SharedTrieCache::new(CacheSize::Unlimited)), None] {
for cache in [Some(SharedTrieCache::new(CacheSize::unlimited())), None] {
// Run multiple times to have a different cache conditions.
for i in 0..5 {
if let Some(cache) = &cache {
@@ -793,7 +793,7 @@ pub mod tests {
proof_record_works_with_iter_inner(StateVersion::V1);
}
fn proof_record_works_with_iter_inner(state_version: StateVersion) {
for cache in [Some(SharedTrieCache::new(CacheSize::Unlimited)), None] {
for cache in [Some(SharedTrieCache::new(CacheSize::unlimited())), None] {
// Run multiple times to have a different cache conditions.
for i in 0..5 {
if let Some(cache) = &cache {
@@ -870,7 +870,7 @@ pub mod tests {
assert_eq!(in_memory.child_storage(child_info_2, &[i]).unwrap().unwrap(), vec![i])
});
for cache in [Some(SharedTrieCache::new(CacheSize::Unlimited)), None] {
for cache in [Some(SharedTrieCache::new(CacheSize::unlimited())), None] {
// Run multiple times to have a different cache conditions.
for i in 0..5 {
eprintln!("Running with cache {}, iteration {}", cache.is_some(), i);
@@ -1002,7 +1002,7 @@ pub mod tests {
nodes
};
let cache = SharedTrieCache::<BlakeTwo256>::new(CacheSize::Unlimited);
let cache = SharedTrieCache::<BlakeTwo256>::new(CacheSize::unlimited());
{
let local_cache = cache.local_cache();
let mut trie_cache = local_cache.as_trie_db_cache(child_1_root);
@@ -1093,7 +1093,7 @@ pub mod tests {
#[test]
fn new_data_is_added_to_the_cache() {
let shared_cache = SharedTrieCache::new(CacheSize::Unlimited);
let shared_cache = SharedTrieCache::new(CacheSize::unlimited());
let new_data = vec![
(&b"new_data0"[..], Some(&b"0"[..])),
(&b"new_data1"[..], Some(&b"1"[..])),
@@ -1159,7 +1159,7 @@ pub mod tests {
assert_eq!(in_memory.child_storage(child_info_1, &key).unwrap().unwrap(), child_trie_1_val);
assert_eq!(in_memory.child_storage(child_info_2, &key).unwrap().unwrap(), child_trie_2_val);
for cache in [Some(SharedTrieCache::new(CacheSize::Unlimited)), None] {
for cache in [Some(SharedTrieCache::new(CacheSize::unlimited())), None] {
// Run multiple times to have a different cache conditions.
for i in 0..5 {
eprintln!("Running with cache {}, iteration {}", cache.is_some(), i);