diff --git a/Cargo.lock b/Cargo.lock index cef138ba1..cf72d69fd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6066,7 +6066,6 @@ dependencies = [ "alloy-rlp", "arbitrary", "async-stream", - "async-trait", "bytes", "derive_more", "ethers-core", diff --git a/crates/net/eth-wire/Cargo.toml b/crates/net/eth-wire/Cargo.toml index 7ad4c2ac8..7bf89f3b2 100644 --- a/crates/net/eth-wire/Cargo.toml +++ b/crates/net/eth-wire/Cargo.toml @@ -35,7 +35,6 @@ tokio-stream.workspace = true pin-project.workspace = true tracing.workspace = true snap = "1.0.5" -async-trait.workspace = true # arbitrary utils arbitrary = { workspace = true, features = ["derive"], optional = true } diff --git a/crates/net/eth-wire/src/disconnect.rs b/crates/net/eth-wire/src/disconnect.rs index b3d5867bf..986028c51 100644 --- a/crates/net/eth-wire/src/disconnect.rs +++ b/crates/net/eth-wire/src/disconnect.rs @@ -5,7 +5,7 @@ use futures::{Sink, SinkExt}; use reth_codecs::derive_arbitrary; use reth_ecies::stream::ECIESStream; use reth_primitives::bytes::{Buf, BufMut}; -use std::fmt::Display; +use std::{fmt::Display, future::Future}; use thiserror::Error; use tokio::io::AsyncWrite; use tokio_util::codec::{Encoder, Framed}; @@ -149,19 +149,17 @@ impl Decodable for DisconnectReason { /// This trait is meant to allow higher level protocols like `eth` to disconnect from a peer, using /// lower-level disconnect functions (such as those that exist in the `p2p` protocol) if the /// underlying stream supports it. -#[async_trait::async_trait] pub trait CanDisconnect: Sink + Unpin { /// Disconnects from the underlying stream, using a [`DisconnectReason`] as disconnect /// information if the stream implements a protocol that can carry the additional disconnect /// metadata. - async fn disconnect( + fn disconnect( &mut self, reason: DisconnectReason, - ) -> Result<(), >::Error>; + ) -> impl Future>::Error>> + Send; } // basic impls for things like Framed -#[async_trait::async_trait] impl CanDisconnect for Framed where T: AsyncWrite + Unpin + Send, @@ -175,7 +173,6 @@ where } } -#[async_trait::async_trait] impl CanDisconnect for ECIESStream where S: AsyncWrite + Unpin + Send, diff --git a/crates/net/eth-wire/src/ethstream.rs b/crates/net/eth-wire/src/ethstream.rs index 9a4539693..a482976bd 100644 --- a/crates/net/eth-wire/src/ethstream.rs +++ b/crates/net/eth-wire/src/ethstream.rs @@ -315,7 +315,6 @@ where } } -#[async_trait::async_trait] impl CanDisconnect for EthStream where S: CanDisconnect + Send, diff --git a/crates/net/eth-wire/src/multiplex.rs b/crates/net/eth-wire/src/multiplex.rs index 40e3d234b..73dd40c00 100644 --- a/crates/net/eth-wire/src/multiplex.rs +++ b/crates/net/eth-wire/src/multiplex.rs @@ -354,7 +354,6 @@ impl Sink for ProtocolProxy { } } -#[async_trait::async_trait] impl CanDisconnect for ProtocolProxy { async fn disconnect( &mut self, diff --git a/crates/net/eth-wire/src/muxdemux.rs b/crates/net/eth-wire/src/muxdemux.rs index 8b173f47f..01bcf285d 100644 --- a/crates/net/eth-wire/src/muxdemux.rs +++ b/crates/net/eth-wire/src/muxdemux.rs @@ -280,7 +280,6 @@ where } } -#[async_trait::async_trait] impl CanDisconnect for MuxDemuxStream where S: Sink + CanDisconnect + Unpin + Send + Sync, @@ -344,7 +343,6 @@ impl Sink for StreamClone { } } -#[async_trait::async_trait] impl CanDisconnect for StreamClone { async fn disconnect(&mut self, _reason: DisconnectReason) -> Result<(), MuxDemuxError> { Err(CannotDisconnectP2PStream) diff --git a/crates/net/eth-wire/src/p2pstream.rs b/crates/net/eth-wire/src/p2pstream.rs index eef45f44d..49ccd7b64 100644 --- a/crates/net/eth-wire/src/p2pstream.rs +++ b/crates/net/eth-wire/src/p2pstream.rs @@ -195,7 +195,6 @@ where } } -#[async_trait::async_trait] impl CanDisconnect for P2PStream where S: Sink + Unpin + Send + Sync, diff --git a/crates/net/network-api/src/lib.rs b/crates/net/network-api/src/lib.rs index 4afa7673f..c27be7ed6 100644 --- a/crates/net/network-api/src/lib.rs +++ b/crates/net/network-api/src/lib.rs @@ -13,11 +13,10 @@ )] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] -use async_trait::async_trait; use reth_eth_wire::{DisconnectReason, EthVersion, Status}; use reth_primitives::{NodeRecord, PeerId}; use reth_rpc_types::NetworkStatus; -use std::{net::SocketAddr, sync::Arc, time::Instant}; +use std::{future::Future, net::SocketAddr, sync::Arc, time::Instant}; pub use error::NetworkError; pub use reputation::{Reputation, ReputationChangeKind}; @@ -32,13 +31,12 @@ pub mod reputation; pub mod noop; /// Provides general purpose information about the network. -#[async_trait] pub trait NetworkInfo: Send + Sync { /// Returns the [`SocketAddr`] that listens for incoming connections. fn local_addr(&self) -> SocketAddr; /// Returns the current status of the network being ran by the local node. - async fn network_status(&self) -> Result; + fn network_status(&self) -> impl Future> + Send; /// Returns the chain id fn chain_id(&self) -> u64; @@ -66,7 +64,6 @@ pub trait PeersInfo: Send + Sync { } /// Provides an API for managing the peers of the network. -#[async_trait] pub trait Peers: PeersInfo { /// Adds a peer to the peer set. fn add_peer(&self, peer: PeerId, addr: SocketAddr) { @@ -82,31 +79,42 @@ pub trait Peers: PeersInfo { fn add_peer_kind(&self, peer: PeerId, kind: PeerKind, addr: SocketAddr); /// Returns the rpc [PeerInfo] for all connected [PeerKind::Trusted] peers. - async fn get_trusted_peers(&self) -> Result, NetworkError> { - self.get_peers_by_kind(PeerKind::Trusted).await + fn get_trusted_peers( + &self, + ) -> impl Future, NetworkError>> + Send { + self.get_peers_by_kind(PeerKind::Trusted) } /// Returns the rpc [PeerInfo] for all connected [PeerKind::Basic] peers. - async fn get_basic_peers(&self) -> Result, NetworkError> { - self.get_peers_by_kind(PeerKind::Basic).await + fn get_basic_peers(&self) -> impl Future, NetworkError>> + Send { + self.get_peers_by_kind(PeerKind::Basic) } /// Returns the rpc [PeerInfo] for all connected peers with the given kind. - async fn get_peers_by_kind(&self, kind: PeerKind) -> Result, NetworkError>; + fn get_peers_by_kind( + &self, + kind: PeerKind, + ) -> impl Future, NetworkError>> + Send; /// Returns the rpc [PeerInfo] for all connected peers. - async fn get_all_peers(&self) -> Result, NetworkError>; + fn get_all_peers(&self) -> impl Future, NetworkError>> + Send; /// Returns the rpc [PeerInfo] for the given peer id. /// /// Returns `None` if the peer is not connected. - async fn get_peer_by_id(&self, peer_id: PeerId) -> Result, NetworkError>; + fn get_peer_by_id( + &self, + peer_id: PeerId, + ) -> impl Future, NetworkError>> + Send; /// Returns the rpc [PeerInfo] for the given peers if they are connected. /// /// Note: This only returns peers that are connected, unconnected peers are ignored but keeping /// the order in which they were requested. - async fn get_peers_by_id(&self, peer_ids: Vec) -> Result, NetworkError>; + fn get_peers_by_id( + &self, + peer_ids: Vec, + ) -> impl Future, NetworkError>> + Send; /// Removes a peer from the peer set that corresponds to given kind. fn remove_peer(&self, peer: PeerId, kind: PeerKind); @@ -121,7 +129,10 @@ pub trait Peers: PeersInfo { fn reputation_change(&self, peer_id: PeerId, kind: ReputationChangeKind); /// Get the reputation of a peer. - async fn reputation_by_id(&self, peer_id: PeerId) -> Result, NetworkError>; + fn reputation_by_id( + &self, + peer_id: PeerId, + ) -> impl Future, NetworkError>> + Send; } /// Represents the kind of peer diff --git a/crates/net/network-api/src/noop.rs b/crates/net/network-api/src/noop.rs index 866010d4b..29d0d5efa 100644 --- a/crates/net/network-api/src/noop.rs +++ b/crates/net/network-api/src/noop.rs @@ -8,7 +8,6 @@ use crate::{ ReputationChangeKind, }; use alloy_chains::Chain; -use async_trait::async_trait; use reth_discv4::DEFAULT_DISCOVERY_PORT; use reth_eth_wire::{DisconnectReason, ProtocolVersion}; use reth_primitives::{NodeRecord, PeerId}; @@ -22,7 +21,6 @@ use std::net::{IpAddr, SocketAddr}; #[non_exhaustive] pub struct NoopNetwork; -#[async_trait] impl NetworkInfo for NoopNetwork { fn local_addr(&self) -> SocketAddr { (IpAddr::from(std::net::Ipv4Addr::UNSPECIFIED), DEFAULT_DISCOVERY_PORT).into() @@ -69,7 +67,6 @@ impl PeersInfo for NoopNetwork { } } -#[async_trait] impl Peers for NoopNetwork { fn add_peer_kind(&self, _peer: PeerId, _kind: PeerKind, _addr: SocketAddr) {} diff --git a/crates/net/network/src/network.rs b/crates/net/network/src/network.rs index 14514253e..903fd99d2 100644 --- a/crates/net/network/src/network.rs +++ b/crates/net/network/src/network.rs @@ -2,7 +2,6 @@ use crate::{ config::NetworkMode, discovery::DiscoveryEvent, manager::NetworkEvent, message::PeerRequest, peers::PeersHandle, protocol::RlpxSubProtocol, swarm::NetworkConnectionState, FetchClient, }; -use async_trait::async_trait; use parking_lot::Mutex; use reth_eth_wire::{DisconnectReason, NewBlock, NewPooledTransactionHashes, SharedTransactions}; use reth_interfaces::sync::{NetworkSyncUpdater, SyncState, SyncStateProvider}; @@ -226,7 +225,6 @@ impl PeersInfo for NetworkHandle { } } -#[async_trait] impl Peers for NetworkHandle { /// Sends a message to the [`NetworkManager`](crate::NetworkManager) to add a peer to the known /// set, with the given kind. @@ -288,7 +286,6 @@ impl Peers for NetworkHandle { } } -#[async_trait] impl NetworkInfo for NetworkHandle { fn local_addr(&self) -> SocketAddr { *self.inner.listener_address.lock()