[refactor] Refactor Option/Result combinators (#3180)
Code simplifications using `Option`/`Result` combinators to make pattern-matches a tad simpler. Opinions on these loosely held, happy to adjust in review. Tool-aided by [comby-rust](https://github.com/huitseeker/comby-rust).
This commit is contained in:
parent
e81a428ffb
commit
3f9e83e840
@ -149,10 +149,8 @@ impl Config {
|
|||||||
pub fn get_existing_legacy_data_dir(&self) -> Option<PathBuf> {
|
pub fn get_existing_legacy_data_dir(&self) -> Option<PathBuf> {
|
||||||
dirs::home_dir()
|
dirs::home_dir()
|
||||||
.map(|home_dir| home_dir.join(&self.data_dir))
|
.map(|home_dir| home_dir.join(&self.data_dir))
|
||||||
// Return `None` if the directory does not exists.
|
// Return `None` if the legacy directory does not exist or if it is identical to the modern.
|
||||||
.filter(|dir| dir.exists())
|
.filter(|dir| dir.exists() && *dir != self.get_modern_data_dir())
|
||||||
// Return `None` if the legacy directory is identical to the modern.
|
|
||||||
.filter(|dir| *dir != self.get_modern_data_dir())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the core path for the client.
|
/// Returns the core path for the client.
|
||||||
|
@ -121,8 +121,7 @@ impl ApiTester {
|
|||||||
harness.chain.slot().unwrap(),
|
harness.chain.slot().unwrap(),
|
||||||
)
|
)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|vec| vec.into_iter().map(|(attestation, _subnet_id)| attestation))
|
.flat_map(|vec| vec.into_iter().map(|(attestation, _subnet_id)| attestation))
|
||||||
.flatten()
|
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
assert!(
|
assert!(
|
||||||
@ -244,8 +243,7 @@ impl ApiTester {
|
|||||||
harness.chain.slot().unwrap(),
|
harness.chain.slot().unwrap(),
|
||||||
)
|
)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|vec| vec.into_iter().map(|(attestation, _subnet_id)| attestation))
|
.flat_map(|vec| vec.into_iter().map(|(attestation, _subnet_id)| attestation))
|
||||||
.flatten()
|
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
let attester_slashing = harness.make_attester_slashing(vec![0, 1]);
|
let attester_slashing = harness.make_attester_slashing(vec![0, 1]);
|
||||||
@ -2390,8 +2388,7 @@ impl ApiTester {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
let attesting_validators: Vec<usize> = committees
|
let attesting_validators: Vec<usize> = committees
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|committee| committee.committee.iter().cloned())
|
.flat_map(|committee| committee.committee.iter().cloned())
|
||||||
.flatten()
|
|
||||||
.collect();
|
.collect();
|
||||||
// All attesters should now be considered live
|
// All attesters should now be considered live
|
||||||
let expected = expected
|
let expected = expected
|
||||||
|
@ -210,10 +210,8 @@ pub fn load_enr_from_disk(dir: &Path) -> Result<Enr, String> {
|
|||||||
let mut enr_string = String::new();
|
let mut enr_string = String::new();
|
||||||
match enr_file.read_to_string(&mut enr_string) {
|
match enr_file.read_to_string(&mut enr_string) {
|
||||||
Err(_) => Err("Could not read ENR from file".to_string()),
|
Err(_) => Err("Could not read ENR from file".to_string()),
|
||||||
Ok(_) => match Enr::from_str(&enr_string) {
|
Ok(_) => Enr::from_str(&enr_string)
|
||||||
Ok(disk_enr) => Ok(disk_enr),
|
.map_err(|e| format!("ENR from file could not be decoded: {:?}", e)),
|
||||||
Err(e) => Err(format!("ENR from file could not be decoded: {:?}", e)),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -646,8 +646,8 @@ async fn poll_beacon_attesters_for_epoch<T: SlotClock + 'static, E: EthSpec>(
|
|||||||
response
|
response
|
||||||
.data
|
.data
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter(|duty| local_pubkeys.contains(&duty.pubkey))
|
|
||||||
.filter(|duty| {
|
.filter(|duty| {
|
||||||
|
local_pubkeys.contains(&duty.pubkey) && {
|
||||||
// Only update the duties if either is true:
|
// Only update the duties if either is true:
|
||||||
//
|
//
|
||||||
// - There were no known duties for this epoch.
|
// - There were no known duties for this epoch.
|
||||||
@ -657,6 +657,7 @@ async fn poll_beacon_attesters_for_epoch<T: SlotClock + 'static, E: EthSpec>(
|
|||||||
.get(&epoch)
|
.get(&epoch)
|
||||||
.map_or(true, |(prior, _)| *prior != dependent_root)
|
.map_or(true, |(prior, _)| *prior != dependent_root)
|
||||||
})
|
})
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
};
|
};
|
||||||
|
@ -983,8 +983,7 @@ fn delete_concurrent_with_signing() {
|
|||||||
|
|
||||||
for interchange in collected_slashing_protection
|
for interchange in collected_slashing_protection
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(Result::unwrap)
|
.flat_map(Result::unwrap)
|
||||||
.flatten()
|
|
||||||
{
|
{
|
||||||
for validator_data in interchange.data {
|
for validator_data in interchange.data {
|
||||||
slashing_protection_map
|
slashing_protection_map
|
||||||
|
Loading…
Reference in New Issue
Block a user