Skip to content

Commit

Permalink
Merge pull request #4514 from IntersectMBO/ldan/govstate-queries
Browse files Browse the repository at this point in the history
Add governance related state queries
  • Loading branch information
lehins authored Aug 1, 2024
2 parents bca8e2b + 5941afe commit 48c5fd3
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
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: [email protected]
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

0 comments on commit 48c5fd3

Please sign in to comment.