Skip to content

Commit 5e1807a

Browse files
committed
Complete/fix Vote definition in BlockSupportsPeras
1 parent 06f4e61 commit 5e1807a

File tree

1 file changed

+40
-6
lines changed
  • ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Block

1 file changed

+40
-6
lines changed

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Block/SupportsPeras.hs

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
module Ouroboros.Consensus.Block.SupportsPeras
1616
( PerasRoundNo (..)
1717
, onPerasRoundNo
18+
, PerasVoteId (..)
19+
, PerasVoteTarget (..)
1820
, PerasVoterId (..)
1921
, PerasVoteStake (..)
2022
, PerasVoteStakeDistr (..)
@@ -30,6 +32,8 @@ module Ouroboros.Consensus.Block.SupportsPeras
3032
, HasPerasVoteRound (..)
3133
, HasPerasVoteBlock (..)
3234
, HasPerasVoteVoterId (..)
35+
, HasPerasVoteTarget (..)
36+
, HasPerasVoteId (..)
3337

3438
-- * Convenience re-exports
3539
, module Ouroboros.Consensus.Peras.Params
@@ -109,6 +113,13 @@ data PerasVoteTarget blk = PerasVoteTarget
109113
deriving stock (Show, Eq, Ord, Generic)
110114
deriving anyclass NoThunks
111115

116+
data PerasVoteId blk = PerasVoteId
117+
{ pviRoundNo :: !PerasRoundNo
118+
, pviVoterId :: !PerasVoterId
119+
}
120+
deriving stock (Show, Eq, Ord, Generic)
121+
deriving anyclass NoThunks
122+
112123
-- | Lookup the stake of vote casted by a member of a given stake distribution.
113124
lookupPerasVoteStake ::
114125
PerasVote blk ->
@@ -162,15 +173,15 @@ class
162173

163174
validatePerasVote ::
164175
PerasCfg blk ->
165-
PerasVote blk ->
166176
PerasVoteStakeDistr ->
177+
PerasVote blk ->
167178
Either (PerasValidationErr blk) (ValidatedPerasVote blk)
168179

169180
forgePerasCert ::
170181
PerasCfg blk ->
171182
PerasVoteTarget blk ->
172183
[ValidatedPerasVote blk] ->
173-
Either (PerasForgeErr blk) (PerasCert blk)
184+
Either (PerasForgeErr blk) (ValidatedPerasCert blk)
174185

175186
-- TODO: degenerate instance for all blks to get things to compile
176187
-- see https://github.com/tweag/cardano-peras/issues/73
@@ -218,7 +229,7 @@ instance StandardHash blk => BlockSupportsPeras blk where
218229
-- TODO: perform actual validation against all
219230
-- possible 'PerasValidationErr' variants
220231
-- see https://github.com/tweag/cardano-peras/issues/120
221-
validatePerasVote _params vote stakeDistr
232+
validatePerasVote _params stakeDistr vote
222233
| Just stake <- lookupPerasVoteStake vote stakeDistr =
223234
Right
224235
ValidatedPerasVote
@@ -238,9 +249,13 @@ instance StandardHash blk => BlockSupportsPeras blk where
238249
Left PerasForgeErrInsufficientVotes
239250
| otherwise =
240251
return $
241-
PerasCert
242-
{ pcCertRound = pvtRoundNo target
243-
, pcCertBoostedBlock = pvtBlock target
252+
ValidatedPerasCert
253+
{ vpcCert =
254+
PerasCert
255+
{ pcCertRound = pvtRoundNo target
256+
, pcCertBoostedBlock = pvtBlock target
257+
}
258+
, vpcCertBoost = perasWeight params
244259
}
245260
where
246261
totalVotesStake =
@@ -408,3 +423,22 @@ instance
408423
HasPerasVoteTarget (WithArrivalTime vote) blk
409424
where
410425
getPerasVoteTarget = getPerasVoteTarget . forgetArrivalTime
426+
427+
class HasPerasVoteId vote blk | vote -> blk where
428+
getPerasVoteId :: vote -> PerasVoteId blk
429+
430+
instance HasPerasVoteId (PerasVote blk) blk where
431+
getPerasVoteId vote =
432+
PerasVoteId
433+
{ pviRoundNo = pvVoteRound vote
434+
, pviVoterId = pvVoteVoterId vote
435+
}
436+
437+
instance HasPerasVoteId (ValidatedPerasVote blk) blk where
438+
getPerasVoteId = getPerasVoteId . vpvVote
439+
440+
instance
441+
HasPerasVoteId vote blk =>
442+
HasPerasVoteId (WithArrivalTime vote) blk
443+
where
444+
getPerasVoteId = getPerasVoteId . forgetArrivalTime

0 commit comments

Comments
 (0)