Skip to content

Commit

Permalink
Merge pull request #4051 from input-output-hk/jordan/adjust-toledgerp…
Browse files Browse the repository at this point in the history
…arams-to-not-error-when-missing-decen-param

Do not require decentralization parameter in protocol parameters
  • Loading branch information
dcoutts authored Jun 15, 2022
2 parents 7e7b21f + bbb8a57 commit 6471c31
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions cardano-api/src/Cardano/Api/ProtocolParameters.hs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ data ProtocolParameters =
--
-- This is the \"d\" parameter from the design document.
--
-- /Deprecated in Babbage/
protocolParamDecentralization :: Maybe Rational,

-- | Extra entropy for the Praos per-epoch nonce.
Expand Down Expand Up @@ -295,7 +296,7 @@ instance FromJSON ProtocolParameters where
v <- o .: "protocolVersion"
ProtocolParameters
<$> ((,) <$> v .: "major" <*> v .: "minor")
<*> o .: "decentralization"
<*> o .:? "decentralization"
<*> o .: "extraPraosEntropy"
<*> o .: "maxBlockHeaderSize"
<*> o .: "maxBlockBodySize"
Expand Down Expand Up @@ -1358,7 +1359,13 @@ toShelleyPParams ProtocolParameters {
= let (maj, minor) = protocolParamProtocolVersion
in Ledger.ProtVer maj minor
, Shelley._d = case protocolParamDecentralization of
Nothing -> error "toAlonzoPParams: Decentralization value required in Shelley era"
-- The decentralization parameter is deprecated in Babbage
-- so we default to 0 if no dentralization parameter is found
-- in the api's 'ProtocolParameter' type. If we don't do this
-- we won't be able to construct an Alonzo tx using the Babbage
-- era's protocol parameter because our only other option is to
-- error.
Nothing -> minBound
Just pDecentral ->
fromMaybe
(error "toAlonzoPParams: invalid Decentralization value")
Expand Down Expand Up @@ -1420,7 +1427,13 @@ toAlonzoPParams ProtocolParameters {
= let (maj, minor) = protocolParamProtocolVersion
in Ledger.ProtVer maj minor
, Alonzo._d = case protocolParamDecentralization of
Nothing -> error "toAlonzoPParams: Decentralization value required in Alonzo era"
-- The decentralization parameter is deprecated in Babbage
-- so we default to 0 if no dentralization parameter is found
-- in the api's 'ProtocolParameter' type. If we don't do this
-- we won't be able to construct an Alonzo tx using the Babbage
-- era's protocol parameter because our only other option is to
-- error.
Nothing -> minBound
Just pDecentral ->
fromMaybe
(error "toAlonzoPParams: invalid Decentralization value")
Expand Down Expand Up @@ -1557,6 +1570,7 @@ toBabbagePParams ProtocolParameters { protocolParamCollateralPercent = Nothing }
error "toBabbagePParams: must specify protocolParamCollateralPercent"
toBabbagePParams ProtocolParameters { protocolParamMaxCollateralInputs = Nothing } =
error "toBabbagePParams: must specify protocolParamMaxCollateralInputs"

-- ----------------------------------------------------------------------------
-- Conversion functions: protocol parameters from ledger types
--
Expand Down

0 comments on commit 6471c31

Please sign in to comment.