From b21790b7691f2d7c1e32308c452224b6ab9182c6 Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Tue, 26 Jul 2022 23:32:10 +0300 Subject: [PATCH] Log error instead of returning it Log error when `best_parachain_block_at_target` can't be updated instead of propagating it. Signed-off-by: Serban Iorga --- .../src/parachains/target.rs | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/bridges/relays/lib-substrate-relay/src/parachains/target.rs b/bridges/relays/lib-substrate-relay/src/parachains/target.rs index b34cbc2eb1e6..c2c1498eea0d 100644 --- a/bridges/relays/lib-substrate-relay/src/parachains/target.rs +++ b/bridges/relays/lib-substrate-relay/src/parachains/target.rs @@ -138,21 +138,25 @@ where &best_para_head_hash.head_hash, Some(at_block.1), ) - .await? - .and_then(|h| match HeaderOf::::decode(&mut &h.0[..]) { - Ok(header) => Some(header), - Err(e) => { - log::error!( - target: "bridge-metrics", - "Failed to decode {} parachain header at {}: {:?}. Metric will have obsolete value", - P::SourceParachain::NAME, - P::TargetChain::NAME, - e, - ); - - None - }, - }); + .await + .and_then(|maybe_encoded_head| match maybe_encoded_head { + Some(encoded_head) => + HeaderOf::::decode(&mut &encoded_head.0[..]) + .map(|head| Some(head)) + .map_err(Self::Error::ResponseParseFailed), + None => Ok(None), + }) + .map_err(|e| { + log::error!( + target: "bridge-metrics", + "Failed to read or decode {} parachain header at {}: {:?}. Metric will have obsolete value", + P::SourceParachain::NAME, + P::TargetChain::NAME, + e, + ); + e + }) + .unwrap_or(None); if let Some(imported_para_head) = imported_para_head { metrics .update_best_parachain_block_at_target(para_id, *imported_para_head.number());