Skip to content

Commit

Permalink
Revert 1150 (#1154)
Browse files Browse the repository at this point in the history
* Revert "Support Pact Events (#1150)"

This reverts commit 10c2c90.

* remove 1150 from CHANGELOG
  • Loading branch information
larskuhtz authored Oct 8, 2020
1 parent 01b5363 commit a88ec54
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 113 deletions.
9 changes: 0 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,6 @@ before that date.

This version will stop working on **2020-11-19T00:00:00Z**.

*Forks:*

* Support for Pact Events. This new pact feature will be activated on
the Kadena Mainnet at block height 1,013,500, which is expected to occur at
2020-10-15 18:47:13 UTC. On Testnet it is activated at block height 558,000,
which is expected to occur at 2020-10-15 17:11:45 UTC. (#1150)

*Other Changes*:

* Upgrade to Rosetta version 1.4.4 (#1149)

* Adjust the default API request rate limits to better match the expected
Expand Down
3 changes: 2 additions & 1 deletion cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ debug-info: True
source-repository-package
type: git
location: https://github.com/kadena-io/pact.git
tag: 43f58739d3b8b5f63fe52036abd1892bef4344e6
tag: eff39aefdcff3979dd93b20bca8bff7ed8490ea8

source-repository-package
type: git
Expand All @@ -30,3 +30,4 @@ source-repository-package

package vault
documentation: false

4 changes: 2 additions & 2 deletions dep/kpkgs/github.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"repo": "kpkgs",
"branch": "master",
"private": false,
"rev": "9f5ca511e3869584c5c595ac4ee5bd7f55ebfb2e",
"sha256": "0zzykcb9pqagv9w789wv4sgdfzpapxl60ppnqjyiznkyvk2pjk8m"
"rev": "378373e8f7142623d322daff0f1ef1b841b57bda",
"sha256": "18ysb396xhi8nm73y9idqsk8kfd296c8pn1jh2nxpfxxa9s6mwps"
}
2 changes: 1 addition & 1 deletion src/Chainweb/Pact/NoCoinbase.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ import Pact.Types.PactValue
noCoinbase :: CommandResult a
noCoinbase = CommandResult
(RequestKey pactInitialHash) Nothing
(PactResult (Right (PactSuccess (PLiteral (LString "NO_COINBASE")) [])))
(PactResult (Right (PLiteral (LString "NO_COINBASE"))))
0 Nothing Nothing Nothing
{-# NOINLINE noCoinbase #-}
18 changes: 3 additions & 15 deletions src/Chainweb/Pact/SPV.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import Control.Monad.Catch

import Data.Aeson hiding (Object, (.=))
import Data.Default (def)
import qualified Data.Map.Strict as M
import Data.Text (Text, pack)
import qualified Data.Text.Encoding as T

Expand Down Expand Up @@ -122,23 +121,12 @@ verifySPV bdb bh typ proof = go typ proof
case _crResult q of
PactResult Left{} ->
return (Left "invalid command result in tx output proof")
PactResult (Right v) -> return $ Right $ translatePactSuccess v
PactResult (Right v) -> case fromPactValue v of
TObject !j _ -> return (Right j)
_ -> return $ Left "spv-verified tx output has invalid type"

t -> return . Left $! "unsupported SPV types: " <> t

translatePactSuccess :: PactSuccess -> Object Name
translatePactSuccess (PactSuccess v es) = Object (ObjectMap m) TyAny def def
where
m = M.fromList
[("value",fromPactValue v)
,("events",toTList TyAny def $ map ev es)]
ev e = toTObject TyAny def $
[("name",toTerm $ _eventName e)
,("params",toTList TyAny def $ map fromPactValue $ _eventParams e)
,("module",toTerm $ asString $ _eventModule e)
,("moduleHash",toTerm $ asString $ _eventModuleHash e)
]

-- | SPV defpact transaction verification support. This call validates a pact 'endorsement'
-- in Pact, providing a validation that the yield data of a cross-chain pact is valid.
--
Expand Down
34 changes: 12 additions & 22 deletions src/Chainweb/Pact/TransactionExec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,12 @@ import Data.Tuple.Strict (T2(..))

-- internal Pact modules

import Pact.Eval (eval, liftTerm)
import Pact.Eval (eval, liftTerm, lookupModule)
import Pact.Gas (freeGasEnv)
import Pact.Interpreter
import Pact.Native.Capabilities (evalCap)
import Pact.Parse (ParsedDecimal(..), parseExprs)
import Pact.Runtime.Capabilities (popCapStack)
import Pact.Runtime.Utils
import Pact.Types.Capability
import Pact.Types.Command
import Pact.Types.Hash as Pact
Expand Down Expand Up @@ -158,7 +157,6 @@ applyCmd v logger pdbenv miner gasModel txCtx spv cmdIn mcache0 =
: ( [ FlagOldReadOnlyBehavior | isPactBackCompatV16 ]
++ [ FlagPreserveModuleNameBug | not isModuleNameFix ]
++ [ FlagPreserveNsModuleInstallBug | not isModuleNameFix2 ]
++ enablePactEvents' txCtx
)

cenv = TransactionEnv Transactional pdbenv logger (ctxToPublicData txCtx) spv nid gasPrice
Expand Down Expand Up @@ -281,10 +279,9 @@ applyCoinbase v logger dbEnv (Miner mid mks) reward@(ParsedDecimal d) txCtx
where
fork1_3InEffect = vuln797Fix v cid bh
throwCritical = fork1_3InEffect || enfCBFailure
ec = mkExecutionConfig $
ec = mkExecutionConfig
[ FlagDisableModuleInstall
, FlagDisableHistoryInTransactionalMode ] ++
enablePactEvents' txCtx
, FlagDisableHistoryInTransactionalMode ]
tenv = TransactionEnv Transactional dbEnv logger (ctxToPublicData txCtx) noSPVSupport
Nothing 0.0 rk 0 ec
txst = TransactionState mc mempty 0 Nothing (_geGasModel freeGasEnv)
Expand Down Expand Up @@ -318,15 +315,10 @@ applyCoinbase v logger dbEnv (Miner mid mks) reward@(ParsedDecimal d) txCtx
logs <- use txLogs

return $! T2
(CommandResult rk (_erTxId er) (successResult er)
(CommandResult rk (_erTxId er) (PactResult (Right (last $ _erOutput er)))
(_erGas er) (Just $ logs) (_erExec er) Nothing)
upgradedModuleCache

enablePactEvents' :: TxContext -> [ExecutionFlag]
enablePactEvents' tc
| enablePactEvents (ctxVersion tc) (ctxCurrentBlockHeight tc) = []
| otherwise = [FlagDisablePactEvents]


applyLocal
:: Logger
Expand Down Expand Up @@ -564,12 +556,6 @@ runGenesis cmd nsp interp = case payload of
chash = toUntypedHash $ _cmdHash cmd
payload = _pPayload $ _cmdPayload cmd

-- | Create success result.
-- Note that 'last' is ok as interpreter guarantees correct output
-- Forces evaluation for lazy errors.
successResult :: EvalResult -> PactResult
successResult er = PactResult $!! Right $ PactSuccess (last $ _erOutput er) (_erEvents er)

-- | Execute an 'ExecMsg' and Return the result with module cache
--
applyExec
Expand All @@ -580,11 +566,14 @@ applyExec
-> NamespacePolicy
-> TransactionM p (CommandResult [TxLog Value])
applyExec interp em senderSigs hsh nsp = do
er@EvalResult{..} <- applyExec' interp em senderSigs hsh nsp
EvalResult{..} <- applyExec' interp em senderSigs hsh nsp
debug $ "gas logs: " <> sshow _erLogGas
logs <- use txLogs
rk <- view txRequestKey
return $! CommandResult rk _erTxId (successResult er)
-- applyExec enforces non-empty expression set so `last` ok
-- forcing it here for lazy errors. TODO NFData the Pacts
lastResult <- return $!! last _erOutput
return $! CommandResult rk _erTxId (PactResult (Right lastResult))
_erGas (Just logs) _erExec Nothing

-- | Variation on 'applyExec' that returns 'EvalResult' as opposed to
Expand Down Expand Up @@ -624,11 +613,12 @@ applyContinuation
-> NamespacePolicy
-> TransactionM p (CommandResult [TxLog Value])
applyContinuation interp cm senderSigs hsh nsp = do
er@EvalResult{..} <- applyContinuation' interp cm senderSigs hsh nsp
EvalResult{..} <- applyContinuation' interp cm senderSigs hsh nsp
debug $ "gas logs: " <> sshow _erLogGas
logs <- use txLogs
rk <- view txRequestKey
return $! (CommandResult rk _erTxId (successResult er)
-- last safe here because cont msg is guaranteed one exp
return $! (CommandResult rk _erTxId (PactResult (Right (last _erOutput)))
_erGas (Just logs) _erExec Nothing)

-- | Execute a 'ContMsg' and return just eval result, not wrapped in a
Expand Down
4 changes: 0 additions & 4 deletions src/Chainweb/Pact/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ module Chainweb.Pact.Types
, ctxToPublicData
, ctxToPublicData'
, ctxCurrentBlockHeight
, ctxVersion
, getTxContext

-- * Pact Service State
Expand Down Expand Up @@ -427,9 +426,6 @@ ctxBlockHeader = _parentHeader . _tcParentHeader
ctxCurrentBlockHeight :: TxContext -> BlockHeight
ctxCurrentBlockHeight = succ . _blockHeight . ctxBlockHeader

ctxVersion :: TxContext -> ChainwebVersion
ctxVersion = _blockChainwebVersion . ctxBlockHeader

-- | Assemble tx context from transaction metadata and parent header.
getTxContext :: PublicMeta -> PactServiceM cas TxContext
getTxContext pm = use psParentHeader >>= \ph -> return (TxContext ph pm)
Expand Down
9 changes: 0 additions & 9 deletions src/Chainweb/Version.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ module Chainweb.Version
, skipTxTimingValidation
, enableModuleNameFix
, enableModuleNameFix2
, enablePactEvents
-- ** BlockHeader Validation Guards
, slowEpochGuard
, oldTargetGuard
Expand Down Expand Up @@ -840,14 +839,6 @@ enableModuleNameFix2 Mainnet01 bh = bh >= 752214 -- ~ 2020-07-17 0:00:00 UTC
enableModuleNameFix2 Testnet04 bh = bh >= 289966 -- ~ 2020-07-13
enableModuleNameFix2 _ bh = bh >= 2

-- | Enable serialization of Pact Events (Pact 3.6) in output
enablePactEvents :: ChainwebVersion -> BlockHeight -> Bool
enablePactEvents Mainnet01 bh = bh >= 1_013_500 -- 2020-10-15 18:47:13 UTC
enablePactEvents Testnet04 bh = bh >= 558_000 -- 2020-10-15 17:11:45 UTC
enablePactEvents Development bh = bh >= 120
enablePactEvents (FastTimedCPM g) _ = g == singletonChainGraph -- For testing events
enablePactEvents _ bh = bh >= 2

-- -------------------------------------------------------------------------- --
-- Header Validation Guards
--
Expand Down
2 changes: 1 addition & 1 deletion stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ extra-deps:

# --- Custom Pins --- #
- github: kadena-io/pact
commit: 43f58739d3b8b5f63fe52036abd1892bef4344e6
commit: eff39aefdcff3979dd93b20bca8bff7ed8490ea8
- github: kadena-io/chainweb-storage
commit: 07e7eb7596c7105aee42dbdb6edd10e3f23c0d7e
- github: kadena-io/rosetta
Expand Down
66 changes: 27 additions & 39 deletions test/Chainweb/Test/Pact/PactExec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,17 @@ import Chainweb.Test.Utils
import Chainweb.Transaction
import Chainweb.Version (ChainwebVersion(..))
import Chainweb.Version.Utils (someChainId)
import Chainweb.Utils (sshow, tryAllSynchronous, decodeB64UrlNoPaddingText)
import Chainweb.Utils (sshow, tryAllSynchronous)

import Pact.Types.Command
import Pact.Types.Hash
import Pact.Types.PactValue
import Pact.Types.Persistence
import Pact.Types.Pretty
import Pact.Types.Runtime (PactEvent(..),ModuleHash(..))

testVersion :: ChainwebVersion
testVersion = FastTimedCPM petersonChainGraph

testEventsVersion :: ChainwebVersion
testEventsVersion = FastTimedCPM singletonChainGraph

tests :: ScheduledTest
tests = ScheduledTest label $
withResource newPayloadDb killPdb $ \pdb ->
Expand All @@ -91,7 +88,7 @@ tests = ScheduledTest label $
\ctx -> _schTest $ execTest ctx testReq4
, withPactCtxSQLite testVersion (bhdbIO rocksIO) pdb defaultPactServiceConfig $
\ctx -> _schTest $ execTest ctx testReq5
, withPactCtxSQLite testEventsVersion (bhdbIO rocksIO) pdb defaultPactServiceConfig $
, withPactCtxSQLite testVersion (bhdbIO rocksIO) pdb defaultPactServiceConfig $
\ctx -> _schTest $ execTxsTest ctx "testTfrGas" testTfrGas
, withPactCtxSQLite testVersion (bhdbIO rocksIO) pdb defaultPactServiceConfig $
\ctx -> _schTest $ execTxsTest ctx "testGasPayer" testGasPayer
Expand Down Expand Up @@ -204,11 +201,11 @@ checkResultSuccess :: HasCallStack => ([PactResult] -> Assertion) -> Either Stri
checkResultSuccess _ (Left e) = assertFailure $ "Expected success, got: " ++ show e
checkResultSuccess test (Right (TestResponse outs _)) = test $ map (_crResult . snd) outs

checkPactResultSuccess :: HasCallStack => String -> PactResult -> (PactSuccess -> Assertion) -> Assertion
checkPactResultSuccess :: HasCallStack => String -> PactResult -> (PactValue -> Assertion) -> Assertion
checkPactResultSuccess _ (PactResult (Right pv)) test = test pv
checkPactResultSuccess msg (PactResult (Left e)) _ = assertFailure $ msg ++ ": expected tx success, got " ++ show e

checkPactResultSuccessLocal :: HasCallStack => String -> (PactSuccess -> Assertion) -> PactResult -> Assertion
checkPactResultSuccessLocal :: HasCallStack => String -> (PactValue -> Assertion) -> PactResult -> Assertion
checkPactResultSuccessLocal msg test r = checkPactResultSuccess msg r test

checkPactResultFailure :: HasCallStack => String -> String -> PactResult -> Assertion
Expand Down Expand Up @@ -238,16 +235,7 @@ testTfrGas = (V.singleton <$> tx,checkResultSuccess test)
]
$ mkCmd "testTfrGas"
$ mkExec' "(coin.transfer \"sender00\" \"sender01\" 1.0)"
test [PactResult (Right pv)] = do
mh <- decodeB64UrlNoPaddingText "_S6HOO3J8-dEusvtnjSF4025dAxKu6eFSIOZocQwimA"
assertEqual "transfer succeeds"
(PactSuccess (pString "Write succeeded")
[PactEvent "TRANSFER"
[pString "sender00",pString "sender01",pDecimal 1.0]
"coin"
(ModuleHash (Hash mh))
])
pv
test [PactResult (Right pv)] = assertEqual "transfer succeeds" (pString "Write succeeded") pv
test r = assertFailure $ "Expected single result, got: " ++ show r

testBadSenderFails :: TxsTest
Expand Down Expand Up @@ -308,13 +296,13 @@ testGasPayer = (txs,checkResultSuccess test)

test [impl,setupUser,fundGasAcct,paidTx] = do
checkPactResultSuccess "impl" impl $
assertEqual "impl" (pactSuccess $ pString "TableCreated")
assertEqual "impl" (pString "TableCreated")
checkPactResultSuccess "setupUser" setupUser $
assertEqual "setupUser" (pactSuccess $ pString "Write succeeded")
assertEqual "setupUser" (pString "Write succeeded")
checkPactResultSuccess "fundGasAcct" fundGasAcct $
assertEqual "fundGasAcct" (pactSuccess $ pString "Write succeeded")
assertEqual "fundGasAcct" (pString "Write succeeded")
checkPactResultSuccess "paidTx" paidTx $
assertEqual "paidTx" (pactSuccess $ pDecimal 3)
assertEqual "paidTx" (pDecimal 3)
test r = assertFailure $ "Expected 4 results, got: " ++ show r


Expand Down Expand Up @@ -366,15 +354,15 @@ testContinuationGasPayer = (txs,checkResultSuccess test)

test [impl,fundGasAcct,contFirstStep,balCheck1,paidSecondStep,balCheck2] = do
checkPactResultSuccess "impl" impl $ assertEqual "impl"
(pactSuccess $ pString "Loaded module user.simple-cont-module, hash pCtVh0IDPvRIdVFXxznBFTwsZcwbIcYAnfv7yzr4wRI")
(pString "Loaded module user.simple-cont-module, hash pCtVh0IDPvRIdVFXxznBFTwsZcwbIcYAnfv7yzr4wRI")
checkPactResultSuccess "fundGasAcct" fundGasAcct $ assertEqual "fundGasAcct"
(pactSuccess $ pString "Write succeeded")
(pString "Write succeeded")
checkPactResultSuccess "contFirstStep" contFirstStep $ assertEqual "contFirstStep"
(pactSuccess $ pString "Step One")
checkPactResultSuccess "balCheck1" balCheck1 $ assertEqual "balCheck1" (pactSuccess $ pDecimal 100)
(pString "Step One")
checkPactResultSuccess "balCheck1" balCheck1 $ assertEqual "balCheck1" (pDecimal 100)
checkPactResultSuccess "paidSecondStep" paidSecondStep $ assertEqual "paidSecondStep"
(pactSuccess $ pString "Step Two")
checkPactResultSuccess "balCheck2" balCheck2 $ assertEqual "balCheck2" (pactSuccess $ pDecimal 99.999_5)
(pString "Step Two")
checkPactResultSuccess "balCheck2" balCheck2 $ assertEqual "balCheck2" (pDecimal 99.999_5)
test r = assertFailure $ "Expected 6 results, got: " ++ show r

testExecGasPayer :: TxsTest
Expand Down Expand Up @@ -418,12 +406,12 @@ testExecGasPayer = (txs,checkResultSuccess test)

test [impl,fundGasAcct,balCheck1,paidTx,balCheck2] = do
checkPactResultSuccess "impl" impl $ assertEqual "impl"
(pactSuccess $ pString "Loaded module user.gas-payer-for-exec, hash _S7ASfb_Lvr5wmjERG_XwPUoojW6GHBWI2u0W6jmID0")
(pString "Loaded module user.gas-payer-for-exec, hash _S7ASfb_Lvr5wmjERG_XwPUoojW6GHBWI2u0W6jmID0")
checkPactResultSuccess "fundGasAcct" fundGasAcct $ assertEqual "fundGasAcct"
(pactSuccess $ pString "Write succeeded")
checkPactResultSuccess "balCheck1" balCheck1 $ assertEqual "balCheck1" (pactSuccess $ pDecimal 100)
checkPactResultSuccess "paidTx" paidTx $ assertEqual "paidTx" (pactSuccess $ pDecimal 3)
checkPactResultSuccess "balCheck2" balCheck2 $ assertEqual "balCheck2" (pactSuccess $ pDecimal 99.999_6)
(pString "Write succeeded")
checkPactResultSuccess "balCheck1" balCheck1 $ assertEqual "balCheck1" (pDecimal 100)
checkPactResultSuccess "paidTx" paidTx $ assertEqual "paidTx" (pDecimal 3)
checkPactResultSuccess "balCheck2" balCheck2 $ assertEqual "balCheck2" (pDecimal 99.999_6)
test r = assertFailure $ "Expected 6 results, got: " ++ show r

testFailureRedeem :: TxsTest
Expand All @@ -445,19 +433,19 @@ testFailureRedeem = (txs,checkResultSuccess test)
test [sbal0,mbal0,ferror,sbal1,mbal1] = do
-- sender 00 first is 100000000 - full gas debit during tx (1)
checkPactResultSuccess "sender bal 0" sbal0 $
assertEqual "sender bal 0" (pactSuccess $ pDecimal 99_999_990)
assertEqual "sender bal 0" (pDecimal 99_999_990)
-- miner first is reward + epsilon tx size gas for [0]
checkPactResultSuccess "miner bal 0" mbal0 $
assertEqual "miner bal 0" (pactSuccess $ pDecimal 2.344523)
assertEqual "miner bal 0" (pDecimal 2.344523)
-- this should reward 10 more to miner
checkPactResultFailure "forced error" "forced error" ferror
-- sender 00 second is down epsilon size costs
-- from [0,1] + 10 for error + 10 full gas debit during tx ~ 99999980
checkPactResultSuccess "sender bal 1" sbal1 $
assertEqual "sender bal 1" (pactSuccess $ pDecimal 99_999_979.92)
assertEqual "sender bal 1" (pDecimal 99_999_979.92)
-- miner second is up 10 from error plus epsilon from [1,2,3] ~ 12
checkPactResultSuccess "miner bal 1" mbal1 $
assertEqual "miner bal 1" (pactSuccess $ pDecimal 12.424523)
assertEqual "miner bal 1" (pDecimal 12.424523)
test r = assertFailure $ "Expected 5 results, got: " ++ show r


Expand All @@ -480,7 +468,7 @@ testAllowReadsLocalSuccess = (tx,test)
mkExec' "(at 'balance (read coin.coin-table \"sender00\"))"
test = checkLocalSuccess $
checkPactResultSuccessLocal "testAllowReadsLocalSuccess" $
assertEqual "sender00 bal" (pactSuccess $ pDecimal 100_000_000.0)
assertEqual "sender00 bal" (pDecimal 100_000_000.0)


-- -------------------------------------------------------------------------- --
Expand Down Expand Up @@ -591,7 +579,7 @@ _showValidationFailure = do
let cr1 = CommandResult
{ _crReqKey = RequestKey pactInitialHash
, _crTxId = Nothing
, _crResult = PactResult $ Right $ pactSuccess $ pString "hi"
, _crResult = PactResult $ Right $ pString "hi"
, _crGas = 0
, _crLogs = Just [TxLog "Domain" "Key" (object [ "stuff" .= True ])]
, _crContinuation = Nothing
Expand Down
Loading

0 comments on commit a88ec54

Please sign in to comment.