Fix Rust beta compiler errors 1.78.0-beta.1 (#5439)

* remove redundant imports

* fix test

* contains key

* fmt

* Merge branch 'unstable' into fix-beta-compiler
This commit is contained in:
Eitan Seri-Levi
2024-03-20 07:17:02 +02:00
committed by GitHub
parent 4449627c7c
commit 01ec42e75a
148 changed files with 104 additions and 301 deletions

View File

@@ -525,7 +525,7 @@ where
return Err(SubscriptionError::NotAllowed);
}
if self.mesh.get(&topic_hash).is_some() {
if self.mesh.contains_key(&topic_hash) {
tracing::debug!(%topic, "Topic is already in the mesh");
return Ok(false);
}
@@ -551,7 +551,7 @@ where
tracing::debug!(%topic, "Unsubscribing from topic");
let topic_hash = topic.hash();
if self.mesh.get(&topic_hash).is_none() {
if !self.mesh.contains_key(&topic_hash) {
tracing::debug!(topic=%topic_hash, "Already unsubscribed from topic");
// we are not subscribed
return Ok(false);

View File

@@ -22,18 +22,13 @@
use super::*;
use crate::gossipsub::subscription_filter::WhitelistSubscriptionFilter;
use crate::gossipsub::transform::{DataTransform, IdentityTransform};
use crate::gossipsub::types::{RpcOut, RpcReceiver};
use crate::gossipsub::ValidationError;
use crate::gossipsub::{
config::Config, config::ConfigBuilder, types::Rpc, IdentTopic as Topic, TopicScoreParams,
};
use crate::gossipsub::types::RpcReceiver;
use crate::gossipsub::{config::ConfigBuilder, types::Rpc, IdentTopic as Topic};
use async_std::net::Ipv4Addr;
use byteorder::{BigEndian, ByteOrder};
use libp2p::core::{ConnectedPoint, Endpoint};
use libp2p::core::ConnectedPoint;
use rand::Rng;
use std::thread::sleep;
use std::time::Duration;
#[derive(Default, Debug)]
struct InjectNodes<D, F>
@@ -427,7 +422,7 @@ fn test_subscribe() {
.create_network();
assert!(
gs.mesh.get(&topic_hashes[0]).is_some(),
gs.mesh.contains_key(&topic_hashes[0]),
"Subscribe should add a new entry to the mesh[topic] hashmap"
);
@@ -477,7 +472,7 @@ fn test_unsubscribe() {
"Topic_peers contain a topic entry"
);
assert!(
gs.mesh.get(topic_hash).is_some(),
gs.mesh.contains_key(topic_hash),
"mesh should contain a topic entry"
);
}
@@ -511,7 +506,7 @@ fn test_unsubscribe() {
// check we clean up internal structures
for topic_hash in &topic_hashes {
assert!(
gs.mesh.get(topic_hash).is_none(),
!gs.mesh.contains_key(topic_hash),
"All topics should have been removed from the mesh"
);
}
@@ -694,7 +689,7 @@ fn test_publish_without_flood_publishing() {
.create_network();
assert!(
gs.mesh.get(&topic_hashes[0]).is_some(),
gs.mesh.contains_key(&topic_hashes[0]),
"Subscribe should add a new entry to the mesh[topic] hashmap"
);
@@ -774,7 +769,7 @@ fn test_fanout() {
.create_network();
assert!(
gs.mesh.get(&topic_hashes[0]).is_some(),
gs.mesh.contains_key(&topic_hashes[0]),
"Subscribe should add a new entry to the mesh[topic] hashmap"
);
// Unsubscribe from topic
@@ -946,7 +941,7 @@ fn test_handle_received_subscriptions() {
);
assert!(
gs.connected_peers.get(&unknown_peer).is_none(),
!gs.connected_peers.contains_key(&unknown_peer),
"Unknown peer should not have been added"
);
@@ -1347,7 +1342,7 @@ fn test_handle_graft_multiple_topics() {
}
assert!(
gs.mesh.get(&topic_hashes[2]).is_none(),
!gs.mesh.contains_key(&topic_hashes[2]),
"Expected the second topic to not be in the mesh"
);
}
@@ -5228,7 +5223,7 @@ fn test_graft_without_subscribe() {
.create_network();
assert!(
gs.mesh.get(&topic_hashes[0]).is_some(),
gs.mesh.contains_key(&topic_hashes[0]),
"Subscribe should add a new entry to the mesh[topic] hashmap"
);

View File

@@ -903,10 +903,8 @@ impl std::fmt::Debug for Config {
mod test {
use super::*;
use crate::gossipsub::topic::IdentityHash;
use crate::gossipsub::types::PeerKind;
use crate::gossipsub::Topic;
use libp2p::core::UpgradeInfo;
use libp2p::swarm::StreamProtocol;
use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};

View File

@@ -221,9 +221,7 @@ impl MessageCache {
#[cfg(test)]
mod tests {
use super::*;
use crate::gossipsub::types::RawMessage;
use crate::{IdentTopic as Topic, TopicHash};
use libp2p::identity::PeerId;
use crate::IdentTopic as Topic;
fn gen_testm(x: u64, topic: TopicHash) -> (MessageId, RawMessage) {
let default_id = |message: &RawMessage| {

View File

@@ -102,7 +102,7 @@ impl PeerStats {
topic_hash: TopicHash,
params: &PeerScoreParams,
) -> Option<&mut TopicStats> {
if params.topics.get(&topic_hash).is_some() {
if params.topics.contains_key(&topic_hash) {
Some(self.topics.entry(topic_hash).or_default())
} else {
self.topics.get_mut(&topic_hash)
@@ -310,7 +310,7 @@ impl PeerScore {
// P6: IP collocation factor
for ip in peer_stats.known_ips.iter() {
if self.params.ip_colocation_factor_whitelist.get(ip).is_some() {
if self.params.ip_colocation_factor_whitelist.contains(ip) {
continue;
}
@@ -705,7 +705,7 @@ impl PeerScore {
) {
let record = self.deliveries.entry(msg_id.clone()).or_default();
if record.peers.get(from).is_some() {
if record.peers.contains(from) {
// we have already seen this duplicate!
return;
}

View File

@@ -30,7 +30,6 @@ use super::ValidationError;
use asynchronous_codec::{Decoder, Encoder, Framed};
use byteorder::{BigEndian, ByteOrder};
use bytes::BytesMut;
use futures::future;
use futures::prelude::*;
use libp2p::core::{InboundUpgrade, OutboundUpgrade, UpgradeInfo};
use libp2p::identity::{PeerId, PublicKey};
@@ -508,10 +507,8 @@ impl Decoder for GossipsubCodec {
#[cfg(test)]
mod tests {
use super::*;
use crate::gossipsub::config::Config;
use crate::gossipsub::protocol::{BytesMut, GossipsubCodec, HandlerEvent};
use crate::gossipsub::IdentTopic as Topic;
use crate::gossipsub::*;
use crate::gossipsub::{IdentTopic as Topic, Version};
use libp2p::identity::Keypair;
use quickcheck::*;

View File

@@ -212,7 +212,6 @@ impl TopicSubscriptionFilter for RegexSubscriptionFilter {
mod test {
use super::*;
use crate::gossipsub::types::SubscriptionAction::*;
use std::iter::FromIterator;
#[test]
fn test_filter_incoming_allow_all_with_duplicates() {

View File

@@ -1251,7 +1251,6 @@ impl BannedPeersCount {
mod tests {
use super::*;
use libp2p::core::multiaddr::Protocol;
use libp2p::core::Multiaddr;
use slog::{o, Drain};
use std::net::{Ipv4Addr, Ipv6Addr};
use types::MinimalEthSpec;

View File

@@ -3,7 +3,7 @@ use crate::rpc::{
codec::base::OutboundCodec,
protocol::{Encoding, ProtocolId, RPCError, SupportedProtocol, ERROR_TYPE_MAX, ERROR_TYPE_MIN},
};
use crate::rpc::{InboundRequest, OutboundRequest, RPCCodedResponse, RPCResponse};
use crate::rpc::{InboundRequest, OutboundRequest};
use libp2p::bytes::BytesMut;
use snap::read::FrameDecoder;
use snap::write::FrameEncoder;
@@ -676,22 +676,13 @@ fn context_bytes_to_fork_name(
mod tests {
use super::*;
use crate::rpc::{protocol::*, MetaData};
use crate::{
rpc::{methods::StatusMessage, Ping, RPCResponseErrorCode},
types::{EnrAttestationBitfield, EnrSyncCommitteeBitfield},
};
use std::sync::Arc;
use crate::rpc::protocol::*;
use crate::types::{EnrAttestationBitfield, EnrSyncCommitteeBitfield};
use types::{
blob_sidecar::BlobIdentifier, BeaconBlock, BeaconBlockAltair, BeaconBlockBase,
BeaconBlockMerge, ChainSpec, EmptyBlock, Epoch, ForkContext, FullPayload, Hash256,
Signature, SignedBeaconBlock, Slot,
BeaconBlockMerge, EmptyBlock, Epoch, FullPayload, Signature, Slot,
};
use snap::write::FrameEncoder;
use ssz::Encode;
use std::io::Write;
type Spec = types::MainnetEthSpec;
fn fork_context(fork_name: ForkName) -> ForkContext {

View File

@@ -9,7 +9,7 @@ use crate::rpc::outbound::{OutboundFramed, OutboundRequest};
use crate::rpc::protocol::InboundFramed;
use fnv::FnvHashMap;
use futures::prelude::*;
use futures::{Sink, SinkExt};
use futures::SinkExt;
use libp2p::swarm::handler::{
ConnectionEvent, ConnectionHandler, ConnectionHandlerEvent, DialUpgradeError,
FullyNegotiatedInbound, FullyNegotiatedOutbound, StreamUpgradeError, SubstreamProtocol,

View File

@@ -6,6 +6,7 @@ use serde::Serialize;
use ssz::Encode;
use ssz_derive::{Decode, Encode};
use ssz_types::{typenum::U256, VariableList};
use std::fmt::Display;
use std::marker::PhantomData;
use std::ops::Deref;
use std::sync::Arc;
@@ -44,11 +45,13 @@ impl Deref for ErrorType {
}
}
impl ToString for ErrorType {
fn to_string(&self) -> String {
impl Display for ErrorType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
#[allow(clippy::invalid_regex)]
let re = Regex::new("\\p{C}").expect("Regex is valid");
String::from_utf8_lossy(&re.replace_all(self.0.deref(), &b""[..])).to_string()
let error_type_str =
String::from_utf8_lossy(&re.replace_all(self.0.deref(), &b""[..])).to_string();
write!(f, "{}", error_type_str)
}
}
@@ -580,7 +583,7 @@ impl<T: EthSpec> std::fmt::Display for RPCCodedResponse<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
RPCCodedResponse::Success(res) => write!(f, "{}", res),
RPCCodedResponse::Error(code, err) => write!(f, "{}: {}", code, err.to_string()),
RPCCodedResponse::Error(code, err) => write!(f, "{}: {}", code, err),
RPCCodedResponse::StreamTermination(_) => write!(f, "Stream Termination"),
}
}

View File

@@ -2,11 +2,10 @@ use super::methods::*;
use super::protocol::ProtocolId;
use super::protocol::SupportedProtocol;
use super::RPCError;
use crate::rpc::protocol::Encoding;
use crate::rpc::{
codec::{base::BaseOutboundCodec, ssz_snappy::SSZSnappyOutboundCodec, OutboundCodec},
methods::ResponseTermination,
use crate::rpc::codec::{
base::BaseOutboundCodec, ssz_snappy::SSZSnappyOutboundCodec, OutboundCodec,
};
use crate::rpc::protocol::Encoding;
use futures::future::BoxFuture;
use futures::prelude::{AsyncRead, AsyncWrite};
use futures::{FutureExt, SinkExt};

View File

@@ -1,8 +1,5 @@
use super::methods::*;
use crate::rpc::{
codec::{base::BaseInboundCodec, ssz_snappy::SSZSnappyInboundCodec, InboundCodec},
methods::{MaxErrorLen, ResponseTermination, MAX_ERROR_LEN},
};
use crate::rpc::codec::{base::BaseInboundCodec, ssz_snappy::SSZSnappyInboundCodec, InboundCodec};
use futures::future::BoxFuture;
use futures::prelude::{AsyncRead, AsyncWrite};
use futures::{FutureExt, StreamExt};

View File

@@ -3,7 +3,6 @@ use crate::rpc::Protocol;
use fnv::FnvHashMap;
use libp2p::PeerId;
use serde::{Deserialize, Serialize};
use std::convert::TryInto;
use std::future::Future;
use std::hash::Hash;
use std::pin::Pin;

View File

@@ -268,8 +268,6 @@ impl futures::stream::Stream for GossipCache {
#[cfg(test)]
mod tests {
use crate::types::GossipKind;
use super::*;
use futures::stream::StreamExt;

View File

@@ -5,7 +5,6 @@ use crate::types::{GossipEncoding, GossipKind, GossipTopic};
use crate::TopicHash;
use snap::raw::{decompress_len, Decoder, Encoder};
use ssz::{Decode, Encode};
use std::boxed::Box;
use std::io::{Error, ErrorKind};
use std::sync::Arc;
use types::{