Fix clippy lints

This commit is contained in:
Paul Hauner
2019-03-20 10:51:53 +11:00
parent 8f23aefb29
commit 84f373fcc2
13 changed files with 38 additions and 51 deletions

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 {