-
Notifications
You must be signed in to change notification settings - Fork 93
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
Much quieter replays #1713
Much quieter replays #1713
Changes from all commits
3961e13
5e33306
3081d53
b3857cd
166adac
3ef7fc1
12529c9
f95511f
6951213
0380363
55df614
f80cecf
3e4f71d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
{-# LANGUAGE AllowAmbiguousTypes #-} | ||
{-# LANGUAGE BangPatterns #-} | ||
{-# LANGUAGE DerivingStrategies #-} | ||
{-# LANGUAGE DeriveAnyClass #-} | ||
{-# LANGUAGE DeriveGeneric #-} | ||
{-# LANGUAGE FlexibleContexts #-} | ||
{-# LANGUAGE GeneralizedNewtypeDeriving #-} | ||
{-# LANGUAGE LambdaCase #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE RankNTypes #-} | ||
|
@@ -72,6 +76,7 @@ import Data.Maybe | |
import qualified Data.Set as S | ||
import Data.Text (Text) | ||
import qualified Data.Text as T | ||
import qualified System.LogLevel as L | ||
|
||
-- internal Pact modules | ||
|
||
|
@@ -223,14 +228,14 @@ applyCmd v logger gasLogger pdbenv miner gasModel txCtx spv cmd initialGas mcach | |
Right _ -> checkTooBigTx initialGas gasLimit applyPayload redeemAllGas | ||
|
||
displayPactError e = do | ||
r <- jsonErrorResult e "tx failure for request key when running cmd" | ||
r <- failTxWith e "tx failure for request key when running cmd" | ||
redeemAllGas r | ||
|
||
stripPactError e = do | ||
let e' = case callCtx of | ||
ApplyLocal -> e | ||
ApplySend -> toEmptyPactError e | ||
r <- jsonErrorResult e' "tx failure for request key when running cmd" | ||
r <- failTxWith e' "tx failure for request key when running cmd" | ||
redeemAllGas r | ||
|
||
applyPayload = do | ||
|
@@ -247,7 +252,7 @@ applyCmd v logger gasLogger pdbenv miner gasModel txCtx spv cmd initialGas mcach | |
| chainweb217Pact' -> stripPactError e | ||
| chainweb213Pact' || not (isOldListErr e) -> displayPactError e | ||
| otherwise -> do | ||
r <- jsonErrorResult (toOldListErr e) "tx failure for request key when running cmd" | ||
r <- failTxWith (toOldListErr e) "tx failure for request key when running cmd" | ||
redeemAllGas r | ||
Right r -> applyRedeem r | ||
|
||
|
@@ -329,7 +334,7 @@ applyGenesisCmd logger dbEnv spv txCtx cmd = | |
|
||
go = do | ||
-- TODO: fix with version recordification so that this matches the flags at genesis heights. | ||
cr <- catchesPactError logger PrintsUnexpectedError $! runGenesis cmd permissiveNamespacePolicy interp | ||
cr <- catchesPactError logger (onChainErrorPrintingFor txCtx) $! runGenesis cmd permissiveNamespacePolicy interp | ||
case cr of | ||
Left e -> fatal $ "Genesis command failed: " <> sshow e | ||
Right r -> r <$ debug "successful genesis tx for request key" | ||
|
@@ -414,7 +419,7 @@ applyCoinbase v logger dbEnv (Miner mid mks@(MinerKeys mk)) reward@(ParsedDecima | |
case cr of | ||
Left e | ||
| throwCritical -> throwM $ CoinbaseFailure $ sshow e | ||
| otherwise -> (`T2` Nothing) <$> jsonErrorResult e "coinbase tx failure" | ||
| otherwise -> (`T2` Nothing) <$> failTxWith e "coinbase tx failure" | ||
Right er -> do | ||
debug | ||
$! "successful coinbase of " | ||
|
@@ -475,7 +480,7 @@ applyLocal logger gasLogger dbEnv gasModel txCtx spv cmdIn mc execConfig = | |
applyContinuation gas0 interp cm signers chash managedNamespacePolicy | ||
|
||
case cr of | ||
Left e -> jsonErrorResult e "applyLocal" | ||
Left e -> failTxWith e "applyLocal" | ||
Right r -> return $! r { _crMetaData = Just (J.toJsonViaEncode $ ctxToPublicData' txCtx) } | ||
|
||
go = checkTooBigTx gas0 gasLimit (applyPayload $ _pPayload $ _cmdPayload cmd) return | ||
|
@@ -623,21 +628,19 @@ applyUpgrades v cid height | |
logError $ "Upgrade transaction failed! " <> sshow e | ||
throwM e | ||
|
||
jsonErrorResult | ||
failTxWith | ||
:: (Logger logger) | ||
=> PactError | ||
-> Text | ||
-> TransactionM logger p (CommandResult [TxLogJson]) | ||
jsonErrorResult err msg = do | ||
failTxWith err msg = do | ||
logs <- use txLogs | ||
gas <- view txGasLimit -- error means all gas was charged | ||
rk <- view txRequestKey | ||
l <- view txLogger | ||
|
||
logInfo_ l | ||
$! msg | ||
<> ": " <> sshow rk | ||
<> ": " <> sshow err | ||
liftIO $ logFunction l L.Info | ||
(TxFailureLog rk err msg) | ||
|
||
return $! CommandResult rk Nothing (PactResult (Left err)) | ||
gas (Just logs) Nothing Nothing [] | ||
|
@@ -992,7 +995,7 @@ checkTooBigTx initialGas gasLimit next onFail | |
$ "Tx too big (" <> pretty initialGas <> "), limit " | ||
<> pretty gasLimit | ||
|
||
r <- jsonErrorResult pe "Tx too big" | ||
r <- failTxWith pe "Tx too big" | ||
onFail r | ||
| otherwise = next | ||
|
||
|
@@ -1136,15 +1139,15 @@ gasLog m = do | |
l <- view txGasLogger | ||
rk <- view txRequestKey | ||
for_ l $ \logger -> | ||
logInfo_ logger $! m <> ": " <> sshow rk | ||
logInfo_ logger $ m <> ": " <> sshow rk | ||
|
||
-- | Log request keys at DEBUG when successful | ||
-- | ||
debug :: (Logger logger) => Text -> TransactionM logger db () | ||
debug s = do | ||
l <- view txLogger | ||
rk <- view txRequestKey | ||
logDebug_ l $! s <> ": " <> sshow rk | ||
logDebug_ l $ s <> ": " <> sshow rk | ||
|
||
|
||
-- | Denotes fatal failure points in the tx exec process | ||
|
@@ -1155,7 +1158,7 @@ fatal e = do | |
rk <- view txRequestKey | ||
|
||
logError_ l | ||
$! "critical transaction failure: " | ||
$ "critical transaction failure: " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the reason for undoing the bangs There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Loggers are always strict, so the bangs aren't necessary... except that they're lazy when they're filtered such that the log message never makes it to the queue. I've seen some pretty big log messages here, so I'd like those not constructed in case that can raise throughput. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, log messages are deep forced before added to the queue. Avoiding construction when their log level is disabled is a good point. |
||
<> sshow rk <> ": " <> e | ||
|
||
throwM $ PactTransactionExecError (fromUntypedHash $ unRequestKey rk) e | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,7 @@ module Chainweb.Pact.Types | |
, GasId(..) | ||
, EnforceCoinbaseFailure(..) | ||
, CoinbaseUsePrecompiled(..) | ||
, cleanModuleCache | ||
|
||
-- * Transaction State | ||
, TransactionState(..) | ||
|
@@ -81,7 +82,6 @@ module Chainweb.Pact.Types | |
, psPreInsertCheckTimeout | ||
, psOnFatalError | ||
, psVersion | ||
, psValidateHashesOnReplay | ||
, psLogger | ||
, psGasLogger | ||
, psAllowReadsInLocal | ||
|
@@ -147,6 +147,7 @@ module Chainweb.Pact.Types | |
-- * types | ||
, TxTimeout(..) | ||
, ApplyCmdExecutionContext(..) | ||
, TxFailureLog(..) | ||
|
||
-- * miscellaneous | ||
, defaultOnFatalError | ||
|
@@ -217,7 +218,6 @@ import Chainweb.Time | |
import Chainweb.Transaction | ||
import Chainweb.Utils | ||
import Chainweb.Version | ||
import Chainweb.Version.Guards | ||
import Utils.Logging.Trace | ||
|
||
|
||
|
@@ -288,6 +288,15 @@ moduleCacheKeys :: ModuleCache -> [ModuleName] | |
moduleCacheKeys (ModuleCache a) = fst <$> LHM.toList a | ||
{-# INLINE moduleCacheKeys #-} | ||
|
||
-- this can't go in Chainweb.Version.Guards because it causes an import cycle | ||
-- it uses genesisHeight which is from BlockHeader which imports Guards | ||
Comment on lines
+291
to
+292
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it make sense to move There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably would cause a cycle. I tried it during recordification. |
||
cleanModuleCache :: ChainwebVersion -> ChainId -> BlockHeight -> Bool | ||
cleanModuleCache v cid bh = | ||
case v ^?! versionForks . at Chainweb217Pact . _Just . onChain cid of | ||
ForkAtBlockHeight bh' -> bh == bh' | ||
ForkAtGenesis -> bh == genesisHeight v cid | ||
ForkNever -> False | ||
|
||
-- -------------------------------------------------------------------- -- | ||
-- Local vs. Send execution context flag | ||
|
||
|
@@ -414,7 +423,6 @@ data PactServiceEnv logger tbl = PactServiceEnv | |
-- ^ The limit of checkpointer's rewind in the `execValidationBlock` command. | ||
, _psOnFatalError :: !(forall a. PactException -> Text -> IO a) | ||
, _psVersion :: !ChainwebVersion | ||
, _psValidateHashesOnReplay :: !Bool | ||
, _psAllowReadsInLocal :: !Bool | ||
, _psLogger :: !logger | ||
, _psGasLogger :: !(Maybe logger) | ||
|
@@ -464,7 +472,6 @@ testPactServiceConfig = PactServiceConfig | |
{ _pactReorgLimit = defaultReorgLimit | ||
, _pactLocalRewindDepthLimit = defaultLocalRewindDepthLimit | ||
, _pactPreInsertCheckTimeout = defaultPreInsertCheckTimeout | ||
, _pactRevalidate = True | ||
, _pactQueueSize = 1000 | ||
, _pactResetDb = True | ||
, _pactAllowReadsInLocal = False | ||
|
@@ -493,6 +500,15 @@ newtype TxTimeout = TxTimeout TransactionHash | |
deriving Show | ||
instance Exception TxTimeout | ||
|
||
data TxFailureLog = TxFailureLog !RequestKey !PactError !Text | ||
deriving stock (Generic) | ||
deriving anyclass (NFData, Typeable) | ||
instance LogMessage TxFailureLog where | ||
logText (TxFailureLog rk err msg) = | ||
msg <> ": " <> sshow rk <> ": " <> sshow err | ||
instance Show TxFailureLog where | ||
show m = unpack (logText m) | ||
|
||
defaultOnFatalError :: forall a. (LogLevel -> Text -> IO ()) -> PactException -> Text -> IO a | ||
defaultOnFatalError lf pex t = do | ||
lf Error errMsg | ||
|
@@ -728,9 +744,11 @@ catchesPactError :: (MonadCatch m, MonadIO m, Logger logger) => logger -> Unexpe | |
catchesPactError logger exnPrinting action = catches (Right <$> action) | ||
[ Handler $ \(e :: PactError) -> return $ Left e | ||
, Handler $ \(e :: SomeException) -> do | ||
liftIO $ logWarn_ logger ("catchesPactError: unknown error: " <> sshow e) | ||
return $ Left $ PactError EvalError def def $ | ||
case exnPrinting of | ||
PrintsUnexpectedError -> viaShow e | ||
CensorsUnexpectedError -> "unknown error" | ||
!err <- case exnPrinting of | ||
PrintsUnexpectedError -> | ||
return (viaShow e) | ||
CensorsUnexpectedError -> do | ||
liftIO $ logWarn_ logger ("catchesPactError: unknown error: " <> sshow e) | ||
return "unknown error" | ||
return $ Left $ PactError EvalError def def err | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