diff --git a/Cargo.lock b/Cargo.lock index ed4de751d..8591457c0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4941,6 +4941,7 @@ dependencies = [ "reth-provider", "reth-rlp", "reth-rlp-derive", + "reth-rpc-types", "reth-tasks", "reth-tracing", "reth-transaction-pool", @@ -4963,6 +4964,7 @@ dependencies = [ "async-trait", "reth-eth-wire", "reth-primitives", + "reth-rpc-types", "serde", "thiserror", "tokio", @@ -5219,7 +5221,6 @@ dependencies = [ "lru 0.9.0", "rand 0.8.5", "reth-interfaces", - "reth-network-api", "reth-primitives", "reth-rlp", "serde", diff --git a/crates/net/network-api/Cargo.toml b/crates/net/network-api/Cargo.toml index 5afc537bd..cac269149 100644 --- a/crates/net/network-api/Cargo.toml +++ b/crates/net/network-api/Cargo.toml @@ -11,6 +11,7 @@ description = "Network interfaces" # reth reth-primitives = { path = "../../primitives" } reth-eth-wire = { path = "../eth-wire" } +reth-rpc-types = { path = "../../rpc/rpc-types" } # io serde = { version = "1.0", features = ["derive"], optional = true } diff --git a/crates/net/network-api/src/lib.rs b/crates/net/network-api/src/lib.rs index 56f959f61..a53f20952 100644 --- a/crates/net/network-api/src/lib.rs +++ b/crates/net/network-api/src/lib.rs @@ -11,12 +11,10 @@ use async_trait::async_trait; use reth_eth_wire::DisconnectReason; -use reth_primitives::{NodeRecord, PeerId, H256, U256}; +use reth_primitives::{NodeRecord, PeerId}; +use reth_rpc_types::NetworkStatus; use std::net::SocketAddr; -#[cfg(feature = "serde")] -use serde::{Deserialize, Serialize}; - pub use error::NetworkError; pub use reputation::{Reputation, ReputationChangeKind}; @@ -93,32 +91,3 @@ pub enum PeerKind { /// Trusted peer. Trusted, } - -/// The status of the network being ran by the local node. -#[derive(Clone, Debug, PartialEq, Eq)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub struct NetworkStatus { - /// The local node client version. - pub client_version: String, - /// The current ethereum protocol version - pub protocol_version: u64, - /// Information about the Ethereum Wire Protocol. - pub eth_protocol_info: EthProtocolInfo, -} -/// Information about the Ethereum Wire Protocol (ETH) -#[derive(Clone, Debug, PartialEq, Eq)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub struct EthProtocolInfo { - /// The current difficulty at the head of the chain. - #[cfg_attr( - feature = "serde", - serde(deserialize_with = "reth_primitives::serde_helper::deserialize_json_u256") - )] - pub difficulty: U256, - /// The block hash of the head of the chain. - pub head: H256, - /// Network ID in base 10. - pub network: u64, - /// Genesis block of the current chain. - pub genesis: H256, -} diff --git a/crates/net/network-api/src/test_utils.rs b/crates/net/network-api/src/test_utils.rs index 3d0950957..74e325e71 100644 --- a/crates/net/network-api/src/test_utils.rs +++ b/crates/net/network-api/src/test_utils.rs @@ -1,10 +1,8 @@ -use crate::{ - EthProtocolInfo, NetworkError, NetworkInfo, NetworkStatus, PeerKind, Peers, PeersInfo, - ReputationChangeKind, -}; +use crate::{NetworkError, NetworkInfo, PeerKind, Peers, PeersInfo, ReputationChangeKind}; use async_trait::async_trait; use reth_eth_wire::{DisconnectReason, ProtocolVersion}; use reth_primitives::{rpc::Chain::Mainnet, NodeRecord, PeerId}; +use reth_rpc_types::{EthProtocolInfo, NetworkStatus}; use std::net::{IpAddr, SocketAddr}; /// A type that implements all network trait that does nothing. diff --git a/crates/net/network/Cargo.toml b/crates/net/network/Cargo.toml index 274e2575c..97f7993af 100644 --- a/crates/net/network/Cargo.toml +++ b/crates/net/network/Cargo.toml @@ -31,6 +31,7 @@ reth-tasks = { path = "../../tasks" } reth-transaction-pool = { path = "../../transaction-pool" } reth-provider = { path = "../../storage/provider"} reth-metrics-common = { path = "../../metrics/common" } +reth-rpc-types = { path = "../../rpc/rpc-types" } # async/futures futures = "0.3" diff --git a/crates/net/network/src/manager.rs b/crates/net/network/src/manager.rs index 31d56a74c..55625a30d 100644 --- a/crates/net/network/src/manager.rs +++ b/crates/net/network/src/manager.rs @@ -39,9 +39,10 @@ use reth_eth_wire::{ DisconnectReason, EthVersion, Status, }; use reth_net_common::bandwidth_meter::BandwidthMeter; -use reth_network_api::{EthProtocolInfo, NetworkStatus, ReputationChangeKind}; +use reth_network_api::ReputationChangeKind; use reth_primitives::{NodeRecord, PeerId, H256}; use reth_provider::BlockProvider; +use reth_rpc_types::{EthProtocolInfo, NetworkStatus}; use std::{ net::SocketAddr, pin::Pin, diff --git a/crates/net/network/src/network.rs b/crates/net/network/src/network.rs index a03f7324b..19139c46d 100644 --- a/crates/net/network/src/network.rs +++ b/crates/net/network/src/network.rs @@ -11,9 +11,10 @@ use reth_interfaces::{ }; use reth_net_common::bandwidth_meter::BandwidthMeter; use reth_network_api::{ - NetworkError, NetworkInfo, NetworkStatus, PeerKind, Peers, PeersInfo, ReputationChangeKind, + NetworkError, NetworkInfo, PeerKind, Peers, PeersInfo, ReputationChangeKind, }; use reth_primitives::{Head, NodeRecord, PeerId, TransactionSigned, H256}; +use reth_rpc_types::NetworkStatus; use std::{ net::SocketAddr, sync::{ diff --git a/crates/rpc/rpc-types/Cargo.toml b/crates/rpc/rpc-types/Cargo.toml index 870ff1d77..3c6404f45 100644 --- a/crates/rpc/rpc-types/Cargo.toml +++ b/crates/rpc/rpc-types/Cargo.toml @@ -13,7 +13,6 @@ Reth RPC types # reth reth-primitives = { path = "../../primitives" } reth-rlp = { path = "../../rlp" } -reth-network-api = { path = "../../net/network-api"} # errors thiserror = "1.0" diff --git a/crates/rpc/rpc-types/src/admin.rs b/crates/rpc/rpc-types/src/admin.rs index 7622eb9a9..d066fd6f7 100644 --- a/crates/rpc/rpc-types/src/admin.rs +++ b/crates/rpc/rpc-types/src/admin.rs @@ -1,5 +1,4 @@ -use reth_network_api::{EthProtocolInfo, NetworkStatus}; -use reth_primitives::{NodeRecord, PeerId}; +use reth_primitives::{NodeRecord, PeerId, H256, U256}; use serde::{Deserialize, Serialize}; use std::{ collections::BTreeMap, @@ -64,6 +63,31 @@ pub struct Ports { pub listener: u16, } +/// The status of the network being ran by the local node. +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub struct NetworkStatus { + /// The local node client version. + pub client_version: String, + /// The current ethereum protocol version + pub protocol_version: u64, + /// Information about the Ethereum Wire Protocol. + pub eth_protocol_info: EthProtocolInfo, +} + +/// Information about the Ethereum Wire Protocol (ETH) +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub struct EthProtocolInfo { + /// The current difficulty at the head of the chain. + #[serde(deserialize_with = "reth_primitives::serde_helper::deserialize_json_u256")] + pub difficulty: U256, + /// The block hash of the head of the chain. + pub head: H256, + /// Network ID in base 10. + pub network: u64, + /// Genesis block of the current chain. + pub genesis: H256, +} + #[cfg(test)] mod tests { use super::*; diff --git a/crates/rpc/rpc-types/src/eth/syncing.rs b/crates/rpc/rpc-types/src/eth/syncing.rs index e54a3a78e..e9ff68e09 100644 --- a/crates/rpc/rpc-types/src/eth/syncing.rs +++ b/crates/rpc/rpc-types/src/eth/syncing.rs @@ -70,14 +70,14 @@ pub struct PeerNetworkInfo { #[derive(Debug, Clone, Default, Serialize)] pub struct PeerProtocolsInfo { /// Ethereum protocol information - pub eth: Option, + pub eth: Option, /// PIP protocol information. pub pip: Option, } /// Peer Ethereum protocol information #[derive(Debug, Clone, Default, Serialize, Deserialize)] -pub struct EthProtocolInfo { +pub struct PeerEthProtocolInfo { /// Negotiated ethereum protocol version pub version: u32, /// Peer total difficulty if known