Skip to content

Commit

Permalink
Add utxoCostPerByte parameter.
Browse files Browse the repository at this point in the history
  • Loading branch information
newhoggy authored and Jimbo4350 committed Aug 2, 2022
1 parent 7c7eaca commit 46acf18
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 67 deletions.
2 changes: 2 additions & 0 deletions cardano-api/gen/Gen/Cardano/Api/Typed.hs
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,7 @@ genProtocolParameters =
<*> Gen.maybe genNat
<*> Gen.maybe genNat
<*> Gen.maybe genNat
<*> Gen.maybe genLovelace

genProtocolParametersUpdate :: Gen ProtocolParametersUpdate
genProtocolParametersUpdate = do
Expand Down Expand Up @@ -795,6 +796,7 @@ genProtocolParametersUpdate = do
protocolUpdateMaxValueSize <- Gen.maybe genNat
protocolUpdateCollateralPercent <- Gen.maybe genNat
protocolUpdateMaxCollateralInputs <- Gen.maybe genNat
protocolUpdateUTxOCostPerByte <- Gen.maybe genLovelace
pure ProtocolParametersUpdate{..}


Expand Down
11 changes: 0 additions & 11 deletions cardano-api/src/Cardano/Api/Fees.hs
Original file line number Diff line number Diff line change
Expand Up @@ -793,10 +793,6 @@ data TxBodyErrorAutoBalance =
-- parameter, for eras that use this parameter.
| TxBodyErrorMissingParamMinUTxO

-- | The 'ProtocolParameters' must provide the value for the cost per
-- word parameter, for eras that use this parameter.
| TxBodyErrorMissingParamCostPerWord

-- | The transaction validity interval is too far into the future.
-- See 'TransactionValidityIntervalError' for details.
| TxBodyErrorValidityInterval TransactionValidityError
Expand Down Expand Up @@ -856,9 +852,6 @@ 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 (TxBodyErrorValidityInterval err) =
displayError err

Expand Down Expand Up @@ -1268,13 +1261,9 @@ calculateMinimumUTxO era txout@(TxOut _ v _ _) pparams' =

data MinimumUTxOError =
PParamsMinUTxOMissing
| PParamsUTxOCostPerWordMissing
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 \
\trying to calculate minimum UTxO value."
133 changes: 86 additions & 47 deletions cardano-api/src/Cardano/Api/ProtocolParameters.hs

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions cardano-api/src/Cardano/Api/Value.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion cardano-cli/src/Cardano/CLI/Run/Friendly.hs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ friendlyProtocolParametersUpdate
, protocolUpdateMaxTxExUnits
, protocolUpdateMaxValueSize
, protocolUpdatePrices
, protocolUpdateUTxOCostPerByte
} =
object . catMaybes $
[ protocolUpdateProtocolVersion <&> \(major, minor) ->
Expand Down Expand Up @@ -258,14 +259,16 @@ friendlyProtocolParametersUpdate
("monetary expansion" .=) . friendlyRational
, protocolUpdateTreasuryCut <&> ("treasury expansion" .=) . friendlyRational
, protocolUpdateUTxOCostPerWord <&>
("UTxO storage cost per unit" .=) . friendlyLovelace
("UTxO storage cost per word" .=) . friendlyLovelace
, protocolUpdateCollateralPercent <&>
("collateral inputs share" .=) . (<> "%") . textShow
, protocolUpdateMaxBlockExUnits <&> ("max block execution units" .=)
, protocolUpdateMaxCollateralInputs <&> ("max collateral inputs" .=)
, protocolUpdateMaxTxExUnits <&> ("max transaction execution units" .=)
, protocolUpdateMaxValueSize <&> ("max value size" .=)
, protocolUpdatePrices <&> ("execution prices" .=) . friendlyPrices
, protocolUpdateUTxOCostPerByte <&>
("UTxO storage cost per byte" .=) . friendlyLovelace
]

friendlyPrices :: ExecutionUnitPrices -> Aeson.Value
Expand Down
9 changes: 9 additions & 0 deletions cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2903,6 +2903,7 @@ pProtocolParametersUpdate =
<*> optional pMaxValueSize
<*> optional pCollateralPercent
<*> optional pMaxCollateralInputs
<*> optional pUTxOCostPerByte

pCostModels :: Parser FilePath
pCostModels =
Expand Down Expand Up @@ -3062,6 +3063,14 @@ pUTxOCostPerWord =
<> Opt.help "Cost in lovelace per unit of UTxO storage (from Alonzo era)."
)

pUTxOCostPerByte :: Parser Lovelace
pUTxOCostPerByte =
Opt.option (readerFromParsecParser parseLovelace)
( Opt.long "utxo-cost-per-byte"
<> Opt.metavar "LOVELACE"
<> Opt.help "Cost in lovelace per unit of UTxO storage (from Babbage era)."
)

pExecutionUnitPrices :: Parser ExecutionUnitPrices
pExecutionUnitPrices = ExecutionUnitPrices
<$> Opt.option readRational
Expand Down
2 changes: 1 addition & 1 deletion cardano-cli/test/data/golden/alonzo/transaction-view.out
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ update proposal:
updates:
- genesis key hash: 1bafa294233a5a7ffbf539ae798da0943aa83d2a19398c2d0e5af114
update:
UTxO storage cost per unit: 194 Lovelace
UTxO storage cost per word: 194 Lovelace
collateral inputs share: 200%
execution prices:
memory: 196/197
Expand Down
4 changes: 2 additions & 2 deletions cardano-node/src/Cardano/Node/Tracing/Era/Shelley.hs
Original file line number Diff line number Diff line change
Expand Up @@ -434,9 +434,9 @@ instance ( ShelleyBasedEra era
mconcat [ "kind" .= String "InvalidWitnessesUTXOW"
, "invalidWitnesses" .= map textShow wits'
]
forMachine _dtal (MissingVKeyWitnessesUTXOW (WitHashes wits')) =
forMachine _dtal (MissingVKeyWitnessesUTXOW wits') =
mconcat [ "kind" .= String "MissingVKeyWitnessesUTXOW"
, "missingWitnesses" .= wits'
, "missingWitnesses" .= String (Text.pack $ show wits')
]
forMachine _dtal (MissingScriptWitnessesUTXOW missingScripts) =
mconcat [ "kind" .= String "MissingScriptWitnessesUTXOW"
Expand Down
6 changes: 3 additions & 3 deletions cardano-node/src/Cardano/Tracing/OrphanInstances/Shelley.hs
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,10 @@ instance ( ShelleyBasedEra era
mconcat [ "kind" .= String "InvalidWitnessesUTXOW"
, "invalidWitnesses" .= map textShow wits'
]
toObject _verb (MissingVKeyWitnessesUTXOW (WitHashes wits')) =
toObject _verb (MissingVKeyWitnessesUTXOW wits') =
mconcat [ "kind" .= String "MissingVKeyWitnessesUTXOW"
, "missingWitnesses" .= wits'
]
, "missingWitnesses" .= String (Text.pack $ show wits')
]
toObject _verb (MissingScriptWitnessesUTXOW missingScripts) =
mconcat [ "kind" .= String "MissingScriptWitnessesUTXOW"
, "missingScripts" .= missingScripts
Expand Down

0 comments on commit 46acf18

Please sign in to comment.