Skip to content

Commit

Permalink
Merge pull request #4661 from kderme/kderme/removed-votes
Browse files Browse the repository at this point in the history
Add GovRemovedVotes event
lehins authored Oct 15, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents 30992cb + 2864130 commit 156f568
Showing 4 changed files with 27 additions and 10 deletions.
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

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
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
@@ -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
@@ -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)))
deriving (Generic, Eq)

instance EraPParams era => NFData (ConwayGovEvent era)
@@ -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
@@ -578,6 +594,7 @@ govTransition = do

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

pure updatedProposalStates

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
@@ -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,

0 comments on commit 156f568

Please sign in to comment.