Created
February 15, 2023 22:18
-
-
Save jwiegley/6b782f06ffbe7ffc8c17888eb0e46834 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/cabal.project b/cabal.project | |
index 49723525c..57e6618de 100644 | |
--- a/cabal.project | |
+++ b/cabal.project | |
@@ -54,7 +54,7 @@ package yet-another-logger | |
source-repository-package | |
type: git | |
location: https://github.com/kadena-io/pact.git | |
- tag: 842fbc4256b3cbbde337dbeaa393b649a26f1574 | |
+ tag: 88051605d06de39dffe4608e25b85ad2b7da77d8 | |
source-repository-package | |
type: git | |
diff --git a/dep/pact/github.json b/dep/pact/github.json | |
index 9c25bc889..0f61ce104 100644 | |
--- a/dep/pact/github.json | |
+++ b/dep/pact/github.json | |
@@ -3,6 +3,6 @@ | |
"repo": "pact", | |
"branch": "master", | |
"private": false, | |
- "rev": "842fbc4256b3cbbde337dbeaa393b649a26f1574", | |
- "sha256": "0sg20svw369v5ibxxhnizfqimvxyjla0afbv8023sqcjsgc1hglc" | |
+ "rev": "88051605d06de39dffe4608e25b85ad2b7da77d8", | |
+ "sha256": "14ij8gspcnhwa14y1n8crq1fccw2b0db2i6jk47cyry05w8xvf6s" | |
} | |
diff --git a/src/Chainweb/Pact/TransactionExec.hs b/src/Chainweb/Pact/TransactionExec.hs | |
index 8cea6858c..1086ce6ba 100644 | |
--- a/src/Chainweb/Pact/TransactionExec.hs | |
+++ b/src/Chainweb/Pact/TransactionExec.hs | |
@@ -878,8 +878,8 @@ buyGas isPactBackCompatV16 cmd (Miner mid mks) = go | |
where | |
sender = view (cmdPayload . pMeta . pmSender) cmd | |
- initState mc logGas = | |
- set evalLogGas (guard logGas >> Just [("GBuyGas",0)]) $ setModuleCache mc $ initCapabilities [magic_GAS] | |
+ initState mc _logGas = | |
+ setModuleCache mc $ initCapabilities [magic_GAS] | |
run input = do | |
(findPayer isPactBackCompatV16 cmd) >>= \r -> case r of | |
@@ -1030,11 +1030,9 @@ checkTooBigTx initialGas gasLimit next onFail | |
| otherwise = next | |
gasInterpreter :: Gas -> TransactionM db (Interpreter p) | |
-gasInterpreter g = do | |
+gasInterpreter _g = do | |
mc <- use txCache | |
- logGas <- isJust <$> view txGasLogger | |
return $ initStateInterpreter | |
- $ set evalLogGas (guard logGas >> Just [("GTxSize",g)]) -- enables gas logging | |
$ setModuleCache mc def |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src-ghc/Pact/Interpreter.hs b/src-ghc/Pact/Interpreter.hs | |
index 1327a869..694a0409 100644 | |
--- a/src-ghc/Pact/Interpreter.hs | |
+++ b/src-ghc/Pact/Interpreter.hs | |
@@ -172,6 +172,7 @@ setupEvalEnv | |
setupEvalEnv dbEnv ent mode msgData refStore gasEnv np spv pd ec = do | |
gasRef <- newIORef 0 | |
warnRef <- newIORef mempty | |
+ gLogRef <- newIORef [] | |
pure EvalEnv { | |
_eeRefStore = refStore | |
, _eeMsgSigs = mkMsgSigs $ mdSigners msgData | |
@@ -192,6 +193,7 @@ setupEvalEnv dbEnv ent mode msgData refStore gasEnv np spv pd ec = do | |
, _eeAdvice = def | |
, _eeInRepl = False | |
, _eeWarnings = warnRef | |
+ , _eeGasLog = gLogRef | |
} | |
where | |
mkMsgSigs ss = M.fromList $ map toPair ss | |
@@ -230,14 +232,14 @@ interpret runner evalEnv terms = do | |
runEval def evalEnv $ evalTerms runner terms | |
gas <- readIORef (_eeGas evalEnv) | |
warnings <- readIORef (_eeWarnings evalEnv) | |
- let gasLogs = _evalLogGas state | |
- pactExec = _evalPactExec state | |
+ gasLogs <- readIORef (_eeGasLog evalEnv) | |
+ let pactExec = _evalPactExec state | |
modules = _rsLoadedModules $ _evalRefs state | |
-- output uses lenient conversion | |
return $! EvalResult | |
terms | |
(map (elideModRefInfo . toPactValueLenient) rs) | |
- logs pactExec gas modules txid gasLogs (_evalEvents state) warnings | |
+ logs pactExec gas modules txid (Just gasLogs) (_evalEvents state) warnings | |
evalTerms :: Interpreter e -> EvalInput -> Eval e EvalOutput | |
evalTerms interp input = withRollback (start (interpreter interp runInput) >>= end) | |
diff --git a/src/Pact/Gas.hs b/src/Pact/Gas.hs | |
index eea7ff30..c7a8e257 100644 | |
--- a/src/Pact/Gas.hs | |
+++ b/src/Pact/Gas.hs | |
@@ -32,7 +32,8 @@ computeGas i args = do | |
(info,name) = either id (_faInfo &&& _faName) i | |
g1 = runGasModel _geGasModel name args | |
let gUsed = g0 + g1 | |
- evalLogGas %= fmap ((renderCompactText' (pretty name <> ":" <> pretty args <> ":currTotalGas=" <> pretty gUsed),g1):) | |
+ glref <- view eeGasLog | |
+ liftIO $ modifyIORef' glref ((renderCompactText' (pretty name <> ":" <> pretty args <> ":currTotalGas=" <> pretty gUsed),g1):) | |
putGas gUsed | |
if gUsed > fromIntegral _geGasLimit then | |
throwErr GasError info $ "Gas limit (" <> pretty _geGasLimit <> ") exceeded: " <> pretty gUsed | |
@@ -72,7 +73,8 @@ computeGasCommit info name args = do | |
g0 <- getGas | |
let !g1 = runGasModel _geGasModel name args | |
!gUsed = g0 + g1 | |
- evalLogGas %= fmap ((renderCompactText' (pretty name <> ":" <> pretty args <> ":currTotalGas=" <> pretty gUsed),g1):) | |
+ glref <- view eeGasLog | |
+ liftIO $ modifyIORef' glref ((renderCompactText' (pretty name <> ":" <> pretty args <> ":currTotalGas=" <> pretty gUsed),g1):) | |
putGas gUsed | |
if gUsed > fromIntegral _geGasLimit then | |
throwErr GasError info $ "Gas limit (" <> pretty _geGasLimit <> ") exceeded: " <> pretty gUsed | |
diff --git a/src/Pact/Repl.hs b/src/Pact/Repl.hs | |
index 744df80b..58222cb4 100644 | |
--- a/src/Pact/Repl.hs | |
+++ b/src/Pact/Repl.hs | |
@@ -133,6 +133,7 @@ initEvalEnv ls = do | |
mv <- newMVar ls | |
gasRef <- newIORef 0 | |
warnRef <- newIORef mempty | |
+ glref <- newIORef [] | |
return $ EvalEnv | |
{ _eeRefStore = RefStore nativeDefs | |
, _eeMsgSigs = mempty | |
@@ -153,6 +154,7 @@ initEvalEnv ls = do | |
, _eeAdvice = def | |
, _eeInRepl = True | |
, _eeWarnings = warnRef | |
+ , _eeGasLog = glref | |
} | |
where | |
spvs mv = set spvSupport (spv mv) noSPVSupport | |
diff --git a/src/Pact/Repl/Lib.hs b/src/Pact/Repl/Lib.hs | |
index 40325582..afdbd91e 100644 | |
--- a/src/Pact/Repl/Lib.hs | |
+++ b/src/Pact/Repl/Lib.hs | |
@@ -719,8 +719,10 @@ envGas i as = argsError i as | |
gasLog :: RNativeFun LibState | |
gasLog _ _ = do | |
- gl <- use evalLogGas | |
- evalLogGas .= Just [] | |
+ glref <- view eeGasLog | |
+ gl <- Just <$> liftIO (readIORef glref) | |
+ liftIO $ writeIORef glref [] | |
+ -- evalLogGas .= Just [] | |
case gl of | |
Nothing -> return $ tStr $ "Enabled gas log" | |
Just logs -> let total = sum (map snd logs) in | |
diff --git a/src/Pact/Types/Purity.hs b/src/Pact/Types/Purity.hs | |
index 72a8bf5b..d34abe2f 100644 | |
--- a/src/Pact/Types/Purity.hs | |
+++ b/src/Pact/Types/Purity.hs | |
@@ -101,6 +101,7 @@ mkPureEnv holder purity readRowImpl env@EvalEnv{..} = do | |
_eeAdvice | |
_eeInRepl | |
_eeWarnings | |
+ _eeGasLog | |
-- | Operationally creates the sysread-only environment. | |
-- Phantom type and typeclass assigned in "runXXX" functions. | |
diff --git a/src/Pact/Types/Runtime.hs b/src/Pact/Types/Runtime.hs | |
index 37241409..7a077162 100644 | |
--- a/src/Pact/Types/Runtime.hs | |
+++ b/src/Pact/Types/Runtime.hs | |
@@ -30,12 +30,12 @@ module Pact.Types.Runtime | |
RefStore(..),rsNatives, | |
EvalEnv(..),eeRefStore,eeMsgSigs,eeMsgBody,eeMode,eeEntity,eePactStep,eePactDbVar,eeInRepl, | |
eePactDb,eePurity,eeHash,eeGas, eeGasEnv,eeNamespacePolicy,eeSPVSupport,eePublicData,eeExecutionConfig, | |
- eeAdvice, eeWarnings, | |
+ eeAdvice, eeWarnings,eeGasLog, | |
toPactId, | |
Purity(..), | |
RefState(..),rsLoaded,rsLoadedModules,rsNamespace,rsQualifiedDeps, | |
EvalState(..),evalRefs,evalCallStack,evalPactExec, | |
- evalCapabilities,evalLogGas,evalEvents, | |
+ evalCapabilities,evalEvents, | |
Eval(..),runEval,runEval',catchesPactError, | |
call,method, | |
readRow,writeRow,keys,txids,createUserTable,getUserTableInfo,beginTx,commitTx,rollbackTx,getTxLog, | |
@@ -253,6 +253,7 @@ data EvalEnv e = EvalEnv { | |
, _eeInRepl :: Bool | |
-- | Warnings ref | |
, _eeWarnings :: IORef (Set PactWarning) | |
+ , _eeGasLog :: IORef [(Text,Gas)] | |
} | |
makeLenses ''EvalEnv | |
@@ -299,13 +300,13 @@ data EvalState = EvalState { | |
-- | Capability list | |
, _evalCapabilities :: Capabilities | |
-- | Tracks gas logs if enabled (i.e. Just) | |
- , _evalLogGas :: Maybe [(Text,Gas)] | |
+ -- , _evalLogGas :: Maybe [(Text,Gas)] | |
-- | Accumulate events | |
, _evalEvents :: ![PactEvent] | |
} deriving (Show, Generic) | |
makeLenses ''EvalState | |
instance NFData EvalState | |
-instance Default EvalState where def = EvalState def def def def def def | |
+instance Default EvalState where def = EvalState def def def def def | |
-- | Interpreter monad, parameterized over back-end MVar state type. | |
newtype Eval e a = |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment