From 946ff300b86628e5e0c3169811cd8fc717b37d14 Mon Sep 17 00:00:00 2001 From: Yura Lazarev Date: Thu, 13 Jun 2024 14:17:40 +0200 Subject: [PATCH 1/6] nix flake update --- flake.lock | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/flake.lock b/flake.lock index cc3893f458..793a8243f6 100644 --- a/flake.lock +++ b/flake.lock @@ -3,11 +3,11 @@ "CHaP": { "flake": false, "locked": { - "lastModified": 1716544578, - "narHash": "sha256-Z9J23IQjRu4gKOI+jj6Rm8Bnza3CYHXLRLhNNg7QVkU=", + "lastModified": 1718715677, + "narHash": "sha256-k0uw32xM9s50w75mtSK9ne82l56sGNYkZN9jveYTQL4=", "owner": "intersectmbo", "repo": "cardano-haskell-packages", - "rev": "19b29505e8d0a5bdd264db8911f88fcaa8a93090", + "rev": "19e2226e504861567da268327e2941768ade8463", "type": "github" }, "original": { @@ -242,11 +242,11 @@ "hackage": { "flake": false, "locked": { - "lastModified": 1716770092, - "narHash": "sha256-N4YGGedV+OfpVPQNqjBfZYfCjBjbWfZ5pdHcapVOScg=", + "lastModified": 1718757495, + "narHash": "sha256-xviuxucDjsQ2HbqzfwVyB4ZmDIyzOnf2oDbVtwBHIco=", "owner": "input-output-hk", "repo": "hackage.nix", - "rev": "179e52b7d49e43ffc2f1826a01e0c1b750db6073", + "rev": "0bb764772a383a926e3f945397a0e59ab3c64d6d", "type": "github" }, "original": { @@ -295,11 +295,11 @@ "stackage": "stackage" }, "locked": { - "lastModified": 1716771027, - "narHash": "sha256-rWtqMkpEDcF1901KEm/Y+hL+y1SidBJA/KdnAePae5c=", + "lastModified": 1718797200, + "narHash": "sha256-ueFxTuZrQ3ZT/Fj5sSeUWlqKa4+OkUU1xW0E+q/XTfw=", "owner": "input-output-hk", "repo": "haskell.nix", - "rev": "200be01f6c0390da8044fbd2998dc7b1e49121a3", + "rev": "cb139fa956158397aa398186bb32dd26f7318784", "type": "github" }, "original": { @@ -524,11 +524,11 @@ "iserv-proxy": { "flake": false, "locked": { - "lastModified": 1710581758, - "narHash": "sha256-UNUXGiKLGUv1TuQumV70rfjCJERP4w8KZEDxsMG0RHc=", + "lastModified": 1717479972, + "narHash": "sha256-7vE3RQycHI1YT9LHJ1/fUaeln2vIpYm6Mmn8FTpYeVo=", "owner": "stable-haskell", "repo": "iserv-proxy", - "rev": "50ea210590ab0519149bfd163d5ba199be925fb6", + "rev": "2ed34002247213fc435d0062350b91bab920626e", "type": "github" }, "original": { @@ -737,11 +737,11 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1684171562, - "narHash": "sha256-BMUWjVWAUdyMWKk0ATMC9H0Bv4qAV/TXwwPUvTiC5IQ=", + "lastModified": 1688392541, + "narHash": "sha256-lHrKvEkCPTUO+7tPfjIcb7Trk6k31rz18vkyqmkeJfY=", "owner": "nixos", "repo": "nixpkgs", - "rev": "55af203d468a6f5032a519cba4f41acf5a74b638", + "rev": "ea4c80b39be4c09702b0cb3b42eab59e2ba4f24b", "type": "github" }, "original": { @@ -819,11 +819,11 @@ "stackage": { "flake": false, "locked": { - "lastModified": 1716769250, - "narHash": "sha256-oTWTrrliw5GMe1qh27WWY7ToN3nfmPieZUYgSyR2uaM=", + "lastModified": 1718756571, + "narHash": "sha256-8rL8viTbuE9/yV1of6SWp2tHmhVMD2UmkOfmN5KDbKg=", "owner": "input-output-hk", "repo": "stackage.nix", - "rev": "d250d0a37d4c8ce39052eeb0174bcea64bc7be33", + "rev": "027672fb6fd45828b0e623c8152572d4058429ad", "type": "github" }, "original": { From 66c770db6ff6030f8f66c9fda22c4fc8c6bf7605 Mon Sep 17 00:00:00 2001 From: Yura Lazarev Date: Thu, 13 Jun 2024 14:18:39 +0200 Subject: [PATCH 2/6] Cabal project: proper constraints. --- cabal.project | 14 +++++------ cardano-api/cardano-api.cabal | 44 +++++++++++++++++------------------ flake.lock | 6 ++--- 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/cabal.project b/cabal.project index e4fdd2783f..b454dd7d6e 100644 --- a/cabal.project +++ b/cabal.project @@ -13,13 +13,18 @@ repository cardano-haskell-packages -- See CONTRIBUTING for information about these, including some Nix commands -- you need to run if you change them index-state: - , hackage.haskell.org 2024-05-24T12:49:48Z - , cardano-haskell-packages 2024-05-24T09:29:56Z + , hackage.haskell.org 2024-06-13T08:49:27Z + , cardano-haskell-packages 2024-06-19T09:05:06Z packages: cardano-api cardano-api-gen +extra-packages: Cabal, process + +if impl(ghc < 9.8) + constraints: interpolatedstring-perl6:setup.time source + program-options ghc-options: -Werror @@ -33,10 +38,6 @@ package cryptonite package bitvec flags: -simd -constraints: - -- io-classes-mtl-0.1.2.0 is not buildable - io-classes-mtl < 0.1.2.0 - tests: True test-show-details: direct @@ -47,4 +48,3 @@ write-ghc-environment-files: always -- IMPORTANT -- Do NOT add more source-repository-package stanzas here unless they are strictly -- temporary! Please read the section in CONTRIBUTING about updating dependencies. - diff --git a/cardano-api/cardano-api.cabal b/cardano-api/cardano-api.cabal index ad306eb899..c17670d847 100644 --- a/cardano-api/cardano-api.cabal +++ b/cardano-api/cardano-api.cabal @@ -163,17 +163,17 @@ library internal , cardano-crypto-class ^>= 2.1.2 , cardano-crypto-wrapper ^>= 1.5 , cardano-data >= 1.0 - , cardano-ledger-alonzo >= 1.8.0 - , cardano-ledger-allegra >= 1.3 - , cardano-ledger-api ^>= 1.9 - , cardano-ledger-babbage >= 1.6.0 - , cardano-ledger-binary ^>= 1.3 - , cardano-ledger-byron >= 1.0.0.4 - , cardano-ledger-conway >= 1.12.0 - , cardano-ledger-core:{cardano-ledger-core, testlib} >= 1.10 - , cardano-ledger-mary >= 1.5 - , cardano-ledger-shelley >= 1.9.0 - , cardano-protocol-tpraos >= 1.0.3.6 + , cardano-ledger-alonzo >= 1.8.1 + , cardano-ledger-allegra >= 1.5 + , cardano-ledger-api ^>= 1.9.2 + , cardano-ledger-babbage >= 1.8.1 + , cardano-ledger-binary ^>= 1.3.3 + , cardano-ledger-byron >= 1.0.1 + , cardano-ledger-conway >= 1.15 + , cardano-ledger-core:{cardano-ledger-core, testlib} >= 1.8 + , cardano-ledger-mary >= 1.6.1 + , cardano-ledger-shelley >= 1.12 + , cardano-protocol-tpraos >= 1.2 , cardano-slotting >= 0.2.0.0 , cardano-strict-containers >= 0.1 , cborg @@ -194,19 +194,19 @@ library internal , mtl , network , optparse-applicative-fork - , ouroboros-consensus ^>= 0.18 - , ouroboros-consensus-cardano ^>= 0.16 - , ouroboros-consensus-diffusion ^>= 0.16 - , ouroboros-consensus-protocol ^>= 0.9 + , ouroboros-consensus ^>= 0.19 + , ouroboros-consensus-cardano ^>= 0.17 + , ouroboros-consensus-diffusion ^>= 0.17 + , ouroboros-consensus-protocol ^>= 0.9.0.1 , ouroboros-network - , ouroboros-network-api ^>= 0.7 + , ouroboros-network-api ^>= 0.7.3 , ouroboros-network-framework , ouroboros-network-protocols , parsec - , plutus-ledger-api:{plutus-ledger-api, plutus-ledger-api-testlib} ^>= 1.27.0 + , plutus-ledger-api:{plutus-ledger-api, plutus-ledger-api-testlib} ^>= 1.30 , prettyprinter , prettyprinter-ansi-terminal - , prettyprinter-configurable ^>= 1.27.0 + , prettyprinter-configurable ^>= 1.30 , random , safe-exceptions , scientific @@ -285,9 +285,9 @@ library gen , cardano-crypto-class ^>= 2.1.2 , cardano-crypto-test ^>= 1.5 , cardano-data - , cardano-ledger-alonzo:{cardano-ledger-alonzo, testlib} >= 1.6.0 + , cardano-ledger-alonzo:{cardano-ledger-alonzo, testlib} >= 1.8.1 , cardano-ledger-byron-test >= 1.5 - , cardano-ledger-core:{cardano-ledger-core, testlib} >= 1.8.0 + , cardano-ledger-core:{cardano-ledger-core, testlib} >= 1.8 , cardano-ledger-shelley >= 1.7.0 , cardano-ledger-conway:testlib >= 1.10.0 , containers @@ -380,8 +380,8 @@ test-suite cardano-api-golden , hedgehog-extras ^>= 0.6.1.0 , microlens , parsec - , plutus-core ^>= 1.27 - , plutus-ledger-api ^>= 1.27.0 + , plutus-core ^>= 1.30 + , plutus-ledger-api ^>= 1.30 , tasty , tasty-hedgehog , time diff --git a/flake.lock b/flake.lock index 793a8243f6..0a2ab42d6a 100644 --- a/flake.lock +++ b/flake.lock @@ -3,11 +3,11 @@ "CHaP": { "flake": false, "locked": { - "lastModified": 1718715677, - "narHash": "sha256-k0uw32xM9s50w75mtSK9ne82l56sGNYkZN9jveYTQL4=", + "lastModified": 1718790880, + "narHash": "sha256-8lIMAxIBYRVs4uQXVnmWT3N5SND5zE2s1t9/chn7DX8=", "owner": "intersectmbo", "repo": "cardano-haskell-packages", - "rev": "19e2226e504861567da268327e2941768ade8463", + "rev": "5ba8c1a3835b87954354757f2aa6611174067165", "type": "github" }, "original": { From 884231e09633ad1eb3e39f438d81f4e78073e0aa Mon Sep 17 00:00:00 2001 From: Jordan Millar Date: Fri, 14 Jun 2024 18:06:07 +0200 Subject: [PATCH 3/6] Replace Cardano.Api.Fees.TransactionValidityError.TransactionValidityTranslationError with Cardano.Api.Fees.ScriptExecutionError.ScriptErrorTranslationError Concretize toShelleyMultiSig and fromShelleyMultiSig to ShelleyEra --- cardano-api/internal/Cardano/Api/Fees.hs | 28 +++++---- .../Governance/Actions/ProposalProcedure.hs | 4 +- cardano-api/internal/Cardano/Api/Script.hs | 62 ++++++++++--------- .../Test/Golden/ErrorsSpec.hs | 4 +- .../golden/LegacyProtocolParameters.json | 4 +- .../ScriptErrorTranslationError.txt | 1 + 6 files changed, 54 insertions(+), 49 deletions(-) create mode 100644 cardano-api/test/cardano-api-golden/files/golden/errors/Cardano.Api.Fees.ScriptExecutionError/ScriptErrorTranslationError.txt diff --git a/cardano-api/internal/Cardano/Api/Fees.hs b/cardano-api/internal/Cardano/Api/Fees.hs index 955c3e93dd..e02e0cbdd0 100644 --- a/cardano-api/internal/Cardano/Api/Fees.hs +++ b/cardano-api/internal/Cardano/Api/Fees.hs @@ -491,7 +491,12 @@ data ScriptExecutionError = -- | A cost model was missing for a language which was used. | ScriptErrorMissingCostModel Plutus.Language - deriving Show + + | forall era. ( Plutus.EraPlutusContext (ShelleyLedgerEra era) + , Show (Plutus.ContextError (ShelleyLedgerEra era)) + ) => ScriptErrorTranslationError (Plutus.ContextError (ShelleyLedgerEra era)) + +deriving instance Show ScriptExecutionError instance Error ScriptExecutionError where prettyError = \case @@ -548,6 +553,10 @@ instance Error ScriptExecutionError where ScriptErrorMissingCostModel language -> "No cost model was found for language " <> pshow language + ScriptErrorTranslationError e -> + "Error translating the transaction context: " <> pshow e + + data TransactionValidityError era where -- | The transaction validity interval is too far into the future. -- @@ -568,11 +577,6 @@ data TransactionValidityError era where TransactionValidityIntervalError :: Consensus.PastHorizonException -> TransactionValidityError era - TransactionValidityTranslationError - :: Plutus.EraPlutusContext (ShelleyLedgerEra era) - => Plutus.ContextError (ShelleyLedgerEra era) - -> TransactionValidityError era - TransactionValidityCostModelError :: (Map AnyPlutusScriptVersion CostModel) -> String -> TransactionValidityError era @@ -600,8 +604,6 @@ instance Error (TransactionValidityError era) where | otherwise = 0 -- This should be impossible. - TransactionValidityTranslationError errmsg -> - "Error translating the transaction context: " <> pshow errmsg TransactionValidityCostModelError cModels err -> mconcat @@ -640,10 +642,9 @@ evaluateTransactionExecutionUnitsShelley :: forall era. () evaluateTransactionExecutionUnitsShelley sbe systemstart epochInfo (LedgerProtocolParameters pp) utxo tx = caseShelleyToMaryOrAlonzoEraOnwards (const (Right Map.empty)) - (\w -> case alonzoEraOnwardsConstraints w $ L.evalTxExUnitsWithLogs pp tx (toLedgerUTxO sbe utxo) ledgerEpochInfo systemstart of - Left err -> Left $ alonzoEraOnwardsConstraints w - $ TransactionValidityTranslationError err - Right exmap -> Right (fromLedgerScriptExUnitsMap w exmap) + (\w -> pure . fromLedgerScriptExUnitsMap w + $ alonzoEraOnwardsConstraints w + $ L.evalTxExUnitsWithLogs pp tx (toLedgerUTxO sbe utxo) ledgerEpochInfo systemstart ) sbe where @@ -689,6 +690,9 @@ evaluateTransactionExecutionUnitsShelley sbe systemstart epochInfo (LedgerProtoc in ScriptErrorMissingScript scriptWitnessedItemIndex $ ResolvablePointers sbe $ Map.map extractScriptBytesAndLanguage resolveable L.NoCostModelInLedgerState l -> ScriptErrorMissingCostModel l + L.ContextError e -> + alonzoEraOnwardsConstraints aOnwards + $ ScriptErrorTranslationError e extractScriptBytesAndLanguage diff --git a/cardano-api/internal/Cardano/Api/Governance/Actions/ProposalProcedure.hs b/cardano-api/internal/Cardano/Api/Governance/Actions/ProposalProcedure.hs index 4ace67d01a..8575878245 100644 --- a/cardano-api/internal/Cardano/Api/Governance/Actions/ProposalProcedure.hs +++ b/cardano-api/internal/Cardano/Api/Governance/Actions/ProposalProcedure.hs @@ -193,13 +193,13 @@ fromProposalProcedure sbe (Proposal pp) = createPreviousGovernanceActionId :: EraCrypto (ShelleyLedgerEra era) ~ StandardCrypto => TxId - -> Word32 -- ^ Governance action transation index + -> Word16 -- ^ Governance action transation index -> Ledger.GovPurposeId (r :: Ledger.GovActionPurpose) (ShelleyLedgerEra era) createPreviousGovernanceActionId txid index = Ledger.GovPurposeId $ createGovernanceActionId txid index -createGovernanceActionId :: TxId -> Word32 -> Gov.GovActionId StandardCrypto +createGovernanceActionId :: TxId -> Word16 -> Gov.GovActionId StandardCrypto createGovernanceActionId txid index = Ledger.GovActionId { Ledger.gaidTxId = toShelleyTxId txid diff --git a/cardano-api/internal/Cardano/Api/Script.hs b/cardano-api/internal/Cardano/Api/Script.hs index f79439484e..64503b23f7 100644 --- a/cardano-api/internal/Cardano/Api/Script.hs +++ b/cardano-api/internal/Cardano/Api/Script.hs @@ -127,6 +127,7 @@ import Cardano.Api.Utils (failEitherWith) import qualified Cardano.Binary as CBOR import qualified Cardano.Crypto.Hash.Class as Crypto +import qualified Cardano.Ledger.Allegra.Scripts as Allegra import qualified Cardano.Ledger.Allegra.Scripts as Timelock import qualified Cardano.Ledger.Alonzo.Scripts as Alonzo import qualified Cardano.Ledger.Babbage.Scripts as Babbage @@ -1193,64 +1194,65 @@ data MultiSigError = MultiSigErrorTimelockNotsupported deriving Show -- | Conversion for the 'Shelley.MultiSig' language used by the Shelley era. -- -toShelleyMultiSig :: forall era. - (Era era, EraCrypto era ~ StandardCrypto) - => SimpleScript - -> Either MultiSigError (Shelley.MultiSig era) +toShelleyMultiSig + :: SimpleScript + -> Either MultiSigError (Shelley.MultiSig (ShelleyLedgerEra ShelleyEra)) toShelleyMultiSig = go where - go :: SimpleScript -> Either MultiSigError (Shelley.MultiSig era) + go :: SimpleScript -> Either MultiSigError (Shelley.MultiSig (ShelleyLedgerEra ShelleyEra)) go (RequireSignature (PaymentKeyHash kh)) = return $ Shelley.RequireSignature (Shelley.asWitness kh) - go (RequireAllOf s) = mapM go s <&> Shelley.RequireAllOf - go (RequireAnyOf s) = mapM go s <&> Shelley.RequireAnyOf - go (RequireMOf m s) = mapM go s <&> Shelley.RequireMOf m + go (RequireAllOf s) = mapM go s <&> Shelley.RequireAllOf . Seq.fromList + go (RequireAnyOf s) = mapM go s <&> Shelley.RequireAnyOf . Seq.fromList + go (RequireMOf m s) = mapM go s <&> Shelley.RequireMOf m . Seq.fromList go _ = Left MultiSigErrorTimelockNotsupported -- | Conversion for the 'Shelley.MultiSig' language used by the Shelley era. -- -fromShelleyMultiSig :: (Era era, EraCrypto era ~ StandardCrypto) - => Shelley.MultiSig era -> SimpleScript +fromShelleyMultiSig :: Shelley.MultiSig (ShelleyLedgerEra ShelleyEra) -> SimpleScript fromShelleyMultiSig = go where go (Shelley.RequireSignature kh) = RequireSignature (PaymentKeyHash (Shelley.coerceKeyRole kh)) - go (Shelley.RequireAllOf s) = RequireAllOf (map go s) - go (Shelley.RequireAnyOf s) = RequireAnyOf (map go s) - go (Shelley.RequireMOf m s) = RequireMOf m (map go s) + go (Shelley.RequireAllOf s) = RequireAllOf (map go $ toList s) + go (Shelley.RequireAnyOf s) = RequireAnyOf (map go $ toList s) + go (Shelley.RequireMOf m s) = RequireMOf m (map go $ toList s) + go _ = error "" -- | Conversion for the 'Timelock.Timelock' language that is shared between the -- Allegra and Mary eras. -- toAllegraTimelock :: forall era. - (Era era, EraCrypto era ~ StandardCrypto) - => SimpleScript -> Timelock.Timelock era + ( Allegra.AllegraEraScript era + , EraCrypto era ~ StandardCrypto + , Ledger.NativeScript era ~ Allegra.Timelock era + ) + => SimpleScript -> Ledger.NativeScript era toAllegraTimelock = go where go :: SimpleScript -> Timelock.Timelock era go (RequireSignature (PaymentKeyHash kh)) - = Timelock.RequireSignature (Shelley.asWitness kh) - go (RequireAllOf s) = Timelock.RequireAllOf (Seq.fromList (map go s)) - go (RequireAnyOf s) = Timelock.RequireAnyOf (Seq.fromList (map go s)) - go (RequireMOf m s) = Timelock.RequireMOf m (Seq.fromList (map go s)) - go (RequireTimeBefore t) = Timelock.RequireTimeExpire t - go (RequireTimeAfter t) = Timelock.RequireTimeStart t + = Shelley.RequireSignature (Shelley.asWitness kh) + go (RequireAllOf s) = Shelley.RequireAllOf (Seq.fromList (map go s)) + go (RequireAnyOf s) = Shelley.RequireAnyOf (Seq.fromList (map go s)) + go (RequireMOf m s) = Shelley.RequireMOf m (Seq.fromList (map go s)) + go (RequireTimeBefore t) = Allegra.RequireTimeExpire t + go (RequireTimeAfter t) = Allegra.RequireTimeStart t -- | Conversion for the 'Timelock.Timelock' language that is shared between the -- Allegra and Mary eras. -- -fromAllegraTimelock :: (Era era, EraCrypto era ~ StandardCrypto) - => Timelock.Timelock era -> SimpleScript +fromAllegraTimelock :: (Allegra.AllegraEraScript era, EraCrypto era ~ StandardCrypto) + => Ledger.NativeScript era -> SimpleScript fromAllegraTimelock = go where - go (Timelock.RequireSignature kh) = RequireSignature - (PaymentKeyHash (Shelley.coerceKeyRole kh)) - go (Timelock.RequireTimeExpire t) = RequireTimeBefore t - go (Timelock.RequireTimeStart t) = RequireTimeAfter t - go (Timelock.RequireAllOf s) = RequireAllOf (map go (toList s)) - go (Timelock.RequireAnyOf s) = RequireAnyOf (map go (toList s)) - go (Timelock.RequireMOf i s) = RequireMOf i (map go (toList s)) + go (Shelley.RequireSignature kh) = RequireSignature (PaymentKeyHash (Shelley.coerceKeyRole kh)) + go (Allegra.RequireTimeExpire t) = RequireTimeBefore t + go (Allegra.RequireTimeStart t) = RequireTimeAfter t + go (Shelley.RequireAllOf s) = RequireAllOf (map go (toList s)) + go (Shelley.RequireAnyOf s) = RequireAnyOf (map go (toList s)) + go (Shelley.RequireMOf i s) = RequireMOf i (map go (toList s)) -- ---------------------------------------------------------------------------- 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 9e6048a008..3379fcb6e7 100644 --- a/cardano-api/test/cardano-api-golden/Test/Golden/ErrorsSpec.hs +++ b/cardano-api/test/cardano-api-golden/Test/Golden/ErrorsSpec.hs @@ -245,6 +245,7 @@ test_ScriptExecutionError = , ("ScriptErrorRedeemerPointsToUnknownScriptHash", ScriptErrorRedeemerPointsToUnknownScriptHash (ScriptWitnessIndexTxIn 0)) , ("ScriptErrorMissingScript", ScriptErrorMissingScript (ScriptWitnessIndexMint 0) (ResolvablePointers ShelleyBasedEraBabbage Map.empty)) -- TODO CIP-1694 make work in all eras , ("ScriptErrorMissingCostModel", ScriptErrorMissingCostModel Plutus.PlutusV2) + , ("ScriptErrorTranslationError", ScriptErrorTranslationError testPastHorizonValue) ] test_StakePoolMetadataValidationError :: TestTree @@ -279,8 +280,7 @@ testPastHorizonValue = Ledger.TimeTranslationPastHorizon text test_TransactionValidityError :: TestTree test_TransactionValidityError = testAllErrorMessages_ "Cardano.Api.Fees" "TransactionValidityError" - [ ("TransactionValidityTranslationError", TransactionValidityTranslationError testPastHorizonValue) - , ("TransactionValidityCostModelError", TransactionValidityCostModelError + [ ("TransactionValidityCostModelError", TransactionValidityCostModelError (Map.fromList [(AnyPlutusScriptVersion PlutusScriptV2, costModel)]) string) -- TODO Implement this when we get access to data constructors of PastHorizon or its fields' types' constructors diff --git a/cardano-api/test/cardano-api-golden/files/golden/LegacyProtocolParameters.json b/cardano-api/test/cardano-api-golden/files/golden/LegacyProtocolParameters.json index f2dd7a00c8..58bddcfbbb 100644 --- a/cardano-api/test/cardano-api-golden/files/golden/LegacyProtocolParameters.json +++ b/cardano-api/test/cardano-api-golden/files/golden/LegacyProtocolParameters.json @@ -577,9 +577,7 @@ 228, 229, 230, - 231, - 232, - 233 + 231 ] }, "decentralization": 0.52, diff --git a/cardano-api/test/cardano-api-golden/files/golden/errors/Cardano.Api.Fees.ScriptExecutionError/ScriptErrorTranslationError.txt b/cardano-api/test/cardano-api-golden/files/golden/errors/Cardano.Api.Fees.ScriptExecutionError/ScriptErrorTranslationError.txt new file mode 100644 index 0000000000..12ba2de35b --- /dev/null +++ b/cardano-api/test/cardano-api-golden/files/golden/errors/Cardano.Api.Fees.ScriptExecutionError/ScriptErrorTranslationError.txt @@ -0,0 +1 @@ +Error translating the transaction context: TimeTranslationPastHorizon "" \ No newline at end of file From 87dc932b7812c7f7fdb3b204b449f1b374b4c0cd Mon Sep 17 00:00:00 2001 From: Jordan Millar Date: Tue, 18 Jun 2024 12:00:33 +0200 Subject: [PATCH 4/6] Update to use consensus' PoolDistr --- cardano-api/internal/Cardano/Api/Query.hs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/cardano-api/internal/Cardano/Api/Query.hs b/cardano-api/internal/Cardano/Api/Query.hs index 4fa03c05e0..abfeb48fc7 100644 --- a/cardano-api/internal/Cardano/Api/Query.hs +++ b/cardano-api/internal/Cardano/Api/Query.hs @@ -122,6 +122,7 @@ import qualified Ouroboros.Consensus.HardFork.History.Qry as Qry import qualified Ouroboros.Consensus.Ledger.Query as Consensus import qualified Ouroboros.Consensus.Protocol.Abstract as Consensus import qualified Ouroboros.Consensus.Shelley.Ledger as Consensus +import qualified Ouroboros.Consensus.Shelley.Ledger.Query.Types as Consensus import Ouroboros.Network.Block (Serialised (..)) import Ouroboros.Network.NodeToClient.Version (NodeToClientVersion (..)) import Ouroboros.Network.Protocol.LocalStateQuery.Client (Some (..)) @@ -461,7 +462,7 @@ decodePoolState (SerialisedPoolState (Serialised ls)) = PoolState <$> decodeFull (Core.eraProtVerLow @(ShelleyLedgerEra era)) ls newtype SerialisedPoolDistribution era - = SerialisedPoolDistribution (Serialised (Shelley.PoolDistr (Core.EraCrypto (ShelleyLedgerEra era)))) + = SerialisedPoolDistribution (Serialised (Consensus.PoolDistr (Core.EraCrypto (ShelleyLedgerEra era)))) newtype PoolDistribution era = PoolDistribution { unPoolDistr :: Shelley.PoolDistr (Core.EraCrypto (ShelleyLedgerEra era)) @@ -524,15 +525,15 @@ fromLedgerUTxO sbe (Shelley.UTxO utxo) = . Map.toList $ utxo -fromShelleyPoolDistr :: Shelley.PoolDistr StandardCrypto +fromShelleyPoolDistr :: Consensus.PoolDistr StandardCrypto -> Map (Hash StakePoolKey) Rational fromShelleyPoolDistr = --TODO: write an appropriate property to show it is safe to use -- Map.fromListAsc or to use Map.mapKeysMonotonic Map.fromList - . map (bimap StakePoolKeyHash Shelley.individualPoolStake) + . map (bimap StakePoolKeyHash Consensus.individualPoolStake) . Map.toList - . Shelley.unPoolDistr + . Consensus.unPoolDistr fromShelleyDelegations :: Map (Shelley.Credential Shelley.Staking StandardCrypto) (Shelley.KeyHash Shelley.StakePool StandardCrypto) From 068dbd7c514560db3346eb7d91e5b8643ab6e7c2 Mon Sep 17 00:00:00 2001 From: Jordan Millar Date: Wed, 19 Jun 2024 11:36:05 +0200 Subject: [PATCH 5/6] Modify readConwayGenesisConfig to supply a default conway genesis if the conway genesis file does not exist --- cardano-api/internal/Cardano/Api/LedgerState.hs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cardano-api/internal/Cardano/Api/LedgerState.hs b/cardano-api/internal/Cardano/Api/LedgerState.hs index 7f32e805e6..bae7f7f663 100644 --- a/cardano-api/internal/Cardano/Api/LedgerState.hs +++ b/cardano-api/internal/Cardano/Api/LedgerState.hs @@ -212,6 +212,7 @@ import qualified Data.Yaml as Yaml import Formatting.Buildable (build) import Lens.Micro import Network.TypedProtocol.Pipelined (Nat (..)) +import System.Directory (doesFileExist) import System.FilePath data InitialLedgerStateError @@ -1257,14 +1258,18 @@ readAlonzoGenesisConfig enc = do modifyError (NEAlonzoConfig (unFile file) . renderAlonzoGenesisError) $ readAlonzoGenesis file (ncAlonzoGenesisHash enc) +-- | If the conway genesis file does not exist we simply put in a default. readConwayGenesisConfig :: MonadIOTransError GenesisConfigError t m => NodeConfig -> t m (ConwayGenesis Consensus.StandardCrypto) readConwayGenesisConfig enc = do let file = ncConwayGenesisFile enc - modifyError (NEConwayConfig (unFile file) . renderConwayGenesisError) - $ readConwayGenesis file (ncConwayGenesisHash enc) + fileExists <- liftIO . doesFileExist $ unFile file + if fileExists + then modifyError (NEConwayConfig (unFile file) . renderConwayGenesisError) + $ readConwayGenesis file (ncConwayGenesisHash enc) + else return conwayGenesisDefaults readShelleyGenesis :: forall m t. MonadIOTransError ShelleyGenesisError t m From 122fb4853b9b6aa2daa2d75ca8efd037df92d68c Mon Sep 17 00:00:00 2001 From: Yuriy Lazaryev Date: Wed, 19 Jun 2024 14:07:58 +0200 Subject: [PATCH 6/6] Update NodeConfig's JSON instance to optionally parse ConwayGenesisFile and ConwayGenesisHash --- .../internal/Cardano/Api/LedgerState.hs | 55 ++++++++++++------- 1 file changed, 36 insertions(+), 19 deletions(-) diff --git a/cardano-api/internal/Cardano/Api/LedgerState.hs b/cardano-api/internal/Cardano/Api/LedgerState.hs index bae7f7f663..f44498f2b7 100644 --- a/cardano-api/internal/Cardano/Api/LedgerState.hs +++ b/cardano-api/internal/Cardano/Api/LedgerState.hs @@ -212,7 +212,6 @@ import qualified Data.Yaml as Yaml import Formatting.Buildable (build) import Lens.Micro import Network.TypedProtocol.Pipelined (Nat (..)) -import System.Directory (doesFileExist) import System.FilePath data InitialLedgerStateError @@ -888,12 +887,16 @@ readNodeConfig => NodeConfigFile 'In -> m NodeConfig readNodeConfig (File ncf) = do - ncfg <- (liftEither . parseNodeConfig) =<< readByteString ncf "node" + ncfg <- liftEither . parseNodeConfig =<< readByteString ncf "node" return ncfg - { ncByronGenesisFile = mapFile (mkAdjustPath ncf) (ncByronGenesisFile ncfg) - , ncShelleyGenesisFile = mapFile (mkAdjustPath ncf) (ncShelleyGenesisFile ncfg) - , ncAlonzoGenesisFile = mapFile (mkAdjustPath ncf) (ncAlonzoGenesisFile ncfg) - , ncConwayGenesisFile = mapFile (mkAdjustPath ncf) (ncConwayGenesisFile ncfg) + { ncByronGenesisFile = + mapFile (mkAdjustPath ncf) (ncByronGenesisFile ncfg) + , ncShelleyGenesisFile = + mapFile (mkAdjustPath ncf) (ncShelleyGenesisFile ncfg) + , ncAlonzoGenesisFile = + mapFile (mkAdjustPath ncf) (ncAlonzoGenesisFile ncfg) + , ncConwayGenesisFile = + mapFile (mkAdjustPath ncf) <$> ncConwayGenesisFile ncfg } data NodeConfig = NodeConfig @@ -904,8 +907,8 @@ data NodeConfig = NodeConfig , ncShelleyGenesisHash :: !GenesisHashShelley , ncAlonzoGenesisFile :: !(File AlonzoGenesis 'In) , ncAlonzoGenesisHash :: !GenesisHashAlonzo - , ncConwayGenesisFile :: !(File ConwayGenesisConfig 'In) - , ncConwayGenesisHash :: !GenesisHashConway + , ncConwayGenesisFile :: !(Maybe (File ConwayGenesisConfig 'In)) + , ncConwayGenesisHash :: !(Maybe GenesisHashConway) , ncRequiresNetworkMagic :: !Cardano.Crypto.RequiresNetworkMagic , ncByronProtocolVersion :: !Cardano.Chain.Update.ProtocolVersion , ncHardForkTriggers :: !Consensus.CardanoHardForkTriggers @@ -925,8 +928,8 @@ instance FromJSON NodeConfig where <*> fmap GenesisHashShelley (o .: "ShelleyGenesisHash") <*> fmap File (o .: "AlonzoGenesisFile") <*> fmap GenesisHashAlonzo (o .: "AlonzoGenesisHash") - <*> fmap File (o .: "ConwayGenesisFile") - <*> fmap GenesisHashConway (o .: "ConwayGenesisHash") + <*> (fmap . fmap) File (o .:? "ConwayGenesisFile") + <*> (fmap . fmap) GenesisHashConway (o .:? "ConwayGenesisHash") <*> o .: "RequiresNetworkMagic" <*> parseByronProtocolVersion o <*> parseHardForkTriggers o @@ -1264,12 +1267,12 @@ readConwayGenesisConfig => NodeConfig -> t m (ConwayGenesis Consensus.StandardCrypto) readConwayGenesisConfig enc = do - let file = ncConwayGenesisFile enc - fileExists <- liftIO . doesFileExist $ unFile file - if fileExists - then modifyError (NEConwayConfig (unFile file) . renderConwayGenesisError) - $ readConwayGenesis file (ncConwayGenesisHash enc) - else return conwayGenesisDefaults + let mFile = ncConwayGenesisFile enc + case mFile of + Nothing -> return conwayGenesisDefaults + Just fp -> + modifyError (NEConwayConfig (unFile fp) . renderConwayGenesisError) + $ readConwayGenesis (ncConwayGenesisFile enc) (ncConwayGenesisHash enc) readShelleyGenesis :: forall m t. MonadIOTransError ShelleyGenesisError t m @@ -1368,10 +1371,13 @@ renderAlonzoGenesisError sge = readConwayGenesis :: forall m t. MonadIOTransError ConwayGenesisError t m - => ConwayGenesisFile 'In - -> GenesisHashConway + => Maybe (ConwayGenesisFile 'In) + -> Maybe GenesisHashConway -> t m (ConwayGenesis Consensus.StandardCrypto) -readConwayGenesis (File file) expectedGenesisHash = do +readConwayGenesis Nothing Nothing = return conwayGenesisDefaults +readConwayGenesis (Just fp) Nothing = throwError $ ConwayGenesisHashMissing $ unFile fp +readConwayGenesis Nothing (Just _) = throwError ConwayGenesisFileMissing +readConwayGenesis (Just (File file)) (Just expectedGenesisHash) = do content <- modifyError id $ handleIOExceptT (ConwayGenesisReadError file . textShow) $ BS.readFile file let genesisHash = GenesisHashConway (Cardano.Crypto.Hash.Class.hashWith id content) checkExpectedGenesisHash genesisHash @@ -1385,6 +1391,8 @@ readConwayGenesis (File file) expectedGenesisHash = do data ConwayGenesisError = ConwayGenesisReadError !FilePath !Text | ConwayGenesisHashMismatch !GenesisHashConway !GenesisHashConway -- actual, expected + | ConwayGenesisHashMissing !FilePath + | ConwayGenesisFileMissing | ConwayGenesisDecodeError !FilePath !Text deriving Show @@ -1393,6 +1401,15 @@ instance Exception ConwayGenesisError renderConwayGenesisError :: ConwayGenesisError -> Text renderConwayGenesisError sge = case sge of + ConwayGenesisFileMissing -> + mconcat + [ "\"ConwayGenesisFile\" is missing from node configuration. " + ] + ConwayGenesisHashMissing fp -> + mconcat + [ "\"ConwayGenesisHash\" is missing from node configuration: " + , Text.pack fp + ] ConwayGenesisReadError fp err -> mconcat [ "There was an error reading the genesis file: ", Text.pack fp