From d1eb9eafebfb1233e0231782c44f814b652c6558 Mon Sep 17 00:00:00 2001 From: John Ky Date: Wed, 6 Jul 2022 23:06:30 +1000 Subject: [PATCH] Rename utxoCostPerWord to utxoCostPerByte and adjust the value appropriately. See https://github.com/input-output-hk/cardano-node/issues/4052 See https://github.com/cardano-foundation/CIPs/pull/265 --- cardano-api/gen/Gen/Cardano/Api/Typed.hs | 2 +- cardano-api/src/Cardano/Api/Fees.hs | 12 +-- .../src/Cardano/Api/ProtocolParameters.hs | 85 ++++++++++--------- cardano-api/src/Cardano/Api/Value.hs | 3 +- cardano-cli/cardano-cli.cabal | 1 + cardano-cli/src/Cardano/CLI/Run/Friendly.hs | 4 +- .../src/Cardano/CLI/Shelley/Parsers.hs | 10 +-- 7 files changed, 63 insertions(+), 54 deletions(-) diff --git a/cardano-api/gen/Gen/Cardano/Api/Typed.hs b/cardano-api/gen/Gen/Cardano/Api/Typed.hs index 4e529274518..49a0dd9cf16 100644 --- a/cardano-api/gen/Gen/Cardano/Api/Typed.hs +++ b/cardano-api/gen/Gen/Cardano/Api/Typed.hs @@ -785,7 +785,7 @@ genProtocolParametersUpdate = do protocolUpdatePoolPledgeInfluence <- Gen.maybe genRationalInt64 protocolUpdateMonetaryExpansion <- Gen.maybe genRational protocolUpdateTreasuryCut <- Gen.maybe genRational - protocolUpdateUTxOCostPerWord <- Gen.maybe genLovelace + protocolUpdateUTxOCostPerByte <- Gen.maybe genLovelace let protocolUpdateCostModels = mempty -- genCostModels --TODO: Babbage figure out how to deal with -- asymmetric cost model JSON instances diff --git a/cardano-api/src/Cardano/Api/Fees.hs b/cardano-api/src/Cardano/Api/Fees.hs index a1c1c659430..6b9d4492a77 100644 --- a/cardano-api/src/Cardano/Api/Fees.hs +++ b/cardano-api/src/Cardano/Api/Fees.hs @@ -795,7 +795,7 @@ data TxBodyErrorAutoBalance = -- | The 'ProtocolParameters' must provide the value for the cost per -- word parameter, for eras that use this parameter. - | TxBodyErrorMissingParamCostPerWord + | TxBodyErrorMissingParamCostPerByte -- | The transaction validity interval is too far into the future. -- See 'TransactionValidityIntervalError' for details. @@ -856,8 +856,8 @@ instance Error TxBodyErrorAutoBalance where displayError TxBodyErrorMissingParamMinUTxO = "The minUTxOValue protocol parameter is required but missing" - displayError TxBodyErrorMissingParamCostPerWord = - "The utxoCostPerWord protocol parameter is required but missing" + displayError TxBodyErrorMissingParamCostPerByte = + "The utxoCostPerByte protocol parameter is required but missing" displayError (TxBodyErrorValidityInterval err) = displayError err @@ -1259,13 +1259,13 @@ calculateMinimumUTxO era txout@(TxOut _ v _ _) pparams' = data MinimumUTxOError = PParamsMinUTxOMissing - | PParamsUTxOCostPerWordMissing + | PParamsUTxOCostPerByteMissing deriving Show instance Error MinimumUTxOError where displayError PParamsMinUTxOMissing = "\"minUtxoValue\" field not present in protocol parameters when \ \trying to calculate minimum UTxO value." - displayError PParamsUTxOCostPerWordMissing = - "\"utxoCostPerWord\" field not present in protocol parameters when \ + displayError PParamsUTxOCostPerByteMissing = + "\"utxoCostPerByte\" field not present in protocol parameters when \ \trying to calculate minimum UTxO value." diff --git a/cardano-api/src/Cardano/Api/ProtocolParameters.hs b/cardano-api/src/Cardano/Api/ProtocolParameters.hs index b03f158efd6..7ec817413f0 100644 --- a/cardano-api/src/Cardano/Api/ProtocolParameters.hs +++ b/cardano-api/src/Cardano/Api/ProtocolParameters.hs @@ -247,10 +247,10 @@ data ProtocolParameters = -- protocolParamTreasuryCut :: Rational, - -- | Cost in ada per word of UTxO storage. + -- | Cost in ada per byte of UTxO storage. -- - -- /Introduced in Alonzo/ - protocolParamUTxOCostPerWord :: Maybe Lovelace, + -- /Introduced in Babbage/ + protocolParamUTxOCostPerByte :: Maybe Lovelace, -- | Cost models for script languages that use them. -- @@ -312,7 +312,7 @@ instance FromJSON ProtocolParameters where <*> o .: "poolPledgeInfluence" <*> o .: "monetaryExpansion" <*> o .: "treasuryCut" - <*> o .:? "utxoCostPerWord" + <*> o .:? "utxoCostPerBytes" <*> o .:? "costModels" .!= Map.empty <*> o .:? "executionUnitPrices" <*> o .:? "maxTxExecutionUnits" @@ -343,7 +343,6 @@ instance ToJSON ProtocolParameters where , "txFeeFixed" .= protocolParamTxFeeFixed , "txFeePerByte" .= protocolParamTxFeePerByte -- Alonzo era: - , "utxoCostPerWord" .= protocolParamUTxOCostPerWord , "costModels" .= protocolParamCostModels , "executionUnitPrices" .= protocolParamPrices , "maxTxExecutionUnits" .= protocolParamMaxTxExUnits @@ -351,6 +350,8 @@ instance ToJSON ProtocolParameters where , "maxValueSize" .= protocolParamMaxValueSize , "collateralPercentage" .= protocolParamCollateralPercent , "maxCollateralInputs" .= protocolParamMaxCollateralInputs + -- Babbage era: + , "utxoCostPerByte" .= protocolParamUTxOCostPerByte ] @@ -473,12 +474,14 @@ data ProtocolParametersUpdate = -- protocolUpdateTreasuryCut :: Maybe Rational, - -- Introduced in Alonzo + -- Introduced in Babbage, - -- | Cost in ada per word of UTxO storage. + -- | Cost in ada per byte of UTxO storage. -- - -- /Introduced in Alonzo/ - protocolUpdateUTxOCostPerWord :: Maybe Lovelace, + -- /Introduced in Babbage/ + protocolUpdateUTxOCostPerByte :: Maybe Lovelace, + + -- Introduced in Alonzo, -- | Cost models for script languages that use them. -- @@ -538,8 +541,9 @@ instance Semigroup ProtocolParametersUpdate where , protocolUpdatePoolPledgeInfluence = merge protocolUpdatePoolPledgeInfluence , protocolUpdateMonetaryExpansion = merge protocolUpdateMonetaryExpansion , protocolUpdateTreasuryCut = merge protocolUpdateTreasuryCut + -- Introduced in Babbage below. + , protocolUpdateUTxOCostPerByte = merge protocolUpdateUTxOCostPerByte -- Introduced in Alonzo below. - , protocolUpdateUTxOCostPerWord = merge protocolUpdateUTxOCostPerWord , protocolUpdateCostModels = mergeMap protocolUpdateCostModels , protocolUpdatePrices = merge protocolUpdatePrices , protocolUpdateMaxTxExUnits = merge protocolUpdateMaxTxExUnits @@ -577,7 +581,7 @@ instance Monoid ProtocolParametersUpdate where , protocolUpdatePoolPledgeInfluence = Nothing , protocolUpdateMonetaryExpansion = Nothing , protocolUpdateTreasuryCut = Nothing - , protocolUpdateUTxOCostPerWord = Nothing + , protocolUpdateUTxOCostPerByte = Nothing , protocolUpdateCostModels = mempty , protocolUpdatePrices = Nothing , protocolUpdateMaxTxExUnits = Nothing @@ -607,7 +611,7 @@ instance ToCBOR ProtocolParametersUpdate where <> toCBOR protocolUpdatePoolPledgeInfluence <> toCBOR protocolUpdateMonetaryExpansion <> toCBOR protocolUpdateTreasuryCut - <> toCBOR protocolUpdateUTxOCostPerWord + <> toCBOR protocolUpdateUTxOCostPerByte <> toCBOR protocolUpdateCostModels <> toCBOR protocolUpdatePrices <> toCBOR protocolUpdateMaxTxExUnits @@ -962,7 +966,7 @@ toAlonzoPParamsUpdate , protocolUpdatePoolPledgeInfluence , protocolUpdateMonetaryExpansion , protocolUpdateTreasuryCut - , protocolUpdateUTxOCostPerWord + , protocolUpdateUTxOCostPerByte -- New in babbage , protocolUpdateCostModels , protocolUpdatePrices , protocolUpdateMaxTxExUnits @@ -997,8 +1001,8 @@ toAlonzoPParamsUpdate noInlineMaybeToStrictMaybe protocolUpdateProtocolVersion , Alonzo._minPoolCost = toShelleyLovelace <$> noInlineMaybeToStrictMaybe protocolUpdateMinPoolCost - , Alonzo._coinsPerUTxOWord = toShelleyLovelace <$> - noInlineMaybeToStrictMaybe protocolUpdateUTxOCostPerWord + , Alonzo._coinsPerUTxOWord = toShelleyLovelace . (* 8) <$> + noInlineMaybeToStrictMaybe protocolUpdateUTxOCostPerByte , Alonzo._costmdls = if Map.null protocolUpdateCostModels then Ledger.SNothing else either (const Ledger.SNothing) Ledger.SJust @@ -1033,7 +1037,7 @@ toBabbagePParamsUpdate , protocolUpdatePoolPledgeInfluence , protocolUpdateMonetaryExpansion , protocolUpdateTreasuryCut - , protocolUpdateUTxOCostPerWord + , protocolUpdateUTxOCostPerByte -- Babbage , protocolUpdateCostModels , protocolUpdatePrices , protocolUpdateMaxTxExUnits @@ -1064,8 +1068,8 @@ toBabbagePParamsUpdate noInlineMaybeToStrictMaybe protocolUpdateProtocolVersion , Babbage._minPoolCost = toShelleyLovelace <$> noInlineMaybeToStrictMaybe protocolUpdateMinPoolCost - , Babbage._coinsPerUTxOByte = coinsPerUTxOWordToCoinsPerUTxOByte . toShelleyLovelace <$> - noInlineMaybeToStrictMaybe protocolUpdateUTxOCostPerWord + , Babbage._coinsPerUTxOByte = toShelleyLovelace <$> + noInlineMaybeToStrictMaybe protocolUpdateUTxOCostPerByte , Babbage._costmdls = if Map.null protocolUpdateCostModels then Ledger.SNothing else either (const Ledger.SNothing) Ledger.SJust @@ -1167,7 +1171,7 @@ fromShelleyPParamsUpdate strictMaybeToMaybe _rho , protocolUpdateTreasuryCut = Ledger.unboundRational <$> strictMaybeToMaybe _tau - , protocolUpdateUTxOCostPerWord = Nothing + , protocolUpdateUTxOCostPerByte = Nothing -- Babbage , protocolUpdateCostModels = mempty , protocolUpdatePrices = Nothing , protocolUpdateMaxTxExUnits = Nothing @@ -1233,7 +1237,7 @@ fromAlonzoPParamsUpdate strictMaybeToMaybe _rho , protocolUpdateTreasuryCut = Ledger.unboundRational <$> strictMaybeToMaybe _tau - , protocolUpdateUTxOCostPerWord = fromShelleyLovelace <$> + , protocolUpdateUTxOCostPerByte = fromShelleyLovelace . coinsPerUTxOWordToCoinsPerUTxOByte <$> strictMaybeToMaybe _coinsPerUTxOWord , protocolUpdateCostModels = maybe mempty fromAlonzoCostModels (strictMaybeToMaybe _costmdls) @@ -1301,7 +1305,7 @@ fromBabbagePParamsUpdate strictMaybeToMaybe _rho , protocolUpdateTreasuryCut = Ledger.unboundRational <$> strictMaybeToMaybe _tau - , protocolUpdateUTxOCostPerWord = (*8) . fromShelleyLovelace <$> + , protocolUpdateUTxOCostPerByte = fromShelleyLovelace <$> strictMaybeToMaybe _coinsPerUTxOByte , protocolUpdateCostModels = maybe mempty fromAlonzoCostModels (strictMaybeToMaybe _costmdls) @@ -1413,7 +1417,7 @@ toAlonzoPParams ProtocolParameters { protocolParamPoolPledgeInfluence, protocolParamMonetaryExpansion, protocolParamTreasuryCut, - protocolParamUTxOCostPerWord = Just utxoCostPerWord, + protocolParamUTxOCostPerByte = Just utxoCostPerByte, protocolParamCostModels, protocolParamPrices = Just prices, protocolParamMaxTxExUnits = Just maxTxExUnits, @@ -1460,7 +1464,8 @@ toAlonzoPParams ProtocolParameters { (Ledger.boundRational protocolParamTreasuryCut) -- New params in Alonzo: - , Alonzo._coinsPerUTxOWord = toShelleyLovelace utxoCostPerWord + , Alonzo._coinsPerUTxOWord = -- adapted from babbage protocol parameter field + toShelleyLovelace (utxoCostPerByte * 8) , Alonzo._costmdls = either (\e -> error $ "toAlonzoPParams: invalid cost models, error: " <> e) id @@ -1474,8 +1479,8 @@ toAlonzoPParams ProtocolParameters { , Alonzo._collateralPercentage = collateralPercentage , Alonzo._maxCollateralInputs = maxCollateralInputs } -toAlonzoPParams ProtocolParameters { protocolParamUTxOCostPerWord = Nothing } = - error "toAlonzoPParams: must specify protocolParamUTxOCostPerWord" +toAlonzoPParams ProtocolParameters { protocolParamUTxOCostPerByte = Nothing } = + error "toAlonzoPParams: must specify protocolParamUTxOCostPerBytes" toAlonzoPParams ProtocolParameters { protocolParamPrices = Nothing } = error "toAlonzoPParams: must specify protocolParamPrices" toAlonzoPParams ProtocolParameters { protocolParamMaxTxExUnits = Nothing } = @@ -1506,7 +1511,7 @@ toBabbagePParams ProtocolParameters { protocolParamPoolPledgeInfluence, protocolParamMonetaryExpansion, protocolParamTreasuryCut, - protocolParamUTxOCostPerWord = Just utxoCostPerWord, + protocolParamUTxOCostPerByte = Just utxoCostPerByte, protocolParamCostModels, protocolParamPrices = Just prices, protocolParamMaxTxExUnits = Just maxTxExUnits, @@ -1540,8 +1545,7 @@ toBabbagePParams ProtocolParameters { (Ledger.boundRational protocolParamTreasuryCut) -- New params in Babbage. - , Babbage._coinsPerUTxOByte = coinsPerUTxOWordToCoinsPerUTxOByte - (toShelleyLovelace utxoCostPerWord) + , Babbage._coinsPerUTxOByte = toShelleyLovelace utxoCostPerByte , Babbage._costmdls = either (\e -> error $ "toAlonzoPParams: invalid cost models, error: " <> e) @@ -1556,8 +1560,8 @@ toBabbagePParams ProtocolParameters { , Babbage._collateralPercentage = collateralPercentage , Babbage._maxCollateralInputs = maxCollateralInputs } -toBabbagePParams ProtocolParameters { protocolParamUTxOCostPerWord = Nothing } = - error "toBabbagePParams: must specify protocolParamUTxOCostPerWord" +toBabbagePParams ProtocolParameters { protocolParamUTxOCostPerByte = Nothing } = + error "toBabbagePParams: must specify protocolParamUTxOCostPerByte" toBabbagePParams ProtocolParameters { protocolParamPrices = Nothing } = error "toBabbagePParams: must specify protocolParamPrices" toBabbagePParams ProtocolParameters { protocolParamMaxTxExUnits = Nothing } = @@ -1627,7 +1631,7 @@ fromShelleyPParams , protocolParamPoolPledgeInfluence = Ledger.unboundRational _a0 , protocolParamMonetaryExpansion = Ledger.unboundRational _rho , protocolParamTreasuryCut = Ledger.unboundRational _tau - , protocolParamUTxOCostPerWord = Nothing + , protocolParamUTxOCostPerByte = Nothing , protocolParamCostModels = Map.empty , protocolParamPrices = Nothing , protocolParamMaxTxExUnits = Nothing @@ -1685,7 +1689,8 @@ fromAlonzoPParams , protocolParamPoolPledgeInfluence = Ledger.unboundRational _a0 , protocolParamMonetaryExpansion = Ledger.unboundRational _rho , protocolParamTreasuryCut = Ledger.unboundRational _tau - , protocolParamUTxOCostPerWord = Just (fromShelleyLovelace _coinsPerUTxOWord) + , protocolParamUTxOCostPerByte = -- adapted from alonzo protocol parameter field + Just (fromShelleyLovelace (coinsPerUTxOWordToCoinsPerUTxOByte _coinsPerUTxOWord)) , protocolParamCostModels = fromAlonzoCostModels _costmdls , protocolParamPrices = Just (fromAlonzoPrices _prices) , protocolParamMaxTxExUnits = Just (fromAlonzoExUnits _maxTxExUnits) @@ -1740,7 +1745,7 @@ fromBabbagePParams , protocolParamPoolPledgeInfluence = Ledger.unboundRational _a0 , protocolParamMonetaryExpansion = Ledger.unboundRational _rho , protocolParamTreasuryCut = Ledger.unboundRational _tau - , protocolParamUTxOCostPerWord = Just (8 * fromShelleyLovelace _coinsPerUTxOByte) + , protocolParamUTxOCostPerByte = Just (fromShelleyLovelace _coinsPerUTxOByte) , protocolParamCostModels = fromAlonzoCostModels _costmdls , protocolParamPrices = Just (fromAlonzoPrices _prices) , protocolParamMaxTxExUnits = Just (fromAlonzoExUnits _maxTxExUnits) @@ -1762,7 +1767,7 @@ instance Error ProtocolParametersError where \ parameters value?" displayError PParamsErrorMissingAlonzoProtocolParameter = "The Alonzo era protocol parameters in use is missing one or more of the \ - \following fields: UTxOCostPerWord, CostModels, Prices, MaxTxExUnits, \ + \following fields: UTxOCostPerByte, CostModels, Prices, MaxTxExUnits, \ \MaxBlockExUnits, MaxValueSize, CollateralPercent, MaxCollateralInputs. Did \ \you intend to use an Alonzo era protocol parameters value?" @@ -1782,7 +1787,7 @@ checkProtocolParameters sbe ProtocolParameters{..} = era :: CardanoEra era era = shelleyBasedToCardanoEra sbe - costPerWord = isJust protocolParamUTxOCostPerWord + costPerByte = isJust protocolParamUTxOCostPerByte cModel = not $ Map.null protocolParamCostModels prices = isJust protocolParamPrices maxTxUnits = isJust protocolParamMaxTxExUnits @@ -1793,8 +1798,7 @@ checkProtocolParameters sbe ProtocolParameters{..} = alonzoRequiredPParamFields :: [Bool] alonzoRequiredPParamFields = - [ costPerWord - , cModel + [ cModel , prices , maxTxUnits , maxBlockExUnits @@ -1803,6 +1807,11 @@ checkProtocolParameters sbe ProtocolParameters{..} = , maxCollateralInputs ] + babbageRequiredPParamFields :: [Bool] + babbageRequiredPParamFields = + [ costPerByte + ] + checkAlonzoParams :: Either ProtocolParametersError () checkAlonzoParams = do if all (== True) alonzoRequiredPParamFields @@ -1816,7 +1825,7 @@ checkProtocolParameters sbe ProtocolParameters{..} = checkBabbageParams :: Either ProtocolParametersError () checkBabbageParams = - if all (== True) $ alonzoRequiredPParamFields ++ babbageDeprecatedFields + if all (== True) $ alonzoRequiredPParamFields ++ babbageRequiredPParamFields ++ babbageDeprecatedFields then return () else Left PParamsErrorMissingAlonzoProtocolParameter diff --git a/cardano-api/src/Cardano/Api/Value.hs b/cardano-api/src/Cardano/Api/Value.hs index 7cbf41385d6..ad69cab44b2 100644 --- a/cardano-api/src/Cardano/Api/Value.hs +++ b/cardano-api/src/Cardano/Api/Value.hs @@ -88,14 +88,13 @@ import Cardano.Api.SerialiseRaw import Cardano.Api.SerialiseUsing import Cardano.Api.Utils (failEitherWith) - -- ---------------------------------------------------------------------------- -- Lovelace -- newtype Lovelace = Lovelace Integer deriving stock (Eq, Ord, Show) - deriving newtype (Enum, Num, ToJSON, FromJSON, ToCBOR, FromCBOR) + deriving newtype (Enum, Real, Integral, Num, ToJSON, FromJSON, ToCBOR, FromCBOR) instance Semigroup Lovelace where Lovelace a <> Lovelace b = Lovelace (a + b) diff --git a/cardano-cli/cardano-cli.cabal b/cardano-cli/cardano-cli.cabal index b16fa3cf477..b59525e51be 100644 --- a/cardano-cli/cardano-cli.cabal +++ b/cardano-cli/cardano-cli.cabal @@ -110,6 +110,7 @@ library , cardano-crypto-wrapper , cardano-data , cardano-ledger-alonzo + -- , cardano-ledger-babbage , cardano-ledger-byron , cardano-ledger-core , cardano-ledger-shelley-ma diff --git a/cardano-cli/src/Cardano/CLI/Run/Friendly.hs b/cardano-cli/src/Cardano/CLI/Run/Friendly.hs index 248115dbf85..63de46ddf75 100644 --- a/cardano-cli/src/Cardano/CLI/Run/Friendly.hs +++ b/cardano-cli/src/Cardano/CLI/Run/Friendly.hs @@ -228,7 +228,7 @@ friendlyProtocolParametersUpdate , protocolUpdatePoolPledgeInfluence , protocolUpdateMonetaryExpansion , protocolUpdateTreasuryCut - , protocolUpdateUTxOCostPerWord + , protocolUpdateUTxOCostPerByte , protocolUpdateCollateralPercent , protocolUpdateMaxBlockExUnits , protocolUpdateMaxCollateralInputs @@ -261,7 +261,7 @@ friendlyProtocolParametersUpdate , protocolUpdateMonetaryExpansion <&> ("monetary expansion" .=) . friendlyRational , protocolUpdateTreasuryCut <&> ("treasury expansion" .=) . friendlyRational - , protocolUpdateUTxOCostPerWord <&> + , protocolUpdateUTxOCostPerByte <&> ("UTxO storage cost per unit" .=) . friendlyLovelace , protocolUpdateCollateralPercent <&> ("collateral inputs share" .=) . (<> "%") . textShow diff --git a/cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs b/cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs index 45eec8be4bd..b5e0a8a7864 100644 --- a/cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs +++ b/cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs @@ -2895,7 +2895,7 @@ pProtocolParametersUpdate = <*> optional pPoolInfluence <*> optional pMonetaryExpansion <*> optional pTreasuryExpansion - <*> optional pUTxOCostPerWord + <*> optional pUTxOCostPerByte <*> pure mempty <*> optional pExecutionUnitPrices <*> optional pMaxTxExecutionUnits @@ -3054,12 +3054,12 @@ pExtraEntropy = . B16.decode . BSC.pack =<< some Parsec.hexDigit -pUTxOCostPerWord :: Parser Lovelace -pUTxOCostPerWord = +pUTxOCostPerByte :: Parser Lovelace +pUTxOCostPerByte = Opt.option (readerFromParsecParser parseLovelace) - ( Opt.long "utxo-cost-per-word" + ( Opt.long "utxo-cost-per-byte" <> Opt.metavar "LOVELACE" - <> Opt.help "Cost in lovelace per unit of UTxO storage (from Alonzo era)." + <> Opt.help "Cost in lovelace per unit of UTxO storage (from Babbage era)." ) pExecutionUnitPrices :: Parser ExecutionUnitPrices