Skip to content

Commit

Permalink
Add two new queries to the ledger api
Browse files Browse the repository at this point in the history
  • Loading branch information
lehins committed May 7, 2024
1 parent dfffd05 commit 06c024b
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions libs/cardano-ledger-api/src/Cardano/Ledger/Api/State/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ module Cardano.Ledger.Api.State.Query (
MemberStatus (..),
NextEpochChange (..),

-- * @GetCurrentPParams@
queryCurrentPParams,

-- * @GetFuturePParams@
queryFuturePParams,

-- * For testing
getNextEpochCommitteeMembers,
) where
Expand Down Expand Up @@ -67,11 +73,7 @@ import Cardano.Ledger.Credential (Credential)
import Cardano.Ledger.DRep (drepExpiryL)
import Cardano.Ledger.Keys (KeyHash, KeyRole (..))
import Cardano.Ledger.SafeHash (SafeHash)
import Cardano.Ledger.Shelley.Governance (
EraGov (
GovState
),
)
import Cardano.Ledger.Shelley.Governance (EraGov (..), FuturePParams (..))
import Cardano.Ledger.Shelley.LedgerState
import Cardano.Ledger.UMap (
StakeCredentials (scRewards, scSPools),
Expand Down Expand Up @@ -274,3 +276,19 @@ getNextEpochCommitteeMembers nes =
let ratifyState = snd . finishDRepPulser $ queryGovState nes ^. drepPulsingStateGovStateL
committee = ratifyState ^. rsEnactStateL . ensCommitteeL
in foldMap' committeeMembers committee

-- | This is a simple lookup into the state for the values of current protocol
-- parameters. These values can change on the epoch boundary. Use `queryFuturePParams` to
-- see if we are aware of any upcoming changes.
queryCurrentPParams :: EraGov era => NewEpochState era -> PParams era
queryCurrentPParams nes = queryGovState nes ^. curPParamsGovStateL

-- | This query will return values for protocol parameters that are likely to be adopted
-- at the next epoch boundary. It is only when we passed 2 stability windows before the
-- end of the epoch that users can rely on this query to produce stable results.
queryFuturePParams :: EraGov era => NewEpochState era -> Maybe (PParams era)
queryFuturePParams nes =
case queryGovState nes ^. futurePParamsGovStateL of
NoPParamsUpdate -> Nothing
PotentialPParamsUpdate mpp -> mpp
DefinitePParamsUpdate pp -> Just pp

0 comments on commit 06c024b

Please sign in to comment.