Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions eras/conway/impl/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 1.21.0.0

* Change lens type of `hkdCommitteeMinSizeL` and `ppCommitteeMinSize` from `Natural` to `Word16`
* Change `STS` instance of `ConwayUTOXS`: use `PParams` as `Environment`
* Remove `TotalDeposits` and `TxUTxODiff` data constructors from `ConwayUtxosEvent`
* Add `Generic` instance for `ApplyTxError`
Expand Down
35 changes: 29 additions & 6 deletions eras/conway/impl/src/Cardano/Ledger/Conway/PParams.hs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class BabbageEraPParams era => ConwayEraPParams era where

hkdPoolVotingThresholdsL :: HKDFunctor f => Lens' (PParamsHKD f era) (HKD f PoolVotingThresholds)
hkdDRepVotingThresholdsL :: HKDFunctor f => Lens' (PParamsHKD f era) (HKD f DRepVotingThresholds)
hkdCommitteeMinSizeL :: HKDFunctor f => Lens' (PParamsHKD f era) (HKD f Natural)
hkdCommitteeMinSizeL :: HKDFunctor f => Lens' (PParamsHKD f era) (HKD f Word16)
hkdCommitteeMaxTermLengthL :: HKDFunctor f => Lens' (PParamsHKD f era) (HKD f EpochInterval)
hkdGovActionLifetimeL :: HKDFunctor f => Lens' (PParamsHKD f era) (HKD f EpochInterval)
hkdGovActionDepositCompactL :: HKDFunctor f => Lens' (PParamsHKD f era) (HKD f (CompactForm Coin))
Expand Down Expand Up @@ -229,7 +229,7 @@ ppDRepVotingThresholdsL ::
forall era. ConwayEraPParams era => Lens' (PParams era) DRepVotingThresholds
ppDRepVotingThresholdsL = ppLensHKD . hkdDRepVotingThresholdsL @era @Identity

ppCommitteeMinSizeL :: forall era. ConwayEraPParams era => Lens' (PParams era) Natural
ppCommitteeMinSizeL :: forall era. ConwayEraPParams era => Lens' (PParams era) Word16
ppCommitteeMinSizeL = ppLensHKD . hkdCommitteeMinSizeL @era @Identity

ppCommitteeMaxTermLengthL :: forall era. ConwayEraPParams era => Lens' (PParams era) EpochInterval
Expand Down Expand Up @@ -267,7 +267,7 @@ ppuDRepVotingThresholdsL ::
ppuDRepVotingThresholdsL = ppuLensHKD . hkdDRepVotingThresholdsL @era @StrictMaybe

ppuCommitteeMinSizeL ::
forall era. ConwayEraPParams era => Lens' (PParamsUpdate era) (StrictMaybe Natural)
forall era. ConwayEraPParams era => Lens' (PParamsUpdate era) (StrictMaybe Word16)
ppuCommitteeMinSizeL = ppuLensHKD . hkdCommitteeMinSizeL @era @StrictMaybe

ppuCommitteeMaxTermLengthL ::
Expand Down Expand Up @@ -881,6 +881,7 @@ instance EraPParams ConwayEra where
, ppMaxTxExUnits
, ppMaxBlockExUnits
, ppMaxValSize
, conwayPPCollateralPercentage
, ppCollateralPercentage
, ppMaxCollateralInputs
, ppPoolVotingThresholds
Expand Down Expand Up @@ -973,10 +974,8 @@ instance ConwayEraPParams ConwayEra where
lens (unTHKD . cppPoolVotingThresholds) $ \pp x -> pp {cppPoolVotingThresholds = THKD x}
hkdDRepVotingThresholdsL =
lens (unTHKD . cppDRepVotingThresholds) $ \pp x -> pp {cppDRepVotingThresholds = THKD x}
hkdCommitteeMinSizeL :: forall f. HKDFunctor f => Lens' (PParamsHKD f ConwayEra) (HKD f Natural)
hkdCommitteeMinSizeL =
lens (asNaturalHKD @f @Word16 . (unTHKD . cppCommitteeMinSize)) $
\pp x -> pp {cppCommitteeMinSize = THKD (asBoundedIntegralHKD @f @Natural @Word16 x)}
lens (unTHKD . cppCommitteeMinSize) $ \pp x -> pp {cppCommitteeMinSize = THKD x}
hkdCommitteeMaxTermLengthL =
lens (unTHKD . cppCommitteeMaxTermLength) $ \pp x -> pp {cppCommitteeMaxTermLength = THKD x}
hkdGovActionLifetimeL =
Expand Down Expand Up @@ -1374,3 +1373,27 @@ ppGovProtocolVersion =
, ppLens = ppProtocolVersionL
, ppUpdate = Nothing
}

