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

Add GovRemovedVotes event #4661

Merged
merged 2 commits into from
Oct 15, 2024
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
4 changes: 2 additions & 2 deletions eras/conway/impl/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Version history for `cardano-ledger-conway`

## 1.17.0.1
## 1.18.0.0

*
* Add new event `GovRemovedVotes` for invalidated votes

## 1.17.0.0

Expand Down
2 changes: 1 addition & 1 deletion eras/conway/impl/cardano-ledger-conway.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 3.0
name: cardano-ledger-conway
version: 1.17.0.0
version: 1.18.0.0
license: Apache-2.0
maintainer: operations@iohk.io
author: IOHK
Expand Down
29 changes: 23 additions & 6 deletions eras/conway/impl/src/Cardano/Ledger/Conway/Rules/Gov.hs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ import qualified Data.Map.Strict as Map
import qualified Data.OSet.Strict as OSet
import Data.Pulse (foldlM')
import qualified Data.Sequence.Strict as SSeq
import Data.Set (Set)
import qualified Data.Set as Set
import GHC.Generics (Generic)
import Lens.Micro
Expand Down Expand Up @@ -290,6 +291,12 @@ instance EraPParams era => FromCBOR (ConwayGovPredFailure era) where

data ConwayGovEvent era
= GovNewProposals !(TxId (EraCrypto era)) !(Proposals era)
| GovRemovedVotes
!(TxId (EraCrypto era))
-- | Votes that were replaced in this tx.
!(Set (Voter (EraCrypto era), GovActionId (EraCrypto era)))
-- | Any votes from these DReps in this or in previous txs are removed
!(Set (Credential 'DRepRole (EraCrypto era)))
kderme marked this conversation as resolved.
Show resolved Hide resolved
deriving (Generic, Eq)

instance EraPParams era => NFData (ConwayGovEvent era)
Expand Down Expand Up @@ -535,15 +542,24 @@ govTransition = do

-- Inversion of the keys in VotingProcedures, where we can find the voters for every
-- govActionId
let (unknownGovActionIds, knownVotes) =
let (unknownGovActionIds, knownVotes, replacedVotes) =
foldrVotingProcedures
-- strictness is not needed for `unknown`
( \voter gaId _ (unknown, !known) ->
-- strictness is not needed for `unknown` or `replaced`
( \voter gaId _ (unknown, !known, replaced) ->
case Map.lookup gaId curGovActionIds of
Just gas -> (unknown, (voter, gas) : known)
Nothing -> (gaId : unknown, known)
Just gas ->
let isVoteReplaced =
case voter of
CommitteeVoter hotCred -> hotCred `Map.member` gasCommitteeVotes gas
DRepVoter cred -> cred `Map.member` gasDRepVotes gas
StakePoolVoter poolId -> poolId `Map.member` gasStakePoolVotes gas
replaced'
| isVoteReplaced = Set.insert (voter, gaId) replaced
| otherwise = replaced
in (unknown, (voter, gas) : known, replaced')
Nothing -> (gaId : unknown, known, replaced)
)
([], [])
([], [], Set.empty)
gsVotingProcedures
curGovActionIds = proposalsActionsMap proposals
isVoterKnown = \case
Expand Down Expand Up @@ -578,6 +594,7 @@ govTransition = do

-- Report the event
tellEvent $ GovNewProposals txid updatedProposalStates
tellEvent $ GovRemovedVotes txid replacedVotes unregisteredDReps

pure updatedProposalStates

Expand Down
2 changes: 1 addition & 1 deletion eras/conway/test-suite/cardano-ledger-conway-test.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ library
cardano-ledger-alonzo:{cardano-ledger-alonzo, testlib} >=1.11,
cardano-ledger-babbage >=1.10,
cardano-ledger-binary >=1.0,
cardano-ledger-conway:{cardano-ledger-conway, testlib} >=1.16.1 && <1.18,
cardano-ledger-conway:{cardano-ledger-conway, testlib} >=1.16.1 && <1.19,
cardano-ledger-core:{cardano-ledger-core, testlib} >=1.11,
cardano-ledger-mary >=1.4,
cardano-ledger-shelley-ma-test >=1.1,
Expand Down