From e6f2dca445be81318900fe593a0fb2f73865067c Mon Sep 17 00:00:00 2001 From: Tuan Tran Date: Wed, 17 Jul 2024 00:40:10 +0700 Subject: [PATCH] chore(net): enable rust.unnameable-types = "warn" lint (#9505) --- Cargo.toml | 1 + crates/net/dns/src/lib.rs | 2 +- crates/net/ecies/src/error.rs | 2 +- crates/net/ecies/src/lib.rs | 2 +- crates/net/eth-wire/src/lib.rs | 2 ++ crates/net/network/src/lib.rs | 5 +++++ crates/net/network/src/manager.rs | 22 +++++++++++++++++++++- crates/net/network/src/metrics.rs | 13 +++++++++++++ crates/net/network/src/session/conn.rs | 6 ++++-- crates/net/network/src/session/mod.rs | 2 +- crates/net/network/src/test_utils/mod.rs | 2 +- 11 files changed, 51 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9461d605fb..9efae389be 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -152,6 +152,7 @@ rust.unreachable_pub = "warn" rust.unused_must_use = "deny" rust.rust_2018_idioms = { level = "deny", priority = -1 } rustdoc.all = "warn" +# rust.unnameable-types = "warn" [workspace.lints.clippy] # These are some of clippy's nursery (i.e., experimental) lints that we like. diff --git a/crates/net/dns/src/lib.rs b/crates/net/dns/src/lib.rs index 55d93c459c..a6f7d1bab1 100644 --- a/crates/net/dns/src/lib.rs +++ b/crates/net/dns/src/lib.rs @@ -21,7 +21,7 @@ use crate::{ }; pub use config::DnsDiscoveryConfig; use enr::Enr; -use error::ParseDnsEntryError; +pub use error::ParseDnsEntryError; use reth_ethereum_forks::{EnrForkIdEntry, ForkId}; use reth_network_peers::{pk2id, NodeRecord}; use schnellru::{ByLength, LruMap}; diff --git a/crates/net/ecies/src/error.rs b/crates/net/ecies/src/error.rs index 424431119c..f476e00c4c 100644 --- a/crates/net/ecies/src/error.rs +++ b/crates/net/ecies/src/error.rs @@ -81,7 +81,7 @@ pub enum ECIESErrorImpl { /// decode a message from the (partially filled) buffer. #[error("stream closed due to not being readable")] UnreadableStream, - // Error when data is not received from peer for a prolonged period. + /// Error when data is not received from peer for a prolonged period. #[error("never received data from remote peer")] StreamTimeout, } diff --git a/crates/net/ecies/src/lib.rs b/crates/net/ecies/src/lib.rs index f766b48b21..b2dcdac670 100644 --- a/crates/net/ecies/src/lib.rs +++ b/crates/net/ecies/src/lib.rs @@ -14,7 +14,7 @@ pub mod stream; pub mod util; mod error; -pub use error::ECIESError; +pub use error::{ECIESError, ECIESErrorImpl}; pub mod codec; diff --git a/crates/net/eth-wire/src/lib.rs b/crates/net/eth-wire/src/lib.rs index e96a27077f..7788f603bc 100644 --- a/crates/net/eth-wire/src/lib.rs +++ b/crates/net/eth-wire/src/lib.rs @@ -45,3 +45,5 @@ pub use crate::{ // Re-export wire types #[doc(inline)] pub use reth_eth_wire_types::*; + +pub use disconnect::UnknownDisconnectReason; diff --git a/crates/net/network/src/lib.rs b/crates/net/network/src/lib.rs index 28dd6932bc..a22dbd532f 100644 --- a/crates/net/network/src/lib.rs +++ b/crates/net/network/src/lib.rs @@ -151,5 +151,10 @@ pub use session::{ pub use transactions::{FilterAnnouncement, MessageFilter, ValidateTx68}; +pub use flattened_response::FlattenedResponse; +pub use manager::DiscoveredEvent; +pub use metrics::TxTypesCounter; pub use reth_eth_wire::{DisconnectReason, HelloMessageWithProtocols}; pub use reth_network_types::{PeersConfig, SessionsConfig}; +pub use session::EthRlpxConnection; +pub use swarm::NetworkConnectionState; diff --git a/crates/net/network/src/manager.rs b/crates/net/network/src/manager.rs index 97d133116d..6f670db9c2 100644 --- a/crates/net/network/src/manager.rs +++ b/crates/net/network/src/manager.rs @@ -1077,9 +1077,29 @@ pub enum NetworkEvent { PeerRemoved(PeerId), } +/// Represents events related to peer discovery in the network. #[derive(Debug, Clone, PartialEq, Eq)] pub enum DiscoveredEvent { - EventQueued { peer_id: PeerId, addr: PeerAddr, fork_id: Option }, + /// Indicates that a new peer has been discovered and queued for potential connection. + /// + /// This event is generated when the system becomes aware of a new peer + /// but hasn't yet established a connection. + /// + /// # Fields + /// + /// * `peer_id` - The unique identifier of the discovered peer. + /// * `addr` - The network address of the discovered peer. + /// * `fork_id` - An optional identifier for the fork that this peer is associated with. `None` + /// if the peer is not associated with a specific fork. + EventQueued { + /// The unique identifier of the discovered peer. + peer_id: PeerId, + /// The network address of the discovered peer. + addr: PeerAddr, + /// An optional identifier for the fork that this peer is associated with. + /// `None` if the peer is not associated with a specific fork. + fork_id: Option, + }, } #[derive(Debug, Default)] diff --git a/crates/net/network/src/metrics.rs b/crates/net/network/src/metrics.rs index 71cd9f0795..8f7b34617d 100644 --- a/crates/net/network/src/metrics.rs +++ b/crates/net/network/src/metrics.rs @@ -347,12 +347,25 @@ pub struct AnnouncedTxTypesMetrics { pub(crate) eip7702: Histogram, } +/// Counts the number of transactions by their type in a block or collection. +/// +/// This struct keeps track of the count of different transaction types +/// as defined by various Ethereum Improvement Proposals (EIPs). #[derive(Debug, Default)] pub struct TxTypesCounter { + /// Count of legacy transactions (pre-EIP-2718). pub(crate) legacy: usize, + + /// Count of transactions conforming to EIP-2930 (Optional access lists). pub(crate) eip2930: usize, + + /// Count of transactions conforming to EIP-1559 (Fee market change). pub(crate) eip1559: usize, + + /// Count of transactions conforming to EIP-4844 (Shard Blob Transactions). pub(crate) eip4844: usize, + + /// Count of transactions conforming to EIP-7702 (Restricted Storage Windows). pub(crate) eip7702: usize, } diff --git a/crates/net/network/src/session/conn.rs b/crates/net/network/src/session/conn.rs index 0da22e9262..fce7b3908d 100644 --- a/crates/net/network/src/session/conn.rs +++ b/crates/net/network/src/session/conn.rs @@ -23,12 +23,14 @@ pub type EthSatelliteConnection = /// Connection types that support the ETH protocol. /// -/// Either a [`EthPeerConnection`] or an [`EthSatelliteConnection`]. +/// This can be either: +/// - A connection that only supports the ETH protocol +/// - A connection that supports the ETH protocol and at least one other `RLPx` protocol // This type is boxed because the underlying stream is ~6KB, // mostly coming from `P2PStream`'s `snap::Encoder` (2072), and `ECIESStream` (3600). #[derive(Debug)] pub enum EthRlpxConnection { - /// A That only supports the ETH protocol. + /// A connection that only supports the ETH protocol. EthOnly(Box), /// A connection that supports the ETH protocol and __at least one other__ `RLPx` protocol. Satellite(Box), diff --git a/crates/net/network/src/session/mod.rs b/crates/net/network/src/session/mod.rs index fc6f0e6a1f..5f01b8dada 100644 --- a/crates/net/network/src/session/mod.rs +++ b/crates/net/network/src/session/mod.rs @@ -40,13 +40,13 @@ mod counter; mod handle; pub use crate::message::PeerRequestSender; use crate::protocol::{IntoRlpxSubProtocol, RlpxSubProtocolHandlers, RlpxSubProtocols}; +pub use conn::EthRlpxConnection; pub use handle::{ ActiveSessionHandle, ActiveSessionMessage, PendingSessionEvent, PendingSessionHandle, SessionCommand, }; use reth_eth_wire::multiplex::RlpxProtocolMultiplexer; pub use reth_network_api::{Direction, PeerInfo}; - /// Internal identifier for active sessions. #[derive(Debug, Clone, Copy, PartialOrd, PartialEq, Eq, Hash)] pub struct SessionId(usize); diff --git a/crates/net/network/src/test_utils/mod.rs b/crates/net/network/src/test_utils/mod.rs index 5ba8a7c7be..71639bc715 100644 --- a/crates/net/network/src/test_utils/mod.rs +++ b/crates/net/network/src/test_utils/mod.rs @@ -7,4 +7,4 @@ pub use init::{ enr_to_peer_id, unused_port, unused_tcp_addr, unused_tcp_and_udp_port, unused_tcp_udp, unused_udp_addr, unused_udp_port, GETH_TIMEOUT, }; -pub use testnet::{NetworkEventStream, Peer, PeerConfig, PeerHandle, Testnet}; +pub use testnet::{NetworkEventStream, Peer, PeerConfig, PeerHandle, Testnet, TestnetHandle};