Skip to content

Commit

Permalink
Merge pull request #3440 from input-output-hk/lehins/fix-pparams-and-…
Browse files Browse the repository at this point in the history
…ledger-state-serialization

Revert back to the group serialization for ProtVer for PParams
  • Loading branch information
lehins authored May 23, 2023
2 parents 040b3a4 + b79bc64 commit d421556
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 133 deletions.
4 changes: 4 additions & 0 deletions eras/alonzo/impl/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
* Remove `witsVKeyNeeded`, in favor of the one from `cardano-ledger-shelley`
* Fix an issue where `TotalDeposits` didn't appear on Alonzo era

## 1.2.1.0

* Fix `PParams AlonzoEra` serialization. [#3440](https://github.com/input-output-hk/cardano-ledger/pull/3440)

## 1.2.0.0

* Replace `DPState c` with `CertState era`
Expand Down
141 changes: 59 additions & 82 deletions eras/alonzo/impl/src/Cardano/Ledger/Alonzo/PParams.hs
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,16 @@ import Cardano.Ledger.Binary (
Encoding,
FromCBOR (..),
ToCBOR (..),
decCBORGroup,
decodeRecordNamed,
encCBORGroup,
encodeFoldableAsDefLenList,
encodeFoldableAsIndefLenList,
encodeListLen,
encodeMapLen,
encodeNull,
encodePreEncoded,
listLen,
serialize',
)
import Cardano.Ledger.Binary.Coders (
Expand All @@ -101,7 +106,6 @@ import Cardano.Ledger.Binary.Coders (
encode,
field,
(!>),
(<!),
)
import Cardano.Ledger.Coin (Coin (..))
import Cardano.Ledger.Crypto (Crypto)
Expand Down Expand Up @@ -278,90 +282,63 @@ instance Crypto c => EraGovernance (AlonzoEra c) where
getProposedPPUpdates = Just . proposals

instance Era era => EncCBOR (AlonzoPParams Identity era) where
encCBOR
AlonzoPParams
{ appMinFeeA
, appMinFeeB
, appMaxBBSize
, appMaxTxSize
, appMaxBHSize
, appKeyDeposit
, appPoolDeposit
, appEMax
, appNOpt
, appA0
, appRho
, appTau
, appD
, appExtraEntropy
, appProtocolVersion
, appMinPoolCost
, appCoinsPerUTxOWord
, appCostModels
, appPrices
, appMaxTxExUnits
, appMaxBlockExUnits
, appMaxValSize
, appCollateralPercentage
, appMaxCollateralInputs
} =
encode $
Rec (AlonzoPParams @Identity)
!> To appMinFeeA
!> To appMinFeeB
!> To appMaxBBSize
!> To appMaxTxSize
!> To appMaxBHSize
!> To appKeyDeposit
!> To appPoolDeposit
!> To appEMax
!> To appNOpt
!> To appA0
!> To appRho
!> To appTau
!> To appD
!> To appExtraEntropy
!> To appProtocolVersion
!> To appMinPoolCost
-- new/updated for alonzo
!> To appCoinsPerUTxOWord
!> To appCostModels
!> To appPrices
!> To appMaxTxExUnits
!> To appMaxBlockExUnits
!> To appMaxValSize
!> To appCollateralPercentage
!> To appMaxCollateralInputs
encCBOR AlonzoPParams {..} =
encodeListLen (23 + listLen appProtocolVersion)
<> encCBOR appMinFeeA
<> encCBOR appMinFeeB
<> encCBOR appMaxBBSize
<> encCBOR appMaxTxSize
<> encCBOR appMaxBHSize
<> encCBOR appKeyDeposit
<> encCBOR appPoolDeposit
<> encCBOR appEMax
<> encCBOR appNOpt
<> encCBOR appA0
<> encCBOR appRho
<> encCBOR appTau
<> encCBOR appD
<> encCBOR appExtraEntropy
<> encCBORGroup appProtocolVersion
<> encCBOR appMinPoolCost
-- new/updated for alonzo
<> encCBOR appCoinsPerUTxOWord
<> encCBOR appCostModels
<> encCBOR appPrices
<> encCBOR appMaxTxExUnits
<> encCBOR appMaxBlockExUnits
<> encCBOR appMaxValSize
<> encCBOR appCollateralPercentage
<> encCBOR appMaxCollateralInputs

instance Era era => DecCBOR (AlonzoPParams Identity era) where
decCBOR =
decode $
RecD AlonzoPParams
<! From -- appMinFeeA
<! From -- appMinFeeB
<! From -- appMaxBBSize
<! From -- appMaxTxSize
<! From -- appMaxBHSize
<! From -- appKeyDeposit
<! From -- appPoolDeposit
<! From -- appEMax
<! From -- appNOpt
<! From -- appA0
<! From -- appRho
<! From -- appTau
<! From -- appD
<! From -- appExtraEntropy
<! From -- appProtocolVersion
<! From -- appMinPoolCost
-- new/updated for alonzo
<! From -- appCoinsPerUTxOWord
<! From -- appCostModels
<! From -- appPrices
<! From -- appMaxTxExUnits
<! From -- appMaxBlockExUnits
<! From -- appMaxValSize
<! From -- appCollateralPercentage
<! From -- appMaxCollateralInputs
decodeRecordNamed "PParams" (\pp -> 23 + fromIntegral (listLen (appProtocolVersion pp))) $ do
appMinFeeA <- decCBOR
appMinFeeB <- decCBOR
appMaxBBSize <- decCBOR
appMaxTxSize <- decCBOR
appMaxBHSize <- decCBOR
appKeyDeposit <- decCBOR
appPoolDeposit <- decCBOR
appEMax <- decCBOR
appNOpt <- decCBOR
appA0 <- decCBOR
appRho <- decCBOR
appTau <- decCBOR
appD <- decCBOR
appExtraEntropy <- decCBOR
appProtocolVersion <- decCBORGroup
appMinPoolCost <- decCBOR
-- new/updated for alonzo
appCoinsPerUTxOWord <- decCBOR
appCostModels <- decCBOR
appPrices <- decCBOR
appMaxTxExUnits <- decCBOR
appMaxBlockExUnits <- decCBOR
appMaxValSize <- decCBOR
appCollateralPercentage <- decCBOR
appMaxCollateralInputs <- decCBOR
pure AlonzoPParams {..}

instance Era era => ToCBOR (AlonzoPParams Identity era) where
toCBOR = toEraCBOR @era
Expand Down
Binary file modified eras/alonzo/test-suite/golden/translations.cbor
Binary file not shown.
4 changes: 4 additions & 0 deletions eras/babbage/impl/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
* Add `EraPlutusContext 'PlutusV2` instance to `BabbageEra`
* Fix an issue where `TotalDeposits` didn't appear on Babbage era

## 1.2.1.0

* Fix `PParams BabbageEra` serialization. [#3440](https://github.com/input-output-hk/cardano-ledger/pull/3440)

## 1.2.0.0

* Replace `DPState c` with `CertState era`
Expand Down
102 changes: 52 additions & 50 deletions eras/babbage/impl/src/Cardano/Ledger/Babbage/PParams.hs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ import Cardano.Ledger.Binary (
Encoding,
FromCBOR (..),
ToCBOR (..),
decCBORGroup,
decodeRecordNamed,
encCBORGroup,
encodeListLen,
listLen,
)
import Cardano.Ledger.Binary.Coders (
Decode (..),
Expand All @@ -71,7 +76,6 @@ import Cardano.Ledger.Binary.Coders (
encode,
field,
(!>),
(<!),
)
import Cardano.Ledger.Coin (Coin (..))
import Cardano.Ledger.Crypto (Crypto)
Expand Down Expand Up @@ -233,61 +237,59 @@ instance Crypto c => EraGovernance (BabbageEra c) where

instance Era era => EncCBOR (BabbagePParams Identity era) where
encCBOR BabbagePParams {..} =
encode
( Rec (BabbagePParams @Identity)
!> To bppMinFeeA
!> To bppMinFeeB
!> To bppMaxBBSize
!> To bppMaxTxSize
!> To bppMaxBHSize
!> To bppKeyDeposit
!> To bppPoolDeposit
!> To bppEMax
!> To bppNOpt
!> To bppA0
!> To bppRho
!> To bppTau
!> To bppProtocolVersion
!> To bppMinPoolCost
!> To bppCoinsPerUTxOByte
!> To bppCostModels
!> To bppPrices
!> To bppMaxTxExUnits
!> To bppMaxBlockExUnits
!> To bppMaxValSize
!> To bppCollateralPercentage
!> To bppMaxCollateralInputs
)
encodeListLen (21 + listLen bppProtocolVersion)
<> encCBOR bppMinFeeA
<> encCBOR bppMinFeeB
<> encCBOR bppMaxBBSize
<> encCBOR bppMaxTxSize
<> encCBOR bppMaxBHSize
<> encCBOR bppKeyDeposit
<> encCBOR bppPoolDeposit
<> encCBOR bppEMax
<> encCBOR bppNOpt
<> encCBOR bppA0
<> encCBOR bppRho
<> encCBOR bppTau
<> encCBORGroup bppProtocolVersion
<> encCBOR bppMinPoolCost
<> encCBOR bppCoinsPerUTxOByte
<> encCBOR bppCostModels
<> encCBOR bppPrices
<> encCBOR bppMaxTxExUnits
<> encCBOR bppMaxBlockExUnits
<> encCBOR bppMaxValSize
<> encCBOR bppCollateralPercentage
<> encCBOR bppMaxCollateralInputs

instance Era era => ToCBOR (BabbagePParams Identity era) where
toCBOR = toEraCBOR @era

instance Era era => DecCBOR (BabbagePParams Identity era) where
decCBOR =
decode $
RecD BabbagePParams
<! From -- bppMinFeeA
<! From -- bppMinFeeB
<! From -- bppMaxBBSize
<! From -- bppMaxTxSize
<! From -- bppMaxBHSize
<! From -- bppKeyDeposit
<! From -- bppPoolDeposit
<! From -- bppEMax
<! From -- bppNOpt
<! From -- bppA0
<! From -- bppRho
<! From -- bppTau
<! From -- bppProtocolVersion
<! From -- bppMinPoolCost
<! From -- bppCoinsPerUTxOByte
<! From -- bppCostModels
<! From -- bppPrices
<! From -- bppMaxTxExUnits
<! From -- bppMaxBlockExUnits
<! From -- maxValSize
<! From -- collateralPercentage
<! From -- maxCollateralInputs
decodeRecordNamed "PParams" (\pp -> 21 + fromIntegral (listLen (bppProtocolVersion pp))) $ do
bppMinFeeA <- decCBOR
bppMinFeeB <- decCBOR
bppMaxBBSize <- decCBOR
bppMaxTxSize <- decCBOR
bppMaxBHSize <- decCBOR
bppKeyDeposit <- decCBOR
bppPoolDeposit <- decCBOR
bppEMax <- decCBOR
bppNOpt <- decCBOR
bppA0 <- decCBOR
bppRho <- decCBOR
bppTau <- decCBOR
bppProtocolVersion <- decCBORGroup
bppMinPoolCost <- decCBOR
bppCoinsPerUTxOByte <- decCBOR
bppCostModels <- decCBOR
bppPrices <- decCBOR
bppMaxTxExUnits <- decCBOR
bppMaxBlockExUnits <- decCBOR
bppMaxValSize <- decCBOR
bppCollateralPercentage <- decCBOR
bppMaxCollateralInputs <- decCBOR
pure BabbagePParams {..}

instance Era era => FromCBOR (BabbagePParams Identity era) where
fromCBOR = fromEraCBOR @era
Expand Down
Binary file modified eras/babbage/test-suite/golden/translations.cbor
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
Expand Down

0 comments on commit d421556

Please sign in to comment.