mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-14 10:22:38 +00:00
Update dependencies to get rid of the yanked deps (#4994)
* Initial attempt to upgrade hashbrown to latest to get rid of the crate warnings. * Replace `.expect()` usage with use of `const`. * Update ahash 0.7 as well * Remove unsafe code. * Update `lru` to 0.12 and fix release test errors. * Set non-blocking socket * Bump testcontainers to 0.15. * Fix lint --------- Co-authored-by: Michael Sproul <michael@sigmaprime.io>
This commit is contained in:
@@ -14,13 +14,15 @@ use lru::LruCache;
|
||||
use smallvec::SmallVec;
|
||||
use state_processing::state_advance::partial_state_advance;
|
||||
use std::cmp::Ordering;
|
||||
use std::num::NonZeroUsize;
|
||||
use types::non_zero_usize::new_non_zero_usize;
|
||||
use types::{
|
||||
BeaconState, BeaconStateError, ChainSpec, CloneConfig, Epoch, EthSpec, Fork, Hash256, Slot,
|
||||
Unsigned,
|
||||
};
|
||||
|
||||
/// The number of sets of proposer indices that should be cached.
|
||||
const CACHE_SIZE: usize = 16;
|
||||
const CACHE_SIZE: NonZeroUsize = new_non_zero_usize(16);
|
||||
|
||||
/// This value is fairly unimportant, it's used to avoid heap allocations. The result of it being
|
||||
/// incorrect is non-substantial from a consensus perspective (and probably also from a
|
||||
|
||||
@@ -17,6 +17,7 @@ use slog::{debug, error, Logger};
|
||||
use slot_clock::SlotClock;
|
||||
use std::fmt;
|
||||
use std::fmt::Debug;
|
||||
use std::num::NonZeroUsize;
|
||||
use std::sync::Arc;
|
||||
use task_executor::TaskExecutor;
|
||||
use types::beacon_block_body::{KzgCommitmentOpts, KzgCommitments};
|
||||
@@ -32,15 +33,17 @@ mod processing_cache;
|
||||
mod state_lru_cache;
|
||||
|
||||
pub use error::{Error as AvailabilityCheckError, ErrorCategory as AvailabilityCheckErrorCategory};
|
||||
use types::non_zero_usize::new_non_zero_usize;
|
||||
|
||||
/// The LRU Cache stores `PendingComponents` which can store up to
|
||||
/// `MAX_BLOBS_PER_BLOCK = 6` blobs each. A `BlobSidecar` is 0.131256 MB. So
|
||||
/// the maximum size of a `PendingComponents` is ~ 0.787536 MB. Setting this
|
||||
/// to 1024 means the maximum size of the cache is ~ 0.8 GB. But the cache
|
||||
/// will target a size of less than 75% of capacity.
|
||||
pub const OVERFLOW_LRU_CAPACITY: usize = 1024;
|
||||
pub const OVERFLOW_LRU_CAPACITY: NonZeroUsize = new_non_zero_usize(1024);
|
||||
/// Until tree-states is implemented, we can't store very many states in memory :(
|
||||
pub const STATE_LRU_CAPACITY: usize = 2;
|
||||
pub const STATE_LRU_CAPACITY_NON_ZERO: NonZeroUsize = new_non_zero_usize(2);
|
||||
pub const STATE_LRU_CAPACITY: usize = STATE_LRU_CAPACITY_NON_ZERO.get();
|
||||
|
||||
/// This includes a cache for any blocks or blobs that have been received over gossip or RPC
|
||||
/// and are awaiting more components before they can be imported. Additionally the
|
||||
|
||||
@@ -42,6 +42,7 @@ use parking_lot::{Mutex, RwLock, RwLockUpgradableReadGuard};
|
||||
use ssz::{Decode, Encode};
|
||||
use ssz_derive::{Decode, Encode};
|
||||
use ssz_types::{FixedVector, VariableList};
|
||||
use std::num::NonZeroUsize;
|
||||
use std::{collections::HashSet, sync::Arc};
|
||||
use types::blob_sidecar::BlobIdentifier;
|
||||
use types::{BlobSidecar, ChainSpec, Epoch, EthSpec, Hash256};
|
||||
@@ -288,7 +289,7 @@ struct Critical<T: BeaconChainTypes> {
|
||||
}
|
||||
|
||||
impl<T: BeaconChainTypes> Critical<T> {
|
||||
pub fn new(capacity: usize) -> Self {
|
||||
pub fn new(capacity: NonZeroUsize) -> Self {
|
||||
Self {
|
||||
in_memory: LruCache::new(capacity),
|
||||
store_keys: HashSet::new(),
|
||||
@@ -329,7 +330,7 @@ impl<T: BeaconChainTypes> Critical<T> {
|
||||
pending_components: PendingComponents<T::EthSpec>,
|
||||
overflow_store: &OverflowStore<T>,
|
||||
) -> Result<(), AvailabilityCheckError> {
|
||||
if self.in_memory.len() == self.in_memory.cap() {
|
||||
if self.in_memory.len() == self.in_memory.cap().get() {
|
||||
// cache will overflow, must write lru entry to disk
|
||||
if let Some((lru_key, lru_value)) = self.in_memory.pop_lru() {
|
||||
overflow_store.persist_pending_components(lru_key, lru_value)?;
|
||||
@@ -377,12 +378,12 @@ pub struct OverflowLRUCache<T: BeaconChainTypes> {
|
||||
/// Mutex to guard maintenance methods which move data between disk and memory
|
||||
maintenance_lock: Mutex<()>,
|
||||
/// The capacity of the LRU cache
|
||||
capacity: usize,
|
||||
capacity: NonZeroUsize,
|
||||
}
|
||||
|
||||
impl<T: BeaconChainTypes> OverflowLRUCache<T> {
|
||||
pub fn new(
|
||||
capacity: usize,
|
||||
capacity: NonZeroUsize,
|
||||
beacon_store: BeaconStore<T>,
|
||||
spec: ChainSpec,
|
||||
) -> Result<Self, AvailabilityCheckError> {
|
||||
@@ -514,7 +515,7 @@ impl<T: BeaconChainTypes> OverflowLRUCache<T> {
|
||||
/// maintain the cache
|
||||
pub fn do_maintenance(&self, cutoff_epoch: Epoch) -> Result<(), AvailabilityCheckError> {
|
||||
// ensure memory usage is below threshold
|
||||
let threshold = self.capacity * 3 / 4;
|
||||
let threshold = self.capacity.get() * 3 / 4;
|
||||
self.maintain_threshold(threshold, cutoff_epoch)?;
|
||||
// clean up any keys on the disk that shouldn't be there
|
||||
self.prune_disk(cutoff_epoch)?;
|
||||
@@ -753,6 +754,7 @@ mod test {
|
||||
use std::ops::AddAssign;
|
||||
use store::{HotColdDB, ItemStore, LevelDB, StoreConfig};
|
||||
use tempfile::{tempdir, TempDir};
|
||||
use types::non_zero_usize::new_non_zero_usize;
|
||||
use types::{ChainSpec, ExecPayload, MinimalEthSpec};
|
||||
|
||||
const LOW_VALIDATOR_COUNT: usize = 32;
|
||||
@@ -974,8 +976,9 @@ mod test {
|
||||
let harness = get_deneb_chain(log.clone(), &chain_db_path).await;
|
||||
let spec = harness.spec.clone();
|
||||
let test_store = harness.chain.store.clone();
|
||||
let capacity_non_zero = new_non_zero_usize(capacity);
|
||||
let cache = Arc::new(
|
||||
OverflowLRUCache::<T>::new(capacity, test_store, spec.clone())
|
||||
OverflowLRUCache::<T>::new(capacity_non_zero, test_store, spec.clone())
|
||||
.expect("should create cache"),
|
||||
);
|
||||
(harness, cache, chain_db_path)
|
||||
@@ -1477,7 +1480,7 @@ mod test {
|
||||
|
||||
// create a new cache with the same store
|
||||
let recovered_cache = OverflowLRUCache::<T>::new(
|
||||
capacity,
|
||||
new_non_zero_usize(capacity),
|
||||
harness.chain.store.clone(),
|
||||
harness.chain.spec.clone(),
|
||||
)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::block_verification_types::AsBlock;
|
||||
use crate::{
|
||||
block_verification_types::BlockImportData,
|
||||
data_availability_checker::{AvailabilityCheckError, STATE_LRU_CAPACITY},
|
||||
data_availability_checker::{AvailabilityCheckError, STATE_LRU_CAPACITY_NON_ZERO},
|
||||
eth1_finalization_cache::Eth1FinalizationData,
|
||||
AvailabilityPendingExecutedBlock, BeaconChainTypes, BeaconStore, PayloadVerificationOutcome,
|
||||
};
|
||||
@@ -61,7 +61,7 @@ pub struct StateLRUCache<T: BeaconChainTypes> {
|
||||
impl<T: BeaconChainTypes> StateLRUCache<T> {
|
||||
pub fn new(store: BeaconStore<T>, spec: ChainSpec) -> Self {
|
||||
Self {
|
||||
states: RwLock::new(LruCache::new(STATE_LRU_CAPACITY)),
|
||||
states: RwLock::new(LruCache::new(STATE_LRU_CAPACITY_NON_ZERO)),
|
||||
store,
|
||||
spec,
|
||||
}
|
||||
|
||||
@@ -3,11 +3,13 @@ use itertools::process_results;
|
||||
use lru::LruCache;
|
||||
use parking_lot::Mutex;
|
||||
use slog::debug;
|
||||
use std::num::NonZeroUsize;
|
||||
use std::time::Duration;
|
||||
use types::non_zero_usize::new_non_zero_usize;
|
||||
use types::Hash256;
|
||||
|
||||
const BLOCK_ROOT_CACHE_LIMIT: usize = 512;
|
||||
const LOOKUP_LIMIT: usize = 8;
|
||||
const BLOCK_ROOT_CACHE_LIMIT: NonZeroUsize = new_non_zero_usize(512);
|
||||
const LOOKUP_LIMIT: NonZeroUsize = new_non_zero_usize(8);
|
||||
const METRICS_TIMEOUT: Duration = Duration::from_millis(100);
|
||||
|
||||
/// Cache for rejecting attestations to blocks from before finalization.
|
||||
@@ -78,7 +80,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
|
||||
// 3. Check the network with a single block lookup.
|
||||
cache.in_progress_lookups.put(block_root, ());
|
||||
if cache.in_progress_lookups.len() == LOOKUP_LIMIT {
|
||||
if cache.in_progress_lookups.len() == LOOKUP_LIMIT.get() {
|
||||
// NOTE: we expect this to occur sometimes if a lot of blocks that we look up fail to be
|
||||
// imported for reasons other than being pre-finalization. The cache will eventually
|
||||
// self-repair in this case by replacing old entries with new ones until all the failed
|
||||
|
||||
Reference in New Issue
Block a user