mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-14 10:22:38 +00:00
Clippy 1.49.0 updates and dht persistence test fix (#2156)
## Issue Addressed `test_dht_persistence` failing ## Proposed Changes Bind `NetworkService::start` to an underscore prefixed variable rather than `_`. `_` was causing it to be dropped immediately This was failing 5/100 times before this update, but I haven't been able to get it to fail after updating it Co-authored-by: realbigsean <seananderson33@gmail.com>
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
use parking_lot::RwLock;
|
||||
use ssz_derive::{Decode, Encode};
|
||||
use std::collections::HashMap;
|
||||
use std::iter::FromIterator;
|
||||
use types::{Hash256, Slot};
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
@@ -61,13 +60,12 @@ impl HeadTracker {
|
||||
slots_len,
|
||||
})
|
||||
} else {
|
||||
let map = HashMap::from_iter(
|
||||
ssz_container
|
||||
.roots
|
||||
.iter()
|
||||
.zip(ssz_container.slots.iter())
|
||||
.map(|(root, slot)| (*root, *slot)),
|
||||
);
|
||||
let map = ssz_container
|
||||
.roots
|
||||
.iter()
|
||||
.zip(ssz_container.slots.iter())
|
||||
.map(|(root, slot)| (*root, *slot))
|
||||
.collect::<HashMap<_, _>>();
|
||||
|
||||
Ok(Self(RwLock::new(map)))
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ use derivative::Derivative;
|
||||
use smallvec::SmallVec;
|
||||
use state_processing::{SigVerifiedOp, VerifyOperation};
|
||||
use std::collections::HashSet;
|
||||
use std::iter::FromIterator;
|
||||
use std::marker::PhantomData;
|
||||
use types::{
|
||||
AttesterSlashing, BeaconState, ChainSpec, EthSpec, ProposerSlashing, SignedVoluntaryExit,
|
||||
@@ -57,10 +56,18 @@ impl<E: EthSpec> ObservableOperation<E> for ProposerSlashing {
|
||||
|
||||
impl<E: EthSpec> ObservableOperation<E> for AttesterSlashing<E> {
|
||||
fn observed_validators(&self) -> SmallVec<[u64; SMALL_VEC_SIZE]> {
|
||||
let attestation_1_indices =
|
||||
HashSet::<u64>::from_iter(self.attestation_1.attesting_indices.iter().copied());
|
||||
let attestation_2_indices =
|
||||
HashSet::<u64>::from_iter(self.attestation_2.attesting_indices.iter().copied());
|
||||
let attestation_1_indices = self
|
||||
.attestation_1
|
||||
.attesting_indices
|
||||
.iter()
|
||||
.copied()
|
||||
.collect::<HashSet<u64>>();
|
||||
let attestation_2_indices = self
|
||||
.attestation_2
|
||||
.attesting_indices
|
||||
.iter()
|
||||
.copied()
|
||||
.collect::<HashSet<u64>>();
|
||||
attestation_1_indices
|
||||
.intersection(&attestation_2_indices)
|
||||
.copied()
|
||||
|
||||
@@ -878,7 +878,13 @@ impl Service {
|
||||
// imported if any one of them cannot be parsed.
|
||||
.collect::<Result<Vec<_>, _>>()?
|
||||
.into_iter()
|
||||
.map(|deposit_log| {
|
||||
// Returns if a deposit is unable to be added to the cache.
|
||||
//
|
||||
// If this error occurs, the cache will no longer be guaranteed to hold either
|
||||
// none or all of the logs for each block (i.e., they may exist _some_ logs for
|
||||
// a block, but not _all_ logs for that block). This scenario can cause the
|
||||
// node to choose an invalid genesis state or propose an invalid block.
|
||||
.try_for_each(|deposit_log| {
|
||||
if let DepositCacheInsertOutcome::Inserted = cache
|
||||
.cache
|
||||
.insert_log(deposit_log)
|
||||
@@ -888,14 +894,7 @@ impl Service {
|
||||
}
|
||||
|
||||
Ok(())
|
||||
})
|
||||
// Returns if a deposit is unable to be added to the cache.
|
||||
//
|
||||
// If this error occurs, the cache will no longer be guaranteed to hold either
|
||||
// none or all of the logs for each block (i.e., they may exist _some_ logs for
|
||||
// a block, but not _all_ logs for that block). This scenario can cause the
|
||||
// node to choose an invalid genesis state or propose an invalid block.
|
||||
.collect::<Result<_, _>>()?;
|
||||
})?;
|
||||
|
||||
debug!(
|
||||
self.log,
|
||||
|
||||
@@ -70,16 +70,16 @@ impl<TSpec: EthSpec> PeerScoreSettings<TSpec> {
|
||||
enr_fork_id: &EnrForkId,
|
||||
current_slot: Slot,
|
||||
) -> error::Result<PeerScoreParams> {
|
||||
let mut params = PeerScoreParams::default();
|
||||
|
||||
params.decay_interval = self.decay_interval;
|
||||
params.decay_to_zero = self.decay_to_zero;
|
||||
params.retain_score = self.epoch * 100;
|
||||
params.app_specific_weight = 1.0;
|
||||
params.ip_colocation_factor_threshold = 3.0;
|
||||
params.behaviour_penalty_threshold = 6.0;
|
||||
|
||||
params.behaviour_penalty_decay = self.score_parameter_decay(self.epoch * 10);
|
||||
let mut params = PeerScoreParams {
|
||||
decay_interval: self.decay_interval,
|
||||
decay_to_zero: self.decay_to_zero,
|
||||
retain_score: self.epoch * 100,
|
||||
app_specific_weight: 1.0,
|
||||
ip_colocation_factor_threshold: 3.0,
|
||||
behaviour_penalty_threshold: 6.0,
|
||||
behaviour_penalty_decay: self.score_parameter_decay(self.epoch * 10),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let target_value = Self::decay_convergence(
|
||||
params.behaviour_penalty_decay,
|
||||
|
||||
@@ -97,7 +97,7 @@ impl<T: EthSpec> PeerInfo<T> {
|
||||
}
|
||||
|
||||
/// Returns the seen IP addresses of the peer.
|
||||
pub fn seen_addresses<'a>(&'a self) -> impl Iterator<Item = IpAddr> + 'a {
|
||||
pub fn seen_addresses(&self) -> impl Iterator<Item = IpAddr> + '_ {
|
||||
self.seen_addresses
|
||||
.iter()
|
||||
.map(|socket_addr| socket_addr.ip())
|
||||
|
||||
@@ -29,14 +29,12 @@ pub struct SyncInfo {
|
||||
|
||||
impl std::cmp::PartialEq for PeerSyncStatus {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
match (self, other) {
|
||||
(PeerSyncStatus::Synced { .. }, PeerSyncStatus::Synced { .. }) => true,
|
||||
(PeerSyncStatus::Advanced { .. }, PeerSyncStatus::Advanced { .. }) => true,
|
||||
(PeerSyncStatus::Behind { .. }, PeerSyncStatus::Behind { .. }) => true,
|
||||
(PeerSyncStatus::IrrelevantPeer, PeerSyncStatus::IrrelevantPeer) => true,
|
||||
(PeerSyncStatus::Unknown, PeerSyncStatus::Unknown) => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!((self, other),
|
||||
(PeerSyncStatus::Synced { .. }, PeerSyncStatus::Synced { .. }) |
|
||||
(PeerSyncStatus::Advanced { .. }, PeerSyncStatus::Advanced { .. }) |
|
||||
(PeerSyncStatus::Behind { .. }, PeerSyncStatus::Behind { .. }) |
|
||||
(PeerSyncStatus::IrrelevantPeer, PeerSyncStatus::IrrelevantPeer) |
|
||||
(PeerSyncStatus::Unknown, PeerSyncStatus::Unknown))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,14 +23,12 @@ pub enum SyncState {
|
||||
|
||||
impl PartialEq for SyncState {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
match (self, other) {
|
||||
(SyncState::SyncingFinalized { .. }, SyncState::SyncingFinalized { .. }) => true,
|
||||
(SyncState::SyncingHead { .. }, SyncState::SyncingHead { .. }) => true,
|
||||
(SyncState::Synced, SyncState::Synced) => true,
|
||||
(SyncState::Stalled, SyncState::Stalled) => true,
|
||||
(SyncState::SyncTransition, SyncState::SyncTransition) => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!((self, other),
|
||||
(SyncState::SyncingFinalized { .. }, SyncState::SyncingFinalized { .. }) |
|
||||
(SyncState::SyncingHead { .. }, SyncState::SyncingHead { .. }) |
|
||||
(SyncState::Synced, SyncState::Synced) |
|
||||
(SyncState::Stalled, SyncState::Stalled) |
|
||||
(SyncState::SyncTransition, SyncState::SyncTransition))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -70,11 +70,9 @@ mod tests {
|
||||
// Create a new network service which implicitly gets dropped at the
|
||||
// end of the block.
|
||||
|
||||
let _ = NetworkService::start(beacon_chain.clone(), &config, executor)
|
||||
let _network_service = NetworkService::start(beacon_chain.clone(), &config, executor)
|
||||
.await
|
||||
.unwrap();
|
||||
// Allow the network task to spawn on the executor before shutting down.
|
||||
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
|
||||
drop(signal);
|
||||
});
|
||||
|
||||
|
||||
@@ -161,7 +161,7 @@ impl<T: BeaconChainTypes> SyncingChain<T> {
|
||||
}
|
||||
|
||||
/// Peers currently syncing this chain.
|
||||
pub fn peers<'a>(&'a self) -> impl Iterator<Item = PeerId> + 'a {
|
||||
pub fn peers(&self) -> impl Iterator<Item = PeerId> + '_ {
|
||||
self.peers.keys().cloned()
|
||||
}
|
||||
|
||||
|
||||
@@ -26,9 +26,10 @@ pub fn get_config<E: EthSpec>(
|
||||
spec: &ChainSpec,
|
||||
log: Logger,
|
||||
) -> Result<ClientConfig, String> {
|
||||
let mut client_config = ClientConfig::default();
|
||||
|
||||
client_config.data_dir = get_data_dir(cli_args);
|
||||
let mut client_config = ClientConfig {
|
||||
data_dir: get_data_dir(cli_args),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
// If necessary, remove any existing database and configuration
|
||||
if client_config.data_dir.exists() && cli_args.is_present("purge-db") {
|
||||
|
||||
@@ -202,9 +202,7 @@ impl<E: EthSpec> HotColdDB<E, LevelDB<E>, LevelDB<E>> {
|
||||
}
|
||||
|
||||
/// Return an iterator over the state roots of all temporary states.
|
||||
pub fn iter_temporary_state_roots<'a>(
|
||||
&'a self,
|
||||
) -> impl Iterator<Item = Result<Hash256, Error>> + 'a {
|
||||
pub fn iter_temporary_state_roots(&self) -> impl Iterator<Item = Result<Hash256, Error>> + '_ {
|
||||
let column = DBColumn::BeaconStateTemporary;
|
||||
let start_key =
|
||||
BytesKey::from_vec(get_key_for_col(column.into(), Hash256::zero().as_bytes()));
|
||||
|
||||
Reference in New Issue
Block a user