Skip to main content

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