Skip to content

Commit 50bcede

Browse files
committed
Tweak and extend Peras cert field projection typeclasses
1 parent d5a82bb commit 50bcede

File tree

1 file changed

+21
-11
lines changed
  • ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Block

1 file changed

+21
-11
lines changed

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

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
{-# LANGUAGE DerivingVia #-}
44
{-# LANGUAGE FlexibleContexts #-}
55
{-# LANGUAGE FlexibleInstances #-}
6+
{-# LANGUAGE FunctionalDependencies #-}
67
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
7-
{-# LANGUAGE MultiParamTypeClasses #-}
88
{-# LANGUAGE NamedFieldPuns #-}
99
{-# LANGUAGE ScopedTypeVariables #-}
1010
{-# LANGUAGE TypeApplications #-}
@@ -38,6 +38,7 @@ import Data.Word (Word64)
3838
import GHC.Generics (Generic)
3939
import NoThunks.Class
4040
import Ouroboros.Consensus.Block.Abstract
41+
import Ouroboros.Consensus.BlockchainTime.WallClock.Types (WithArrivalTime (..))
4142
import Ouroboros.Consensus.Util
4243
import Ouroboros.Consensus.Util.Condense
4344
import Quiet (Quiet (..))
@@ -166,20 +167,29 @@ makePerasCfg _ =
166167
{ perasCfgWeightBoost = boostPerCert
167168
}
168169

169-
class StandardHash blk => HasPerasCert cert blk where
170-
getPerasCert :: cert blk -> PerasCert blk
170+
class StandardHash blk => HasPerasCert cert blk | cert -> blk where
171+
getPerasCert :: cert -> PerasCert blk
171172

172-
instance StandardHash blk => HasPerasCert PerasCert blk where
173+
getPerasCertRound :: HasPerasCert cert blk => cert -> PerasRoundNo
174+
getPerasCertRound = pcCertRound . getPerasCert
175+
176+
getPerasCertBoostedBlock :: HasPerasCert cert blk => cert -> Point blk
177+
getPerasCertBoostedBlock = pcCertBoostedBlock . getPerasCert
178+
179+
instance StandardHash blk => HasPerasCert (PerasCert blk) blk where
173180
getPerasCert = id
174181

175-
instance StandardHash blk => HasPerasCert ValidatedPerasCert blk where
182+
instance StandardHash blk => HasPerasCert (ValidatedPerasCert blk) blk where
176183
getPerasCert = vpcCert
177184

178-
getPerasCertRound :: HasPerasCert cert blk => cert blk -> PerasRoundNo
179-
getPerasCertRound = pcCertRound . getPerasCert
185+
instance HasPerasCert cert blk => HasPerasCert (WithArrivalTime cert) blk where
186+
getPerasCert = getPerasCert . forgetArrivalTime
180187

181-
getPerasCertBoostedBlock :: HasPerasCert cert blk => cert blk -> Point blk
182-
getPerasCertBoostedBlock = pcCertBoostedBlock . getPerasCert
188+
class HasPerasCertBoost cert blk | cert -> blk where
189+
getPerasCertBoost :: cert -> PerasWeight
190+
191+
instance HasPerasCertBoost (ValidatedPerasCert blk) blk where
192+
getPerasCertBoost = vpcCertBoost
183193

184-
getPerasCertBoost :: ValidatedPerasCert blk -> PerasWeight
185-
getPerasCertBoost = vpcCertBoost
194+
instance HasPerasCertBoost cert blk => HasPerasCertBoost (WithArrivalTime cert) blk where
195+
getPerasCertBoost = getPerasCertBoost . forgetArrivalTime

0 commit comments

Comments
 (0)