Skip to content

Commit 9f54955

Browse files
committed
New query GetPoolDistr
1 parent e975b9b commit 9f54955

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ data ShelleyNodeToClientVersion =
3131
-- | New queries introduced: GetRewardInfoPools
3232
| ShelleyNodeToClientVersion5
3333

34-
-- | New queries introduced: GetPoolState
34+
-- | New queries introduced: GetPoolDistr, GetPoolState
3535
| ShelleyNodeToClientVersion6
3636
deriving (Show, Eq, Ord, Enum, Bounded)
3737

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,11 @@ data instance BlockQuery (ShelleyBlock proto era) :: Type -> Type where
193193
-> BlockQuery (ShelleyBlock proto era)
194194
(SL.PState (EraCrypto era))
195195

196+
GetPoolDistr
197+
:: Maybe (Set (SL.KeyHash 'SL.StakePool (EraCrypto era)))
198+
-> BlockQuery (ShelleyBlock proto era)
199+
(SL.PoolDistr (EraCrypto era))
200+
196201
-- WARNING: please add new queries to the end of the list and stick to this
197202
-- order in all other pattern matches on queries. This helps in particular
198203
-- with the en/decoders, as we want the CBOR tags to be ordered.
@@ -273,6 +278,11 @@ instance ShelleyCompatible proto era => QueryLedger (ShelleyBlock proto era) whe
273278
, SL._retiring = Map.restrictKeys (SL._retiring dpsPState) poolIds
274279
}
275280
Nothing -> dpsPState
281+
GetPoolDistr mPoolIds ->
282+
let poolDistr = SL.calculatePoolDistr . SL._pstakeSet . SL.esSnapshots $ getEpochState st in
283+
case mPoolIds of
284+
Just poolIds -> SL.PoolDistr $ Map.restrictKeys (SL.unPoolDistr poolDistr) poolIds
285+
Nothing -> poolDistr
276286
where
277287
lcfg = configLedger $ getExtLedgerCfg cfg
278288
globals = shelleyLedgerGlobals lcfg
@@ -287,6 +297,8 @@ instance ShelleyCompatible proto era => QueryLedger (ShelleyBlock proto era) whe
287297
hst = headerState ext
288298
st = shelleyLedgerState lst
289299

300+
301+
290302
instance SameDepIndex (BlockQuery (ShelleyBlock proto era)) where
291303
sameDepIndex GetLedgerTip GetLedgerTip
292304
= Just Refl
@@ -387,6 +399,13 @@ instance SameDepIndex (BlockQuery (ShelleyBlock proto era)) where
387399
= Nothing
388400
sameDepIndex (GetPoolState _) _
389401
= Nothing
402+
sameDepIndex (GetPoolDistr poolids) (GetPoolDistr poolids')
403+
| poolids == poolids'
404+
= Just Refl
405+
| otherwise
406+
= Nothing
407+
sameDepIndex (GetPoolDistr _) _
408+
= Nothing
390409

391410
deriving instance Eq (BlockQuery (ShelleyBlock proto era) result)
392411
deriving instance Show (BlockQuery (ShelleyBlock proto era) result)
@@ -413,6 +432,7 @@ instance ShelleyCompatible proto era => ShowQuery (BlockQuery (ShelleyBlock prot
413432
GetStakePoolParams {} -> show
414433
GetRewardInfoPools -> show
415434
GetPoolState {} -> show
435+
GetPoolDistr {} -> show
416436

417437
-- | Is the given query supported by the given 'ShelleyNodeToClientVersion'?
418438
querySupportedVersion :: BlockQuery (ShelleyBlock proto era) result -> ShelleyNodeToClientVersion -> Bool
@@ -437,6 +457,7 @@ querySupportedVersion = \case
437457
GetStakePoolParams {} -> (>= v4)
438458
GetRewardInfoPools -> (>= v5)
439459
GetPoolState {} -> (>= v6)
460+
GetPoolDistr {} -> (>= v6)
440461
-- WARNING: when adding a new query, a new @ShelleyNodeToClientVersionX@
441462
-- must be added. See #2830 for a template on how to do this.
442463
where
@@ -524,6 +545,8 @@ encodeShelleyQuery query = case query of
524545
CBOR.encodeListLen 1 <> CBOR.encodeWord8 18
525546
GetPoolState poolids ->
526547
CBOR.encodeListLen 2 <> CBOR.encodeWord8 19 <> toCBOR poolids
548+
GetPoolDistr poolids ->
549+
CBOR.encodeListLen 2 <> CBOR.encodeWord8 20 <> toCBOR poolids
527550

528551
decodeShelleyQuery ::
529552
ShelleyBasedEra era
@@ -552,6 +575,7 @@ decodeShelleyQuery = do
552575
(2, 17) -> SomeSecond . GetStakePoolParams <$> fromCBOR
553576
(1, 18) -> return $ SomeSecond GetRewardInfoPools
554577
(2, 19) -> SomeSecond . GetPoolState <$> fromCBOR
578+
(2, 20) -> SomeSecond . GetPoolDistr <$> fromCBOR
555579
_ -> fail $
556580
"decodeShelleyQuery: invalid (len, tag): (" <>
557581
show len <> ", " <> show tag <> ")"
@@ -580,6 +604,7 @@ encodeShelleyResult query = case query of
580604
GetStakePoolParams {} -> toCBOR
581605
GetRewardInfoPools -> toCBOR
582606
GetPoolState {} -> toCBOR
607+
GetPoolDistr {} -> toCBOR
583608

584609
decodeShelleyResult ::
585610
ShelleyCompatible proto era
@@ -606,3 +631,4 @@ decodeShelleyResult query = case query of
606631
GetStakePoolParams {} -> fromCBOR
607632
GetRewardInfoPools -> fromCBOR
608633
GetPoolState {} -> fromCBOR
634+
GetPoolDistr {} -> fromCBOR

ouroboros-consensus/docs/interface-CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ may appear out of chronological order.
5656
The internals of each entry are organized similar to
5757
https://keepachangelog.com/en/1.1.0/, adapted to our plan explained above.
5858

59+
## Circa 2022-08-01
60+
61+
### Added
62+
63+
- `GetPoolDistr`: Get the pool distribution for the given stake pool ids
64+
New addition to client version `NodeToClientV_14`
65+
5966
## Circa 2022-07-20
6067

6168
### Fixed

ouroboros-network/src/Ouroboros/Network/NodeToClient/Version.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ data NodeToClientVersion
3535
| NodeToClientV_13
3636
-- ^ enabled @CardanoNodeToClientVersion9@, i.e., Babbage
3737
| NodeToClientV_14
38-
-- ^ added @GetPoolState
38+
-- ^ added @GetPoolDistr, @GetPoolState
3939
deriving (Eq, Ord, Enum, Bounded, Show, Typeable)
4040

4141
-- | We set 16ths bit to distinguish `NodeToNodeVersion` and

0 commit comments

Comments
 (0)