Skip to content

Commit

Permalink
Report pool size based on most recent ledger state
Browse files Browse the repository at this point in the history
instead of based on a regular snapshot.
  • Loading branch information
kantp committed Sep 15, 2020
1 parent d758f18 commit 83cb520
Showing 1 changed file with 21 additions and 7 deletions.
Expand Up @@ -63,12 +63,13 @@ import Shelley.Spec.Ledger.UTxO (UTxO (..))
-- affected by undelegated stake), but the wallet wants to display pool
-- saturation for rewards purposes. For that, it needs the fraction of total
-- stake.
poolsByTotalStakeFraction :: Globals -> ShelleyState era -> PoolDistr era
--
-- This is not based on any snapshot, but uses the current ledger state.
poolsByTotalStakeFraction :: Era era => Globals -> ShelleyState era -> PoolDistr era
poolsByTotalStakeFraction globals ss =
PoolDistr poolsByTotalStake
where
EpochState _ ss' _ _ _ _ = nesEs ss
EB.SnapShot stake _ _ = EB._pstakeGo ss'
EB.SnapShot stake _ _ = currentSnapshot ss
Coin totalStake = getTotalStake globals ss
Coin activeStake = fold . EB.unStake $ stake
stakeRatio = activeStake % totalStake
Expand All @@ -89,6 +90,8 @@ getTotalStake globals ss =
-- For each given credential, this function returns a map from each stake
-- pool (identified by the key hash of the pool operator) to the
-- non-myopic pool member reward for that stake pool.
--
-- This is not based on any snapshot, but uses the current ledger state.
getNonMyopicMemberRewards ::
Era era =>
Globals ->
Expand All @@ -112,10 +115,7 @@ getNonMyopicMemberRewards globals ss creds =
{ likelihoodsNM = ls,
rewardPotNM = rPot
} = esNonMyopic es
utxo = _utxo . _utxoState . esLState $ es
dstate = _dstate . _delegationState . esLState $ es
pstate = _pstate . _delegationState . esLState $ es
EB.SnapShot stake delegs poolParams = stakeDistr utxo dstate pstate
EB.SnapShot stake delegs poolParams = currentSnapshot ss
poolData =
Map.mapWithKey
(\k p -> (percentile' (histLookup k), p, toShare . fold . EB.unStake $ EB.poolStake k delegs stake))
Expand All @@ -142,6 +142,20 @@ getNonMyopicMemberRewards globals ss creds =
(_poolOwners pool)
in _poolPledge poolp <= ostake

-- | Create a current snapshot of the ledger state.
--
-- When ranking pools, and reporting their saturation level, in the wallet, we
-- do not want to use one of the regular snapshots, but rather the most recent
-- ledger state.
currentSnapshot :: Era era => ShelleyState era -> EB.SnapShot era
currentSnapshot ss =
stakeDistr utxo dstate pstate
where
es = nesEs ss
utxo = _utxo . _utxoState . esLState $ es
dstate = _dstate . _delegationState . esLState $ es
pstate = _pstate . _delegationState . esLState $ es

-- | Get the full UTxO.
getUTxO ::
ShelleyState era ->
Expand Down

0 comments on commit 83cb520

Please sign in to comment.