Skip to content

Commit

Permalink
chore(deps): update jsonrpsee dependency (ethereum#1462)
Browse files Browse the repository at this point in the history
  • Loading branch information
morph-dev authored Sep 24, 2024
1 parent ba8ecd0 commit 08293cd
Show file tree
Hide file tree
Showing 11 changed files with 341 additions and 555 deletions.
650 changes: 231 additions & 419 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ ethereum_ssz_derive = "0.7.1"
ethportal-api = { path = "ethportal-api" }
futures = "0.3.23"
hex = "0.4.3"
hyper = "0.14.28"
jsonrpsee = "0.20.0"
jsonrpsee = "0.24.4"
keccak-hash = "0.10.0"
lazy_static = "1.4.0"
light-client = { path = "light-client" }
Expand All @@ -111,7 +110,7 @@ r2d2 = "0.8.9"
r2d2_sqlite = "0.24.0"
rand = "0.8.5"
reqwest = { version = "0.12.7", features = ["native-tls-vendored", "json"] }
reth-ipc = { tag = "v0.2.0-beta.5", git = "https://github.com/paradigmxyz/reth.git"}
reth-ipc = { tag = "v1.0.7", git = "https://github.com/paradigmxyz/reth.git"}
revm = { version = "14.0.2", default-features = false, features = ["std", "secp256k1", "serde-json"] }
revm-primitives = { version = "9.0.2", default-features = false, features = ["std", "serde"] }
rpc = { path = "rpc"}
Expand Down
1 change: 0 additions & 1 deletion ethportal-peertest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ ethereum_ssz.workspace = true
ethportal-api.workspace = true
futures.workspace = true
hex.workspace = true
hyper = { workspace = true, features = ["full"] }
jsonrpsee = { workspace = true, features = ["async-client", "client", "macros", "server"]}
portal-bridge.workspace = true
rand.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion ethportal-peertest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async fn launch_node(trin_config: TrinConfig) -> anyhow::Result<PeertestNode> {
// Short sleep to make sure all peertest nodes can connect
thread::sleep(time::Duration::from_secs(2));
let ipc_client = reth_ipc::client::IpcClientBuilder::default()
.build(web3_ipc_path)
.build(&web3_ipc_path.to_string_lossy())
.await
.unwrap();

Expand Down
6 changes: 3 additions & 3 deletions ethportal-peertest/src/scenarios/gossip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub async fn test_gossip_with_trace(peertest: &Peertest, target: &Client) {
let (fresh_ipc_path, trin_config) = fresh_node_config();
let _test_client_rpc_handle = trin::run_trin(trin_config).await.unwrap();
let fresh_target = reth_ipc::client::IpcClientBuilder::default()
.build(fresh_ipc_path)
.build(&fresh_ipc_path)
.await
.unwrap();
let fresh_enr = fresh_target.node_info().await.unwrap().enr;
Expand Down Expand Up @@ -86,7 +86,7 @@ pub async fn test_gossip_dropped_with_offer(peertest: &Peertest, target: &Client
let (fresh_ipc_path, trin_config) = fresh_node_config();
let _test_client_rpc_handle = trin::run_trin(trin_config).await.unwrap();
let fresh_target = reth_ipc::client::IpcClientBuilder::default()
.build(fresh_ipc_path)
.build(&fresh_ipc_path)
.await
.unwrap();
let fresh_enr = fresh_target.node_info().await.unwrap().enr;
Expand Down Expand Up @@ -245,7 +245,7 @@ pub async fn test_gossip_dropped_with_find_content(peertest: &Peertest, target:
let (fresh_ipc_path, trin_config) = fresh_node_config();
let _test_client_rpc_handle = trin::run_trin(trin_config).await.unwrap();
let fresh_target = reth_ipc::client::IpcClientBuilder::default()
.build(fresh_ipc_path)
.build(&fresh_ipc_path)
.await
.unwrap();

Expand Down
29 changes: 14 additions & 15 deletions portal-bridge/src/gossip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use tracing::{debug, warn, Instrument};

use crate::stats::{BeaconSlotStats, HistoryBlockStats, StatsReporter};
use ethportal_api::{
jsonrpsee::core::Error,
types::portal::{ContentInfo, TraceGossipInfo},
BeaconContentKey, BeaconContentValue, BeaconNetworkApiClient, ContentValue, HistoryContentKey,
HistoryContentValue, HistoryNetworkApiClient, OverlayContentKey,
Expand Down Expand Up @@ -38,7 +37,7 @@ async fn beacon_trace_gossip(
client: HttpClient,
content_key: BeaconContentKey,
content_value: BeaconContentValue,
) -> Result<GossipReport, Error> {
) -> GossipReport {
let mut retries = 0;
let mut traces = vec![];
let mut found = false;
Expand All @@ -53,11 +52,11 @@ async fn beacon_trace_gossip(
if let Ok(trace) = result {
traces.push(trace.clone());
if !trace.transferred.is_empty() {
return Ok(GossipReport {
return GossipReport {
traces,
retries,
found,
});
};
}
}
// if not, make rfc request to see if data is available on network
Expand All @@ -66,11 +65,11 @@ async fn beacon_trace_gossip(
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;
return Ok(GossipReport {
return GossipReport {
traces,
retries,
found,
});
};
}
retries += 1;
debug!("Unable to locate content on network, after failing to gossip, retrying in {:?} seconds. content key={:?}", RETRY_AFTER, content_key.to_hex());
Expand All @@ -81,11 +80,11 @@ async fn beacon_trace_gossip(
GOSSIP_RETRY_COUNT,
content_key.to_hex(),
);
Ok(GossipReport {
GossipReport {
traces,
retries,
found,
})
}
}

/// Gossip any given content key / value to the history network.
Expand All @@ -111,7 +110,7 @@ async fn history_trace_gossip(
client: HttpClient,
content_key: HistoryContentKey,
content_value: HistoryContentValue,
) -> Result<GossipReport, Error> {
) -> GossipReport {
let mut retries = 0;
let mut traces = vec![];
let mut found = false;
Expand All @@ -126,11 +125,11 @@ async fn history_trace_gossip(
if let Ok(trace) = result {
traces.push(trace.clone());
if !trace.transferred.is_empty() {
return Ok(GossipReport {
return GossipReport {
traces,
retries,
found,
});
};
}
}
// if not, make rfc request to see if data is available on network
Expand All @@ -139,11 +138,11 @@ async fn history_trace_gossip(
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;
return Ok(GossipReport {
return GossipReport {
traces,
retries,
found,
});
};
}
retries += 1;
debug!("Unable to locate content on network, after failing to gossip, retrying in {:?} seconds. content key={:?}", RETRY_AFTER, content_key.to_hex());
Expand All @@ -154,11 +153,11 @@ async fn history_trace_gossip(
GOSSIP_RETRY_COUNT,
content_key.to_hex(),
);
Ok(GossipReport {
GossipReport {
traces,
retries,
found,
})
}
}

pub struct GossipReport {
Expand Down
51 changes: 22 additions & 29 deletions portal-bridge/src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{collections::HashSet, str::FromStr};
use tracing::{debug, info};

use crate::gossip::GossipReport;
use ethportal_api::{jsonrpsee::core::Error, types::enr::Enr, BeaconContentKey, HistoryContentKey};
use ethportal_api::{types::enr::Enr, BeaconContentKey, HistoryContentKey};

// Trait for tracking / reporting gossip stats
pub trait StatsReporter<TContentKey> {
Expand Down Expand Up @@ -194,34 +194,27 @@ impl std::fmt::Display for ContentStats {
}
}

impl From<Result<GossipReport, Error>> for ContentStats {
fn from(result: Result<GossipReport, Error>) -> Self {
let mut content_stats = ContentStats::default();
match result {
Ok(gossip_report) => {
content_stats.retries += gossip_report.retries;
content_stats.found = gossip_report.found;
for trace in &gossip_report.traces {
for enr in trace.offered.iter() {
let enr = Enr::from_str(enr)
.expect("ENR from trace gossip response to successfully decode.");
content_stats.offered.insert(enr);
}

for enr in trace.accepted.iter() {
let enr = Enr::from_str(enr)
.expect("ENR from trace gossip response to successfully decode.");
content_stats.accepted.insert(enr);
}

for enr in trace.transferred.iter() {
let enr = Enr::from_str(enr)
.expect("ENR from trace gossip response to successfully decode.");
content_stats.transferred.insert(enr);
}
}
}
Err(_) => content_stats.failures += 1,
impl From<GossipReport> for ContentStats {
fn from(gossip_report: GossipReport) -> Self {
let mut content_stats = ContentStats {
retries: gossip_report.retries,
found: gossip_report.found,
..ContentStats::default()
};

let enr_from_str = |enr: &String| {
Enr::from_str(enr).expect("ENR from trace gossip response to successfully decode.")
};
for trace in &gossip_report.traces {
content_stats
.offered
.extend(trace.offered.iter().map(enr_from_str));
content_stats
.accepted
.extend(trace.accepted.iter().map(enr_from_str));
content_stats
.transferred
.extend(trace.transferred.iter().map(enr_from_str));
}
content_stats
}
Expand Down
4 changes: 2 additions & 2 deletions rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ alloy-rpc-types.workspace = true
discv5.workspace = true
eth_trie.workspace = true
ethportal-api.workspace = true
hyper.workspace = true
http = "1.1.0"
portalnet.workspace = true
reth-ipc.workspace = true
revm.workspace = true
Expand All @@ -27,7 +27,7 @@ strum.workspace = true
thiserror.workspace = true
tokio.workspace = true
tower = { version = "0.4.13", features = ["full"] }
tower-http = { version = "0.4.4", features = ["full"] }
tower-http = { version = "0.5.0", features = ["full"] }
tracing.workspace = true
trin-evm.workspace = true
trin-utils.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion rpc/src/cors.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use hyper::{http::HeaderValue, Method};
use http::{HeaderValue, Method};
use tower_http::cors::{AllowOrigin, Any, CorsLayer};

/// Error thrown when parsing cors domains went wrong
Expand Down
44 changes: 11 additions & 33 deletions rpc/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,58 +1,36 @@
use crate::{
jsonrpsee::{
core::Error as JsonRpseeError,
server::AlreadyStoppedError,
types::{ErrorObject, ErrorObjectOwned},
},
rpc_server::ServerKind,
PortalRpcModule,
};
use ethportal_api::{types::query_trace::QueryTrace, ContentValueError};
use reth_ipc::server::IpcServerStartError;
use serde::{Deserialize, Serialize};
use std::io;

/// Rpc Errors.
#[derive(Debug, thiserror::Error)]
#[allow(clippy::enum_variant_names)]
pub enum RpcError {
/// Wrapper for `jsonrpsee::core::Error`.
#[error(transparent)]
RpcError(#[from] JsonRpseeError),
/// Address already in use.
#[error("Address {kind} is already in use (os error 98)")]
AddressAlreadyInUse {
/// Server kind.
kind: ServerKind,
/// IO error.
error: io::Error,
},
/// More descriptive io::Error.
#[error("IO Error: {0} for server kind: {1}")]
IoError(io::Error, ServerKind),
/// Http and WS server configured on the same port but with conflicting settings.
#[error(transparent)]
WsHttpSamePortError(#[from] WsHttpSamePortError),
/// Error while starting ipc server.
#[error(transparent)]
IpcServerStartError(#[from] IpcServerStartError),
/// Server already stopped.
#[error(transparent)]
AlreadyStoppedError(#[from] AlreadyStoppedError),
/// Custom error.
#[error("{0}")]
Custom(String),
}

impl RpcError {
/// Converts a `jsonrpsee::core::Error` to a more descriptive `RpcError`.
pub fn from_jsonrpsee_error(err: JsonRpseeError, kind: ServerKind) -> RpcError {
match err {
JsonRpseeError::Transport(err) => {
if let Some(io_error) = err.downcast_ref::<io::Error>() {
if io_error.kind() == io::ErrorKind::AddrInUse {
return RpcError::AddressAlreadyInUse {
kind,
error: io::Error::from(io_error.kind()),
};
}
}
RpcError::RpcError(JsonRpseeError::Transport(err))
}
_ => err.into(),
}
}
}

#[derive(Debug, PartialEq, Eq, thiserror::Error)]
pub enum RpcServeError {
/// A generic error with no data
Expand Down
Loading

0 comments on commit 08293cd

Please sign in to comment.