Skip to content

Commit 6dfff97

Browse files
committed
consensus: remove BoundedMeasure and WithTop
BoundedMeasure is no longer necessary, as of PR #1182.
1 parent e3c79cb commit 6dfff97

File tree

2 files changed

+11
-46
lines changed
  • ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Ledger
  • ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Mempool

2 files changed

+11
-46
lines changed

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

Lines changed: 8 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ module Ouroboros.Consensus.Shelley.Ledger.Mempool (
2323
, SL.ApplyTxError (..)
2424
, TxId (..)
2525
, Validated (..)
26-
, WithTop (..)
2726
, fixedBlockBodyOverhead
2827
, mkShelleyTx
2928
, mkShelleyValidatedTx
@@ -54,8 +53,7 @@ import Control.Monad.Except (Except)
5453
import Control.Monad.Identity (Identity (..))
5554
import Data.DerivingVia (InstantiatedAt (..))
5655
import Data.Foldable (toList)
57-
import Data.Measure (BoundedMeasure, Measure)
58-
import qualified Data.Measure as Measure
56+
import Data.Measure (Measure)
5957
import Data.Typeable (Typeable)
6058
import GHC.Generics (Generic)
6159
import GHC.Natural (Natural)
@@ -322,13 +320,15 @@ instance ( ShelleyCompatible p (AlonzoEra c)
322320

323321
data AlonzoMeasure = AlonzoMeasure {
324322
byteSize :: !Mempool.ByteSize
325-
, exUnits :: !(ExUnits' (WithTop Natural))
323+
, exUnits :: !(ExUnits' Natural)
326324
} deriving stock (Eq, Generic, Show)
327-
deriving (BoundedMeasure, Measure)
325+
deriving (Measure)
328326
via (InstantiatedAt Generic AlonzoMeasure)
329327

330-
fromExUnits :: ExUnits -> ExUnits' (WithTop Natural)
331-
fromExUnits = fmap NotTop . unWrapExUnits
328+
-- | This function used to do more, but now it's merely a synonym that avoids
329+
-- more import statements in modules that import this one.
330+
fromExUnits :: ExUnits -> ExUnits' Natural
331+
fromExUnits = unWrapExUnits
332332

333333
txMeasureAlonzo ::
334334
forall proto era.
@@ -367,7 +367,7 @@ data ConwayMeasure = ConwayMeasure {
367367
alonzoMeasure :: !AlonzoMeasure
368368
, refScriptsSize :: !Mempool.ByteSize
369369
} deriving stock (Eq, Generic, Show)
370-
deriving (BoundedMeasure, Measure)
370+
deriving (Measure)
371371
via (InstantiatedAt Generic ConwayMeasure)
372372

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

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Mempool/Capacity.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module Ouroboros.Consensus.Mempool.Capacity (
2424
) where
2525

2626
import Cardano.Prelude (NFData)
27-
import Data.Measure (BoundedMeasure, Measure)
27+
import Data.Measure (Measure)
2828
import Data.Word (Word32)
2929
import NoThunks.Class
3030
import Ouroboros.Consensus.Ledger.Basics
@@ -106,7 +106,7 @@ instance Monoid MempoolSize where
106106
-- eras (starting with Alonzo) this measure was a bit more complex
107107
-- as it had to take other factors into account (like execution units).
108108
-- For details please see the individual instances for the TxLimits.
109-
class BoundedMeasure (TxMeasure blk) => TxLimits blk where
109+
class Measure (TxMeasure blk) => TxLimits blk where
110110
type TxMeasure blk
111111

112112
-- | What is the measure an individual tx?
@@ -125,4 +125,4 @@ class BoundedMeasure (TxMeasure blk) => TxLimits blk where
125125
newtype ByteSize = ByteSize { unByteSize :: Word32 }
126126
deriving stock (Show)
127127
deriving newtype (Eq, NFData, Ord)
128-
deriving newtype (BoundedMeasure, Measure)
128+
deriving newtype (Measure)

0 commit comments

Comments
 (0)