Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Chainweb/Pact/PactService.hs
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ execLocal cwtx preflight sigVerify rdepth = pactLabel "execLocal" $ do
lift (Pact5.liftPactServiceM (Pact5.assertPreflightMetadata (view Pact5.payloadObj <$> pact5Cmd) txCtx sigVerify)) >>= \case
Left err -> earlyReturn $ review _MetadataValidationFailure err
Right () -> return ()
let initialGas = Pact5.initialGasOf $ Pact5._cmdPayload pact5Cmd
let initialGas = Pact5.initialGasOf v cid (Pact5.ctxCurrentBlockHeight txCtx) $ Pact5._cmdPayload pact5Cmd
applyCmdResult <- lift $ Pact5.pactTransaction Nothing (\dbEnv ->
Pact5.applyCmd
_psLogger _psGasLogger dbEnv
Expand Down
4 changes: 3 additions & 1 deletion src/Chainweb/Pact/PactService/Pact5/ExecBlock.hs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,9 @@ applyPactCmd env miner txIdxInBlock tx = StateT $ \(blockHandle, blockGasRemaini
let alteredTx = (view payloadObj <$> tx) & Pact5.cmdPayload . Pact5.pMeta . pmGasLimit %~ maybe id min (blockGasRemaining ^? traversed)
resultOrGasError <- liftIO $ runReaderT
(unsafeApplyPactCmd blockHandle
(initialGasOf (tx ^. Pact5.cmdPayload))
(initialGasOf (_chainwebVersion env) (Chainweb.Version._chainId env)
(env ^. psParentHeader . parentHeader . blockHeight)
(tx ^. Pact5.cmdPayload))
alteredTx)
env
case resultOrGasError of
Expand Down
8 changes: 5 additions & 3 deletions src/Chainweb/Pact5/TransactionExec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -979,16 +979,18 @@ redeemGas logger db txCtx gasUsed maybeFundTxPactId cmd
-- | Initial gas charged for transaction size
-- ignoring the size of a continuation proof, if present
--
initialGasOf :: PayloadWithText meta ParsedCode -> Gas
initialGasOf payload = Gas gasFee
initialGasOf :: ChainwebVersion -> V.ChainId -> BlockHeight -> PayloadWithText meta ParsedCode -> Gas
initialGasOf v cid bh payload = Gas gasFee
where
feePerByte :: Rational = 0.01

contProofSize =
case payload ^. payloadObj . pPayload of
Continuation (ContMsg _ _ _ _ (Just (ContProof p))) -> B.length p
_ -> 0
txSize = SB.length (payload ^. payloadBytes) - contProofSize
txSize
| chainweb31 v cid bh = SB.length (payload ^. payloadBytes)
| otherwise = SB.length (payload ^. payloadBytes) - contProofSize

costPerByte = fromIntegral txSize * feePerByte
sizePenalty = txSizeAccelerationFee costPerByte
Expand Down
1 change: 1 addition & 0 deletions test/unit/Chainweb/Test/Pact5/RemotePactTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ crosschainTest baseRdb step = runResourceT $ do
, P.fun _peName ? P.equals "X_RESUME"
, P.succeed
]
, P.fun _crGas ? P.equals (Gas 234)
]
, P.match _Just ? P.fun _crResult ? P.match _PactResultErr ? P.fun _peMsg ? P.fun _boundedText
? P.equals ("Requested defpact execution already completed for defpact id: " <> T.take 20 (renderDefPactId $ _peDefPactId cont) <> "...")
Expand Down
Loading