aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/config.rs16
-rw-r--r--src/util/data.rs6
-rw-r--r--src/util/error.rs39
3 files changed, 45 insertions, 16 deletions
diff --git a/src/util/config.rs b/src/util/config.rs
index 08ece5b7..f1c5c019 100644
--- a/src/util/config.rs
+++ b/src/util/config.rs
@@ -6,8 +6,8 @@ use std::path::PathBuf;
use serde::de::Error as SerdeError;
use serde::{de, Deserialize};
-use netapp::NodeID;
use netapp::util::parse_and_resolve_peer_addr;
+use netapp::NodeID;
use crate::error::Error;
@@ -46,10 +46,6 @@ pub struct Config {
/// Consul service name to use
pub consul_service_name: Option<String>,
- /// Max number of concurrent RPC request
- #[serde(default = "default_max_concurrent_rpc_requests")]
- pub max_concurrent_rpc_requests: usize,
-
/// Sled cache size, in bytes
#[serde(default = "default_sled_cache_capacity")]
pub sled_cache_capacity: u64,
@@ -91,9 +87,6 @@ fn default_sled_cache_capacity() -> u64 {
fn default_sled_flush_every_ms() -> u64 {
2000
}
-fn default_max_concurrent_rpc_requests() -> usize {
- 12
-}
fn default_block_size() -> usize {
1048576
}
@@ -117,10 +110,11 @@ where
let mut ret = vec![];
for peer in <Vec<&str>>::deserialize(deserializer)? {
- let (pubkey, addrs) = parse_and_resolve_peer_addr(peer)
- .ok_or_else(|| D::Error::custom(format!("Unable to parse or resolve peer: {}", peer)))?;
+ let (pubkey, addrs) = parse_and_resolve_peer_addr(peer).ok_or_else(|| {
+ D::Error::custom(format!("Unable to parse or resolve peer: {}", peer))
+ })?;
for ip in addrs {
- ret.push((pubkey.clone(), ip));
+ ret.push((pubkey, ip));
}
}
diff --git a/src/util/data.rs b/src/util/data.rs
index d4fe0009..6b8ee527 100644
--- a/src/util/data.rs
+++ b/src/util/data.rs
@@ -93,9 +93,9 @@ impl From<netapp::NodeID> for FixedBytes32 {
}
}
-impl Into<netapp::NodeID> for FixedBytes32 {
- fn into(self) -> netapp::NodeID {
- netapp::NodeID::from_slice(self.as_slice()).unwrap()
+impl From<FixedBytes32> for netapp::NodeID {
+ fn from(bytes: FixedBytes32) -> netapp::NodeID {
+ netapp::NodeID::from_slice(bytes.as_slice()).unwrap()
}
}
diff --git a/src/util/error.rs b/src/util/error.rs
index 390327f1..626958da 100644
--- a/src/util/error.rs
+++ b/src/util/error.rs
@@ -47,8 +47,14 @@ pub enum Error {
#[error(display = "Timeout")]
Timeout,
- #[error(display = "Too many errors: {:?}", _0)]
- TooManyErrors(Vec<String>),
+ #[error(
+ display = "Could not reach quorum of {}. {} of {} request succeeded, others returned errors: {:?}",
+ _0,
+ _1,
+ _2,
+ _3
+ )]
+ Quorum(usize, usize, usize, Vec<String>),
#[error(display = "Bad RPC: {}", _0)]
BadRpc(String),
@@ -81,6 +87,35 @@ impl<T> From<tokio::sync::mpsc::error::SendError<T>> for Error {
}
}
+impl<'a> From<&'a str> for Error {
+ fn from(v: &'a str) -> Error {
+ Error::Message(v.to_string())
+ }
+}
+
+impl From<String> for Error {
+ fn from(v: String) -> Error {
+ Error::Message(v)
+ }
+}
+
+pub trait ErrorContext<T, E> {
+ fn err_context<C: std::borrow::Borrow<str>>(self, ctx: C) -> Result<T, Error>;
+}
+
+impl<T, E> ErrorContext<T, E> for Result<T, E>
+where
+ E: std::fmt::Display,
+{
+ #[inline]
+ fn err_context<C: std::borrow::Borrow<str>>(self, ctx: C) -> Result<T, Error> {
+ match self {
+ Ok(x) => Ok(x),
+ Err(e) => Err(Error::Message(format!("{}\n{}", ctx.borrow(), e))),
+ }
+ }
+}
+
// Custom serialization for our error type, for use in RPC.
// Errors are serialized as a string of their Display representation.
// Upon deserialization, they all become a RemoteError with the