mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
Move PeersHandleProvider to new module reth_network_api::test_utils (#10060)
This commit is contained in:
3
Cargo.lock
generated
3
Cargo.lock
generated
@ -7560,6 +7560,7 @@ dependencies = [
|
||||
"alloy-primitives",
|
||||
"alloy-rpc-types-admin",
|
||||
"auto_impl",
|
||||
"derive_more",
|
||||
"enr",
|
||||
"futures",
|
||||
"reth-eth-wire-types",
|
||||
@ -7609,7 +7610,6 @@ dependencies = [
|
||||
name = "reth-network-types"
|
||||
version = "1.0.3"
|
||||
dependencies = [
|
||||
"derive_more",
|
||||
"humantime-serde",
|
||||
"reth-ethereum-forks",
|
||||
"reth-net-banlist",
|
||||
@ -7617,7 +7617,6 @@ dependencies = [
|
||||
"reth-network-peers",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tokio",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
|
||||
@ -127,7 +127,9 @@ pub mod tasks {
|
||||
/// Re-exported from `reth_network`.
|
||||
pub mod network {
|
||||
pub use reth_network::*;
|
||||
pub use reth_network_api::{noop, NetworkInfo, Peers, PeersHandleProvider, PeersInfo};
|
||||
pub use reth_network_api::{
|
||||
noop, test_utils::PeersHandleProvider, NetworkInfo, Peers, PeersInfo,
|
||||
};
|
||||
}
|
||||
|
||||
/// Re-exported from `reth_transaction_pool`.
|
||||
|
||||
@ -33,6 +33,7 @@ thiserror.workspace = true
|
||||
serde = { workspace = true, features = ["derive"], optional = true }
|
||||
tokio = { workspace = true, features = ["sync"] }
|
||||
auto_impl.workspace = true
|
||||
derive_more.workspace = true
|
||||
|
||||
[features]
|
||||
default = ["serde"]
|
||||
|
||||
@ -18,10 +18,11 @@ pub mod downloaders;
|
||||
pub mod error;
|
||||
/// Implementation of network traits for that does nothing.
|
||||
pub mod noop;
|
||||
pub mod test_utils;
|
||||
|
||||
pub use alloy_rpc_types_admin::EthProtocolInfo;
|
||||
pub use reth_network_p2p::BlockClient;
|
||||
pub use reth_network_types::{PeerKind, PeersHandle, Reputation, ReputationChangeKind};
|
||||
pub use reth_network_types::{PeerKind, Reputation, ReputationChangeKind};
|
||||
|
||||
pub use downloaders::BlockDownloaderProvider;
|
||||
pub use error::NetworkError;
|
||||
@ -162,15 +163,6 @@ pub trait Peers: PeersInfo {
|
||||
) -> impl Future<Output = Result<Option<Reputation>, NetworkError>> + Send;
|
||||
}
|
||||
|
||||
/// Provides an API for managing the peers of the network.
|
||||
#[auto_impl::auto_impl(&, Arc)]
|
||||
pub trait PeersHandleProvider {
|
||||
/// Returns the [`PeersHandle`] that can be cloned and shared.
|
||||
///
|
||||
/// The [`PeersHandle`] can be used to interact with the network's peer set.
|
||||
fn peers_handle(&self) -> &PeersHandle;
|
||||
}
|
||||
|
||||
/// Info about an active peer session.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct PeerInfo {
|
||||
|
||||
5
crates/net/network-api/src/test_utils/mod.rs
Normal file
5
crates/net/network-api/src/test_utils/mod.rs
Normal file
@ -0,0 +1,5 @@
|
||||
//! API for integration testing network components.
|
||||
|
||||
pub mod peers_manager;
|
||||
|
||||
pub use peers_manager::{PeerCommand, PeersHandle, PeersHandleProvider};
|
||||
@ -1,12 +1,21 @@
|
||||
//! Async peer handle.
|
||||
//! Interaction with `reth_network::PeersManager`, for integration testing. Otherwise
|
||||
//! `reth_network::NetworkManager` manages `reth_network::PeersManager`.
|
||||
|
||||
use std::net::SocketAddr;
|
||||
|
||||
use derive_more::Constructor;
|
||||
use reth_network_peers::{NodeRecord, PeerId};
|
||||
use reth_network_types::{Peer, ReputationChangeKind};
|
||||
use tokio::sync::{mpsc, oneshot};
|
||||
|
||||
use crate::{Peer, PeerCommand, ReputationChangeKind};
|
||||
/// Provides an API for managing the peers of the network.
|
||||
#[auto_impl::auto_impl(&, Arc)]
|
||||
pub trait PeersHandleProvider {
|
||||
/// Returns the [`PeersHandle`] that can be cloned and shared.
|
||||
///
|
||||
/// The [`PeersHandle`] can be used to interact with the network's peer set.
|
||||
fn peers_handle(&self) -> &PeersHandle;
|
||||
}
|
||||
|
||||
/// A communication channel to the `PeersManager` to apply manual changes to the peer set.
|
||||
#[derive(Clone, Debug, Constructor)]
|
||||
@ -53,3 +62,20 @@ impl PeersHandle {
|
||||
rx.await.unwrap_or_default()
|
||||
}
|
||||
}
|
||||
|
||||
/// Commands the `PeersManager` listens for.
|
||||
#[derive(Debug)]
|
||||
pub enum PeerCommand {
|
||||
/// Command for manually add
|
||||
Add(PeerId, SocketAddr),
|
||||
/// Remove a peer from the set
|
||||
///
|
||||
/// If currently connected this will disconnect the session
|
||||
Remove(PeerId),
|
||||
/// Apply a reputation change to the given peer.
|
||||
ReputationChange(PeerId, ReputationChangeKind),
|
||||
/// Get information about a peer
|
||||
GetPeer(PeerId, oneshot::Sender<Option<Peer>>),
|
||||
/// Get node information on all peers
|
||||
GetPeers(oneshot::Sender<Vec<NodeRecord>>),
|
||||
}
|
||||
@ -16,9 +16,6 @@ workspace = true
|
||||
reth-network-peers.workspace = true
|
||||
reth-net-banlist.workspace = true
|
||||
reth-ethereum-forks.workspace = true
|
||||
|
||||
# async
|
||||
tokio = { workspace = true, features = ["sync"] }
|
||||
reth-network-p2p.workspace = true
|
||||
|
||||
# io
|
||||
@ -28,7 +25,6 @@ serde_json = { workspace = true }
|
||||
|
||||
# misc
|
||||
tracing.workspace = true
|
||||
derive_more.workspace = true
|
||||
|
||||
[features]
|
||||
serde = ["dep:serde", "dep:humantime-serde", "reth-network-p2p/serde"]
|
||||
|
||||
@ -24,10 +24,9 @@ pub use reth_network_p2p::reputation::{Reputation, ReputationChangeKind, Reputat
|
||||
pub use backoff::BackoffKind;
|
||||
pub use peers::{
|
||||
addr::PeerAddr,
|
||||
handle::PeersHandle,
|
||||
kind::PeerKind,
|
||||
reputation::{is_banned_reputation, ReputationChangeOutcome, DEFAULT_REPUTATION},
|
||||
state::PeerConnectionState,
|
||||
ConnectionsConfig, Peer, PeerCommand, PeersConfig,
|
||||
ConnectionsConfig, Peer, PeersConfig,
|
||||
};
|
||||
pub use session::{SessionLimits, SessionsConfig};
|
||||
|
||||
@ -1,25 +0,0 @@
|
||||
//! Commands sent to peer manager.
|
||||
|
||||
use std::net::SocketAddr;
|
||||
|
||||
use reth_network_peers::{NodeRecord, PeerId};
|
||||
use tokio::sync::oneshot;
|
||||
|
||||
use crate::{Peer, ReputationChangeKind};
|
||||
|
||||
/// Commands the `PeersManager` listens for.
|
||||
#[derive(Debug)]
|
||||
pub enum PeerCommand {
|
||||
/// Command for manually add
|
||||
Add(PeerId, SocketAddr),
|
||||
/// Remove a peer from the set
|
||||
///
|
||||
/// If currently connected this will disconnect the session
|
||||
Remove(PeerId),
|
||||
/// Apply a reputation change to the given peer.
|
||||
ReputationChange(PeerId, ReputationChangeKind),
|
||||
/// Get information about a peer
|
||||
GetPeer(PeerId, oneshot::Sender<Option<Peer>>),
|
||||
/// Get node information on all peers
|
||||
GetPeers(oneshot::Sender<Vec<NodeRecord>>),
|
||||
}
|
||||
@ -1,13 +1,10 @@
|
||||
pub mod addr;
|
||||
pub mod cmd;
|
||||
pub mod config;
|
||||
pub mod handle;
|
||||
pub mod kind;
|
||||
pub mod state;
|
||||
|
||||
pub use reth_network_p2p::reputation;
|
||||
|
||||
pub use cmd::PeerCommand;
|
||||
pub use config::{ConnectionsConfig, PeersConfig};
|
||||
pub use reputation::ReputationChangeWeights;
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
//! Builder support for configuring the entire setup.
|
||||
|
||||
use reth_network_api::PeersHandleProvider;
|
||||
use reth_network_api::test_utils::PeersHandleProvider;
|
||||
use reth_transaction_pool::TransactionPool;
|
||||
use tokio::sync::mpsc;
|
||||
|
||||
|
||||
@ -13,9 +13,9 @@ use reth_eth_wire::{
|
||||
BlockBodies, BlockHeaders, GetBlockBodies, GetBlockHeaders, GetNodeData, GetReceipts,
|
||||
HeadersDirection, NodeData, Receipts,
|
||||
};
|
||||
use reth_network_api::test_utils::PeersHandle;
|
||||
use reth_network_p2p::error::RequestResult;
|
||||
use reth_network_peers::PeerId;
|
||||
use reth_network_types::PeersHandle;
|
||||
use reth_primitives::{BlockBody, BlockHashOrNumber, Header};
|
||||
use reth_storage_api::{BlockReader, HeaderProvider, ReceiptProvider};
|
||||
use tokio::sync::{mpsc::Receiver, oneshot};
|
||||
|
||||
@ -6,6 +6,7 @@ use std::sync::{
|
||||
};
|
||||
|
||||
use futures::{future, future::Either};
|
||||
use reth_network_api::test_utils::PeersHandle;
|
||||
use reth_network_p2p::{
|
||||
bodies::client::{BodiesClient, BodiesFut},
|
||||
download::DownloadClient,
|
||||
@ -14,7 +15,7 @@ use reth_network_p2p::{
|
||||
priority::Priority,
|
||||
};
|
||||
use reth_network_peers::PeerId;
|
||||
use reth_network_types::{PeersHandle, ReputationChangeKind};
|
||||
use reth_network_types::ReputationChangeKind;
|
||||
use reth_primitives::{Header, B256};
|
||||
use tokio::sync::{mpsc::UnboundedSender, oneshot};
|
||||
|
||||
|
||||
@ -15,13 +15,14 @@ use std::{
|
||||
|
||||
use futures::StreamExt;
|
||||
use reth_eth_wire::{GetBlockBodies, GetBlockHeaders};
|
||||
use reth_network_api::test_utils::PeersHandle;
|
||||
use reth_network_p2p::{
|
||||
error::{EthResponseValidator, PeerRequestResult, RequestError, RequestResult},
|
||||
headers::client::HeadersRequest,
|
||||
priority::Priority,
|
||||
};
|
||||
use reth_network_peers::PeerId;
|
||||
use reth_network_types::{PeersHandle, ReputationChangeKind};
|
||||
use reth_network_types::ReputationChangeKind;
|
||||
use reth_primitives::{BlockBody, Header, B256};
|
||||
use tokio::sync::{mpsc, mpsc::UnboundedSender, oneshot};
|
||||
use tokio_stream::wrappers::UnboundedReceiverStream;
|
||||
|
||||
@ -138,9 +138,7 @@ mod state;
|
||||
mod swarm;
|
||||
|
||||
pub use reth_eth_wire::{DisconnectReason, HelloMessageWithProtocols};
|
||||
pub use reth_network_api::{
|
||||
BlockDownloaderProvider, NetworkInfo, Peers, PeersHandleProvider, PeersInfo,
|
||||
};
|
||||
pub use reth_network_api::{BlockDownloaderProvider, NetworkInfo, Peers, PeersInfo};
|
||||
pub use reth_network_p2p::sync::{NetworkSyncUpdater, SyncState};
|
||||
pub use reth_network_types::{PeersConfig, SessionsConfig};
|
||||
pub use session::{
|
||||
|
||||
@ -34,9 +34,9 @@ use reth_eth_wire::{
|
||||
};
|
||||
use reth_fs_util::{self as fs, FsPathError};
|
||||
use reth_metrics::common::mpsc::UnboundedMeteredSender;
|
||||
use reth_network_api::{EthProtocolInfo, NetworkStatus, PeerInfo};
|
||||
use reth_network_api::{test_utils::PeersHandle, EthProtocolInfo, NetworkStatus, PeerInfo};
|
||||
use reth_network_peers::{NodeRecord, PeerId};
|
||||
use reth_network_types::{PeerAddr, PeersHandle, ReputationChangeKind};
|
||||
use reth_network_types::{PeerAddr, ReputationChangeKind};
|
||||
use reth_primitives::ForkId;
|
||||
use reth_storage_api::BlockNumReader;
|
||||
use reth_tasks::shutdown::GracefulShutdown;
|
||||
|
||||
@ -11,15 +11,15 @@ use parking_lot::Mutex;
|
||||
use reth_discv4::Discv4;
|
||||
use reth_eth_wire::{DisconnectReason, NewBlock, NewPooledTransactionHashes, SharedTransactions};
|
||||
use reth_network_api::{
|
||||
BlockDownloaderProvider, NetworkError, NetworkInfo, NetworkStatus, PeerInfo, Peers,
|
||||
PeersHandleProvider, PeersInfo,
|
||||
test_utils::{PeersHandle, PeersHandleProvider},
|
||||
BlockDownloaderProvider, NetworkError, NetworkInfo, NetworkStatus, PeerInfo, Peers, PeersInfo,
|
||||
};
|
||||
use reth_network_p2p::{
|
||||
sync::{NetworkSyncUpdater, SyncState, SyncStateProvider},
|
||||
BlockClient,
|
||||
};
|
||||
use reth_network_peers::{NodeRecord, PeerId};
|
||||
use reth_network_types::{PeerAddr, PeerKind, PeersHandle, Reputation, ReputationChangeKind};
|
||||
use reth_network_types::{PeerAddr, PeerKind, Reputation, ReputationChangeKind};
|
||||
use reth_primitives::{Head, TransactionSigned, B256};
|
||||
use reth_tokio_util::{EventSender, EventStream};
|
||||
use secp256k1::SecretKey;
|
||||
|
||||
@ -12,14 +12,15 @@ use std::{
|
||||
use futures::StreamExt;
|
||||
use reth_eth_wire::{errors::EthStreamError, DisconnectReason};
|
||||
use reth_net_banlist::BanList;
|
||||
use reth_network_api::test_utils::{PeerCommand, PeersHandle};
|
||||
use reth_network_peers::{NodeRecord, PeerId};
|
||||
use reth_network_types::{
|
||||
peers::{
|
||||
config::PeerBackoffDurations,
|
||||
reputation::{DEFAULT_REPUTATION, MAX_TRUSTED_PEER_REPUTATION_CHANGE},
|
||||
},
|
||||
ConnectionsConfig, Peer, PeerAddr, PeerCommand, PeerConnectionState, PeerKind, PeersConfig,
|
||||
PeersHandle, ReputationChangeKind, ReputationChangeOutcome, ReputationChangeWeights,
|
||||
ConnectionsConfig, Peer, PeerAddr, PeerConnectionState, PeerKind, PeersConfig,
|
||||
ReputationChangeKind, ReputationChangeOutcome, ReputationChangeWeights,
|
||||
};
|
||||
use reth_primitives::ForkId;
|
||||
use thiserror::Error;
|
||||
|
||||
@ -12,9 +12,11 @@ use futures::{FutureExt, StreamExt};
|
||||
use pin_project::pin_project;
|
||||
use reth_chainspec::MAINNET;
|
||||
use reth_eth_wire::{protocol::Protocol, DisconnectReason, HelloMessageWithProtocols};
|
||||
use reth_network_api::{NetworkInfo, Peers, PeersHandleProvider};
|
||||
use reth_network_api::{
|
||||
test_utils::{PeersHandle, PeersHandleProvider},
|
||||
NetworkInfo, Peers,
|
||||
};
|
||||
use reth_network_peers::PeerId;
|
||||
use reth_network_types::PeersHandle;
|
||||
use reth_provider::test_utils::NoopProvider;
|
||||
use reth_storage_api::{BlockReader, BlockReaderIdExt, HeaderProvider, StateProviderFactory};
|
||||
use reth_tasks::TokioTaskExecutor;
|
||||
|
||||
@ -15,9 +15,9 @@ use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4};
|
||||
use reth::builder::NodeHandle;
|
||||
use reth_network::{
|
||||
config::SecretKey, protocol::IntoRlpxSubProtocol, NetworkConfig, NetworkManager,
|
||||
NetworkProtocols, PeersHandleProvider,
|
||||
NetworkProtocols,
|
||||
};
|
||||
use reth_network_api::NetworkInfo;
|
||||
use reth_network_api::{test_utils::PeersHandleProvider, NetworkInfo};
|
||||
use reth_node_ethereum::EthereumNode;
|
||||
use reth_provider::test_utils::NoopProvider;
|
||||
use subprotocol::{
|
||||
|
||||
Reference in New Issue
Block a user