Rust 1.54.0 lints (#2483)

## Issue Addressed

N/A

## Proposed Changes

- Removing a bunch of unnecessary references
- Updated `Error::VariantError` to `Error::Variant`
- There were additional enum variant lints that I ignored, because I thought our variant names were fine
- removed `MonitoredValidator`'s `pubkey` field, because I couldn't find it used anywhere. It looks like we just use the string version of the pubkey (the `id` field) if there is no index

## Additional Info



Co-authored-by: realbigsean <seananderson33@gmail.com>
This commit is contained in:
realbigsean
2021-07-30 01:11:47 +00:00
parent 8efd9fc324
commit 303deb9969
104 changed files with 307 additions and 313 deletions
@@ -448,7 +448,7 @@ impl<T: BeaconChainTypes> VerifiedAggregatedAttestation<T> {
//
// Attestations must be for a known block. If the block is unknown, we simply drop the
// attestation and do not delay consideration for later.
let head_block = verify_head_block_is_known(chain, &attestation, None)?;
let head_block = verify_head_block_is_known(chain, attestation, None)?;
// Check the attestation target root is consistent with the head root.
//
@@ -457,7 +457,7 @@ impl<T: BeaconChainTypes> VerifiedAggregatedAttestation<T> {
//
// Whilst this attestation *technically* could be used to add value to a block, it is
// invalid in the spirit of the protocol. Here we choose safety over profit.
verify_attestation_target_root::<T::EthSpec>(&head_block, &attestation)?;
verify_attestation_target_root::<T::EthSpec>(&head_block, attestation)?;
// Ensure that the attestation has participants.
if attestation.aggregation_bits.is_zero() {
@@ -628,7 +628,7 @@ impl<T: BeaconChainTypes> VerifiedUnaggregatedAttestation<T> {
// MAXIMUM_GOSSIP_CLOCK_DISPARITY allowance).
//
// We do not queue future attestations for later processing.
verify_propagation_slot_range(chain, &attestation)?;
verify_propagation_slot_range(chain, attestation)?;
// Check to ensure that the attestation is "unaggregated". I.e., it has exactly one
// aggregation bit set.
@@ -642,10 +642,10 @@ impl<T: BeaconChainTypes> VerifiedUnaggregatedAttestation<T> {
//
// Enforce a maximum skip distance for unaggregated attestations.
let head_block =
verify_head_block_is_known(chain, &attestation, chain.config.import_max_skip_slots)?;
verify_head_block_is_known(chain, attestation, chain.config.import_max_skip_slots)?;
// Check the attestation target root is consistent with the head root.
verify_attestation_target_root::<T::EthSpec>(&head_block, &attestation)?;
verify_attestation_target_root::<T::EthSpec>(&head_block, attestation)?;
Ok(())
}
@@ -927,7 +927,7 @@ pub fn verify_attestation_signature<T: BeaconChainTypes>(
let signature_set = indexed_attestation_signature_set_from_pubkeys(
|validator_index| pubkey_cache.get(validator_index).map(Cow::Borrowed),
&indexed_attestation.signature,
&indexed_attestation,
indexed_attestation,
&fork,
chain.genesis_validators_root,
&chain.spec,
@@ -1031,7 +1031,7 @@ pub fn verify_signed_aggregate_signatures<T: BeaconChainTypes>(
let signature_sets = vec![
signed_aggregate_selection_proof_signature_set(
|validator_index| pubkey_cache.get(validator_index).map(Cow::Borrowed),
&signed_aggregate,
signed_aggregate,
&fork,
chain.genesis_validators_root,
&chain.spec,
@@ -1039,7 +1039,7 @@ pub fn verify_signed_aggregate_signatures<T: BeaconChainTypes>(
.map_err(BeaconChainError::SignatureSetError)?,
signed_aggregate_signature_set(
|validator_index| pubkey_cache.get(validator_index).map(Cow::Borrowed),
&signed_aggregate,
signed_aggregate,
&fork,
chain.genesis_validators_root,
&chain.spec,
@@ -1048,7 +1048,7 @@ pub fn verify_signed_aggregate_signatures<T: BeaconChainTypes>(
indexed_attestation_signature_set_from_pubkeys(
|validator_index| pubkey_cache.get(validator_index).map(Cow::Borrowed),
&indexed_attestation.signature,
&indexed_attestation,
indexed_attestation,
&fork,
chain.genesis_validators_root,
&chain.spec,
@@ -1069,7 +1069,7 @@ fn obtain_indexed_attestation_and_committees_per_slot<T: BeaconChainTypes>(
attestation: &Attestation<T::EthSpec>,
) -> Result<(IndexedAttestation<T::EthSpec>, CommitteesPerSlot), Error> {
map_attestation_committee(chain, attestation, |(committee, committees_per_slot)| {
get_indexed_attestation(committee.committee, &attestation)
get_indexed_attestation(committee.committee, attestation)
.map(|attestation| (attestation, committees_per_slot))
.map_err(Error::Invalid)
})
+5 -6
View File
@@ -1372,7 +1372,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
attester_cache_key,
request_slot,
request_index,
&self,
self,
)?
};
drop(cache_timer);
@@ -1729,7 +1729,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
self.shuffling_is_compatible(
&att.data.beacon_block_root,
att.data.target.epoch,
&state,
state,
)
})
}
@@ -2182,9 +2182,8 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
for attestation in signed_block.message().body().attestations() {
let committee =
state.get_beacon_committee(attestation.data.slot, attestation.data.index)?;
let indexed_attestation =
get_indexed_attestation(&committee.committee, attestation)
.map_err(|e| BlockError::BeaconChainError(e.into()))?;
let indexed_attestation = get_indexed_attestation(committee.committee, attestation)
.map_err(|e| BlockError::BeaconChainError(e.into()))?;
slasher.accept_attestation(indexed_attestation);
}
}
@@ -3267,7 +3266,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
metrics::stop_timer(committee_building_timer);
map_fn(&committee_cache, shuffling_decision_block)
map_fn(committee_cache, shuffling_decision_block)
}
}
@@ -278,6 +278,7 @@ impl<T: EthSpec> From<DBError> for BlockError<T> {
}
/// Information about invalid blocks which might still be slashable despite being invalid.
#[allow(clippy::enum_variant_names)]
pub enum BlockSlashInfo<TErr> {
/// The block is invalid, but its proposer signature wasn't checked.
SignatureNotChecked(SignedBeaconBlockHeader, TErr),
@@ -837,7 +838,7 @@ impl<T: BeaconChainTypes> IntoFullyVerifiedBlock<T> for SignedBeaconBlock<T::Eth
}
fn block(&self) -> &SignedBeaconBlock<T::EthSpec> {
&self
self
}
}
@@ -996,7 +997,7 @@ impl<'a, T: BeaconChainTypes> FullyVerifiedBlock<'a, T> {
for (i, summary) in summaries.iter().enumerate() {
let epoch = state.current_epoch() - Epoch::from(summaries.len() - i);
if let Err(e) =
validator_monitor.process_validator_statuses(epoch, &summary, &chain.spec)
validator_monitor.process_validator_statuses(epoch, summary, &chain.spec)
{
error!(
chain.log,
@@ -1204,7 +1205,7 @@ pub fn check_block_relevancy<T: BeaconChainTypes>(
// Do not process a block from a finalized slot.
check_block_against_finalized_slot(block, chain)?;
let block_root = block_root.unwrap_or_else(|| get_block_root(&signed_block));
let block_root = block_root.unwrap_or_else(|| get_block_root(signed_block));
// Check if the block is already known. We know it is post-finalization, so it is
// sufficient to check the fork choice.
+1 -1
View File
@@ -666,7 +666,7 @@ fn genesis_block<T: EthSpec>(
genesis_state: &mut BeaconState<T>,
spec: &ChainSpec,
) -> Result<SignedBeaconBlock<T>, String> {
let mut genesis_block = BeaconBlock::empty(&spec);
let mut genesis_block = BeaconBlock::empty(spec);
*genesis_block.state_root_mut() = genesis_state
.update_tree_hash_cache()
.map_err(|e| format!("Error hashing genesis state: {:?}", e))?;
+8 -8
View File
@@ -762,7 +762,7 @@ mod test {
"test should not use dummy backend"
);
let mut state: BeaconState<E> = BeaconState::new(0, get_eth1_data(0), &spec);
let mut state: BeaconState<E> = BeaconState::new(0, get_eth1_data(0), spec);
*state.eth1_deposit_index_mut() = 0;
state.eth1_data_mut().deposit_count = 0;
@@ -815,7 +815,7 @@ mod test {
"cache should store all logs"
);
let mut state: BeaconState<E> = BeaconState::new(0, get_eth1_data(0), &spec);
let mut state: BeaconState<E> = BeaconState::new(0, get_eth1_data(0), spec);
*state.eth1_deposit_index_mut() = 0;
state.eth1_data_mut().deposit_count = 0;
@@ -877,10 +877,10 @@ mod test {
"test should not use dummy backend"
);
let state: BeaconState<E> = BeaconState::new(0, get_eth1_data(0), &spec);
let state: BeaconState<E> = BeaconState::new(0, get_eth1_data(0), spec);
let a = eth1_chain
.eth1_data_for_block_production(&state, &spec)
.eth1_data_for_block_production(&state, spec)
.expect("should produce default eth1 data vote");
assert_eq!(
a,
@@ -902,11 +902,11 @@ mod test {
"test should not use dummy backend"
);
let mut state: BeaconState<E> = BeaconState::new(0, get_eth1_data(0), &spec);
let mut state: BeaconState<E> = BeaconState::new(0, get_eth1_data(0), spec);
*state.slot_mut() = Slot::from(slots_per_eth1_voting_period * 10);
let follow_distance_seconds = eth1_follow_distance * spec.seconds_per_eth1_block;
let voting_period_start = get_voting_period_start_seconds(&state, &spec);
let voting_period_start = get_voting_period_start_seconds(&state, spec);
let start_eth1_block = voting_period_start - follow_distance_seconds * 2;
let end_eth1_block = voting_period_start - follow_distance_seconds;
@@ -926,7 +926,7 @@ mod test {
});
let vote = eth1_chain
.eth1_data_for_block_production(&state, &spec)
.eth1_data_for_block_production(&state, spec)
.expect("should produce default eth1 data vote");
assert_eq!(
@@ -956,7 +956,7 @@ mod test {
get_votes_to_consider(
blocks.iter(),
get_voting_period_start_seconds(&state, spec),
&spec,
spec,
),
HashMap::new()
);
@@ -574,7 +574,7 @@ mod tests {
}
fn key_from_sync_contribution(a: &SyncCommitteeContribution<E>) -> SyncContributionData {
SyncContributionData::from_contribution(&a)
SyncContributionData::from_contribution(a)
}
macro_rules! test_suite {
@@ -573,7 +573,7 @@ pub fn verify_signed_aggregate_signatures<T: BeaconChainTypes>(
let signature_sets = vec![
signed_sync_aggregate_selection_proof_signature_set(
|validator_index| pubkey_cache.get(validator_index).map(Cow::Borrowed),
&signed_aggregate,
signed_aggregate,
&fork,
chain.genesis_validators_root,
&chain.spec,
@@ -581,7 +581,7 @@ pub fn verify_signed_aggregate_signatures<T: BeaconChainTypes>(
.map_err(BeaconChainError::SignatureSetError)?,
signed_sync_aggregate_signature_set(
|validator_index| pubkey_cache.get(validator_index).map(Cow::Borrowed),
&signed_aggregate,
signed_aggregate,
&fork,
chain.genesis_validators_root,
&chain.spec,
+6 -6
View File
@@ -698,8 +698,8 @@ where
slot: Slot,
) -> HarnessAttestations<E> {
let unaggregated_attestations = self.make_unaggregated_attestations(
&attesting_validators,
&state,
attesting_validators,
state,
state_root,
block_hash,
slot,
@@ -785,7 +785,7 @@ where
relative_sync_committee: RelativeSyncCommittee,
) -> HarnessSyncContributions<E> {
let sync_messages =
self.make_sync_committee_messages(&state, block_hash, slot, relative_sync_committee);
self.make_sync_committee_messages(state, block_hash, slot, relative_sync_committee);
let sync_contributions: Vec<Option<SignedContributionAndProof<E>>> = sync_messages
.iter()
@@ -825,7 +825,7 @@ where
})?;
let default = SyncCommitteeContribution::from_message(
&sync_message,
sync_message,
subnet_id as u64,
*subcommittee_position,
)
@@ -989,7 +989,7 @@ where
let mut signed_block_headers = vec![block_header_1, block_header_2]
.into_iter()
.map(|block_header| {
block_header.sign::<E>(&sk, &fork, genesis_validators_root, &self.chain.spec)
block_header.sign::<E>(sk, &fork, genesis_validators_root, &self.chain.spec)
})
.collect::<Vec<_>>();
@@ -1199,7 +1199,7 @@ where
validators: &[usize],
) {
let attestations =
self.make_attestations(validators, &state, state_root, block_hash, block.slot());
self.make_attestations(validators, state, state_root, block_hash, block.slot());
self.process_attestations(attestations);
}
@@ -126,8 +126,6 @@ type SummaryMap = HashMap<Epoch, EpochSummary>;
struct MonitoredValidator {
/// A human-readable identifier for the validator.
pub id: String,
/// The validator voting pubkey.
pub pubkey: PublicKeyBytes,
/// The validator index in the state.
pub index: Option<u64>,
/// A history of the validator over time.
@@ -140,7 +138,6 @@ impl MonitoredValidator {
id: index
.map(|i| i.to_string())
.unwrap_or_else(|| pubkey.to_string()),
pubkey,
index,
summaries: <_>::default(),
}
+6 -6
View File
@@ -12,7 +12,7 @@ pub enum Error {
/// Logs have to be added with monotonically-increasing block numbers.
NonConsecutive { log_index: u64, expected: usize },
/// The eth1 event log data was unable to be parsed.
LogParseError(String),
LogParse(String),
/// There are insufficient deposits in the cache to fulfil the request.
InsufficientDeposits {
known_deposits: usize,
@@ -26,9 +26,9 @@ pub enum Error {
/// E.g., you cannot request deposit 10 when the deposit count is 9.
DepositCountInvalid { deposit_count: u64, range_end: u64 },
/// Error with the merkle tree for deposits.
DepositTreeError(merkle_proof::MerkleTreeError),
DepositTree(merkle_proof::MerkleTreeError),
/// An unexpected condition was encountered.
InternalError(String),
Internal(String),
}
#[derive(Encode, Decode, Clone)]
@@ -160,7 +160,7 @@ impl DepositCache {
self.logs.push(log);
self.deposit_tree
.push_leaf(deposit)
.map_err(Error::DepositTreeError)?;
.map_err(Error::DepositTree)?;
self.deposit_roots.push(self.deposit_tree.root());
Ok(DepositCacheInsertOutcome::Inserted)
}
@@ -219,7 +219,7 @@ impl DepositCache {
let leaves = self
.leaves
.get(0..deposit_count as usize)
.ok_or_else(|| Error::InternalError("Unable to get known leaves".into()))?;
.ok_or_else(|| Error::Internal("Unable to get known leaves".into()))?;
// Note: there is likely a more optimal solution than recreating the `DepositDataTree`
// each time this function is called.
@@ -233,7 +233,7 @@ impl DepositCache {
let deposits = self
.logs
.get(start as usize..end as usize)
.ok_or_else(|| Error::InternalError("Unable to get known log".into()))?
.ok_or_else(|| Error::Internal("Unable to get known log".into()))?
.iter()
.map(|deposit_log| {
let (_leaf, proof) = tree.generate_proof(deposit_log.index as usize);
+2 -2
View File
@@ -378,7 +378,7 @@ pub async fn get_deposit_logs_in_range(
.ok_or("Data was not string")?;
Ok(Log {
block_number: hex_to_u64_be(&block_number)?,
block_number: hex_to_u64_be(block_number)?,
data: hex_to_bytes(data)?,
})
})
@@ -446,7 +446,7 @@ pub async fn send_rpc_request(
/// Accepts an entire HTTP body (as a string) and returns either the `result` field or the `error['message']` field, as a serde `Value`.
fn response_result_or_error(response: &str) -> Result<Value, RpcError> {
let json = serde_json::from_str::<Value>(&response)
let json = serde_json::from_str::<Value>(response)
.map_err(|e| RpcError::InvalidJson(e.to_string()))?;
if let Some(error) = json.get("error").map(|e| e.get("message")).flatten() {
+1 -1
View File
@@ -48,7 +48,7 @@ impl Inner {
/// Encode the eth1 block and deposit cache as bytes.
pub fn as_bytes(&self) -> Vec<u8> {
let ssz_eth1_cache = SszEth1Cache::from_inner(&self);
let ssz_eth1_cache = SszEth1Cache::from_inner(self);
ssz_eth1_cache.as_ssz_bytes()
}
+5 -5
View File
@@ -705,7 +705,7 @@ impl Service {
}
}
}
endpoints.fallback.map_format_error(|s| &s.endpoint, &e)
endpoints.fallback.map_format_error(|s| &s.endpoint, e)
};
let process_err = |e: Error| match &e {
@@ -716,7 +716,7 @@ impl Service {
let (remote_head_block, new_block_numbers_deposit, new_block_numbers_block_cache) =
endpoints
.first_success(|e| async move {
get_remote_head_and_new_block_ranges(e, &self, node_far_behind_seconds).await
get_remote_head_and_new_block_ranges(e, self, node_far_behind_seconds).await
})
.await
.map_err(|e| {
@@ -881,7 +881,7 @@ impl Service {
Some(range) => range,
None => endpoints
.first_success(|e| async move {
relevant_new_block_numbers_from_endpoint(e, &self, HeadType::Deposit).await
relevant_new_block_numbers_from_endpoint(e, self, HeadType::Deposit).await
})
.await
.map_err(Error::FallbackError)?,
@@ -922,7 +922,7 @@ impl Service {
.first_success(|e| async move {
get_deposit_logs_in_range(
e,
&deposit_contract_address_ref,
deposit_contract_address_ref,
block_range_ref.clone(),
Duration::from_millis(GET_DEPOSIT_LOG_TIMEOUT_MILLIS),
)
@@ -1034,7 +1034,7 @@ impl Service {
Some(range) => range,
None => endpoints
.first_success(|e| async move {
relevant_new_block_numbers_from_endpoint(e, &self, HeadType::BlockCache)
relevant_new_block_numbers_from_endpoint(e, self, HeadType::BlockCache)
.await
})
.await
+3 -3
View File
@@ -67,7 +67,7 @@ pub fn use_or_load_enr(
Ok(disk_enr) => {
// if the same node id, then we may need to update our sequence number
if local_enr.node_id() == disk_enr.node_id() {
if compare_enr(&local_enr, &disk_enr) {
if compare_enr(local_enr, &disk_enr) {
debug!(log, "ENR loaded from disk"; "file" => ?enr_f);
// the stored ENR has the same configuration, use it
*local_enr = disk_enr;
@@ -92,7 +92,7 @@ pub fn use_or_load_enr(
}
}
save_enr_to_disk(&config.network_dir, &local_enr, log);
save_enr_to_disk(&config.network_dir, local_enr, log);
Ok(())
}
@@ -193,7 +193,7 @@ pub fn load_enr_from_disk(dir: &Path) -> Result<Enr, String> {
pub fn save_enr_to_disk(dir: &Path, enr: &Enr, log: &slog::Logger) {
let _ = std::fs::create_dir_all(dir);
match File::create(dir.join(Path::new(ENR_FILENAME)))
.and_then(|mut f| f.write_all(&enr.to_base64().as_bytes()))
.and_then(|mut f| f.write_all(enr.to_base64().as_bytes()))
{
Ok(_) => {
debug!(log, "ENR written to disk");
@@ -254,7 +254,7 @@ pub fn peer_id_to_node_id(peer_id: &PeerId) -> Result<discv5::enr::NodeId, Strin
let uncompressed_key_bytes = &pk.encode_uncompressed()[1..];
let mut output = [0_u8; 32];
let mut hasher = Keccak::v256();
hasher.update(&uncompressed_key_bytes);
hasher.update(uncompressed_key_bytes);
hasher.finalize(&mut output);
Ok(discv5::enr::NodeId::parse(&output).expect("Must be correct length"))
}
+1 -1
View File
@@ -198,7 +198,7 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
let listen_socket = SocketAddr::new(config.listen_address, config.discovery_port);
// convert the keypair into an ENR key
let enr_key: CombinedKey = CombinedKey::from_libp2p(&local_key)?;
let enr_key: CombinedKey = CombinedKey::from_libp2p(local_key)?;
let mut discv5 = Discv5::new(local_enr, enr_key, config.discv5_config.clone())
.map_err(|e| format!("Discv5 service failed. Error: {:?}", e))?;
@@ -778,7 +778,7 @@ impl<TSpec: EthSpec> PeerManager<TSpec> {
) -> bool {
{
let mut peerdb = self.network_globals.peers.write();
if peerdb.is_banned(&peer_id) {
if peerdb.is_banned(peer_id) {
// don't connect if the peer is banned
slog::crit!(self.log, "Connection has been allowed to a banned peer"; "peer_id" => %peer_id);
}
@@ -952,7 +952,7 @@ impl<TSpec: EthSpec> PeerManager<TSpec> {
/// previous bans from discovery.
fn unban_peer(&mut self, peer_id: &PeerId) -> Result<(), &'static str> {
let mut peer_db = self.network_globals.peers.write();
peer_db.unban(&peer_id)?;
peer_db.unban(peer_id)?;
let seen_ip_addresses = peer_db
.peer_info(peer_id)
@@ -319,7 +319,7 @@ impl<TSpec: EthSpec> PeerDB<TSpec> {
let mut by_status = self
.peers
.iter()
.filter(|(_, info)| is_status(&info))
.filter(|(_, info)| is_status(info))
.collect::<Vec<_>>();
by_status.sort_by_key(|(_, info)| info.score());
by_status.into_iter().rev().collect()
@@ -332,7 +332,7 @@ impl<TSpec: EthSpec> PeerDB<TSpec> {
{
self.peers
.iter()
.filter(|(_, info)| is_status(&info))
.filter(|(_, info)| is_status(info))
.max_by_key(|(_, info)| info.score())
.map(|(id, _)| id)
}
@@ -1066,7 +1066,7 @@ mod tests {
let mut socker_addr = Multiaddr::from(ip2);
socker_addr.push(Protocol::Tcp(8080));
for p in &peers {
pdb.connect_ingoing(&p, socker_addr.clone(), None);
pdb.connect_ingoing(p, socker_addr.clone(), None);
pdb.disconnect_and_ban(p);
pdb.inject_disconnect(p);
pdb.disconnect_and_ban(p);
@@ -1078,7 +1078,7 @@ mod tests {
// unban all peers
for p in &peers {
reset_score(&mut pdb, &p);
reset_score(&mut pdb, p);
pdb.unban(p).unwrap();
}
+1 -1
View File
@@ -578,6 +578,6 @@ fn load_or_build_metadata<E: EthSpec>(
};
debug!(log, "Metadata sequence number"; "seq_num" => meta_data.seq_number);
save_metadata_to_disk(network_dir, meta_data.clone(), &log);
save_metadata_to_disk(network_dir, meta_data.clone(), log);
meta_data
}
+2 -2
View File
@@ -142,7 +142,7 @@ pub async fn build_full_mesh(
}
let multiaddrs: Vec<Multiaddr> = nodes
.iter()
.map(|x| get_enr(&x).multiaddr()[1].clone())
.map(|x| get_enr(x).multiaddr()[1].clone())
.collect();
for (i, node) in nodes.iter_mut().enumerate().take(n) {
@@ -216,7 +216,7 @@ pub async fn build_linear(rt: Weak<Runtime>, log: slog::Logger, n: usize) -> Vec
let multiaddrs: Vec<Multiaddr> = nodes
.iter()
.map(|x| get_enr(&x).multiaddr()[1].clone())
.map(|x| get_enr(x).multiaddr()[1].clone())
.collect();
for i in 0..n - 1 {
match libp2p::Swarm::dial_addr(&mut nodes[i].swarm, multiaddrs[i + 1].clone()) {
@@ -316,7 +316,7 @@ impl Eth1GenesisService {
//
// Note: this state is fully valid, some fields have been bypassed to make verification
// faster.
let state = self.cheap_state_at_eth1_block::<E>(block, &spec)?;
let state = self.cheap_state_at_eth1_block::<E>(block, spec)?;
let active_validator_count = state
.get_active_validator_indices(E::genesis_epoch(), spec)
.map_err(|e| format!("Genesis validators error: {:?}", e))?
@@ -328,7 +328,7 @@ impl Eth1GenesisService {
if is_valid_genesis_state(&state, spec) {
let genesis_state = self
.genesis_from_eth1_block(block.clone(), &spec)
.genesis_from_eth1_block(block.clone(), spec)
.map_err(|e| format!("Failed to generate valid genesis state : {}", e))?;
return Ok(Some(genesis_state));
@@ -372,12 +372,12 @@ impl Eth1GenesisService {
let genesis_state = initialize_beacon_state_from_eth1(
eth1_block.hash,
eth1_block.timestamp,
genesis_deposits(deposit_logs, &spec)?,
&spec,
genesis_deposits(deposit_logs, spec)?,
spec,
)
.map_err(|e| format!("Unable to initialize genesis state: {:?}", e))?;
if is_valid_genesis_state(&genesis_state, &spec) {
if is_valid_genesis_state(&genesis_state, spec) {
Ok(genesis_state)
} else {
Err("Generated state was not valid.".to_string())
@@ -406,7 +406,7 @@ impl Eth1GenesisService {
deposit_root: Hash256::zero(),
deposit_count: 0,
},
&spec,
spec,
);
self.deposit_logs_at_block(eth1_block.number)
+2 -2
View File
@@ -63,7 +63,7 @@ fn cached_attestation_duties<T: BeaconChainTypes>(
.map_err(warp_utils::reject::beacon_chain_error)?;
let (duties, dependent_root) = chain
.validator_attestation_duties(&request_indices, request_epoch, head.block_root)
.validator_attestation_duties(request_indices, request_epoch, head.block_root)
.map_err(warp_utils::reject::beacon_chain_error)?;
convert_to_api_response(duties, request_indices, dependent_root, chain)
@@ -104,7 +104,7 @@ fn compute_historic_attester_duties<T: BeaconChainTypes>(
)?;
state
} else {
StateId::slot(request_epoch.start_slot(T::EthSpec::slots_per_epoch())).state(&chain)?
StateId::slot(request_epoch.start_slot(T::EthSpec::slots_per_epoch())).state(chain)?
};
// Sanity-check the state lookup.
+5 -7
View File
@@ -1515,11 +1515,9 @@ pub fn serve<T: BeaconChainTypes>(
peer_id: peer_id.to_string(),
enr: peer_info.enr.as_ref().map(|enr| enr.to_base64()),
last_seen_p2p_address: address,
direction: api_types::PeerDirection::from_connection_direction(
&dir,
),
direction: api_types::PeerDirection::from_connection_direction(dir),
state: api_types::PeerState::from_peer_connection_status(
&peer_info.connection_status(),
peer_info.connection_status(),
),
}));
}
@@ -1563,9 +1561,9 @@ pub fn serve<T: BeaconChainTypes>(
// the eth2 API spec implies only peers we have been connected to at some point should be included.
if let Some(dir) = peer_info.connection_direction.as_ref() {
let direction =
api_types::PeerDirection::from_connection_direction(&dir);
api_types::PeerDirection::from_connection_direction(dir);
let state = api_types::PeerState::from_peer_connection_status(
&peer_info.connection_status(),
peer_info.connection_status(),
);
let state_matches = query.state.as_ref().map_or(true, |states| {
@@ -1616,7 +1614,7 @@ pub fn serve<T: BeaconChainTypes>(
.peers()
.for_each(|(_, peer_info)| {
let state = api_types::PeerState::from_peer_connection_status(
&peer_info.connection_status(),
peer_info.connection_status(),
);
match state {
api_types::PeerState::Connected => connected += 1,
+1 -1
View File
@@ -185,7 +185,7 @@ fn compute_historic_proposer_duties<T: BeaconChainTypes>(
ensure_state_is_in_epoch(&mut state, state_root, epoch, &chain.spec)?;
state
} else {
StateId::slot(epoch.start_slot(T::EthSpec::slots_per_epoch())).state(&chain)?
StateId::slot(epoch.start_slot(T::EthSpec::slots_per_epoch())).state(chain)?
};
// Ensure the state lookup was correct.
+4 -4
View File
@@ -410,7 +410,7 @@ pub fn expose_publish_metrics<T: EthSpec>(messages: &[PubsubMessage<T>]) {
PubsubMessage::Attestation(subnet_id) => {
inc_counter_vec(
&ATTESTATIONS_PUBLISHED_PER_SUBNET_PER_SLOT,
&[&subnet_id.0.as_ref()],
&[subnet_id.0.as_ref()],
);
inc_counter(&GOSSIP_UNAGGREGATED_ATTESTATIONS_TX)
}
@@ -577,7 +577,7 @@ pub fn update_gossip_metrics<T: EthSpec>(
// mesh peers
for topic_hash in gossipsub.topics() {
let peers = gossipsub.mesh_peers(&topic_hash).count();
let peers = gossipsub.mesh_peers(topic_hash).count();
if let Ok(topic) = GossipTopic::decode(topic_hash.as_str()) {
match topic.kind() {
GossipKind::Attestation(subnet_id) => {
@@ -633,7 +633,7 @@ pub fn update_gossip_metrics<T: EthSpec>(
if let Ok(topic) = GossipTopic::decode(topic_hash.as_str()) {
match topic.kind() {
GossipKind::BeaconBlock => {
for peer in gossipsub.mesh_peers(&topic_hash) {
for peer in gossipsub.mesh_peers(topic_hash) {
if let Some(client) = peer_to_client.get(peer) {
if let Some(v) =
get_int_gauge(&BEACON_BLOCK_MESH_PEERS_PER_CLIENT, &[client])
@@ -644,7 +644,7 @@ pub fn update_gossip_metrics<T: EthSpec>(
}
}
GossipKind::BeaconAggregateAndProof => {
for peer in gossipsub.mesh_peers(&topic_hash) {
for peer in gossipsub.mesh_peers(topic_hash) {
if let Some(client) = peer_to_client.get(peer) {
if let Some(v) = get_int_gauge(
&BEACON_AGGREGATE_AND_PROOF_MESH_PEERS_PER_CLIENT,
+2 -2
View File
@@ -195,7 +195,7 @@ impl<T: BeaconChainTypes> NetworkService<T> {
// attestation service
let attestation_service =
AttestationService::new(beacon_chain.clone(), &config, &network_log);
AttestationService::new(beacon_chain.clone(), config, &network_log);
// create a timer for updating network metrics
let metrics_update = tokio::time::interval(Duration::from_secs(METRIC_UPDATE_INTERVAL));
@@ -251,7 +251,7 @@ fn spawn_service<T: BeaconChainTypes>(
.map(|gauge| gauge.reset());
}
metrics::update_gossip_metrics::<T::EthSpec>(
&service.libp2p.swarm.behaviour_mut().gs(),
service.libp2p.swarm.behaviour_mut().gs(),
&service.network_globals,
);
// update sync metrics
@@ -126,7 +126,7 @@ impl<T: EthSpec> BatchInfo<T> {
BatchState::Downloading(peer_id, _, _)
| BatchState::AwaitingProcessing(peer_id, _)
| BatchState::Processing(Attempt { peer_id, .. })
| BatchState::AwaitingValidation(Attempt { peer_id, .. }) => Some(&peer_id),
| BatchState::AwaitingValidation(Attempt { peer_id, .. }) => Some(peer_id),
BatchState::Poisoned => unreachable!("Poisoned batch"),
}
}
+1 -1
View File
@@ -383,7 +383,7 @@ impl<T: EthSpec> OperationPool<T> {
let relevant_attester_slashings = reader.iter().flat_map(|(slashing, fork)| {
if *fork == state.fork().previous_version || *fork == state.fork().current_version {
AttesterSlashingMaxCover::new(&slashing, &to_be_slashed, state)
AttesterSlashingMaxCover::new(slashing, &to_be_slashed, state)
} else {
None
}
+1 -1
View File
@@ -121,7 +121,7 @@ mod test {
}
fn covering_set(&self) -> &Self {
&self
self
}
fn update_covering_set(&mut self, _: &Self, other: &Self) {
+1 -1
View File
@@ -264,7 +264,7 @@ pub fn get_config<E: EthSpec>(
/*
* Load the eth2 network dir to obtain some additional config values.
*/
let eth2_network_config = get_eth2_network_config(&cli_args)?;
let eth2_network_config = get_eth2_network_config(cli_args)?;
client_config.eth1.deposit_contract_address = format!("{:?}", spec.deposit_contract_address);
client_config.eth1.deposit_contract_deploy_block =
+3 -3
View File
@@ -305,7 +305,7 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
pub fn put_state(&self, state_root: &Hash256, state: &BeaconState<E>) -> Result<(), Error> {
let mut ops: Vec<KeyValueStoreOp> = Vec::new();
if state.slot() < self.get_split_slot() {
self.store_cold_state(state_root, &state, &mut ops)?;
self.store_cold_state(state_root, state, &mut ops)?;
self.cold_db.do_atomically(ops)
} else {
self.store_hot_state(state_root, state, &mut ops)?;
@@ -563,7 +563,7 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
"slot" => state.slot().as_u64(),
"state_root" => format!("{:?}", state_root)
);
store_full_state(state_root, &state, ops)?;
store_full_state(state_root, state, ops)?;
}
// Store a summary of the state.
@@ -861,7 +861,7 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
per_block_processing(
&mut state,
&block,
block,
None,
BlockSignatureStrategy::NoVerification,
&self.spec,
+1 -1
View File
@@ -271,7 +271,7 @@ mod tests {
fn simplediskdb() {
let dir = tempdir().unwrap();
let path = dir.path();
let store = LevelDB::open(&path).unwrap();
let store = LevelDB::open(path).unwrap();
test_impl(store);
}