Skip to content

Commit ba9c4c5

Browse files
committed
Return more detail in Eth1 HTTP errors (sigp#2383)
## Issue Addressed NA ## Proposed Changes Whilst investigating sigp#2372, I [learned](sigp#2372 (comment)) that the error message returned from some failed Eth1 requests are always `NotReachable`. This makes debugging quite painful. This PR adds more detail to these errors. For example: - Bad infura key: `ERRO Failed to update eth1 cache error: Failed to update Eth1 service: "All fallback errored: https://mainnet.infura.io/ => EndpointError(RequestFailed(\"Response HTTP status was not 200 OK: 401 Unauthorized.\"))", retry_millis: 60000, service: eth1_rpc` - Unreachable server: `ERRO Failed to update eth1 cache error: Failed to update Eth1 service: "All fallback errored: http://127.0.0.1:8545/ => EndpointError(RequestFailed(\"Request failed: reqwest::Error { kind: Request, url: Url { scheme: \\\"http\\\", cannot_be_a_base: false, username: \\\"\\\", password: None, host: Some(Ipv4(127.0.0.1)), port: Some(8545), path: \\\"/\\\", query: None, fragment: None }, source: hyper::Error(Connect, ConnectError(\\\"tcp connect error\\\", Os { code: 111, kind: ConnectionRefused, message: \\\"Connection refused\\\" })) }\"))", retry_millis: 60000, service: eth1_rpc` - Bad server: `ERRO Failed to update eth1 cache error: Failed to update Eth1 service: "All fallback errored: http://127.0.0.1:8545/ => EndpointError(RequestFailed(\"Response HTTP status was not 200 OK: 501 Not Implemented.\"))", retry_millis: 60000, service: eth1_rpc` ## Additional Info NA
1 parent 4c7bb49 commit ba9c4c5

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

beacon_node/eth1/src/service.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ const WARNING_MSG: &str = "BLOCK PROPOSALS WILL FAIL WITHOUT VALID, SYNCED ETH1
4444
/// A factor used to reduce the eth1 follow distance to account for discrepancies in the block time.
4545
const ETH1_BLOCK_TIME_TOLERANCE_FACTOR: u64 = 4;
4646

47-
#[derive(Debug, PartialEq, Clone, Copy)]
47+
#[derive(Debug, PartialEq, Clone)]
4848
pub enum EndpointError {
49-
NotReachable,
49+
RequestFailed(String),
5050
WrongNetworkId,
5151
WrongChainId,
5252
FarBehind,
@@ -73,7 +73,7 @@ async fn reset_endpoint_state(endpoint: &EndpointWithState) {
7373
}
7474

7575
async fn get_state(endpoint: &EndpointWithState) -> Option<EndpointState> {
76-
*endpoint.state.read().await
76+
endpoint.state.read().await.clone()
7777
}
7878

7979
/// A cache structure to lazily check usability of endpoints. An endpoint is usable if it is
@@ -90,11 +90,11 @@ impl EndpointsCache {
9090
/// Checks the usability of an endpoint. Results get cached and therefore only the first call
9191
/// for each endpoint does the real check.
9292
async fn state(&self, endpoint: &EndpointWithState) -> EndpointState {
93-
if let Some(result) = *endpoint.state.read().await {
93+
if let Some(result) = endpoint.state.read().await.clone() {
9494
return result;
9595
}
9696
let mut value = endpoint.state.write().await;
97-
if let Some(result) = *value {
97+
if let Some(result) = value.clone() {
9898
return result;
9999
}
100100
crate::metrics::inc_counter_vec(
@@ -108,7 +108,7 @@ impl EndpointsCache {
108108
&self.log,
109109
)
110110
.await;
111-
*value = Some(state);
111+
*value = Some(state.clone());
112112
if state.is_err() {
113113
crate::metrics::inc_counter_vec(
114114
&crate::metrics::ENDPOINT_ERRORS,
@@ -147,7 +147,7 @@ impl EndpointsCache {
147147
&[endpoint_str],
148148
);
149149
if let SingleEndpointError::EndpointError(e) = &t {
150-
*endpoint.state.write().await = Some(Err(*e));
150+
*endpoint.state.write().await = Some(Err(e.clone()));
151151
} else {
152152
// A non-`EndpointError` error occurred, so reset the state.
153153
reset_endpoint_state(endpoint).await;
@@ -181,14 +181,14 @@ async fn endpoint_state(
181181
config_chain_id: &Eth1Id,
182182
log: &Logger,
183183
) -> EndpointState {
184-
let error_connecting = |_| {
184+
let error_connecting = |e| {
185185
warn!(
186186
log,
187187
"Error connecting to eth1 node endpoint";
188188
"endpoint" => %endpoint,
189189
"action" => "trying fallbacks"
190190
);
191-
EndpointError::NotReachable
191+
EndpointError::RequestFailed(e)
192192
};
193193
let network_id = get_network_id(endpoint, Duration::from_millis(STANDARD_TIMEOUT_MILLIS))
194194
.await

0 commit comments

Comments
 (0)