Skip to content

Commit

Permalink
refactor update jsonrpc endpoint from *RecursiveTraceContent to *GetC…
Browse files Browse the repository at this point in the history
…ontent
  • Loading branch information
KolbyML committed Oct 14, 2024
1 parent f4eb3e1 commit c845a39
Show file tree
Hide file tree
Showing 25 changed files with 91 additions and 97 deletions.
8 changes: 4 additions & 4 deletions book/src/developers/protocols/json_rpc.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The specification for these endpoints can be found [here](https://playground.ope
- `portal_historyLocalContent`
- `portal_historyPing`
- `portal_historyOffer`
- `portal_historyRecursiveFindContent`
- `portal_historyGetContent`
- `portal_historyStore`
- `portal_stateFindContent`
- `portal_stateFindNodes`
Expand All @@ -30,7 +30,7 @@ The specification for these endpoints can be found [here](https://playground.ope
The following endpoints are not part of the Portal Network specification and are defined
in subsequent sections:
- [`portal_historyRadius`](#portal_historyradius)
- [`portal_historyTraceRecursiveFindContent`](#portal_historytracerecursivefindcontent)
- [`portal_historyTraceGetContent`](#portal_historytracegetcontent)
- [`portal_paginateLocalContentKeys`](#portal_paginatelocalcontentkeys)
- [`portal_stateRadius`](#portal_stateradius)

Expand All @@ -54,8 +54,8 @@ Returns the current data storage radius being used for the History network.
}
```

## `portal_historyTraceRecursiveFindContent`
Same as `portal_historyRecursiveFindContent`, but will also return a "route" with the content. The "route" contains all of the ENR's contacted during the lookup, and their respective distance to the target content. If the content is available in local storage, the route will contain an empty array.
## `portal_historyTraceGetContent`
Same as `portal_historyGetContent`, but will also return a "route" with the content. The "route" contains all of the ENR's contacted during the lookup, and their respective distance to the target content. If the content is available in local storage, the route will contain an empty array.

### Parameters
- `content_key`: Target content key.
Expand Down
8 changes: 4 additions & 4 deletions book/src/users/use/portal_network_data.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ Let us request the block body for block 16624561
- Block hash: `0xd27f5e55d88b447788667b3d72cca66b7c944160f68f0a62aaf02aa7e4b2af17`
- Selector for a block body: `0x01` (defined in Portal Network spec under the History sub-protocol).
- Content key: `0x01d27f5e55d88b447788667b3d72cca66b7c944160f68f0a62aaf02aa7e4b2af17`
- Request: `portal_historyRecursiveFindContent`, which accepts a content key as a parameter
- Request: `portal_historyGetContent`, which accepts a content key as a parameter

```json
{"jsonrpc":"2.0","method":"portal_historyRecursiveFindContent","params":["0x01d27f5e55d88b447788667b3d72cca66b7c944160f68f0a62aaf02aa7e4b2af17"],"id":1}
{"jsonrpc":"2.0","method":"portal_historyGetContent","params":["0x01d27f5e55d88b447788667b3d72cca66b7c944160f68f0a62aaf02aa7e4b2af17"],"id":1}
```
## HTTP

```sh
curl -X POST -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","method":"portal_historyRecursiveFindContent","params":["0x01d27f5e55d88b447788667b3d72cca66b7c944160f68f0a62aaf02aa7e4b2af17"],"id":1}' http://localhost:8545 | jq
curl -X POST -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","method":"portal_historyGetContent","params":["0x01d27f5e55d88b447788667b3d72cca66b7c944160f68f0a62aaf02aa7e4b2af17"],"id":1}' http://localhost:8545 | jq
```

## IPC

```sh
echo '{"jsonrpc":"2.0","method":"portal_historyRecursiveFindContent","params":["0x01d27f5e55d88b447788667b3d72cca66b7c944160f68f0a62aaf02aa7e4b2af17"],"id":1}' | nc -U /tmp/trin-jsonrpc.ipc | jq
echo '{"jsonrpc":"2.0","method":"portal_historyGetContent","params":["0x01d27f5e55d88b447788667b3d72cca66b7c944160f68f0a62aaf02aa7e4b2af17"],"id":1}' | nc -U /tmp/trin-jsonrpc.ipc | jq
```
8 changes: 4 additions & 4 deletions ethportal-api/src/beacon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ pub trait BeaconNetworkApi {
-> RpcResult<ContentInfo>;

/// Lookup a target content key in the network
#[method(name = "beaconRecursiveFindContent")]
async fn recursive_find_content(&self, content_key: BeaconContentKey)
#[method(name = "beaconGetContent")]
async fn get_content(&self, content_key: BeaconContentKey)
-> RpcResult<ContentInfo>;

/// Lookup a target content key in the network. Return tracing info.
#[method(name = "beaconTraceRecursiveFindContent")]
async fn trace_recursive_find_content(
#[method(name = "beaconTraceGetContent")]
async fn trace_get_content(
&self,
content_key: BeaconContentKey,
) -> RpcResult<TraceContentInfo>;
Expand Down
11 changes: 4 additions & 7 deletions ethportal-api/src/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,12 @@ pub trait HistoryNetworkApi {
) -> RpcResult<ContentInfo>;

/// Lookup a target content key in the network
#[method(name = "historyRecursiveFindContent")]
async fn recursive_find_content(
&self,
content_key: HistoryContentKey,
) -> RpcResult<ContentInfo>;
#[method(name = "historyGetContent")]
async fn get_content(&self, content_key: HistoryContentKey) -> RpcResult<ContentInfo>;

/// Lookup a target content key in the network. Return tracing info.
#[method(name = "historyTraceRecursiveFindContent")]
async fn trace_recursive_find_content(
#[method(name = "historyTraceGetContent")]
async fn trace_get_content(
&self,
content_key: HistoryContentKey,
) -> RpcResult<TraceContentInfo>;
Expand Down
11 changes: 4 additions & 7 deletions ethportal-api/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,12 @@ pub trait StateNetworkApi {
async fn find_content(&self, enr: Enr, content_key: StateContentKey) -> RpcResult<ContentInfo>;

/// Lookup a target content key in the network
#[method(name = "stateRecursiveFindContent")]
async fn recursive_find_content(&self, content_key: StateContentKey) -> RpcResult<ContentInfo>;
#[method(name = "stateGetContent")]
async fn get_content(&self, content_key: StateContentKey) -> RpcResult<ContentInfo>;

/// Lookup a target content key in the network. Return tracing info.
#[method(name = "stateTraceRecursiveFindContent")]
async fn trace_recursive_find_content(
&self,
content_key: StateContentKey,
) -> RpcResult<TraceContentInfo>;
#[method(name = "stateTraceGetContent")]
async fn trace_get_content(&self, content_key: StateContentKey) -> RpcResult<TraceContentInfo>;

/// Pagination of local content keys
#[method(name = "statePaginateLocalContentKeys")]
Expand Down
12 changes: 6 additions & 6 deletions ethportal-api/src/types/jsonrpc/endpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ pub enum StateEndpoint {
/// params: [enr, content_key]
FindContent(Enr, StateContentKey),
/// params: content_key
RecursiveFindContent(StateContentKey),
GetContent(StateContentKey),
/// params: content_key
TraceRecursiveFindContent(StateContentKey),
TraceGetContent(StateContentKey),
/// params: [content_key, content_value]
Store(StateContentKey, StateContentValue),
/// params: [enr, Vec<(content_key, content_value>)]
Expand Down Expand Up @@ -84,9 +84,9 @@ pub enum HistoryEndpoint {
/// params: [enr]
Ping(Enr),
/// params: content_key
RecursiveFindContent(HistoryContentKey),
GetContent(HistoryContentKey),
/// params: content_key
TraceRecursiveFindContent(HistoryContentKey),
TraceGetContent(HistoryContentKey),
/// params: [content_key, content_value]
Store(HistoryContentKey, HistoryContentValue),
/// params: None
Expand Down Expand Up @@ -136,9 +136,9 @@ pub enum BeaconEndpoint {
/// params: enr
Ping(Enr),
/// params: content_key
RecursiveFindContent(BeaconContentKey),
GetContent(BeaconContentKey),
/// params: content_key
TraceRecursiveFindContent(BeaconContentKey),
TraceGetContent(BeaconContentKey),
/// params: [content_key, content_value]
Store(BeaconContentKey, BeaconContentValue),
/// params: None
Expand Down
6 changes: 3 additions & 3 deletions ethportal-api/src/types/portal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub type RawContentValue = Bytes;
pub type DataRadius = U256;
pub type Distance = U256;

/// Part of a TraceRecursiveFindContent response
/// Part of a TraceGetContent response
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct NodeInfo {
Expand Down Expand Up @@ -53,7 +53,7 @@ pub struct TraceGossipInfo {
pub transferred: Vec<String>,
}

/// Response for FindContent & RecursiveFindContent endpoints
/// Response for FindContent & GetContent endpoints
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
#[allow(clippy::large_enum_variant)]
Expand All @@ -69,7 +69,7 @@ pub enum ContentInfo {
Enrs { enrs: Vec<Enr> },
}

/// Parsed response for TraceRecursiveFindContent endpoint
/// Parsed response for TraceGetContent endpoint
///
/// This struct represents the content info, and is only used
/// when the content is found locally or on the network.
Expand Down
12 changes: 6 additions & 6 deletions ethportal-peertest/src/scenarios/find.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub async fn test_find_content_return_enr(target: &Client, peertest: &Peertest)
}
}

pub async fn test_trace_recursive_find_content(peertest: &Peertest) {
pub async fn test_trace_get_content(peertest: &Peertest) {
info!("Testing trace recursive find content");
let (content_key, content_value) = fixture_header_by_hash();
let store_result = HistoryNetworkApiClient::store(
Expand All @@ -95,7 +95,7 @@ pub async fn test_trace_recursive_find_content(peertest: &Peertest) {
assert!(store_result);

let query_start_time = SystemTime::now();
let trace_content_info = HistoryNetworkApiClient::trace_recursive_find_content(
let trace_content_info = HistoryNetworkApiClient::trace_get_content(
&peertest.nodes[0].ipc_client,
content_key.clone(),
)
Expand Down Expand Up @@ -136,11 +136,11 @@ pub async fn test_trace_recursive_find_content(peertest: &Peertest) {
}

// This test ensures that when content is not found the correct response is returned.
pub async fn test_trace_recursive_find_content_for_absent_content(peertest: &Peertest) {
pub async fn test_trace_get_content_for_absent_content(peertest: &Peertest) {
let client = &peertest.nodes[0].ipc_client;
let (content_key, _) = fixture_header_by_hash();

let error = HistoryNetworkApiClient::trace_recursive_find_content(client, content_key)
let error = HistoryNetworkApiClient::trace_get_content(client, content_key)
.await
.unwrap_err()
.to_string();
Expand All @@ -150,7 +150,7 @@ pub async fn test_trace_recursive_find_content_for_absent_content(peertest: &Pee
assert!(error.contains("-39001"));
}

pub async fn test_trace_recursive_find_content_local_db(peertest: &Peertest) {
pub async fn test_trace_get_content_local_db(peertest: &Peertest) {
let (content_key, content_value) = fixture_header_by_hash();

let store_result = HistoryNetworkApiClient::store(
Expand All @@ -163,7 +163,7 @@ pub async fn test_trace_recursive_find_content_local_db(peertest: &Peertest) {

assert!(store_result);

let trace_content_info = HistoryNetworkApiClient::trace_recursive_find_content(
let trace_content_info = HistoryNetworkApiClient::trace_get_content(
&peertest.bootnode.ipc_client,
content_key,
)
Expand Down
2 changes: 1 addition & 1 deletion ethportal-peertest/src/scenarios/gossip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ pub async fn test_gossip_dropped_with_find_content(peertest: &Peertest, target:
// send find_content request from fresh target to target
let _result = fresh_target
//.find_content(target.node_info().await.unwrap().enr, acc_key_2.clone())
.recursive_find_content(body_key_2.clone())
.get_content(body_key_2.clone())
.await
.unwrap();

Expand Down
4 changes: 2 additions & 2 deletions ethportal-peertest/src/scenarios/utp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub async fn test_recursive_utp(peertest: &Peertest) {

let content_info = peertest.nodes[0]
.ipc_client
.recursive_find_content(content_key)
.get_content(content_key)
.await
.unwrap();

Expand Down Expand Up @@ -76,7 +76,7 @@ pub async fn test_trace_recursive_utp(peertest: &Peertest) {

let trace_content_info: TraceContentInfo = peertest.nodes[0]
.ipc_client
.trace_recursive_find_content(content_key)
.trace_get_content(content_key)
.await
.unwrap();

Expand Down
10 changes: 5 additions & 5 deletions portal-bridge/src/bridge/era1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ impl Era1Bridge {
for content_key in content_keys_to_sample {
let result = self
.portal_client
.recursive_find_content(content_key.clone())
.get_content(content_key.clone())
.await;
if let Ok(ContentInfo::Content { .. }) = result {
found += 1;
Expand Down Expand Up @@ -371,7 +371,7 @@ impl Era1Bridge {
let header_hash = block_tuple.header.header.hash();
let header_content_key = HistoryContentKey::new_block_header_by_hash(header_hash);
let header_content_info = portal_client
.recursive_find_content(header_content_key.clone())
.get_content(header_content_key.clone())
.await;
if let Ok(ContentInfo::Content { .. }) = header_content_info {
info!(
Expand Down Expand Up @@ -424,7 +424,7 @@ impl Era1Bridge {
let header_content_key =
HistoryContentKey::new_block_header_by_number(block_tuple.header.header.number);
let header_content_info = portal_client
.recursive_find_content(header_content_key.clone())
.get_content(header_content_key.clone())
.await;
if let Ok(ContentInfo::Content { .. }) = header_content_info {
info!(
Expand Down Expand Up @@ -467,7 +467,7 @@ impl Era1Bridge {
let body_hash = block_tuple.header.header.hash();
let body_content_key = HistoryContentKey::new_block_body(body_hash);
let body_content_info = portal_client
.recursive_find_content(body_content_key.clone())
.get_content(body_content_key.clone())
.await;
if let Ok(ContentInfo::Content { .. }) = body_content_info {
info!(
Expand Down Expand Up @@ -508,7 +508,7 @@ impl Era1Bridge {
let receipts_hash = block_tuple.header.header.hash();
let receipts_content_key = HistoryContentKey::new_block_receipts(receipts_hash);
let receipts_content_info = portal_client
.recursive_find_content(receipts_content_key.clone())
.get_content(receipts_content_key.clone())
.await;
if let Ok(ContentInfo::Content { .. }) = receipts_content_info {
info!(
Expand Down
4 changes: 2 additions & 2 deletions portal-bridge/src/gossip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async fn beacon_trace_gossip(
}
// if not, make rfc request to see if data is available on network
let result =
BeaconNetworkApiClient::recursive_find_content(&client, content_key.clone()).await;
BeaconNetworkApiClient::get_content(&client, content_key.clone()).await;
if let Ok(ContentInfo::Content { .. }) = result {
debug!("Found content on network, after failing to gossip, aborting gossip. content key={:?}", content_key.to_hex());
found = true;
Expand Down Expand Up @@ -134,7 +134,7 @@ async fn history_trace_gossip(
}
// if not, make rfc request to see if data is available on network
let result =
HistoryNetworkApiClient::recursive_find_content(&client, content_key.clone()).await;
HistoryNetworkApiClient::get_content(&client, content_key.clone()).await;
if let Ok(ContentInfo::Content { .. }) = result {
debug!("Found content on network, after failing to gossip, aborting gossip. content key={:?}", content_key.to_hex());
found = true;
Expand Down
8 changes: 4 additions & 4 deletions rpc/src/beacon_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,20 +126,20 @@ impl BeaconNetworkApiServer for BeaconNetworkApi {
}

/// Lookup a target content key in the network
async fn recursive_find_content(
async fn get_content(
&self,
content_key: BeaconContentKey,
) -> RpcResult<ContentInfo> {
let endpoint = BeaconEndpoint::RecursiveFindContent(content_key);
let endpoint = BeaconEndpoint::GetContent(content_key);
Ok(proxy_to_subnet(&self.network, endpoint).await?)
}

/// Lookup a target content key in the network. Return tracing info.
async fn trace_recursive_find_content(
async fn trace_get_content(
&self,
content_key: BeaconContentKey,
) -> RpcResult<TraceContentInfo> {
let endpoint = BeaconEndpoint::TraceRecursiveFindContent(content_key);
let endpoint = BeaconEndpoint::TraceGetContent(content_key);
Ok(proxy_to_subnet(&self.network, endpoint).await?)
}

Expand Down
4 changes: 2 additions & 2 deletions rpc/src/eth_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,11 @@ impl EthApi {
&self,
content_key: HistoryContentKey,
) -> Result<HistoryContentValue, RpcServeError> {
let endpoint = HistoryEndpoint::RecursiveFindContent(content_key.clone());
let endpoint = HistoryEndpoint::GetContent(content_key.clone());
let response: ContentInfo = proxy_to_subnet(&self.history_network, endpoint).await?;
let ContentInfo::Content { content, .. } = response else {
return Err(RpcServeError::Message(format!(
"Invalid response variant: History RecursiveFindContent should contain content value; got {response:?}"
"Invalid response variant: History GetContent should contain content value; got {response:?}"
)));
};

Expand Down
4 changes: 2 additions & 2 deletions rpc/src/evm_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,13 @@ impl EvmBlockState {
return Ok(value.clone());
}

let endpoint = StateEndpoint::RecursiveFindContent(content_key.clone());
let endpoint = StateEndpoint::GetContent(content_key.clone());
let response: ContentInfo = proxy_to_subnet(&self.state_network, endpoint)
.await
.map_err(|err| EvmStateError::InternalError(err.to_string()))?;
let ContentInfo::Content { content, .. } = response else {
return Err(EvmStateError::InternalError(format!(
"Invalid response variant: State RecursiveFindContent should contain content value; got {response:?}"
"Invalid response variant: State GetContent should contain content value; got {response:?}"
)));
};

Expand Down
8 changes: 4 additions & 4 deletions rpc/src/history_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,20 @@ impl HistoryNetworkApiServer for HistoryNetworkApi {
}

/// Lookup a target content key in the network
async fn recursive_find_content(
async fn get_content(
&self,
content_key: HistoryContentKey,
) -> RpcResult<ContentInfo> {
let endpoint = HistoryEndpoint::RecursiveFindContent(content_key);
let endpoint = HistoryEndpoint::GetContent(content_key);
Ok(proxy_to_subnet(&self.network, endpoint).await?)
}

/// Lookup a target content key in the network. Return tracing info.
async fn trace_recursive_find_content(
async fn trace_get_content(
&self,
content_key: HistoryContentKey,
) -> RpcResult<TraceContentInfo> {
let endpoint = HistoryEndpoint::TraceRecursiveFindContent(content_key);
let endpoint = HistoryEndpoint::TraceGetContent(content_key);
Ok(proxy_to_subnet(&self.network, endpoint).await?)
}

Expand Down
Loading

0 comments on commit c845a39

Please sign in to comment.