Skip to content

Commit 837d4a8

Browse files
committed
Delete GetProposedPParamsUpdates, deprecate GetPoolDistr and GetStakeDistribution for their new conterparts
1 parent 1c81c3b commit 837d4a8

File tree

4 files changed

+79
-25
lines changed

4 files changed

+79
-25
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
- Delete `GetProposedPParamsUpdates`.
23+
- Deprecate `GetPoolDistr` in favor of `GetPoolDistr2` (new in `NodeToClientV_21`).
24+
- Deprecate `GetStakeDistribution` in favor of `GetStakeDistribution2` (new in `NodeToClientV_21`).

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

Lines changed: 50 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,14 @@ type Delegations = Map (SL.Credential 'SL.Staking) (SL.KeyHash 'SL.StakePool)
138138

139139
type VoteDelegatees = Map (SL.Credential 'SL.Staking) SL.DRep
140140

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

143150
data instance BlockQuery (ShelleyBlock proto era) fp result where
144151
GetLedgerTip :: BlockQuery (ShelleyBlock proto era) QFNoTables (Point (ShelleyBlock proto era))
@@ -150,8 +157,6 @@ data instance BlockQuery (ShelleyBlock proto era) fp result where
150157
BlockQuery (ShelleyBlock proto era) QFNoTables NonMyopicMemberRewards
151158
GetCurrentPParams ::
152159
BlockQuery (ShelleyBlock proto era) QFNoTables (LC.PParams era)
153-
GetProposedPParamsUpdates ::
154-
BlockQuery (ShelleyBlock proto era) QFNoTables (SL.ProposedPPUpdates era)
155160
-- | This gets the stake distribution, but not in terms of _active_ stake
156161
-- (which we need for the leader schedule), but rather in terms of _total_
157162
-- stake, which is relevant for rewards. It is used by the wallet to show
@@ -338,6 +343,20 @@ data instance BlockQuery (ShelleyBlock proto era) fp result where
338343
CG.ConwayEraGov era =>
339344
KeyHash 'StakePool ->
340345
BlockQuery (ShelleyBlock proto era) QFNoTables CG.DefaultVote
346+
GetPoolDistr2 ::
347+
Maybe (Set (SL.KeyHash 'SL.StakePool)) ->
348+
BlockQuery
349+
(ShelleyBlock proto era)
350+
QFNoTables
351+
SL.PoolDistr
352+
-- | This gets the stake distribution, but not in terms of _active_ stake
353+
-- (which we need for the leader schedule), but rather in terms of _total_
354+
-- stake, which is relevant for rewards. It is used by the wallet to show
355+
-- saturation levels to the end user. We should consider refactoring this, to
356+
-- an endpoint that provides all the information that the wallet wants about
357+
-- pools, in an extensible fashion.
358+
GetStakeDistribution2 ::
359+
BlockQuery (ShelleyBlock proto era) QFNoTables SL.PoolDistr
341360

342361
-- WARNING: please add new queries to the end of the list and stick to this
343362
-- order in all other pattern matches on queries. This helps in particular
@@ -376,10 +395,8 @@ instance
376395
SL.getNonMyopicMemberRewards globals st creds
377396
GetCurrentPParams ->
378397
getPParams st
379-
GetProposedPParamsUpdates ->
380-
SL.ProposedPPUpdates Map.empty
381398
GetStakeDistribution ->
382-
fromLedgerPoolDistr $ SL.poolsByTotalStakeFraction globals st
399+
fromLedgerPoolDistr $ answerPureBlockQuery cfg GetStakeDistribution2 ext
383400
DebugEpochState ->
384401
getEpochState st
385402
GetCBOR query' ->
@@ -469,9 +486,7 @@ instance
469486
, ssGoTotal = getAllStake ssStakeGo
470487
}
471488
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
489+
fromLedgerPoolDistr $ answerPureBlockQuery cfg (GetPoolDistr2 mPoolIds) ext
475490
GetStakeDelegDeposits stakeCreds ->
476491
let lookupDeposit =
477492
SL.lookupDepositDState (view SL.certDStateL $ SL.lsCertState $ SL.esLState $ SL.nesEs st)
@@ -509,6 +524,11 @@ instance
509524
in LedgerPeerSnapshot (slot, bigLedgerPeers)
510525
QueryStakePoolDefaultVote stakePool ->
511526
SL.queryStakePoolDefaultVote st stakePool
527+
GetPoolDistr2 mPoolIds ->
528+
let stakeSet = SL.ssStakeSet . SL.esSnapshots $ getEpochState st
529+
in SL.calculatePoolDistr' (maybe (const True) (flip Set.member) mPoolIds) stakeSet
530+
GetStakeDistribution2 ->
531+
SL.poolsByTotalStakeFraction globals st
512532
where
513533
lcfg = configLedger $ getExtLedgerCfg cfg
514534
globals = shelleyLedgerGlobals lcfg
@@ -533,8 +553,7 @@ instance
533553
GetEpochNo -> const True
534554
GetNonMyopicMemberRewards{} -> const True
535555
GetCurrentPParams -> const True
536-
GetProposedPParamsUpdates -> (< v12)
537-
GetStakeDistribution -> const True
556+
GetStakeDistribution -> (< v13)
538557
GetUTxOByAddress{} -> const True
539558
GetUTxOWhole -> const True
540559
DebugEpochState -> const True
@@ -550,7 +569,7 @@ instance
550569
GetRewardInfoPools -> const True
551570
GetPoolState{} -> const True
552571
GetStakeSnapshots{} -> const True
553-
GetPoolDistr{} -> const True
572+
GetPoolDistr{} -> (< v13)
554573
GetStakeDelegDeposits{} -> const True
555574
GetConstitution -> (>= v8)
556575
GetGovState -> (>= v8)
@@ -565,6 +584,8 @@ instance
565584
GetFuturePParams{} -> (>= v10)
566585
GetBigLedgerPeerSnapshot -> (>= v11)
567586
QueryStakePoolDefaultVote{} -> (>= v12)
587+
GetPoolDistr2{} -> (>= v13)
588+
GetStakeDistribution2{} -> (>= v13)
568589
where
569590
-- WARNING: when adding a new query, a new @ShelleyNodeToClientVersionX@
570591
-- must be added. See #2830 for a template on how to do this.
@@ -574,6 +595,7 @@ instance
574595
v10 = ShelleyNodeToClientVersion10
575596
v11 = ShelleyNodeToClientVersion11
576597
v12 = ShelleyNodeToClientVersion12
598+
v13 = ShelleyNodeToClientVersion13
577599

578600
instance SameDepIndex2 (BlockQuery (ShelleyBlock proto era)) where
579601
sameDepIndex2 GetLedgerTip GetLedgerTip =
@@ -595,10 +617,6 @@ instance SameDepIndex2 (BlockQuery (ShelleyBlock proto era)) where
595617
Just Refl
596618
sameDepIndex2 GetCurrentPParams _ =
597619
Nothing
598-
sameDepIndex2 GetProposedPParamsUpdates GetProposedPParamsUpdates =
599-
Just Refl
600-
sameDepIndex2 GetProposedPParamsUpdates _ =
601-
Nothing
602620
sameDepIndex2 GetStakeDistribution GetStakeDistribution =
603621
Just Refl
604622
sameDepIndex2 GetStakeDistribution _ =
@@ -727,6 +745,10 @@ instance SameDepIndex2 (BlockQuery (ShelleyBlock proto era)) where
727745
sameDepIndex2 GetBigLedgerPeerSnapshot _ = Nothing
728746
sameDepIndex2 QueryStakePoolDefaultVote{} QueryStakePoolDefaultVote{} = Just Refl
729747
sameDepIndex2 QueryStakePoolDefaultVote{} _ = Nothing
748+
sameDepIndex2 GetPoolDistr2{} GetPoolDistr2{} = Just Refl
749+
sameDepIndex2 GetPoolDistr2{} _ = Nothing
750+
sameDepIndex2 GetStakeDistribution2{} GetStakeDistribution2{} = Just Refl
751+
sameDepIndex2 GetStakeDistribution2{} _ = Nothing
730752

731753
deriving instance Eq (BlockQuery (ShelleyBlock proto era) fp result)
732754
deriving instance Show (BlockQuery (ShelleyBlock proto era) fp result)
@@ -737,7 +759,6 @@ instance ShelleyCompatible proto era => ShowQuery (BlockQuery (ShelleyBlock prot
737759
GetEpochNo -> show
738760
GetNonMyopicMemberRewards{} -> show
739761
GetCurrentPParams -> show
740-
GetProposedPParamsUpdates -> show
741762
GetStakeDistribution -> show
742763
GetUTxOByAddress{} -> show
743764
GetUTxOWhole -> show
@@ -769,6 +790,8 @@ instance ShelleyCompatible proto era => ShowQuery (BlockQuery (ShelleyBlock prot
769790
GetFuturePParams{} -> show
770791
GetBigLedgerPeerSnapshot -> show
771792
QueryStakePoolDefaultVote{} -> show
793+
GetPoolDistr2{} -> show
794+
GetStakeDistribution2{} -> show
772795

773796
{-------------------------------------------------------------------------------
774797
Auxiliary
@@ -823,8 +846,6 @@ encodeShelleyQuery query = case query of
823846
CBOR.encodeListLen 2 <> CBOR.encodeWord8 2 <> toCBOR creds
824847
GetCurrentPParams ->
825848
CBOR.encodeListLen 1 <> CBOR.encodeWord8 3
826-
GetProposedPParamsUpdates ->
827-
CBOR.encodeListLen 1 <> CBOR.encodeWord8 4
828849
GetStakeDistribution ->
829850
CBOR.encodeListLen 1 <> CBOR.encodeWord8 5
830851
GetUTxOByAddress addrs ->
@@ -891,6 +912,10 @@ encodeShelleyQuery query = case query of
891912
CBOR.encodeListLen 1 <> CBOR.encodeWord8 34
892913
QueryStakePoolDefaultVote stakePoolKey ->
893914
CBOR.encodeListLen 2 <> CBOR.encodeWord8 35 <> LC.toEraCBOR @era stakePoolKey
915+
GetPoolDistr2 poolids ->
916+
CBOR.encodeListLen 2 <> CBOR.encodeWord8 36 <> toCBOR poolids
917+
GetStakeDistribution2 ->
918+
CBOR.encodeListLen 1 <> CBOR.encodeWord8 37
894919

895920
decodeShelleyQuery ::
896921
forall era proto.
@@ -925,7 +950,6 @@ decodeShelleyQuery = do
925950
(1, 1) -> return $ SomeBlockQuery GetEpochNo
926951
(2, 2) -> SomeBlockQuery . GetNonMyopicMemberRewards <$> fromCBOR
927952
(1, 3) -> return $ SomeBlockQuery GetCurrentPParams
928-
(1, 4) -> return $ SomeBlockQuery GetProposedPParamsUpdates
929953
(1, 5) -> return $ SomeBlockQuery GetStakeDistribution
930954
(2, 6) -> SomeBlockQuery . GetUTxOByAddress <$> LC.fromEraCBOR @era
931955
(1, 7) -> return $ SomeBlockQuery GetUTxOWhole
@@ -962,6 +986,8 @@ decodeShelleyQuery = do
962986
(1, 33) -> requireCG $ return $ SomeBlockQuery GetFuturePParams
963987
(1, 34) -> return $ SomeBlockQuery GetBigLedgerPeerSnapshot
964988
(2, 35) -> requireCG $ SomeBlockQuery . QueryStakePoolDefaultVote <$> LC.fromEraCBOR @era
989+
(2, 36) -> SomeBlockQuery . GetPoolDistr2 <$> fromCBOR
990+
(1, 37) -> return $ SomeBlockQuery GetStakeDistribution2
965991
_ -> failmsg "invalid"
966992

967993
encodeShelleyResult ::
@@ -975,7 +1001,6 @@ encodeShelleyResult v query = case query of
9751001
GetLedgerTip -> encodePoint encode
9761002
GetEpochNo -> toCBOR
9771003
GetNonMyopicMemberRewards{} -> toCBOR
978-
GetProposedPParamsUpdates -> toCBOR
9791004
GetCurrentPParams -> fst $ currentPParamsEnDecoding v
9801005
GetStakeDistribution -> LC.toEraCBOR @era
9811006
GetUTxOByAddress{} -> toCBOR
@@ -1008,6 +1033,8 @@ encodeShelleyResult v query = case query of
10081033
GetFuturePParams{} -> LC.toEraCBOR @era
10091034
GetBigLedgerPeerSnapshot -> toCBOR
10101035
QueryStakePoolDefaultVote{} -> toCBOR
1036+
GetPoolDistr2{} -> LC.toEraCBOR @era
1037+
GetStakeDistribution2{} -> LC.toEraCBOR @era
10111038

10121039
decodeShelleyResult ::
10131040
forall proto era fp result.
@@ -1020,7 +1047,6 @@ decodeShelleyResult v query = case query of
10201047
GetLedgerTip -> decodePoint decode
10211048
GetEpochNo -> fromCBOR
10221049
GetNonMyopicMemberRewards{} -> fromCBOR
1023-
GetProposedPParamsUpdates -> fromCBOR
10241050
GetCurrentPParams -> snd $ currentPParamsEnDecoding v
10251051
GetStakeDistribution -> LC.fromEraCBOR @era
10261052
GetUTxOByAddress{} -> fromCBOR
@@ -1053,6 +1079,8 @@ decodeShelleyResult v query = case query of
10531079
GetFuturePParams{} -> LC.fromEraCBOR @era
10541080
GetBigLedgerPeerSnapshot -> fromCBOR
10551081
QueryStakePoolDefaultVote{} -> fromCBOR
1082+
GetPoolDistr2{} -> LC.fromEraCBOR @era
1083+
GetStakeDistribution2 -> LC.fromEraCBOR @era
10561084

10571085
currentPParamsEnDecoding ::
10581086
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)