Skip to content

Commit 1bc6224

Browse files
agustinmistaamesgengeo2atbagrel1nbacquey
committed
Add onPerasRoundNo helper and Num instance
This commit adds a small helper to compute over Peras round numbers. Will be needed later on to implement the Peras voting rules. Co-authored-by: Agustin Mista <agustin.mista@moduscreate.com> Co-authored-by: Alexander Esgen <alexander.esgen@iohk.io> Co-authored-by: Georgy Lukyanov <georgy.lukyanov@iohk.io> Co-authored-by: Thomas BAGREL <thomas.bagrel@tweag.io> Co-authored-by: Nicolas BACQUEY <nicolas.bacquey@tweag.io>
1 parent 1d5ee9f commit 1bc6224

File tree

1 file changed

+9
-1
lines changed
  • ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Block

1 file changed

+9
-1
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
module Ouroboros.Consensus.Block.SupportsPeras
1515
( PerasRoundNo (..)
16+
, onPerasRoundNo
1617
, PerasWeight (..)
1718
, BlockSupportsPeras (..)
1819
, PerasCert (..)
@@ -32,6 +33,7 @@ module Ouroboros.Consensus.Block.SupportsPeras
3233
import Codec.Serialise (Serialise (..))
3334
import Codec.Serialise.Decoding (decodeListLenOf)
3435
import Codec.Serialise.Encoding (encodeListLen)
36+
import Data.Coerce (coerce)
3537
import Data.Monoid (Sum (..))
3638
import Data.Proxy (Proxy (..))
3739
import Data.Word (Word64)
@@ -45,14 +47,20 @@ import Quiet (Quiet (..))
4547
newtype PerasRoundNo = PerasRoundNo {unPerasRoundNo :: Word64}
4648
deriving Show via Quiet PerasRoundNo
4749
deriving stock Generic
48-
deriving newtype (Enum, Eq, Ord, NoThunks, Serialise)
50+
deriving newtype (Enum, Eq, Ord, Num, Bounded, NoThunks, Serialise)
4951

5052
instance Condense PerasRoundNo where
5153
condense = show . unPerasRoundNo
5254

5355
instance ShowProxy PerasRoundNo where
5456
showProxy _ = "PerasRoundNo"
5557

58+
-- | Lift a binary operation on 'Word64' to 'PerasRoundNo'
59+
onPerasRoundNo ::
60+
(Word64 -> Word64 -> Word64) ->
61+
(PerasRoundNo -> PerasRoundNo -> PerasRoundNo)
62+
onPerasRoundNo = coerce
63+
5664
newtype PerasWeight = PerasWeight {unPerasWeight :: Word64}
5765
deriving Show via Quiet PerasWeight
5866
deriving stock Generic

0 commit comments

Comments
 (0)