Skip to content

Commit

Permalink
fix(rpc/admin): convert remote_id to public key
Browse files Browse the repository at this point in the history
Signed-off-by: jsvisa <delweng@gmail.com>
  • Loading branch information
jsvisa committed Jun 27, 2024
1 parent a86edc0 commit 894bb68
Showing 1 changed file with 35 additions and 26 deletions.
61 changes: 35 additions & 26 deletions crates/rpc/rpc/src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use async_trait::async_trait;
use jsonrpsee::core::RpcResult;
use reth_chainspec::ChainSpec;
use reth_network_api::{NetworkInfo, PeerKind, Peers};
use reth_network_peers::{AnyNode, NodeRecord};
use reth_network_peers::{id2pk, AnyNode, NodeRecord};
use reth_rpc_api::AdminApiServer;
use reth_rpc_types::admin::{
EthInfo, EthPeerInfo, EthProtocolInfo, NodeInfo, PeerInfo, PeerNetworkInfo, PeerProtocolInfo,
Expand Down Expand Up @@ -65,32 +65,41 @@ where
/// Handler for `admin_peers`
async fn peers(&self) -> RpcResult<Vec<PeerInfo>> {
let peers = self.network.get_all_peers().await.to_rpc_result()?;
let peers = peers
.into_iter()
.map(|peer| PeerInfo {
// remove the leading 0x
id: format!("{:x}", B256::from_slice(&peer.remote_id.as_slice()[..32])),
name: peer.client_version.to_string(),
enode: NodeRecord::new(peer.tcp_addr, Some(peer.udp_addr), peer.remote_id)
.to_string(),
enr: None,
caps: peer.capabilities.capabilities().iter().map(|cap| cap.to_string()).collect(),
network: PeerNetworkInfo {
remote_address: peer.tcp_addr,
local_address: peer.local_addr.unwrap_or_else(|| self.network.local_addr()),
inbound: peer.direction.is_incoming(),
trusted: false, // TODO: check
static_node: false, // TODO: check
},
protocols: PeerProtocolInfo {
eth: Some(EthPeerInfo::Info(EthInfo { version: peer.status.version as u64 })),
snap: None,
other: Default::default(),
},
})
.collect();
let mut infos = Vec::with_capacity(peers.len());

Ok(peers)
for peer in peers.into_iter() {
if let Ok(pk) = id2pk(peer.remote_id) {
infos.push(PeerInfo {
id: pk.to_string(),
name: peer.client_version.to_string(),
enode: NodeRecord::new(peer.tcp_addr, Some(peer.udp_addr), peer.remote_id)
.to_string(),
enr: None,
caps: peer
.capabilities
.capabilities()
.iter()
.map(|cap| cap.to_string())
.collect(),
network: PeerNetworkInfo {
remote_address: peer.tcp_addr,
local_address: peer.local_addr.unwrap_or_else(|| self.network.local_addr()),
inbound: peer.direction.is_incoming(),
trusted: false, // TODO: check
static_node: false, // TODO: check
},
protocols: PeerProtocolInfo {
eth: Some(EthPeerInfo::Info(EthInfo {
version: peer.status.version as u64,
})),
snap: None,
other: Default::default(),
},
})
}
}

Ok(infos)
}

/// Handler for `admin_nodeInfo`
Expand Down

0 comments on commit 894bb68

Please sign in to comment.