@@ -193,6 +193,11 @@ data instance BlockQuery (ShelleyBlock proto era) :: Type -> Type where
193
193
-> BlockQuery (ShelleyBlock proto era )
194
194
(SL. PState (EraCrypto era ))
195
195
196
+ GetPoolDistr
197
+ :: Maybe (Set (SL. KeyHash 'SL.StakePool (EraCrypto era )))
198
+ -> BlockQuery (ShelleyBlock proto era )
199
+ (SL. PoolDistr (EraCrypto era ))
200
+
196
201
-- WARNING: please add new queries to the end of the list and stick to this
197
202
-- order in all other pattern matches on queries. This helps in particular
198
203
-- 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
273
278
, SL. _retiring = Map. restrictKeys (SL. _retiring dpsPState) poolIds
274
279
}
275
280
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
276
286
where
277
287
lcfg = configLedger $ getExtLedgerCfg cfg
278
288
globals = shelleyLedgerGlobals lcfg
@@ -287,6 +297,8 @@ instance ShelleyCompatible proto era => QueryLedger (ShelleyBlock proto era) whe
287
297
hst = headerState ext
288
298
st = shelleyLedgerState lst
289
299
300
+
301
+
290
302
instance SameDepIndex (BlockQuery (ShelleyBlock proto era )) where
291
303
sameDepIndex GetLedgerTip GetLedgerTip
292
304
= Just Refl
@@ -387,6 +399,13 @@ instance SameDepIndex (BlockQuery (ShelleyBlock proto era)) where
387
399
= Nothing
388
400
sameDepIndex (GetPoolState _) _
389
401
= Nothing
402
+ sameDepIndex (GetPoolDistr poolids) (GetPoolDistr poolids')
403
+ | poolids == poolids'
404
+ = Just Refl
405
+ | otherwise
406
+ = Nothing
407
+ sameDepIndex (GetPoolDistr _) _
408
+ = Nothing
390
409
391
410
deriving instance Eq (BlockQuery (ShelleyBlock proto era ) result )
392
411
deriving instance Show (BlockQuery (ShelleyBlock proto era ) result )
@@ -413,6 +432,7 @@ instance ShelleyCompatible proto era => ShowQuery (BlockQuery (ShelleyBlock prot
413
432
GetStakePoolParams {} -> show
414
433
GetRewardInfoPools -> show
415
434
GetPoolState {} -> show
435
+ GetPoolDistr {} -> show
416
436
417
437
-- | Is the given query supported by the given 'ShelleyNodeToClientVersion'?
418
438
querySupportedVersion :: BlockQuery (ShelleyBlock proto era ) result -> ShelleyNodeToClientVersion -> Bool
@@ -437,6 +457,7 @@ querySupportedVersion = \case
437
457
GetStakePoolParams {} -> (>= v4)
438
458
GetRewardInfoPools -> (>= v5)
439
459
GetPoolState {} -> (>= v6)
460
+ GetPoolDistr {} -> (>= v6)
440
461
-- WARNING: when adding a new query, a new @ShelleyNodeToClientVersionX@
441
462
-- must be added. See #2830 for a template on how to do this.
442
463
where
@@ -524,6 +545,8 @@ encodeShelleyQuery query = case query of
524
545
CBOR. encodeListLen 1 <> CBOR. encodeWord8 18
525
546
GetPoolState poolids ->
526
547
CBOR. encodeListLen 2 <> CBOR. encodeWord8 19 <> toCBOR poolids
548
+ GetPoolDistr poolids ->
549
+ CBOR. encodeListLen 2 <> CBOR. encodeWord8 20 <> toCBOR poolids
527
550
528
551
decodeShelleyQuery ::
529
552
ShelleyBasedEra era
@@ -552,6 +575,7 @@ decodeShelleyQuery = do
552
575
(2 , 17 ) -> SomeSecond . GetStakePoolParams <$> fromCBOR
553
576
(1 , 18 ) -> return $ SomeSecond GetRewardInfoPools
554
577
(2 , 19 ) -> SomeSecond . GetPoolState <$> fromCBOR
578
+ (2 , 20 ) -> SomeSecond . GetPoolDistr <$> fromCBOR
555
579
_ -> fail $
556
580
" decodeShelleyQuery: invalid (len, tag): (" <>
557
581
show len <> " , " <> show tag <> " )"
@@ -580,6 +604,7 @@ encodeShelleyResult query = case query of
580
604
GetStakePoolParams {} -> toCBOR
581
605
GetRewardInfoPools -> toCBOR
582
606
GetPoolState {} -> toCBOR
607
+ GetPoolDistr {} -> toCBOR
583
608
584
609
decodeShelleyResult ::
585
610
ShelleyCompatible proto era
@@ -606,3 +631,4 @@ decodeShelleyResult query = case query of
606
631
GetStakePoolParams {} -> fromCBOR
607
632
GetRewardInfoPools -> fromCBOR
608
633
GetPoolState {} -> fromCBOR
634
+ GetPoolDistr {} -> fromCBOR
0 commit comments