reth_rpc_api/admin.rs
1use alloy_rpc_types_admin::{NodeInfo, PeerInfo};
2use jsonrpsee::{core::RpcResult, proc_macros::rpc};
3use reth_network_peers::{AnyNode, NodeRecord};
4
5/// Admin namespace rpc interface that gives access to several non-standard RPC methods.
6#[cfg_attr(not(feature = "client"), rpc(server, namespace = "admin"))]
7#[cfg_attr(feature = "client", rpc(server, client, namespace = "admin"))]
8pub trait AdminApi {
9 /// Adds the given node record to the peerset.
10 #[method(name = "addPeer")]
11 fn add_peer(&self, record: NodeRecord) -> RpcResult<bool>;
12
13 /// Disconnects from a remote node if the connection exists.
14 ///
15 /// Returns true if the peer was successfully removed.
16 #[method(name = "removePeer")]
17 fn remove_peer(&self, record: AnyNode) -> RpcResult<bool>;
18
19 /// Adds the given node record to the trusted peerset.
20 #[method(name = "addTrustedPeer")]
21 fn add_trusted_peer(&self, record: AnyNode) -> RpcResult<bool>;
22
23 /// Removes a remote node from the trusted peer set, but it does not disconnect it
24 /// automatically.
25 ///
26 /// Returns true if the peer was successfully removed.
27 #[method(name = "removeTrustedPeer")]
28 fn remove_trusted_peer(&self, record: AnyNode) -> RpcResult<bool>;
29
30 /// Bans a remote node and disconnects an active non-trusted session if one exists.
31 #[method(name = "banPeer")]
32 fn ban_peer(&self, record: AnyNode) -> RpcResult<bool>;
33
34 /// Unbans a remote node.
35 #[method(name = "unbanPeer")]
36 fn unban_peer(&self, record: AnyNode) -> RpcResult<bool>;
37
38 /// The peers administrative property can be queried for all the information known about the
39 /// connected remote nodes at the networking granularity. These include general information
40 /// about the nodes themselves as participants of the devp2p P2P overlay protocol, as well as
41 /// specialized information added by each of the running application protocols
42 #[method(name = "peers")]
43 async fn peers(&self) -> RpcResult<Vec<PeerInfo>>;
44
45 /// Creates an RPC subscription which serves events received from the network.
46 #[subscription(
47 name = "peerEvents",
48 unsubscribe = "peerEvents_unsubscribe",
49 item = String
50 )]
51 async fn subscribe_peer_events(&self) -> jsonrpsee::core::SubscriptionResult;
52
53 /// Returns the ENR of the node.
54 #[method(name = "nodeInfo")]
55 async fn node_info(&self) -> RpcResult<NodeInfo>;
56
57 /// Clears all transactions from the transaction pool.
58 /// Returns the number of transactions that were removed from the pool.
59 #[method(name = "clearTxpool")]
60 async fn clear_txpool(&self) -> RpcResult<u64>;
61}