Skip to content

Commit 739e265

Browse files
committed
New(GetPoolDistr|GetStakeDistribution)2 returning ledger types
1 parent 1c81c3b commit 739e265

File tree

14 files changed

+86
-11
lines changed

14 files changed

+86
-11
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!--
2+
A new scriv changelog fragment.
3+
4+
Uncomment the section that is right (remove the HTML comment wrapper).
5+
-->
6+
7+
<!--
8+
### Patch
9+
10+
- A bullet item for the Patch category.
11+
12+
-->
13+
<!--
14+
### Non-Breaking
15+
16+
- A bullet item for the Non-Breaking category.
17+
18+
-->
19+
20+
### Breaking
21+
22+
- Deprecate `GetPoolDistr` in favor of `GetPoolDistr2` (new in `NodeToClientV_21`).
23+
- Deprecate `GetStakeDistribution` in favor of `GetStakeDistribution2` (new in `NodeToClientV_21`).

ouroboros-consensus-cardano/golden/cardano/QueryVersion3/CardanoNodeToClientVersion17/Result_Allegra_StakeDistribution2

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ouroboros-consensus-cardano/golden/cardano/QueryVersion3/CardanoNodeToClientVersion17/Result_Alonzo_StakeDistribution2

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ouroboros-consensus-cardano/golden/cardano/QueryVersion3/CardanoNodeToClientVersion17/Result_Mary_StakeDistribution2

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ouroboros-consensus-cardano/golden/cardano/QueryVersion3/CardanoNodeToClientVersion17/Result_Shelley_StakeDistribution2

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ouroboros-consensus-cardano/golden/shelley/QueryVersion3/ShelleyNodeToClientVersion13/Query_GetStakeDistribution2

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ouroboros-consensus-cardano/golden/shelley/QueryVersion3/ShelleyNodeToClientVersion13/Result_StakeDistribution2

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Ledger/Query.hs

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,14 @@ type Delegations = Map (SL.Credential 'SL.Staking) (SL.KeyHash 'SL.StakePool)
139139
type VoteDelegatees = Map (SL.Credential 'SL.Staking) SL.DRep
140140

141141
{-# DEPRECATED GetProposedPParamsUpdates "Deprecated in ShelleyNodeToClientVersion12" #-}
142+
{-# DEPRECATED
143+
GetPoolDistr
144+
"Deprecated in ShelleyNodeToClientVersion13. Implement the new alterative GetPoolDistr2"
145+
#-}
146+
{-# DEPRECATED
147+
GetStakeDistribution
148+
"Deprecated in ShelleyNodeToClientVersion13. Implement the new alterative GetStakeDistribution2"
149+
#-}
142150

143151
data instance BlockQuery (ShelleyBlock proto era) fp result where
144152
GetLedgerTip :: BlockQuery (ShelleyBlock proto era) QFNoTables (Point (ShelleyBlock proto era))
@@ -338,6 +346,20 @@ data instance BlockQuery (ShelleyBlock proto era) fp result where
338346
CG.ConwayEraGov era =>
339347
KeyHash 'StakePool ->
340348
BlockQuery (ShelleyBlock proto era) QFNoTables CG.DefaultVote
349+
GetPoolDistr2 ::
350+
Maybe (Set (SL.KeyHash 'SL.StakePool)) ->
351+
BlockQuery
352+
(ShelleyBlock proto era)
353+
QFNoTables
354+
SL.PoolDistr
355+
-- | This gets the stake distribution, but not in terms of _active_ stake
356+
-- (which we need for the leader schedule), but rather in terms of _total_
357+
-- stake, which is relevant for rewards. It is used by the wallet to show
358+
-- saturation levels to the end user. We should consider refactoring this, to
359+
-- an endpoint that provides all the information that the wallet wants about
360+
-- pools, in an extensible fashion.
361+
GetStakeDistribution2 ::
362+
BlockQuery (ShelleyBlock proto era) QFNoTables SL.PoolDistr
341363

342364
-- WARNING: please add new queries to the end of the list and stick to this
343365
-- order in all other pattern matches on queries. This helps in particular
@@ -379,7 +401,7 @@ instance
379401
GetProposedPParamsUpdates ->
380402
SL.ProposedPPUpdates Map.empty
381403
GetStakeDistribution ->
382-
fromLedgerPoolDistr $ SL.poolsByTotalStakeFraction globals st
404+
fromLedgerPoolDistr $ answerPureBlockQuery cfg GetStakeDistribution2 ext
383405
DebugEpochState ->
384406
getEpochState st
385407
GetCBOR query' ->
@@ -469,9 +491,7 @@ instance
469491
, ssGoTotal = getAllStake ssStakeGo
470492
}
471493
GetPoolDistr mPoolIds ->
472-
let stakeSet = SL.ssStakeSet . SL.esSnapshots $ getEpochState st
473-
in fromLedgerPoolDistr $
474-
SL.calculatePoolDistr' (maybe (const True) (flip Set.member) mPoolIds) stakeSet
494+
fromLedgerPoolDistr $ answerPureBlockQuery cfg (GetPoolDistr2 mPoolIds) ext
475495
GetStakeDelegDeposits stakeCreds ->
476496
let lookupDeposit =
477497
SL.lookupDepositDState (view SL.certDStateL $ SL.lsCertState $ SL.esLState $ SL.nesEs st)
@@ -509,6 +529,11 @@ instance
509529
in LedgerPeerSnapshot (slot, bigLedgerPeers)
510530
QueryStakePoolDefaultVote stakePool ->
511531
SL.queryStakePoolDefaultVote st stakePool
532+
GetPoolDistr2 mPoolIds ->
533+
let stakeSet = SL.ssStakeSet . SL.esSnapshots $ getEpochState st
534+
in SL.calculatePoolDistr' (maybe (const True) (flip Set.member) mPoolIds) stakeSet
535+
GetStakeDistribution2 ->
536+
SL.poolsByTotalStakeFraction globals st
512537
where
513538
lcfg = configLedger $ getExtLedgerCfg cfg
514539
globals = shelleyLedgerGlobals lcfg
@@ -534,7 +559,7 @@ instance
534559
GetNonMyopicMemberRewards{} -> const True
535560
GetCurrentPParams -> const True
536561
GetProposedPParamsUpdates -> (< v12)
537-
GetStakeDistribution -> const True
562+
GetStakeDistribution -> (< v13)
538563
GetUTxOByAddress{} -> const True
539564
GetUTxOWhole -> const True
540565
DebugEpochState -> const True
@@ -550,7 +575,7 @@ instance
550575
GetRewardInfoPools -> const True
551576
GetPoolState{} -> const True
552577
GetStakeSnapshots{} -> const True
553-
GetPoolDistr{} -> const True
578+
GetPoolDistr{} -> (< v13)
554579
GetStakeDelegDeposits{} -> const True
555580
GetConstitution -> (>= v8)
556581
GetGovState -> (>= v8)
@@ -565,6 +590,8 @@ instance
565590
GetFuturePParams{} -> (>= v10)
566591
GetBigLedgerPeerSnapshot -> (>= v11)
567592
QueryStakePoolDefaultVote{} -> (>= v12)
593+
GetPoolDistr2{} -> (>= v13)
594+
GetStakeDistribution2{} -> (>= v13)
568595
where
569596
-- WARNING: when adding a new query, a new @ShelleyNodeToClientVersionX@
570597
-- must be added. See #2830 for a template on how to do this.
@@ -574,6 +601,7 @@ instance
574601
v10 = ShelleyNodeToClientVersion10
575602
v11 = ShelleyNodeToClientVersion11
576603
v12 = ShelleyNodeToClientVersion12
604+
v13 = ShelleyNodeToClientVersion13
577605

578606
instance SameDepIndex2 (BlockQuery (ShelleyBlock proto era)) where
579607
sameDepIndex2 GetLedgerTip GetLedgerTip =
@@ -727,6 +755,10 @@ instance SameDepIndex2 (BlockQuery (ShelleyBlock proto era)) where
727755
sameDepIndex2 GetBigLedgerPeerSnapshot _ = Nothing
728756
sameDepIndex2 QueryStakePoolDefaultVote{} QueryStakePoolDefaultVote{} = Just Refl
729757
sameDepIndex2 QueryStakePoolDefaultVote{} _ = Nothing
758+
sameDepIndex2 GetPoolDistr2{} GetPoolDistr2{} = Just Refl
759+
sameDepIndex2 GetPoolDistr2{} _ = Nothing
760+
sameDepIndex2 GetStakeDistribution2{} GetStakeDistribution2{} = Just Refl
761+
sameDepIndex2 GetStakeDistribution2{} _ = Nothing
730762

731763
deriving instance Eq (BlockQuery (ShelleyBlock proto era) fp result)
732764
deriving instance Show (BlockQuery (ShelleyBlock proto era) fp result)
@@ -769,6 +801,8 @@ instance ShelleyCompatible proto era => ShowQuery (BlockQuery (ShelleyBlock prot
769801
GetFuturePParams{} -> show
770802
GetBigLedgerPeerSnapshot -> show
771803
QueryStakePoolDefaultVote{} -> show
804+
GetPoolDistr2{} -> show
805+
GetStakeDistribution2{} -> show
772806

773807
{-------------------------------------------------------------------------------
774808
Auxiliary
@@ -891,6 +925,10 @@ encodeShelleyQuery query = case query of
891925
CBOR.encodeListLen 1 <> CBOR.encodeWord8 34
892926
QueryStakePoolDefaultVote stakePoolKey ->
893927
CBOR.encodeListLen 2 <> CBOR.encodeWord8 35 <> LC.toEraCBOR @era stakePoolKey
928+
GetPoolDistr2 poolids ->
929+
CBOR.encodeListLen 2 <> CBOR.encodeWord8 36 <> toCBOR poolids
930+
GetStakeDistribution2 ->
931+
CBOR.encodeListLen 1 <> CBOR.encodeWord8 37
894932

895933
decodeShelleyQuery ::
896934
forall era proto.
@@ -962,6 +1000,8 @@ decodeShelleyQuery = do
9621000
(1, 33) -> requireCG $ return $ SomeBlockQuery GetFuturePParams
9631001
(1, 34) -> return $ SomeBlockQuery GetBigLedgerPeerSnapshot
9641002
(2, 35) -> requireCG $ SomeBlockQuery . QueryStakePoolDefaultVote <$> LC.fromEraCBOR @era
1003+
(2, 36) -> SomeBlockQuery . GetPoolDistr2 <$> fromCBOR
1004+
(1, 37) -> return $ SomeBlockQuery GetStakeDistribution2
9651005
_ -> failmsg "invalid"
9661006

9671007
encodeShelleyResult ::
@@ -975,8 +1015,8 @@ encodeShelleyResult v query = case query of
9751015
GetLedgerTip -> encodePoint encode
9761016
GetEpochNo -> toCBOR
9771017
GetNonMyopicMemberRewards{} -> toCBOR
978-
GetProposedPParamsUpdates -> toCBOR
9791018
GetCurrentPParams -> fst $ currentPParamsEnDecoding v
1019+
GetProposedPParamsUpdates -> toCBOR
9801020
GetStakeDistribution -> LC.toEraCBOR @era
9811021
GetUTxOByAddress{} -> toCBOR
9821022
GetUTxOWhole -> toCBOR
@@ -1008,6 +1048,8 @@ encodeShelleyResult v query = case query of
10081048
GetFuturePParams{} -> LC.toEraCBOR @era
10091049
GetBigLedgerPeerSnapshot -> toCBOR
10101050
QueryStakePoolDefaultVote{} -> toCBOR
1051+
GetPoolDistr2{} -> LC.toEraCBOR @era
1052+
GetStakeDistribution2{} -> LC.toEraCBOR @era
10111053

10121054
decodeShelleyResult ::
10131055
forall proto era fp result.
@@ -1020,8 +1062,8 @@ decodeShelleyResult v query = case query of
10201062
GetLedgerTip -> decodePoint decode
10211063
GetEpochNo -> fromCBOR
10221064
GetNonMyopicMemberRewards{} -> fromCBOR
1023-
GetProposedPParamsUpdates -> fromCBOR
10241065
GetCurrentPParams -> snd $ currentPParamsEnDecoding v
1066+
GetProposedPParamsUpdates -> fromCBOR
10251067
GetStakeDistribution -> LC.fromEraCBOR @era
10261068
GetUTxOByAddress{} -> fromCBOR
10271069
GetUTxOWhole -> fromCBOR
@@ -1053,6 +1095,8 @@ decodeShelleyResult v query = case query of
10531095
GetFuturePParams{} -> LC.fromEraCBOR @era
10541096
GetBigLedgerPeerSnapshot -> fromCBOR
10551097
QueryStakePoolDefaultVote{} -> fromCBOR
1098+
GetPoolDistr2{} -> LC.fromEraCBOR @era
1099+
GetStakeDistribution2 -> LC.fromEraCBOR @era
10561100

10571101
currentPParamsEnDecoding ::
10581102
forall era s.

ouroboros-consensus-cardano/src/unstable-shelley-testlib/Test/Consensus/Shelley/Examples.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
{-# LANGUAGE ScopedTypeVariables #-}
66
{-# LANGUAGE TypeApplications #-}
77
{-# LANGUAGE TypeFamilies #-}
8+
{-# OPTIONS_GHC -Wno-deprecations #-}
89

910
module Test.Consensus.Shelley.Examples
1011
( -- * Setup
@@ -169,6 +170,7 @@ fromShelleyLedgerExamples
169170
, ("GetNonMyopicMemberRewards", SomeBlockQuery $ GetNonMyopicMemberRewards sleRewardsCredentials)
170171
, ("GetGenesisConfig", SomeBlockQuery GetGenesisConfig)
171172
, ("GetBigLedgerPeerSnapshot", SomeBlockQuery GetBigLedgerPeerSnapshot)
173+
, ("GetStakeDistribution2", SomeBlockQuery GetStakeDistribution2)
172174
]
173175
results =
174176
labelled
@@ -201,6 +203,7 @@ fromShelleyLedgerExamples
201203
)
202204
)
203205
)
206+
, ("StakeDistribution2", SomeResult GetStakeDistribution2 srePoolDistr)
204207
]
205208
annTip =
206209
AnnTip

ouroboros-consensus-cardano/src/unstable-shelley-testlib/Test/Consensus/Shelley/Generators.hs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import qualified Ouroboros.Consensus.Protocol.Praos.Header as Praos
3333
import Ouroboros.Consensus.Protocol.TPraos (TPraos, TPraosState (..))
3434
import Ouroboros.Consensus.Shelley.Eras
3535
import Ouroboros.Consensus.Shelley.Ledger
36-
import Ouroboros.Consensus.Shelley.Ledger.Query.Types
3736
import Ouroboros.Consensus.Shelley.Protocol.Praos ()
3837
import Ouroboros.Consensus.Shelley.Protocol.TPraos ()
3938
import Ouroboros.Network.Block (mkSerialised)
@@ -172,12 +171,12 @@ instance CanMock proto era => Arbitrary (SomeBlockQuery (BlockQuery (ShelleyBloc
172171
, pure $ SomeBlockQuery GetEpochNo
173172
, SomeBlockQuery . GetNonMyopicMemberRewards <$> arbitrary
174173
, pure $ SomeBlockQuery GetCurrentPParams
175-
, pure $ SomeBlockQuery GetStakeDistribution
176174
, pure $ SomeBlockQuery DebugEpochState
177175
, (\(SomeBlockQuery q) -> SomeBlockQuery (GetCBOR q)) <$> arbitrary
178176
, SomeBlockQuery . GetFilteredDelegationsAndRewardAccounts <$> arbitrary
179177
, pure $ SomeBlockQuery GetGenesisConfig
180178
, pure $ SomeBlockQuery DebugNewEpochState
179+
, pure $ SomeBlockQuery GetStakeDistribution2
181180
]
182181

183182
instance (Arbitrary (InstantStake era), CanMock proto era) => Arbitrary (SomeResult (ShelleyBlock proto era)) where
@@ -187,7 +186,6 @@ instance (Arbitrary (InstantStake era), CanMock proto era) => Arbitrary (SomeRes
187186
, SomeResult GetEpochNo <$> arbitrary
188187
, SomeResult <$> (GetNonMyopicMemberRewards <$> arbitrary) <*> arbitrary
189188
, SomeResult GetCurrentPParams <$> arbitrary
190-
, SomeResult GetStakeDistribution . fromLedgerPoolDistr <$> arbitrary
191189
, SomeResult DebugEpochState <$> arbitrary
192190
, ( \(SomeResult q r) ->
193191
SomeResult (GetCBOR q) (mkSerialised (encodeShelleyResult maxBound q) r)
@@ -196,6 +194,7 @@ instance (Arbitrary (InstantStake era), CanMock proto era) => Arbitrary (SomeRes
196194
, SomeResult <$> (GetFilteredDelegationsAndRewardAccounts <$> arbitrary) <*> arbitrary
197195
, SomeResult GetGenesisConfig . compactGenesis <$> arbitrary
198196
, SomeResult DebugNewEpochState <$> arbitrary
197+
, SomeResult GetStakeDistribution2 <$> arbitrary
199198
]
200199

201200
instance Arbitrary NonMyopicMemberRewards where

0 commit comments

Comments
 (0)