Fix clippy lints

This commit is contained in:
Paul Hauner 2019-03-20 10:51:53 +11:00
parent 8f23aefb29
commit 84f373fcc2
No known key found for this signature in database
GPG Key ID: D362883A9218FCC6
13 changed files with 38 additions and 51 deletions

View File

@ -82,7 +82,7 @@ where
let state_root = genesis_state.canonical_root();
state_store.put(&state_root, &ssz_encode(&genesis_state)[..])?;
let block_root = genesis_block.into_header().canonical_root();
let block_root = genesis_block.block_header().canonical_root();
block_store.put(&block_root, &ssz_encode(&genesis_block)[..])?;
let finalized_head = RwLock::new(CheckPoint::new(
@ -189,7 +189,7 @@ where
pub fn advance_state(&self, slot: Slot) -> Result<(), SlotProcessingError> {
let state_slot = self.state.read().slot;
let latest_block_header = self.head().beacon_block.into_header();
let latest_block_header = self.head().beacon_block.block_header();
for _ in state_slot.as_u64()..slot.as_u64() {
per_slot_processing(&mut *self.state.write(), &latest_block_header, &self.spec)?;
@ -561,7 +561,7 @@ where
pub fn process_block(&self, block: BeaconBlock) -> Result<BlockProcessingOutcome, Error> {
debug!("Processing block with slot {}...", block.slot);
let block_root = block.into_header().canonical_root();
let block_root = block.block_header().canonical_root();
let present_slot = self.present_slot();
@ -596,7 +596,7 @@ where
// Transition the parent state to the present slot.
let mut state = parent_state;
let previous_block_header = parent_block.into_header();
let previous_block_header = parent_block.block_header();
for _ in state.slot.as_u64()..present_slot.as_u64() {
if let Err(e) = per_slot_processing(&mut state, &previous_block_header, &self.spec) {
return Ok(BlockProcessingOutcome::InvalidBlock(

View File

@ -215,10 +215,8 @@ impl<T: ClientDB + Sized> ForkChoice for SlowLMDGhost<T> {
head_vote_count = vote_count;
}
// resolve ties - choose smaller hash
else if vote_count == head_vote_count {
if *child_hash < head_hash {
head_hash = *child_hash;
}
else if vote_count == head_vote_count && *child_hash < head_hash {
head_hash = *child_hash;
}
}
}

View File

@ -109,7 +109,7 @@ pub fn process_block_header(
Invalid::ParentBlockRootMismatch
);
state.latest_block_header = block.into_temporary_header(spec);
state.latest_block_header = block.temporary_block_header(spec);
Ok(())
}
@ -388,7 +388,7 @@ pub fn process_deposits(
// Create a new validator.
let validator = Validator {
pubkey: deposit_input.pubkey.clone(),
withdrawal_credentials: deposit_input.withdrawal_credentials.clone(),
withdrawal_credentials: deposit_input.withdrawal_credentials,
activation_epoch: spec.far_future_epoch,
exit_epoch: spec.far_future_epoch,
withdrawable_epoch: spec.far_future_epoch,

View File

@ -176,17 +176,7 @@ fn validate_attestation_signature_optional(
);
if verify_signature {
let attestation_epoch = attestation.data.slot.epoch(spec.slots_per_epoch);
verify_attestation_signature(
state,
committee,
attestation_epoch,
&attestation.aggregation_bitfield,
&attestation.custody_bitfield,
&attestation.data,
&attestation.aggregate_signature,
spec,
)?;
verify_attestation_signature(state, committee, attestation, spec)?;
}
// Crosslink data root is zero (to be removed in phase 1).
@ -210,32 +200,29 @@ fn validate_attestation_signature_optional(
fn verify_attestation_signature(
state: &BeaconState,
committee: &[usize],
attestation_epoch: Epoch,
aggregation_bitfield: &Bitfield,
custody_bitfield: &Bitfield,
attestation_data: &AttestationData,
aggregate_signature: &AggregateSignature,
a: &Attestation,
spec: &ChainSpec,
) -> Result<(), Error> {
let mut aggregate_pubs = vec![AggregatePublicKey::new(); 2];
let mut message_exists = vec![false; 2];
let attestation_epoch = a.data.slot.epoch(spec.slots_per_epoch);
for (i, v) in committee.iter().enumerate() {
let validator_signed = aggregation_bitfield.get(i).map_err(|_| {
let validator_signed = a.aggregation_bitfield.get(i).map_err(|_| {
Error::Invalid(Invalid::BadAggregationBitfieldLength {
committee_len: committee.len(),
bitfield_len: aggregation_bitfield.len(),
bitfield_len: a.aggregation_bitfield.len(),
})
})?;
if validator_signed {
let custody_bit: bool = match custody_bitfield.get(i) {
let custody_bit: bool = match a.custody_bitfield.get(i) {
Ok(bit) => bit,
// Invalidate signature if custody_bitfield.len() < committee
Err(_) => {
return Err(Error::Invalid(Invalid::BadCustodyBitfieldLength {
committee_len: committee.len(),
bitfield_len: aggregation_bitfield.len(),
bitfield_len: a.aggregation_bitfield.len(),
}));
}
};
@ -254,14 +241,14 @@ fn verify_attestation_signature(
// Message when custody bitfield is `false`
let message_0 = AttestationDataAndCustodyBit {
data: attestation_data.clone(),
data: a.data.clone(),
custody_bit: false,
}
.hash_tree_root();
// Message when custody bitfield is `true`
let message_1 = AttestationDataAndCustodyBit {
data: attestation_data.clone(),
data: a.data.clone(),
custody_bit: true,
}
.hash_tree_root();
@ -283,7 +270,8 @@ fn verify_attestation_signature(
let domain = spec.get_domain(attestation_epoch, Domain::Attestation, &state.fork);
verify!(
aggregate_signature.verify_multiple(&messages[..], domain, &keys[..]),
a.aggregate_signature
.verify_multiple(&messages[..], domain, &keys[..]),
Invalid::BadSignature
);

View File

@ -71,9 +71,7 @@ pub fn get_existing_validator_index(
) -> Result<Option<u64>, Error> {
let deposit_input = &deposit.deposit_data.deposit_input;
let validator_index = state
.get_validator_index(&deposit_input.pubkey)?
.and_then(|i| Some(i));
let validator_index = state.get_validator_index(&deposit_input.pubkey)?;
match validator_index {
None => Ok(None),

View File

@ -28,7 +28,7 @@ pub fn get_attestation_participants(
let mut participants = Vec::with_capacity(committee.len());
for (i, validator_index) in committee.iter().enumerate() {
match bitfield.get(i) {
Ok(bit) if bit == true => participants.push(*validator_index),
Ok(bit) if bit => participants.push(*validator_index),
_ => {}
}
}

View File

@ -64,7 +64,6 @@ pub fn should_update_validator_registry(
let current_epoch_committee_count = spec.get_epoch_committee_count(num_active_validators);
for shard in (0..current_epoch_committee_count)
.into_iter()
.map(|i| (state.current_shuffling_start_shard + i as u64) % spec.shard_count)
{
if state.latest_crosslinks[shard as usize].epoch <= state.validator_registry_update_epoch {

View File

@ -71,7 +71,7 @@ impl BeaconBlock {
/// Note: performs a full tree-hash of `self.body`.
///
/// Spec v0.5.0
pub fn into_header(&self) -> BeaconBlockHeader {
pub fn block_header(&self) -> BeaconBlockHeader {
BeaconBlockHeader {
slot: self.slot,
previous_block_root: self.previous_block_root,
@ -84,11 +84,11 @@ impl BeaconBlock {
/// Returns a "temporary" header, where the `state_root` is `spec.zero_hash`.
///
/// Spec v0.5.0
pub fn into_temporary_header(&self, spec: &ChainSpec) -> BeaconBlockHeader {
pub fn temporary_block_header(&self, spec: &ChainSpec) -> BeaconBlockHeader {
BeaconBlockHeader {
state_root: spec.zero_hash,
signature: spec.empty_signature.clone(),
..self.into_header()
..self.block_header()
}
}
}

View File

@ -162,7 +162,7 @@ impl BeaconState {
latest_state_roots: vec![spec.zero_hash; spec.slots_per_historical_root],
latest_active_index_roots: vec![spec.zero_hash; spec.latest_active_index_roots_length],
latest_slashed_balances: vec![0; spec.latest_slashed_exit_length],
latest_block_header: BeaconBlock::empty(spec).into_temporary_header(spec),
latest_block_header: BeaconBlock::empty(spec).temporary_block_header(spec),
historical_roots: vec![],
/*
@ -386,7 +386,8 @@ impl BeaconState {
spec: &ChainSpec,
) -> Result<(), BeaconStateError> {
let i = self.get_latest_block_roots_index(slot, spec)?;
Ok(self.latest_block_roots[i] = block_root)
self.latest_block_roots[i] = block_root;
Ok(())
}
/// Safely obtains the index for `latest_randao_mixes`
@ -449,7 +450,8 @@ impl BeaconState {
spec: &ChainSpec,
) -> Result<(), Error> {
let i = self.get_randao_mix_index(epoch, spec)?;
Ok(self.latest_randao_mixes[i] = mix)
self.latest_randao_mixes[i] = mix;
Ok(())
}
/// Safely obtains the index for `latest_active_index_roots`, given some `epoch`.
@ -492,7 +494,8 @@ impl BeaconState {
spec: &ChainSpec,
) -> Result<(), Error> {
let i = self.get_active_index_root_index(epoch, spec)?;
Ok(self.latest_active_index_roots[i] = index_root)
self.latest_active_index_roots[i] = index_root;
Ok(())
}
/// Replace `active_index_roots` with clones of `index_root`.
@ -537,7 +540,8 @@ impl BeaconState {
spec: &ChainSpec,
) -> Result<(), Error> {
let i = self.get_latest_state_roots_index(slot, spec)?;
Ok(self.latest_state_roots[i] = state_root)
self.latest_state_roots[i] = state_root;
Ok(())
}
/// Safely obtains the index for `latest_slashed_balances`, given some `epoch`.
@ -573,7 +577,8 @@ impl BeaconState {
spec: &ChainSpec,
) -> Result<(), Error> {
let i = self.get_slashed_balance_index(epoch, spec)?;
Ok(self.latest_slashed_balances[i] = balance)
self.latest_slashed_balances[i] = balance;
Ok(())
}
/// Generate a seed for the given `epoch`.

View File

@ -304,7 +304,6 @@ impl EpochCrosslinkCommitteesBuilder {
for (i, slot) in self.epoch.slot_iter(spec.slots_per_epoch).enumerate() {
for j in (0..committees.len())
.into_iter()
.skip(i * committees_per_slot)
.take(committees_per_slot)
{

View File

@ -33,7 +33,7 @@ impl RelativeEpoch {
/// Returns the `epoch` that `self` refers to, with respect to the `base` epoch.
///
/// Spec v0.5.0
pub fn into_epoch(&self, base: Epoch) -> Epoch {
pub fn into_epoch(self, base: Epoch) -> Epoch {
match self {
RelativeEpoch::Previous => base - 1,
RelativeEpoch::Current => base,

View File

@ -214,7 +214,7 @@ impl TestingBeaconStateBuilder {
- spec.min_attestation_inclusion_delay;
let last_slot = std::cmp::min(state.slot.as_u64(), last_slot);
for slot in first_slot..last_slot + 1 {
for slot in first_slot..=last_slot {
let slot = Slot::from(slot);
let committees = state

View File

@ -47,7 +47,7 @@ impl TestingDepositBuilder {
self.deposit
.deposit_data
.deposit_input
.withdrawal_credentials = withdrawal_credentials.clone();
.withdrawal_credentials = withdrawal_credentials;
self.deposit.deposit_data.deposit_input.proof_of_possession = self
.deposit