diff --git a/cardano-api/internal/Cardano/Api/Genesis.hs b/cardano-api/internal/Cardano/Api/Genesis.hs index 3f6ff7e34c..6d9b9abf9c 100644 --- a/cardano-api/internal/Cardano/Api/Genesis.hs +++ b/cardano-api/internal/Cardano/Api/Genesis.hs @@ -341,8 +341,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 @@ -717,15 +722,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 07eea2b58e..aa94454621 100644 --- a/cardano-api/internal/Cardano/Api/LedgerState.hs +++ b/cardano-api/internal/Cardano/Api/LedgerState.hs @@ -1358,6 +1358,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 @@ -1442,6 +1444,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 @@ -1523,6 +1527,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 5f3d24662f..54ef3dd39e 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 @@ -62,11 +62,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