Removing reth network api dependency from rpc types (#2281)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
Aditya Pandey
2023-04-17 17:33:06 +05:30
committed by GitHub
parent a0bfb654cd
commit 6f15f844a5
10 changed files with 40 additions and 45 deletions

3
Cargo.lock generated
View File

@ -4941,6 +4941,7 @@ dependencies = [
"reth-provider", "reth-provider",
"reth-rlp", "reth-rlp",
"reth-rlp-derive", "reth-rlp-derive",
"reth-rpc-types",
"reth-tasks", "reth-tasks",
"reth-tracing", "reth-tracing",
"reth-transaction-pool", "reth-transaction-pool",
@ -4963,6 +4964,7 @@ dependencies = [
"async-trait", "async-trait",
"reth-eth-wire", "reth-eth-wire",
"reth-primitives", "reth-primitives",
"reth-rpc-types",
"serde", "serde",
"thiserror", "thiserror",
"tokio", "tokio",
@ -5219,7 +5221,6 @@ dependencies = [
"lru 0.9.0", "lru 0.9.0",
"rand 0.8.5", "rand 0.8.5",
"reth-interfaces", "reth-interfaces",
"reth-network-api",
"reth-primitives", "reth-primitives",
"reth-rlp", "reth-rlp",
"serde", "serde",

View File

@ -11,6 +11,7 @@ description = "Network interfaces"
# reth # reth
reth-primitives = { path = "../../primitives" } reth-primitives = { path = "../../primitives" }
reth-eth-wire = { path = "../eth-wire" } reth-eth-wire = { path = "../eth-wire" }
reth-rpc-types = { path = "../../rpc/rpc-types" }
# io # io
serde = { version = "1.0", features = ["derive"], optional = true } serde = { version = "1.0", features = ["derive"], optional = true }

View File

@ -11,12 +11,10 @@
use async_trait::async_trait; use async_trait::async_trait;
use reth_eth_wire::DisconnectReason; 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; use std::net::SocketAddr;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
pub use error::NetworkError; pub use error::NetworkError;
pub use reputation::{Reputation, ReputationChangeKind}; pub use reputation::{Reputation, ReputationChangeKind};
@ -93,32 +91,3 @@ pub enum PeerKind {
/// Trusted peer. /// Trusted peer.
Trusted, 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,
}

View File

@ -1,10 +1,8 @@
use crate::{ use crate::{NetworkError, NetworkInfo, PeerKind, Peers, PeersInfo, ReputationChangeKind};
EthProtocolInfo, NetworkError, NetworkInfo, NetworkStatus, PeerKind, Peers, PeersInfo,
ReputationChangeKind,
};
use async_trait::async_trait; use async_trait::async_trait;
use reth_eth_wire::{DisconnectReason, ProtocolVersion}; use reth_eth_wire::{DisconnectReason, ProtocolVersion};
use reth_primitives::{rpc::Chain::Mainnet, NodeRecord, PeerId}; use reth_primitives::{rpc::Chain::Mainnet, NodeRecord, PeerId};
use reth_rpc_types::{EthProtocolInfo, NetworkStatus};
use std::net::{IpAddr, SocketAddr}; use std::net::{IpAddr, SocketAddr};
/// A type that implements all network trait that does nothing. /// A type that implements all network trait that does nothing.

View File

@ -31,6 +31,7 @@ reth-tasks = { path = "../../tasks" }
reth-transaction-pool = { path = "../../transaction-pool" } reth-transaction-pool = { path = "../../transaction-pool" }
reth-provider = { path = "../../storage/provider"} reth-provider = { path = "../../storage/provider"}
reth-metrics-common = { path = "../../metrics/common" } reth-metrics-common = { path = "../../metrics/common" }
reth-rpc-types = { path = "../../rpc/rpc-types" }
# async/futures # async/futures
futures = "0.3" futures = "0.3"

View File

@ -39,9 +39,10 @@ use reth_eth_wire::{
DisconnectReason, EthVersion, Status, DisconnectReason, EthVersion, Status,
}; };
use reth_net_common::bandwidth_meter::BandwidthMeter; 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_primitives::{NodeRecord, PeerId, H256};
use reth_provider::BlockProvider; use reth_provider::BlockProvider;
use reth_rpc_types::{EthProtocolInfo, NetworkStatus};
use std::{ use std::{
net::SocketAddr, net::SocketAddr,
pin::Pin, pin::Pin,

View File

@ -11,9 +11,10 @@ use reth_interfaces::{
}; };
use reth_net_common::bandwidth_meter::BandwidthMeter; use reth_net_common::bandwidth_meter::BandwidthMeter;
use reth_network_api::{ 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_primitives::{Head, NodeRecord, PeerId, TransactionSigned, H256};
use reth_rpc_types::NetworkStatus;
use std::{ use std::{
net::SocketAddr, net::SocketAddr,
sync::{ sync::{

View File

@ -13,7 +13,6 @@ Reth RPC types
# reth # reth
reth-primitives = { path = "../../primitives" } reth-primitives = { path = "../../primitives" }
reth-rlp = { path = "../../rlp" } reth-rlp = { path = "../../rlp" }
reth-network-api = { path = "../../net/network-api"}
# errors # errors
thiserror = "1.0" thiserror = "1.0"

View File

@ -1,5 +1,4 @@
use reth_network_api::{EthProtocolInfo, NetworkStatus}; use reth_primitives::{NodeRecord, PeerId, H256, U256};
use reth_primitives::{NodeRecord, PeerId};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::{ use std::{
collections::BTreeMap, collections::BTreeMap,
@ -64,6 +63,31 @@ pub struct Ports {
pub listener: u16, 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)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;

View File

@ -70,14 +70,14 @@ pub struct PeerNetworkInfo {
#[derive(Debug, Clone, Default, Serialize)] #[derive(Debug, Clone, Default, Serialize)]
pub struct PeerProtocolsInfo { pub struct PeerProtocolsInfo {
/// Ethereum protocol information /// Ethereum protocol information
pub eth: Option<EthProtocolInfo>, pub eth: Option<PeerEthProtocolInfo>,
/// PIP protocol information. /// PIP protocol information.
pub pip: Option<PipProtocolInfo>, pub pip: Option<PipProtocolInfo>,
} }
/// Peer Ethereum protocol information /// Peer Ethereum protocol information
#[derive(Debug, Clone, Default, Serialize, Deserialize)] #[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct EthProtocolInfo { pub struct PeerEthProtocolInfo {
/// Negotiated ethereum protocol version /// Negotiated ethereum protocol version
pub version: u32, pub version: u32,
/// Peer total difficulty if known /// Peer total difficulty if known