Skip to content

Commit

Permalink
Improve eth1 fallback logging (#2490)
Browse files Browse the repository at this point in the history
## Issue Addressed

Resolves #2487 

## Proposed Changes

Logs a message once in every invocation of `Eth1Service::update` method if the primary endpoint is unavailable for some reason. 

e.g.
```log
Aug 03 00:09:53.517 WARN Error connecting to eth1 node endpoint  action: trying fallbacks, endpoint: http://localhost:8545/, service: eth1_rpc
Aug 03 00:09:56.959 INFO Fetched data from fallback              fallback_number: 1, service: eth1_rpc
```

The main aim of this PR is to have an accompanying message to the "action: trying fallbacks" error message that is returned when checking the endpoint for liveness. This is mainly to indicate to the user that the fallback was live and reachable. 

## Additional info
This PR is not meant to be a catch all for all cases where the primary endpoint failed. For instance, this won't log anything if the primary node was working fine during endpoint liveness checking and failed during deposit/block fetching. This is done intentionally to reduce number of logs while initial deposit/block sync and to avoid more complicated logic.
  • Loading branch information
pawanjay176 committed Aug 30, 2021
1 parent beab306 commit 99737c5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
38 changes: 25 additions & 13 deletions beacon_node/eth1/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,12 @@ impl EndpointsCache {
state
}

/// Return the first successful result along with number of previous errors encountered
/// or all the errors encountered if every none of the fallback endpoints return required output.
pub async fn first_success<'a, F, O, R>(
&'a self,
func: F,
) -> Result<O, FallbackError<SingleEndpointError>>
) -> Result<(O, usize), FallbackError<SingleEndpointError>>
where
F: Fn(&'a SensitiveUrl) -> R,
R: Future<Output = Result<O, SingleEndpointError>>,
Expand Down Expand Up @@ -713,18 +715,24 @@ impl Service {
e => format!("{:?}", e),
};

let (remote_head_block, new_block_numbers_deposit, new_block_numbers_block_cache) =
endpoints
.first_success(|e| async move {
get_remote_head_and_new_block_ranges(e, self, node_far_behind_seconds).await
})
.await
.map_err(|e| {
format!(
"Failed to update Eth1 service: {:?}",
process_single_err(&e)
)
})?;
let (
(remote_head_block, new_block_numbers_deposit, new_block_numbers_block_cache),
num_errors,
) = endpoints
.first_success(|e| async move {
get_remote_head_and_new_block_ranges(e, self, node_far_behind_seconds).await
})
.await
.map_err(|e| {
format!(
"Failed to update Eth1 service: {:?}",
process_single_err(&e)
)
})?;

if num_errors > 0 {
info!(self.log, "Fetched data from fallback"; "fallback_number" => num_errors);
}

*self.inner.remote_head_block.write() = Some(remote_head_block);

Expand Down Expand Up @@ -884,6 +892,7 @@ impl Service {
relevant_new_block_numbers_from_endpoint(e, self, HeadType::Deposit).await
})
.await
.map(|(res, _)| res)
.map_err(Error::FallbackError)?,
}
};
Expand Down Expand Up @@ -930,6 +939,7 @@ impl Service {
.map_err(SingleEndpointError::GetDepositLogsFailed)
})
.await
.map(|(res, _)| res)
.map_err(Error::FallbackError)?;

/*
Expand Down Expand Up @@ -1038,6 +1048,7 @@ impl Service {
.await
})
.await
.map(|(res, _)| res)
.map_err(Error::FallbackError)?,
}
};
Expand Down Expand Up @@ -1103,6 +1114,7 @@ impl Service {
download_eth1_block(e, self.inner.clone(), Some(block_number)).await
})
.await
.map(|(res, _)| res)
.map_err(Error::FallbackError)?;

self.inner
Expand Down
10 changes: 7 additions & 3 deletions common/fallback/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,20 @@ impl<T> Fallback<T> {
Self { servers }
}

/// Return the first successful result or all errors encountered.
pub async fn first_success<'a, F, O, E, R>(&'a self, func: F) -> Result<O, FallbackError<E>>
/// Return the first successful result along with number of previous errors encountered
/// or all the errors encountered if every server fails.
pub async fn first_success<'a, F, O, E, R>(
&'a self,
func: F,
) -> Result<(O, usize), FallbackError<E>>
where
F: Fn(&'a T) -> R,
R: Future<Output = Result<O, E>>,
{
let mut errors = vec![];
for server in &self.servers {
match func(server).await {
Ok(val) => return Ok(val),
Ok(val) => return Ok((val, errors.len())),
Err(e) => errors.push(e),
}
}
Expand Down

0 comments on commit 99737c5

Please sign in to comment.