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

View File

@@ -93,7 +93,7 @@ impl SlashingDatabase {
/// Open an existing `SlashingDatabase` from disk.
pub fn open(path: &Path) -> Result<Self, NotSafe> {
let conn_pool = Self::open_conn_pool(&path)?;
let conn_pool = Self::open_conn_pool(path)?;
Ok(Self { conn_pool })
}
@@ -159,7 +159,7 @@ impl SlashingDatabase {
) -> Result<(), NotSafe> {
let mut stmt = txn.prepare("INSERT INTO validators (public_key) VALUES (?1)")?;
for pubkey in public_keys {
if self.get_validator_id_opt(&txn, pubkey)?.is_none() {
if self.get_validator_id_opt(txn, pubkey)?.is_none() {
stmt.execute(&[pubkey.as_hex_string()])?;
}
}
@@ -481,10 +481,10 @@ impl SlashingDatabase {
signing_root: SigningRoot,
txn: &Transaction,
) -> Result<Safe, NotSafe> {
let safe = self.check_block_proposal(&txn, validator_pubkey, slot, signing_root)?;
let safe = self.check_block_proposal(txn, validator_pubkey, slot, signing_root)?;
if safe != Safe::SameData {
self.insert_block_proposal(&txn, validator_pubkey, slot, signing_root)?;
self.insert_block_proposal(txn, validator_pubkey, slot, signing_root)?;
}
Ok(safe)
}
@@ -541,7 +541,7 @@ impl SlashingDatabase {
txn: &Transaction,
) -> Result<Safe, NotSafe> {
let safe = self.check_attestation(
&txn,
txn,
validator_pubkey,
att_source_epoch,
att_target_epoch,
@@ -550,7 +550,7 @@ impl SlashingDatabase {
if safe != Safe::SameData {
self.insert_attestation(
&txn,
txn,
validator_pubkey,
att_source_epoch,
att_target_epoch,
@@ -695,7 +695,7 @@ impl SlashingDatabase {
.query_and_then(params![], |row| {
let validator_pubkey: String = row.get(0)?;
let slot = row.get(1)?;
let signing_root = Some(hash256_from_row(2, &row)?);
let signing_root = Some(hash256_from_row(2, row)?);
let signed_block = InterchangeBlock { slot, signing_root };
data.entry(validator_pubkey)
.or_insert_with(|| (vec![], vec![]))
@@ -715,7 +715,7 @@ impl SlashingDatabase {
let validator_pubkey: String = row.get(0)?;
let source_epoch = row.get(1)?;
let target_epoch = row.get(2)?;
let signing_root = Some(hash256_from_row(3, &row)?);
let signing_root = Some(hash256_from_row(3, row)?);
let signed_attestation = InterchangeAttestation {
source_epoch,
target_epoch,

View File

@@ -183,7 +183,7 @@ impl Config {
// Copy the provided bytes over.
//
// Panic-free because `graffiti_bytes.len()` <= `GRAFFITI_BYTES_LEN`.
graffiti[..graffiti_bytes.len()].copy_from_slice(&graffiti_bytes);
graffiti[..graffiti_bytes.len()].copy_from_slice(graffiti_bytes);
config.graffiti = Some(graffiti.into());
}

View File

@@ -378,7 +378,7 @@ async fn poll_beacon_attesters<T: SlotClock + 'static, E: EthSpec>(
// Download the duties and update the duties for the current epoch.
if let Err(e) = poll_beacon_attesters_for_epoch(
&duties_service,
duties_service,
current_epoch,
&local_indices,
&local_pubkeys,
@@ -402,7 +402,7 @@ async fn poll_beacon_attesters<T: SlotClock + 'static, E: EthSpec>(
// Download the duties and update the duties for the next epoch.
if let Err(e) =
poll_beacon_attesters_for_epoch(&duties_service, next_epoch, &local_indices, &local_pubkeys)
poll_beacon_attesters_for_epoch(duties_service, next_epoch, &local_indices, &local_pubkeys)
.await
{
error!(
@@ -431,7 +431,7 @@ async fn poll_beacon_attesters<T: SlotClock + 'static, E: EthSpec>(
.attesters
.read()
.iter()
.filter_map(|(_, map)| map.get(&epoch))
.filter_map(|(_, map)| map.get(epoch))
// The BN logs a warning if we try and subscribe to current or near-by slots. Give it a
// buffer.
.filter(|(_, duty_and_proof)| {
@@ -636,7 +636,7 @@ async fn poll_beacon_proposers<T: SlotClock + 'static, E: EthSpec>(
current_slot,
&initial_block_proposers,
block_service_tx,
&log,
log,
)
.await;
@@ -723,7 +723,7 @@ async fn poll_beacon_proposers<T: SlotClock + 'static, E: EthSpec>(
current_slot,
&additional_block_producers,
block_service_tx,
&log,
log,
)
.await;
debug!(

View File

@@ -9,6 +9,7 @@ use bls::PublicKeyBytes;
use types::{graffiti::GraffitiString, Graffiti};
#[derive(Debug)]
#[allow(clippy::enum_variant_names)]
pub enum Error {
InvalidFile(std::io::Error),
InvalidLine(String),
@@ -91,7 +92,7 @@ fn read_line(line: &str) -> Result<(Option<PublicKeyBytes>, Graffiti), Error> {
if key == "default" {
Ok((None, graffiti))
} else {
let pk = PublicKeyBytes::from_str(&key).map_err(Error::InvalidPublicKey)?;
let pk = PublicKeyBytes::from_str(key).map_err(Error::InvalidPublicKey)?;
Ok((Some(pk), graffiti))
}
} else {

View File

@@ -97,7 +97,7 @@ pub async fn create_validators<P: AsRef<Path>, T: 'static + SlotClock, E: EthSpe
let validator_dir = ValidatorDirBuilder::new(validator_dir.as_ref().into())
.voting_keystore(keystores.voting, voting_password.as_bytes())
.withdrawal_keystore(keystores.withdrawal, withdrawal_password.as_bytes())
.create_eth1_tx_data(request.deposit_gwei, &spec)
.create_eth1_tx_data(request.deposit_gwei, spec)
.store_withdrawal_keystore(false)
.build()
.map_err(|e| {

View File

@@ -33,7 +33,7 @@ const USE_STDIN: bool = false;
pub enum Error {
/// Refused to open a validator with an existing lockfile since that validator may be in-use by
/// another process.
LockfileError(LockfileError),
Lockfile(LockfileError),
/// The voting public key in the definition did not match the one in the keystore.
VotingPublicKeyMismatch {
definition: Box<PublicKey>,
@@ -66,7 +66,7 @@ pub enum Error {
impl From<LockfileError> for Error {
fn from(error: LockfileError) -> Self {
Self::LockfileError(error)
Self::Lockfile(error)
}
}
@@ -456,7 +456,7 @@ impl InitializedValidators {
read_password(path).map_err(Error::UnableToReadVotingKeystorePassword)?
} else {
let keystore = open_keystore(voting_keystore_path)?;
unlock_keystore_via_stdin_password(&keystore, &voting_keystore_path)?
unlock_keystore_via_stdin_password(&keystore, voting_keystore_path)?
.0
.as_ref()
.to_vec()

View File

@@ -84,7 +84,7 @@ impl<T: EthSpec> ProductionValidatorClient<T> {
context: RuntimeContext<T>,
cli_args: &ArgMatches<'_>,
) -> Result<Self, String> {
let config = Config::from_cli(&cli_args, context.log())
let config = Config::from_cli(cli_args, context.log())
.map_err(|e| format!("Unable to initialize config: {}", e))?;
Self::new(context, config).await
}

View File

@@ -20,7 +20,7 @@ pub fn spawn_notifier<T: EthSpec>(client: &ProductionValidatorClient<T>) -> Resu
loop {
if let Some(duration_to_next_slot) = duties_service.slot_clock.duration_to_next_slot() {
sleep(duration_to_next_slot + slot_duration / 2).await;
notify(&duties_service, &log).await;
notify(&duties_service, log).await;
} else {
error!(log, "Failed to read slot clock");
// If we can't read the slot clock, just wait another slot.