Skip to content

Commit 0d07d81

Browse files
authored
Implement Beacon network RPC endpoints (#732)
1 parent 6c7f801 commit 0d07d81

File tree

11 files changed

+497
-5
lines changed

11 files changed

+497
-5
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ethportal-api/src/beacon.rs

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
use crate::types::portal::FindNodesInfo;
2+
use crate::types::portal::{
3+
AcceptInfo, ContentInfo, DataRadius, PaginateLocalContentInfo, PongInfo, TraceContentInfo,
4+
};
5+
use crate::{NodeId, RoutingTableInfo};
6+
use jsonrpsee::{core::RpcResult, proc_macros::rpc};
7+
use trin_types::content_key::BeaconContentKey;
8+
use trin_types::content_value::{BeaconContentValue, PossibleBeaconContentValue};
9+
use trin_types::enr::Enr;
10+
11+
/// Portal Beacon JSON-RPC endpoints
12+
#[rpc(client, server, namespace = "portal")]
13+
pub trait BeaconNetworkApi {
14+
/// Returns meta information about overlay routing table.
15+
#[method(name = "beaconRoutingTableInfo")]
16+
async fn routing_table_info(&self) -> RpcResult<RoutingTableInfo>;
17+
18+
/// Returns the node data radios
19+
#[method(name = "beaconRadius")]
20+
async fn radius(&self) -> RpcResult<DataRadius>;
21+
22+
/// Write an Ethereum Node Record to the overlay routing table.
23+
#[method(name = "beaconAddEnr")]
24+
async fn add_enr(&self, enr: Enr) -> RpcResult<bool>;
25+
26+
/// Fetch the latest ENR associated with the given node ID.
27+
#[method(name = "beaconGetEnr")]
28+
async fn get_enr(&self, node_id: NodeId) -> RpcResult<Enr>;
29+
30+
/// Delete Node ID from the overlay routing table.
31+
#[method(name = "beaconDeleteEnr")]
32+
async fn delete_enr(&self, node_id: NodeId) -> RpcResult<bool>;
33+
34+
/// Fetch the ENR representation associated with the given Node ID.
35+
#[method(name = "beaconLookupEnr")]
36+
async fn lookup_enr(&self, node_id: NodeId) -> RpcResult<Enr>;
37+
38+
/// Send a PING message to the designated node and wait for a PONG response
39+
#[method(name = "beaconPing")]
40+
async fn ping(&self, enr: Enr) -> RpcResult<PongInfo>;
41+
42+
/// Send a FINDNODES request for nodes that fall within the given set of distances, to the designated
43+
/// peer and wait for a response
44+
#[method(name = "beaconFindNodes")]
45+
async fn find_nodes(&self, enr: Enr, distances: Vec<u16>) -> RpcResult<FindNodesInfo>;
46+
47+
/// Lookup a target node within in the network
48+
#[method(name = "beaconRecursiveFindNodes")]
49+
async fn recursive_find_nodes(&self, node_id: NodeId) -> RpcResult<Vec<Enr>>;
50+
51+
/// Send FINDCONTENT message to get the content with a content key.
52+
#[method(name = "beaconFindContent")]
53+
async fn find_content(&self, enr: Enr, content_key: BeaconContentKey)
54+
-> RpcResult<ContentInfo>;
55+
56+
/// Lookup a target content key in the network
57+
#[method(name = "beaconRecursiveFindContent")]
58+
async fn recursive_find_content(
59+
&self,
60+
content_key: BeaconContentKey,
61+
) -> RpcResult<PossibleBeaconContentValue>;
62+
63+
/// Lookup a target content key in the network. Return tracing info.
64+
#[method(name = "beaconTraceRecursiveFindContent")]
65+
async fn trace_recursive_find_content(
66+
&self,
67+
content_key: BeaconContentKey,
68+
) -> RpcResult<TraceContentInfo>;
69+
70+
/// Pagination of local content keys
71+
#[method(name = "beaconPaginateLocalContentKeys")]
72+
async fn paginate_local_content_keys(
73+
&self,
74+
offset: u64,
75+
limit: u64,
76+
) -> RpcResult<PaginateLocalContentInfo>;
77+
78+
/// Send the provided content value to interested peers. Clients may choose to send to some or all peers.
79+
/// Return the number of peers that the content was gossiped to.
80+
#[method(name = "beaconGossip")]
81+
async fn gossip(
82+
&self,
83+
content_key: BeaconContentKey,
84+
content_value: BeaconContentValue,
85+
) -> RpcResult<u32>;
86+
87+
/// Send an OFFER request with given ContentKey, to the designated peer and wait for a response.
88+
/// Returns the content keys bitlist upon successful content transmission or empty bitlist receive.
89+
#[method(name = "beaconOffer")]
90+
async fn offer(
91+
&self,
92+
enr: Enr,
93+
content_key: BeaconContentKey,
94+
content_value: Option<BeaconContentValue>,
95+
) -> RpcResult<AcceptInfo>;
96+
97+
/// Store content key with a content data to the local database.
98+
#[method(name = "beaconStore")]
99+
async fn store(
100+
&self,
101+
content_key: BeaconContentKey,
102+
content_value: BeaconContentValue,
103+
) -> RpcResult<bool>;
104+
105+
/// Get a content from the local database
106+
#[method(name = "beaconLocalContent")]
107+
async fn local_content(
108+
&self,
109+
content_key: BeaconContentKey,
110+
) -> RpcResult<PossibleBeaconContentValue>;
111+
}

ethportal-api/src/history.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub trait HistoryNetworkApi {
1515
#[method(name = "historyRoutingTableInfo")]
1616
async fn routing_table_info(&self) -> RpcResult<RoutingTableInfo>;
1717

18-
/// Returns meta information about overlay routing table.
18+
/// Returns the node data radios
1919
#[method(name = "historyRadius")]
2020
async fn radius(&self) -> RpcResult<DataRadius>;
2121

@@ -71,7 +71,7 @@ pub trait HistoryNetworkApi {
7171
) -> RpcResult<TraceContentInfo>;
7272

7373
/// Pagination of local content keys
74-
#[method(name = "paginateLocalContentKeys")]
74+
#[method(name = "historyPaginateLocalContentKeys")]
7575
async fn paginate_local_content_keys(
7676
&self,
7777
offset: u64,

ethportal-api/src/lib.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,26 @@
33
//! `ethportal_api` is a collection of Portal Network APIs and types.
44
#![warn(clippy::unwrap_used)]
55

6+
mod beacon;
67
pub mod discv5;
78
mod history;
89
pub mod types;
910
mod web3;
1011

1112
pub use crate::discv5::{Discv5ApiClient, Discv5ApiServer};
13+
pub use beacon::{BeaconNetworkApiClient, BeaconNetworkApiServer};
1214
pub use history::{HistoryNetworkApiClient, HistoryNetworkApiServer};
1315
pub use web3::{Web3ApiClient, Web3ApiServer};
1416

1517
// Re-exports trin-types
1618
pub use trin_types::content_key::{
17-
BlockBodyKey, BlockHeaderKey, BlockReceiptsKey, EpochAccumulatorKey, HistoryContentKey,
18-
OverlayContentKey, StateContentKey,
19+
BeaconContentKey, BlockBodyKey, BlockHeaderKey, BlockReceiptsKey, EpochAccumulatorKey,
20+
HistoryContentKey, LightClientBootstrapKey, LightClientUpdatesKey, OverlayContentKey,
21+
StateContentKey,
1922
};
2023
pub use trin_types::content_value::{
21-
ContentValue, ContentValueError, HistoryContentValue, PossibleHistoryContentValue,
24+
BeaconContentValue, ContentValue, ContentValueError, HistoryContentValue,
25+
PossibleBeaconContentValue, PossibleHistoryContentValue,
2226
};
2327
pub use trin_types::execution::block_body::*;
2428
pub use trin_types::execution::header::*;

newsfragments/732.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Implement Beacon portal network json-rpc API

0 commit comments

Comments
 (0)