Skip to content

Commit

Permalink
Merge pull request #2533 from input-output-hk/jc/pulser-only-store-on…
Browse files Browse the repository at this point in the history
…e-snapshot

only store the go snapshot in the reward pulser
  • Loading branch information
Jared Corduan authored Oct 28, 2021
2 parents 58e5424 + e0f1ed1 commit 29d19cd
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 11 deletions.
10 changes: 6 additions & 4 deletions eras/shelley/impl/src/Cardano/Ledger/Shelley/LedgerState.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
}
Expand All @@ -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
Expand All @@ -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
}

Expand Down
32 changes: 27 additions & 5 deletions eras/shelley/impl/src/Cardano/Ledger/Shelley/RewardUpdate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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,
Expand All @@ -178,17 +179,38 @@ 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
!> To pot
)

instance CC.Crypto crypto => FromCBOR (RewardSnapShot crypto) where
fromCBOR = decode (RecD RewardSnapShot <! From <! D boundedRationalFromCBOR <! From <! From <! From <! From <! From <! From <! From <! From)
fromCBOR =
decode
( RecD RewardSnapShot
<! From
<! From
<! D boundedRationalFromCBOR
<! From
<! From
<! From
<! From
<! From
<! From
<! From
<! From
)

-- Some functions that only need a subset of the PParams can be
-- passed a RewardSnapShot, as it copies of some values from PParams
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,7 @@ instance
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary

instance
Mock crypto =>
Expand Down
5 changes: 3 additions & 2 deletions libs/cardano-ledger-pretty/src/Cardano/Ledger/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 29d19cd

Please sign in to comment.