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
+4 -4
View File
@@ -73,14 +73,14 @@ pub fn write_file_via_temporary(
// If the file already exists, preserve its permissions by copying it.
// Otherwise, create a new file with restricted permissions.
if file_path.exists() {
fs::copy(&file_path, &temp_path).map_err(FsError::UnableToCopyFile)?;
fs::write(&temp_path, &bytes).map_err(FsError::UnableToWriteFile)?;
fs::copy(file_path, temp_path).map_err(FsError::UnableToCopyFile)?;
fs::write(temp_path, bytes).map_err(FsError::UnableToWriteFile)?;
} else {
create_with_600_perms(&temp_path, &bytes)?;
create_with_600_perms(temp_path, bytes)?;
}
// With the temporary file created, perform an atomic rename.
fs::rename(&temp_path, &file_path).map_err(FsError::UnableToRenameFile)?;
fs::rename(temp_path, file_path).map_err(FsError::UnableToRenameFile)?;
Ok(())
}
@@ -405,7 +405,7 @@ mod tests {
voting_keystore_path: ""
voting_public_key: "0xaf3c7ddab7e293834710fca2d39d068f884455ede270e0d0293dc818e4f2f0f975355067e8437955cb29aec674e5c9e7"
"#;
let def: ValidatorDefinition = serde_yaml::from_str(&no_graffiti).unwrap();
let def: ValidatorDefinition = serde_yaml::from_str(no_graffiti).unwrap();
assert!(def.graffiti.is_none());
let invalid_graffiti = r#"---
@@ -417,7 +417,7 @@ mod tests {
voting_public_key: "0xaf3c7ddab7e293834710fca2d39d068f884455ede270e0d0293dc818e4f2f0f975355067e8437955cb29aec674e5c9e7"
"#;
let def: Result<ValidatorDefinition, _> = serde_yaml::from_str(&invalid_graffiti);
let def: Result<ValidatorDefinition, _> = serde_yaml::from_str(invalid_graffiti);
assert!(def.is_err());
let valid_graffiti = r#"---
@@ -429,7 +429,7 @@ mod tests {
voting_public_key: "0xaf3c7ddab7e293834710fca2d39d068f884455ede270e0d0293dc818e4f2f0f975355067e8437955cb29aec674e5c9e7"
"#;
let def: ValidatorDefinition = serde_yaml::from_str(&valid_graffiti).unwrap();
let def: ValidatorDefinition = serde_yaml::from_str(valid_graffiti).unwrap();
assert_eq!(
def.graffiti,
Some(GraffitiString::from_str("mrfwashere").unwrap())
+1 -1
View File
@@ -35,7 +35,7 @@ pub fn parse_pubkey(secret: &str) -> Result<PublicKey, Error> {
&secret[SECRET_PREFIX.len()..]
};
serde_utils::hex::decode(&secret)
serde_utils::hex::decode(secret)
.map_err(|e| Error::InvalidSecret(format!("invalid hex: {:?}", e)))
.and_then(|bytes| {
if bytes.len() != PK_LEN {
+4 -4
View File
@@ -16,8 +16,8 @@ pub enum Error {
UnableToRemoveWallet(io::Error),
UnableToCreateWallet(io::Error),
UnableToReadWallet(io::Error),
JsonWriteError(WalletError),
JsonReadError(WalletError),
JsonWrite(WalletError),
JsonRead(WalletError),
}
/// Read a wallet with the given `uuid` from the `wallet_dir`.
@@ -32,7 +32,7 @@ pub fn read<P: AsRef<Path>>(wallet_dir: P, uuid: &Uuid) -> Result<Wallet, Error>
.create(false)
.open(json_path)
.map_err(Error::UnableToReadWallet)
.and_then(|f| Wallet::from_json_reader(f).map_err(Error::JsonReadError))
.and_then(|f| Wallet::from_json_reader(f).map_err(Error::JsonRead))
}
}
@@ -84,7 +84,7 @@ pub fn create<P: AsRef<Path>>(wallet_dir: P, wallet: &Wallet) -> Result<(), Erro
.create_new(true)
.open(json_path)
.map_err(Error::UnableToCreateWallet)
.and_then(|f| wallet.to_json_writer(f).map_err(Error::JsonWriteError))
.and_then(|f| wallet.to_json_writer(f).map_err(Error::JsonWrite))
}
}
+1 -3
View File
@@ -140,9 +140,7 @@ impl<'a> slog_term::RecordDecorator for AlignedRecordDecorator<'a> {
write!(
self,
"{}",
std::iter::repeat(' ')
.take(self.message_width - self.message_count)
.collect::<String>()
" ".repeat(self.message_width - self.message_count)
)?;
self.message_active = false;
self.message_count = 0;
+1 -1
View File
@@ -153,7 +153,7 @@ pub fn gather_metrics(metrics_map: &HashMap<String, JsonMetric>) -> Option<serde
for mf in metric_families.iter() {
let metric_name = mf.get_name();
if metrics_map.contains_key(metric_name) {
let value = get_value(&mf).unwrap_or_default();
let value = get_value(mf).unwrap_or_default();
let metric = metrics_map.get(metric_name)?;
let value = metric.get_typed_value(value);
let _ = res.insert(metric.json_output_key.to_string(), value);
+2 -2
View File
@@ -131,8 +131,8 @@ impl MonitoringHttpClient {
let freezer_db_path = self.db_path.as_ref().ok_or_else(|| {
Error::BeaconMetricsFailed("Beacon metrics require freezer db path".to_string())
})?;
let metrics = gather_beacon_metrics(&db_path, &freezer_db_path)
.map_err(Error::BeaconMetricsFailed)?;
let metrics =
gather_beacon_metrics(db_path, freezer_db_path).map_err(Error::BeaconMetricsFailed)?;
Ok(MonitoringMetrics {
metadata: Metadata::new(ProcessType::BeaconNode),
process_metrics: Process::Beacon(metrics),
+1 -1
View File
@@ -180,7 +180,7 @@ impl<'a> Builder<'a> {
signature: Signature::empty().into(),
};
deposit_data.signature = deposit_data.create_signature(&voting_keypair.sk, &spec);
deposit_data.signature = deposit_data.create_signature(&voting_keypair.sk, spec);
let deposit_data =
encode_eth1_tx_data(&deposit_data).map_err(Error::UnableToEncodeDeposit)?;