ethportal_api/
history.rs

1use discv5::enr::NodeId;
2use jsonrpsee::{core::RpcResult, proc_macros::rpc};
3use serde_json::Value;
4
5use crate::{
6    types::{
7        content_key::history::HistoryContentKey,
8        enr::Enr,
9        ping_extensions::extension_types::PingExtensionType,
10        portal::{
11            AcceptInfo, DataRadius, FindContentInfo, FindNodesInfo, GetContentInfo,
12            PaginateLocalContentInfo, PongInfo, PutContentInfo, TraceContentInfo,
13        },
14        portal_wire::OfferTrace,
15    },
16    RawContentValue, RoutingTableInfo,
17};
18
19/// Portal History JSON-RPC endpoints
20#[rpc(client, server, namespace = "portal")]
21pub trait HistoryNetworkApi {
22    /// Returns meta information about overlay routing table.
23    #[method(name = "historyRoutingTableInfo")]
24    async fn routing_table_info(&self) -> RpcResult<RoutingTableInfo>;
25
26    /// Returns the node data radios
27    #[method(name = "historyRadius")]
28    async fn radius(&self) -> RpcResult<DataRadius>;
29
30    /// Write an Ethereum Node Record to the overlay routing table.
31    #[method(name = "historyAddEnr")]
32    async fn add_enr(&self, enr: Enr) -> RpcResult<bool>;
33
34    /// Fetch the latest ENR associated with the given node ID.
35    #[method(name = "historyGetEnr")]
36    async fn get_enr(&self, node_id: NodeId) -> RpcResult<Enr>;
37
38    /// Delete Node ID from the overlay routing table.
39    #[method(name = "historyDeleteEnr")]
40    async fn delete_enr(&self, node_id: NodeId) -> RpcResult<bool>;
41
42    /// Fetch the ENR representation associated with the given Node ID.
43    #[method(name = "historyLookupEnr")]
44    async fn lookup_enr(&self, node_id: NodeId) -> RpcResult<Enr>;
45
46    /// Send a PING message to the designated node and wait for a PONG response
47    #[method(name = "historyPing")]
48    async fn ping(
49        &self,
50        enr: Enr,
51        payload_type: Option<PingExtensionType>,
52        payload: Option<Value>,
53    ) -> RpcResult<PongInfo>;
54
55    /// Send a FINDNODES request for nodes that fall within the given set of distances, to the
56    /// designated peer and wait for a response
57    #[method(name = "historyFindNodes")]
58    async fn find_nodes(&self, enr: Enr, distances: Vec<u16>) -> RpcResult<FindNodesInfo>;
59
60    /// Lookup a target node within in the network
61    #[method(name = "historyRecursiveFindNodes")]
62    async fn recursive_find_nodes(&self, node_id: NodeId) -> RpcResult<Vec<Enr>>;
63
64    /// Send FINDCONTENT message to get the content with a content key.
65    #[method(name = "historyFindContent")]
66    async fn find_content(
67        &self,
68        enr: Enr,
69        content_key: HistoryContentKey,
70    ) -> RpcResult<FindContentInfo>;
71
72    /// First checks local storage if content is not found lookup a target content key in the
73    /// network
74    #[method(name = "historyGetContent")]
75    async fn get_content(&self, content_key: HistoryContentKey) -> RpcResult<GetContentInfo>;
76
77    /// First checks local storage if content is not found lookup a target content key in the
78    /// network. Return tracing info.
79    #[method(name = "historyTraceGetContent")]
80    async fn trace_get_content(
81        &self,
82        content_key: HistoryContentKey,
83    ) -> RpcResult<TraceContentInfo>;
84
85    /// Pagination of local content keys
86    #[method(name = "historyPaginateLocalContentKeys")]
87    async fn paginate_local_content_keys(
88        &self,
89        offset: u64,
90        limit: u64,
91    ) -> RpcResult<PaginateLocalContentInfo<HistoryContentKey>>;
92
93    /// Send the provided content value to interested peers. Clients may choose to send to some or
94    /// all peers. Return the number of peers that the content was gossiped to.
95    #[method(name = "historyPutContent")]
96    async fn put_content(
97        &self,
98        content_key: HistoryContentKey,
99        content_value: RawContentValue,
100    ) -> RpcResult<PutContentInfo>;
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 = "historyOffer")]
107    async fn offer(
108        &self,
109        enr: Enr,
110        content_items: Vec<(HistoryContentKey, 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 the offer.
116    #[method(name = "historyTraceOffer")]
117    async fn trace_offer(
118        &self,
119        enr: Enr,
120        content_key: HistoryContentKey,
121        content_value: RawContentValue,
122    ) -> RpcResult<OfferTrace>;
123
124    /// Store content key with a content data to the local database.
125    #[method(name = "historyStore")]
126    async fn store(
127        &self,
128        content_key: HistoryContentKey,
129        content_value: RawContentValue,
130    ) -> RpcResult<bool>;
131
132    /// Get a content value from the local database
133    #[method(name = "historyLocalContent")]
134    async fn local_content(&self, content_key: HistoryContentKey) -> RpcResult<RawContentValue>;
135}