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 20, 2024
1 parent de0b85b commit fba35db
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 10 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
7 changes: 1 addition & 6 deletions src/Chainweb/Pact/PactService/ExecBlock.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ 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

Check failure on line 48 in src/Chainweb/Pact/PactService/ExecBlock.hs

View workflow job for this annotation

GitHub Actions / Build (9.8.2, 3.12, macos-latest, true)

The qualified import of ‘Data.ByteString.Lazy’ is redundant

Check failure on line 48 in src/Chainweb/Pact/PactService/ExecBlock.hs

View workflow job for this annotation

GitHub Actions / Build (9.8.2, 3.12, ubuntu-22.04, false)

The qualified import of ‘Data.ByteString.Lazy’ is redundant

Check failure on line 48 in src/Chainweb/Pact/PactService/ExecBlock.hs

View workflow job for this annotation

GitHub Actions / Build (9.10.1, 3.12, ubuntu-22.04, false)

The qualified import of ‘Data.ByteString.Lazy’ is redundant

Check failure on line 48 in src/Chainweb/Pact/PactService/ExecBlock.hs

View workflow job for this annotation

GitHub Actions / Build (9.6.6, 3.12, ubuntu-22.04, false)

The qualified import of ‘Data.ByteString.Lazy’ is redundant

Check failure on line 48 in src/Chainweb/Pact/PactService/ExecBlock.hs

View workflow job for this annotation

GitHub Actions / Build (9.8.2, 3.12, ubuntu-22.04, true)

The qualified import of ‘Data.ByteString.Lazy’ is redundant
import Data.Decimal
Expand Down Expand Up @@ -565,16 +564,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 fba35db

Please sign in to comment.