Skip to content

Commit 2ebacd7

Browse files
committed
consensus: no longer need BoundedMeasure, Measure suffices
1 parent c28d630 commit 2ebacd7

File tree

3 files changed

+17
-56
lines changed
  • ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Ledger
  • ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus

3 files changed

+17
-56
lines changed

ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Ledger/Mempool.hs

Lines changed: 6 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
{-# LANGUAGE FlexibleContexts #-}
77
{-# LANGUAGE FlexibleInstances #-}
88
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
9-
{-# LANGUAGE LambdaCase #-}
109
{-# LANGUAGE NamedFieldPuns #-}
1110
{-# LANGUAGE OverloadedStrings #-}
1211
{-# LANGUAGE Rank2Types #-}
@@ -24,7 +23,6 @@ module Ouroboros.Consensus.Shelley.Ledger.Mempool (
2423
, SL.ApplyTxError (..)
2524
, TxId (..)
2625
, Validated (..)
27-
, WithTop (..)
2826
, fixedBlockBodyOverhead
2927
, mkShelleyTx
3028
, mkShelleyValidatedTx
@@ -55,8 +53,7 @@ import Control.Monad.Except (Except)
5553
import Control.Monad.Identity (Identity (..))
5654
import Data.DerivingVia (InstantiatedAt (..))
5755
import Data.Foldable (toList)
58-
import Data.Measure (BoundedMeasure, Measure)
59-
import qualified Data.Measure as Measure
56+
import Data.Measure (Measure)
6057
import Data.Typeable (Typeable)
6158
import GHC.Generics (Generic)
6259
import GHC.Natural (Natural)
@@ -322,17 +319,17 @@ instance ( ShelleyCompatible p (AlonzoEra c)
322319

323320
data AlonzoMeasure = AlonzoMeasure {
324321
byteSize :: !ByteSize
325-
, exUnits :: !(ExUnits' (WithTop Natural))
322+
, exUnits :: !(ExUnits' Natural)
326323
} deriving stock (Eq, Generic, Show)
327324
deriving anyclass (NoThunks)
328-
deriving (BoundedMeasure, Measure)
325+
deriving (Measure)
329326
via (InstantiatedAt Generic AlonzoMeasure)
330327

331328
instance HasByteSize AlonzoMeasure where
332329
txMeasureByteSize = byteSize
333330

334-
fromExUnits :: ExUnits -> ExUnits' (WithTop Natural)
335-
fromExUnits = fmap NotTop . unWrapExUnits
331+
fromExUnits :: ExUnits -> ExUnits' Natural
332+
fromExUnits = unWrapExUnits
336333

337334
txMeasureAlonzo ::
338335
forall proto era.
@@ -369,7 +366,7 @@ data ConwayMeasure = ConwayMeasure {
369366
, refScriptsSize :: !ByteSize
370367
} deriving stock (Eq, Generic, Show)
371368
deriving anyclass (NoThunks)
372-
deriving (BoundedMeasure, Measure)
369+
deriving (Measure)
373370
via (InstantiatedAt Generic ConwayMeasure)
374371

375372
instance HasByteSize ConwayMeasure where
@@ -396,39 +393,3 @@ instance ( ShelleyCompatible p (ConwayEra c)
396393
-- For post-Conway eras, this will become a protocol parameter.
397394
SL.maxRefScriptSizePerBlock
398395
}
399-
400-
{-------------------------------------------------------------------------------
401-
WithTop
402-
-------------------------------------------------------------------------------}
403-
404-
-- | Add a unique top element to a lattice.
405-
--
406-
-- TODO This should be relocated to `cardano-base:Data.Measure'.
407-
data WithTop a = NotTop !a | Top
408-
deriving (Eq, Generic, Show)
409-
deriving anyclass (NoThunks)
410-
411-
instance Ord a => Ord (WithTop a) where
412-
compare = curry $ \case
413-
(Top , Top ) -> EQ
414-
(Top , _ ) -> GT
415-
(_ , Top ) -> LT
416-
(NotTop l, NotTop r) -> compare l r
417-
418-
instance Measure a => Measure (WithTop a) where
419-
zero = NotTop Measure.zero
420-
plus = curry $ \case
421-
(Top , _ ) -> Top
422-
(_ , Top ) -> Top
423-
(NotTop l, NotTop r) -> NotTop $ Measure.plus l r
424-
min = curry $ \case
425-
(Top , r ) -> r
426-
(l , Top ) -> l
427-
(NotTop l, NotTop r) -> NotTop $ Measure.min l r
428-
max = curry $ \case
429-
(Top , _ ) -> Top
430-
(_ , Top ) -> Top
431-
(NotTop l, NotTop r) -> NotTop $ Measure.max l r
432-
433-
instance Measure a => BoundedMeasure (WithTop a) where
434-
maxBound = Top

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/HardFork/Combinator/Abstract/CanHardFork.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
module Ouroboros.Consensus.HardFork.Combinator.Abstract.CanHardFork (CanHardFork (..)) where
88

9-
import Data.Measure (BoundedMeasure)
9+
import Data.Measure (Measure)
1010
import Data.SOP.Constraint
1111
import Data.SOP.Functors (Product2)
1212
import Data.SOP.InPairs (InPairs, RequiringBoth)
@@ -31,10 +31,10 @@ import Ouroboros.Consensus.TypeFamilyWrappers
3131
class ( All SingleEraBlock xs
3232
, Typeable xs
3333
, IsNonEmpty xs
34-
, BoundedMeasure (HardForkTxMeasure xs)
35-
, HasByteSize (HardForkTxMeasure xs)
36-
, NoThunks (HardForkTxMeasure xs)
37-
, Show (HardForkTxMeasure xs)
34+
, Measure (HardForkTxMeasure xs)
35+
, HasByteSize (HardForkTxMeasure xs)
36+
, NoThunks (HardForkTxMeasure xs)
37+
, Show (HardForkTxMeasure xs)
3838
) => CanHardFork xs where
3939
-- | A measure that can accurately represent the 'TxMeasure' of any era.
4040
--

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Ledger/SupportsMempool.hs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import Control.Monad.Except
2525
import Data.ByteString.Short (ShortByteString)
2626
import Data.DerivingVia (InstantiatedAt (..))
2727
import Data.Kind (Type)
28-
import Data.Measure (BoundedMeasure, Measure)
28+
import Data.Measure (Measure)
2929
import Data.Word (Word32)
3030
import GHC.Stack (HasCallStack)
3131
import NoThunks.Class
@@ -165,10 +165,10 @@ class HasTxs blk where
165165
-- state). In future eras (starting with Alonzo) this measure was a bit more
166166
-- complex as it had to take other factors into account (like execution units).
167167
-- For details please see the individual instances for the TxLimits.
168-
class ( BoundedMeasure (TxMeasure blk)
169-
, HasByteSize (TxMeasure blk)
170-
, NoThunks (TxMeasure blk)
171-
, Show (TxMeasure blk)
168+
class ( Measure (TxMeasure blk)
169+
, HasByteSize (TxMeasure blk)
170+
, NoThunks (TxMeasure blk)
171+
, Show (TxMeasure blk)
172172
) => TxLimits blk where
173173
-- | The (possibly multi-dimensional) size of a transaction in a block.
174174
type TxMeasure blk
@@ -207,7 +207,7 @@ class ( BoundedMeasure (TxMeasure blk)
207207
newtype ByteSize = ByteSize { unByteSize :: Word32 }
208208
deriving stock (Show)
209209
deriving newtype (Eq, Ord)
210-
deriving newtype (BoundedMeasure, Measure)
210+
deriving newtype (Measure)
211211
deriving newtype (NFData)
212212
deriving (Monoid, Semigroup) via (InstantiatedAt Measure ByteSize)
213213
deriving (NoThunks) via OnlyCheckWhnfNamed "ByteSize" ByteSize

0 commit comments

Comments
 (0)