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",
"tower-load", "tower-load",
"tracing", "tracing",
"tracing-error",
"tracing-futures", "tracing-futures",
"zebra-chain", "zebra-chain",
] ]

View File

@ -36,3 +36,4 @@ tower-load = "0.3"
metrics = "0.12" metrics = "0.12"
zebra-chain = { path = "../zebra-chain" } 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 thiserror::Error;
use tracing_error::TracedError;
use zebra_chain::serialization::SerializationError; use zebra_chain::serialization::SerializationError;
/// A wrapper around `Arc<PeerError>` that implements `Error`. /// A wrapper around `Arc<PeerError>` that implements `Error`.
#[derive(Error, Debug, Clone)] #[derive(Error, Debug, Clone)]
#[error("{0}")] #[error(transparent)]
pub struct SharedPeerError(Arc<PeerError>); pub struct SharedPeerError(Arc<TracedError<PeerError>>);
impl<E> From<E> for SharedPeerError impl<E> From<E> for SharedPeerError
where where
PeerError: From<E>, PeerError: From<E>,
{ {
fn from(source: E) -> Self { 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> { async fn drain_requests(&mut self, request_goal: usize) -> Result<(), Report> {
while self.block_requests.len() > request_goal { while self.block_requests.len() > request_goal {
match self.block_requests.next().await { match self
Some(Ok(zebra_network::Response::Blocks(blocks))) => { .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 { for block in blocks {
self.downloaded_block_heights self.downloaded_block_heights
.insert(block.coinbase_height().unwrap()); .insert(block.coinbase_height().unwrap());
@ -225,12 +231,9 @@ where
.map_err(|e| eyre!(e))?; .map_err(|e| eyre!(e))?;
} }
} }
Some(Ok(_)) => continue, Ok(_) => continue,
Some(Err(e)) => { Err(e) => {
error!(%e); error!("{:?}", e);
}
None => {
unreachable!("None is never encountered due to the condition on the while loop")
} }
} }
} }