Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Simplified interface to phase-2 validation of transactions, eg. evaluation of Plutus scripts.
The evaluateTx
function simplifies the call to ledger and plutus providing
an EvaluationReport
using pre-canned ProtocolParameters
. This should only
be used for testing or benchmarking purpose as the real evaluation
parameters are set when the Hydra node starts.
NOTE: The reason this module is here instead of part of `test/` directory
is to be used in tx-cost
executable.
Synopsis
- evaluateTx :: Tx -> UTxO -> Either EvaluationError EvaluationReport
- evaluateTx' :: ExecutionUnits -> Tx -> UTxO -> Either EvaluationError EvaluationReport
- checkBudget :: ExecutionUnits -> EvaluationReport -> Either EvaluationError EvaluationReport
- data EvaluationError
- = TransactionBudgetOverspent { }
- | TransactionInvalid (TransactionValidityError Era)
- | PParamsConversion ProtocolParametersConversionError
- type EvaluationReport = Map ScriptWitnessIndex (Either ScriptExecutionError ExecutionUnits)
- renderEvaluationReportFailures :: EvaluationReport -> Text
- usedExecutionUnits :: EvaluationReport -> ExecutionUnits
- estimateMinFee :: Tx -> EvaluationReport -> Coin
- prepareTxScripts :: Tx -> UTxO -> Either String [ByteString]
- pparams :: PParams LedgerEra
- maxTxSize :: Natural
- maxTxExecutionUnits :: ExecutionUnits
- maxMem :: Natural
- maxCpu :: Natural
- epochInfo :: Monad m => EpochInfo m
- eraHistoryWithHorizonAt :: SlotNo -> EraHistory
- eraHistoryWithoutHorizon :: EraHistory
- epochSize :: EpochSize
- slotLength :: SlotLength
- systemStart :: SystemStart
- propTransactionEvaluates :: (Tx, UTxO) -> Property
- propTransactionFailsEvaluation :: (Tx, UTxO) -> Property
- genPointInTime :: Gen (SlotNo, UTCTime)
- genValidityBoundsFromContestationPeriod :: ContestationPeriod -> Gen (SlotNo, (SlotNo, UTCTime))
- genPointInTimeBefore :: UTCTime -> Gen (SlotNo, UTCTime)
- genPointInTimeAfter :: UTCTime -> Gen (SlotNo, UTCTime)
- plutusV3CostModel :: CostModel
- plutusV2CostModel :: CostModel
Evaluate transactions
evaluateTx :: Tx -> UTxO -> Either EvaluationError EvaluationReport Source #
Thin wrapper around evaluateTransactionExecutionUnits
, using fixtures
from this module for systemStart
, eraHistory
and pparams
.
Additionally, this function checks the overall execution units are not
exceeding maxTxExecutionUnits
.
:: ExecutionUnits | Max tx execution units. |
-> Tx | |
-> UTxO | |
-> Either EvaluationError EvaluationReport |
Like evaluateTx
, but with a configurable maximum transaction
ExecutionUnits
.
checkBudget :: ExecutionUnits -> EvaluationReport -> Either EvaluationError EvaluationReport Source #
Check the budget used by provided EvaluationReport
does not exceed given
maximum ExecutionUnits
.
data EvaluationError Source #
Errors returned by evaluateTx
extending the upstream
TransactionValidityError
with additional cases.
TransactionBudgetOverspent | |
TransactionInvalid (TransactionValidityError Era) | |
PParamsConversion ProtocolParametersConversionError |
Instances
Show EvaluationError Source # | |
Defined in Hydra.Ledger.Cardano.Evaluate |
type EvaluationReport = Map ScriptWitnessIndex (Either ScriptExecutionError ExecutionUnits) Source #
Evaluation result for each of the included scripts. Either they failed
evaluation or used a number of ExecutionUnits
.
usedExecutionUnits :: EvaluationReport -> ExecutionUnits Source #
Get the total used ExecutionUnits
from an EvaluationReport
. Useful to
further process the result of evaluateTx
.
estimateMinFee :: Tx -> EvaluationReport -> Coin Source #
Estimate minimum fee for given transaction and evaluated redeemers. Instead
of using the budgets from the transaction (which are usually set to 0 until
balancing), this directly computes the fee from transaction size and the
units of the EvaluationReport
. Note that this function only provides a
rough estimate using this modules' pparams
and likely under-estimates cost
as we have no witnesses on this Tx
.
Profile transactions
prepareTxScripts :: Tx -> UTxO -> Either String [ByteString] Source #
Like evaluateTx
, but instead of actual evaluation, return the
flat-encoded, fully applied scripts for each redeemer to be evaluated
externally by uplc
. Use input format "flat-namedDeBruijn". This can be used
to gather profiling information.
NOTE: This assumes we use Babbage
and only PlutusV2
scripts are used.
Fixtures
pparams :: PParams LedgerEra Source #
Current (2023-04-12) mainchain protocol parameters. XXX: Avoid specifiying not required parameters here (e.g. max block units should not matter). XXX: Load and use mainnet parameters from a file which we can easily review to be in sync with mainnet.
maxTxExecutionUnits :: ExecutionUnits Source #
Max transaction execution unit budget of the current pparams
.
epochInfo :: Monad m => EpochInfo m Source #
An artifical EpochInfo
comprised by a single never ending (forking) era,
with fixed epochSize
and slotLength
.
eraHistoryWithHorizonAt :: SlotNo -> EraHistory Source #
An era history with a single era which will end at some point.
A "real" EraHistory
received from the cardano-node will have the eraEnd
at a known or earliest possible end of the current era + a safe zone.
See EraParams
for details.
NOTE: This era is using not so realistic epoch sizes of 1 and sets a slot length of 1
eraHistoryWithoutHorizon :: EraHistory Source #
slotLength :: SlotLength Source #
systemStart :: SystemStart Source #
Properties
propTransactionEvaluates :: (Tx, UTxO) -> Property Source #
Expect a given Tx
and UTxO
to pass evaluation.
propTransactionFailsEvaluation :: (Tx, UTxO) -> Property Source #
Expect a given Tx
and UTxO
to fail phase 1 or phase 2 evaluation.
Generators
genPointInTime :: Gen (SlotNo, UTCTime) Source #
genValidityBoundsFromContestationPeriod :: ContestationPeriod -> Gen (SlotNo, (SlotNo, UTCTime)) Source #
Parameter here is the contestation period (cp) so we need to generate start (tMin) and end (tMax) tx validity bound such that their difference is not higher than the cp. Returned slots are tx validity bounds
genPointInTimeBefore :: UTCTime -> Gen (SlotNo, UTCTime) Source #
genPointInTimeAfter :: UTCTime -> Gen (SlotNo, UTCTime) Source #
Plutus cost model fixtures
plutusV3CostModel :: CostModel Source #
Current (2024-10-03) mainnet PlutusV3 cost model.
plutusV2CostModel :: CostModel Source #
Current (2023-08-04) mainnet PlutusV2 cost model.