Skip to content

Commit

Permalink
consensus query for ledger reward provenance
Browse files Browse the repository at this point in the history
This commit adds a new consensus query which returns a lot of data
surrounding the reward calculation in the ledger. There is data
concerning the overall calculation, but also detailed information about
each individual stake pool's rewards and performance.
  • Loading branch information
JaredCorduan committed Dec 21, 2020
1 parent 1a66429 commit 1762372
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ source-repository-package
source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-ledger-specs
tag: 5dc8d805bf7f63fe24c919c4b016b4d591abe66e
--sha256: 14985r1sn1bbjdn1bami4aahza5vm29aj6psz2zyvichhcma90vn
tag: cf3b01490a2cc7ebbb5ac6f7a4de79e8b1d5c70f
--sha256:1v15xqy0qvb7ll4080pplrq2ygqgnf443kaq5i6mj0105941mcjc
subdir:
byron/chain/executable-spec
byron/crypto
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import Ouroboros.Consensus.Util (ShowProxy (..))

import qualified Shelley.Spec.Ledger.API as SL
import qualified Shelley.Spec.Ledger.LedgerState as SL (RewardAccounts)
import qualified Shelley.Spec.Ledger.RewardProvenance as SL (RewardProvenance)

import Ouroboros.Consensus.Shelley.Eras (EraCrypto)
import Ouroboros.Consensus.Shelley.Ledger.Block
Expand Down Expand Up @@ -85,6 +86,8 @@ data instance Query (ShelleyBlock era) :: Type -> Type where
GetNonMyopicMemberRewards
:: Set (Either SL.Coin (SL.Credential 'SL.Staking (EraCrypto era)))
-> Query (ShelleyBlock era) (NonMyopicMemberRewards (EraCrypto era))
GetRewardProvenance
:: Query (ShelleyBlock era) (SL.RewardProvenance (EraCrypto era))
GetCurrentPParams
:: Query (ShelleyBlock era) (SL.PParams era)
GetProposedPParamsUpdates
Expand Down Expand Up @@ -154,6 +157,8 @@ instance ShelleyBasedEra era => QueryLedger (ShelleyBlock era) where
GetNonMyopicMemberRewards creds ->
NonMyopicMemberRewards $
SL.getNonMyopicMemberRewards globals st creds
GetRewardProvenance ->
snd $ SL.getRewardInfo globals st
GetCurrentPParams ->
getPParams st
GetProposedPParamsUpdates ->
Expand Down Expand Up @@ -207,6 +212,8 @@ instance SameDepIndex (Query (ShelleyBlock era)) where
= Nothing
sameDepIndex (GetNonMyopicMemberRewards _) _
= Nothing
sameDepIndex GetRewardProvenance _
= Nothing
sameDepIndex GetCurrentPParams GetCurrentPParams
= Just Refl
sameDepIndex GetCurrentPParams _
Expand Down Expand Up @@ -267,6 +274,7 @@ instance ShelleyBasedEra era => ShowQuery (Query (ShelleyBlock era)) where
GetLedgerTip -> show
GetEpochNo -> show
GetNonMyopicMemberRewards {} -> show
GetRewardProvenance -> show
GetCurrentPParams -> show
GetProposedPParamsUpdates -> show
GetStakeDistribution -> show
Expand All @@ -285,6 +293,7 @@ querySupportedVersion = \case
GetLedgerTip -> (>= v1)
GetEpochNo -> (>= v1)
GetNonMyopicMemberRewards {} -> (>= v1)
GetRewardProvenance -> (>= v2)
GetCurrentPParams -> (>= v1)
GetProposedPParamsUpdates -> (>= v1)
GetStakeDistribution -> (>= v1)
Expand Down Expand Up @@ -362,6 +371,8 @@ encodeShelleyQuery query = case query of
CBOR.encodeListLen 1 <> CBOR.encodeWord8 12
DebugChainDepState ->
CBOR.encodeListLen 1 <> CBOR.encodeWord8 13
GetRewardProvenance ->
CBOR.encodeListLen 1 <> CBOR.encodeWord8 14

decodeShelleyQuery ::
ShelleyBasedEra era
Expand All @@ -384,6 +395,7 @@ decodeShelleyQuery = do
(1, 11) -> return $ SomeSecond GetGenesisConfig
(1, 12) -> return $ SomeSecond DebugNewEpochState
(1, 13) -> return $ SomeSecond DebugChainDepState
(1, 14) -> return $ SomeSecond GetRewardProvenance
_ -> fail $
"decodeShelleyQuery: invalid (len, tag): (" <>
show len <> ", " <> show tag <> ")"
Expand All @@ -406,6 +418,7 @@ encodeShelleyResult query = case query of
GetGenesisConfig -> toCBOR
DebugNewEpochState -> toCBOR
DebugChainDepState -> toCBOR
GetRewardProvenance -> toCBOR

decodeShelleyResult ::
ShelleyBasedEra era
Expand All @@ -426,3 +439,4 @@ decodeShelleyResult query = case query of
GetGenesisConfig -> fromCBOR
DebugNewEpochState -> fromCBOR
DebugChainDepState -> fromCBOR
GetRewardProvenance -> fromCBOR

0 comments on commit 1762372

Please sign in to comment.