@@ -86,6 +86,7 @@ import Pact.Core.Hash
8686import Pact.Core.Info
8787import Pact.Core.Names
8888import Pact.Core.Namespace
89+ import Pact.Core.Scheme (defPPKScheme )
8990import Pact.Core.PactValue
9091import Pact.Core.Persistence.Types hiding (GasM (.. ))
9192import Pact.Core.Persistence.Utils (ignoreGas )
@@ -103,11 +104,13 @@ import Chainweb.BlockCreationTime
103104import Chainweb.BlockHash
104105import Chainweb.BlockHeader
105106import Chainweb.BlockHeight
107+ import Chainweb.ForkState
106108import Chainweb.Logger
107109import Chainweb.Miner.Pact
108110import Chainweb.Pact.Types
109111import Chainweb.Pact5.Templates
110112import Chainweb.Pact5.Types
113+ import Chainweb.Pact5.InitialGasModel
111114
112115import Chainweb.Time
113116import Chainweb.Pact5.Transaction
@@ -977,33 +980,25 @@ redeemGas logger db txCtx gasUsed maybeFundTxPactId cmd
977980-- -- Utilities
978981
979982-- | Initial gas charged for transaction size
980- -- ignoring the size of a continuation proof, if present
981- --
982- initialGasOf :: ChainwebVersion -> V. ChainId -> BlockHeight -> PayloadWithText meta ParsedCode -> Gas
983- initialGasOf v cid bh payload = Gas gasFee
984- where
985- feePerByte :: Rational = 0.01
986-
987- contProofSize =
988- case payload ^. payloadObj . pPayload of
989- Continuation (ContMsg _ _ _ _ (Just (ContProof p))) -> B. length p
990- _ -> 0
991- txSize
992- | chainweb31 v cid bh = SB. length (payload ^. payloadBytes)
993- | otherwise = SB. length (payload ^. payloadBytes) - contProofSize
994-
995- costPerByte = fromIntegral txSize * feePerByte
996- sizePenalty = txSizeAccelerationFee costPerByte
997- gasFee = ceiling (costPerByte + sizePenalty)
998- {-# INLINE initialGasOf #-}
999-
1000- txSizeAccelerationFee :: Rational -> Rational
1001- txSizeAccelerationFee costPerByte = total
983+ initialGasOf :: ChainwebVersion -> V. ChainId -> BlockHeight -> ForkNumber -> Transaction -> Gas
984+ initialGasOf v cid bh fn tx = Gas $ ceiling $ sizeCost + sizePenaltyCost + sigsCost
1002985 where
1003- total = (costPerByte / bytePenalty) ^ power
1004- bytePenalty = 512
1005- power :: Integer = 7
1006- {-# INLINE txSizeAccelerationFee #-}
986+ model = activeInitialGasModel v cid fn bh
987+ proofSize = case tx ^. cmdPayload . payloadObj . pPayload of
988+ Continuation (ContMsg _ _ _ _ (Just (ContProof p))) -> B. length p
989+ _ -> 0
990+
991+ rawSize = SB. length (tx ^. cmdPayload . payloadBytes) - proofSize
992+ sigsSize = sum $ map (B. length . J. encodeStrict) $ tx ^. cmdSigs
993+
994+ sizeCost = model ^. feePerByte * ( model ^. rawPayloadSizeFactor * fromIntegral rawSize
995+ + model ^. proofSizeFactor * fromIntegral proofSize
996+ + model ^. signatureSizeFactor * fromIntegral sigsSize)
997+ sizePenaltyCost = (model ^. sizePenalty) sizeCost
998+
999+ sigsCost = sum $ map ((model ^. signatureCost) . fromMaybe defPPKScheme . view siScheme)
1000+ $ tx ^. cmdPayload . payloadObj . pSigners
1001+
10071002
10081003-- | Chainweb's namespace policy for ordinary transactions.
10091004-- Doesn't allow installing modules in the root namespace.
0 commit comments