Skip to content

Commit

Permalink
stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
newhoggy committed Jul 7, 2022
1 parent d1eb9ea commit 305e182
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 27 deletions.
2 changes: 1 addition & 1 deletion cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ source-repository-package
source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-ledger
tag: 0913292b13963ae4b60136eddb8d18b137f96a21
tag: 65292694de72f137e6b90c5f361ae7646b48775f
--sha256: 19rrnvvplvg8v989bcv6vpjwvblfa0m65izxkcp8dclf0a914qq3
subdir:
eras/alonzo/impl
Expand Down
4 changes: 3 additions & 1 deletion 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 All @@ -785,7 +786,7 @@ genProtocolParametersUpdate = do
protocolUpdatePoolPledgeInfluence <- Gen.maybe genRationalInt64
protocolUpdateMonetaryExpansion <- Gen.maybe genRational
protocolUpdateTreasuryCut <- Gen.maybe genRational
protocolUpdateUTxOCostPerByte <- Gen.maybe genLovelace
protocolUpdateUTxOCostPerWord <- Gen.maybe genLovelace
let protocolUpdateCostModels = mempty -- genCostModels
--TODO: Babbage figure out how to deal with
-- asymmetric cost model JSON instances
Expand All @@ -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: 11 additions & 0 deletions cardano-api/src/Cardano/Api/Fees.hs
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,10 @@ data TxBodyErrorAutoBalance =

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

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

-- | The transaction validity interval is too far into the future.
Expand Down Expand Up @@ -856,6 +860,9 @@ 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"

Expand Down Expand Up @@ -1259,13 +1266,17 @@ 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 \
\trying to calculate minimum UTxO value."
displayError PParamsUTxOCostPerByteMissing =
"\"utxoCostPerByte\" field not present in protocol parameters when \
\trying to calculate minimum UTxO value."
65 changes: 43 additions & 22 deletions cardano-api/src/Cardano/Api/ProtocolParameters.hs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ import qualified Cardano.Ledger.Alonzo.PParams as Alonzo
import qualified Cardano.Ledger.Alonzo.Scripts as Alonzo

import qualified Cardano.Ledger.Babbage.PParams as Babbage
import Cardano.Ledger.Babbage.Translation (coinsPerUTxOWordToCoinsPerUTxOByte)

import Text.PrettyBy.Default (display)

Expand Down Expand Up @@ -249,8 +248,8 @@ data ProtocolParameters =

-- | Cost in ada per byte of UTxO storage.
--
-- /Introduced in Babbage/
protocolParamUTxOCostPerByte :: Maybe Lovelace,
-- /Introduced in Alonzo/
protocolParamUTxOCostPerWord :: Maybe Lovelace,

-- | Cost models for script languages that use them.
--
Expand Down Expand Up @@ -286,7 +285,13 @@ data ProtocolParameters =
-- | The maximum number of collateral inputs allowed in a transaction.
--
-- /Introduced in Alonzo/
protocolParamMaxCollateralInputs :: Maybe Natural
protocolParamMaxCollateralInputs :: Maybe Natural,

-- | Cost in ada per byte of UTxO storage.
--
-- /Introduced in Babbage/
protocolParamUTxOCostPerByte :: Maybe Lovelace

}
deriving (Eq, Generic, Show)

Expand All @@ -312,14 +317,15 @@ instance FromJSON ProtocolParameters where
<*> o .: "poolPledgeInfluence"
<*> o .: "monetaryExpansion"
<*> o .: "treasuryCut"
<*> o .:? "utxoCostPerBytes"
<*> o .:? "utxoCostPerWord"
<*> o .:? "costModels" .!= Map.empty
<*> o .:? "executionUnitPrices"
<*> o .:? "maxTxExecutionUnits"
<*> o .:? "maxBlockExecutionUnits"
<*> o .:? "maxValueSize"
<*> o .:? "collateralPercentage"
<*> o .:? "maxCollateralInputs"
<*> o .:? "utxoCostPerByte"

