Skip to content

Commit c38499b

Browse files
committed
Force calculation of rewards
TODO: this needs simplification
1 parent 02aaaca commit c38499b

File tree

1 file changed

+44
-0
lines changed
  • cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic

1 file changed

+44
-0
lines changed

cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/Rewards.hs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,29 @@ module Cardano.DbSync.Era.Shelley.Generic.Rewards (
1010
RewardRests (..),
1111
rewardsCount,
1212
rewardsTotalAda,
13+
getRewardsUpdate,
1314
) where
1415

1516
import Cardano.Db (Ada, RewardSource (..), word64ToAda)
1617
import Cardano.DbSync.Types
18+
import Cardano.Ledger.BaseTypes (strictMaybeToMaybe)
1719
import Cardano.Ledger.Coin (Coin (..))
20+
import Cardano.Ledger.Crypto (StandardCrypto)
21+
import Cardano.Ledger.Shelley.LedgerState hiding (LedgerState)
1822
import Cardano.Prelude
1923
import qualified Data.Map.Strict as Map
24+
import Data.SOP.Strict.NP
2025
import qualified Data.Set as Set
26+
import Ouroboros.Consensus.Cardano.Block (EraCrypto, LedgerState (..))
2127
import Ouroboros.Consensus.Cardano.CanHardFork ()
28+
import Ouroboros.Consensus.Config (TopLevelConfig (..))
29+
import Ouroboros.Consensus.HardFork.Combinator.AcrossEras
30+
import Ouroboros.Consensus.HardFork.Combinator.Basics
31+
import Ouroboros.Consensus.HardFork.Combinator.PartialConfig
32+
import Ouroboros.Consensus.Ledger.Extended (ExtLedgerState (..))
33+
import Ouroboros.Consensus.Shelley.Ledger (ShelleyBlock)
34+
import Ouroboros.Consensus.Shelley.Ledger.Ledger
35+
import Ouroboros.Consensus.Shelley.ShelleyHFC
2236

2337
data Reward = Reward
2438
{ rewardSource :: !RewardSource
@@ -53,3 +67,33 @@ rewardsTotalAda rwds =
5367
. sum
5468
. concatMap (map (unCoin . rewardAmount) . Set.toList)
5569
$ Map.elems (unRewards rwds)
70+
71+
getRewardsUpdate :: TopLevelConfig CardanoBlock -> ExtLedgerState CardanoBlock -> Maybe (RewardUpdate StandardCrypto)
72+
getRewardsUpdate cfg els =
73+
case ledgerState els of
74+
LedgerStateByron _ -> Nothing
75+
LedgerStateShelley sls -> genericRewardUpdate cfg sls
76+
LedgerStateAllegra als -> genericRewardUpdate cfg als
77+
LedgerStateMary mls -> genericRewardUpdate cfg mls
78+
LedgerStateAlonzo als -> genericRewardUpdate cfg als
79+
LedgerStateBabbage bls -> genericRewardUpdate cfg bls
80+
LedgerStateConway cls -> genericRewardUpdate cfg cls
81+
82+
genericRewardUpdate ::
83+
forall era p.
84+
(EraCrypto era ~ StandardCrypto) =>
85+
TopLevelConfig CardanoBlock ->
86+
LedgerState (ShelleyBlock p era) ->
87+
Maybe (RewardUpdate StandardCrypto)
88+
genericRewardUpdate cfg lstate = do
89+
pulsing <- strictMaybeToMaybe mPulsing
90+
case pulsing of
91+
Complete _ -> Nothing
92+
Pulsing _ _ -> do
93+
let Identity (rewardUpdate, _) = runReaderT (completeRupd pulsing) globals
94+
Just rewardUpdate
95+
where
96+
mPulsing = nesRu $ shelleyLedgerState lstate
97+
98+
globals = case getPerEraLedgerConfig $ hardForkLedgerConfigPerEra $ topLevelConfigLedger cfg of
99+
_ :* wplc :* _ -> shelleyLedgerGlobals $ shelleyLedgerConfig $ unwrapPartialLedgerConfig wplc

0 commit comments

Comments
 (0)