From e0f1ed1a2635006490b64aa5ca0776e51917db60 Mon Sep 17 00:00:00 2001 From: Jared Corduan Date: Wed, 27 Oct 2021 20:51:06 -0400 Subject: [PATCH] only store the go snapshot in the reward pulser And also the fees in the 'SnapShots'. --- .../src/Cardano/Ledger/Shelley/LedgerState.hs | 10 +++--- .../Cardano/Ledger/Shelley/RewardUpdate.hs | 32 ++++++++++++++++--- .../Serialisation/EraIndepGenerators.hs | 1 + .../src/Cardano/Ledger/Pretty.hs | 5 +-- 4 files changed, 37 insertions(+), 11 deletions(-) diff --git a/eras/shelley/impl/src/Cardano/Ledger/Shelley/LedgerState.hs b/eras/shelley/impl/src/Cardano/Ledger/Shelley/LedgerState.hs index b55d868040a..35fb96bbd52 100644 --- a/eras/shelley/impl/src/Cardano/Ledger/Shelley/LedgerState.hs +++ b/eras/shelley/impl/src/Cardano/Ledger/Shelley/LedgerState.hs @@ -1153,7 +1153,8 @@ startStep slotsPerEpoch b@(BlocksMade b') es@(EpochState acnt ss ls pr _ nm) max totalStake = circulation es maxSupply rewsnap = RewardSnapShot - { rewSnapshots = ss, + { rewSnapshot = _pstakeGo ss, + rewFees = _feeSS ss, rewa0 = getField @"_a0" pr, rewnOpt = getField @"_nOpt" pr, rewprotocolVersion = getField @"_protocolVersion" pr, @@ -1246,12 +1247,13 @@ completeRupd ( Pulsing rewsnap@RewardSnapShot { rewDeltaR1 = deltaR1, + rewFees = feesSS, rewR = oldr, rewDeltaT1 = (Coin deltaT1), rewNonMyopic = nm, rewTotalStake = totalstake, rewRPot = rpot, - rewSnapshots = snaps, + rewSnapshot = snap, rewa0 = a0, rewnOpt = nOpt } @@ -1266,7 +1268,7 @@ completeRupd -- A function to compute the 'desirablity' aggregate. Called only if we are computing -- provenance. Adds nested pair ('key',(LikeliHoodEstimate,Desirability)) to the Map 'ans' addDesireability ans key likelihood = - let SnapShot _ _ poolParams = _pstakeGo snaps + let SnapShot _ _ poolParams = snap estimate = percentile' likelihood in Map.insert key @@ -1285,7 +1287,7 @@ completeRupd { deltaT = DeltaCoin deltaT1, deltaR = invert (toDeltaCoin deltaR1) <> toDeltaCoin deltaR2, rs = rs_, - deltaF = invert (toDeltaCoin $ _feeSS snaps), + deltaF = invert (toDeltaCoin feesSS), nonMyopic = updateNonMyopic nm oldr newLikelihoods } diff --git a/eras/shelley/impl/src/Cardano/Ledger/Shelley/RewardUpdate.hs b/eras/shelley/impl/src/Cardano/Ledger/Shelley/RewardUpdate.hs index 7b17617d0a0..2372fa4ed9d 100644 --- a/eras/shelley/impl/src/Cardano/Ledger/Shelley/RewardUpdate.hs +++ b/eras/shelley/impl/src/Cardano/Ledger/Shelley/RewardUpdate.hs @@ -36,7 +36,7 @@ import qualified Cardano.Ledger.Crypto as CC (Crypto) import Cardano.Ledger.Keys (KeyHash, KeyRole (..)) import Cardano.Ledger.Serialization (decodeRecordNamed) import Cardano.Ledger.Shelley.EpochBoundary - ( SnapShots (..), + ( SnapShot (..), Stake (..), poolStake, ) @@ -160,7 +160,8 @@ emptyRewardUpdate = -- | To pulse the reward update, we need a snap shot of the EpochState particular to this computation data RewardSnapShot crypto = RewardSnapShot - { rewSnapshots :: !(SnapShots crypto), + { rewSnapshot :: !(SnapShot crypto), + rewFees :: !Coin, rewa0 :: !NonNegativeInterval, rewnOpt :: !Natural, rewprotocolVersion :: !ProtVer, @@ -178,9 +179,16 @@ instance NoThunks (RewardSnapShot crypto) instance NFData (RewardSnapShot crypto) instance CC.Crypto crypto => ToCBOR (RewardSnapShot crypto) where - toCBOR (RewardSnapShot ss a0 nopt ver nm dr1 r dt1 tot pot) = + toCBOR (RewardSnapShot ss fees a0 nopt ver nm dr1 r dt1 tot pot) = encode - ( Rec RewardSnapShot !> To ss !> E boundedRationalToCBOR a0 !> To nopt !> To ver !> To nm !> To dr1 + ( Rec RewardSnapShot + !> To ss + !> To fees + !> E boundedRationalToCBOR a0 + !> To nopt + !> To ver + !> To nm + !> To dr1 !> To r !> To dt1 !> To tot @@ -188,7 +196,21 @@ instance CC.Crypto crypto => ToCBOR (RewardSnapShot crypto) where ) instance CC.Crypto crypto => FromCBOR (RewardSnapShot crypto) where - fromCBOR = decode (RecD RewardSnapShot arbitrary <*> arbitrary <*> arbitrary + <*> arbitrary instance Mock crypto => diff --git a/libs/cardano-ledger-pretty/src/Cardano/Ledger/Pretty.hs b/libs/cardano-ledger-pretty/src/Cardano/Ledger/Pretty.hs index 089ebf993d5..d4764c2b309 100644 --- a/libs/cardano-ledger-pretty/src/Cardano/Ledger/Pretty.hs +++ b/libs/cardano-ledger-pretty/src/Cardano/Ledger/Pretty.hs @@ -490,10 +490,11 @@ ppRewardUpdate (RewardUpdate dt dr rss df nonmyop) = ] ppRewardSnapShot :: RewardSnapShot crypto -> PDoc -ppRewardSnapShot (RewardSnapShot snaps a0 nopt ver non deltaR1 rR deltaT1 total pot) = +ppRewardSnapShot (RewardSnapShot snap fee a0 nopt ver non deltaR1 rR deltaT1 total pot) = ppRecord "RewardSnapShot" - [ ("snapshots", ppSnapShots snaps), + [ ("snapshots", ppSnapShot snap), + ("fees", ppCoin fee), ("a0", ppRational $ unboundRational a0), ("nOpt", ppNatural nopt), ("version", ppProtVer ver),