instance ToJSON ProtocolParameters where
toJSON ProtocolParameters{..} =
Expand All @@ -343,6 +349,7 @@ instance ToJSON ProtocolParameters where
, "txFeeFixed" .= protocolParamTxFeeFixed
, "txFeePerByte" .= protocolParamTxFeePerByte
-- Alonzo era:
, "utxoCostPerWord" .= protocolParamUTxOCostPerWord
, "costModels" .= protocolParamCostModels
, "executionUnitPrices" .= protocolParamPrices
, "maxTxExecutionUnits" .= protocolParamMaxTxExUnits
Expand Down Expand Up @@ -474,12 +481,12 @@ data ProtocolParametersUpdate =
--
protocolUpdateTreasuryCut :: Maybe Rational,

-- Introduced in Babbage,
-- Introduced in Alonzo,

-- | Cost in ada per byte of UTxO storage.
--
-- /Introduced in Babbage/
protocolUpdateUTxOCostPerByte :: Maybe Lovelace,
-- /Introduced in Alonzo, obsoleted in Babbage by 'protocolUpdateUTxOCostPerByte'/
protocolUpdateUTxOCostPerWord :: Maybe Lovelace,

-- Introduced in Alonzo,

Expand Down Expand Up @@ -517,7 +524,12 @@ data ProtocolParametersUpdate =
-- | The maximum number of collateral inputs allowed in a transaction.
--
-- /Introduced in Alonzo/
protocolUpdateMaxCollateralInputs :: Maybe Natural
protocolUpdateMaxCollateralInputs :: Maybe Natural,

-- | Cost in ada per byte of UTxO storage.
--
-- /Introduced in Babbage. Supercedes 'protocolUpdateUTxOCostPerWord'/
protocolUpdateUTxOCostPerByte :: Maybe Lovelace
}
deriving (Eq, Show)

Expand All @@ -541,16 +553,17 @@ 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
, protocolUpdateMaxBlockExUnits = merge protocolUpdateMaxBlockExUnits
, protocolUpdateMaxValueSize = merge protocolUpdateMaxValueSize
, protocolUpdateCollateralPercent = merge protocolUpdateCollateralPercent
, protocolUpdateMaxCollateralInputs = merge protocolUpdateMaxCollateralInputs
-- Introduced in Babbage below.
, protocolUpdateUTxOCostPerByte = merge protocolUpdateUTxOCostPerByte
}
where
-- prefer the right hand side:
Expand Down Expand Up @@ -581,19 +594,20 @@ instance Monoid ProtocolParametersUpdate where
, protocolUpdatePoolPledgeInfluence = Nothing
, protocolUpdateMonetaryExpansion = Nothing
, protocolUpdateTreasuryCut = Nothing
, protocolUpdateUTxOCostPerByte = Nothing
, protocolUpdateUTxOCostPerWord = Nothing
, protocolUpdateCostModels = mempty
, protocolUpdatePrices = Nothing
, protocolUpdateMaxTxExUnits = Nothing
, protocolUpdateMaxBlockExUnits = Nothing
, protocolUpdateMaxValueSize = Nothing
, protocolUpdateCollateralPercent = Nothing
, protocolUpdateMaxCollateralInputs = Nothing
, protocolUpdateUTxOCostPerByte = Nothing
}

instance ToCBOR ProtocolParametersUpdate where
toCBOR ProtocolParametersUpdate{..} =
CBOR.encodeListLen 25
CBOR.encodeListLen 26
<> toCBOR protocolUpdateProtocolVersion
<> toCBOR protocolUpdateDecentralization
<> toCBOR protocolUpdateExtraPraosEntropy
Expand Down Expand Up @@ -622,7 +636,7 @@ instance ToCBOR ProtocolParametersUpdate where

instance FromCBOR ProtocolParametersUpdate where
fromCBOR = do
CBOR.enforceSize "ProtocolParametersUpdate" 25
CBOR.enforceSize "ProtocolParametersUpdate" 26
ProtocolParametersUpdate
<$> fromCBOR
<*> fromCBOR
Expand All @@ -649,6 +663,7 @@ instance FromCBOR ProtocolParametersUpdate where
<*> fromCBOR
<*> fromCBOR
<*> fromCBOR
<*> fromCBOR


