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

Reward event to distinguish members and leaders #2536

Merged
merged 1 commit into from
Nov 3, 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
11 changes: 7 additions & 4 deletions eras/shelley/impl/src/Cardano/Ledger/Shelley/LedgerState.hs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ import Cardano.Ledger.Shelley.Rewards
( Likelihood (..),
NonMyopic (..),
PerformanceEstimate (..),
Reward,
aggregateRewards,
applyDecay,
desirability,
Expand Down Expand Up @@ -1025,7 +1026,7 @@ applyRUpd' ::
) =>
RewardUpdate (Crypto era) ->
EpochState era ->
(EpochState era, Map (Credential 'Staking (Crypto era)) Coin)
(EpochState era, Map (Credential 'Staking (Crypto era)) (Set (Reward (Crypto era))))
applyRUpd'
ru
(EpochState as ss ls pr pp _nm) = (EpochState as' ss ls' pr pp nm', regRU)
Expand All @@ -1036,10 +1037,12 @@ applyRUpd'
(regRU, unregRU) =
Map.partitionWithKey
(\k _ -> eval (k ∈ dom (_rewards dState)))
(aggregateRewards pr $ rs ru)
(rs ru)
totalUnregistered = fold $ aggregateRewards pr unregRU
registered = aggregateRewards pr regRU
as' =
as
{ _treasury = addDeltaCoin (_treasury as) (deltaT ru) <> fold unregRU,
{ _treasury = addDeltaCoin (_treasury as) (deltaT ru) <> totalUnregistered,
_reserves = addDeltaCoin (_reserves as) (deltaR ru)
}
ls' =
Expand All @@ -1050,7 +1053,7 @@ applyRUpd'
delegState
{ _dstate =
dState
{ _rewards = eval (_rewards dState ∪+ regRU)
{ _rewards = eval (_rewards dState ∪+ registered)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import Cardano.Ledger.PoolDistr (IndividualPoolStake (..), PoolDistr (..))
import Cardano.Ledger.Shelley.Constraints (UsesTxOut, UsesValue)
import Cardano.Ledger.Shelley.EpochBoundary
import Cardano.Ledger.Shelley.LedgerState
import Cardano.Ledger.Shelley.Rewards (sumRewards)
import Cardano.Ledger.Shelley.Rewards (Reward, sumRewards)
import Cardano.Ledger.Shelley.Rules.Epoch
import Cardano.Ledger.Shelley.Rules.Mir
import Cardano.Ledger.Shelley.TxBody
Expand All @@ -41,6 +41,7 @@ import Control.State.Transition
import Data.Default.Class (Default, def)
import qualified Data.Map.Strict as Map
import Data.Maybe (catMaybes)
import Data.Set (Set)
import GHC.Generics (Generic)
import GHC.Records
import NoThunks.Class (NoThunks (..))
Expand Down Expand Up @@ -73,7 +74,7 @@ instance
NoThunks (NewEpochPredicateFailure era)

data NewEpochEvent era
= SumRewards !EpochNo !(Map.Map (Credential 'Staking (Crypto era)) Coin)
= RewardEvent !EpochNo !(Map.Map (Credential 'Staking (Crypto era)) (Set (Reward (Crypto era))))
| EpochEvent (Event (Core.EraRule "EPOCH" era))
| MirEvent (Event (Core.EraRule "MIR" era))

Expand Down Expand Up @@ -149,7 +150,7 @@ newEpochTransition = do
let totRs = sumRewards (esPrevPp es) rs_
Val.isZero (dt <> (dr <> toDeltaCoin totRs <> df)) ?! CorruptRewardUpdate ru'
let (es', regRU) = applyRUpd' ru' es
tellEvent $ SumRewards e regRU
tellEvent $ RewardEvent e regRU
pure es'
es' <- case ru of
SNothing -> pure es
Expand Down