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
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
project: cardano-api
pr: 1211
kind:
- breaking
description: |
Remove unreachable error constructors. None of these were produced anywhere in the repo — only defined, pretty-printed, and listed in golden fixtures.

Removed:

- `TransactionValidityError` (entire type, both constructors `TransactionValidityIntervalError` and `TransactionValidityCostModelError`).
- `TxFeeEstimationTransactionTranslationError`, the `TxFeeEstimationError` constructor that wrapped the now-removed `TransactionValidityError`.
- `TxBodyErrorByronEraNotSupported`, `TxBodyErrorMissingParamMinUTxO`, and `TxBodyErrorNonAdaAssetsUnbalanced` from the legacy `Cardano.Api.Tx.Internal.Fee.TxBodyErrorAutoBalance`.
- `TxBodyErrorNonAdaAssetsUnbalanced` from the experimental `Cardano.Api.Experimental.Tx.Internal.Fee.TxBodyErrorAutoBalance`.

The corresponding `test_TransactionValidityError` golden test, the three dead `TxBodyErrorAutoBalance` fixture entries, and their expected `.txt` files are dropped too. The `Ouroboros.Consensus.HardFork.History` import in `Fee.hs` becomes unused and is removed.
3 changes: 0 additions & 3 deletions cardano-api/src/Cardano/Api/Experimental/Tx/Internal/Fee.hs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ data TxBodyErrorAutoBalance era
-- ^ Offending TxOut
L.Coin
-- ^ Minimum UTXO
| TxBodyErrorNonAdaAssetsUnbalanced Value
| TxBodyErrorScriptWitnessIndexMissingFromExecUnitsMap
ScriptWitnessIndex
(Map ScriptWitnessIndex ExecutionUnits)
Expand Down Expand Up @@ -180,8 +179,6 @@ instance Error (TxBodyErrorAutoBalance era) where
[ "Minimum UTxO threshold not met for tx output: " <> pretty (show txout) <> "\n"
, "Minimum required UTxO: " <> pretty minUTxO
]
TxBodyErrorNonAdaAssetsUnbalanced val ->
"Non-Ada assets are unbalanced: " <> pretty (renderValue val)
TxBodyErrorScriptWitnessIndexMissingFromExecUnitsMap sIndex eUnitsMap ->
mconcat
[ "ScriptWitnessIndex (redeemer pointer): " <> pshow sIndex <> " is missing from the execution "
Expand Down
1 change: 0 additions & 1 deletion cardano-api/src/Cardano/Api/Tx.hs
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,6 @@ module Cardano.Api.Tx
, evaluateTransactionExecutionUnits
, evaluateTransactionExecutionUnitsShelley
, ScriptExecutionError (..)
, TransactionValidityError (..)

-- ** Transaction balance
, evaluateTransactionBalance
Expand Down
73 changes: 1 addition & 72 deletions cardano-api/src/Cardano/Api/Tx/Internal/Fee.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ module Cardano.Api.Tx.Internal.Fee
, evaluateTransactionExecutionUnits
, evaluateTransactionExecutionUnitsShelley
, ScriptExecutionError (..)
, TransactionValidityError (..)

-- ** Transaction balance
, evaluateTransactionBalance
Expand Down Expand Up @@ -88,7 +87,6 @@ import Cardano.Ledger.Coin qualified as L
import Cardano.Ledger.Conway.Governance qualified as L
import Cardano.Ledger.Credential as Ledger (Credential)
import Cardano.Ledger.Plutus.Language qualified as Plutus
import Ouroboros.Consensus.HardFork.History qualified as Consensus

import Data.Bifunctor (bimap, first, second)
import Data.Bitraversable (bitraverse)
Expand Down Expand Up @@ -179,8 +177,7 @@ estimateOrCalculateBalancedTxBody era feeEstMode pparams txBodyContent poolids s
)

