Skip to content

Commit 1dc13a2

Browse files
authored
Merge pull request #4905 from IntersectMBO/lehins/move-gov-state-to-core
Move `EraGov` interface into `cardano-ledger-core`
2 parents cc7c6af + df8a61a commit 1dc13a2

File tree

17 files changed

+184
-161
lines changed

17 files changed

+184
-161
lines changed

eras/allegra/impl/src/Cardano/Ledger/Allegra/PParams.hs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ instance EraGov AllegraEra where
4444
type GovState AllegraEra = ShelleyGovState AllegraEra
4545
emptyGovState = emptyShelleyGovState
4646

47-
getProposedPPUpdates = Just . sgsCurProposals
48-
4947
curPParamsGovStateL = curPParamsShelleyGovStateL
5048

5149
prevPParamsGovStateL = prevPParamsShelleyGovStateL

eras/alonzo/impl/src/Cardano/Ledger/Alonzo/PParams.hs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,6 @@ instance EraGov AlonzoEra where
378378
type GovState AlonzoEra = ShelleyGovState AlonzoEra
379379
emptyGovState = emptyShelleyGovState
380380

381-
getProposedPPUpdates = Just . sgsCurProposals
382-
383381
curPParamsGovStateL = curPParamsShelleyGovStateL
384382

385383
prevPParamsGovStateL = prevPParamsShelleyGovStateL

eras/babbage/impl/src/Cardano/Ledger/Babbage/PParams.hs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,6 @@ instance EraGov BabbageEra where
264264
type GovState BabbageEra = ShelleyGovState BabbageEra
265265
emptyGovState = emptyShelleyGovState
266266

267-
getProposedPPUpdates = Just . sgsCurProposals
268-
269267
curPParamsGovStateL = curPParamsShelleyGovStateL
270268

271269
prevPParamsGovStateL = prevPParamsShelleyGovStateL

eras/mary/impl/src/Cardano/Ledger/Mary/PParams.hs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ instance EraGov MaryEra where
5151
type GovState MaryEra = ShelleyGovState MaryEra
5252
emptyGovState = emptyShelleyGovState
5353

54-
getProposedPPUpdates = Just . sgsCurProposals
55-
5654
curPParamsGovStateL = curPParamsShelleyGovStateL
5755

5856
prevPParamsGovStateL = prevPParamsShelleyGovStateL

eras/shelley/impl/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## 1.16.0.0
44

5+
* Remove `getProposedPPUpdates` as no longer relevant
6+
* Remove `proposalsL` and `futureProposalsL` as unused
57
* Remove redundant supercalss constraints for `ApplyBlock`
68
* Add `applyBlockEither`, `applyBlockEitherNoEvents`, `applyBlockNoValidaton`, `applyTickNoEvents`.
79
* Add `applyBlock` and `applyTick` to `ApplyBlock` type class.

eras/shelley/impl/src/Cardano/Ledger/Shelley.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ where
1111

1212
import Cardano.Ledger.Shelley.Era (ShelleyEra)
1313
import Cardano.Ledger.Shelley.Genesis ()
14+
import Cardano.Ledger.Shelley.Governance ()
1415
import Cardano.Ledger.Shelley.PParams ()
1516
import Cardano.Ledger.Shelley.Rules ()
1617
import Cardano.Ledger.Shelley.Scripts (nativeMultiSigTag)

