Skip to content

Commit f931d94

Browse files
authored
Add GetSPOStakeDistr query (#1139)
2 parents 91d36ca + 1232297 commit f931d94

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### Breaking
2+
3+
- Added `GetSPOStakeDistr` query

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,17 @@ data instance BlockQuery (ShelleyBlock proto era) :: Type -> Type where
287287
GetAccountState
288288
:: BlockQuery (ShelleyBlock proto era) AccountState
289289

290+
-- | Query the SPO voting stake distribution.
291+
-- This stake distribution is different from the one used in leader election.
292+
--
293+
-- See: https://github.com/IntersectMBO/cardano-ledger/issues/4342
294+
--
295+
-- Not supported in eras before Conway.
296+
GetSPOStakeDistr
297+
:: CG.ConwayEraGov era
298+
=> Set (KeyHash 'StakePool (EraCrypto era))
299+
-> BlockQuery (ShelleyBlock proto era) (Map (KeyHash 'StakePool (EraCrypto era)) Coin)
300+
290301
-- WARNING: please add new queries to the end of the list and stick to this
291302
-- order in all other pattern matches on queries. This helps in particular
292303
-- with the en/decoders, as we want the CBOR tags to be ordered.
@@ -441,6 +452,8 @@ instance (ShelleyCompatible proto era, ProtoCrypto proto ~ crypto)
441452
getFilteredVoteDelegatees st stakeCreds
442453
GetAccountState ->
443454
SL.queryAccountState st
455+
GetSPOStakeDistr keys ->
456+
SL.querySPOStakeDistr st keys
444457
where
445458
lcfg = configLedger $ getExtLedgerCfg cfg
446459
globals = shelleyLedgerGlobals lcfg
@@ -594,6 +607,8 @@ instance SameDepIndex (BlockQuery (ShelleyBlock proto era)) where
594607
sameDepIndex GetFilteredVoteDelegatees {} _ = Nothing
595608
sameDepIndex GetAccountState {} GetAccountState {} = Just Refl
596609
sameDepIndex GetAccountState {} _ = Nothing
610+
sameDepIndex GetSPOStakeDistr{} GetSPOStakeDistr{} = Just Refl
611+
sameDepIndex GetSPOStakeDistr{} _ = Nothing
597612

598613
deriving instance Eq (BlockQuery (ShelleyBlock proto era) result)
599614
deriving instance Show (BlockQuery (ShelleyBlock proto era) result)
@@ -630,6 +645,7 @@ instance ShelleyCompatible proto era => ShowQuery (BlockQuery (ShelleyBlock prot
630645
GetCommitteeMembersState {} -> show
631646
GetFilteredVoteDelegatees {} -> show
632647
GetAccountState {} -> show
648+
GetSPOStakeDistr {} -> show
633649

634650
-- | Is the given query supported by the given 'ShelleyNodeToClientVersion'?
635651
querySupportedVersion :: BlockQuery (ShelleyBlock proto era) result -> ShelleyNodeToClientVersion -> Bool
@@ -664,6 +680,7 @@ querySupportedVersion = \case
664680
GetCommitteeMembersState {} -> (>= v8)
665681
GetFilteredVoteDelegatees {} -> (>= v8)
666682
GetAccountState {} -> (>= v8)
683+
GetSPOStakeDistr {} -> (>= v8)
667684
-- WARNING: when adding a new query, a new @ShelleyNodeToClientVersionX@
668685
-- must be added. See #2830 for a template on how to do this.
669686
where
@@ -787,6 +804,8 @@ encodeShelleyQuery query = case query of
787804
CBOR.encodeListLen 2 <> CBOR.encodeWord8 28 <> LC.toEraCBOR @era stakeCreds
788805
GetAccountState ->
789806
CBOR.encodeListLen 1 <> CBOR.encodeWord8 29
807+
GetSPOStakeDistr keys ->
808+
CBOR.encodeListLen 2 <> CBOR.encodeWord8 30 <> LC.toEraCBOR @era keys
790809

791810
decodeShelleyQuery ::
792811
forall era proto. ShelleyBasedEra era
@@ -844,6 +863,7 @@ decodeShelleyQuery = do
844863
(2, 28) -> requireCG $ do
845864
SomeSecond . GetFilteredVoteDelegatees <$> LC.fromEraCBOR @era
846865
(1, 29) -> return $ SomeSecond GetAccountState
866+
(2, 30) -> requireCG $ SomeSecond . GetSPOStakeDistr <$> LC.fromEraCBOR @era
847867
_ -> failmsg "invalid"
848868

849869
encodeShelleyResult ::
@@ -881,6 +901,7 @@ encodeShelleyResult v query = case query of
881901
GetCommitteeMembersState {} -> LC.toEraCBOR @era
882902
GetFilteredVoteDelegatees {} -> LC.toEraCBOR @era
883903
GetAccountState {} -> LC.toEraCBOR @era
904+
GetSPOStakeDistr {} -> LC.toEraCBOR @era
884905

885906
decodeShelleyResult ::
886907
forall proto era result. ShelleyCompatible proto era
@@ -918,6 +939,7 @@ decodeShelleyResult v query = case query of
918939
GetCommitteeMembersState {} -> LC.fromEraCBOR @era
919940
GetFilteredVoteDelegatees {} -> LC.fromEraCBOR @era
920941
GetAccountState {} -> LC.fromEraCBOR @era
942+
GetSPOStakeDistr {} -> LC.fromEraCBOR @era
921943

922944
currentPParamsEnDecoding ::
923945
forall era s.

0 commit comments

Comments
 (0)