mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-07 08:52:54 +00:00
Fix clippy warnings (#1385)
## Issue Addressed NA ## Proposed Changes Fixes most clippy warnings and ignores the rest of them, see issue #1388.
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
use crate::ForkChoiceStore;
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use proto_array::{Block as ProtoBlock, ProtoArrayForkChoice};
|
||||
use ssz_derive::{Decode, Encode};
|
||||
use std::marker::PhantomData;
|
||||
use types::{
|
||||
BeaconBlock, BeaconState, BeaconStateError, Epoch, EthSpec, Hash256, IndexedAttestation, Slot,
|
||||
};
|
||||
|
||||
use crate::ForkChoiceStore;
|
||||
use std::cmp::Ordering;
|
||||
|
||||
/// Defined here:
|
||||
///
|
||||
/// https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/specs/phase0/fork-choice.md#configuration
|
||||
@@ -301,21 +304,22 @@ where
|
||||
.get_block(&block_root)
|
||||
.ok_or_else(|| Error::MissingProtoArrayBlock(block_root))?;
|
||||
|
||||
if block.slot > ancestor_slot {
|
||||
Ok(self
|
||||
match block.slot.cmp(&ancestor_slot) {
|
||||
Ordering::Greater => Ok(self
|
||||
.proto_array
|
||||
.core_proto_array()
|
||||
.iter_block_roots(&block_root)
|
||||
// Search for a slot that is **less than or equal to** the target slot. We check
|
||||
// for lower slots to account for skip slots.
|
||||
.find(|(_, slot)| *slot <= ancestor_slot)
|
||||
.map(|(root, _)| root))
|
||||
} else if block.slot == ancestor_slot {
|
||||
Ok(Some(block_root))
|
||||
} else {
|
||||
// Root is older than queried slot, thus a skip slot. Return most recent root prior to
|
||||
// slot.
|
||||
Ok(Some(block_root))
|
||||
.map(|(root, _)| root)),
|
||||
Ordering::Less => Ok(Some(block_root)),
|
||||
Ordering::Equal =>
|
||||
// Root is older than queried slot, thus a skip slot. Return most recent root prior
|
||||
// to slot.
|
||||
{
|
||||
Ok(Some(block_root))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -331,17 +335,14 @@ where
|
||||
|
||||
let store = &mut self.fc_store;
|
||||
|
||||
let result = self
|
||||
.proto_array
|
||||
self.proto_array
|
||||
.find_head(
|
||||
store.justified_checkpoint().epoch,
|
||||
store.justified_checkpoint().root,
|
||||
store.finalized_checkpoint().epoch,
|
||||
store.justified_balances(),
|
||||
)
|
||||
.map_err(Into::into);
|
||||
|
||||
result
|
||||
.map_err(Into::into)
|
||||
}
|
||||
|
||||
/// Returns `true` if the given `store` should be updated to set
|
||||
@@ -496,17 +497,16 @@ where
|
||||
// information:
|
||||
//
|
||||
// https://github.com/ethereum/eth2.0-specs/pull/1880
|
||||
if *self.fc_store.justified_checkpoint() != state.current_justified_checkpoint {
|
||||
if state.current_justified_checkpoint.epoch
|
||||
if *self.fc_store.justified_checkpoint() != state.current_justified_checkpoint
|
||||
&& (state.current_justified_checkpoint.epoch
|
||||
> self.fc_store.justified_checkpoint().epoch
|
||||
|| self
|
||||
.get_ancestor(self.fc_store.justified_checkpoint().root, finalized_slot)?
|
||||
!= Some(self.fc_store.finalized_checkpoint().root)
|
||||
{
|
||||
self.fc_store
|
||||
.set_justified_checkpoint(state.current_justified_checkpoint)
|
||||
.map_err(Error::UnableToSetJustifiedCheckpoint)?;
|
||||
}
|
||||
!= Some(self.fc_store.finalized_checkpoint().root))
|
||||
{
|
||||
self.fc_store
|
||||
.set_justified_checkpoint(state.current_justified_checkpoint)
|
||||
.map_err(Error::UnableToSetJustifiedCheckpoint)?;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -557,13 +557,13 @@ where
|
||||
//
|
||||
// This is not in the specification, however it should be transparent to other nodes. We
|
||||
// return early here to avoid wasting precious resources verifying the rest of it.
|
||||
if indexed_attestation.attesting_indices.len() == 0 {
|
||||
if indexed_attestation.attesting_indices.is_empty() {
|
||||
return Err(InvalidAttestation::EmptyAggregationBitfield);
|
||||
}
|
||||
|
||||
let slot_now = self.fc_store.get_current_slot();
|
||||
let epoch_now = slot_now.epoch(E::slots_per_epoch());
|
||||
let target = indexed_attestation.data.target.clone();
|
||||
let target = indexed_attestation.data.target;
|
||||
|
||||
// Attestation must be from the current or previous epoch.
|
||||
if target.epoch > epoch_now {
|
||||
@@ -822,9 +822,10 @@ pub struct PersistedForkChoice {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use types::{EthSpec, MainnetEthSpec};
|
||||
|
||||
use super::*;
|
||||
|
||||
type E = MainnetEthSpec;
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user