IntersectMBO / IntersectMBO/cardano-ledger

Fix computation of voting stake for stake pools without any delegations

Open
#6,061 0 comments 0 reactions 1 assignee Claimed by @neilmayhew View on GitHub
Dominant language
Haskell
Stars
295
Forks
179
Avg merge
4d 7h
Merged PRs (30d)
29

Description

Originally observed by Copilot:

`addToPoolDistr` currently drops proposal deposits when the delegated pool is missing from `vpoolDistrAmountsL` (because of the `Map.lookup` guard). This can undercount voting stake for credentials that have proposal deposits but zero active stake, since such pools may not appear in the snapshot map. Prefer inserting with a default instead of requiring a pre-existing entry.

Here how to properly solved this in here:

```haskell
...
addToPoolDistr accountState mProposalDeposit distr = fromMaybe distr $ do
stakePool <- accountState ^. stakePoolDelegationAccountStateL
proposalDeposit <- mProposalDeposit
ips <-
case Map.lookup stakePool $ distr ^. vspdIndividualStakeL of
Just ips -> Just ips
Nothing -> do
guard (curProtVer >= natVersion @12)
Just mempty
pure $
distr
& vspdIndividualStakeL %~ Map.insert stakePool (ips <> proposalDeposit)
& vspdTotalVotingStakeL %~ \t -> unsafeNonZero (unNonZero t <> fromCompact proposalDeposit)
...
```

Current protocol version can be extracted from `EnactState`, since it is available in `DRepPulser`: https://github.com/IntersectMBO/cardano-ledger/blob/86fdafe08c16ce0a48eb0b33a8331d6db2bb48a3/eras/conway/impl/src/Cardano/Ledger/Conway/Governance/DRepPulser.hs#L272

_Originally posted by @lehins in [#6054](https://github.com/IntersectMBO/cardano-ledger/pull/6054/changes#r3959508426)_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.