{-# LANGUAGE DeriveAnyClass    #-}
{-# LANGUAGE DeriveGeneric     #-}
{-# LANGUAGE DeriveTraversable #-}
module Ouroboros.Consensus.Storage.ImmutableDB.Impl.Types (
    -- * Misc types
    BlockOrEBB (..)
  , WithBlockSize (..)
  , isBlockOrEBB
    -- * Validation policy
  , ValidationPolicy (..)
    -- * Chunk file error
  , ChunkFileError (..)
    -- * Tracing
  , TraceCacheEvent (..)
  , TraceChunkValidation (..)
  , TraceEvent (..)
  ) where

import           Data.Text (Text)
import           Data.Word
import           GHC.Generics (Generic)
import           NoThunks.Class (NoThunks)

import           Ouroboros.Consensus.Block
import           Ouroboros.Consensus.Util.CBOR (ReadIncrementalErr)

import           Ouroboros.Consensus.Storage.ImmutableDB.API (Tip)

-- Importing from Internal to avoid circular dependency
import           Ouroboros.Consensus.Storage.ImmutableDB.Chunks.Internal
                     (ChunkNo)

{------------------------------------------------------------------------------
  Misc types
------------------------------------------------------------------------------}

data BlockOrEBB =
    Block !SlotNo
  | EBB   !EpochNo
  deriving (BlockOrEBB -> BlockOrEBB -> Bool
(BlockOrEBB -> BlockOrEBB -> Bool)
-> (BlockOrEBB -> BlockOrEBB -> Bool) -> Eq BlockOrEBB
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BlockOrEBB -> BlockOrEBB -> Bool
$c/= :: BlockOrEBB -> BlockOrEBB -> Bool
== :: BlockOrEBB -> BlockOrEBB -> Bool
$c== :: BlockOrEBB -> BlockOrEBB -> Bool
Eq, Int -> BlockOrEBB -> ShowS
[BlockOrEBB] -> ShowS
BlockOrEBB -> String
(Int -> BlockOrEBB -> ShowS)
-> (BlockOrEBB -> String)
-> ([BlockOrEBB] -> ShowS)
-> Show BlockOrEBB
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BlockOrEBB] -> ShowS
$cshowList :: [BlockOrEBB] -> ShowS
show :: BlockOrEBB -> String
$cshow :: BlockOrEBB -> String
showsPrec :: Int -> BlockOrEBB -> ShowS
$cshowsPrec :: Int -> BlockOrEBB -> ShowS
Show, (forall x. BlockOrEBB -> Rep BlockOrEBB x)
-> (forall x. Rep BlockOrEBB x -> BlockOrEBB) -> Generic BlockOrEBB
forall x. Rep BlockOrEBB x -> BlockOrEBB
forall x. BlockOrEBB -> Rep BlockOrEBB x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep BlockOrEBB x -> BlockOrEBB
$cfrom :: forall x. BlockOrEBB -> Rep BlockOrEBB x
Generic, Context -> BlockOrEBB -> IO (Maybe ThunkInfo)
Proxy BlockOrEBB -> String
(Context -> BlockOrEBB -> IO (Maybe ThunkInfo))
-> (Context -> BlockOrEBB -> IO (Maybe ThunkInfo))
-> (Proxy BlockOrEBB -> String)
-> NoThunks BlockOrEBB
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
showTypeOf :: Proxy BlockOrEBB -> String
$cshowTypeOf :: Proxy BlockOrEBB -> String
wNoThunks :: Context -> BlockOrEBB -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> BlockOrEBB -> IO (Maybe ThunkInfo)
noThunks :: Context -> BlockOrEBB -> IO (Maybe ThunkInfo)
$cnoThunks :: Context -> BlockOrEBB -> IO (Maybe ThunkInfo)
NoThunks)

isBlockOrEBB :: BlockOrEBB -> IsEBB
isBlockOrEBB :: BlockOrEBB -> IsEBB
isBlockOrEBB (Block SlotNo
_) = IsEBB
IsNotEBB
isBlockOrEBB (EBB   EpochNo
_) = IsEBB
IsEBB

data WithBlockSize a = WithBlockSize {
      WithBlockSize a -> Word32
blockSize        :: !Word32
    , WithBlockSize a -> a
withoutBlockSize :: !a
    }
  deriving (WithBlockSize a -> WithBlockSize a -> Bool
(WithBlockSize a -> WithBlockSize a -> Bool)
-> (WithBlockSize a -> WithBlockSize a -> Bool)
-> Eq (WithBlockSize a)
forall a. Eq a => WithBlockSize a -> WithBlockSize a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: WithBlockSize a -> WithBlockSize a -> Bool
$c/= :: forall a. Eq a => WithBlockSize a -> WithBlockSize a -> Bool
== :: WithBlockSize a -> WithBlockSize a -> Bool
$c== :: forall a. Eq a => WithBlockSize a -> WithBlockSize a -> Bool
Eq, Int -> WithBlockSize a -> ShowS
[WithBlockSize a] -> ShowS
WithBlockSize a -> String
(Int -> WithBlockSize a -> ShowS)
-> (WithBlockSize a -> String)
-> ([WithBlockSize a] -> ShowS)
-> Show (WithBlockSize a)
forall a. Show a => Int -> WithBlockSize a -> ShowS
forall a. Show a => [WithBlockSize a] -> ShowS
forall a. Show a => WithBlockSize a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [WithBlockSize a] -> ShowS
$cshowList :: forall a. Show a => [WithBlockSize a] -> ShowS
show :: WithBlockSize a -> String
$cshow :: forall a. Show a => WithBlockSize a -> String
showsPrec :: Int -> WithBlockSize a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> WithBlockSize a -> ShowS
Show, (forall x. WithBlockSize a -> Rep (WithBlockSize a) x)
-> (forall x. Rep (WithBlockSize a) x -> WithBlockSize a)
-> Generic (WithBlockSize a)
forall x. Rep (WithBlockSize a) x -> WithBlockSize a
forall x. WithBlockSize a -> Rep (WithBlockSize a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (WithBlockSize a) x -> WithBlockSize a
forall a x. WithBlockSize a -> Rep (WithBlockSize a) x
$cto :: forall a x. Rep (WithBlockSize a) x -> WithBlockSize a
$cfrom :: forall a x. WithBlockSize a -> Rep (WithBlockSize a) x
Generic, Context -> WithBlockSize a -> IO (Maybe ThunkInfo)
Proxy (WithBlockSize a) -> String
(Context -> WithBlockSize a -> IO (Maybe ThunkInfo))
-> (Context -> WithBlockSize a -> IO (Maybe ThunkInfo))
-> (Proxy (WithBlockSize a) -> String)
-> NoThunks (WithBlockSize a)
forall a.
NoThunks a =>
Context -> WithBlockSize a -> IO (Maybe ThunkInfo)
forall a. NoThunks a => Proxy (WithBlockSize a) -> String
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
showTypeOf :: Proxy (WithBlockSize a) -> String
$cshowTypeOf :: forall a. NoThunks a => Proxy (WithBlockSize a) -> String
wNoThunks :: Context -> WithBlockSize a -> IO (Maybe ThunkInfo)
$cwNoThunks :: forall a.
NoThunks a =>
Context -> WithBlockSize a -> IO (Maybe ThunkInfo)
noThunks :: Context -> WithBlockSize a -> IO (Maybe ThunkInfo)
$cnoThunks :: forall a.
NoThunks a =>
Context -> WithBlockSize a -> IO (Maybe ThunkInfo)
NoThunks, a -> WithBlockSize b -> WithBlockSize a
(a -> b) -> WithBlockSize a -> WithBlockSize b
(forall a b. (a -> b) -> WithBlockSize a -> WithBlockSize b)
-> (forall a b. a -> WithBlockSize b -> WithBlockSize a)
-> Functor WithBlockSize
forall a b. a -> WithBlockSize b -> WithBlockSize a
forall a b. (a -> b) -> WithBlockSize a -> WithBlockSize b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> WithBlockSize b -> WithBlockSize a
$c<$ :: forall a b. a -> WithBlockSize b -> WithBlockSize a
fmap :: (a -> b) -> WithBlockSize a -> WithBlockSize b
$cfmap :: forall a b. (a -> b) -> WithBlockSize a -> WithBlockSize b
Functor, WithBlockSize a -> Bool
(a -> m) -> WithBlockSize a -> m
(a -> b -> b) -> b -> WithBlockSize a -> b
(forall m. Monoid m => WithBlockSize m -> m)
-> (forall m a. Monoid m => (a -> m) -> WithBlockSize a -> m)
-> (forall m a. Monoid m => (a -> m) -> WithBlockSize a -> m)
-> (forall a b. (a -> b -> b) -> b -> WithBlockSize a -> b)
-> (forall a b. (a -> b -> b) -> b -> WithBlockSize a -> b)
-> (forall b a. (b -> a -> b) -> b -> WithBlockSize a -> b)
-> (forall b a. (b -> a -> b) -> b -> WithBlockSize a -> b)
-> (forall a. (a -> a -> a) -> WithBlockSize a -> a)
-> (forall a. (a -> a -> a) -> WithBlockSize a -> a)
-> (forall a. WithBlockSize a -> [a])
-> (forall a. WithBlockSize a -> Bool)
-> (forall a. WithBlockSize a -> Int)
-> (forall a. Eq a => a -> WithBlockSize a -> Bool)
-> (forall a. Ord a => WithBlockSize a -> a)
-> (forall a. Ord a => WithBlockSize a -> a)
-> (forall a. Num a => WithBlockSize a -> a)
-> (forall a. Num a => WithBlockSize a -> a)
-> Foldable WithBlockSize
forall a. Eq a => a -> WithBlockSize a -> Bool
forall a. Num a => WithBlockSize a -> a
forall a. Ord a => WithBlockSize a -> a
forall m. Monoid m => WithBlockSize m -> m
forall a. WithBlockSize a -> Bool
forall a. WithBlockSize a -> Int
forall a. WithBlockSize a -> [a]
forall a. (a -> a -> a) -> WithBlockSize a -> a
forall m a. Monoid m => (a -> m) -> WithBlockSize a -> m
forall b a. (b -> a -> b) -> b -> WithBlockSize a -> b
forall a b. (a -> b -> b) -> b -> WithBlockSize a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: WithBlockSize a -> a
$cproduct :: forall a. Num a => WithBlockSize a -> a
sum :: WithBlockSize a -> a
$csum :: forall a. Num a => WithBlockSize a -> a
minimum :: WithBlockSize a -> a
$cminimum :: forall a. Ord a => WithBlockSize a -> a
maximum :: WithBlockSize a -> a
$cmaximum :: forall a. Ord a => WithBlockSize a -> a
elem :: a -> WithBlockSize a -> Bool
$celem :: forall a. Eq a => a -> WithBlockSize a -> Bool
length :: WithBlockSize a -> Int
$clength :: forall a. WithBlockSize a -> Int
null :: WithBlockSize a -> Bool
$cnull :: forall a. WithBlockSize a -> Bool
toList :: WithBlockSize a -> [a]
$ctoList :: forall a. WithBlockSize a -> [a]
foldl1 :: (a -> a -> a) -> WithBlockSize a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> WithBlockSize a -> a
foldr1 :: (a -> a -> a) -> WithBlockSize a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> WithBlockSize a -> a
foldl' :: (b -> a -> b) -> b -> WithBlockSize a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> WithBlockSize a -> b
foldl :: (b -> a -> b) -> b -> WithBlockSize a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> WithBlockSize a -> b
foldr' :: (a -> b -> b) -> b -> WithBlockSize a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> WithBlockSize a -> b
foldr :: (a -> b -> b) -> b -> WithBlockSize a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> WithBlockSize a -> b
foldMap' :: (a -> m) -> WithBlockSize a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> WithBlockSize a -> m
foldMap :: (a -> m) -> WithBlockSize a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> WithBlockSize a -> m
fold :: WithBlockSize m -> m
$cfold :: forall m. Monoid m => WithBlockSize m -> m
Foldable, Functor WithBlockSize
Foldable WithBlockSize
Functor WithBlockSize
-> Foldable WithBlockSize
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> WithBlockSize a -> f (WithBlockSize b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    WithBlockSize (f a) -> f (WithBlockSize a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> WithBlockSize a -> m (WithBlockSize b))
-> (forall (m :: * -> *) a.
    Monad m =>
    WithBlockSize (m a) -> m (WithBlockSize a))
-> Traversable WithBlockSize
(a -> f b) -> WithBlockSize a -> f (WithBlockSize b)
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a.
Monad m =>
WithBlockSize (m a) -> m (WithBlockSize a)
forall (f :: * -> *) a.
Applicative f =>
WithBlockSize (f a) -> f (WithBlockSize a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> WithBlockSize a -> m (WithBlockSize b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> WithBlockSize a -> f (WithBlockSize b)
sequence :: WithBlockSize (m a) -> m (WithBlockSize a)
$csequence :: forall (m :: * -> *) a.
Monad m =>
WithBlockSize (m a) -> m (WithBlockSize a)
mapM :: (a -> m b) -> WithBlockSize a -> m (WithBlockSize b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> WithBlockSize a -> m (WithBlockSize b)
sequenceA :: WithBlockSize (f a) -> f (WithBlockSize a)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
WithBlockSize (f a) -> f (WithBlockSize a)
traverse :: (a -> f b) -> WithBlockSize a -> f (WithBlockSize b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> WithBlockSize a -> f (WithBlockSize b)
$cp2Traversable :: Foldable WithBlockSize
$cp1Traversable :: Functor WithBlockSize
Traversable)

{------------------------------------------------------------------------------
  Validation policy
------------------------------------------------------------------------------}

-- | The validation policy used when opening an
-- 'Ouroboros.Consensus.Storage.ImmutableDB.API.ImmutableDB'.
--
-- The validation policy is used by
-- 'Ouroboros.Consensus.Storage.ImmutableDB.Impl.openDB': the initial opening of
-- the database, either an empty database or a database that was previously
-- closed.
--
-- The recovery policy dictates which on-disk files should be validated.
data ValidationPolicy =
    ValidateMostRecentChunk
    -- ^ The chunk and index files of the most recent chunk stored on disk will
    -- be validated.
    --
    -- Prior chunk and index files are ignored, even their presence will not
    -- be checked.
    --
    -- A 'MissingFileError' or an 'InvalidFileError' will be thrown in case of a
    -- missing or invalid chunk file, or an invalid index file.
    --
    -- Because not all files are validated, subsequent operations on the
    -- database after opening may result in unexpected errors.
  | ValidateAllChunks
    -- ^ The chunk and index files of all chunks starting from the first one up
    -- to the last chunk stored on disk will be validated.
    --
    -- A 'MissingFileError' or an 'InvalidFileError' will be thrown in case of a
    -- missing or invalid chunk file, or an invalid index file.
  deriving (Int -> ValidationPolicy -> ShowS
[ValidationPolicy] -> ShowS
ValidationPolicy -> String
(Int -> ValidationPolicy -> ShowS)
-> (ValidationPolicy -> String)
-> ([ValidationPolicy] -> ShowS)
-> Show ValidationPolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ValidationPolicy] -> ShowS
$cshowList :: [ValidationPolicy] -> ShowS
show :: ValidationPolicy -> String
$cshow :: ValidationPolicy -> String
showsPrec :: Int -> ValidationPolicy -> ShowS
$cshowsPrec :: Int -> ValidationPolicy -> ShowS
Show, ValidationPolicy -> ValidationPolicy -> Bool
(ValidationPolicy -> ValidationPolicy -> Bool)
-> (ValidationPolicy -> ValidationPolicy -> Bool)
-> Eq ValidationPolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ValidationPolicy -> ValidationPolicy -> Bool
$c/= :: ValidationPolicy -> ValidationPolicy -> Bool
== :: ValidationPolicy -> ValidationPolicy -> Bool
$c== :: ValidationPolicy -> ValidationPolicy -> Bool
Eq, (forall x. ValidationPolicy -> Rep ValidationPolicy x)
-> (forall x. Rep ValidationPolicy x -> ValidationPolicy)
-> Generic ValidationPolicy
forall x. Rep ValidationPolicy x -> ValidationPolicy
forall x. ValidationPolicy -> Rep ValidationPolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ValidationPolicy x -> ValidationPolicy
$cfrom :: forall x. ValidationPolicy -> Rep ValidationPolicy x
Generic)

{------------------------------------------------------------------------------
  Chunk file error
------------------------------------------------------------------------------}

-- | Defined here instead of in the @Parser@ module because 'TraceEvent'
-- depends on it.
data ChunkFileError blk =
    -- | A block could not be decoded
    ChunkErrRead ReadIncrementalErr

    -- | The previous hash of a block did not match the hash of the previous
    -- block.
  | ChunkErrHashMismatch
      (HeaderHash blk)  -- ^ The hash of the previous block
      (ChainHash blk)   -- ^ The previous hash of the block

    -- | The integrity verification of the block with the given point returned
    -- 'False', indicating that the block got corrupted.
  | ChunkErrCorrupt (Point blk)
  deriving (ChunkFileError blk -> ChunkFileError blk -> Bool
(ChunkFileError blk -> ChunkFileError blk -> Bool)
-> (ChunkFileError blk -> ChunkFileError blk -> Bool)
-> Eq (ChunkFileError blk)
forall blk.
StandardHash blk =>
ChunkFileError blk -> ChunkFileError blk -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ChunkFileError blk -> ChunkFileError blk -> Bool
$c/= :: forall blk.
StandardHash blk =>
ChunkFileError blk -> ChunkFileError blk -> Bool
== :: ChunkFileError blk -> ChunkFileError blk -> Bool
$c== :: forall blk.
StandardHash blk =>
ChunkFileError blk -> ChunkFileError blk -> Bool
Eq, Int -> ChunkFileError blk -> ShowS
[ChunkFileError blk] -> ShowS
ChunkFileError blk -> String
(Int -> ChunkFileError blk -> ShowS)
-> (ChunkFileError blk -> String)
-> ([ChunkFileError blk] -> ShowS)
-> Show (ChunkFileError blk)
forall blk. StandardHash blk => Int -> ChunkFileError blk -> ShowS
forall blk. StandardHash blk => [ChunkFileError blk] -> ShowS
forall blk. StandardHash blk => ChunkFileError blk -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ChunkFileError blk] -> ShowS
$cshowList :: forall blk. StandardHash blk => [ChunkFileError blk] -> ShowS
show :: ChunkFileError blk -> String
$cshow :: forall blk. StandardHash blk => ChunkFileError blk -> String
showsPrec :: Int -> ChunkFileError blk -> ShowS
$cshowsPrec :: forall blk. StandardHash blk => Int -> ChunkFileError blk -> ShowS
Show)

{------------------------------------------------------------------------------
  Tracing
------------------------------------------------------------------------------}

data TraceEvent blk =
    NoValidLastLocation
  | ValidatedLastLocation ChunkNo (Tip blk)
    -- Validation of previous DB
  | ChunkValidationEvent (TraceChunkValidation blk ChunkNo)
  | ChunkFileDoesntFit (ChainHash blk) (ChainHash blk)
    -- ^ The hash of the last block in the previous epoch doesn't match the
    -- previous hash of the first block in the current epoch
  | Migrating Text
    -- ^ Performing a migration of the on-disk files

    -- Delete after
  | DeletingAfter (WithOrigin (Tip blk))
    -- Closing the DB
  | DBAlreadyClosed
  | DBClosed
    -- Events traced by the index cache
  | TraceCacheEvent !TraceCacheEvent
  deriving (TraceEvent blk -> TraceEvent blk -> Bool
(TraceEvent blk -> TraceEvent blk -> Bool)
-> (TraceEvent blk -> TraceEvent blk -> Bool)
-> Eq (TraceEvent blk)
forall blk.
StandardHash blk =>
TraceEvent blk -> TraceEvent blk -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TraceEvent blk -> TraceEvent blk -> Bool
$c/= :: forall blk.
StandardHash blk =>
TraceEvent blk -> TraceEvent blk -> Bool
== :: TraceEvent blk -> TraceEvent blk -> Bool
$c== :: forall blk.
StandardHash blk =>
TraceEvent blk -> TraceEvent blk -> Bool
Eq, (forall x. TraceEvent blk -> Rep (TraceEvent blk) x)
-> (forall x. Rep (TraceEvent blk) x -> TraceEvent blk)
-> Generic (TraceEvent blk)
forall x. Rep (TraceEvent blk) x -> TraceEvent blk
forall x. TraceEvent blk -> Rep (TraceEvent blk) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall blk x. Rep (TraceEvent blk) x -> TraceEvent blk
forall blk x. TraceEvent blk -> Rep (TraceEvent blk) x
$cto :: forall blk x. Rep (TraceEvent blk) x -> TraceEvent blk
$cfrom :: forall blk x. TraceEvent blk -> Rep (TraceEvent blk) x
Generic, Int -> TraceEvent blk -> ShowS
[TraceEvent blk] -> ShowS
TraceEvent blk -> String
(Int -> TraceEvent blk -> ShowS)
-> (TraceEvent blk -> String)
-> ([TraceEvent blk] -> ShowS)
-> Show (TraceEvent blk)
forall blk. StandardHash blk => Int -> TraceEvent blk -> ShowS
forall blk. StandardHash blk => [TraceEvent blk] -> ShowS
forall blk. StandardHash blk => TraceEvent blk -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TraceEvent blk] -> ShowS
$cshowList :: forall blk. StandardHash blk => [TraceEvent blk] -> ShowS
show :: TraceEvent blk -> String
$cshow :: forall blk. StandardHash blk => TraceEvent blk -> String
showsPrec :: Int -> TraceEvent blk -> ShowS
$cshowsPrec :: forall blk. StandardHash blk => Int -> TraceEvent blk -> ShowS
Show)

data TraceChunkValidation blk validateTo =
    StartedValidatingChunk ChunkNo validateTo
  | ValidatedChunk         ChunkNo validateTo
  | MissingChunkFile       ChunkNo
  | InvalidChunkFile       ChunkNo (ChunkFileError blk)
  | MissingPrimaryIndex    ChunkNo
  | MissingSecondaryIndex  ChunkNo
  | InvalidPrimaryIndex    ChunkNo
  | InvalidSecondaryIndex  ChunkNo
  | RewritePrimaryIndex    ChunkNo
  | RewriteSecondaryIndex  ChunkNo
  deriving ((forall x.
 TraceChunkValidation blk validateTo
 -> Rep (TraceChunkValidation blk validateTo) x)
-> (forall x.
    Rep (TraceChunkValidation blk validateTo) x
    -> TraceChunkValidation blk validateTo)
-> Generic (TraceChunkValidation blk validateTo)
forall x.
Rep (TraceChunkValidation blk validateTo) x
-> TraceChunkValidation blk validateTo
forall x.
TraceChunkValidation blk validateTo
-> Rep (TraceChunkValidation blk validateTo) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall blk validateTo x.
Rep (TraceChunkValidation blk validateTo) x
-> TraceChunkValidation blk validateTo
forall blk validateTo x.
TraceChunkValidation blk validateTo
-> Rep (TraceChunkValidation blk validateTo) x
$cto :: forall blk validateTo x.
Rep (TraceChunkValidation blk validateTo) x
-> TraceChunkValidation blk validateTo
$cfrom :: forall blk validateTo x.
TraceChunkValidation blk validateTo
-> Rep (TraceChunkValidation blk validateTo) x
Generic, TraceChunkValidation blk validateTo
-> TraceChunkValidation blk validateTo -> Bool
(TraceChunkValidation blk validateTo
 -> TraceChunkValidation blk validateTo -> Bool)
-> (TraceChunkValidation blk validateTo
    -> TraceChunkValidation blk validateTo -> Bool)
-> Eq (TraceChunkValidation blk validateTo)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall blk validateTo.
(StandardHash blk, Eq validateTo) =>
TraceChunkValidation blk validateTo
-> TraceChunkValidation blk validateTo -> Bool
/= :: TraceChunkValidation blk validateTo
-> TraceChunkValidation blk validateTo -> Bool
$c/= :: forall blk validateTo.
(StandardHash blk, Eq validateTo) =>
TraceChunkValidation blk validateTo
-> TraceChunkValidation blk validateTo -> Bool
== :: TraceChunkValidation blk validateTo
-> TraceChunkValidation blk validateTo -> Bool
$c== :: forall blk validateTo.
(StandardHash blk, Eq validateTo) =>
TraceChunkValidation blk validateTo
-> TraceChunkValidation blk validateTo -> Bool
Eq, Int -> TraceChunkValidation blk validateTo -> ShowS
[TraceChunkValidation blk validateTo] -> ShowS
TraceChunkValidation blk validateTo -> String
(Int -> TraceChunkValidation blk validateTo -> ShowS)
-> (TraceChunkValidation blk validateTo -> String)
-> ([TraceChunkValidation blk validateTo] -> ShowS)
-> Show (TraceChunkValidation blk validateTo)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall blk validateTo.
(StandardHash blk, Show validateTo) =>
Int -> TraceChunkValidation blk validateTo -> ShowS
forall blk validateTo.
(StandardHash blk, Show validateTo) =>
[TraceChunkValidation blk validateTo] -> ShowS
forall blk validateTo.
(StandardHash blk, Show validateTo) =>
TraceChunkValidation blk validateTo -> String
showList :: [TraceChunkValidation blk validateTo] -> ShowS
$cshowList :: forall blk validateTo.
(StandardHash blk, Show validateTo) =>
[TraceChunkValidation blk validateTo] -> ShowS
show :: TraceChunkValidation blk validateTo -> String
$cshow :: forall blk validateTo.
(StandardHash blk, Show validateTo) =>
TraceChunkValidation blk validateTo -> String
showsPrec :: Int -> TraceChunkValidation blk validateTo -> ShowS
$cshowsPrec :: forall blk validateTo.
(StandardHash blk, Show validateTo) =>
Int -> TraceChunkValidation blk validateTo -> ShowS
Show, a -> TraceChunkValidation blk b -> TraceChunkValidation blk a
(a -> b)
-> TraceChunkValidation blk a -> TraceChunkValidation blk b
(forall a b.
 (a -> b)
 -> TraceChunkValidation blk a -> TraceChunkValidation blk b)
-> (forall a b.
    a -> TraceChunkValidation blk b -> TraceChunkValidation blk a)
-> Functor (TraceChunkValidation blk)
forall a b.
a -> TraceChunkValidation blk b -> TraceChunkValidation blk a
forall a b.
(a -> b)
-> TraceChunkValidation blk a -> TraceChunkValidation blk b
forall blk a b.
a -> TraceChunkValidation blk b -> TraceChunkValidation blk a
forall blk a b.
(a -> b)
-> TraceChunkValidation blk a -> TraceChunkValidation blk b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> TraceChunkValidation blk b -> TraceChunkValidation blk a
$c<$ :: forall blk a b.
a -> TraceChunkValidation blk b -> TraceChunkValidation blk a
fmap :: (a -> b)
-> TraceChunkValidation blk a -> TraceChunkValidation blk b
$cfmap :: forall blk a b.
(a -> b)
-> TraceChunkValidation blk a -> TraceChunkValidation blk b
Functor)

-- | The argument with type 'Word32' is the number of past chunk currently in
-- the cache.
data TraceCacheEvent =
    TraceCurrentChunkHit   ChunkNo   Word32
  | TracePastChunkHit      ChunkNo   Word32
  | TracePastChunkMiss     ChunkNo   Word32
  | TracePastChunkEvict    ChunkNo   Word32
    -- ^ The least recently used past chunk was evicted because the cache
    -- was full.
  | TracePastChunksExpired [ChunkNo] Word32
    -- ^ Past chunks were expired from the cache because they haven't been
    -- used for a while.
  deriving (TraceCacheEvent -> TraceCacheEvent -> Bool
(TraceCacheEvent -> TraceCacheEvent -> Bool)
-> (TraceCacheEvent -> TraceCacheEvent -> Bool)
-> Eq TraceCacheEvent
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TraceCacheEvent -> TraceCacheEvent -> Bool
$c/= :: TraceCacheEvent -> TraceCacheEvent -> Bool
== :: TraceCacheEvent -> TraceCacheEvent -> Bool
$c== :: TraceCacheEvent -> TraceCacheEvent -> Bool
Eq, (forall x. TraceCacheEvent -> Rep TraceCacheEvent x)
-> (forall x. Rep TraceCacheEvent x -> TraceCacheEvent)
-> Generic TraceCacheEvent
forall x. Rep TraceCacheEvent x -> TraceCacheEvent
forall x. TraceCacheEvent -> Rep TraceCacheEvent x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TraceCacheEvent x -> TraceCacheEvent
$cfrom :: forall x. TraceCacheEvent -> Rep TraceCacheEvent x
Generic, Int -> TraceCacheEvent -> ShowS
[TraceCacheEvent] -> ShowS
TraceCacheEvent -> String
(Int -> TraceCacheEvent -> ShowS)
-> (TraceCacheEvent -> String)
-> ([TraceCacheEvent] -> ShowS)
-> Show TraceCacheEvent
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TraceCacheEvent] -> ShowS
$cshowList :: [TraceCacheEvent] -> ShowS
show :: TraceCacheEvent -> String
$cshow :: TraceCacheEvent -> String
showsPrec :: Int -> TraceCacheEvent -> ShowS
$cshowsPrec :: Int -> TraceCacheEvent -> ShowS
Show)