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

@@ -22,9 +22,9 @@ ethereum_ssz_derive = { workspace = true }
filesystem = { workspace = true }
fixed_bytes = { workspace = true }
flate2 = { version = "1.0.14", features = ["zlib"], default-features = false }
hashlink = { workspace = true }
lmdb-rkv = { git = "https://github.com/sigp/lmdb-rs", rev = "f33845c6469b94265319aac0ed5085597862c27e", optional = true }
lmdb-rkv-sys = { git = "https://github.com/sigp/lmdb-rs", rev = "f33845c6469b94265319aac0ed5085597862c27e", optional = true }
lru = { workspace = true }
# MDBX is pinned at the last version with Windows and macOS support.
mdbx = { package = "libmdbx", git = "https://github.com/sigp/libmdbx-rs", rev = "e6ff4b9377c1619bcf0bfdf52bee5a980a432a1a", optional = true }

View File

@@ -9,8 +9,8 @@ use crate::{
};
use bls::AggregateSignature;
use byteorder::{BigEndian, ByteOrder};
use hashlink::lru_cache::LruCache;
use interface::{Environment, OpenDatabases, RwTransaction};
use lru::LruCache;
use parking_lot::Mutex;
use serde::de::DeserializeOwned;
use ssz::{Decode, Encode};
@@ -305,7 +305,8 @@ impl<E: EthSpec> SlasherDB<E> {
}
}
let attestation_root_cache = Mutex::new(LruCache::new(config.attestation_root_cache_size));
let attestation_root_cache =
Mutex::new(LruCache::new(config.attestation_root_cache_size.get()));
let mut db = Self {
env,
@@ -559,7 +560,7 @@ impl<E: EthSpec> SlasherDB<E> {
let indexed_attestation = self.get_indexed_attestation(txn, indexed_id)?;
let attestation_data_root = indexed_attestation.data().tree_hash_root();
cache.put(indexed_id, attestation_data_root);
cache.insert(indexed_id, attestation_data_root);
Ok((attestation_data_root, Some(indexed_attestation)))
}
@@ -570,13 +571,13 @@ impl<E: EthSpec> SlasherDB<E> {
attestation_data_root: Hash256,
) {
let mut cache = self.attestation_root_cache.lock();
cache.put(indexed_attestation_id, attestation_data_root);
cache.insert(indexed_attestation_id, attestation_data_root);
}
fn delete_attestation_data_roots(&self, ids: impl IntoIterator<Item = IndexedAttestationId>) {
let mut cache = self.attestation_root_cache.lock();
for indexed_id in ids {
cache.pop(&indexed_id);
cache.remove(&indexed_id);
}
}