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

Rework the trie cache #12982

Merged
57 changes: 43 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client/db/src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl<B: BlockT> BenchmarkingState<B> {
proof_recorder_root: Cell::new(root),
enable_tracking,
// Enable the cache, but do not sync anything to the shared state.
shared_trie_cache: SharedTrieCache::new(CacheSize::Maximum(0)),
shared_trie_cache: SharedTrieCache::new(CacheSize::new(0)),
};

state.add_whitelist_to_tracker();
Expand Down
2 changes: 1 addition & 1 deletion client/db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1169,7 +1169,7 @@ impl<Block: BlockT> Backend<Block> {
blocks_pruning: config.blocks_pruning,
genesis_state: RwLock::new(None),
shared_trie_cache: config.trie_cache_maximum_size.map(|maximum_size| {
SharedTrieCache::new(sp_trie::cache::CacheSize::Maximum(maximum_size))
SharedTrieCache::new(sp_trie::cache::CacheSize::new(maximum_size))
}),
};

Expand Down
20 changes: 10 additions & 10 deletions primitives/state-machine/src/trie_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
),
];
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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"[..])),
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions primitives/trie/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ codec = { package = "parity-scale-codec", version = "3.0.0", default-features =
hashbrown = { version = "0.12.3", optional = true }
hash-db = { version = "0.15.2", default-features = false }
lazy_static = { version = "1.4.0", optional = true }
lru = { version = "0.8.1", optional = true }
memory-db = { version = "0.31.0", default-features = false }
nohash-hasher = { version = "0.2.0", optional = true }
parking_lot = { version = "0.12.1", optional = true }
Expand All @@ -34,6 +33,7 @@ trie-db = { version = "0.24.0", default-features = false }
trie-root = { version = "0.17.0", default-features = false }
sp-core = { version = "7.0.0", default-features = false, path = "../core" }
sp-std = { version = "5.0.0", default-features = false, path = "../std" }
schnellru = { version = "0.1.1", optional = true }

[dev-dependencies]
array-bytes = "4.1"
Expand All @@ -50,7 +50,7 @@ std = [
"hashbrown",
"hash-db/std",
"lazy_static",
"lru",
"schnellru",
"memory-db/std",
"nohash-hasher",
"parking_lot",
Expand Down
Loading