-- ----------------------------------------------------------------------------
Expand Down Expand Up @@ -1171,14 +1186,16 @@ fromShelleyPParamsUpdate
strictMaybeToMaybe _rho
, protocolUpdateTreasuryCut = Ledger.unboundRational <$>
strictMaybeToMaybe _tau
, protocolUpdateUTxOCostPerByte = Nothing -- Babbage
, protocolUpdateUTxOCostPerWord = Nothing
, protocolUpdateCostModels = mempty
, protocolUpdatePrices = Nothing
, protocolUpdateMaxTxExUnits = Nothing
, protocolUpdateMaxBlockExUnits = Nothing
, protocolUpdateMaxValueSize = Nothing
, protocolUpdateCollateralPercent = Nothing
, protocolUpdateMaxCollateralInputs = Nothing

, protocolUpdateUTxOCostPerByte = Nothing
}

fromAlonzoPParamsUpdate :: Alonzo.PParamsUpdate ledgerera
Expand Down Expand Up @@ -1237,7 +1254,7 @@ fromAlonzoPParamsUpdate
strictMaybeToMaybe _rho
, protocolUpdateTreasuryCut = Ledger.unboundRational <$>
strictMaybeToMaybe _tau
, protocolUpdateUTxOCostPerByte = fromShelleyLovelace . coinsPerUTxOWordToCoinsPerUTxOByte <$>
, protocolUpdateUTxOCostPerWord = fromShelleyLovelace <$>
strictMaybeToMaybe _coinsPerUTxOWord
, protocolUpdateCostModels = maybe mempty fromAlonzoCostModels
(strictMaybeToMaybe _costmdls)
Expand All @@ -1250,6 +1267,7 @@ fromAlonzoPParamsUpdate
, protocolUpdateMaxValueSize = strictMaybeToMaybe _maxValSize
, protocolUpdateCollateralPercent = strictMaybeToMaybe _collateralPercentage
, protocolUpdateMaxCollateralInputs = strictMaybeToMaybe _maxCollateralInputs
, protocolUpdateUTxOCostPerByte = Nothing
}


Expand Down Expand Up @@ -1305,8 +1323,7 @@ fromBabbagePParamsUpdate
strictMaybeToMaybe _rho
, protocolUpdateTreasuryCut = Ledger.unboundRational <$>
strictMaybeToMaybe _tau
, protocolUpdateUTxOCostPerByte = fromShelleyLovelace <$>
strictMaybeToMaybe _coinsPerUTxOByte
, protocolUpdateUTxOCostPerWord = Nothing
, protocolUpdateCostModels = maybe mempty fromAlonzoCostModels
(strictMaybeToMaybe _costmdls)
, protocolUpdatePrices = fromAlonzoPrices <$>
Expand All @@ -1318,6 +1335,8 @@ fromBabbagePParamsUpdate
, protocolUpdateMaxValueSize = strictMaybeToMaybe _maxValSize
, protocolUpdateCollateralPercent = strictMaybeToMaybe _collateralPercentage
, protocolUpdateMaxCollateralInputs = strictMaybeToMaybe _maxCollateralInputs
, protocolUpdateUTxOCostPerByte = fromShelleyLovelace <$>
strictMaybeToMaybe _coinsPerUTxOByte
}


Expand Down Expand Up @@ -1631,14 +1650,15 @@ fromShelleyPParams
, protocolParamPoolPledgeInfluence = Ledger.unboundRational _a0
, protocolParamMonetaryExpansion = Ledger.unboundRational _rho
, protocolParamTreasuryCut = Ledger.unboundRational _tau
, protocolParamUTxOCostPerByte = Nothing
, protocolParamUTxOCostPerWord = Nothing
, protocolParamCostModels = Map.empty
, protocolParamPrices = Nothing
, protocolParamMaxTxExUnits = Nothing
, protocolParamMaxBlockExUnits = Nothing
, protocolParamMaxValueSize = Nothing
, protocolParamCollateralPercent = Nothing
, protocolParamMaxCollateralInputs = Nothing
, protocolParamUTxOCostPerByte = Nothing
}


