Skip to content

Commit

Permalink
Switch trie cache random seed (#1935)
Browse files Browse the repository at this point in the history
Use a more secure seed for hashsets of cache.
  • Loading branch information
cheme authored and tdimitrov committed Oct 23, 2023
1 parent e928647 commit 5980602
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions substrate/primitives/trie/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ lazy_static = { version = "1.4.0", optional = true }
memory-db = { version = "0.32.0", default-features = false }
nohash-hasher = { version = "0.2.0", optional = true }
parking_lot = { version = "0.12.1", optional = true }
rand = { version = "0.8", optional = true }
scale-info = { version = "2.5.0", default-features = false, features = ["derive"] }
thiserror = { version = "1.0.48", optional = true }
tracing = { version = "0.1.29", optional = true }
Expand Down Expand Up @@ -53,6 +54,7 @@ std = [
"memory-db/std",
"nohash-hasher",
"parking_lot",
"rand",
"scale-info/std",
"schnellru",
"sp-core/std",
Expand Down
6 changes: 5 additions & 1 deletion substrate/primitives/trie/src/cache/shared_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ use std::{
use trie_db::{node::NodeOwned, CachedValue};

lazy_static::lazy_static! {
static ref RANDOM_STATE: ahash::RandomState = ahash::RandomState::default();
static ref RANDOM_STATE: ahash::RandomState = {
use rand::Rng;
let mut rng = rand::thread_rng();
ahash::RandomState::generate_with(rng.gen(), rng.gen(), rng.gen(), rng.gen())
};
}

pub struct SharedNodeCacheLimiter {
Expand Down

0 comments on commit 5980602

Please sign in to comment.