hydra-node-0.10.0: The Hydra node
Safe HaskellNone



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.


Evaluate transactions

evaluateTx :: Tx -> UTxO -> Either EvaluationError EvaluationReport #

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.

evaluateTx' #


:: 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 #

Check the budget used by provided EvaluationReport does not exceed given maximum ExecutionUnits.

data EvaluationError #

Errors returned by evaluateTx extending the upstream TransactionValidityError with additional cases.


Instances details
Show EvaluationError # 
Instance details

Defined in Hydra.Ledger.Cardano.Evaluate

type EvaluationReport = Map ScriptWitnessIndex (Either ScriptExecutionError ExecutionUnits) #

Evaluation result for each of the included scripts. Either they failed evaluation or used a number of ExecutionUnits.

usedExecutionUnits :: EvaluationReport -> ExecutionUnits #

Get the total used ExecutionUnits from an EvaluationReport. Useful to further process the result of evaluateTx.

estimateMinFee :: Tx -> EvaluationReport -> Lovelace #

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] #

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.


pparams :: ProtocolParameters #

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.

maxTxSize :: Natural #

Max transaction size of the current pparams.

maxTxExecutionUnits :: ExecutionUnits #

Max transaction execution unit budget of the current pparams.

maxMem :: Natural #

Max memory and cpu units of the current pparams.

maxCpu :: Natural #

Max memory and cpu units of the current pparams.

epochInfo :: Monad m => EpochInfo m #

An artifical EpochInfo comprised by a single never ending (forking) era, with fixed epochSize and slotLength.

eraHistoryWithHorizonAt :: SlotNo -> EraHistory CardanoMode #

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

epochSize :: EpochSize #

slotLength :: SlotLength #

genValidityBoundsFromContestationPeriod :: ContestationPeriod -> Gen (SlotNo, (SlotNo, UTCTime)) #

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

slotNoFromUTCTime :: UTCTime -> SlotNo #

Using hard-coded systemStart and slotLength, do not use in production!

slotNoToUTCTime :: HasCallStack => SlotNo -> UTCTime #

Using hard-coded defaults above. Fails for slots past epoch boundaries.