Skip to content

Commit

Permalink
Reimplement DRep threshold computation
Browse files Browse the repository at this point in the history
This is an alternative approach to figuring out thresholds. Original
approach was buggy and did not work correctly, which resulted in #3835
  • Loading branch information
lehins committed Nov 1, 2023
1 parent 6661f86 commit 7caefa5
Show file tree
Hide file tree
Showing 8 changed files with 498 additions and 445 deletions.
2 changes: 2 additions & 0 deletions eras/alonzo/impl/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## 1.5.1.0

* Swap the order of arguments for `updateCostModels`

### `testlib`

* Provide CDDL spec files with `readAlonzoCddlFileNames` and `readAlonzoCddlFiles` from
Expand Down
8 changes: 4 additions & 4 deletions eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Scripts.hs
Original file line number Diff line number Diff line change
Expand Up @@ -547,13 +547,13 @@ data CostModels = CostModels
emptyCostModels :: CostModels
emptyCostModels = CostModels mempty mempty mempty

-- | Updates the first @CostModels@ with the second one so that only the
-- cost models that are present in the second one get updated while all the
-- | Updates the second @CostModels@ with the first one so that only the
-- cost models that are present in the first one get updated while all the
-- others stay unchanged
updateCostModels :: CostModels -> CostModels -> CostModels
updateCostModels
(CostModels oldValid oldErrors oldUnk)
(CostModels newValid newErrors newUnk) =
(CostModels newValid newErrors newUnk)
(CostModels oldValid oldErrors oldUnk) =
CostModels
(Map.union newValid oldValid)
(Map.union newErrors oldErrors)
Expand Down
12 changes: 6 additions & 6 deletions eras/conway/impl/src/Cardano/Ledger/Conway/Governance.hs
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,9 @@ module Cardano.Ledger.Conway.Governance (
psDRepDistrL,
psDRepStateL,
RunConwayRatify (..),

-- * Exported for testing
pparamsUpdateThreshold
pparamsUpdateThreshold,
) where

import Cardano.Ledger.BaseTypes (
Expand Down Expand Up @@ -188,11 +189,10 @@ import Cardano.Ledger.Conway.Governance.Snapshots (
snapshotRemoveIds,
)
import Cardano.Ledger.Conway.PParams (
ConwayEraPParams,
ConwayEraPParams (..),
DRepVotingThresholds (..),
PParamGroup (..),
PPGroup (..),
PoolVotingThresholds (..),
modifiedGroups,
ppCommitteeMinSizeL,
ppDRepVotingThresholdsL,
ppPoolVotingThresholdsL,
Expand Down Expand Up @@ -690,14 +690,14 @@ pparamsUpdateThreshold ::
pparamsUpdateThreshold pp ppu =
let thresholdLens = \case
NetworkGroup -> dvtPPNetworkGroupL
GovernanceGroup -> dvtPPGovGroupL
GovGroup -> dvtPPGovGroupL
TechnicalGroup -> dvtPPTechnicalGroupL
EconomicGroup -> dvtPPEconomicGroupL
lookupGroupThreshold grp =
pp ^. ppDRepVotingThresholdsL . thresholdLens grp
in Set.foldr' max minBound $
Set.map lookupGroupThreshold $
modifiedGroups @era ppu
modifiedPPGroups @era ppu

data VotingThreshold
= -- | This is the actual threshold. It is lazy, because upon proposal we only care if
Expand Down
Loading

0 comments on commit 7caefa5

Please sign in to comment.