Skip to content

Commit aa5564d

Browse files
authored
Stop panicking when a state block commit fails (#4016)
1 parent 75ae05b commit aa5564d

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

zebra-state/src/service.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
//! - [`ChainTipChange`]: a read-only channel that can asynchronously await chain tip changes.
1313
1414
use std::{
15+
convert,
1516
future::Future,
1617
pin::Pin,
1718
sync::Arc,
@@ -753,7 +754,12 @@ impl Service<Request> for StateService {
753754
async move {
754755
rsp_rx
755756
.await
756-
.expect("sender is not dropped")
757+
.map_err(|_recv_error| {
758+
BoxError::from("block was dropped from the state CommitBlock queue")
759+
})
760+
// TODO: replace with Result::flatten once it stabilises
761+
// https://github.com/rust-lang/rust/issues/70142
762+
.and_then(convert::identity)
757763
.map(Response::Committed)
758764
.map_err(Into::into)
759765
}
@@ -773,7 +779,14 @@ impl Service<Request> for StateService {
773779
async move {
774780
rsp_rx
775781
.await
776-
.expect("sender is not dropped")
782+
.map_err(|_recv_error| {
783+
BoxError::from(
784+
"block was dropped from the state CommitFinalizedBlock queue",
785+
)
786+
})
787+
// TODO: replace with Result::flatten once it stabilises
788+
// https://github.com/rust-lang/rust/issues/70142
789+
.and_then(convert::identity)
777790
.map(Response::Committed)
778791
.map_err(Into::into)
779792
}

0 commit comments

Comments
 (0)