Beacon node does not quit on eth1 errors (#1663)

## Issue Addressed

N/A

## Proposed Changes

Log critical errors instead of quitting if eth1 node cannot be reached or is on wrong network id.
This commit is contained in:
Pawan Dhananjay 2020-09-25 00:43:45 +00:00
parent b8013b7b2c
commit 15638d1448
3 changed files with 14 additions and 38 deletions

View File

@ -598,24 +598,6 @@ where
.clone()
.ok_or_else(|| "caching_eth1_backend requires a chain spec".to_string())?;
// Check if the eth1 endpoint we connect to is on the correct network id.
// Note: This check also effectively checks the eth1 http connection before the beacon chain
// is completely started and fails loudly if there is an issue.
let network_id =
eth1::http::check_eth1_endpoint(&config.endpoint, Duration::from_millis(15_000))
.await
.map_err(|_| "Error connecting to eth1 node.\n\
Please ensure that you have an eth1 http server running locally on localhost:8545 \
or pass an external endpoint using `--eth1-endpoint <SERVER-ADDRESS>`.\n\
Also ensure that `eth` and `net` apis are enabled on the eth1 http server.".to_string())?;
if network_id != config.network_id {
return Err(format!(
"Invalid eth1 network id. Expected {:?}, got {:?}",
config.network_id, network_id
));
}
let backend = if let Some(eth1_service_from_genesis) = self.eth1_service {
eth1_service_from_genesis.update_config(config)?;

View File

@ -55,19 +55,6 @@ impl FromStr for Eth1NetworkId {
}
}
/// Checks that the provided eth1 node has all the relevant api endpoints open
/// and returns the network id.
pub async fn check_eth1_endpoint(
endpoint: &str,
timeout: Duration,
) -> Result<Eth1NetworkId, String> {
// Checks that the "eth" api works as expected.
let _block_number = get_block_number(endpoint, timeout).await?;
// Checks that the "net" api works as expected.
let network_id = get_network_id(endpoint, timeout).await?;
Ok(network_id)
}
/// Get the eth1 network id of the given endpoint.
pub async fn get_network_id(endpoint: &str, timeout: Duration) -> Result<Eth1NetworkId, String> {
let response_body = send_rpc_request(endpoint, "net_version", json!([]), timeout).await?;

View File

@ -11,7 +11,7 @@ use crate::{
use futures::{future::TryFutureExt, stream, stream::TryStreamExt, StreamExt};
use parking_lot::{RwLock, RwLockReadGuard};
use serde::{Deserialize, Serialize};
use slog::{debug, error, info, trace, Logger};
use slog::{crit, debug, error, info, trace, Logger};
use std::ops::{Range, RangeInclusive};
use std::sync::Arc;
use std::time::{SystemTime, UNIX_EPOCH};
@ -30,6 +30,8 @@ const GET_BLOCK_TIMEOUT_MILLIS: u64 = STANDARD_TIMEOUT_MILLIS;
/// Timeout when doing an eth_getLogs to read the deposit contract logs.
const GET_DEPOSIT_LOG_TIMEOUT_MILLIS: u64 = STANDARD_TIMEOUT_MILLIS;
const WARNING_MSG: &str = "BLOCK PROPOSALS WILL FAIL WITHOUT VALID ETH1 CONNECTION";
#[derive(Debug, PartialEq)]
pub enum Error {
/// The remote node is less synced that we expect, it is not useful until has done more
@ -365,18 +367,23 @@ impl Service {
match result {
Ok(network_id) => {
if network_id != config_network {
error!(
crit!(
self.log,
"Failed to update eth1 cache";
"reason" => "Invalid eth1 network id",
"Invalid eth1 network. Please switch to correct network";
"expected" => format!("{:?}",DEFAULT_NETWORK_ID),
"got" => format!("{:?}",network_id),
"received" => format!("{:?}",network_id),
"warning" => WARNING_MSG,
);
return Ok(());
}
}
Err(e) => {
error!(self.log, "Failed to get eth1 network id"; "error" => e);
Err(_) => {
crit!(
self.log,
"Error connecting to eth1 node. Please ensure that you have an eth1 http server running locally on http://localhost:8545 or \
pass an external endpoint using `--eth1-endpoint <SERVER-ADDRESS>`. Also ensure that `eth` and `net` apis are enabled on the eth1 http server";
"warning" => WARNING_MSG,
);
return Ok(());
}
}