From c5cfd04f60258d032828a0c3eb526cea949d44d2 Mon Sep 17 00:00:00 2001 From: Edmund Noble Date: Thu, 30 May 2024 16:49:11 -0400 Subject: [PATCH] log: put cut fetch trace telemetry around timeout instead of inside The trace telemetry would never happen if we timed out, making it very unclear which cuts timed out while being fetched Change-Id: I2a4a92d6a600b8cd47ad61d2403397bc72a7bfeb --- src/Chainweb/CutDB.hs | 85 ++++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 42 deletions(-) diff --git a/src/Chainweb/CutDB.hs b/src/Chainweb/CutDB.hs index ea74dec474..356ae6e852 100644 --- a/src/Chainweb/CutDB.hs +++ b/src/Chainweb/CutDB.hs @@ -765,50 +765,51 @@ cutHashesToBlockHeaderMap -- ^ The 'Left' value holds missing hashes, the 'Right' value holds -- a 'Cut'. cutHashesToBlockHeaderMap conf logfun headerStore payloadStore hs = - timeout (_cutDbParamsFetchTimeout conf) go >>= \case - Nothing -> do - let cutOriginText = case _cutHashesLocalPayload hs of - Nothing -> "from " <> maybe "unknown origin" (\p -> "origin " <> toText p) origin - Just _ -> "which was locally mined - the mining loop will stall until unstuck by another miner" - - logfun (maybe Warn (\_ -> Error) (_cutHashesLocalPayload hs)) - $ "Timeout while processing cut " - <> cutIdToTextShort hsid - <> " at height " <> sshow (_cutHashesHeight hs) - <> " from origin " <> cutOriginText - return Nothing - Just (Left missing) -> do - loggCutId logfun Warn hs $ "Failed to get prerequisites for some blocks. Missing: " <> encodeToText missing - return Nothing - Just (Right headers) -> do - return (Just headers) + trace logfun "Chainweb.CutDB.cutHashesToBlockHeaderMap" hsid 1 $ do + timeout (_cutDbParamsFetchTimeout conf) go >>= \case + Nothing -> do + let cutOriginText = case _cutHashesLocalPayload hs of + Nothing -> "from " <> maybe "unknown origin" (\p -> "origin " <> toText p) origin + Just _ -> "which was locally mined - the mining loop will stall until unstuck by another miner" + + logfun (maybe Warn (\_ -> Error) (_cutHashesLocalPayload hs)) + $ "Timeout while processing cut " + <> cutIdToTextShort hsid + <> " at height " <> sshow (_cutHashesHeight hs) + <> " from origin " <> cutOriginText + return Nothing + Just (Left missing) -> do + loggCutId logfun Warn hs $ "Failed to get prerequisites for some blocks. Missing: " <> encodeToText missing + return Nothing + Just (Right headers) -> do + return (Just headers) where hsid = _cutId hs - go = - trace logfun "Chainweb.CutDB.cutHashesToBlockHeaderMap" hsid 1 $ do - plds <- emptyTable - casInsertBatch plds $ HM.elems $ _cutHashesPayloads hs - - hdrs <- emptyTable - casInsertBatch hdrs $ HM.elems $ _cutHashesHeaders hs - - -- for better error messages on validation failure - -- must be a locally-produced payload - let localPayload = _cutHashesLocalPayload hs - - (headers :> missing) <- S.each (HM.toList $ _cutHashes hs) - & S.map (fmap _bhwhHash) - & S.mapM (tryGetBlockHeader hdrs plds localPayload) - & S.partitionEithers - & S.fold_ (\x (cid, h) -> HM.insert cid h x) mempty id - & S.fold (\x (cid, h) -> HM.insert cid h x) mempty id - if null missing - then return $! Right headers - else do - when (isJust $ _cutHashesLocalPayload hs) $ - logfun @Text Error - "error validating locally mined cut; the mining loop will stall until unstuck by another mining node" - return $! Left missing + go = do + + plds <- emptyTable + casInsertBatch plds $ HM.elems $ _cutHashesPayloads hs + + hdrs <- emptyTable + casInsertBatch hdrs $ HM.elems $ _cutHashesHeaders hs + + -- for better error messages on validation failure + -- must be a locally-produced payload + let localPayload = _cutHashesLocalPayload hs + + (headers :> missing) <- S.each (HM.toList $ _cutHashes hs) + & S.map (fmap _bhwhHash) + & S.mapM (tryGetBlockHeader hdrs plds localPayload) + & S.partitionEithers + & S.fold_ (\x (cid, h) -> HM.insert cid h x) mempty id + & S.fold (\x (cid, h) -> HM.insert cid h x) mempty id + if null missing + then return $! Right headers + else do + when (isJust $ _cutHashesLocalPayload hs) $ + logfun @Text Error + "error validating locally mined cut; the mining loop will stall until unstuck by another mining node" + return $! Left missing origin = _cutOrigin hs priority = Priority (- int (_cutHashesHeight hs))