Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

log: log rewinds in execValidateBlock instead of blocks played #1956

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading