Skip to content

Commit fc415f4

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 7f2cf06 commit fc415f4

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
, BlockSupportsPeras (..)
1718
, PerasCert (..)
1819
, ValidatedPerasCert (..)
@@ -28,6 +29,7 @@ module Ouroboros.Consensus.Block.SupportsPeras
2829
import Codec.Serialise (Serialise (..))
2930
import Codec.Serialise.Decoding (decodeListLenOf)
3031
import Codec.Serialise.Encoding (encodeListLen)
32+
import Data.Coerce (coerce)
3133
import Data.Proxy (Proxy (..))
3234
import Data.Word (Word64)
3335
import GHC.Generics (Generic)
@@ -41,14 +43,20 @@ import Quiet (Quiet (..))
4143
newtype PerasRoundNo = PerasRoundNo {unPerasRoundNo :: Word64}
4244
deriving Show via Quiet PerasRoundNo
4345
deriving stock Generic
44-
deriving newtype (Enum, Eq, Ord, NoThunks, Serialise)
46+
deriving newtype (Enum, Eq, Ord, Num, Bounded, NoThunks, Serialise)
4547

4648
instance Condense PerasRoundNo where
4749
condense = show . unPerasRoundNo
4850

4951
instance ShowProxy PerasRoundNo where
5052
showProxy _ = "PerasRoundNo"
5153

54+
-- | Lift a binary operation on 'Word64' to 'PerasRoundNo'
55+
onPerasRoundNo ::
56+
(Word64 -> Word64 -> Word64) ->
57+
(PerasRoundNo -> PerasRoundNo -> PerasRoundNo)
58+
onPerasRoundNo = coerce
59+
5260
-- TODO using 'Validated' for extra safety? Or some @.Unsafe@ module?
5361
data ValidatedPerasCert blk = ValidatedPerasCert
5462
{ vpcCert :: !(PerasCert blk)

0 commit comments

Comments
 (0)