From e28998824fe0e51de61beafe7ed8ca4195bbf6b0 Mon Sep 17 00:00:00 2001 From: Mateusz Galazyn Date: Wed, 10 Jul 2024 13:27:15 +0200 Subject: [PATCH] Add default alonzo default era check --- cardano-api/internal/Cardano/Api/Genesis.hs | 37 ++++++++++++------- .../internal/Cardano/Api/LedgerState.hs | 6 +++ .../Test/Cardano/Api/Genesis.hs | 9 +++++ 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/cardano-api/internal/Cardano/Api/Genesis.hs b/cardano-api/internal/Cardano/Api/Genesis.hs index b727ccef4b..3b3e2038ca 100644 --- a/cardano-api/internal/Cardano/Api/Genesis.hs +++ b/cardano-api/internal/Cardano/Api/Genesis.hs @@ -338,8 +338,13 @@ decodeAlonzoGenesis (Just era) genesisBs = modifyError ("Cannot decode era-sensi -- | Some reasonable starting defaults for constructing a 'AlonzoGenesis'. -- Based on https://github.com/IntersectMBO/cardano-node/blob/master/cardano-testnet/src/Testnet/Defaults.hs -alonzoGenesisDefaults :: AlonzoGenesis -alonzoGenesisDefaults = +-- The era determines Plutus V2 cost model parameters: +-- * Conway: 185 +-- * <= Babbage: 175 +alonzoGenesisDefaults + :: CardanoEra era + -> AlonzoGenesis +alonzoGenesisDefaults era = AlonzoGenesis { agPrices = Prices @@ -714,15 +719,21 @@ alonzoGenesisDefaults = , 38887044 , 32947 , 10 - , -- New Conway costmodel parameters below - 1292075 - , 24469 - , 74 - , 0 - , 1 - , 936157 - , 49601 - , 237 - , 0 - , 1 ] + <> defaultV2CostModelNewConwayParams + + -- New Conway cost model parameters + defaultV2CostModelNewConwayParams = + monoidForEraInEon @ConwayEraOnwards era $ + const + [ 1292075 + , 24469 + , 74 + , 0 + , 1 + , 936157 + , 49601 + , 237 + , 0 + , 1 + ] diff --git a/cardano-api/internal/Cardano/Api/LedgerState.hs b/cardano-api/internal/Cardano/Api/LedgerState.hs index 5078a224aa..a5b4260943 100644 --- a/cardano-api/internal/Cardano/Api/LedgerState.hs +++ b/cardano-api/internal/Cardano/Api/LedgerState.hs @@ -1343,6 +1343,8 @@ shelleyPraosNonce genesisHash = readCardanoGenesisConfig :: MonadIOTransError GenesisConfigError t m => Maybe (CardanoEra era) + -- ^ Provide era witness to read Alonzo Genesis in an era-sensitive manner (see + -- 'Cardano.Api.Genesis.decodeAlonzGenesis' for more details) -> NodeConfig -> t m GenesisConfig readCardanoGenesisConfig mEra enc = do @@ -1427,6 +1429,8 @@ readShelleyGenesisConfig enc = do readAlonzoGenesisConfig :: MonadIOTransError GenesisConfigError t m => Maybe (CardanoEra era) + -- ^ Provide era witness to read Alonzo Genesis in an era-sensitive manner (see + -- 'Cardano.Api.Genesis.decodeAlonzGenesis' for more details) -> NodeConfig -> t m AlonzoGenesis readAlonzoGenesisConfig mEra enc = do @@ -1508,6 +1512,8 @@ readAlonzoGenesis :: forall m t era . MonadIOTransError AlonzoGenesisError t m => Maybe (CardanoEra era) + -- ^ Provide era witness to read Alonzo Genesis in an era-sensitive manner (see + -- 'Cardano.Api.Genesis.decodeAlonzGenesis' for more details) -> File AlonzoGenesis 'In -> GenesisHashAlonzo -> t m AlonzoGenesis diff --git a/cardano-api/test/cardano-api-test/Test/Cardano/Api/Genesis.hs b/cardano-api/test/cardano-api-test/Test/Cardano/Api/Genesis.hs index 5b0103de97..cb2bf380c2 100644 --- a/cardano-api/test/cardano-api-test/Test/Cardano/Api/Genesis.hs +++ b/cardano-api/test/cardano-api-test/Test/Cardano/Api/Genesis.hs @@ -65,11 +65,20 @@ prop_reading_plutus_v2_era_sensitive_costmodel era cmf = H.propertyOnce $ do else last10CostModelValues === last10CostModelCorrectValues else length v2costModelValues === 175 + -- Make sure that our just read genesis is CBOR encoding roundtripping aeo <- H.nothingFail $ maybeEon @AlonzoEraOnwards @era let allCostModelsBs = encodeCborInEraCostModels aeo allCostModels allCostModels' <- H.leftFail $ decodeCborInEraCostModels aeo allCostModelsBs + H.note_ "Check that read genesis is CBOR encoding roundtripping" allCostModels' === allCostModels + -- Yeah, let's check the default one if it's roundtripping as well + let defaultCostModels = L.agCostModels $ alonzoGenesisDefaults era + defaultCostModelsBs = encodeCborInEraCostModels aeo defaultCostModels + defaultCostModels' <- H.leftFail $ decodeCborInEraCostModels aeo defaultCostModelsBs + H.note_ "Check that the default genesis is CBOR encoding roundtripping" + defaultCostModels' === defaultCostModels + -- | Test reading and decoding of AlonzoGenesis with cost models - an era independent test prop_reading_plutus_v2_costmodel :: PlutusV2CostModelFormat