mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-11 18:04:18 +00:00
Fix ups and Clippy
This commit is contained in:
@@ -7,6 +7,7 @@ edition = "2021"
|
||||
[dev-dependencies]
|
||||
tempfile = "3.1.0"
|
||||
beacon_chain = {path = "../beacon_chain"}
|
||||
logging = { path = "../../common/logging" }
|
||||
|
||||
[dependencies]
|
||||
db-key = "0.0.5"
|
||||
@@ -26,7 +27,7 @@ lighthouse_metrics = { path = "../../common/lighthouse_metrics" }
|
||||
lru = "0.7.1"
|
||||
sloggers = { version = "2.1.1", features = ["json"] }
|
||||
directory = { path = "../../common/directory" }
|
||||
tree_hash = "0.4.0"
|
||||
tree_hash = "0.5.0"
|
||||
take-until = "0.1.0"
|
||||
zstd = "0.11.0"
|
||||
strum = { version = "0.24.0", features = ["derive"] }
|
||||
|
||||
@@ -1729,6 +1729,7 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
|
||||
}
|
||||
|
||||
/// Load the state root of a restore point.
|
||||
#[allow(unused)]
|
||||
fn load_restore_point_hash(&self, restore_point_index: u64) -> Result<Hash256, Error> {
|
||||
let key = Self::restore_point_key(restore_point_index);
|
||||
self.cold_db
|
||||
@@ -1738,6 +1739,7 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
|
||||
}
|
||||
|
||||
/// Store the state root of a restore point.
|
||||
#[allow(unused)]
|
||||
fn store_restore_point_hash(
|
||||
&self,
|
||||
restore_point_index: u64,
|
||||
@@ -1751,6 +1753,7 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
|
||||
}
|
||||
|
||||
/// Convert a `restore_point_index` into a database key.
|
||||
#[allow(unused)]
|
||||
fn restore_point_key(restore_point_index: u64) -> Hash256 {
|
||||
Hash256::from_low_u64_be(restore_point_index)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::*;
|
||||
use ssz::{DecodeError, Encode};
|
||||
use ssz::Encode;
|
||||
use ssz_derive::Encode;
|
||||
use std::io::{Read, Write};
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -146,7 +146,7 @@ impl<E: EthSpec> StateCache<E> {
|
||||
.iter()
|
||||
.rev()
|
||||
.find_map(|(ancestor_slot, state_root)| {
|
||||
(*ancestor_slot <= slot).then(|| *state_root)
|
||||
(*ancestor_slot <= slot).then_some(*state_root)
|
||||
})?;
|
||||
|
||||
let state = self.get_by_state_root(state_root)?;
|
||||
|
||||
@@ -218,6 +218,7 @@ impl DatabaseValidator {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
fn into_immutable_validator(&self) -> Result<(PublicKey, ValidatorImmutable), Error> {
|
||||
let pubkey = PublicKey::deserialize_uncompressed(&self.pubkey)
|
||||
.map_err(Error::InvalidValidatorPubkeyBytes)?;
|
||||
@@ -236,14 +237,14 @@ impl DatabaseValidator {
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use crate::test_utils::{BeaconChainHarness, EphemeralHarnessType};
|
||||
use crate::{HotColdDB, KeyValueStore, MemoryStore};
|
||||
use beacon_chain::test_utils::BeaconChainHarness;
|
||||
use logging::test_logger;
|
||||
use std::sync::Arc;
|
||||
use store::HotColdDB;
|
||||
use types::{BeaconState, EthSpec, Keypair, MainnetEthSpec};
|
||||
|
||||
type E = MainnetEthSpec;
|
||||
type T = EphemeralHarnessType<E>;
|
||||
type Store = MemoryStore<E>;
|
||||
|
||||
fn get_state(validator_count: usize) -> (BeaconState<E>, Vec<Keypair>) {
|
||||
let harness = BeaconChainHarness::builder(MainnetEthSpec)
|
||||
@@ -257,14 +258,14 @@ mod test {
|
||||
(harness.get_current_state(), harness.validator_keypairs)
|
||||
}
|
||||
|
||||
fn get_store() -> BeaconStore<T> {
|
||||
fn get_store() -> Arc<HotColdDB<E, Store, Store>> {
|
||||
Arc::new(
|
||||
HotColdDB::open_ephemeral(<_>::default(), E::default_spec(), test_logger()).unwrap(),
|
||||
)
|
||||
}
|
||||
|
||||
#[allow(clippy::needless_range_loop)]
|
||||
fn check_cache_get(cache: &ValidatorPubkeyCache<T>, keypairs: &[Keypair]) {
|
||||
fn check_cache_get(cache: &ValidatorPubkeyCache<E, Store, Store>, keypairs: &[Keypair]) {
|
||||
let validator_count = keypairs.len();
|
||||
|
||||
for i in 0..validator_count + 1 {
|
||||
@@ -297,7 +298,7 @@ mod test {
|
||||
|
||||
let store = get_store();
|
||||
|
||||
let mut cache = ValidatorPubkeyCache::new(&state, store).expect("should create cache");
|
||||
let mut cache = ValidatorPubkeyCache::new(&state, &store).expect("should create cache");
|
||||
|
||||
check_cache_get(&cache, &keypairs[..]);
|
||||
|
||||
@@ -330,13 +331,12 @@ mod test {
|
||||
let store = get_store();
|
||||
|
||||
// Create a new cache.
|
||||
let cache = ValidatorPubkeyCache::new(&state, store.clone()).expect("should create cache");
|
||||
let cache = ValidatorPubkeyCache::new(&state, &store).expect("should create cache");
|
||||
check_cache_get(&cache, &keypairs[..]);
|
||||
drop(cache);
|
||||
|
||||
// Re-init the cache from the store.
|
||||
let mut cache =
|
||||
ValidatorPubkeyCache::load_from_store(store.clone()).expect("should open cache");
|
||||
let mut cache = ValidatorPubkeyCache::load_from_store(&store).expect("should open cache");
|
||||
check_cache_get(&cache, &keypairs[..]);
|
||||
|
||||
// Add some more keypairs.
|
||||
@@ -349,7 +349,7 @@ mod test {
|
||||
drop(cache);
|
||||
|
||||
// Re-init the cache from the store.
|
||||
let cache = ValidatorPubkeyCache::load_from_store(store).expect("should open cache");
|
||||
let cache = ValidatorPubkeyCache::load_from_store(&store).expect("should open cache");
|
||||
check_cache_get(&cache, &keypairs[..]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user