Skip to content

Commit 282735a

Browse files
committed
consensus: no longer need BoundedMeasure, Measure suffices
1 parent 5aadb7e commit 282735a

File tree

3 files changed

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

3 files changed

+17
-54
lines changed

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

Lines changed: 6 additions & 43 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,7 +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)
57+
import Data.Measure (Measure)
5958
import qualified Data.Measure as Measure
6059
import Data.Typeable (Typeable)
6160
import GHC.Generics (Generic)
@@ -322,17 +321,17 @@ instance ( ShelleyCompatible p (AlonzoEra c)
322321

323322
data AlonzoMeasure = AlonzoMeasure {
324323
byteSize :: !ByteSize
325-
, exUnits :: !(ExUnits' (WithTop Natural))
324+
, exUnits :: !(ExUnits' Natural)
326325
} deriving stock (Eq, Generic, Show)
327326
deriving anyclass (NoThunks)
328-
deriving (BoundedMeasure, Measure)
327+
deriving (Measure)
329328
via (InstantiatedAt Generic AlonzoMeasure)
330329

331330
instance HasByteSize AlonzoMeasure where
332331
txMeasureByteSize = byteSize
333332

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

337336
txMeasureAlonzo ::
338337
forall proto era.
@@ -369,7 +368,7 @@ data ConwayMeasure = ConwayMeasure {
369368
, refScriptsSize :: !ByteSize
370369
} deriving stock (Eq, Generic, Show)
371370
deriving anyclass (NoThunks)
372-
deriving (BoundedMeasure, Measure)
371+
deriving (Measure)
373372
via (InstantiatedAt Generic ConwayMeasure)
374373

375374
instance HasByteSize ConwayMeasure where
@@ -396,39 +395,3 @@ instance ( ShelleyCompatible p (ConwayEra c)
396395
-- For post-Conway eras, this will become a protocol parameter.
397396
SL.maxRefScriptSizePerBlock
398397
}
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
type HardForkTxMeasure xs
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)