check for lost race before warning (#2833)

This commit is contained in:
Robert Habermeier
2021-04-07 22:04:15 +02:00
committed by GitHub
parent 1e4517800b
commit 8eae0fa443
@@ -636,13 +636,26 @@ pub(crate) async fn handle_new_head(
match imported_block_info(ctx, env, block_hash, &block_header).await? {
Some(i) => imported_blocks_and_info.push((block_hash, block_header, i)),
None => {
// Such errors are likely spurious, but this prevents us from getting gaps
// in the approval-db.
tracing::warn!(
target: LOG_TARGET,
"Unable to gather info about imported block {:?}. Skipping chain.",
(block_hash, block_header.number),
);
// It's possible that we've lost a race with finality.
let (tx, rx) = oneshot::channel();
ctx.send_message(
ChainApiMessage::FinalizedBlockHash(block_header.number.clone(), tx).into()
).await;
let lost_to_finality = match rx.await {
Ok(Ok(Some(h))) if h != block_hash => true,
_ => false,
};
if !lost_to_finality {
// Such errors are likely spurious, but this prevents us from getting gaps
// in the approval-db.
tracing::warn!(
target: LOG_TARGET,
"Unable to gather info about imported block {:?}. Skipping chain.",
(block_hash, block_header.number),
);
}
return Ok(Vec::new());
},