From 683147035b00f4c915fd6e2d9a37a21b8ce52799 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Wed, 13 Feb 2019 10:28:57 +1100 Subject: [PATCH] Fix clippy lints in block and epoch processing --- eth2/state_processing/src/block_processable.rs | 11 +++++++---- eth2/state_processing/src/epoch_processable.rs | 4 ++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/eth2/state_processing/src/block_processable.rs b/eth2/state_processing/src/block_processable.rs index 5f9fe1f7f7..f043a723d6 100644 --- a/eth2/state_processing/src/block_processable.rs +++ b/eth2/state_processing/src/block_processable.rs @@ -4,8 +4,8 @@ use log::debug; use ssz::{ssz_encode, TreeHash}; use types::{ beacon_state::{AttestationValidationError, CommitteesError}, - AggregatePublicKey, Attestation, BeaconBlock, BeaconState, ChainSpec, Epoch, Exit, Fork, - Hash256, PendingAttestation, PublicKey, Signature, + AggregatePublicKey, Attestation, BeaconBlock, BeaconState, ChainSpec, Crosslink, Epoch, Exit, + Fork, Hash256, PendingAttestation, PublicKey, Signature, }; // TODO: define elsehwere. @@ -330,11 +330,14 @@ fn validate_attestation_signature_optional( .ok_or(AttestationValidationError::NoBlockRoot)?, AttestationValidationError::WrongJustifiedRoot ); + let potential_crosslink = Crosslink { + shard_block_root: attestation.data.shard_block_root, + epoch: attestation.data.slot.epoch(spec.epoch_length), + }; ensure!( (attestation.data.latest_crosslink == state.latest_crosslinks[attestation.data.shard as usize]) - | (attestation.data.latest_crosslink - == state.latest_crosslinks[attestation.data.shard as usize]), + | (attestation.data.latest_crosslink == potential_crosslink), AttestationValidationError::BadLatestCrosslinkRoot ); if verify_signature { diff --git a/eth2/state_processing/src/epoch_processable.rs b/eth2/state_processing/src/epoch_processable.rs index 4afa725ceb..aece61184d 100644 --- a/eth2/state_processing/src/epoch_processable.rs +++ b/eth2/state_processing/src/epoch_processable.rs @@ -52,6 +52,10 @@ pub trait EpochProcessable { } 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> { let current_epoch = self.current_epoch(spec); let previous_epoch = self.previous_epoch(spec);