Update to Rust 1.59 and 2021 edition (#3038)
## Proposed Changes Lots of lint updates related to `flat_map`, `unwrap_or_else` and string patterns. I did a little more creative refactoring in the op pool, but otherwise followed Clippy's suggestions. ## Additional Info We need this PR to unblock CI.
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
name = "beacon_node"
|
||||
version = "2.1.3"
|
||||
authors = ["Paul Hauner <paul@paulhauner.com>", "Age Manning <Age@AgeManning.com"]
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
name = "beacon_node"
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
name = "beacon_chain"
|
||||
version = "0.2.0"
|
||||
authors = ["Paul Hauner <paul@paulhauner.com>", "Age Manning <Age@AgeManning.com>"]
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
autotests = false # using a single test binary compiles faster
|
||||
|
||||
[features]
|
||||
|
||||
@@ -2289,7 +2289,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
.position(|(_root, block)| {
|
||||
block.slot().epoch(T::EthSpec::slots_per_epoch()) > start_epoch
|
||||
})
|
||||
.unwrap_or_else(|| filtered_chain_segment.len());
|
||||
.unwrap_or(filtered_chain_segment.len());
|
||||
|
||||
// Split off the first section blocks that are all either within the current epoch of
|
||||
// the first block. These blocks can all be signature-verified with the same
|
||||
|
||||
@@ -421,10 +421,7 @@ impl<T: AggregateMap> NaiveAggregationPool<T> {
|
||||
|
||||
/// Iterate all items in all slots of `self`.
|
||||
pub fn iter(&self) -> impl Iterator<Item = &T::Value> {
|
||||
self.maps
|
||||
.iter()
|
||||
.map(|(_slot, map)| map.get_map().iter().map(|(_key, value)| value))
|
||||
.flatten()
|
||||
self.maps.values().flat_map(|map| map.get_map().values())
|
||||
}
|
||||
|
||||
/// Removes any items with a slot lower than `current_slot` and bars any future
|
||||
|
||||
@@ -635,7 +635,7 @@ pub fn verify_sync_committee_message<T: BeaconChainTypes>(
|
||||
let pubkey = pubkey_cache
|
||||
.get_pubkey_from_pubkey_bytes(pubkey_bytes)
|
||||
.map(Cow::Borrowed)
|
||||
.ok_or_else(|| Error::UnknownValidatorPubkey(*pubkey_bytes))?;
|
||||
.ok_or(Error::UnknownValidatorPubkey(*pubkey_bytes))?;
|
||||
|
||||
let next_slot_epoch = (sync_message.get_slot() + 1).epoch(T::EthSpec::slots_per_epoch());
|
||||
let fork = chain.spec.fork_at_epoch(next_slot_epoch);
|
||||
|
||||
@@ -198,14 +198,11 @@ impl MonitoredValidator {
|
||||
/// as the value recorded by the validator monitor ignores skip slots.
|
||||
fn min_inclusion_distance(&self, epoch: &Epoch) -> Option<u64> {
|
||||
let summaries = self.summaries.read();
|
||||
summaries
|
||||
.get(epoch)
|
||||
.map(|summary| {
|
||||
summary
|
||||
.attestation_min_block_inclusion_distance
|
||||
.map(Into::into)
|
||||
})
|
||||
.flatten()
|
||||
summaries.get(epoch).and_then(|summary| {
|
||||
summary
|
||||
.attestation_min_block_inclusion_distance
|
||||
.map(Into::into)
|
||||
})
|
||||
}
|
||||
|
||||
/// Maps `func` across the `self.summaries`.
|
||||
|
||||
@@ -175,9 +175,7 @@ impl<T: BeaconChainTypes> ValidatorPubkeyCache<T> {
|
||||
|
||||
/// Get the `PublicKey` for a validator with `PublicKeyBytes`.
|
||||
pub fn get_pubkey_from_pubkey_bytes(&self, pubkey: &PublicKeyBytes) -> Option<&PublicKey> {
|
||||
self.get_index(pubkey)
|
||||
.map(|index| self.get(index))
|
||||
.flatten()
|
||||
self.get_index(pubkey).and_then(|index| self.get(index))
|
||||
}
|
||||
|
||||
/// Get the public key (in bytes form) for a validator with index `i`.
|
||||
|
||||
@@ -179,7 +179,7 @@ fn aggregated_gossip_verification() {
|
||||
get_valid_sync_contribution(&harness, RelativeSyncCommittee::Current);
|
||||
|
||||
macro_rules! assert_invalid {
|
||||
($desc: tt, $attn_getter: expr, $($error: pat) |+ $( if $guard: expr )?) => {
|
||||
($desc: tt, $attn_getter: expr, $($error: pat_param) |+ $( if $guard: expr )?) => {
|
||||
assert!(
|
||||
matches!(
|
||||
harness
|
||||
@@ -505,7 +505,7 @@ fn unaggregated_gossip_verification() {
|
||||
get_valid_sync_committee_message(&harness, current_slot, RelativeSyncCommittee::Current);
|
||||
|
||||
macro_rules! assert_invalid {
|
||||
($desc: tt, $attn_getter: expr, $subnet_getter: expr, $($error: pat) |+ $( if $guard: expr )?) => {
|
||||
($desc: tt, $attn_getter: expr, $subnet_getter: expr, $($error: pat_param) |+ $( if $guard: expr )?) => {
|
||||
assert!(
|
||||
matches!(
|
||||
harness
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
name = "client"
|
||||
version = "0.2.0"
|
||||
authors = ["Sigma Prime <contact@sigmaprime.io>"]
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
|
||||
[dev-dependencies]
|
||||
toml = "0.5.6"
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
name = "eth1"
|
||||
version = "0.2.0"
|
||||
authors = ["Paul Hauner <paul@paulhauner.com>"]
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
|
||||
[dev-dependencies]
|
||||
eth1_test_rig = { path = "../../testing/eth1_test_rig" }
|
||||
|
||||
@@ -449,7 +449,7 @@ fn response_result_or_error(response: &str) -> Result<Value, RpcError> {
|
||||
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() {
|
||||
if let Some(error) = json.get("error").and_then(|e| e.get("message")) {
|
||||
let error = error.to_string();
|
||||
if error.contains(EIP155_ERROR_STR) {
|
||||
Err(RpcError::Eip155Error)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[package]
|
||||
name = "execution_layer"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
name = "genesis"
|
||||
version = "0.2.0"
|
||||
authors = ["Paul Hauner <paul@paulhauner.com>"]
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
|
||||
[dev-dependencies]
|
||||
eth1_test_rig = { path = "../../testing/eth1_test_rig" }
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
name = "http_api"
|
||||
version = "0.1.0"
|
||||
authors = ["Paul Hauner <paul@paulhauner.com>"]
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
autotests = false # using a single test binary compiles faster
|
||||
|
||||
[dependencies]
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
name = "http_metrics"
|
||||
version = "0.1.0"
|
||||
authors = ["Paul Hauner <paul@paulhauner.com>"]
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
name = "lighthouse_network"
|
||||
version = "0.2.0"
|
||||
authors = ["Sigma Prime <contact@sigmaprime.io>"]
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
discv5 = { version = "0.1.0-beta.13", features = ["libp2p"] }
|
||||
|
||||
@@ -458,7 +458,7 @@ impl<TSpec: EthSpec> Behaviour<TSpec> {
|
||||
GossipKind::Attestation(subnet_id) => {
|
||||
if let Some(v) = metrics::get_int_gauge(
|
||||
&metrics::FAILED_ATTESTATION_PUBLISHES_PER_SUBNET,
|
||||
&[&subnet_id.to_string()],
|
||||
&[subnet_id.as_ref()],
|
||||
) {
|
||||
v.inc()
|
||||
};
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
name = "network"
|
||||
version = "0.2.0"
|
||||
authors = ["Sigma Prime <contact@sigmaprime.io>"]
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
|
||||
[dev-dependencies]
|
||||
sloggers = { version = "2.1.1", features = ["json"] }
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
name = "operation_pool"
|
||||
version = "0.2.0"
|
||||
authors = ["Michael Sproul <michael@sigmaprime.io>"]
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
derivative = "2.1.1"
|
||||
|
||||
@@ -560,9 +560,8 @@ impl<T: EthSpec> OperationPool<T> {
|
||||
pub fn get_all_attestations(&self) -> Vec<Attestation<T>> {
|
||||
self.attestations
|
||||
.read()
|
||||
.iter()
|
||||
.map(|(_, attns)| attns.iter().cloned())
|
||||
.flatten()
|
||||
.values()
|
||||
.flat_map(|attns| attns.iter().cloned())
|
||||
.collect()
|
||||
}
|
||||
|
||||
@@ -575,10 +574,10 @@ impl<T: EthSpec> OperationPool<T> {
|
||||
{
|
||||
self.attestations
|
||||
.read()
|
||||
.iter()
|
||||
.map(|(_, attns)| attns.iter().cloned())
|
||||
.flatten()
|
||||
.filter(filter)
|
||||
.values()
|
||||
.flat_map(|attns| attns.iter())
|
||||
.filter(|attn| filter(*attn))
|
||||
.cloned()
|
||||
.collect()
|
||||
}
|
||||
|
||||
|
||||
@@ -97,20 +97,19 @@ impl<T: EthSpec> PersistedOperationPool<T> {
|
||||
/// Reconstruct an `OperationPool`. Sets `sync_contributions` to its `Default` if `self` matches
|
||||
/// `PersistedOperationPool::Base`.
|
||||
pub fn into_operation_pool(self) -> Result<OperationPool<T>, OpPoolError> {
|
||||
let attestations = RwLock::new(self.attestations().to_vec().into_iter().collect());
|
||||
let attester_slashings =
|
||||
RwLock::new(self.attester_slashings().to_vec().into_iter().collect());
|
||||
let attestations = RwLock::new(self.attestations().iter().cloned().collect());
|
||||
let attester_slashings = RwLock::new(self.attester_slashings().iter().cloned().collect());
|
||||
let proposer_slashings = RwLock::new(
|
||||
self.proposer_slashings()
|
||||
.to_vec()
|
||||
.into_iter()
|
||||
.iter()
|
||||
.cloned()
|
||||
.map(|slashing| (slashing.signed_header_1.message.proposer_index, slashing))
|
||||
.collect(),
|
||||
);
|
||||
let voluntary_exits = RwLock::new(
|
||||
self.voluntary_exits()
|
||||
.to_vec()
|
||||
.into_iter()
|
||||
.iter()
|
||||
.cloned()
|
||||
.map(|exit| (exit.message.validator_index, exit))
|
||||
.collect(),
|
||||
);
|
||||
@@ -125,7 +124,7 @@ impl<T: EthSpec> PersistedOperationPool<T> {
|
||||
},
|
||||
PersistedOperationPool::Altair(_) => {
|
||||
let sync_contributions =
|
||||
RwLock::new(self.sync_contributions()?.to_vec().into_iter().collect());
|
||||
RwLock::new(self.sync_contributions()?.iter().cloned().collect());
|
||||
|
||||
OperationPool {
|
||||
attestations,
|
||||
|
||||
@@ -705,13 +705,15 @@ pub fn set_network_config(
|
||||
// Appending enr-port to the dns hostname to appease `to_socket_addrs()` parsing.
|
||||
// Since enr-update is disabled with a dns address, not setting the enr-udp-port
|
||||
// will make the node undiscoverable.
|
||||
if let Some(enr_udp_port) = config.enr_udp_port.or_else(|| {
|
||||
if use_listening_port_as_enr_port_by_default {
|
||||
Some(config.discovery_port)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}) {
|
||||
if let Some(enr_udp_port) =
|
||||
config
|
||||
.enr_udp_port
|
||||
.or(if use_listening_port_as_enr_port_by_default {
|
||||
Some(config.discovery_port)
|
||||
} else {
|
||||
None
|
||||
})
|
||||
{
|
||||
addr.push_str(&format!(":{}", enr_udp_port));
|
||||
} else {
|
||||
return Err(
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
name = "store"
|
||||
version = "0.2.0"
|
||||
authors = ["Paul Hauner <paul@paulhauner.com>"]
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
|
||||
[dev-dependencies]
|
||||
tempfile = "3.1.0"
|
||||
|
||||
@@ -762,7 +762,7 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
|
||||
let partial_state_bytes = self
|
||||
.cold_db
|
||||
.get_bytes(DBColumn::BeaconState.into(), state_root.as_bytes())?
|
||||
.ok_or_else(|| HotColdDBError::MissingRestorePoint(*state_root))?;
|
||||
.ok_or(HotColdDBError::MissingRestorePoint(*state_root))?;
|
||||
let mut partial_state: PartialBeaconState<E> =
|
||||
PartialBeaconState::from_ssz_bytes(&partial_state_bytes, &self.spec)?;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
name = "timer"
|
||||
version = "0.2.0"
|
||||
authors = ["Sigma Prime <contact@sigmaprime.io>"]
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
beacon_chain = { path = "../beacon_chain" }
|
||||
|
||||
Reference in New Issue
Block a user