Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion account_manager/src/wallet/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
}

pub fn cli_run(wallet_base_dir: PathBuf) -> Result<(), String> {
let mgr = WalletManager::open(&wallet_base_dir)
let mgr = WalletManager::open(wallet_base_dir)
.map_err(|e| format!("Unable to open --{}: {:?}", WALLETS_DIR_FLAG, e))?;

for (name, _uuid) in mgr
Expand Down
8 changes: 2 additions & 6 deletions beacon_node/beacon_chain/src/naive_aggregation_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ impl<T: AggregateMap> NaiveAggregationPool<T> {

/// Returns the total number of items stored in `self`.
pub fn num_items(&self) -> usize {
self.maps.iter().map(|(_, map)| map.len()).sum()
self.maps.values().map(T::len).sum()
}

/// Returns an aggregated `T::Value` with the given `T::Data`, if any.
Expand Down Expand Up @@ -448,11 +448,7 @@ impl<T: AggregateMap> NaiveAggregationPool<T> {
// If we have too many maps, remove the lowest amount to ensure we only have
// `SLOTS_RETAINED` left.
if self.maps.len() > SLOTS_RETAINED {
let mut slots = self
.maps
.iter()
.map(|(slot, _map)| *slot)
.collect::<Vec<_>>();
let mut slots = self.maps.keys().copied().collect::<Vec<_>>();
// Sort is generally pretty slow, however `SLOTS_RETAINED` is quite low so it should be
// negligible.
slots.sort_unstable();
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/beacon_chain/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1459,7 +1459,7 @@ where
let proposer_index = state.get_beacon_proposer_index(slot, &self.spec).unwrap();

let signed_block = block.sign(
&self.validator_keypairs[proposer_index as usize].sk,
&self.validator_keypairs[proposer_index].sk,
&state.fork(),
state.genesis_validators_root(),
&self.spec,
Expand Down
5 changes: 1 addition & 4 deletions beacon_node/beacon_chain/src/validator_monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,10 +631,7 @@ impl<T: EthSpec> ValidatorMonitor<T> {

// Return the `id`'s of all monitored validators.
pub fn get_all_monitored_validators(&self) -> Vec<String> {
self.validators
.iter()
.map(|(_, val)| val.id.clone())
.collect()
self.validators.values().map(|val| val.id.clone()).collect()
}

/// If `self.auto_register == true`, add the `validator_index` to `self.monitored_validators`.
Expand Down
6 changes: 3 additions & 3 deletions beacon_node/eth1/src/deposit_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ pub mod tests {
#[test]
fn test_finalization_boundaries() {
let n = 8;
let half = (n / 2) as usize;
let half = n / 2;

let mut deposit_cache = get_cache_with_deposits(n as u64);

Expand Down Expand Up @@ -828,9 +828,9 @@ pub mod tests {
// get_log(half+quarter) should return log with index `half+quarter`
assert_eq!(
q3_log_before_finalization.index,
(half + quarter) as u64,
half + quarter,
"log index should be {}",
(half + quarter),
half + quarter,
);

// get lower quarter of deposits with max deposit count
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/execution_layer/src/engine_api/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl From<jsonwebtoken::errors::Error> for Error {
/// Provides wrapper around `[u8; JWT_SECRET_LENGTH]` that implements `Zeroize`.
#[derive(Zeroize, Clone)]
#[zeroize(drop)]
pub struct JwtKey([u8; JWT_SECRET_LENGTH as usize]);
pub struct JwtKey([u8; JWT_SECRET_LENGTH]);

impl JwtKey {
/// Wrap given slice in `Self`. Returns an error if slice.len() != `JWT_SECRET_LENGTH`.
Expand Down
4 changes: 2 additions & 2 deletions beacon_node/http_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2840,7 +2840,7 @@ pub fn serve<T: BeaconChainTypes>(
let is_live =
chain.validator_seen_at_epoch(index as usize, request_data.epoch);
api_types::LivenessResponseData {
index: index as u64,
index,
epoch: request_data.epoch,
is_live,
}
Expand Down Expand Up @@ -2876,7 +2876,7 @@ pub fn serve<T: BeaconChainTypes>(
.and_then(
|sysinfo, app_start: std::time::Instant, data_dir, network_globals| {
blocking_json_task(move || {
let app_uptime = app_start.elapsed().as_secs() as u64;
let app_uptime = app_start.elapsed().as_secs();
Ok(api_types::GenericResponse::from(observe_system_health_bn(
sysinfo,
data_dir,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,7 @@ impl RealScore {

/// Add an f64 to the score abiding by the limits.
fn add(&mut self, score: f64) {
let mut new_score = self.lighthouse_score + score;
if new_score > MAX_SCORE {
new_score = MAX_SCORE;
}
if new_score < MIN_SCORE {
new_score = MIN_SCORE;
}

let new_score = (self.lighthouse_score + score).clamp(MIN_SCORE, MAX_SCORE);
self.set_lighthouse_score(new_score);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ fn handle_length(
// Note: length-prefix of > 10 bytes(uint64) would be a decoding error
match uvi_codec.decode(bytes).map_err(RPCError::from)? {
Some(length) => {
*len = Some(length as usize);
*len = Some(length);
Ok(Some(length))
}
None => Ok(None), // need more bytes to decode length
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,11 @@ impl<TSpec: EthSpec> PeerScoreSettings<TSpec> {

let modulo_smaller = max(
1,
smaller_committee_size / self.target_aggregators_per_committee as usize,
smaller_committee_size / self.target_aggregators_per_committee,
);
let modulo_larger = max(
1,
(smaller_committee_size + 1) / self.target_aggregators_per_committee as usize,
(smaller_committee_size + 1) / self.target_aggregators_per_committee,
);

Ok((
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/lighthouse_network/src/service/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ fn keypair_from_hex(hex_bytes: &str) -> error::Result<Keypair> {
hex_bytes.to_string()
};

hex::decode(&hex_bytes)
hex::decode(hex_bytes)
.map_err(|e| format!("Failed to parse p2p secret key bytes: {:?}", e).into())
.and_then(keypair_from_bytes)
}
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/operation_pool/src/attestation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl<'a, T: EthSpec> AttMaxCover<'a, T> {
let indices = get_attesting_indices::<T>(committee.committee, &fresh_validators).ok()?;
let fresh_validators_rewards: HashMap<u64, u64> = indices
.iter()
.map(|i| *i as u64)
.copied()
.flat_map(|validator_index| {
let reward = base::get_base_reward(
state,
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/store/src/chunked_vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ mod test {

fn needs_genesis_value_test_randao<F: Field<TestSpec>>(_: F) {
let spec = &TestSpec::default_spec();
let max = TestSpec::slots_per_epoch() as u64 * (F::Length::to_u64() - 1);
let max = TestSpec::slots_per_epoch() * (F::Length::to_u64() - 1);
for i in 0..max {
assert!(
F::slot_needs_genesis_value(Slot::new(i), spec),
Expand Down
2 changes: 1 addition & 1 deletion common/account_utils/src/validator_definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ impl ValidatorDefinitions {
.write(true)
.read(true)
.create_new(false)
.open(&config_path)
.open(config_path)
.map_err(Error::UnableToOpenFile)?;
serde_yaml::from_reader(file).map_err(Error::UnableToParseFile)
}
Expand Down
2 changes: 1 addition & 1 deletion common/validator_dir/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ impl<'a> Builder<'a> {
if path.exists() {
return Err(Error::DepositDataAlreadyExists(path));
} else {
let hex = format!("0x{}", hex::encode(&deposit_data));
let hex = format!("0x{}", hex::encode(deposit_data));
File::options()
.write(true)
.read(true)
Expand Down
6 changes: 3 additions & 3 deletions consensus/serde_utils/src/hex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ mod test {
#[test]
fn encoding() {
let bytes = vec![0, 255];
let hex = encode(&bytes);
let hex = encode(bytes);
assert_eq!(hex.as_str(), "0x00ff");

let bytes = vec![];
let hex = encode(&bytes);
let hex = encode(bytes);
assert_eq!(hex.as_str(), "0x");

let bytes = vec![1, 2, 3];
let hex = encode(&bytes);
let hex = encode(bytes);
assert_eq!(hex.as_str(), "0x010203");
}
}
2 changes: 1 addition & 1 deletion consensus/serde_utils/src/u64_hex_be.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl<'de> Visitor<'de> for QuantityVisitor {
} else if stripped.starts_with('0') {
Err(de::Error::custom("cannot have leading zero"))
} else if stripped.len() % 2 != 0 {
hex::decode(&format!("0{}", stripped))
hex::decode(format!("0{}", stripped))
.map_err(|e| de::Error::custom(format!("invalid hex ({:?})", e)))
} else {
hex::decode(stripped).map_err(|e| de::Error::custom(format!("invalid hex ({:?})", e)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ pub fn process_sync_aggregate<T: EthSpec>(
.zip(aggregate.sync_committee_bits.iter())
{
if participation_bit {
increase_balance(state, participant_index as usize, participant_reward)?;
increase_balance(state, participant_index, participant_reward)?;
increase_balance(state, proposer_index as usize, proposer_reward)?;
} else {
decrease_balance(state, participant_index as usize, participant_reward)?;
decrease_balance(state, participant_index, participant_reward)?;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub fn get_flag_index_deltas<T: EthSpec>(
let base_reward = get_base_reward(state, index, base_reward_per_increment, spec)?;
let mut delta = Delta::default();

if unslashed_participating_indices.contains(index as usize)? {
if unslashed_participating_indices.contains(index)? {
if !state.is_in_inactivity_leak(previous_epoch, spec) {
let reward_numerator = base_reward
.safe_mul(weight)?
Expand All @@ -89,8 +89,8 @@ pub fn get_flag_index_deltas<T: EthSpec>(
delta.penalize(base_reward.safe_mul(weight)?.safe_div(WEIGHT_DENOMINATOR)?)?;
}
deltas
.get_mut(index as usize)
.ok_or(Error::DeltaOutOfBounds(index as usize))?
.get_mut(index)
.ok_or(Error::DeltaOutOfBounds(index))?
.combine(delta)?;
}
Ok(())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ fn get_inclusion_delay_delta(
let max_attester_reward = base_reward.safe_sub(proposer_reward)?;
delta.reward(max_attester_reward.safe_div(inclusion_info.delay)?)?;

let proposer_index = inclusion_info.proposer_index as usize;
let proposer_index = inclusion_info.proposer_index;
Ok((delta, Some((proposer_index, proposer_delta))))
} else {
Ok((Delta::default(), None))
Expand Down
2 changes: 1 addition & 1 deletion consensus/types/src/beacon_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ impl<T: EthSpec> BeaconState<T> {
/// Spec v0.12.1
pub fn get_committee_count_at_slot(&self, slot: Slot) -> Result<u64, Error> {
let cache = self.committee_cache_at_slot(slot)?;
Ok(cache.committees_per_slot() as u64)
Ok(cache.committees_per_slot())
}

/// Compute the number of committees in an entire epoch.
Expand Down
2 changes: 1 addition & 1 deletion consensus/types/src/beacon_state/committee_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl CommitteeCache {
self.committees_per_slot as usize,
index as usize,
);
let committee = self.compute_committee(committee_index as usize)?;
let committee = self.compute_committee(committee_index)?;

Some(BeaconCommittee {
slot,
Expand Down
20 changes: 5 additions & 15 deletions consensus/types/src/beacon_state/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,12 +344,7 @@ mod committees {

let cache_epoch = cache_epoch.into_epoch(state_epoch);

execute_committee_consistency_test(
new_head_state,
cache_epoch,
validator_count as usize,
spec,
);
execute_committee_consistency_test(new_head_state, cache_epoch, validator_count, spec);
}

async fn committee_consistency_test_suite<T: EthSpec>(cached_epoch: RelativeEpoch) {
Expand All @@ -361,18 +356,13 @@ mod committees {
.mul(spec.target_committee_size)
.add(1);

committee_consistency_test::<T>(validator_count as usize, Epoch::new(0), cached_epoch)
.await;
committee_consistency_test::<T>(validator_count, Epoch::new(0), cached_epoch).await;

committee_consistency_test::<T>(
validator_count as usize,
T::genesis_epoch() + 4,
cached_epoch,
)
.await;
committee_consistency_test::<T>(validator_count, T::genesis_epoch() + 4, cached_epoch)
.await;

committee_consistency_test::<T>(
validator_count as usize,
validator_count,
T::genesis_epoch()
+ (T::slots_per_historical_root() as u64)
.mul(T::slots_per_epoch())
Expand Down
2 changes: 1 addition & 1 deletion consensus/types/src/preset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ mod test {
}

fn preset_from_file<T: DeserializeOwned>(preset_name: &str, filename: &str) -> T {
let f = File::open(&presets_base_path().join(preset_name).join(filename))
let f = File::open(presets_base_path().join(preset_name).join(filename))
.expect("preset file exists");
serde_yaml::from_reader(f).unwrap()
}
Expand Down
20 changes: 10 additions & 10 deletions slasher/tests/attester_slashings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ fn double_vote_multi_vals() {
fn double_vote_some_vals() {
let v1 = vec![0, 1, 2, 3, 4, 5, 6];
let v2 = vec![0, 2, 4, 6];
let att1 = indexed_att(&v1, 0, 1, 0);
let att2 = indexed_att(&v2, 0, 1, 1);
let att1 = indexed_att(v1, 0, 1, 0);
let att2 = indexed_att(v2, 0, 1, 1);
let slashings = hashset![att_slashing(&att1, &att2)];
let attestations = vec![att1, att2];
slasher_test_indiv(&attestations, &slashings, 1);
Expand All @@ -53,9 +53,9 @@ fn double_vote_some_vals_repeat() {
let v1 = vec![0, 1, 2, 3, 4, 5, 6];
let v2 = vec![0, 2, 4, 6];
let v3 = vec![1, 3, 5];
let att1 = indexed_att(&v1, 0, 1, 0);
let att2 = indexed_att(&v2, 0, 1, 1);
let att3 = indexed_att(&v3, 0, 1, 0);
let att1 = indexed_att(v1, 0, 1, 0);
let att2 = indexed_att(v2, 0, 1, 1);
let att3 = indexed_att(v3, 0, 1, 0);
let slashings = hashset![att_slashing(&att1, &att2)];
let attestations = vec![att1, att2, att3];
slasher_test_indiv(&attestations, &slashings, 1);
Expand All @@ -67,8 +67,8 @@ fn double_vote_some_vals_repeat() {
fn no_double_vote_same_target() {
let v1 = vec![0, 1, 2, 3, 4, 5, 6];
let v2 = vec![0, 1, 2, 3, 4, 5, 7, 8];
let att1 = indexed_att(&v1, 0, 1, 0);
let att2 = indexed_att(&v2, 0, 1, 0);
let att1 = indexed_att(v1, 0, 1, 0);
let att2 = indexed_att(v2, 0, 1, 0);
let attestations = vec![att1, att2];
slasher_test_indiv(&attestations, &hashset! {}, 1);
slasher_test_indiv(&attestations, &hashset! {}, 1000);
Expand All @@ -79,8 +79,8 @@ fn no_double_vote_same_target() {
fn no_double_vote_distinct_vals() {
let v1 = vec![0, 1, 2, 3];
let v2 = vec![4, 5, 6, 7];
let att1 = indexed_att(&v1, 0, 1, 0);
let att2 = indexed_att(&v2, 0, 1, 1);
let att1 = indexed_att(v1, 0, 1, 0);
let att2 = indexed_att(v2, 0, 1, 1);
let attestations = vec![att1, att2];
slasher_test_indiv(&attestations, &hashset! {}, 1);
slasher_test_indiv(&attestations, &hashset! {}, 1000);
Expand All @@ -89,7 +89,7 @@ fn no_double_vote_distinct_vals() {
#[test]
fn no_double_vote_repeated() {
let v = vec![0, 1, 2, 3, 4];
let att1 = indexed_att(&v, 0, 1, 0);
let att1 = indexed_att(v, 0, 1, 0);
let att2 = att1.clone();
let attestations = vec![att1, att2];
slasher_test_indiv(&attestations, &hashset! {}, 1);
Expand Down
2 changes: 1 addition & 1 deletion testing/execution_engine_integration/src/nethermind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl GenericExecutionEngine for NethermindEngine {
fn init_datadir() -> TempDir {
let datadir = TempDir::new().unwrap();
let genesis_json_path = datadir.path().join("genesis.json");
let mut file = File::create(&genesis_json_path).unwrap();
let mut file = File::create(genesis_json_path).unwrap();
let json = nethermind_genesis_json();
serde_json::to_writer(&mut file, &json).unwrap();
datadir
Expand Down
2 changes: 1 addition & 1 deletion testing/node_test_rig/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ impl<E: EthSpec> LocalExecutionNode<E> {
.tempdir()
.expect("should create temp directory for client datadir");
let jwt_file_path = datadir.path().join("jwt.hex");
if let Err(e) = std::fs::write(&jwt_file_path, config.jwt_key.hex_string()) {
if let Err(e) = std::fs::write(jwt_file_path, config.jwt_key.hex_string()) {
panic!("Failed to write jwt file {}", e);
}
Self {
Expand Down
Loading