Skip to content

Commit

Permalink
Fix peer count serialization in beacon API
Browse files Browse the repository at this point in the history
  • Loading branch information
Tumas committed May 16, 2024
1 parent b81448d commit abf3793
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
34 changes: 32 additions & 2 deletions http_api/src/standard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,36 @@ pub struct MetaPeersResponse {
count: usize,
}

#[derive(Serialize)]
pub struct NodePeerCountResponse {
#[serde(with = "serde_utils::string_or_native")]
connected: u64,
#[serde(with = "serde_utils::string_or_native")]
connecting: u64,
#[serde(with = "serde_utils::string_or_native")]
disconnected: u64,
#[serde(with = "serde_utils::string_or_native")]
disconnecting: u64,
}

impl From<NodePeerCount> for NodePeerCountResponse {
fn from(node_peer_count: NodePeerCount) -> Self {
let NodePeerCount {
connected,
connecting,
disconnected,
disconnecting,
} = node_peer_count;

Self {
connected,
connecting,
disconnected,
disconnecting,
}
}
}

#[derive(Serialize)]
struct NodeVersionResponse<'version> {
version: Option<&'version str>,
Expand Down Expand Up @@ -1598,14 +1628,14 @@ pub async fn node_peer<P: Preset>(
/// `GET /eth/v1/node/peer_count`
pub async fn node_peer_count<P: Preset>(
State(api_to_p2p_tx): State<UnboundedSender<ApiToP2p<P>>>,
) -> Result<EthResponse<NodePeerCount>, Error> {
) -> Result<EthResponse<NodePeerCountResponse>, Error> {
let (sender, receiver) = futures::channel::oneshot::channel();

ApiToP2p::RequestPeerCount(sender).send(&api_to_p2p_tx);

let data = receiver.await?;

Ok(EthResponse::json(data))
Ok(EthResponse::json(data.into()))
}

/// `GET /eth/v1/node/version`
Expand Down
8 changes: 4 additions & 4 deletions p2p/src/network_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ impl NodePeer {

#[derive(Serialize)]
pub struct NodePeerCount {
connected: u64,
connecting: u64,
disconnected: u64,
disconnecting: u64,
pub connected: u64,
pub connecting: u64,
pub disconnected: u64,
pub disconnecting: u64,
}

#[derive(Serialize)]
Expand Down

0 comments on commit abf3793

Please sign in to comment.