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