import Cardano.Ledger.Keys (
+
import qualified Cardano.Ledger.Shelley.HardForks as HardForks
import Cardano.Ledger.Shelley.LedgerState.Types
import Cardano.Ledger.Shelley.RewardUpdate (RewardUpdate (..))
import Cardano.Ledger.Shelley.Rewards (aggregateCompactRewards, aggregateRewards, filterRewards)
-- step2 = aggregate (dom activeDelegs ◁ rewards) step1
-- This function has a non-incremental analog, 'stakeDistr', mosty used in tests, which does use the UTxO.
-
incrementalStakeDistr incstake ds ps =
+
incrementalStakeDistr pp (IStake credStake ptrStake) ds ps =
(Stake $ VMap.fromMap (compactCoinOrError <$> step2))
UMap tripmap ptrmap = dsUnified ds
PState {psStakePoolParams = poolParams} = ps
delegs_ = UM.viewToVMap (delegations ds)
-
-- A credential is active, only if it is being delegated
-
step1 = resolveActiveIncrementalPtrs (`VMap.member` delegs_) ptrmap incstake
+
-- A credential is active, only if it is being delegated: (dom activeDelegs ◁ credStake)
+
activeCreds = Map.filterWithKey (\k _ -> VMap.member k delegs_) credStake
+
ignorePtrs = HardForks.forgoPointerAddressResolution (pp ^. ppProtocolVersionL)
+
else resolveActiveIncrementalPtrs (`VMap.member` delegs_) ptrmap (IStake activeCreds ptrStake)
step2 = aggregateActiveStake tripmap step1
-- | Resolve inserts and deletes which were indexed by Ptrs, by looking them
Map (Credential 'Staking c) Coin
resolveActiveIncrementalPtrs isActive ptrMap_ (IStake credStake ptrStake) =
-
Map.foldlWithKey' accum step1A ptrStake -- step1A ∪ (dom activeDelegs ◁ ptrStake)
+
Map.foldlWithKey' accum credStake ptrStake -- step1A ∪ (dom activeDelegs ◁ ptrStake)
-
-- (dom activeDelegs ◁ credStake)
-
step1A = Map.filterWithKey (\k _ -> isActive k) credStake
case Map.lookup ptr ptrMap_ of -- Map ptrs to Credentials