Fix clippy lints in block and epoch processing

This commit is contained in:
Paul Hauner 2019-02-13 10:28:57 +11:00
parent d2a1000520
commit 683147035b
No known key found for this signature in database
GPG Key ID: D362883A9218FCC6
2 changed files with 11 additions and 4 deletions

View File

@ -4,8 +4,8 @@ use log::debug;
use ssz::{ssz_encode, TreeHash}; use ssz::{ssz_encode, TreeHash};
use types::{ use types::{
beacon_state::{AttestationValidationError, CommitteesError}, beacon_state::{AttestationValidationError, CommitteesError},
AggregatePublicKey, Attestation, BeaconBlock, BeaconState, ChainSpec, Epoch, Exit, Fork, AggregatePublicKey, Attestation, BeaconBlock, BeaconState, ChainSpec, Crosslink, Epoch, Exit,
Hash256, PendingAttestation, PublicKey, Signature, Fork, Hash256, PendingAttestation, PublicKey, Signature,
}; };
// TODO: define elsehwere. // TODO: define elsehwere.
@ -330,11 +330,14 @@ fn validate_attestation_signature_optional(
.ok_or(AttestationValidationError::NoBlockRoot)?, .ok_or(AttestationValidationError::NoBlockRoot)?,
AttestationValidationError::WrongJustifiedRoot AttestationValidationError::WrongJustifiedRoot
); );
let potential_crosslink = Crosslink {
shard_block_root: attestation.data.shard_block_root,
epoch: attestation.data.slot.epoch(spec.epoch_length),
};
ensure!( ensure!(
(attestation.data.latest_crosslink (attestation.data.latest_crosslink
== state.latest_crosslinks[attestation.data.shard as usize]) == state.latest_crosslinks[attestation.data.shard as usize])
| (attestation.data.latest_crosslink | (attestation.data.latest_crosslink == potential_crosslink),
== state.latest_crosslinks[attestation.data.shard as usize]),
AttestationValidationError::BadLatestCrosslinkRoot AttestationValidationError::BadLatestCrosslinkRoot
); );
if verify_signature { if verify_signature {

View File

@ -52,6 +52,10 @@ pub trait EpochProcessable {
} }
impl EpochProcessable for BeaconState { impl EpochProcessable for BeaconState {
// Cyclomatic complexity is ignored. It would be ideal to split this function apart, however it
// remains monolithic to allow for easier spec updates. Once the spec is more stable we can
// optimise.
#[allow(clippy::cyclomatic_complexity)]
fn per_epoch_processing(&mut self, spec: &ChainSpec) -> Result<(), Error> { fn per_epoch_processing(&mut self, spec: &ChainSpec) -> Result<(), Error> {
let current_epoch = self.current_epoch(spec); let current_epoch = self.current_epoch(spec);
let previous_epoch = self.previous_epoch(spec); let previous_epoch = self.previous_epoch(spec);