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

undo pretty printing of BlockValidationFailures #2046

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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: 0 additions & 1 deletion chainweb.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,6 @@ library
build-depends:
, Decimal >= 0.4.2
, aeson >= 2.2
, aeson-pretty >= 0.8
, asn1-encoding >=0.9
, asn1-types >=0.3
, async >= 2.2
Expand Down
4 changes: 2 additions & 2 deletions src/Chainweb/Pact/PactService.hs
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ execReadOnlyReplay lowerBound maybeUpperBound = pactLabel "execReadOnlyReplay" $
let
printValidationError (BlockValidationFailure (BlockValidationFailureMsg m)) = do
writeIORef validationFailedRef True
logFunctionText logger Error m
logFunctionText logger Error (J.getJsonText m)
printValidationError e = throwM e
handleMissingBlock NoHistory = throwM $ BlockHeaderLookupFailure $
"execReadOnlyReplay: missing block: " <> sshow bh
Expand All @@ -831,7 +831,7 @@ execReadOnlyReplay lowerBound maybeUpperBound = pactLabel "execReadOnlyReplay" $
)
validationFailed <- readIORef validationFailedRef
when validationFailed $
throwM $ BlockValidationFailure $ BlockValidationFailureMsg "Prior block validation errors"
throwM $ BlockValidationFailure $ BlockValidationFailureMsg $ J.encodeJsonText ("Prior block validation errors" :: Text)
return r

heightProgress :: BlockHeight -> BlockHeight -> IORef BlockHeight -> (Text -> IO ()) -> IO ()
Expand Down
9 changes: 1 addition & 8 deletions src/Chainweb/Pact/PactService/ExecBlock.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ import Control.Monad.Reader
import Control.Monad.State.Strict

import qualified Data.Aeson as A
import qualified Data.Aeson.Encode.Pretty as A
import qualified Data.ByteString.Short as SB
import qualified Data.ByteString.Lazy as BL
import Data.Decimal
import Data.List qualified as List
import Data.Either
Expand All @@ -56,7 +54,6 @@ import qualified Data.Map as Map
import Data.Maybe
import Data.Text (Text)
import qualified Data.Text as T
import qualified Data.Text.Encoding as T
import Data.Vector (Vector)
import qualified Data.Vector as V

Expand Down Expand Up @@ -565,16 +562,12 @@ validateHashes bHeader payload miner transactions =
if newHash == prevHash
then Right actualPwo
else Left $ BlockValidationFailure $ BlockValidationFailureMsg $
prettyJson $ J.encodeText $ J.object
J.encodeJsonText $ J.object
[ "header" J..= J.encodeWithAeson (ObjectEncoded bHeader)
, "mismatch" J..= errorMsg "Payload hash" prevHash newHash
, "details" J..= difference
]
where
prettyJson txt = case A.eitherDecodeStrict @A.Value (T.encodeUtf8 txt) of
Right obj -> T.cons '\n' $ T.decodeUtf8 $ BL.toStrict $ A.encodePretty obj
Left err -> error $ "validateHashes: impossible JSON decode failure: " <> show err

actualPwo = toPayloadWithOutputs miner transactions

newHash = _payloadWithOutputsPayloadHash actualPwo
Expand Down
2 changes: 1 addition & 1 deletion src/Chainweb/Pact/Service/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ data LocalPreflightSimulation
| LegacySimulation
deriving stock (Eq, Show, Generic)

newtype BlockValidationFailureMsg = BlockValidationFailureMsg Text
newtype BlockValidationFailureMsg = BlockValidationFailureMsg J.JsonText
deriving (Eq, Ord, Generic)
deriving newtype (J.Encode)

Expand Down
Loading