conwayPPCollateralPercentage :: PParam ConwayEra
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lehins - what do you think of this approach?

The downside is of course that we'd have to duplicate the definition for Dijkstra and future eras, which kinda defeats the purpose of PParam mechanism.

Another way I was thinking of is to allow specifying something like setFromCBOR in PParam, in order to decouple the lens from the decoder, but this would also lead to different definitions of the PParam.

The root of the difficulty is the fact that hkdCollateralPercentageL is defined in AlonzoEraPParams -
I experimented with turning it off after Babbage (with AtMostEra) and adding a new field to ConwayEraPParams, but the problem with this is reusing the validations in Conway+ eras.

I'm leaning towards this approach I drafted here, but I'm curious what you think.

conwayPPCollateralPercentage =
PParam
{ ppName = "collateralPercentage"
, ppLens = ppCollateralPercentageWord16L
, ppUpdate = Just $ PParamUpdate 23 ppuCollateralPercentageWord16L
}

hkdCollateralPercentageWord16L :: Lens' (PParamsHKD f ConwayEra) (HKD f Word16)
hkdCollateralPercentageWord16L =
lens
(unTHKD . cppCollateralPercentage)
(\pp x -> pp {cppCollateralPercentage = THKD x})

ppCollateralPercentageWord16L ::
Lens' (PParams ConwayEra) Word16
ppCollateralPercentageWord16L =
ppLensHKD . hkdCollateralPercentageWord16L @Identity

ppuCollateralPercentageWord16L ::
Lens' (PParamsUpdate ConwayEra) (StrictMaybe Word16)
ppuCollateralPercentageWord16L =
ppuLensHKD . hkdCollateralPercentageWord16L @StrictMaybe
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ propConwayPParamsUpgrade ppu pp = property $ do
let pp' = upgradePParams ppu pp :: PParams ConwayEra
pp' ^. ppPoolVotingThresholdsL `shouldBe` ucppPoolVotingThresholds ppu
pp' ^. ppDRepVotingThresholdsL `shouldBe` ucppDRepVotingThresholds ppu
fromIntegral (pp' ^. ppCommitteeMinSizeL) `shouldBe` ucppCommitteeMinSize ppu
pp' ^. ppCommitteeMinSizeL `shouldBe` ucppCommitteeMinSize ppu
pp' ^. ppCommitteeMaxTermLengthL `shouldBe` ucppCommitteeMaxTermLength ppu
pp' ^. ppGovActionLifetimeL `shouldBe` ucppGovActionLifetime ppu
pp' ^. ppGovActionDepositL `shouldBe` ucppGovActionDeposit ppu
Expand Down
4 changes: 1 addition & 3 deletions eras/dijkstra/impl/src/Cardano/Ledger/Dijkstra/PParams.hs
Original file line number Diff line number Diff line change
Expand Up @@ -573,10 +573,8 @@ instance ConwayEraPParams DijkstraEra where
lens (unTHKD . dppPoolVotingThresholds) $ \pp x -> pp {dppPoolVotingThresholds = THKD x}
hkdDRepVotingThresholdsL =
lens (unTHKD . dppDRepVotingThresholds) $ \pp x -> pp {dppDRepVotingThresholds = THKD x}
hkdCommitteeMinSizeL :: forall f. HKDFunctor f => Lens' (PParamsHKD f DijkstraEra) (HKD f Natural)
hkdCommitteeMinSizeL =
lens (asNaturalHKD @f @Word16 . (unTHKD . dppCommitteeMinSize)) $
\pp x -> pp {dppCommitteeMinSize = THKD (asBoundedIntegralHKD @f @Natural @Word16 x)}
lens (unTHKD . dppCommitteeMinSize) $ \pp x -> pp {dppCommitteeMinSize = THKD x}
hkdCommitteeMaxTermLengthL =
lens (unTHKD . dppCommitteeMaxTermLength) $ \pp x -> pp {dppCommitteeMaxTermLength = THKD x}
hkdGovActionLifetimeL =
Expand Down
Loading