ethportal_api/
history.rs

1use discv5::enr::NodeId;
2use jsonrpsee::{core::RpcResult, proc_macros::rpc};
3
4use crate::{
5    types::{
6        content_key::history::HistoryContentKey,
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 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(&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 = "historyFindNodes")]
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 = "historyRecursiveFindNodes")]
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 = "historyFindContent")]
60    async fn find_content(
61        &self,
62        enr: Enr,
63        content_key: HistoryContentKey,
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 = "historyGetContent")]
69    async fn get_content(&self, content_key: HistoryContentKey) -> 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 = "historyTraceGetContent")]
74    async fn trace_get_content(
75        &self,
76        content_key: HistoryContentKey,
77    ) -> RpcResult<TraceContentInfo>;
78
79    /// Pagination of local content keys
80    #[method(name = "historyPaginateLocalContentKeys")]
81    async fn paginate_local_content_keys(
82        &self,
83        offset: u64,
84        limit: u64,
85    ) -> RpcResult<PaginateLocalContentInfo<HistoryContentKey>>;
86
87    /// Send the provided content value to interested peers. Clients may choose to send to some or
88    /// all peers. Return the number of peers that the content was gossiped to.
89    #[method(name = "historyPutContent")]
90    async fn put_content(
91        &self,
92        content_key: HistoryContentKey,
93        content_value: RawContentValue,
94    ) -> RpcResult<PutContentInfo>;
95
96    /// Send the provided content value to interested peers. Clients may choose to send to some or
97    /// all peers. Return tracing info detailing the gossip propagation.
98    #[method(name = "historyTracePutContent")]
99    async fn trace_put_content(
100        &self,
101        content_key: HistoryContentKey,
102        content_value: RawContentValue,
103    ) -> RpcResult<TracePutContentInfo>;
104
105    /// Send an OFFER request with given ContentItems, to the designated peer and wait for a
106    /// response. Does not store the content locally.
107    /// Returns the content keys bitlist upon successful content transmission or empty bitlist
108    /// receive.
109    #[method(name = "historyOffer")]
110    async fn offer(
111        &self,
112        enr: Enr,
113        content_items: Vec<(HistoryContentKey, RawContentValue)>,
114    ) -> RpcResult<AcceptInfo>;
115
116    /// Send an OFFER request with given ContentItems, to the designated peer.
117    /// Does not store the content locally.
118    /// Returns trace info for the offer.
119    #[method(name = "historyTraceOffer")]
120    async fn trace_offer(
121        &self,
122        enr: Enr,
123        content_key: HistoryContentKey,
124        content_value: RawContentValue,
125    ) -> RpcResult<OfferTrace>;
126
127    /// Store content key with a content data to the local database.
128    #[method(name = "historyStore")]
129    async fn store(
130        &self,
131        content_key: HistoryContentKey,
132        content_value: RawContentValue,
133    ) -> RpcResult<bool>;
134
135    /// Get a content value from the local database
136    #[method(name = "historyLocalContent")]
137    async fn local_content(&self, content_key: HistoryContentKey) -> RpcResult<RawContentValue>;
138}