Skip to content

Commit cedd6f7

Browse files
committed
consensus: no longer need BoundedMeasure, Measure suffices
1 parent 5b93326 commit cedd6f7

File tree

3 files changed

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

3 files changed

+17
-55
lines changed

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

Lines changed: 6 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ module Ouroboros.Consensus.Shelley.Ledger.Mempool (
2424
, SL.ApplyTxError (..)
2525
, TxId (..)
2626
, Validated (..)
27-
, WithTop (..)
2827
, fixedBlockBodyOverhead
2928
, mkShelleyTx
3029
, mkShelleyValidatedTx
@@ -55,8 +54,7 @@ import Control.Monad.Except (Except)
5554
import Control.Monad.Identity (Identity (..))
5655
import Data.DerivingVia (InstantiatedAt (..))
5756
import Data.Foldable (toList)
58-
import Data.Measure (BoundedMeasure, Measure)
59-
import qualified Data.Measure as Measure
57+
import Data.Measure (Measure)
6058
import Data.Typeable (Typeable)
6159
import GHC.Generics (Generic)
6260
import GHC.Natural (Natural)
@@ -322,17 +320,17 @@ instance ( ShelleyCompatible p (AlonzoEra c)
322320

323321
data AlonzoMeasure = AlonzoMeasure {
324322
byteSize :: !ByteSize
325-
, exUnits :: !(ExUnits' (WithTop Natural))
323+
, exUnits :: !(ExUnits' Natural)
326324
} deriving stock (Eq, Generic, Show)
327325
deriving anyclass (NoThunks)
328-
deriving (BoundedMeasure, Measure)
326+
deriving (Measure)
329327
via (InstantiatedAt Generic AlonzoMeasure)
330328

331329
instance HasByteSize AlonzoMeasure where
332330
txMeasureByteSize = byteSize
333331

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

337335
txMeasureAlonzo ::
338336
forall proto era.
@@ -369,7 +367,7 @@ data ConwayMeasure = ConwayMeasure {
369367
, refScriptsSize :: !ByteSize
370368
} deriving stock (Eq, Generic, Show)
371369
deriving anyclass (NoThunks)
372-
deriving (BoundedMeasure, Measure)
370+
deriving (Measure)
373371
via (InstantiatedAt Generic ConwayMeasure)
374372

375373
instance HasByteSize ConwayMeasure where
@@ -396,39 +394,3 @@ instance ( ShelleyCompatible p (ConwayEra c)
396394
-- For post-Conway eras, this will become a protocol parameter.
397395
SL.maxRefScriptSizePerBlock
398396
}
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)