Network: Extend NetworkInfo trait with NetworkStatus (#923)

This commit is contained in:
Enrique Ortiz
2023-01-19 15:43:51 -04:00
committed by GitHub
parent 2a77e08080
commit cfef666886
11 changed files with 113 additions and 43 deletions

View File

@ -8,4 +8,11 @@ readme = "README.md"
description = "Network interfaces"
[dependencies]
reth-primitives = { path = "../../primitives" }
# reth
reth-primitives = { path = "../../primitives" }
# io
serde = { version = "1.0", features = ["derive"] }
# misc
async-trait = "0.1"

View File

@ -9,13 +9,22 @@
//!
//! Provides abstractions for the reth-network crate.
use reth_primitives::NodeRecord;
use std::net::SocketAddr;
use async_trait::async_trait;
use reth_primitives::{NodeRecord, H256, U256};
use serde::{Deserialize, Serialize};
use std::{error::Error, net::SocketAddr};
/// Provides general purpose information about the network.
#[async_trait]
pub trait NetworkInfo: Send + Sync {
/// Associated error type for the network implementation.
type Error: Send + Sync + Error;
/// Returns the [`SocketAddr`] that listens for incoming connections.
fn local_addr(&self) -> SocketAddr;
/// Returns the current status of the network being ran by the local node.
async fn network_status(&self) -> Result<NetworkStatus, Self::Error>;
}
/// Provides general purpose information about Peers in the network.
@ -28,3 +37,25 @@ pub trait PeersInfo: Send + Sync {
/// Returns the Ethereum Node Record of the node.
fn local_node_record(&self) -> NodeRecord;
}
/// The status of the network being ran by the local node.
#[derive(Serialize, Deserialize, Debug, Default)]
pub struct NetworkStatus {
/// The local node client name.
pub client_name: String,
/// Information about the Ethereum Wire Protocol.
pub eth_protocol_info: EthProtocolInfo,
}
/// Information about the Ethereum Wire Protocol (ETH)
#[derive(Serialize, Deserialize, Debug, Default)]
pub struct EthProtocolInfo {
/// The current difficulty at the head of the chain.
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,
}