data TxFeeEstimationError era
= TxFeeEstimationTransactionTranslationError (TransactionValidityError era)
| TxFeeEstimationScriptExecutionError (TxBodyErrorAutoBalance era)
= TxFeeEstimationScriptExecutionError (TxBodyErrorAutoBalance era)
| TxFeeEstimationBalanceError (TxBodyErrorAutoBalance era)
| TxFeeEstimationxBodyError TxBodyError
| TxFeeEstimationFinalConstructionError TxBodyError
Expand All @@ -189,7 +186,6 @@ data TxFeeEstimationError era

instance Error (TxFeeEstimationError era) where
prettyError = \case
TxFeeEstimationTransactionTranslationError e -> prettyError e
TxFeeEstimationScriptExecutionError e -> prettyError e
TxFeeEstimationBalanceError e -> prettyError e
TxFeeEstimationxBodyError e -> prettyError e
Expand Down Expand Up @@ -638,61 +634,6 @@ instance Error ScriptExecutionError where
ScriptErrorTranslationError e ->
"Error translating the transaction context: " <> pshow e

data TransactionValidityError era where
-- | The transaction validity interval is too far into the future.
--
-- Transactions containing Plutus scripts must have a validity interval that is
-- not excessively far in the future. This ensures that the UTC
-- corresponding to the validity interval expressed in slot numbers,
-- can be reliably determined.
--
-- Plutus scripts are given the transaction validity interval in UTC to
-- prevent sensitivity to variations in slot lengths.
--
-- If either end of the validity interval exceeds the \"time horizon\", the
-- consensus algorithm cannot reliably establish the relationship between
-- slots and time.
--
-- This error occurs when thevalidity interval exceeds the time horizon.
-- For the Cardano mainnet, the time horizon is set to 36 hours beyond the
-- current time. This effectively restricts the submission and validation
-- of transactions that include Plutus scripts if the end of their validity
-- interval extends more than 36 hours into the future.
TransactionValidityIntervalError
:: Consensus.PastHorizonException -> TransactionValidityError era
TransactionValidityCostModelError
:: (Map AnyPlutusScriptVersion CostModel) -> String -> TransactionValidityError era

deriving instance Show (TransactionValidityError era)

instance Error (TransactionValidityError era) where
prettyError = \case
TransactionValidityIntervalError pastTimeHorizon ->
mconcat
[ "The transaction validity interval is too far in the future. "
, "For this network it must not be more than "
, pretty (timeHorizonSlots pastTimeHorizon)
, "slots ahead of the current time slot. "
, "(Transactions with Plutus scripts must have validity intervals that "
, "are close enough in the future that we can reliably turn the slot "
, "numbers into UTC wall clock times.)"
]
where
timeHorizonSlots :: Consensus.PastHorizonException -> Word
timeHorizonSlots Consensus.PastHorizon{Consensus.pastHorizonSummary}
| eraSummaries@(_ : _) <- pastHorizonSummary
, Consensus.StandardSafeZone slots <-
(Consensus.eraSafeZone . Consensus.eraParams . last) eraSummaries =
fromIntegral slots
| otherwise =
0 -- This should be impossible.
TransactionValidityCostModelError cModels err ->
mconcat
[ "An error occurred while converting from the cardano-api cost"
, " models to the cardano-ledger cost models. Error: " <> pretty err
, " Cost models: " <> pshow cModels
]

