mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-07 08:52:54 +00:00
Merge branch 'unstable' into deneb-merge-from-unstable-20230627
# Conflicts: # Cargo.lock # common/eth2_network_config/built_in_network_configs/gnosis/config.yaml
This commit is contained in:
@@ -27,6 +27,11 @@ futures = "0.3.8"
|
||||
store = { path = "../../beacon_node/store", optional = true }
|
||||
slashing_protection = { path = "../../validator_client/slashing_protection", optional = true }
|
||||
mediatype = "0.19.13"
|
||||
mime = "0.3.16"
|
||||
pretty_reqwest_error = { path = "../../common/pretty_reqwest_error" }
|
||||
|
||||
[dev-dependencies]
|
||||
tokio = { version = "1.14.0", features = ["full"] }
|
||||
|
||||
[target.'cfg(target_os = "linux")'.dependencies]
|
||||
psutil = { version = "3.2.2", optional = true }
|
||||
|
||||
@@ -19,6 +19,7 @@ use self::types::{Error as ResponseError, *};
|
||||
use futures::Stream;
|
||||
use futures_util::StreamExt;
|
||||
use lighthouse_network::PeerId;
|
||||
use pretty_reqwest_error::PrettyReqwestError;
|
||||
pub use reqwest;
|
||||
use reqwest::{IntoUrl, RequestBuilder, Response};
|
||||
pub use reqwest::{StatusCode, Url};
|
||||
@@ -39,7 +40,7 @@ pub const CONSENSUS_VERSION_HEADER: &str = "Eth-Consensus-Version";
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
/// The `reqwest` client raised an error.
|
||||
Reqwest(reqwest::Error),
|
||||
HttpClient(PrettyReqwestError),
|
||||
/// The server returned an error message where the body was able to be parsed.
|
||||
ServerMessage(ErrorMessage),
|
||||
/// The server returned an error message with an array of errors.
|
||||
@@ -70,7 +71,7 @@ pub enum Error {
|
||||
|
||||
impl From<reqwest::Error> for Error {
|
||||
fn from(error: reqwest::Error) -> Self {
|
||||
Error::Reqwest(error)
|
||||
Error::HttpClient(error.into())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +79,7 @@ impl Error {
|
||||
/// If the error has a HTTP status code, return it.
|
||||
pub fn status(&self) -> Option<StatusCode> {
|
||||
match self {
|
||||
Error::Reqwest(error) => error.status(),
|
||||
Error::HttpClient(error) => error.inner().status(),
|
||||
Error::ServerMessage(msg) => StatusCode::try_from(msg.code).ok(),
|
||||
Error::ServerIndexedMessage(msg) => StatusCode::try_from(msg.code).ok(),
|
||||
Error::StatusCode(status) => Some(*status),
|
||||
@@ -278,7 +279,7 @@ impl BeaconNodeHttpClient {
|
||||
.await?
|
||||
.json()
|
||||
.await
|
||||
.map_err(Error::Reqwest)
|
||||
.map_err(Into::into)
|
||||
}
|
||||
|
||||
/// Perform a HTTP POST request with a custom timeout.
|
||||
@@ -303,7 +304,7 @@ impl BeaconNodeHttpClient {
|
||||
.await?
|
||||
.json()
|
||||
.await
|
||||
.map_err(Error::Reqwest)
|
||||
.map_err(Error::from)
|
||||
}
|
||||
|
||||
/// Generic POST function supporting arbitrary responses and timeouts.
|
||||
@@ -1673,7 +1674,7 @@ impl BeaconNodeHttpClient {
|
||||
.bytes_stream()
|
||||
.map(|next| match next {
|
||||
Ok(bytes) => EventKind::from_sse_bytes(bytes.as_ref()),
|
||||
Err(e) => Err(Error::Reqwest(e)),
|
||||
Err(e) => Err(Error::HttpClient(e.into())),
|
||||
}))
|
||||
}
|
||||
|
||||
|
||||
@@ -364,12 +364,12 @@ pub struct DatabaseInfo {
|
||||
impl BeaconNodeHttpClient {
|
||||
/// Perform a HTTP GET request, returning `None` on a 404 error.
|
||||
async fn get_bytes_opt<U: IntoUrl>(&self, url: U) -> Result<Option<Vec<u8>>, Error> {
|
||||
let response = self.client.get(url).send().await.map_err(Error::Reqwest)?;
|
||||
let response = self.client.get(url).send().await.map_err(Error::from)?;
|
||||
match ok_or_error(response).await {
|
||||
Ok(resp) => Ok(Some(
|
||||
resp.bytes()
|
||||
.await
|
||||
.map_err(Error::Reqwest)?
|
||||
.map_err(Error::from)?
|
||||
.into_iter()
|
||||
.collect::<Vec<_>>(),
|
||||
)),
|
||||
|
||||
@@ -170,7 +170,7 @@ impl ValidatorClientHttpClient {
|
||||
.map_err(|_| Error::InvalidSignatureHeader)?
|
||||
.to_string();
|
||||
|
||||
let body = response.bytes().await.map_err(Error::Reqwest)?;
|
||||
let body = response.bytes().await.map_err(Error::from)?;
|
||||
|
||||
let message =
|
||||
Message::parse_slice(digest(&SHA256, &body).as_ref()).expect("sha256 is 32 bytes");
|
||||
@@ -222,7 +222,7 @@ impl ValidatorClientHttpClient {
|
||||
.headers(self.headers()?)
|
||||
.send()
|
||||
.await
|
||||
.map_err(Error::Reqwest)?;
|
||||
.map_err(Error::from)?;
|
||||
ok_or_error(response).await
|
||||
}
|
||||
|
||||
@@ -236,7 +236,7 @@ impl ValidatorClientHttpClient {
|
||||
.await?
|
||||
.json()
|
||||
.await
|
||||
.map_err(Error::Reqwest)
|
||||
.map_err(Error::from)
|
||||
}
|
||||
|
||||
/// Perform a HTTP GET request, returning `None` on a 404 error.
|
||||
@@ -266,7 +266,7 @@ impl ValidatorClientHttpClient {
|
||||
.json(body)
|
||||
.send()
|
||||
.await
|
||||
.map_err(Error::Reqwest)?;
|
||||
.map_err(Error::from)?;
|
||||
ok_or_error(response).await
|
||||
}
|
||||
|
||||
@@ -297,7 +297,7 @@ impl ValidatorClientHttpClient {
|
||||
.json(body)
|
||||
.send()
|
||||
.await
|
||||
.map_err(Error::Reqwest)?;
|
||||
.map_err(Error::from)?;
|
||||
let response = ok_or_error(response).await?;
|
||||
self.signed_body(response).await?;
|
||||
Ok(())
|
||||
@@ -316,7 +316,7 @@ impl ValidatorClientHttpClient {
|
||||
.json(body)
|
||||
.send()
|
||||
.await
|
||||
.map_err(Error::Reqwest)?;
|
||||
.map_err(Error::from)?;
|
||||
ok_or_error(response).await
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ BELLATRIX_FORK_VERSION: 0x02000064
|
||||
BELLATRIX_FORK_EPOCH: 385536
|
||||
# Capella
|
||||
CAPELLA_FORK_VERSION: 0x03000064
|
||||
CAPELLA_FORK_EPOCH: 18446744073709551615
|
||||
CAPELLA_FORK_EPOCH: 648704
|
||||
# Deneb
|
||||
DENEB_FORK_VERSION: 0x04000064
|
||||
DENEB_FORK_EPOCH: 18446744073709551615
|
||||
|
||||
10
common/pretty_reqwest_error/Cargo.toml
Normal file
10
common/pretty_reqwest_error/Cargo.toml
Normal file
@@ -0,0 +1,10 @@
|
||||
[package]
|
||||
name = "pretty_reqwest_error"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
reqwest = { version = "0.11.0", features = ["json","stream"] }
|
||||
sensitive_url = { path = "../sensitive_url" }
|
||||
62
common/pretty_reqwest_error/src/lib.rs
Normal file
62
common/pretty_reqwest_error/src/lib.rs
Normal file
@@ -0,0 +1,62 @@
|
||||
use sensitive_url::SensitiveUrl;
|
||||
use std::error::Error as StdError;
|
||||
use std::fmt;
|
||||
|
||||
pub struct PrettyReqwestError(reqwest::Error);
|
||||
|
||||
impl PrettyReqwestError {
|
||||
pub fn inner(&self) -> &reqwest::Error {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for PrettyReqwestError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
if let Some(url) = self.0.url() {
|
||||
if let Ok(url) = SensitiveUrl::new(url.clone()) {
|
||||
write!(f, "url: {}", url)?;
|
||||
} else {
|
||||
write!(f, "url: unable_to_parse")?;
|
||||
};
|
||||
}
|
||||
|
||||
let kind = if self.0.is_builder() {
|
||||
"builder"
|
||||
} else if self.0.is_redirect() {
|
||||
"redirect"
|
||||
} else if self.0.is_status() {
|
||||
"status"
|
||||
} else if self.0.is_timeout() {
|
||||
"timeout"
|
||||
} else if self.0.is_request() {
|
||||
"request"
|
||||
} else if self.0.is_connect() {
|
||||
"connect"
|
||||
} else if self.0.is_body() {
|
||||
"body"
|
||||
} else if self.0.is_decode() {
|
||||
"decode"
|
||||
} else {
|
||||
"unknown"
|
||||
};
|
||||
write!(f, ", kind: {}", kind)?;
|
||||
|
||||
if let Some(status) = self.0.status() {
|
||||
write!(f, ", status_code: {}", status)?;
|
||||
}
|
||||
|
||||
if let Some(ref source) = self.0.source() {
|
||||
write!(f, ", detail: {}", source)?;
|
||||
} else {
|
||||
write!(f, ", source: unknown")?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<reqwest::Error> for PrettyReqwestError {
|
||||
fn from(inner: reqwest::Error) -> Self {
|
||||
Self(inner)
|
||||
}
|
||||
}
|
||||
@@ -75,7 +75,7 @@ impl SensitiveUrl {
|
||||
SensitiveUrl::new(surl)
|
||||
}
|
||||
|
||||
fn new(full: Url) -> Result<Self, SensitiveError> {
|
||||
pub fn new(full: Url) -> Result<Self, SensitiveError> {
|
||||
let mut redacted = full.clone();
|
||||
redacted
|
||||
.path_segments_mut()
|
||||
|
||||
Reference in New Issue
Block a user