Skip to content

Commit

Permalink
Roundtrip modules
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcardon committed Oct 12, 2024
1 parent e550ef8 commit 0111909
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
4 changes: 2 additions & 2 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ source-repository-package
source-repository-package
type: git
location: https://github.com/kadena-io/pact-5.git
tag: 0aff0651cf37d463d6d4534a42c037cb00c0bf20
--sha256: 0z6zl9fzsv3c3ig5lxcj6jvffllvg20x21rbvvw8sh4g7rbjs0xc
tag: d114e14f22ced74bfbdcde8e82c3e0038203421d
--sha256: 11a6d2c0wc8smv8aacpfdl12yp5dd392v4yq5mnh5lvac08kmqcw

source-repository-package
type: git
Expand Down
5 changes: 4 additions & 1 deletion src/Chainweb/Pact/ReflectingDb.hs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ pact4ReflectingDb PactTables{..} pact4Db = do

Pact4.Modules -> do
let rowString = Pact4.asString k
encoded = J.encodeStrict v
jsonEncoded = J.encodeStrict v

let serial = serialisePact_lineinfo
let encoded = maybe jsonEncoded (_encodeModuleData serial . view document) (_decodeModuleData serial jsonEncoded)
atomicModifyIORef' ptModules $ \(MockSysTable m) -> (MockSysTable $ M.insertWith (\_new old -> old) (Rendered rowString) encoded m, ())
Pact4.KeySets -> do
let rowString = Pact4.asString k
Expand Down
23 changes: 17 additions & 6 deletions src/Chainweb/Pact5/TransactionExec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ applyCoinbase logger db reward txCtx = do
let (coinbaseTerm, coinbaseData) = mkCoinbaseTerm mid mks reward
eCoinbaseTxResult <-
evalExecTerm Transactional
db noSPVSupport freeGasModel (Set.fromList [FlagDisableRuntimeRTC]) SimpleNamespacePolicy
db noSPVSupport freeGasModel GasLogsDisabled (Set.fromList [FlagDisableRuntimeRTC]) SimpleNamespacePolicy
(ctxToPublicData def txCtx)
MsgData
{ mdHash = coinbaseHash
Expand Down Expand Up @@ -604,7 +604,7 @@ runPayload execMode execFlags db spv specialCaps namespacePolicy gasModel txCtx
case payload ^. pPayload of
Exec ExecMsg {..} ->
evalExec (RawCode (_pcCode _pmCode)) execMode
db spv gasModel execFlags namespacePolicy
db spv gasModel GasLogsDisabled execFlags namespacePolicy
(ctxToPublicData publicMeta txCtx)
MsgData
{ mdHash = _cmdHash cmd
Expand All @@ -617,7 +617,8 @@ runPayload execMode execFlags db spv specialCaps namespacePolicy gasModel txCtx
(_pcExps _pmCode)
Continuation ContMsg {..} ->
evalContinuation execMode
db spv gasModel execFlags namespacePolicy
-- TODO: Fix gas logs? Maybe pass in an
db spv gasModel GasLogsDisabled execFlags namespacePolicy
(ctxToPublicData publicMeta txCtx)
MsgData
{ mdHash = _cmdHash cmd
Expand Down Expand Up @@ -654,7 +655,7 @@ runUpgrade
runUpgrade _logger db txContext cmd = case payload ^. pPayload of
Exec pm ->
evalExec (RawCode (_pcCode (_pmCode pm))) Transactional
db noSPVSupport freeGasModel (Set.fromList [FlagDisableRuntimeRTC])
db noSPVSupport freeGasModel GasLogsDisabled (Set.fromList [FlagDisableRuntimeRTC])
-- allow installing to root namespace
SimpleNamespacePolicy
(ctxToPublicData publicMeta txContext)
Expand Down Expand Up @@ -744,6 +745,8 @@ buyGas logger db txCtx cmd = do
noSPVSupport
-- TODO: magic constant, 1500 max gas limit for buyGas?
(tableGasModel (MilliGasLimit $ gasToMilliGas $ min (Gas 3000) (gasLimit ^. _GasLimit)))
-- TODO: Gas logs
GasLogsDisabled
(Set.fromList [FlagDisableRuntimeRTC]) SimpleNamespacePolicy
(ctxToPublicData publicMeta txCtx)
MsgData
Expand All @@ -763,6 +766,8 @@ buyGas logger db txCtx cmd = do
noSPVSupport
-- TODO: magic constant, 1500 max gas limit for buyGas?
(tableGasModel (MilliGasLimit $ gasToMilliGas $ min (Gas 3000) (gasLimit ^. _GasLimit)))
-- Todo: Gas logs
GasLogsDisabled
(Set.fromList [FlagDisableRuntimeRTC]) SimpleNamespacePolicy
(ctxToPublicData publicMeta txCtx)
MsgData
Expand Down Expand Up @@ -835,7 +840,10 @@ redeemGas logger db txCtx gasUsed maybeFundTxPactId cmd
evalExecTerm
Transactional
-- TODO: more execution flags?
db noSPVSupport freeGasModel (Set.fromList [FlagDisableRuntimeRTC]) SimpleNamespacePolicy
db noSPVSupport freeGasModel
-- TODO: Gas logs
GasLogsDisabled
(Set.fromList [FlagDisableRuntimeRTC]) SimpleNamespacePolicy
(ctxToPublicData publicMeta txCtx)
MsgData
{ mdData = redeemGasData
Expand All @@ -856,7 +864,10 @@ redeemGas logger db txCtx gasUsed maybeFundTxPactId cmd
-- before chainweb 2.24, we use defpacts for gas; see: 'pact/coin-contract/coin.pact#fund-tx'
let redeemGasData = PObject $ Map.singleton "fee" (PDecimal $ _pact5GasSupply gasFee)
evalContinuation Transactional
db noSPVSupport freeGasModel (Set.fromList [FlagDisableRuntimeRTC]) SimpleNamespacePolicy
db noSPVSupport freeGasModel
-- TODO: Gas logs
GasLogsDisabled
(Set.fromList [FlagDisableRuntimeRTC]) SimpleNamespacePolicy
(ctxToPublicData publicMeta txCtx)
MsgData
{ mdData = redeemGasData
Expand Down

0 comments on commit 0111909

Please sign in to comment.