-- | Compute the 'ExecutionUnits' required for each script in the transaction.
--
-- This process involves executing all scripts and counting the actual execution units
Expand Down Expand Up @@ -874,18 +815,12 @@ data TxBodyErrorAutoBalance era
-- ^ Minimum UTxO
L.Coin
-- ^ Tx balance
| -- | 'makeTransactionBodyAutoBalance' does not yet support the Byron era.
TxBodyErrorByronEraNotSupported
| -- | The 'ProtocolParameters' must provide the value for the min utxo
-- parameter, for eras that use this parameter.
TxBodyErrorMissingParamMinUTxO
| -- | The minimum spendable UTxO threshold has not been met.
TxBodyErrorMinUTxONotMet
TxOutInAnyEra
-- ^ Offending TxOut
L.Coin
-- ^ Minimum UTXO
| TxBodyErrorNonAdaAssetsUnbalanced Value
| TxBodyErrorScriptWitnessIndexMissingFromExecUnitsMap
ScriptWitnessIndex
(Map ScriptWitnessIndex ExecutionUnits)
Expand Down Expand Up @@ -926,17 +861,11 @@ instance Error (TxBodyErrorAutoBalance era) where
, "The usual solution is to provide more inputs, or inputs with more ada to "
, "meet the minimum UTxO threshold"
]
TxBodyErrorByronEraNotSupported ->
"The Byron era is not yet supported by makeTransactionBodyAutoBalance"
TxBodyErrorMissingParamMinUTxO ->
"The minUTxOValue protocol parameter is required but missing"
TxBodyErrorMinUTxONotMet txout minUTxO ->
mconcat
[ "Minimum UTxO threshold not met for tx output: " <> pretty (prettyRenderTxOut txout) <> "\n"
, "Minimum required UTxO: " <> pretty minUTxO
]
TxBodyErrorNonAdaAssetsUnbalanced val ->
"Non-Ada assets are unbalanced: " <> pretty (renderValue val)
TxBodyErrorScriptWitnessIndexMissingFromExecUnitsMap sIndex eUnitsMap ->
mconcat
[ "ScriptWitnessIndex (redeemer pointer): " <> pshow sIndex <> " is missing from the execution "
Expand Down
29 changes: 0 additions & 29 deletions cardano-api/test/cardano-api-golden/Test/Golden/ErrorsSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ module Test.Golden.ErrorsSpec
, test_StakePoolMetadataValidationError
, test_TextEnvelopeCddlError
, test_TextEnvelopeError
, test_TransactionValidityError
, test_TxBodyError
, test_TxBodyErrorAutoBalance
, test_TxMetadataJsonError
Expand Down Expand Up @@ -389,28 +388,6 @@ test_TextEnvelopeError =
testPastHorizonValue :: Ledger.AlonzoContextError Ledger.AlonzoEra
testPastHorizonValue = Ledger.TimeTranslationPastHorizon text

test_TransactionValidityError :: TestTree
test_TransactionValidityError =
testAllErrorMessages_
"Cardano.Api.Tx.Internal.Fee"
"TransactionValidityError"
[
( "TransactionValidityCostModelError"
, TransactionValidityCostModelError
(fromList [(AnyPlutusScriptVersion PlutusScriptV2, costModel)])
string
)
-- TODO Implement this when we get access to data constructors of PastHorizon or its fields' types' constructors
-- or we get a dummy value for such purposes.
--
-- , ("TransactionValidityIntervalError", TransactionValidityIntervalError $
-- Qry.PastHorizon
-- { Qry.pastHorizonCallStack = GHC.callStack
-- , Qry.pastHorizonExpression = error "" -- Some $ Qry.ClosedExpr $ Qry.ELit 0
-- , Qry.pastHorizonSummary = []
-- })
]

test_TxBodyError :: TestTree
test_TxBodyError =
testAllErrorMessages_
Expand Down Expand Up @@ -439,13 +416,7 @@ test_TxBodyErrorAutoBalance =
, ("TxBodyScriptBadScriptValidity", TxBodyScriptBadScriptValidity)
, ("TxBodyErrorBalanceNegative", TxBodyErrorBalanceNegative (-1) mempty)
, ("TxBodyErrorAdaBalanceTooSmall", TxBodyErrorAdaBalanceTooSmall txOutInAnyEra1 0 1)
, ("TxBodyErrorByronEraNotSupported", TxBodyErrorByronEraNotSupported)
, ("TxBodyErrorMissingParamMinUTxO", TxBodyErrorMissingParamMinUTxO)
, ("TxBodyErrorMinUTxONotMet", TxBodyErrorMinUTxONotMet txOutInAnyEra1 1)
,
( "TxBodyErrorNonAdaAssetsUnbalanced"
, TxBodyErrorNonAdaAssetsUnbalanced (fromList [(AdaAssetId, Quantity 1)])
)
,
( "TxBodyErrorScriptWitnessIndexMissingFromExecUnitsMap"
, TxBodyErrorScriptWitnessIndexMissingFromExecUnitsMap
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading