Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add governance related state queries #4514

Merged
merged 2 commits into from
Aug 1, 2024
Merged
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
5 changes: 3 additions & 2 deletions libs/cardano-ledger-api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Version history for `cardano-ledger-api`

## 1.9.2.2
## 1.9.3.0

*
* Add `queryRatifyState` state query
* Add `queryProposals` state query

## 1.9.2.1

Expand Down
3 changes: 2 additions & 1 deletion libs/cardano-ledger-api/cardano-ledger-api.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 3.0
name: cardano-ledger-api
version: 1.9.2.2
version: 1.9.3.0
license: Apache-2.0
maintainer: operations@iohk.io
author: IOHK
Expand Down Expand Up @@ -62,6 +62,7 @@ library
cardano-ledger-core >=1.13.2 && <1.15,
cardano-ledger-mary >=1.5 && <1.7,
cardano-ledger-shelley ^>=1.12,
cardano-strict-containers,
containers,
FailT,
microlens,
Expand Down
39 changes: 38 additions & 1 deletion libs/cardano-ledger-api/src/Cardano/Ledger/Api/State/Query.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}

module Cardano.Ledger.Api.State.Query (
Expand Down Expand Up @@ -45,6 +46,12 @@ module Cardano.Ledger.Api.State.Query (
-- * @GetFuturePParams@
queryFuturePParams,

-- * @GetProposals@
queryProposals,

-- * @GetRatifyState@
queryRatifyState,

-- * For testing
getNextEpochCommitteeMembers,
) where
Expand All @@ -64,13 +71,18 @@ import Cardano.Ledger.Conway.Governance (
Committee (committeeMembers),
Constitution (constitutionAnchor),
ConwayEraGov (..),
DRepPulser (..),
DRepPulsingState (..),
GovActionId,
GovActionState (..),
PulsingSnapshot,
RatifyState,
committeeThresholdL,
ensCommitteeL,
finishDRepPulser,
psDRepDistr,
psPoolDistr,
psProposalsL,
rsEnactStateL,
)
import Cardano.Ledger.Conway.Rules (updateDormantDRepExpiry)
Expand All @@ -90,6 +102,9 @@ import Data.Foldable (foldMap')
import Data.Map (Map)
import qualified Data.Map.Strict as Map
import Data.Maybe (isJust)
import Data.Sequence (Seq (..))
import qualified Data.Sequence as Seq
import Data.Sequence.Strict (StrictSeq (..))
import Data.Set (Set)
import qualified Data.Set as Set
import Lens.Micro
Expand Down Expand Up @@ -289,7 +304,7 @@ getNextEpochCommitteeMembers ::
NewEpochState era ->
Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
getNextEpochCommitteeMembers nes =
let ratifyState = snd $ finishedPulserState nes
let ratifyState = queryRatifyState nes
committee = ratifyState ^. rsEnactStateL . ensCommitteeL
in foldMap' committeeMembers committee

Expand All @@ -309,6 +324,28 @@ queryFuturePParams nes =
PotentialPParamsUpdate mpp -> mpp
DefinitePParamsUpdate pp -> Just pp

-- | Query proposals that are considered for ratification.
queryProposals ::
ConwayEraGov era =>
NewEpochState era ->
-- | Specify a set of Governance Action IDs to filter the proposals. When this set is
-- empty, all the proposals considered for ratification will be returned.
Set (GovActionId (EraCrypto era)) ->
Seq (GovActionState era)
queryProposals nes gids
| null gids = proposals
-- TODO: Add `filter` to `cardano-strict-containers`
| otherwise =
Seq.filter (\GovActionState {..} -> gasId `Set.member` gids) proposals
where
proposals = fromStrict $ case (nes ^. newEpochStateGovStateL . drepPulsingStateGovStateL) of
DRComplete snap _rs -> snap ^. psProposalsL
DRPulsing DRepPulser {..} -> dpProposals

-- | Query ratification state.
queryRatifyState :: ConwayEraGov era => NewEpochState era -> RatifyState era
queryRatifyState = snd . finishedPulserState

finishedPulserState ::
ConwayEraGov era =>
NewEpochState era ->
Expand Down
Loading