mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-22 06:14:38 +00:00
Address clippy lints, panic in ssz_derive on overflow (#1714)
## Issue Addressed NA ## Proposed Changes - Panic or return error if we overflow `usize` in SSZ decoding/encoding derive macros. - I claim that the panics can only be triggered by a faulty type definition in lighthouse, they cannot be triggered externally on a validly defined struct. - Use `Ordering` instead of some `if` statements, as demanded by clippy. - Remove some old clippy `allow` that seem to no longer be required. - Add comments to interesting clippy statements that we're going to continue to ignore. - Create #1713 ## Additional Info NA
This commit is contained in:
@@ -23,11 +23,13 @@ impl PubkeyCache {
|
||||
///
|
||||
/// The added index must equal the number of validators already added to the map. This ensures
|
||||
/// that an index is never skipped.
|
||||
#[allow(clippy::integer_arithmetic)]
|
||||
pub fn insert(&mut self, pubkey: PublicKeyBytes, index: ValidatorIndex) -> bool {
|
||||
if index == self.len {
|
||||
self.map.insert(pubkey, index);
|
||||
self.len += 1;
|
||||
self.len = self
|
||||
.len
|
||||
.checked_add(1)
|
||||
.expect("map length cannot exceed usize");
|
||||
true
|
||||
} else {
|
||||
false
|
||||
|
||||
@@ -587,9 +587,13 @@ impl Default for YamlConfig {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::integer_arithmetic)] // Arith cannot overflow or panic.
|
||||
fn milliseconds_to_seconds(millis: u64) -> u64 {
|
||||
millis / 1000
|
||||
}
|
||||
|
||||
/// Spec v0.12.1
|
||||
impl YamlConfig {
|
||||
#[allow(clippy::integer_arithmetic)]
|
||||
pub fn from_spec<T: EthSpec>(spec: &ChainSpec) -> Self {
|
||||
Self {
|
||||
config_name: T::spec_name().to_string(),
|
||||
@@ -611,7 +615,7 @@ impl YamlConfig {
|
||||
hysteresis_upward_multiplier: spec.hysteresis_upward_multiplier,
|
||||
proportional_slashing_multiplier: spec.proportional_slashing_multiplier,
|
||||
bls_withdrawal_prefix: spec.bls_withdrawal_prefix_byte,
|
||||
seconds_per_slot: spec.milliseconds_per_slot / 1000,
|
||||
seconds_per_slot: milliseconds_to_seconds(spec.milliseconds_per_slot),
|
||||
min_attestation_inclusion_delay: spec.min_attestation_inclusion_delay,
|
||||
min_seed_lookahead: spec.min_seed_lookahead.into(),
|
||||
max_seed_lookahead: spec.max_seed_lookahead.into(),
|
||||
|
||||
@@ -18,7 +18,7 @@ pub struct Graffiti(#[serde(with = "serde_graffiti")] pub [u8; GRAFFITI_BYTES_LE
|
||||
|
||||
impl Graffiti {
|
||||
pub fn as_utf8_lossy(&self) -> String {
|
||||
#[allow(clippy::invalid_regex)]
|
||||
#[allow(clippy::invalid_regex)] // This is a false positive, this regex is valid.
|
||||
let re = Regex::new("\\p{C}").expect("graffiti regex is valid");
|
||||
String::from_utf8_lossy(&re.replace_all(&self.0[..], &b""[..])).to_string()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user