From 99f8d49bd9235b0f440759f3c6adffda858ea541 Mon Sep 17 00:00:00 2001 From: Lucsanszky Date: Tue, 30 Jul 2024 03:13:01 +0200 Subject: [PATCH 1/2] Add state query for proposals --- libs/cardano-ledger-api/CHANGELOG.md | 4 +-- .../cardano-ledger-api.cabal | 3 +- .../src/Cardano/Ledger/Api/State/Query.hs | 30 +++++++++++++++++++ 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/libs/cardano-ledger-api/CHANGELOG.md b/libs/cardano-ledger-api/CHANGELOG.md index b782ac5589..ae4841c4a5 100644 --- a/libs/cardano-ledger-api/CHANGELOG.md +++ b/libs/cardano-ledger-api/CHANGELOG.md @@ -1,8 +1,8 @@ # Version history for `cardano-ledger-api` -## 1.9.2.2 +## 1.9.3.0 -* +* Add `queryProposals` state query ## 1.9.2.1 diff --git a/libs/cardano-ledger-api/cardano-ledger-api.cabal b/libs/cardano-ledger-api/cardano-ledger-api.cabal index f477d680f3..dcb3cd5a8b 100644 --- a/libs/cardano-ledger-api/cardano-ledger-api.cabal +++ b/libs/cardano-ledger-api/cardano-ledger-api.cabal @@ -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 @@ -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, diff --git a/libs/cardano-ledger-api/src/Cardano/Ledger/Api/State/Query.hs b/libs/cardano-ledger-api/src/Cardano/Ledger/Api/State/Query.hs index 3453d532f2..d49ddfddc2 100644 --- a/libs/cardano-ledger-api/src/Cardano/Ledger/Api/State/Query.hs +++ b/libs/cardano-ledger-api/src/Cardano/Ledger/Api/State/Query.hs @@ -1,5 +1,6 @@ {-# LANGUAGE DataKinds #-} {-# LANGUAGE GADTs #-} +{-# LANGUAGE RecordWildCards #-} {-# LANGUAGE ScopedTypeVariables #-} module Cardano.Ledger.Api.State.Query ( @@ -45,6 +46,9 @@ module Cardano.Ledger.Api.State.Query ( -- * @GetFuturePParams@ queryFuturePParams, + -- * @GetProposals@ + queryProposals, + -- * For testing getNextEpochCommitteeMembers, ) where @@ -64,6 +68,10 @@ import Cardano.Ledger.Conway.Governance ( Committee (committeeMembers), Constitution (constitutionAnchor), ConwayEraGov (..), + DRepPulser (..), + DRepPulsingState (..), + GovActionId, + GovActionState (..), PulsingSnapshot, RatifyState, committeeThresholdL, @@ -71,6 +79,7 @@ import Cardano.Ledger.Conway.Governance ( finishDRepPulser, psDRepDistr, psPoolDistr, + psProposalsL, rsEnactStateL, ) import Cardano.Ledger.Conway.Rules (updateDormantDRepExpiry) @@ -90,6 +99,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 @@ -309,6 +321,24 @@ 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 + finishedPulserState :: ConwayEraGov era => NewEpochState era -> From 5941afe85186465ba372f224e6a23daed6ad0201 Mon Sep 17 00:00:00 2001 From: Lucsanszky Date: Tue, 30 Jul 2024 03:22:44 +0200 Subject: [PATCH 2/2] Add state query for `RatifyState` --- libs/cardano-ledger-api/CHANGELOG.md | 1 + .../src/Cardano/Ledger/Api/State/Query.hs | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/libs/cardano-ledger-api/CHANGELOG.md b/libs/cardano-ledger-api/CHANGELOG.md index ae4841c4a5..c8fe0e0bcc 100644 --- a/libs/cardano-ledger-api/CHANGELOG.md +++ b/libs/cardano-ledger-api/CHANGELOG.md @@ -2,6 +2,7 @@ ## 1.9.3.0 +* Add `queryRatifyState` state query * Add `queryProposals` state query ## 1.9.2.1 diff --git a/libs/cardano-ledger-api/src/Cardano/Ledger/Api/State/Query.hs b/libs/cardano-ledger-api/src/Cardano/Ledger/Api/State/Query.hs index d49ddfddc2..f33e319544 100644 --- a/libs/cardano-ledger-api/src/Cardano/Ledger/Api/State/Query.hs +++ b/libs/cardano-ledger-api/src/Cardano/Ledger/Api/State/Query.hs @@ -49,6 +49,9 @@ module Cardano.Ledger.Api.State.Query ( -- * @GetProposals@ queryProposals, + -- * @GetRatifyState@ + queryRatifyState, + -- * For testing getNextEpochCommitteeMembers, ) where @@ -301,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 @@ -339,6 +342,10 @@ queryProposals nes gids 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 ->