Skip to content

Commit

Permalink
log: log rewinds in execValidateBlock instead of blocks played
Browse files Browse the repository at this point in the history
Change-Id: Id2d597d6e72b0bbd6825184b9dd122261502d035
  • Loading branch information
edmundnoble committed Jun 14, 2024
1 parent 1a9eb99 commit 3cead4b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
1 change: 1 addition & 0 deletions changes/2024-05-30T144952-0400.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Log rewound blocks during catchup instead of played blocks
32 changes: 16 additions & 16 deletions src/Chainweb/Pact/PactService.hs
Original file line number Diff line number Diff line change
Expand Up @@ -866,15 +866,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
Expand All @@ -885,7 +884,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

Expand All @@ -899,14 +898,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
Expand All @@ -915,12 +914,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."
Expand Down

0 comments on commit 3cead4b

Please sign in to comment.