eras/shelley/impl/src/Cardano/Ledger/Shelley/AdaPots.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import Cardano.Ledger.CertState (
3131
import Cardano.Ledger.Coin (Coin (..))
3232
import Cardano.Ledger.Compactible (fromCompact)
3333
import Cardano.Ledger.Core
34-
import Cardano.Ledger.Shelley.Governance (EraGov (..))
3534
import Cardano.Ledger.Shelley.LedgerState.Types (
3635
EpochState (..),
3736
LedgerState (..),

eras/shelley/impl/src/Cardano/Ledger/Shelley/Governance.hs

Lines changed: 5 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
{-# LANGUAGE DerivingStrategies #-}
44
{-# LANGUAGE DerivingVia #-}
55
{-# LANGUAGE FlexibleContexts #-}
6-
{-# LANGUAGE LambdaCase #-}
76
{-# LANGUAGE OverloadedStrings #-}
87
{-# LANGUAGE RecordWildCards #-}
98
{-# LANGUAGE ScopedTypeVariables #-}
109
{-# LANGUAGE StandaloneDeriving #-}
1110
{-# LANGUAGE TypeApplications #-}
12-
{-# LANGUAGE TypeFamilyDependencies #-}
11+
{-# LANGUAGE TypeFamilies #-}
1312
{-# LANGUAGE TypeOperators #-}
1413
{-# LANGUAGE UndecidableInstances #-}
15-
{-# LANGUAGE UndecidableSuperClasses #-}
14+
{-# OPTIONS_GHC -Wno-orphans #-}
1615

1716
module Cardano.Ledger.Shelley.Governance (
1817
EraGov (..),
@@ -24,14 +23,11 @@ module Cardano.Ledger.Shelley.Governance (
2423
nextEpochPParams,
2524
nextEpochUpdatedPParams,
2625
-- Lens
27-
proposalsL,
28-
futureProposalsL,
2926
curPParamsShelleyGovStateL,
3027
prevPParamsShelleyGovStateL,
3128
futurePParamsShelleyGovStateL,
3229
) where
3330

34-
import Cardano.Ledger.BaseTypes (StrictMaybe (..), fromSMaybe, maybeToStrictMaybe)
3531
import Cardano.Ledger.Binary (
3632
DecCBOR (decCBOR),
3733
DecShareCBOR (..),
@@ -42,11 +38,11 @@ import Cardano.Ledger.Binary (
4238
decNoShareCBOR,
4339
)
4440
import Cardano.Ledger.Binary.Coders (Decode (..), Encode (..), decode, encode, (!>), (<!))
45-
import Cardano.Ledger.CertState (Obligations)
4641
import Cardano.Ledger.Core
4742
import Cardano.Ledger.Credential (Credential)
4843
import Cardano.Ledger.Shelley.Era (ShelleyEra)
4944
import Cardano.Ledger.Shelley.PParams (ProposedPPUpdates, emptyPPPUpdates)
45+
import Cardano.Ledger.State
5046
import Control.DeepSeq (NFData (..))
5147
import Data.Aeson (
5248
KeyValue,
@@ -56,68 +52,13 @@ import Data.Aeson (
5652
(.=),
5753
)
5854
import Data.Default (Default (..))
59-
import Data.Kind (Type)
60-
import Data.Typeable
6155
import GHC.Generics (Generic)
62-
import Lens.Micro (Lens', lens, (^.))
63-
import NoThunks.Class (AllowThunk (..), NoThunks (..))
64-
65-
class
66-
( EraPParams era
67-
, Eq (GovState era)
68-
, Show (GovState era)
69-
, NoThunks (GovState era)
70-
, NFData (GovState era)
71-
, EncCBOR (GovState era)
72-
, DecCBOR (GovState era)
73-
, DecShareCBOR (GovState era)
74-
, Share (GovState era)
75-
~ ( Interns (Credential 'Staking)
76-
, Interns (KeyHash 'StakePool)
77-
, Interns (Credential 'DRepRole)
78-
, Interns (Credential 'HotCommitteeRole)
79-
)
80-
, ToCBOR (GovState era)
81-
, FromCBOR (GovState era)
82-
, Default (GovState era)
83-
, ToJSON (GovState era)
84-
) =>
85-
EraGov era
86-
where
87-
type GovState era = (r :: Type) | r -> era
88-
89-
-- | Construct empty governance state
90-
emptyGovState :: GovState era
91-
emptyGovState = def
92-
93-
-- | Returns `Nothing` for all eras starting with Conway, otherwise returns proposed
94-
-- pparams updates
95-
getProposedPPUpdates :: GovState era -> Maybe (ProposedPPUpdates era)
96-
getProposedPPUpdates _ = Nothing
97-
98-
-- | Lens for accessing current protocol parameters
99-
curPParamsGovStateL :: Lens' (GovState era) (PParams era)
100-
101-
-- | Lens for accessing the previous protocol parameters
102-
prevPParamsGovStateL :: Lens' (GovState era) (PParams era)
103-
104-
-- | Lens for accessing the future protocol parameters.
105-
--
106-
-- This lens will produce `DefinitePParamsUpdate` whenever we are absolutely sure that
107-
-- the new PParams will be updated. Which means there will be no chance of a
108-
-- `DefinitePParamsUpdate` value until we are past the point of no return, which is 2
109-
-- stability windows before the end of the epoch. This lens is mostly intended for
110-
-- ledger usage and `nextEpochUpdatedPParams` should be used instead whenever definite
111-
-- results are desired.
112-
futurePParamsGovStateL :: Lens' (GovState era) (FuturePParams era)
113-
114-
obligationGovState :: GovState era -> Obligations
56+
import Lens.Micro (Lens', lens)
57+
import NoThunks.Class (NoThunks (..))
11558

11659
instance EraGov ShelleyEra where
11760
type GovState ShelleyEra = ShelleyGovState ShelleyEra
11861

119-
getProposedPPUpdates = Just . sgsCurProposals
120-
12162
curPParamsGovStateL = curPParamsShelleyGovStateL
12263

12364
prevPParamsGovStateL = prevPParamsShelleyGovStateL
@@ -136,87 +77,6 @@ data ShelleyGovState era = ShelleyGovState
13677
}
13778
deriving (Generic)
13879

139-
data FuturePParams era
140-
= -- | This indicates that there is definitely not going to be an update to PParams
141-
-- expected at the next epoch boundary.
142-
NoPParamsUpdate
143-
| -- | This case specifies the PParams that will be adopted at the next epoch boundary.
144-
DefinitePParamsUpdate !(PParams era)
145-
| -- | With this case there is no guarantee that these will be the new PParams, users
146-
-- should not rely on this value to be computed efficiently and should use
147-
-- `nextEpochPParams` instead. The field is lazy on purpose, since we truly need to
148-
-- compute this field only towards the end of the epoch, which is done by
149-
-- `solidifyFuturePParams` two stability windows before the end of the epoch.
150-
PotentialPParamsUpdate (Maybe (PParams era))
151-
deriving (Generic)
152-
153-
instance Default (FuturePParams era) where
154-
def = NoPParamsUpdate
155-
156-
instance ToJSON (PParams era) => ToJSON (FuturePParams era)
157-
158-
-- | Return new PParams only when it is known that there was an update proposed and it is
159-
-- guaranteed to be applied
160-
knownFuturePParams :: FuturePParams era -> Maybe (PParams era)
161-
knownFuturePParams = \case
162-
DefinitePParamsUpdate pp -> Just pp
163-
_ -> Nothing
164-
165-
-- | This function is guaranteed to produce `PParams` that will be adopted at the next
166-
-- epoch boundary, whenever this function is applied to the `GovState` that was produced
167-
-- by ledger at any point that is two stability windows before the end of the epoch. If
168-
-- you need to know if there were actual changes to those PParams then use
169-
-- `nextEpochUpdatedPParams` instead.
170-
nextEpochPParams :: EraGov era => GovState era -> PParams era
171-
nextEpochPParams govState =
172-
fromSMaybe (govState ^. curPParamsGovStateL) $ nextEpochUpdatedPParams govState
173-
174-
-- | This function is guaranteed to return updated PParams when it is called during the
175-
-- last two stability windows of the epoch and there were proposals to update PParams that
176-
-- all relevant parties reached consensus on. In other words whenever there is a definite
177-
-- update to PParams coming on the epoch boundary those PParams will be returned,
178-
-- otherwise it will return `Nothing`. This function is inexpensive and can be invoked at
179-
-- any time without danger of forcing some suspended computation.
180-
nextEpochUpdatedPParams :: EraGov era => GovState era -> StrictMaybe (PParams era)
181-
nextEpochUpdatedPParams govState =
182-
maybeToStrictMaybe $ knownFuturePParams (govState ^. futurePParamsGovStateL)
183-
184-
solidifyFuturePParams :: FuturePParams era -> FuturePParams era
185-
solidifyFuturePParams = \case
186-
-- Here we convert a potential to a definite update:
187-
PotentialPParamsUpdate Nothing -> NoPParamsUpdate
188-
PotentialPParamsUpdate (Just pp) -> DefinitePParamsUpdate pp
189-
fpp -> fpp
190-
191-
deriving stock instance Eq (PParams era) => Eq (FuturePParams era)
192-
deriving stock instance Show (PParams era) => Show (FuturePParams era)
193-
deriving via AllowThunk (FuturePParams era) instance NoThunks (FuturePParams era)
194-
instance (Typeable era, EncCBOR (PParams era)) => EncCBOR (FuturePParams era) where
195-
encCBOR =
196-
encode . \case
197-
NoPParamsUpdate -> Sum NoPParamsUpdate 0
198-
DefinitePParamsUpdate pp -> Sum DefinitePParamsUpdate 1 !> To pp
199-
PotentialPParamsUpdate pp -> Sum PotentialPParamsUpdate 2 !> To pp
200-
201-
instance (Typeable era, DecCBOR (PParams era)) => DecCBOR (FuturePParams era) where
202-
decCBOR = decode . Summands "FuturePParams" $ \case
203-
0 -> SumD NoPParamsUpdate
204-
1 -> SumD DefinitePParamsUpdate <! From
205-
2 -> SumD PotentialPParamsUpdate <! From
206-
k -> Invalid k
207-
208-
instance NFData (PParams era) => NFData (FuturePParams era) where
209-
rnf = \case
210-
NoPParamsUpdate -> ()
211-
PotentialPParamsUpdate pp -> rnf pp
212-
DefinitePParamsUpdate pp -> rnf pp
213-
214-
proposalsL :: Lens' (ShelleyGovState era) (ProposedPPUpdates era)
215-
proposalsL = lens sgsCurProposals (\sgov x -> sgov {sgsCurProposals = x})
216-
217-
futureProposalsL :: Lens' (ShelleyGovState era) (ProposedPPUpdates era)
218-
futureProposalsL = lens sgsFutureProposals (\sgov x -> sgov {sgsFutureProposals = x})
219-
22080
curPParamsShelleyGovStateL :: Lens' (ShelleyGovState era) (PParams era)
22181
curPParamsShelleyGovStateL = lens sgsCurPParams (\sps x -> sps {sgsCurPParams = x})
22282

eras/shelley/impl/src/Cardano/Ledger/Shelley/LedgerState/IncrementalStake.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ import Cardano.Ledger.Credential (
4848
Credential (..),
4949
StakeReference (StakeRefBase, StakeRefPtr),
5050
)
51-
import Cardano.Ledger.Shelley.Governance (EraGov (GovState))
5251
import qualified Cardano.Ledger.Shelley.HardForks as HardForks
5352
import Cardano.Ledger.Shelley.LedgerState.Types
5453
import Cardano.Ledger.Shelley.RewardUpdate (RewardUpdate (..))

eras/shelley/impl/src/Cardano/Ledger/Shelley/LedgerState/PulsingReward.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ import Cardano.Ledger.Coin (
4545
)
4646
import Cardano.Ledger.Core
4747
import Cardano.Ledger.PoolParams (PoolParams (..))
48-
import Cardano.Ledger.Shelley.Governance (EraGov)
4948
import qualified Cardano.Ledger.Shelley.HardForks as HardForks
5049
import Cardano.Ledger.Shelley.LedgerState.Types
5150
import Cardano.Ledger.Shelley.PoolRank (

0 commit comments

Comments
 (0)