Skip to content

Commit

Permalink
Add alonzo default genesis check
Browse files Browse the repository at this point in the history
  • Loading branch information
carbolymer authored and palas committed Jul 12, 2024
1 parent b060f04 commit 1774476
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 13 deletions.
37 changes: 24 additions & 13 deletions cardano-api/internal/Cardano/Api/Genesis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
]
6 changes: 6 additions & 0 deletions cardano-api/internal/Cardano/Api/LedgerState.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions cardano-api/test/cardano-api-test/Test/Cardano/Api/Genesis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1774476

Please sign in to comment.