Expand Down Expand Up @@ -1689,15 +1709,15 @@ fromAlonzoPParams
, protocolParamPoolPledgeInfluence = Ledger.unboundRational _a0
, protocolParamMonetaryExpansion = Ledger.unboundRational _rho
, protocolParamTreasuryCut = Ledger.unboundRational _tau
, protocolParamUTxOCostPerByte = -- adapted from alonzo protocol parameter field
Just (fromShelleyLovelace (coinsPerUTxOWordToCoinsPerUTxOByte _coinsPerUTxOWord))
, protocolParamUTxOCostPerWord = Just (fromShelleyLovelace _coinsPerUTxOWord)
, protocolParamCostModels = fromAlonzoCostModels _costmdls
, protocolParamPrices = Just (fromAlonzoPrices _prices)
, protocolParamMaxTxExUnits = Just (fromAlonzoExUnits _maxTxExUnits)
, protocolParamMaxBlockExUnits = Just (fromAlonzoExUnits _maxBlockExUnits)
, protocolParamMaxValueSize = Just _maxValSize
, protocolParamCollateralPercent = Just _collateralPercentage
, protocolParamMaxCollateralInputs = Just _maxCollateralInputs
, protocolParamUTxOCostPerByte = Nothing
}

fromBabbagePParams :: Babbage.PParams ledgerera -> ProtocolParameters
Expand Down Expand Up @@ -1745,14 +1765,15 @@ fromBabbagePParams
, protocolParamPoolPledgeInfluence = Ledger.unboundRational _a0
, protocolParamMonetaryExpansion = Ledger.unboundRational _rho
, protocolParamTreasuryCut = Ledger.unboundRational _tau
, protocolParamUTxOCostPerByte = Just (fromShelleyLovelace _coinsPerUTxOByte)
, protocolParamUTxOCostPerWord = Nothing
, protocolParamCostModels = fromAlonzoCostModels _costmdls
, protocolParamPrices = Just (fromAlonzoPrices _prices)
, protocolParamMaxTxExUnits = Just (fromAlonzoExUnits _maxTxExUnits)
, protocolParamMaxBlockExUnits = Just (fromAlonzoExUnits _maxBlockExUnits)
, protocolParamMaxValueSize = Just _maxValSize
, protocolParamCollateralPercent = Just _collateralPercentage
, protocolParamMaxCollateralInputs = Just _maxCollateralInputs
, protocolParamUTxOCostPerByte = Just (fromShelleyLovelace _coinsPerUTxOByte)
}

data ProtocolParametersError =
Expand Down
11 changes: 10 additions & 1 deletion cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2895,14 +2895,15 @@ pProtocolParametersUpdate =
<*> optional pPoolInfluence
<*> optional pMonetaryExpansion
<*> optional pTreasuryExpansion
<*> optional pUTxOCostPerByte
<*> optional pUTxOCostPerWord
<*> pure mempty
<*> optional pExecutionUnitPrices
<*> optional pMaxTxExecutionUnits
<*> optional pMaxBlockExecutionUnits
<*> optional pMaxValueSize
<*> optional pCollateralPercent
<*> optional pMaxCollateralInputs
<*> optional pUTxOCostPerByte

pCostModels :: Parser FilePath
pCostModels =
Expand Down Expand Up @@ -3054,6 +3055,14 @@ pExtraEntropy =
. B16.decode . BSC.pack
=<< some Parsec.hexDigit

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

pUTxOCostPerByte :: Parser Lovelace
pUTxOCostPerByte =
Opt.option (readerFromParsecParser parseLovelace)
Expand Down
2 changes: 1 addition & 1 deletion cardano-node/src/Cardano/Node/Tracing/Era/Shelley.hs
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ 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'
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ 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'
]
Expand Down

0 comments on commit 305e182

Please sign in to comment.