Skip to content

Commit

Permalink
Rename ProposalsSnapshot to Proposals (#3859)
Browse files Browse the repository at this point in the history
* Rename module Governance.Snapshots to Governance.Proposals.
* Rename all functions related to the proposals data-type.
  • Loading branch information
aniketd authored Nov 10, 2023
1 parent 5c1c24b commit f7f6479
Show file tree
Hide file tree
Showing 18 changed files with 159 additions and 156 deletions.
3 changes: 3 additions & 0 deletions eras/conway/impl/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## 1.11.0.0

* Rename data-type `ProposalsSnapshot` to `Proposals`. #3859
* Rename module `Governance.Snapshots` to `Governance.Proposals`.
* Rename all the functions related to the data-type.
* Switch to using `OMap` for `ProposalsSnapshot` #3791
* Add `VotingOnExpiredGovAction` predicate failure in `GOV` #3825
* Rename `modifiedGroups` -> `modifiedPPGroups` and move into `ConwayEraPParams`
Expand Down
2 changes: 1 addition & 1 deletion eras/conway/impl/cardano-ledger-conway.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ library
other-modules:
Cardano.Ledger.Conway.Era
Cardano.Ledger.Conway.Governance.Procedures
Cardano.Ledger.Conway.Governance.Snapshots
Cardano.Ledger.Conway.Governance.Proposals
Cardano.Ledger.Conway.Rules.Cert
Cardano.Ledger.Conway.Rules.Deleg
Cardano.Ledger.Conway.Rules.Pool
Expand Down
46 changes: 23 additions & 23 deletions eras/conway/impl/src/Cardano/Ledger/Conway/Governance.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ module Cardano.Ledger.Conway.Governance (
isStakePoolVotingAllowed,
isDRepVotingAllowed,
isCommitteeVotingAllowed,
ProposalsSnapshot,
snapshotInsertGovAction,
snapshotActions,
snapshotAddVote,
snapshotIds,
snapshotRemoveIds,
snapshotLookupId,
snapshotGovActionStates,
Proposals,
proposalsInsertGovAction,
proposalsActions,
proposalsAddVote,
proposalsIds,
proposalsRemoveIds,
proposalsLookupId,
proposalsGovActionStates,
fromGovActionStateSeq,
isConsistent_,
-- Lenses
Expand Down Expand Up @@ -175,17 +175,17 @@ import Cardano.Ledger.Conway.Governance.Procedures (
govActionIdToText,
indexedGovProps,
)
import Cardano.Ledger.Conway.Governance.Snapshots (
ProposalsSnapshot,
import Cardano.Ledger.Conway.Governance.Proposals (
Proposals,
fromGovActionStateSeq,
isConsistent_,
snapshotActions,
snapshotAddVote,
snapshotGovActionStates,
snapshotIds,
snapshotInsertGovAction,
snapshotLookupId,
snapshotRemoveIds,
proposalsActions,
proposalsAddVote,
proposalsGovActionStates,
proposalsIds,
proposalsInsertGovAction,
proposalsLookupId,
proposalsRemoveIds,
)
import Cardano.Ledger.Conway.PParams (
ConwayEraPParams (..),
Expand Down Expand Up @@ -563,7 +563,7 @@ toRatifyStatePairs cg@(RatifyState _ _ _) =

-- =============================================
data ConwayGovState era = ConwayGovState
{ cgProposals :: !(ProposalsSnapshot era) -- TODO rename 'ProposalsSnapshot' to 'Proposals'
{ cgProposals :: !(Proposals era)
, cgEnactState :: !(EnactState era)
, cgDRepPulsingState :: !(DRepPulsingState era)
-- ^ The 'cgDRepPulsingState' field is a pulser that incrementally computes the stake distribution of the DReps
Expand All @@ -576,7 +576,7 @@ data ConwayGovState era = ConwayGovState

deriving instance EraPParams era => Eq (ConwayGovState era)

cgProposalsL :: Lens' (ConwayGovState era) (ProposalsSnapshot era)
cgProposalsL :: Lens' (ConwayGovState era) (Proposals era)
cgProposalsL = lens cgProposals (\x y -> x {cgProposals = y})

cgEnactStateL :: Lens' (ConwayGovState era) (EnactState era)
Expand Down Expand Up @@ -665,7 +665,7 @@ instance EraPParams (ConwayEra c) => EraGov (ConwayEra c) where

obligationGovState st =
Obligations
{ oblProposal = foldMap' gasDeposit $ snapshotActions (st ^. cgProposalsL)
{ oblProposal = foldMap' gasDeposit $ proposalsActions (st ^. cgProposalsL)
, oblDRep = Coin 0
, oblStake = Coin 0
, oblPool = Coin 0
Expand All @@ -675,7 +675,7 @@ instance EraPParams (ConwayEra c) => EraGov (ConwayEra c) where

class EraGov era => ConwayEraGov era where
constitutionGovStateL :: Lens' (GovState era) (Constitution era)
proposalsGovStateL :: Lens' (GovState era) (ProposalsSnapshot era)
proposalsGovStateL :: Lens' (GovState era) (Proposals era)
drepPulsingStateGovStateL :: Lens' (GovState era) (DRepPulsingState era)
enactStateGovStateL :: Lens' (GovState era) (EnactState era)

Expand Down Expand Up @@ -944,7 +944,7 @@ data DRepPulser era (m :: Type -> Type) ans where
, dpEnactState :: !(EnactState era)
-- ^ Snapshot of the EnactState, Used to build the Env of the RATIFY rule
, dpProposals :: !(StrictSeq (GovActionState era))
-- ^ Snap shot of the (ProposalsSnapshot era) isomorphic to (StrictSeq (GovActionState era))
-- ^ Snap shot of the (Proposals era) isomorphic to (StrictSeq (GovActionState era))
-- Used to build the Signal of the RATIFY rule
, dpGlobals :: !Globals
} ->
Expand Down Expand Up @@ -1175,7 +1175,7 @@ setFreshDRepPulsingState epochNo stakePoolDistr epochState = do
(cgEnactState govState)
{ ensTreasury = epochState ^. epochStateTreasuryL
}
, dpProposals = snapshotActions (govState ^. cgProposalsL)
, dpProposals = proposalsActions (govState ^. cgProposalsL)
, dpGlobals = globals
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE UndecidableInstances #-}

module Cardano.Ledger.Conway.Governance.Snapshots (
ProposalsSnapshot,
snapshotIds,
snapshotAddVote,
snapshotInsertGovAction,
snapshotActions,
snapshotRemoveIds,
snapshotLookupId,
module Cardano.Ledger.Conway.Governance.Proposals (
Proposals,
proposalsIds,
proposalsAddVote,
proposalsInsertGovAction,
proposalsActions,
proposalsRemoveIds,
proposalsLookupId,
fromGovActionStateSeq,
snapshotGovActionStates,
proposalsGovActionStates,
-- Testing
isConsistent_,
) where
Expand Down Expand Up @@ -44,70 +44,70 @@ import GHC.Generics (Generic)
import Lens.Micro (Lens', (%~))
import NoThunks.Class (NoThunks)

newtype ProposalsSnapshot era
= ProposalsSnapshot
newtype Proposals era
= Proposals
(OMap.OMap (GovActionId (EraCrypto era)) (GovActionState era))
deriving newtype (Show, Eq)
deriving stock (Generic)

instance EraPParams era => ToExpr (ProposalsSnapshot era)
instance EraPParams era => ToExpr (Proposals era)

instance EraPParams era => ToJSON (ProposalsSnapshot era)
instance EraPParams era => ToJSON (Proposals era)

instance EraPParams era => NFData (ProposalsSnapshot era)
instance EraPParams era => NFData (Proposals era)

instance EraPParams era => NoThunks (ProposalsSnapshot era)
instance EraPParams era => NoThunks (Proposals era)

instance Default (ProposalsSnapshot era) where
def = ProposalsSnapshot def
instance Default (Proposals era) where
def = Proposals def

instance EraPParams era => EncCBOR (ProposalsSnapshot era) where
encCBOR = encCBOR . snapshotActions
instance EraPParams era => EncCBOR (Proposals era) where
encCBOR = encCBOR . proposalsActions

instance EraPParams era => DecCBOR (ProposalsSnapshot era) where
instance EraPParams era => DecCBOR (Proposals era) where
decCBOR = fromGovActionStateSeq <$> decCBOR

-- TODO: Implement Sharing: https://github.com/input-output-hk/cardano-ledger/issues/3486
instance EraPParams era => DecShareCBOR (ProposalsSnapshot era) where
instance EraPParams era => DecShareCBOR (Proposals era) where
decShareCBOR _ = fromGovActionStateSeq <$> decCBOR

-- | Insert a `GovActionState`, overwriting an entry of it if the
-- corresponding `GovActionId` already exists.
snapshotInsertGovAction ::
proposalsInsertGovAction ::
GovActionState era ->
ProposalsSnapshot era ->
ProposalsSnapshot era
snapshotInsertGovAction gas (ProposalsSnapshot omap) =
ProposalsSnapshot (omap OMap.||> gas)
Proposals era ->
Proposals era
proposalsInsertGovAction gas (Proposals omap) =
Proposals (omap OMap.||> gas)

-- | Get the sequence of `GovActionState`s
snapshotActions ::
ProposalsSnapshot era ->
proposalsActions ::
Proposals era ->
StrictSeq (GovActionState era)
snapshotActions (ProposalsSnapshot omap) = OMap.toStrictSeq omap
proposalsActions (Proposals omap) = OMap.toStrictSeq omap

-- | Get the sequence of `GovActionId`s
snapshotIds ::
ProposalsSnapshot era ->
proposalsIds ::
Proposals era ->
StrictSeq (GovActionId (EraCrypto era))
snapshotIds (ProposalsSnapshot omap) = OMap.toStrictSeqOKeys omap
proposalsIds (Proposals omap) = OMap.toStrictSeqOKeys omap

-- | Get the unordered map of `GovActionId`s and `GovActionState`s
snapshotGovActionStates ::
ProposalsSnapshot era ->
proposalsGovActionStates ::
Proposals era ->
Map (GovActionId (EraCrypto era)) (GovActionState era)
snapshotGovActionStates (ProposalsSnapshot omap) = OMap.toMap omap
proposalsGovActionStates (Proposals omap) = OMap.toMap omap

-- | Add a vote to an existing `GovActionState` This is a no-op if the .
-- provided `GovActionId` does not already exist .
snapshotAddVote ::
proposalsAddVote ::
Voter (EraCrypto era) ->
Vote ->
GovActionId (EraCrypto era) ->
ProposalsSnapshot era ->
ProposalsSnapshot era
snapshotAddVote voter vote gai (ProposalsSnapshot omap) =
ProposalsSnapshot $ OMap.adjust updateVote gai omap
Proposals era ->
Proposals era
proposalsAddVote voter vote gai (Proposals omap) =
Proposals $ OMap.adjust updateVote gai omap
where
insertVote ::
Ord k =>
Expand All @@ -122,28 +122,28 @@ snapshotAddVote voter vote gai (ProposalsSnapshot omap) =
CommitteeVoter c -> insertVote gasCommitteeVotesL c

-- | Extract `GovActionState`s for the given set of `GovActionId`s from the `Proposals`
snapshotRemoveIds ::
proposalsRemoveIds ::
Set (GovActionId (EraCrypto era)) ->
ProposalsSnapshot era ->
(ProposalsSnapshot era, Map.Map (GovActionId (EraCrypto era)) (GovActionState era))
snapshotRemoveIds gais (ProposalsSnapshot omap) =
Proposals era ->
(Proposals era, Map.Map (GovActionId (EraCrypto era)) (GovActionState era))
proposalsRemoveIds gais (Proposals omap) =
let (retained, removed) = OMap.extractKeys gais omap
in (ProposalsSnapshot retained, removed)
in (Proposals retained, removed)

snapshotLookupId ::
proposalsLookupId ::
GovActionId (EraCrypto era) ->
ProposalsSnapshot era ->
Proposals era ->
Maybe (GovActionState era)
snapshotLookupId gai (ProposalsSnapshot omap) = OMap.lookup gai omap
proposalsLookupId gai (Proposals omap) = OMap.lookup gai omap

-- | Converts a sequence of `GovActionState`s to a `ProposalsSnapshot`.
-- | Converts a sequence of `GovActionState`s to a `Proposals`.
--
-- /Warning/ - This function expects `GovActionState`'s to have unique
-- `GovActionId`s, because duplicate Ids will result in `GovActionStates`
-- to be dropped.
fromGovActionStateSeq :: StrictSeq (GovActionState era) -> ProposalsSnapshot era
fromGovActionStateSeq = ProposalsSnapshot . OMap.fromFoldable
fromGovActionStateSeq :: StrictSeq (GovActionState era) -> Proposals era
fromGovActionStateSeq = Proposals . OMap.fromFoldable

-- | Internal function for checking if the invariants are maintained
isConsistent_ :: ProposalsSnapshot era -> Bool
isConsistent_ (ProposalsSnapshot omap) = OMap.invariantHolds' omap
isConsistent_ :: Proposals era -> Bool
isConsistent_ (Proposals omap) = OMap.invariantHolds' omap
4 changes: 2 additions & 2 deletions eras/conway/impl/src/Cardano/Ledger/Conway/Rules/Epoch.hs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import Cardano.Ledger.Conway.Governance (
setFreshDRepPulsingState,
)
import Cardano.Ledger.Conway.Governance.Procedures (Committee (..))
import Cardano.Ledger.Conway.Governance.Snapshots (snapshotRemoveIds)
import Cardano.Ledger.Conway.Governance.Proposals (proposalsRemoveIds)
import Cardano.Ledger.EpochBoundary (SnapShots)
import Cardano.Ledger.PoolDistr (PoolDistr)
import Cardano.Ledger.Shelley.LedgerState (
Expand Down Expand Up @@ -285,7 +285,7 @@ epochTransition = do
applyEnactedWithdrawals accountState1 dState1 rsEnactState
(newProposals, removedGovActions) =
-- It is important that we use current proposals here instead of the ones from the pulser
snapshotRemoveIds rsRemoved (govState0 ^. cgProposalsL)
proposalsRemoveIds rsRemoved (govState0 ^. cgProposalsL)
govState1 =
govState0
& cgProposalsL .~ newProposals
Expand Down
Loading

0 comments on commit f7f6479

Please sign in to comment.