Skip to content

Commit

Permalink
Introduce futurePParamsGovStateL:
Browse files Browse the repository at this point in the history
And `futurePParamsShelleyGovStateL` and `sgsFuturePParams`

For now none of these are functional they are just placeholders
  • Loading branch information
lehins committed Apr 25, 2024
1 parent a2d7a81 commit b0a86eb
Show file tree
Hide file tree
Showing 14 changed files with 67 additions and 42 deletions.
9 changes: 3 additions & 6 deletions eras/allegra/impl/src/Cardano/Ledger/Allegra/PParams.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,14 @@ instance Crypto c => EraPParams (AllegraEra c) where

instance Crypto c => EraGov (AllegraEra c) where
type GovState (AllegraEra c) = ShelleyGovState (AllegraEra c)
emptyGovState =
ShelleyGovState
emptyPPPUpdates
emptyPPPUpdates
emptyPParams
emptyPParams
emptyGovState = emptyShelleyGovState

getProposedPPUpdates = Just . sgsCurProposals

curPParamsGovStateL = curPParamsShelleyGovStateL

prevPParamsGovStateL = prevPParamsShelleyGovStateL

futurePParamsGovStateL = futurePParamsShelleyGovStateL

obligationGovState = const mempty
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ instance Crypto c => TranslateEra (AllegraEra c) ShelleyGovState where
, sgsFutureProposals = translateEra' ctxt $ sgsFutureProposals ps
, sgsCurPParams = translateEra' ctxt $ sgsCurPParams ps
, sgsPrevPParams = translateEra' ctxt $ sgsPrevPParams ps
, sgsFuturePParams = translateEra' ctxt <$> sgsFuturePParams ps
}

