Use hashlink over lru for LruCache (#8911)

Use the `LruCache` implementation provided by `hashlink` instead of the current `lru` one.
This is mostly a 1-to-1 swap with only slight API incompatibilities.
I have decided to leave some config files which previously used `NonZeroUsize` but they may not be required anymore and could potentially switch to `usize`.


Co-Authored-By: Mac L <mjladson@pm.me>
This commit is contained in:
Mac L
2026-06-16 10:54:11 +04:00
committed by GitHub
parent 41dff2d965
commit e0ff3b5709
28 changed files with 166 additions and 192 deletions

View File

@@ -20,12 +20,12 @@ ethereum_ssz = { workspace = true }
execution_layer = { workspace = true }
fixed_bytes = { workspace = true }
futures = { workspace = true }
hashlink = { workspace = true }
health_metrics = { workspace = true }
hex = { workspace = true }
lighthouse_network = { workspace = true }
lighthouse_version = { workspace = true }
logging = { workspace = true }
lru = { workspace = true }
metrics = { workspace = true }
network = { workspace = true }
network_utils = { workspace = true }

View File

@@ -1,6 +1,5 @@
use lru::LruCache;
use hashlink::lru_cache::LruCache;
use parking_lot::Mutex;
use std::num::NonZeroUsize;
use std::sync::Arc;
use types::{AttestationShufflingId, CommitteeCache, Epoch};
@@ -25,7 +24,7 @@ pub struct HistoricalCommitteeCache {
}
impl HistoricalCommitteeCache {
pub fn new(size: NonZeroUsize) -> Self {
pub fn new(size: usize) -> Self {
Self {
committees: Mutex::new(LruCache::new(size)),
}
@@ -38,6 +37,6 @@ impl HistoricalCommitteeCache {
}
pub fn insert(&self, id: HistoricalShufflingId, cache: Arc<CommitteeCache>) {
self.committees.lock().put(id, cache);
self.committees.lock().insert(id, cache);
}
}

View File

@@ -22,10 +22,10 @@ use lighthouse_network::{
};
use network::{NetworkReceivers, NetworkSenders};
use sensitive_url::SensitiveUrl;
use std::future::Future;
use std::net::SocketAddr;
use std::sync::Arc;
use std::time::Duration;
use std::{future::Future, num::NonZeroUsize};
use store::MemoryStore;
use task_executor::test_utils::TestRuntime;
use types::{ChainSpec, EthSpec};
@@ -294,7 +294,7 @@ pub async fn create_api_server_with_config<T: BeaconChainTypes>(
beacon_processor_send: Some(beacon_processor_send),
sse_logging_components: None,
historical_committee_cache: Arc::new(HistoricalCommitteeCache::new(
NonZeroUsize::new(http_config.historical_committee_cache_size).unwrap(),
http_config.historical_committee_cache_size,
)),
});