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        enr::Enr,
8        ping_extensions::extension_types::PingExtensionType,
9        portal::{
10            AcceptInfo, DataRadius, FindContentInfo, FindNodesInfo, GetContentInfo, PongInfo,
11            PutContentInfo, TraceContentInfo,
12        },
13        portal_wire::OfferTrace,
14    },
15    HistoryContentKey, RawContentValue, RoutingTableInfo,
16};
17
18/// Portal History JSON-RPC endpoints
19#[rpc(client, server, namespace = "portal")]
20pub trait HistoryNetworkApi {
21    /// Returns meta information about overlay routing table.
22    #[method(name = "historyRoutingTableInfo")]
23    async fn routing_table_info(&self) -> RpcResult<RoutingTableInfo>;
24
25    /// Returns the node data radios
26    #[method(name = "historyRadius")]
27    async fn radius(&self) -> RpcResult<DataRadius>;
28
29    /// Write an Ethereum Node Record to the overlay routing table.
30    #[method(name = "historyAddEnr")]
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 = "historyGetEnr")]
35    async fn get_enr(&self, node_id: NodeId) -> RpcResult<Enr>;
36
37    /// Delete Node ID from the overlay routing table.
38    #[method(name = "historyDeleteEnr")]
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 = "historyLookupEnr")]
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 = "historyPing")]
47    async fn ping(
48        &self,
49        enr: Enr,
50        payload_type: Option<PingExtensionType>,
51        payload: Option<Value>,
52    ) -> RpcResult<PongInfo>;
53
54    /// Send a FINDNODES request for nodes that fall within the given set of distances, to the
55    /// designated peer and wait for a response
56    #[method(name = "historyFindNodes")]
57    async fn find_nodes(&self, enr: Enr, distances: Vec<u16>) -> RpcResult<FindNodesInfo>;
58
59    /// Lookup a target node within in the network
60    #[method(name = "historyRecursiveFindNodes")]
61    async fn recursive_find_nodes(&self, node_id: NodeId) -> RpcResult<Vec<Enr>>;
62
63    /// Send FINDCONTENT message to get the content with a content key.
64    #[method(name = "historyFindContent")]
65    async fn find_content(
66        &self,
67        enr: Enr,
68        content_key: HistoryContentKey,
69    ) -> RpcResult<FindContentInfo>;
70
71    /// First checks local storage if content is not found lookup a target content key in the
72    /// network
73    #[method(name = "historyGetContent")]
74    async fn get_content(&self, content_key: HistoryContentKey) -> RpcResult<GetContentInfo>;
75
76    /// First checks local storage if content is not found lookup a target content key in the
77    /// network. Return tracing info.
78    #[method(name = "historyTraceGetContent")]
79    async fn trace_get_content(
80        &self,
81        content_key: HistoryContentKey,
82    ) -> RpcResult<TraceContentInfo>;
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 = "historyPutContent")]
87    async fn put_content(
88        &self,
89        content_key: HistoryContentKey,
90        content_value: RawContentValue,
91    ) -> RpcResult<PutContentInfo>;
92
93    /// Send an OFFER request with given ContentItems, to the designated peer and wait for a
94    /// response. Does not store the content locally.
95    /// Returns the content keys bitlist upon successful content transmission or empty bitlist
96    /// receive.
97    #[method(name = "historyOffer")]
98    async fn offer(
99        &self,
100        enr: Enr,
101        content_items: Vec<(HistoryContentKey, RawContentValue)>,
102    ) -> RpcResult<AcceptInfo>;
103
104    /// Send an OFFER request with given ContentItems, to the designated peer.
105    /// Does not store the content locally.
106    /// Returns trace info for the offer.
107    #[method(name = "historyTraceOffer")]
108    async fn trace_offer(
109        &self,
110        enr: Enr,
111        content_key: HistoryContentKey,
112        content_value: RawContentValue,
113    ) -> RpcResult<OfferTrace>;
114
115    /// Store content key with a content data to the local database.
116    #[method(name = "historyStore")]
117    async fn store(
118        &self,
119        content_key: HistoryContentKey,
120        content_value: RawContentValue,
121    ) -> RpcResult<bool>;
122
123    /// Get a content value from the local database
124    #[method(name = "historyLocalContent")]
125    async fn local_content(&self, content_key: HistoryContentKey) -> RpcResult<RawContentValue>;
126}