Skip to content

Commit

Permalink
Removing reth network api dependency from rpc types (paradigmxyz#2281)
Browse files Browse the repository at this point in the history
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
  • Loading branch information
i-m-aditya and mattsse committed Apr 17, 2023
1 parent a0bfb65 commit 6f15f84
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 45 deletions.
3 changes: 2 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/net/network-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
35 changes: 2 additions & 33 deletions crates/net/network-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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,
}
6 changes: 2 additions & 4 deletions crates/net/network-api/src/test_utils.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
1 change: 1 addition & 0 deletions crates/net/network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion crates/net/network/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion crates/net/network/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down
1 change: 0 additions & 1 deletion crates/rpc/rpc-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
28 changes: 26 additions & 2 deletions crates/rpc/rpc-types/src/admin.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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::*;
Expand Down
4 changes: 2 additions & 2 deletions crates/rpc/rpc-types/src/eth/syncing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6f15f84

Please sign in to comment.