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-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",

View File

@ -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 }

View File

@ -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,
}

View File

@ -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.

View File

@ -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"

View File

@ -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,

View File

@ -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::{

View File

@ -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"

View File

@ -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::*;

View File

@ -70,14 +70,14 @@ pub struct PeerNetworkInfo {
#[derive(Debug, Clone, Default, Serialize)]
pub struct PeerProtocolsInfo {
/// Ethereum protocol information
pub eth: Option<EthProtocolInfo>,
pub eth: Option<PeerEthProtocolInfo>,
/// PIP protocol information.
pub pip: Option<PipProtocolInfo>,
}
/// 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