mirror of
https://github.com/sigp/lighthouse.git
synced 2026-06-30 11:24:31 +00:00
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:
@@ -20,13 +20,13 @@ fixed_bytes = { workspace = true }
|
||||
fork_choice = { workspace = true }
|
||||
hash-db = "0.15.2"
|
||||
hash256-std-hasher = "0.15.2"
|
||||
hashlink = { workspace = true }
|
||||
hex = { workspace = true }
|
||||
jsonwebtoken = "9"
|
||||
keccak-hash = "0.10.0"
|
||||
kzg = { workspace = true }
|
||||
lighthouse_version = { workspace = true }
|
||||
logging = { workspace = true }
|
||||
lru = { workspace = true }
|
||||
metrics = { workspace = true }
|
||||
parking_lot = { workspace = true }
|
||||
pretty_reqwest_error = { workspace = true }
|
||||
|
||||
@@ -5,9 +5,8 @@ use crate::engine_api::{
|
||||
PayloadId,
|
||||
};
|
||||
use crate::{ClientVersionV1, HttpJsonRpc};
|
||||
use lru::LruCache;
|
||||
use hashlink::lru_cache::LruCache;
|
||||
use std::future::Future;
|
||||
use std::num::NonZeroUsize;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use task_executor::TaskExecutor;
|
||||
@@ -15,12 +14,11 @@ use tokio::sync::{Mutex, RwLock, watch};
|
||||
use tokio_stream::wrappers::WatchStream;
|
||||
use tracing::{debug, error, info, warn};
|
||||
use types::ExecutionBlockHash;
|
||||
use types::new_non_zero_usize;
|
||||
|
||||
/// The number of payload IDs that will be stored for each `Engine`.
|
||||
///
|
||||
/// Since the size of each value is small (~800 bytes) a large number is used for safety.
|
||||
const PAYLOAD_ID_LRU_CACHE_SIZE: NonZeroUsize = new_non_zero_usize(512);
|
||||
const PAYLOAD_ID_LRU_CACHE_SIZE: usize = 512;
|
||||
const CACHED_RESPONSE_AGE_LIMIT: Duration = Duration::from_secs(900); // 15 minutes
|
||||
|
||||
/// Stores the remembered state of a engine.
|
||||
@@ -175,7 +173,7 @@ impl Engine {
|
||||
if let Some(key) = payload_attributes
|
||||
.map(|pa| PayloadIdCacheKey::new(&forkchoice_state.head_block_hash, &pa))
|
||||
{
|
||||
self.payload_id_cache.lock().await.put(key, payload_id);
|
||||
self.payload_id_cache.lock().await.insert(key, payload_id);
|
||||
} else {
|
||||
debug!(?payload_id, "Engine returned unexpected payload_id");
|
||||
}
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
use eth2::types::FullPayloadContents;
|
||||
use lru::LruCache;
|
||||
use hashlink::lru_cache::LruCache;
|
||||
use parking_lot::Mutex;
|
||||
use std::num::NonZeroUsize;
|
||||
use tree_hash::TreeHash;
|
||||
use types::new_non_zero_usize;
|
||||
use types::{EthSpec, Hash256};
|
||||
|
||||
pub const DEFAULT_PAYLOAD_CACHE_SIZE: NonZeroUsize = new_non_zero_usize(10);
|
||||
pub const DEFAULT_PAYLOAD_CACHE_SIZE: usize = 10;
|
||||
|
||||
/// A cache mapping execution payloads by tree hash roots.
|
||||
pub struct PayloadCache<E: EthSpec> {
|
||||
@@ -27,11 +25,11 @@ impl<E: EthSpec> Default for PayloadCache<E> {
|
||||
impl<E: EthSpec> PayloadCache<E> {
|
||||
pub fn put(&self, payload: FullPayloadContents<E>) -> Option<FullPayloadContents<E>> {
|
||||
let root = payload.payload_ref().tree_hash_root();
|
||||
self.payloads.lock().put(PayloadCacheId(root), payload)
|
||||
self.payloads.lock().insert(PayloadCacheId(root), payload)
|
||||
}
|
||||
|
||||
pub fn pop(&self, root: &Hash256) -> Option<FullPayloadContents<E>> {
|
||||
self.payloads.lock().pop(&PayloadCacheId(*root))
|
||||
self.payloads.lock().remove(&PayloadCacheId(*root))
|
||||
}
|
||||
|
||||
pub fn get(&self, hash: &Hash256) -> Option<FullPayloadContents<E>> {
|
||||
|
||||
Reference in New Issue
Block a user