ethportal_api/
state.rs

1use discv5::enr::NodeId;
2use jsonrpsee::{core::RpcResult, proc_macros::rpc};
3
4use crate::{
5    types::{
6        content_key::state::StateContentKey,
7        enr::Enr,
8        portal::{
9            AcceptInfo, DataRadius, FindContentInfo, FindNodesInfo, GetContentInfo,
10            PaginateLocalContentInfo, PongInfo, PutContentInfo, TraceContentInfo,
11            TracePutContentInfo,
12        },
13        portal_wire::OfferTrace,
14    },
15    RawContentValue, RoutingTableInfo,
16};
17
18/// Portal State JSON-RPC endpoints
19#[rpc(client, server, namespace = "portal")]
20pub trait StateNetworkApi {
21    /// Returns meta information about overlay routing table.
22    #[method(name = "stateRoutingTableInfo")]
23    async fn routing_table_info(&self) -> RpcResult<RoutingTableInfo>;
24
25    /// Returns the node data radios
26    #[method(name = "stateRadius")]
27    async fn radius(&self) -> RpcResult<DataRadius>;
28
29    /// Write an Ethereum Node Record to the overlay routing table.
30    #[method(name = "stateAddEnr")]
31    async fn add_enr(&self, enr: Enr) -> RpcResult<bool>;
32
33    /// Fetch the latest ENR associated with the given node ID.
34    #[method(name = "stateGetEnr")]
35    async fn get_enr(&self, node_id: NodeId) -> RpcResult<Enr>;
36
37    /// Delete Node ID from the overlay routing table.
38    #[method(name = "stateDeleteEnr")]
39    async fn delete_enr(&self, node_id: NodeId) -> RpcResult<bool>;
40
41    /// Fetch the ENR representation associated with the given Node ID.
42    #[method(name = "stateLookupEnr")]
43    async fn lookup_enr(&self, node_id: NodeId) -> RpcResult<Enr>;
44
45    /// Send a PING message to the designated node and wait for a PONG response
46    #[method(name = "statePing")]
47    async fn ping(&self, enr: Enr) -> RpcResult<PongInfo>;
48
49    /// Send a FINDNODES request for nodes that fall within the given set of distances, to the
50    /// designated peer and wait for a response
51    #[method(name = "stateFindNodes")]
52    async fn find_nodes(&self, enr: Enr, distances: Vec<u16>) -> RpcResult<FindNodesInfo>;
53
54    /// Lookup a target node within in the network
55    #[method(name = "stateRecursiveFindNodes")]
56    async fn recursive_find_nodes(&self, node_id: NodeId) -> RpcResult<Vec<Enr>>;
57
58    /// Send FINDCONTENT message to get the content with a content key.
59    #[method(name = "stateFindContent")]
60    async fn find_content(
61        &self,
62        enr: Enr,
63        content_key: StateContentKey,
64    ) -> RpcResult<FindContentInfo>;
65
66    /// First checks local storage if content is not found lookup a target content key in the
67    /// network
68    #[method(name = "stateGetContent")]
69    async fn get_content(&self, content_key: StateContentKey) -> RpcResult<GetContentInfo>;
70
71    /// First checks local storage if content is not found lookup a target content key in the
72    /// network. Return tracing info.
73    #[method(name = "stateTraceGetContent")]
74    async fn trace_get_content(&self, content_key: StateContentKey) -> RpcResult<TraceContentInfo>;
75
76    /// Pagination of local content keys
77    #[method(name = "statePaginateLocalContentKeys")]
78    async fn paginate_local_content_keys(
79        &self,
80        offset: u64,
81        limit: u64,
82    ) -> RpcResult<PaginateLocalContentInfo<StateContentKey>>;
83
84    /// Send the provided content value to interested peers. Clients may choose to send to some or
85    /// all peers. Return the number of peers that the content was gossiped to.
86    #[method(name = "statePutContent")]
87    async fn put_content(
88        &self,
89        content_key: StateContentKey,
90        content_value: RawContentValue,
91    ) -> RpcResult<PutContentInfo>;
92
93    /// Send the provided content value to interested peers. Clients may choose to send to some or
94    /// all peers. Return tracing info detailing the gossip propagation.
95    #[method(name = "stateTracePutContent")]
96    async fn trace_put_content(
97        &self,
98        content_key: StateContentKey,
99        content_value: RawContentValue,
100    ) -> RpcResult<TracePutContentInfo>;
101
102    /// Send an OFFER request with given ContentItems, to the designated peer and wait for a
103    /// response. Does not store the content locally.
104    /// Returns the content keys bitlist upon successful content transmission or empty bitlist
105    /// receive.
106    #[method(name = "stateOffer")]
107    async fn offer(
108        &self,
109        enr: Enr,
110        content_items: Vec<(StateContentKey, RawContentValue)>,
111    ) -> RpcResult<AcceptInfo>;
112
113    /// Send an OFFER request with given ContentItems, to the designated peer.
114    /// Does not store the content locally.
115    /// Returns trace info for offer.
116    #[method(name = "stateTraceOffer")]
117    async fn trace_offer(
118        &self,
119        enr: Enr,
120        content_key: StateContentKey,
121        content_value: RawContentValue,
122    ) -> RpcResult<OfferTrace>;
123
124    /// Store content key with a content data to the local database.
125    #[method(name = "stateStore")]
126    async fn store(
127        &self,
128        content_key: StateContentKey,
129        content_value: RawContentValue,
130    ) -> RpcResult<bool>;
131
132    /// Get a content from the local database
133    #[method(name = "stateLocalContent")]
134    async fn local_content(&self, content_key: StateContentKey) -> RpcResult<RawContentValue>;
135}