fix sharedpeererror to propagate tracing context

This commit is contained in:
Jane Lusby 2020-06-17 13:08:11 -07:00 committed by Henry de Valence
parent fa6b098056
commit df18ac72c5
4 changed files with 17 additions and 11 deletions

1
Cargo.lock generated
View File

@ -2344,6 +2344,7 @@ dependencies = [
"tower",
"tower-load",
"tracing",
"tracing-error",
"tracing-futures",
"zebra-chain",
]

View File

@ -36,3 +36,4 @@ tower-load = "0.3"
metrics = "0.12"
zebra-chain = { path = "../zebra-chain" }
tracing-error = { version = "0.1.2", features = ["traced-error"] }

View File

@ -2,19 +2,20 @@ use std::sync::{Arc, Mutex};
use thiserror::Error;
use tracing_error::TracedError;
use zebra_chain::serialization::SerializationError;
/// A wrapper around `Arc<PeerError>` that implements `Error`.
#[derive(Error, Debug, Clone)]
#[error("{0}")]
pub struct SharedPeerError(Arc<PeerError>);
#[error(transparent)]
pub struct SharedPeerError(Arc<TracedError<PeerError>>);
impl<E> From<E> for SharedPeerError
where
PeerError: From<E>,
{
fn from(source: E) -> Self {
Self(Arc::new(PeerError::from(source)))
Self(Arc::new(TracedError::from(PeerError::from(source))))
}
}

View File

@ -211,8 +211,14 @@ where
async fn drain_requests(&mut self, request_goal: usize) -> Result<(), Report> {
while self.block_requests.len() > request_goal {
match self.block_requests.next().await {
Some(Ok(zebra_network::Response::Blocks(blocks))) => {
match self
.block_requests
.next()
.await
.expect("expected: block_requests is never empty")
.map_err::<Report, _>(|e| eyre!(e))
{
Ok(zebra_network::Response::Blocks(blocks)) => {
for block in blocks {
self.downloaded_block_heights
.insert(block.coinbase_height().unwrap());
@ -225,12 +231,9 @@ where
.map_err(|e| eyre!(e))?;
}
}
Some(Ok(_)) => continue,
Some(Err(e)) => {
error!(%e);
}
None => {
unreachable!("None is never encountered due to the condition on the while loop")
Ok(_) => continue,
Err(e) => {
error!("{:?}", e);
}
}
}