Skip to content

Commit

Permalink
undo pretty printing of blockvalidationfailures
Browse files Browse the repository at this point in the history
Change-Id: I2b978049d02936a4d09b00487311aac985f45b62
  • Loading branch information
chessai committed Nov 21, 2024
1 parent de0b85b commit 34a1c68
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 12 deletions.
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

0 comments on commit 34a1c68

Please sign in to comment.