ethportal_api/
beacon.rs

1use alloy::primitives::B256;
2use discv5::enr::NodeId;
3use jsonrpsee::{core::RpcResult, proc_macros::rpc};
4
5use crate::{
6    consensus::header::BeaconBlockHeader,
7    light_client::store::LightClientStore,
8    types::{
9        consensus::light_client::{
10            finality_update::LightClientFinalityUpdate,
11            optimistic_update::LightClientOptimisticUpdate,
12        },
13        content_key::beacon::BeaconContentKey,
14        enr::Enr,
15        portal::{
16            AcceptInfo, DataRadius, FindContentInfo, FindNodesInfo, GetContentInfo,
17            PaginateLocalContentInfo, PongInfo, PutContentInfo, TraceContentInfo,
18            TracePutContentInfo,
19        },
20        portal_wire::OfferTrace,
21    },
22    RawContentValue, RoutingTableInfo,
23};
24
25/// Portal Beacon JSON-RPC endpoints
26#[rpc(client, server, namespace = "portal")]
27pub trait BeaconNetworkApi {
28    /// Returns meta information about overlay routing table.
29    #[method(name = "beaconRoutingTableInfo")]
30    async fn routing_table_info(&self) -> RpcResult<RoutingTableInfo>;
31
32    /// Returns the node data radios
33    #[method(name = "beaconRadius")]
34    async fn radius(&self) -> RpcResult<DataRadius>;
35
36    /// Write an Ethereum Node Record to the overlay routing table.
37    #[method(name = "beaconAddEnr")]
38    async fn add_enr(&self, enr: Enr) -> RpcResult<bool>;
39
40    /// Fetch the latest ENR associated with the given node ID.
41    #[method(name = "beaconGetEnr")]
42    async fn get_enr(&self, node_id: NodeId) -> RpcResult<Enr>;
43
44    /// Delete Node ID from the overlay routing table.
45    #[method(name = "beaconDeleteEnr")]
46    async fn delete_enr(&self, node_id: NodeId) -> RpcResult<bool>;
47
48    /// Returns the local store of the light client.
49    #[method(name = "beaconLightClientStore")]
50    async fn light_client_store(&self) -> RpcResult<LightClientStore>;
51
52    /// Fetch the ENR representation associated with the given Node ID.
53    #[method(name = "beaconLookupEnr")]
54    async fn lookup_enr(&self, node_id: NodeId) -> RpcResult<Enr>;
55
56    /// Send a PING message to the designated node and wait for a PONG response
57    #[method(name = "beaconPing")]
58    async fn ping(&self, enr: Enr) -> RpcResult<PongInfo>;
59
60    /// Get the finalized state root of the finalized beacon header.
61    #[method(name = "beaconFinalizedStateRoot")]
62    async fn finalized_state_root(&self) -> RpcResult<B256>;
63
64    /// Get the finalized beacon header
65    #[method(name = "beaconFinalizedHeader")]
66    async fn finalized_header(&self) -> RpcResult<BeaconBlockHeader>;
67
68    /// Get the latest finality update
69    #[method(name = "beaconFinalityUpdate")]
70    async fn finality_update(&self) -> RpcResult<LightClientFinalityUpdate>;
71
72    /// Get the latest optimistic update
73    #[method(name = "beaconOptimisticUpdate")]
74    async fn optimistic_update(&self) -> RpcResult<LightClientOptimisticUpdate>;
75
76    /// Send a FINDNODES request for nodes that fall within the given set of distances, to the
77    /// designated peer and wait for a response
78    #[method(name = "beaconFindNodes")]
79    async fn find_nodes(&self, enr: Enr, distances: Vec<u16>) -> RpcResult<FindNodesInfo>;
80
81    /// Lookup a target node within in the network
82    #[method(name = "beaconRecursiveFindNodes")]
83    async fn recursive_find_nodes(&self, node_id: NodeId) -> RpcResult<Vec<Enr>>;
84
85    /// Get the optimistic root of the optimistic header.
86    #[method(name = "beaconOptimisticStateRoot")]
87    async fn optimistic_state_root(&self) -> RpcResult<B256>;
88
89    /// Send FINDCONTENT message to get the content with a content key.
90    #[method(name = "beaconFindContent")]
91    async fn find_content(
92        &self,
93        enr: Enr,
94        content_key: BeaconContentKey,
95    ) -> RpcResult<FindContentInfo>;
96
97    /// First checks local storage if content is not found lookup a target content key in the
98    /// network
99    #[method(name = "beaconGetContent")]
100    async fn get_content(&self, content_key: BeaconContentKey) -> RpcResult<GetContentInfo>;
101
102    /// First checks local storage if content is not found lookup a target content key in the
103    /// network. Return tracing info.
104    #[method(name = "beaconTraceGetContent")]
105    async fn trace_get_content(&self, content_key: BeaconContentKey)
106        -> RpcResult<TraceContentInfo>;
107
108    /// Pagination of local content keys
109    #[method(name = "beaconPaginateLocalContentKeys")]
110    async fn paginate_local_content_keys(
111        &self,
112        offset: u64,
113        limit: u64,
114    ) -> RpcResult<PaginateLocalContentInfo<BeaconContentKey>>;
115
116    /// Send the provided content value to interested peers. Clients may choose to send to some or
117    /// all peers. Return the number of peers that the content was gossiped to.
118    #[method(name = "beaconPutContent")]
119    async fn put_content(
120        &self,
121        content_key: BeaconContentKey,
122        content_value: RawContentValue,
123    ) -> RpcResult<PutContentInfo>;
124
125    /// Send the provided content value to interested peers. Clients may choose to send to some or
126    /// all peers. Return tracing info detailing the gossip propagation.
127    #[method(name = "beaconTracePutContent")]
128    async fn trace_put_content(
129        &self,
130        content_key: BeaconContentKey,
131        content_value: RawContentValue,
132    ) -> RpcResult<TracePutContentInfo>;
133
134    /// Send an OFFER request with given ContentItems, to the designated peer and wait for a
135    /// response. Does not store the content locally.
136    /// Returns the content keys bitlist upon successful content transmission or empty bitlist
137    /// receive.
138    #[method(name = "beaconOffer")]
139    async fn offer(
140        &self,
141        enr: Enr,
142        content_items: Vec<(BeaconContentKey, RawContentValue)>,
143    ) -> RpcResult<AcceptInfo>;
144
145    /// Send an OFFER request with given ContentItems, to the designated peer.
146    /// Does not store the content locally.
147    /// Returns trace info for the offer.
148    #[method(name = "beaconTraceOffer")]
149    async fn trace_offer(
150        &self,
151        enr: Enr,
152        content_key: BeaconContentKey,
153        content_value: RawContentValue,
154    ) -> RpcResult<OfferTrace>;
155
156    /// Store content key with a content data to the local database.
157    #[method(name = "beaconStore")]
158    async fn store(
159        &self,
160        content_key: BeaconContentKey,
161        content_value: RawContentValue,
162    ) -> RpcResult<bool>;
163
164    /// Get a content from the local database
165    #[method(name = "beaconLocalContent")]
166    async fn local_content(&self, content_key: BeaconContentKey) -> RpcResult<RawContentValue>;
167}