From 091247318c753bb90db896f4936c2b6b14a11417 Mon Sep 17 00:00:00 2001 From: Edmund Noble Date: Mon, 27 May 2024 10:40:51 -0400 Subject: [PATCH] log: log rewinds in execValidateBlock instead of blocks played Change-Id: Id2d597d6e72b0bbd6825184b9dd122261502d035 --- changes/2024-05-30T144952-0400.txt | 1 + src/Chainweb/Pact/PactService.hs | 32 +++++++++++++++--------------- 2 files changed, 17 insertions(+), 16 deletions(-) create mode 100644 changes/2024-05-30T144952-0400.txt diff --git a/changes/2024-05-30T144952-0400.txt b/changes/2024-05-30T144952-0400.txt new file mode 100644 index 0000000000..790ff19e55 --- /dev/null +++ b/changes/2024-05-30T144952-0400.txt @@ -0,0 +1 @@ +Log rewound blocks during catchup instead of played blocks (#xxxx) diff --git a/src/Chainweb/Pact/PactService.hs b/src/Chainweb/Pact/PactService.hs index 7b387704d3..99eeef342a 100644 --- a/src/Chainweb/Pact/PactService.hs +++ b/src/Chainweb/Pact/PactService.hs @@ -841,15 +841,14 @@ execValidateBlock memPoolAccess headerToValidate payloadToValidate = pactLabel " -- check that we don't exceed the rewind limit. for the purpose -- of this check, the genesis block and the genesis parent -- have the same height. - do - let !currHeight = maybe (genesisHeight v cid) _blockHeight currHeader - let !ancestorHeight = maybe (genesisHeight v cid) _blockHeight commonAncestor - let !rewindLimitSatisfied = ancestorHeight + fromIntegral reorgLimit >= currHeight - unless rewindLimitSatisfied $ - throwM $ RewindLimitExceeded - (RewindLimit reorgLimit) - currHeader - commonAncestor + let !currHeight = maybe (genesisHeight v cid) _blockHeight currHeader + let !ancestorHeight = maybe (genesisHeight v cid) _blockHeight commonAncestor + let !rewindLimitSatisfied = ancestorHeight + fromIntegral reorgLimit >= currHeight + unless rewindLimitSatisfied $ + throwM $ RewindLimitExceeded + (RewindLimit reorgLimit) + currHeader + commonAncestor -- get all blocks on the fork we're going to play, up to the parent -- of the block we're validating let withForkBlockStream kont = case parentOfHeaderToValidate of @@ -860,7 +859,7 @@ execValidateBlock memPoolAccess headerToValidate payloadToValidate = pactLabel " let forkStartHeight = maybe (genesisHeight v cid) (succ . _blockHeight) commonAncestor in getBranchIncreasing bhdb parentHeaderOfHeaderToValidate (fromIntegral forkStartHeight) kont - ((), T2 results (Sum numForkBlocksPlayed)) <- + ((), results) <- withPactState $ \runPact -> withForkBlockStream $ \forkBlockHeaders -> do @@ -874,14 +873,14 @@ execValidateBlock memPoolAccess headerToValidate payloadToValidate = pactLabel " <> ". Block: " <> encodeToText (ObjectEncoded forkBh) Just x -> return $ payloadWithOutputsToPayloadData x void $ execBlock forkBh (CheckablePayload payload) - return (T2 [] (Sum (1 :: Word)), forkBh) + return ([], forkBh) ) forkBlockHeaders -- run the new block, the one we're validating, and -- validate its hashes let runThisBlock = Stream.yield $ do !output <- execBlock headerToValidate payloadToValidate - return (T2 [output] (Sum (0 :: Word)), headerToValidate) + return ([output], headerToValidate) -- here we rewind to the common ancestor block, run the -- transactions in all of its child blocks until the parent @@ -890,12 +889,13 @@ execValidateBlock memPoolAccess headerToValidate payloadToValidate = pactLabel " runPact $ restoreAndSave (ParentHeader <$> commonAncestor) (runForkBlockHeaders >> runThisBlock) - let logPlayed = - -- we consider a fork of height 3 or more to be notable. - if numForkBlocksPlayed > 3 + let logRewind = + -- we consider a fork of height more than 3 to be notable. + if ancestorHeight + 3 < currHeight then logWarn else logDebug - logPlayed $ "execValidateBlock: played " <> sshow numForkBlocksPlayed <> " fork blocks" + logRewind $ + "execValidateBlock: rewound " <> sshow (currHeight - ancestorHeight) <> " blocks" (totalGasUsed, result) <- case results of [r] -> return r _ -> throwM $ PactInternalError "execValidateBlock: wrong number of block results returned from _cpRestoreAndSave."