instance Crypto c => TranslateEra (AllegraEra c) ShelleyTxOut where
Expand Down
10 changes: 3 additions & 7 deletions eras/alonzo/impl/src/Cardano/Ledger/Alonzo/PParams.hs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ import Cardano.Ledger.Plutus.ExUnits (
import Cardano.Ledger.Plutus.Language (Language (..))
import Cardano.Ledger.Shelley.PParams (
ShelleyPParams (..),
emptyPPPUpdates,
shelleyCommonPParamsHKDPairs,
shelleyCommonPParamsHKDPairsV6,
shelleyCommonPParamsHKDPairsV8,
Expand Down Expand Up @@ -378,19 +377,16 @@ instance Crypto c => AlonzoEraPParams (AlonzoEra c) where

instance Crypto c => EraGov (AlonzoEra c) where
type GovState (AlonzoEra c) = ShelleyGovState (AlonzoEra c)
emptyGovState =
ShelleyGovState
emptyPPPUpdates
emptyPPPUpdates
emptyPParams
emptyPParams
emptyGovState = emptyShelleyGovState

getProposedPPUpdates = Just . sgsCurProposals

curPParamsGovStateL = curPParamsShelleyGovStateL

prevPParamsGovStateL = prevPParamsShelleyGovStateL

futurePParamsGovStateL = futurePParamsShelleyGovStateL

obligationGovState = const mempty

instance Era era => EncCBOR (AlonzoPParams Identity era) where
Expand Down
1 change: 1 addition & 0 deletions eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Translation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ instance Crypto c => TranslateEra (AlonzoEra c) ShelleyGovState where
, sgsFutureProposals = translateEra' ctxt $ sgsFutureProposals ps
, sgsCurPParams = translateEra' ctxt $ sgsCurPParams ps
, sgsPrevPParams = translateEra' ctxt $ sgsPrevPParams ps
, sgsFuturePParams = translateEra' ctxt <$> sgsFuturePParams ps
}

instance Crypto c => TranslateEra (AlonzoEra c) ProposedPPUpdates where
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,6 @@ instance Era era => Arbitrary (AlonzoContextError era) where

instance
( EraTxOut era
, Era era
, Arbitrary (Value era)
, Arbitrary (TxOut era)
, Arbitrary (PredicateFailure (EraRule "UTXOS" era))
Expand Down
11 changes: 4 additions & 7 deletions eras/babbage/impl/src/Cardano/Ledger/Babbage/PParams.hs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ import Cardano.Ledger.Core (EraPParams (..))
import Cardano.Ledger.Crypto (Crypto)
import Cardano.Ledger.HKD (HKD, HKDFunctor (..))
import Cardano.Ledger.Orphans ()
import Cardano.Ledger.Shelley.PParams (emptyPPPUpdates, shelleyCommonPParamsHKDPairsV8)
import Cardano.Ledger.Shelley.PParams (shelleyCommonPParamsHKDPairsV8)
import Control.DeepSeq (NFData)
import Data.Aeson as Aeson (
FromJSON (..),
Expand Down Expand Up @@ -263,19 +263,16 @@ instance Crypto c => BabbageEraPParams (BabbageEra c) where

instance Crypto c => EraGov (BabbageEra c) where
type GovState (BabbageEra c) = ShelleyGovState (BabbageEra c)
emptyGovState =
ShelleyGovState
emptyPPPUpdates
emptyPPPUpdates
emptyPParams
emptyPParams
emptyGovState = emptyShelleyGovState

getProposedPPUpdates = Just . sgsCurProposals

curPParamsGovStateL = curPParamsShelleyGovStateL

prevPParamsGovStateL = prevPParamsShelleyGovStateL

futurePParamsGovStateL = futurePParamsShelleyGovStateL

obligationGovState = const mempty

instance Era era => EncCBOR (BabbagePParams Identity era) where
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ instance Crypto c => TranslateEra (BabbageEra c) ShelleyGovState where
, sgsFutureProposals = translateEra' ctxt $ sgsFutureProposals ps
, sgsCurPParams = translateEra' ctxt $ sgsCurPParams ps
, sgsPrevPParams = translateEra' ctxt $ sgsPrevPParams ps
, sgsFuturePParams = translateEra' ctxt <$> sgsFuturePParams ps
}

instance Crypto c => TranslateEra (BabbageEra c) ProposedPPUpdates where
Expand Down
11 changes: 5 additions & 6 deletions eras/mary/impl/src/Cardano/Ledger/Mary/PParams.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import Cardano.Ledger.Shelley.Governance (
EraGov (..),
ShelleyGovState (..),
curPParamsShelleyGovStateL,
emptyShelleyGovState,
futurePParamsShelleyGovStateL,
prevPParamsShelleyGovStateL,
)
import Cardano.Ledger.Shelley.PParams
Expand Down Expand Up @@ -48,17 +50,14 @@ instance Crypto c => EraPParams (MaryEra c) where

instance Crypto c => EraGov (MaryEra c) where
type GovState (MaryEra c) = ShelleyGovState (MaryEra c)
emptyGovState =
ShelleyGovState
emptyPPPUpdates
emptyPPPUpdates
emptyPParams
emptyPParams
emptyGovState = emptyShelleyGovState

getProposedPPUpdates = Just . sgsCurProposals

curPParamsGovStateL = curPParamsShelleyGovStateL

prevPParamsGovStateL = prevPParamsShelleyGovStateL

futurePParamsGovStateL = futurePParamsShelleyGovStateL

obligationGovState = const mempty
1 change: 1 addition & 0 deletions eras/mary/impl/src/Cardano/Ledger/Mary/Translation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ instance Crypto c => TranslateEra (MaryEra c) ShelleyGovState where
, sgsFutureProposals = translateEra' ctxt $ sgsFutureProposals ps
, sgsCurPParams = translateEra' ctxt $ sgsCurPParams ps
, sgsPrevPParams = translateEra' ctxt $ sgsPrevPParams ps
, sgsFuturePParams = translateEra' ctxt <$> sgsFuturePParams ps
}

instance Crypto c => TranslateEra (MaryEra c) UTxOState where
Expand Down
2 changes: 1 addition & 1 deletion eras/shelley/impl/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## 1.10.1.0

*
* Introduce `futurePParamsGovStateL`, `futurePParamsShelleyGovStateL` and `sgsFuturePParams`

### `testlib`

Expand Down
35 changes: 28 additions & 7 deletions eras/shelley/impl/src/Cardano/Ledger/Shelley/Governance.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
module Cardano.Ledger.Shelley.Governance (
EraGov (..),
ShelleyGovState (..),
emptyShelleyGovState,
-- Lens
proposalsL,
futureProposalsL,
curPParamsShelleyGovStateL,
prevPParamsShelleyGovStateL,
futurePParamsShelleyGovStateL,

-- * Deprecations
proposals,
Expand Down Expand Up @@ -87,6 +89,9 @@ class
-- | Lens for accessing the previous protocol parameters
prevPParamsGovStateL :: Lens' (GovState era) (PParams era)

-- | Lens for accessing the previous protocol parameters
futurePParamsGovStateL :: Lens' (GovState era) (Maybe (PParams era))

obligationGovState :: GovState era -> Obligations

instance Crypto c => EraGov (ShelleyEra c) where
Expand All @@ -98,13 +103,19 @@ instance Crypto c => EraGov (ShelleyEra c) where

prevPParamsGovStateL = prevPParamsShelleyGovStateL

futurePParamsGovStateL = futurePParamsShelleyGovStateL

obligationGovState = const mempty -- No GovState obigations in ShelleyEra

data ShelleyGovState era = ShelleyGovState
{ sgsCurProposals :: !(ProposedPPUpdates era)
, sgsFutureProposals :: !(ProposedPPUpdates era)
, sgsCurPParams :: !(PParams era)
, sgsPrevPParams :: !(PParams era)
, sgsFuturePParams :: Maybe (PParams era)
-- ^ Prediction of any parameter changes that might happen on the epoch boundary. The
-- field is lazy on purpose, since we only need to compute this field only towards the
-- end of the epoch.
}
deriving (Generic)

Expand Down Expand Up @@ -133,6 +144,10 @@ curPParamsShelleyGovStateL = lens sgsCurPParams (\sps x -> sps {sgsCurPParams =
prevPParamsShelleyGovStateL :: Lens' (ShelleyGovState era) (PParams era)
prevPParamsShelleyGovStateL = lens sgsPrevPParams (\sps x -> sps {sgsPrevPParams = x})

futurePParamsShelleyGovStateL :: Lens' (ShelleyGovState era) (Maybe (PParams era))
futurePParamsShelleyGovStateL =
lens sgsFuturePParams (\sps x -> sps {sgsFuturePParams = x})

deriving instance
( Show (PParamsUpdate era)
, Show (PParams era)
Expand Down Expand Up @@ -164,13 +179,14 @@ instance
) =>
EncCBOR (ShelleyGovState era)
where
encCBOR (ShelleyGovState ppup fppup pp ppp) =
encCBOR (ShelleyGovState ppup fppup pp ppp fpp) =
encode $
Rec ShelleyGovState
!> To ppup
!> To fppup
!> To pp
!> To ppp
!> To fpp

instance
( Era era
Expand All @@ -186,6 +202,7 @@ instance
<! From
<! From
<! From
<! From

instance
( Era era
Expand Down Expand Up @@ -227,9 +244,13 @@ toPPUPStatePairs ShelleyGovState {..} =
]

instance EraPParams era => Default (ShelleyGovState era) where
def =
ShelleyGovState
emptyPPPUpdates
emptyPPPUpdates
emptyPParams
emptyPParams
def = emptyShelleyGovState

emptyShelleyGovState :: EraPParams era => ShelleyGovState era
emptyShelleyGovState =
ShelleyGovState
emptyPPPUpdates
emptyPPPUpdates
emptyPParams
emptyPParams
Nothing
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ instance
) =>
Arbitrary (ShelleyGovState era)
where
arbitrary = ShelleyGovState <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary
arbitrary = ShelleyGovState <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary
shrink = genericShrink

------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,9 @@ futurePParamProposals p = Var (pV p "futurePParamProposals" (MapR GenHashR (PPar
currPParams :: Era era => Proof era -> Term era (PParamsF era)
currPParams p = Var (pV p "currPParams" (PParamsR p) No)

futurePParams :: Era era => Proof era -> Term era (Maybe (PParamsF era))
futurePParams p = Var (pV p "futurePParams" (MaybeR (PParamsR p)) No)

prevPParams :: Gov.EraGov era => Proof era -> Term era (PParamsF era)
prevPParams p =
Var (V "prevPParams" (PParamsR p) (Yes NewEpochStateR (nesEsL . prevPParamsEpochStateL . ppFL p)))
Expand All @@ -424,13 +427,15 @@ ppupStateT p =
:$ Lensed (futurePParamProposals p) (futureProposalsL . proposedMapL p)
:$ Lensed (currPParams p) (Gov.curPParamsGovStateL . pparamsFL p)
:$ Lensed (prevPParams p) (Gov.curPParamsGovStateL . pparamsFL p)
:$ Lensed (futurePParams p) (Gov.futurePParamsGovStateL . pparamsMaybeFL p)
where
ppupfun x y (PParamsF _ pp) (PParamsF _ prev) =
ShelleyGovState
(ProposedPPUpdates (Map.map unPParamsUpdate x))
(ProposedPPUpdates (Map.map unPParamsUpdate y))
pp
prev
. fmap (\(PParamsF _ fpp) -> fpp)

govL :: Lens' (GovState era) (Gov.GovState era)
govL = lens f g
Expand Down Expand Up @@ -2139,6 +2144,12 @@ constitutionChildren = Var $ V "constitutionChildren" (SetR GovActionIdR) No
pparamsFL :: Proof era -> Lens' (PParams era) (PParamsF era)
pparamsFL p = lens (PParamsF p) (\_ (PParamsF _ x) -> x)

pparamsMaybeFL :: Proof era -> Lens' (Maybe (PParams era)) (Maybe (PParamsF era))
pparamsMaybeFL p =
lens
(fmap (PParamsF p))
(\_ -> fmap (\(PParamsF _ x) -> x))

smCommL :: Lens' (StrictMaybe (Committee era)) (Committee era)
smCommL = lens getter (\_ t -> SJust t)
where
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2805,14 +2805,15 @@ pcGovState p x = case whichGovState p of
(GovStateConwayToConway) -> unReflect pcConwayGovState p x

pcShelleyGovState :: Proof era -> ShelleyGovState era -> PDoc
pcShelleyGovState p (ShelleyGovState _proposal _futproposal pp prevpp) =
pcShelleyGovState p (ShelleyGovState _proposal _futproposal pp prevpp mfuturepp) =
ppRecord
"ShelleyGovState"
[ ("proposals", ppString "(Proposals ...)")
, ("futureProposals", ppString "(Proposals ...)")
, ("pparams", pcPParamsSynopsis p pp)
, ("prevParams", pcPParamsSynopsis p prevpp)
]
$ [ ("proposals", ppString "(Proposals ...)")
, ("futureProposals", ppString "(Proposals ...)")
, ("pparams", pcPParamsSynopsis p pp)
, ("prevParams", pcPParamsSynopsis p prevpp)
]
++ [("futureParams", pcPParamsSynopsis p futurepp) | Just futurepp <- [mfuturepp]]

instance Reflect era => PrettyA (ShelleyGovState era) where
prettyA = pcShelleyGovState reify
Expand Down

0 comments on commit b0a86eb

Please sign in to comment.