diff --git a/Cargo.lock b/Cargo.lock index 1bab72dc3b01..c8b054e2fe47 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -355,7 +355,7 @@ dependencies = [ "futures-lite", "parking", "polling", - "rustix 1.1.1", + "rustix 1.1.2", "slab", "windows-sys 0.60.2", ] @@ -1491,15 +1491,6 @@ dependencies = [ "unicode-segmentation", ] -[[package]] -name = "convert_case" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baaaa0ecca5b51987b9423ccdc971514dd8b0bb7b4060b983d3664dad3f1f89f" -dependencies = [ - "unicode-segmentation", -] - [[package]] name = "core-foundation" version = "0.9.4" @@ -2111,7 +2102,7 @@ version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bda628edc44c4bb645fbe0f758797143e4e07926f7ebf4e9bdfbd3d2ce621df3" dependencies = [ - "convert_case 0.7.1", + "convert_case", "proc-macro2", "quote", "syn 2.0.106", @@ -3148,7 +3139,6 @@ dependencies = [ "clap_complete", "colored 3.0.0", "console-subscriber", - "convert_case 0.8.0", "criterion", "crypto_secretbox", "cs_serde_bytes", @@ -3968,7 +3958,7 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc257fdb4038301ce4b9cd1b3b51704509692bb3ff716a410cbd07925d9dae55" dependencies = [ - "rustix 1.1.1", + "rustix 1.1.2", "windows-targets 0.52.6", ] @@ -3995,7 +3985,7 @@ dependencies = [ "js-sys", "libc", "r-efi", - "wasi 0.14.4+wasi-0.2.4", + "wasi 0.14.5+wasi-0.2.4", "wasm-bindgen", ] @@ -5777,12 +5767,6 @@ version = "0.4.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d26c52dbd32dccf2d10cac7725f8eae5296885fb5703b261f7d0a0739ec807ab" -[[package]] -name = "linux-raw-sys" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd945864f07fe9f5371a27ad7b52a172b4b499999f1d97574c9fa68373937e12" - [[package]] name = "linux-raw-sys" version = "0.11.0" @@ -5953,7 +5937,7 @@ version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ad38eb12aea514a0466ea40a80fd8cc83637065948eb4a426e4aa46261175227" dependencies = [ - "rustix 1.1.1", + "rustix 1.1.2", ] [[package]] @@ -6050,11 +6034,11 @@ dependencies = [ [[package]] name = "miow" -version = "0.6.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "359f76430b20a79f9e20e115b3428614e654f04fab314482fc0fda0ebd3c6044" +checksum = "536bfad37a309d62069485248eeaba1e8d9853aaf951caaeaed0585a95346f08" dependencies = [ - "windows-sys 0.48.0", + "windows-sys 0.61.0", ] [[package]] @@ -6917,7 +6901,7 @@ dependencies = [ "concurrent-queue", "hermit-abi", "pin-project-lite", - "rustix 1.1.1", + "rustix 1.1.2", "windows-sys 0.60.2", ] @@ -7895,15 +7879,14 @@ dependencies = [ [[package]] name = "rustix" -version = "1.1.1" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9621e389a110cae094269936383d69b869492f03e5c1ed2d575a53c029d4441d" +checksum = "cd15f8a2c5551a84d56efdc1cd049089e409ac19a3072d5037a17fd70719ff3e" dependencies = [ "bitflags 2.9.4", "errno", "libc", "linux-raw-sys 0.11.0", - "linux-raw-sys 0.9.4", "windows-sys 0.61.0", ] @@ -8971,21 +8954,21 @@ dependencies = [ [[package]] name = "target-lexicon" -version = "0.13.2" +version = "0.13.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e502f78cdbb8ba4718f566c418c52bc729126ffd16baee5baa718cf25dd5a69a" +checksum = "df7f62577c25e07834649fc3b39fafdc597c0a3527dc1c60129201ccfcbaa50c" [[package]] name = "tempfile" -version = "3.21.0" +version = "3.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15b61f8f20e3a6f7e0649d825294eaf317edce30f82cf6026e7e4cb9222a7d1e" +checksum = "84fa4d11fadde498443cca10fd3ac23c951f0dc59e080e9f4b93d4df4e4eea53" dependencies = [ "fastrand", "getrandom 0.3.3", "once_cell", - "rustix 1.1.1", - "windows-sys 0.60.2", + "rustix 1.1.2", + "windows-sys 0.61.0", ] [[package]] @@ -9698,9 +9681,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.18" +version = "1.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" +checksum = "f63a545481291138910575129486daeaf8ac54aee4387fe7906919f7830c7d9d" [[package]] name = "unicode-properties" @@ -9866,9 +9849,18 @@ checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" [[package]] name = "wasi" -version = "0.14.4+wasi-0.2.4" +version = "0.14.5+wasi-0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4494f6290a82f5fe584817a676a34b9d6763e8d9d18204009fb31dceca98fd4" +dependencies = [ + "wasip2", +] + +[[package]] +name = "wasip2" +version = "1.0.0+wasi-0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88a5f4a424faf49c3c2c344f166f0662341d470ea185e939657aaff130f0ec4a" +checksum = "03fa2761397e5bd52002cd7e73110c71af2109aca4e521a9f40473fe685b0a24" dependencies = [ "wit-bindgen", ] @@ -10808,7 +10800,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af3a19837351dc82ba89f8a125e22a3c475f05aba604acc023d62b2739ae2909" dependencies = [ "libc", - "rustix 1.1.1", + "rustix 1.1.2", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 575ea3e2c1de..a36b792aff4a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -54,7 +54,6 @@ cid = { workspace = true } clap = { version = "4", features = ["derive"] } clap_complete = "4" colored = "3" -convert_case = "0.8" crypto_secretbox = "0.1" data-encoding = "2" data-encoding-macro = "0.1" diff --git a/src/state_manager/cache.rs b/src/state_manager/cache.rs index 83dd2f89ba27..108ce526b0ea 100644 --- a/src/state_manager/cache.rs +++ b/src/state_manager/cache.rs @@ -12,42 +12,24 @@ use std::pin::Pin; use std::sync::Arc; use tokio::sync::Mutex as TokioMutex; -const DEFAULT_RECEIPT_AND_EVENT_CACHE_SIZE: NonZeroUsize = nonzero!(4096usize); - struct TipsetStateCacheInner { values: SizeTrackingLruCache, pending: Vec<(TipsetKey, Arc>)>, } -impl Default for TipsetStateCacheInner { - fn default() -> Self { - Self { - values: SizeTrackingLruCache::new_with_default_metrics_registry( - Self::cache_name().into(), - DEFAULT_TIPSET_CACHE_SIZE, - ), - pending: Vec::with_capacity(8), - } - } -} - impl TipsetStateCacheInner { - pub fn with_size(cache_size: NonZeroUsize) -> Self { + pub fn with_size(cache_identifier: &str, cache_size: NonZeroUsize) -> Self { Self { values: SizeTrackingLruCache::new_with_default_metrics_registry( - Self::cache_name().into(), + Self::cache_name(cache_identifier).into(), cache_size, ), pending: Vec::with_capacity(8), } } - fn cache_name() -> String { - use convert_case::{Case, Casing as _}; - format!( - "tipset_state_{}", - crate::utils::misc::short_type_name::().to_case(Case::Snake) - ) + fn cache_name(cache_identifier: &str) -> String { + format!("tipset_state_{cache_identifier}") } } @@ -56,27 +38,22 @@ pub(crate) struct TipsetStateCache { cache: Arc>>, } -impl Default for TipsetStateCache { - fn default() -> Self { - TipsetStateCache::with_size(DEFAULT_RECEIPT_AND_EVENT_CACHE_SIZE) - } -} - enum CacheLookupStatus { Exist(V), Empty(Arc>), } impl TipsetStateCache { - pub fn new() -> Self { - Self { - cache: Arc::new(SyncMutex::new(TipsetStateCacheInner::default())), - } + pub fn new(cache_identifier: &str) -> Self { + Self::with_size(cache_identifier, DEFAULT_TIPSET_CACHE_SIZE) } - pub fn with_size(cache_size: NonZeroUsize) -> Self { + pub fn with_size(cache_identifier: &str, cache_size: NonZeroUsize) -> Self { Self { - cache: Arc::new(SyncMutex::new(TipsetStateCacheInner::with_size(cache_size))), + cache: Arc::new(SyncMutex::new(TipsetStateCacheInner::with_size( + cache_identifier, + cache_size, + ))), } } @@ -195,9 +172,17 @@ pub struct EnabledTipsetDataCache { impl EnabledTipsetDataCache { pub fn new() -> Self { + const DEFAULT_RECEIPT_AND_EVENT_CACHE_SIZE: NonZeroUsize = nonzero!(4096usize); + Self { - events_cache: TipsetStateCache::default(), - receipt_cache: TipsetStateCache::default(), + events_cache: TipsetStateCache::with_size( + "events", + DEFAULT_RECEIPT_AND_EVENT_CACHE_SIZE, + ), + receipt_cache: TipsetStateCache::with_size( + "receipts", + DEFAULT_RECEIPT_AND_EVENT_CACHE_SIZE, + ), } } } @@ -337,7 +322,7 @@ mod tests { #[tokio::test] async fn test_tipset_cache_basic_functionality() { - let cache: TipsetStateCache = TipsetStateCache::new(); + let cache: TipsetStateCache = TipsetStateCache::new("test"); let key = create_test_tipset_key(1); // Test cache miss and computation @@ -357,7 +342,7 @@ mod tests { #[tokio::test] async fn test_concurrent_same_key_computation() { - let cache: Arc> = Arc::new(TipsetStateCache::new()); + let cache: Arc> = Arc::new(TipsetStateCache::new("test")); let key = create_test_tipset_key(1); let computation_count = Arc::new(AtomicU8::new(0)); @@ -404,7 +389,7 @@ mod tests { #[tokio::test] async fn test_concurrent_different_keys() { - let cache: Arc> = Arc::new(TipsetStateCache::new()); + let cache: Arc> = Arc::new(TipsetStateCache::new("test")); let computation_count = Arc::new(AtomicU8::new(0)); // Start tasks that try to compute the different keys diff --git a/src/state_manager/mod.rs b/src/state_manager/mod.rs index 5ca111b48777..24de41efc66f 100644 --- a/src/state_manager/mod.rs +++ b/src/state_manager/mod.rs @@ -202,7 +202,7 @@ where Ok(Self { cs, - cache: TipsetStateCache::new(), // For StateOutputValue + cache: TipsetStateCache::new("state_output"), // For StateOutputValue beacon, chain_config, engine, diff --git a/src/utils/misc/mod.rs b/src/utils/misc/mod.rs index f44465991feb..61b8277d5b56 100644 --- a/src/utils/misc/mod.rs +++ b/src/utils/misc/mod.rs @@ -8,8 +8,6 @@ pub use adaptive_value_provider::*; mod logo; pub use logo::*; pub mod env; -mod r#type; -pub use r#type::*; #[derive(Debug, Clone, PartialEq, Eq, strum::EnumString)] #[strum(serialize_all = "kebab-case")] diff --git a/src/utils/misc/type.rs b/src/utils/misc/type.rs deleted file mode 100644 index 0fe4009a41d9..000000000000 --- a/src/utils/misc/type.rs +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2019-2025 ChainSafe Systems -// SPDX-License-Identifier: Apache-2.0, MIT - -use std::{any::type_name, borrow::Cow}; - -pub fn short_type_name() -> Cow<'static, str> { - let prefix_pattern = lazy_regex::regex!(r#"(([^,:<>]+::)|\s)*"#); - let n = type_name::(); - prefix_pattern.replace_all(n, "") -} - -#[cfg(test)] -mod tests { - use super::*; - use std::borrow::Cow; - use std::io::Result as IoResult; - - #[test] - fn test_short_type_name() { - assert_eq!(short_type_name::(), "String"); - assert_eq!(short_type_name::>(), "Option"); - assert_eq!( - short_type_name::>>(), - "Result,Error>" - ); - assert_eq!(short_type_name::>(), "Cow"); - assert_eq!( - short_type_name::>>(), - "Result,Error>" - ); - } -}