From aa5564dffa53af8cd1e87ec4d559727c3b2190b7 Mon Sep 17 00:00:00 2001 From: teor Date: Thu, 31 Mar 2022 20:26:21 +1000 Subject: [PATCH] Stop panicking when a state block commit fails (#4016) --- zebra-state/src/service.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/zebra-state/src/service.rs b/zebra-state/src/service.rs index 415adf025..0a342d9ca 100644 --- a/zebra-state/src/service.rs +++ b/zebra-state/src/service.rs @@ -12,6 +12,7 @@ //! - [`ChainTipChange`]: a read-only channel that can asynchronously await chain tip changes. use std::{ + convert, future::Future, pin::Pin, sync::Arc, @@ -753,7 +754,12 @@ impl Service for StateService { async move { rsp_rx .await - .expect("sender is not dropped") + .map_err(|_recv_error| { + BoxError::from("block was dropped from the state CommitBlock queue") + }) + // TODO: replace with Result::flatten once it stabilises + // https://github.com/rust-lang/rust/issues/70142 + .and_then(convert::identity) .map(Response::Committed) .map_err(Into::into) } @@ -773,7 +779,14 @@ impl Service for StateService { async move { rsp_rx .await - .expect("sender is not dropped") + .map_err(|_recv_error| { + BoxError::from( + "block was dropped from the state CommitFinalizedBlock queue", + ) + }) + // TODO: replace with Result::flatten once it stabilises + // https://github.com/rust-lang/rust/issues/70142 + .and_then(convert::identity) .map(Response::Committed) .map_err(Into::into) }