ethportal_api/
legacy_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,
11            PaginateLocalContentInfo, PongInfo, PutContentInfo, TraceContentInfo,
12        },
13        portal_wire::OfferTrace,
14    },
15    LegacyHistoryContentKey, RawContentValue, RoutingTableInfo,
16};
17
18/// Portal History JSON-RPC endpoints
19#[rpc(client, server, namespace = "portal")]
20pub trait LegacyHistoryNetworkApi {
21    /// Returns meta information about overlay routing table.
22    #[method(name = "legacyHistoryRoutingTableInfo")]
23    async fn routing_table_info(&self) -> RpcResult<RoutingTableInfo>;
24
25    /// Returns the node data radios
26    #[method(name = "legacyHistoryRadius")]
27    async fn radius(&self) -> RpcResult<DataRadius>;
28
29    /// Write an Ethereum Node Record to the overlay routing table.
30    #[method(name = "legacyHistoryAddEnr")]
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 = "legacyHistoryGetEnr")]
35    async fn get_enr(&self, node_id: NodeId) -> RpcResult<Enr>;
36
37    /// Delete Node ID from the overlay routing table.
38    #[method(name = "legacyHistoryDeleteEnr")]
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 = "legacyHistoryLookupEnr")]
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 = "legacyHistoryPing")]
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 = "legacyHistoryFindNodes")]
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 = "legacyHistoryRecursiveFindNodes")]
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 = "legacyHistoryFindContent")]
65    async fn find_content(
66        &self,
67        enr: Enr,
68        content_key: LegacyHistoryContentKey,
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 = "legacyHistoryGetContent")]
74    async fn get_content(&self, content_key: LegacyHistoryContentKey) -> 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 = "legacyHistoryTraceGetContent")]
79    async fn trace_get_content(
80        &self,
81        content_key: LegacyHistoryContentKey,
82    ) -> RpcResult<TraceContentInfo>;
83
84    /// Pagination of local content keys
85    #[method(name = "legacyHistoryPaginateLocalContentKeys")]
86    async fn paginate_local_content_keys(
87        &self,
88        offset: u64,
89        limit: u64,
90    ) -> RpcResult<PaginateLocalContentInfo<LegacyHistoryContentKey>>;
91
92    /// Send the provided content value to interested peers. Clients may choose to send to some or
93    /// all peers. Return the number of peers that the content was gossiped to.
94    #[method(name = "legacyHistoryPutContent")]
95    async fn put_content(
96        &self,
97        content_key: LegacyHistoryContentKey,
98        content_value: RawContentValue,
99    ) -> RpcResult<PutContentInfo>;
100
101    /// Send an OFFER request with given ContentItems, to the designated peer and wait for a
102    /// response. Does not store the content locally.
103    /// Returns the content keys bitlist upon successful content transmission or empty bitlist
104    /// receive.
105    #[method(name = "legacyHistoryOffer")]
106    async fn offer(
107        &self,
108        enr: Enr,
109        content_items: Vec<(LegacyHistoryContentKey, RawContentValue)>,
110    ) -> RpcResult<AcceptInfo>;
111
112    /// Send an OFFER request with given ContentItems, to the designated peer.
113    /// Does not store the content locally.
114    /// Returns trace info for the offer.
115    #[method(name = "legacyHistoryTraceOffer")]
116    async fn trace_offer(
117        &self,
118        enr: Enr,
119        content_key: LegacyHistoryContentKey,
120        content_value: RawContentValue,
121    ) -> RpcResult<OfferTrace>;
122
123    /// Store content key with a content data to the local database.
124    #[method(name = "legacyHistoryStore")]
125    async fn store(
126        &self,
127        content_key: LegacyHistoryContentKey,
128        content_value: RawContentValue,
129    ) -> RpcResult<bool>;
130
131    /// Get a content value from the local database
132    #[method(name = "legacyHistoryLocalContent")]
133    async fn local_content(
134        &self,
135        content_key: LegacyHistoryContentKey,
136    ) -> RpcResult<RawContentValue>;
137}