mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-09 03:17:55 +00:00
Add various fixes to clippy lints
Thou shalt appease clippy
This commit is contained in:
@@ -57,7 +57,7 @@ fn get_chain_of_blocks<T: EthSpec, U: Store>(
|
||||
) -> Vec<(Hash256, BeaconBlock)> {
|
||||
let spec = T::default_spec();
|
||||
let mut blocks_and_roots: Vec<(Hash256, BeaconBlock)> = vec![];
|
||||
let mut unique_hashes = (0..).into_iter().map(|i| Hash256::from(i));
|
||||
let mut unique_hashes = (0..).map(Hash256::from);
|
||||
let mut random_block = BeaconBlock::random_for_test(&mut XorShiftRng::from_seed([42; 16]));
|
||||
random_block.previous_block_root = Hash256::zero();
|
||||
let beacon_state = get_state::<T>(validator_count);
|
||||
|
||||
@@ -49,7 +49,7 @@ fn verify_indexed_attestation_parametric<T: EthSpec>(
|
||||
);
|
||||
|
||||
// Check that nobody signed with custody bit 1 (to be removed in phase 1)
|
||||
if custody_bit_1_indices.len() > 0 {
|
||||
if !custody_bit_1_indices.is_empty() {
|
||||
invalid!(Invalid::CustodyBitfieldHasSetBits);
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ where
|
||||
state
|
||||
.validator_registry
|
||||
.get(validator_idx as usize)
|
||||
.ok_or(Error::Invalid(Invalid::UnknownValidator(validator_idx)))
|
||||
.ok_or_else(|| Error::Invalid(Invalid::UnknownValidator(validator_idx)))
|
||||
.map(|validator| {
|
||||
aggregate_pubkey.add(&validator.pubkey);
|
||||
aggregate_pubkey
|
||||
|
||||
@@ -156,7 +156,7 @@ pub fn process_crosslinks<T: EthSpec>(
|
||||
|
||||
state.previous_crosslinks = state.current_crosslinks.clone();
|
||||
|
||||
for relative_epoch in vec![RelativeEpoch::Previous, RelativeEpoch::Current] {
|
||||
for &relative_epoch in &[RelativeEpoch::Previous, RelativeEpoch::Current] {
|
||||
let epoch = relative_epoch.into_epoch(state.current_epoch());
|
||||
for offset in 0..state.get_epoch_committee_count(relative_epoch)? {
|
||||
let shard =
|
||||
|
||||
@@ -422,7 +422,7 @@ impl<T: EthSpec> BeaconState<T> {
|
||||
};
|
||||
let effective_balance = self.validator_registry[candidate_index].effective_balance;
|
||||
if (effective_balance * MAX_RANDOM_BYTE)
|
||||
>= (spec.max_effective_balance * random_byte as u64)
|
||||
>= (spec.max_effective_balance * u64::from(random_byte))
|
||||
{
|
||||
break candidate_index;
|
||||
}
|
||||
|
||||
@@ -162,7 +162,6 @@ impl CommitteeCache {
|
||||
let i = self.shuffled_position(validator_index)?;
|
||||
|
||||
(0..self.committee_count)
|
||||
.into_iter()
|
||||
.map(|nth_committee| (nth_committee, self.compute_committee_range(nth_committee)))
|
||||
.find(|(_, range)| {
|
||||
if let Some(range) = range {
|
||||
|
||||
@@ -174,7 +174,7 @@ impl ChainSpec {
|
||||
/*
|
||||
* Time parameters
|
||||
*/
|
||||
genesis_time: u32::max_value() as u64,
|
||||
genesis_time: u64::from(u32::max_value()),
|
||||
seconds_per_slot: 6,
|
||||
min_attestation_inclusion_delay: 4,
|
||||
min_seed_lookahead: Epoch::new(1),
|
||||
|
||||
@@ -77,7 +77,7 @@ impl Epoch {
|
||||
/// Position of some slot inside an epoch, if any.
|
||||
///
|
||||
/// E.g., the first `slot` in `epoch` is at position `0`.
|
||||
pub fn position(&self, slot: Slot, slots_per_epoch: u64) -> Option<usize> {
|
||||
pub fn position(self, slot: Slot, slots_per_epoch: u64) -> Option<usize> {
|
||||
let start = self.start_slot(slots_per_epoch);
|
||||
let end = self.end_slot(slots_per_epoch);
|
||||
|
||||
|
||||
@@ -271,7 +271,7 @@ fn build_proposer_slashing<T: EthSpec>(
|
||||
Signature::new(message, domain, secret_key)
|
||||
};
|
||||
|
||||
TestingProposerSlashingBuilder::double_vote::<T, _>(validator_index, signer, spec)
|
||||
TestingProposerSlashingBuilder::double_vote::<T, _>(validator_index, signer)
|
||||
}
|
||||
|
||||
/// Builds an `AttesterSlashing` for some `validator_indices`.
|
||||
|
||||
@@ -17,7 +17,7 @@ impl TestingProposerSlashingBuilder {
|
||||
/// - `domain: Domain`
|
||||
///
|
||||
/// Where domain is a domain "constant" (e.g., `spec.domain_attestation`).
|
||||
pub fn double_vote<T, F>(proposer_index: u64, signer: F, spec: &ChainSpec) -> ProposerSlashing
|
||||
pub fn double_vote<T, F>(proposer_index: u64, signer: F) -> ProposerSlashing
|
||||
where
|
||||
T: EthSpec,
|
||||
F: Fn(u64, &[u8], Epoch, Domain) -> Signature,
|
||||
|
||||
@@ -13,6 +13,7 @@ where
|
||||
u8::from_str_radix(&s.as_str()[2..], 16).map_err(D::Error::custom)
|
||||
}
|
||||
|
||||
#[allow(clippy::trivially_copy_pass_by_ref)] // Serde requires the `byte` to be a ref.
|
||||
pub fn u8_to_hex_str<S>(byte: &u8, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
|
||||
@@ -80,7 +80,7 @@ where
|
||||
)
|
||||
})?;
|
||||
file.write_all(toml_encoded.as_bytes())
|
||||
.expect(&format!("Unable to write to {:?}", path));
|
||||
.unwrap_or_else(|_| panic!("Unable to write to {:?}", path));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user