Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

only store the go snapshot in the reward pulser #2533

Merged
merged 1 commit into from
Oct 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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