fix: chain sel + av-store error handling (#4159)

* fix: error handling

* more error handling

* fixup

* fixup

* fixup name

* fixup

* simplify

* spelling, docs
This commit is contained in:
Bernhard Schuster
2021-10-28 11:47:00 +02:00
committed by GitHub
parent c3d6ebe61a
commit 3c72f213ad
2 changed files with 71 additions and 28 deletions
+39 -19
View File
@@ -348,14 +348,11 @@ async fn run<Context, B>(
B: Backend,
{
loop {
let res = run_iteration(&mut ctx, &mut backend, &stagnant_check_interval, &*clock).await;
let res = run_until_error(&mut ctx, &mut backend, &stagnant_check_interval, &*clock).await;
match res {
Err(e) => {
e.trace();
if let Error::Subsystem(SubsystemError::Context(_)) = e {
break
}
break
},
Ok(()) => {
tracing::info!(target: LOG_TARGET, "received `Conclude` signal, exiting");
@@ -370,7 +367,7 @@ async fn run<Context, B>(
//
// A return value of `Ok` indicates that an exit should be made, while non-fatal errors
// lead to another call to this function.
async fn run_iteration<Context, B>(
async fn run_until_error<Context, B>(
ctx: &mut Context,
backend: &mut B,
stagnant_check_interval: &StagnantCheckInterval,
@@ -440,21 +437,36 @@ async fn fetch_finalized(
ctx: &mut impl SubsystemContext,
) -> Result<Option<(Hash, BlockNumber)>, Error> {
let (number_tx, number_rx) = oneshot::channel();
let (hash_tx, hash_rx) = oneshot::channel();
ctx.send_message(ChainApiMessage::FinalizedBlockNumber(number_tx)).await;
let number = number_rx.await??;
let number = match number_rx.await? {
Ok(number) => number,
Err(err) => {
tracing::warn!(target: LOG_TARGET, ?err, "Fetching finalized number failed");
return Ok(None)
},
};
let (hash_tx, hash_rx) = oneshot::channel();
ctx.send_message(ChainApiMessage::FinalizedBlockHash(number, hash_tx)).await;
match hash_rx.await?? {
None => {
tracing::warn!(target: LOG_TARGET, number, "Missing hash for finalized block number");
return Ok(None)
match hash_rx.await? {
Err(err) => {
tracing::warn!(
target: LOG_TARGET,
number,
?err,
"Fetching finalized block number failed"
);
Ok(None)
},
Some(h) => Ok(Some((h, number))),
Ok(None) => {
tracing::warn!(target: LOG_TARGET, number, "Missing hash for finalized block number");
Ok(None)
},
Ok(Some(h)) => Ok(Some((h, number))),
}
}
@@ -462,10 +474,13 @@ async fn fetch_header(
ctx: &mut impl SubsystemContext,
hash: Hash,
) -> Result<Option<Header>, Error> {
let (h_tx, h_rx) = oneshot::channel();
ctx.send_message(ChainApiMessage::BlockHeader(hash, h_tx)).await;
let (tx, rx) = oneshot::channel();
ctx.send_message(ChainApiMessage::BlockHeader(hash, tx)).await;
h_rx.await?.map_err(Into::into)
Ok(rx.await?.unwrap_or_else(|err| {
tracing::warn!(target: LOG_TARGET, ?hash, ?err, "Missing hash for finalized block number");
None
}))
}
async fn fetch_block_weight(
@@ -475,7 +490,12 @@ async fn fetch_block_weight(
let (tx, rx) = oneshot::channel();
ctx.send_message(ChainApiMessage::BlockWeight(hash, tx)).await;
rx.await?.map_err(Into::into)
let res = rx.await?;
Ok(res.unwrap_or_else(|err| {
tracing::warn!(target: LOG_TARGET, ?hash, ?err, "Missing hash for finalized block number");
None
}))
}
// Handle a new active leaf.
@@ -590,7 +610,7 @@ fn extract_reversion_logs(header: &Header) -> Vec<BlockNumber> {
logs
}
// Handle a finalized block event.
/// Handle a finalized block event.
fn handle_finalized_block(
backend: &mut impl Backend,
finalized_hash: Hash,