{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE UndecidableSuperClasses #-}
module Ouroboros.Consensus.HardFork.Combinator.Abstract.CanHardFork
( CanHardFork (..)
, HashSizeOfHead
, rawHashNS
) where
import Data.ByteString.Short (ShortByteString)
import Data.Function (on)
import Data.Measure (Measure)
import Data.SOP.BasicFunctors (K (..))
import Data.SOP.Constraint
import Data.SOP.NonEmpty
import qualified Data.SOP.Strict as SOP
import Data.SOP.Tails (Tails)
import qualified Data.SOP.Tails as Tails
import Data.Typeable
import GHC.TypeNats (KnownNat)
import NoThunks.Class (NoThunks)
import Ouroboros.Consensus.Block (HashSize)
import Ouroboros.Consensus.HardFork.Combinator.Abstract.SingleEraBlock
import Ouroboros.Consensus.HardFork.Combinator.Protocol.ChainSel
import Ouroboros.Consensus.HardFork.Combinator.Translation
import Ouroboros.Consensus.Ledger.SupportsMempool
import Ouroboros.Consensus.TypeFamilyWrappers
type family HashSizeOfHead xs where
HashSizeOfHead (x ': _) = HashSize x
class HashSize blk ~ HashSizeOfHead xs => EqualHashSizeOfHead xs blk
instance HashSize blk ~ HashSizeOfHead xs => EqualHashSizeOfHead xs blk
class
( All SingleEraBlock xs
, All (EqualHashSizeOfHead xs) xs
, KnownNat (HashSizeOfHead xs)
, Typeable xs
, IsNonEmpty xs
,
Measure (HardForkTxMeasurePhase1 xs)
, HasByteSize (HardForkTxMeasurePhase1 xs)
, NoThunks (HardForkTxMeasurePhase1 xs)
, Show (HardForkTxMeasurePhase1 xs)
, TxMeasurePhase1Metrics (HardForkTxMeasurePhase1 xs)
,
Measure (HardForkTxMeasurePhase2 xs)
, NoThunks (HardForkTxMeasurePhase2 xs)
, Show (HardForkTxMeasurePhase2 xs)
, TxMeasurePhase2Metrics (HardForkTxMeasurePhase2 xs)
) =>
CanHardFork xs
where
type HardForkTxMeasurePhase1 xs
type HardForkTxMeasurePhase2 xs
hardForkEraTranslation :: EraTranslation xs
hardForkChainSel :: Tails AcrossEraTiebreaker xs
hardForkInjTxMeasurePhase1 :: SOP.NS WrapTxMeasurePhase1 xs -> HardForkTxMeasurePhase1 xs
hardForkInjTxMeasurePhase2 :: SOP.NS WrapTxMeasurePhase2 xs -> HardForkTxMeasurePhase2 xs
hardForkEqGenTxId :: SOP.NS WrapGenTxId xs -> SOP.NS WrapGenTxId xs -> Bool
hardForkCompareGenTxId ::
SOP.NS WrapGenTxId xs -> SOP.NS WrapGenTxId xs -> Ordering
rawHashNS :: All SingleEraBlock xs => SOP.NS WrapGenTxId xs -> ShortByteString
rawHashNS :: forall (xs :: [*]).
All SingleEraBlock xs =>
NS WrapGenTxId xs -> ShortByteString
rawHashNS = NS (K ShortByteString) xs -> ShortByteString
NS (K ShortByteString) xs -> CollapseTo NS ShortByteString
forall (xs :: [*]) a.
SListIN NS xs =>
NS (K a) xs -> CollapseTo NS a
forall k l (h :: (k -> *) -> l -> *) (xs :: l) a.
(HCollapse h, SListIN h xs) =>
h (K a) xs -> CollapseTo h a
SOP.hcollapse (NS (K ShortByteString) xs -> ShortByteString)
-> (NS WrapGenTxId xs -> NS (K ShortByteString) xs)
-> NS WrapGenTxId xs
-> ShortByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy SingleEraBlock
-> (forall a.
SingleEraBlock a =>
WrapGenTxId a -> K ShortByteString a)
-> NS WrapGenTxId xs
-> NS (K ShortByteString) xs
forall {k} {l} (h :: (k -> *) -> l -> *) (c :: k -> Constraint)
(xs :: l) (proxy :: (k -> Constraint) -> *) (f :: k -> *)
(f' :: k -> *).
(AllN (Prod h) c xs, HAp h) =>
proxy c
-> (forall (a :: k). c a => f a -> f' a) -> h f xs -> h f' xs
SOP.hcmap Proxy SingleEraBlock
proxySingle (ShortByteString -> K ShortByteString a
forall k a (b :: k). a -> K a b
K (ShortByteString -> K ShortByteString a)
-> (WrapGenTxId a -> ShortByteString)
-> WrapGenTxId a
-> K ShortByteString a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TxId (GenTx a) -> ShortByteString
forall tx. ConvertRawTxId tx => TxId tx -> ShortByteString
toRawTxIdHash (TxId (GenTx a) -> ShortByteString)
-> (WrapGenTxId a -> TxId (GenTx a))
-> WrapGenTxId a
-> ShortByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrapGenTxId a -> TxId (GenTx a)
forall blk. WrapGenTxId blk -> GenTxId blk
unwrapGenTxId)
instance SingleEraBlock blk => CanHardFork '[blk] where
type HardForkTxMeasurePhase1 '[blk] = TxMeasurePhase1 blk
type HardForkTxMeasurePhase2 '[blk] = TxMeasurePhase2 blk
hardForkEraTranslation :: EraTranslation '[blk]
hardForkEraTranslation = EraTranslation '[blk]
forall blk. EraTranslation '[blk]
trivialEraTranslation
hardForkChainSel :: Tails AcrossEraTiebreaker '[blk]
hardForkChainSel = Tails AcrossEraTiebreaker '[blk]
forall {k} (f :: k -> k -> *) (x :: k). Tails f '[x]
Tails.mk1
hardForkInjTxMeasurePhase1 :: NS WrapTxMeasurePhase1 '[blk] -> HardForkTxMeasurePhase1 '[blk]
hardForkInjTxMeasurePhase1 (SOP.Z (WrapTxMeasurePhase1 TxMeasurePhase1 x
x)) = TxMeasurePhase1 x
HardForkTxMeasurePhase1 '[blk]
x
hardForkInjTxMeasurePhase2 :: NS WrapTxMeasurePhase2 '[blk] -> HardForkTxMeasurePhase2 '[blk]
hardForkInjTxMeasurePhase2 (SOP.Z (WrapTxMeasurePhase2 TxMeasurePhase2 x
x)) = TxMeasurePhase2 x
HardForkTxMeasurePhase2 '[blk]
x
hardForkEqGenTxId :: NS WrapGenTxId '[blk] -> NS WrapGenTxId '[blk] -> Bool
hardForkEqGenTxId = ShortByteString -> ShortByteString -> Bool
forall a. Eq a => a -> a -> Bool
(==) (ShortByteString -> ShortByteString -> Bool)
-> (NS WrapGenTxId '[blk] -> ShortByteString)
-> NS WrapGenTxId '[blk]
-> NS WrapGenTxId '[blk]
-> Bool
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` NS WrapGenTxId '[blk] -> ShortByteString
forall (xs :: [*]).
All SingleEraBlock xs =>
NS WrapGenTxId xs -> ShortByteString
rawHashNS
hardForkCompareGenTxId :: NS WrapGenTxId '[blk] -> NS WrapGenTxId '[blk] -> Ordering
hardForkCompareGenTxId = ShortByteString -> ShortByteString -> Ordering
forall a. Ord a => a -> a -> Ordering
compare (ShortByteString -> ShortByteString -> Ordering)
-> (NS WrapGenTxId '[blk] -> ShortByteString)
-> NS WrapGenTxId '[blk]
-> NS WrapGenTxId '[blk]
-> Ordering
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` NS WrapGenTxId '[blk] -> ShortByteString
forall (xs :: [*]).
All SingleEraBlock xs =>
NS WrapGenTxId xs -> ShortByteString
rawHashNS