From 1c005b54283b0db38cf24794f77010cb3c9fc2b7 Mon Sep 17 00:00:00 2001 From: Jordan Millar Date: Fri, 15 May 2026 15:29:05 -0400 Subject: [PATCH 1/2] Remove unreachable error constructors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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, TransactionValidityCostModelError) - TxFeeEstimationTransactionTranslationError, the TxFeeEstimationError constructor that wrapped 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. --- .../Api/Experimental/Tx/Internal/Fee.hs | 3 - cardano-api/src/Cardano/Api/Tx.hs | 1 - .../src/Cardano/Api/Tx/Internal/Fee.hs | 73 +------------------ .../Test/Golden/ErrorsSpec.hs | 29 -------- .../TransactionValidityCostModelError.txt | 1 - .../TxBodyErrorByronEraNotSupported.txt | 1 - .../TxBodyErrorMissingParamMinUTxO.txt | 1 - .../TxBodyErrorNonAdaAssetsUnbalanced.txt | 1 - 8 files changed, 1 insertion(+), 109 deletions(-) delete mode 100644 cardano-api/test/cardano-api-golden/files/errors/Cardano.Api.Tx.Internal.Fee.TransactionValidityError/TransactionValidityCostModelError.txt delete mode 100644 cardano-api/test/cardano-api-golden/files/errors/Cardano.Api.Tx.Internal.Fee.TxBodyErrorAutoBalance/TxBodyErrorByronEraNotSupported.txt delete mode 100644 cardano-api/test/cardano-api-golden/files/errors/Cardano.Api.Tx.Internal.Fee.TxBodyErrorAutoBalance/TxBodyErrorMissingParamMinUTxO.txt delete mode 100644 cardano-api/test/cardano-api-golden/files/errors/Cardano.Api.Tx.Internal.Fee.TxBodyErrorAutoBalance/TxBodyErrorNonAdaAssetsUnbalanced.txt diff --git a/cardano-api/src/Cardano/Api/Experimental/Tx/Internal/Fee.hs b/cardano-api/src/Cardano/Api/Experimental/Tx/Internal/Fee.hs index 1ce6a27568..be84b5cbec 100644 --- a/cardano-api/src/Cardano/Api/Experimental/Tx/Internal/Fee.hs +++ b/cardano-api/src/Cardano/Api/Experimental/Tx/Internal/Fee.hs @@ -118,7 +118,6 @@ data TxBodyErrorAutoBalance era -- ^ Offending TxOut L.Coin -- ^ Minimum UTXO - | TxBodyErrorNonAdaAssetsUnbalanced Value | TxBodyErrorScriptWitnessIndexMissingFromExecUnitsMap ScriptWitnessIndex (Map ScriptWitnessIndex ExecutionUnits) @@ -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 " diff --git a/cardano-api/src/Cardano/Api/Tx.hs b/cardano-api/src/Cardano/Api/Tx.hs index 19c99d2feb..e8a8ed7231 100644 --- a/cardano-api/src/Cardano/Api/Tx.hs +++ b/cardano-api/src/Cardano/Api/Tx.hs @@ -731,7 +731,6 @@ module Cardano.Api.Tx , evaluateTransactionExecutionUnits , evaluateTransactionExecutionUnitsShelley , ScriptExecutionError (..) - , TransactionValidityError (..) -- ** Transaction balance , evaluateTransactionBalance diff --git a/cardano-api/src/Cardano/Api/Tx/Internal/Fee.hs b/cardano-api/src/Cardano/Api/Tx/Internal/Fee.hs index 1788d1d332..0978eb5d17 100644 --- a/cardano-api/src/Cardano/Api/Tx/Internal/Fee.hs +++ b/cardano-api/src/Cardano/Api/Tx/Internal/Fee.hs @@ -25,7 +25,6 @@ module Cardano.Api.Tx.Internal.Fee , evaluateTransactionExecutionUnits , evaluateTransactionExecutionUnitsShelley , ScriptExecutionError (..) - , TransactionValidityError (..) -- ** Transaction balance , evaluateTransactionBalance @@ -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) @@ -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 @@ -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 @@ -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 @@ -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) @@ -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 " diff --git a/cardano-api/test/cardano-api-golden/Test/Golden/ErrorsSpec.hs b/cardano-api/test/cardano-api-golden/Test/Golden/ErrorsSpec.hs index 876616ac29..9156687b94 100644 --- a/cardano-api/test/cardano-api-golden/Test/Golden/ErrorsSpec.hs +++ b/cardano-api/test/cardano-api-golden/Test/Golden/ErrorsSpec.hs @@ -22,7 +22,6 @@ module Test.Golden.ErrorsSpec , test_StakePoolMetadataValidationError , test_TextEnvelopeCddlError , test_TextEnvelopeError - , test_TransactionValidityError , test_TxBodyError , test_TxBodyErrorAutoBalance , test_TxMetadataJsonError @@ -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_ @@ -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 diff --git a/cardano-api/test/cardano-api-golden/files/errors/Cardano.Api.Tx.Internal.Fee.TransactionValidityError/TransactionValidityCostModelError.txt b/cardano-api/test/cardano-api-golden/files/errors/Cardano.Api.Tx.Internal.Fee.TransactionValidityError/TransactionValidityCostModelError.txt deleted file mode 100644 index d8f0490c12..0000000000 --- a/cardano-api/test/cardano-api-golden/files/errors/Cardano.Api.Tx.Internal.Fee.TransactionValidityError/TransactionValidityCostModelError.txt +++ /dev/null @@ -1 +0,0 @@ -An error occurred while converting from the cardano-api cost models to the cardano-ledger cost models. Error: Cost models: fromList [(AnyPlutusScriptVersion PlutusScriptV2,CostModel [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42])] \ No newline at end of file diff --git a/cardano-api/test/cardano-api-golden/files/errors/Cardano.Api.Tx.Internal.Fee.TxBodyErrorAutoBalance/TxBodyErrorByronEraNotSupported.txt b/cardano-api/test/cardano-api-golden/files/errors/Cardano.Api.Tx.Internal.Fee.TxBodyErrorAutoBalance/TxBodyErrorByronEraNotSupported.txt deleted file mode 100644 index bac6844d6d..0000000000 --- a/cardano-api/test/cardano-api-golden/files/errors/Cardano.Api.Tx.Internal.Fee.TxBodyErrorAutoBalance/TxBodyErrorByronEraNotSupported.txt +++ /dev/null @@ -1 +0,0 @@ -The Byron era is not yet supported by makeTransactionBodyAutoBalance \ No newline at end of file diff --git a/cardano-api/test/cardano-api-golden/files/errors/Cardano.Api.Tx.Internal.Fee.TxBodyErrorAutoBalance/TxBodyErrorMissingParamMinUTxO.txt b/cardano-api/test/cardano-api-golden/files/errors/Cardano.Api.Tx.Internal.Fee.TxBodyErrorAutoBalance/TxBodyErrorMissingParamMinUTxO.txt deleted file mode 100644 index 68e11b65fc..0000000000 --- a/cardano-api/test/cardano-api-golden/files/errors/Cardano.Api.Tx.Internal.Fee.TxBodyErrorAutoBalance/TxBodyErrorMissingParamMinUTxO.txt +++ /dev/null @@ -1 +0,0 @@ -The minUTxOValue protocol parameter is required but missing \ No newline at end of file diff --git a/cardano-api/test/cardano-api-golden/files/errors/Cardano.Api.Tx.Internal.Fee.TxBodyErrorAutoBalance/TxBodyErrorNonAdaAssetsUnbalanced.txt b/cardano-api/test/cardano-api-golden/files/errors/Cardano.Api.Tx.Internal.Fee.TxBodyErrorAutoBalance/TxBodyErrorNonAdaAssetsUnbalanced.txt deleted file mode 100644 index c2ca7320df..0000000000 --- a/cardano-api/test/cardano-api-golden/files/errors/Cardano.Api.Tx.Internal.Fee.TxBodyErrorAutoBalance/TxBodyErrorNonAdaAssetsUnbalanced.txt +++ /dev/null @@ -1 +0,0 @@ -Non-Ada assets are unbalanced: 1 lovelace \ No newline at end of file From b6497f2465c2ed29ac57a8050aae7bb6ac4ba8be Mon Sep 17 00:00:00 2001 From: Jordan Millar Date: Fri, 15 May 2026 15:30:18 -0400 Subject: [PATCH 2/2] Add changelog fragment for PR #1211 --- ..._api_remove_unreachable_error_constructors.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .changes/20260515_cardano_api_remove_unreachable_error_constructors.yml diff --git a/.changes/20260515_cardano_api_remove_unreachable_error_constructors.yml b/.changes/20260515_cardano_api_remove_unreachable_error_constructors.yml new file mode 100644 index 0000000000..67b8396f41 --- /dev/null +++ b/.changes/20260515_cardano_api_remove_unreachable_error_constructors.yml @@ -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.