{-# 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.Storage.ImmutableDB.API (Tip)
import           Ouroboros.Consensus.Storage.ImmutableDB.Chunks.Internal
                     (ChunkNo)
import           Ouroboros.Consensus.Util.CBOR (ReadIncrementalErr)

{------------------------------------------------------------------------------
  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
$c== :: BlockOrEBB -> BlockOrEBB -> Bool
== :: BlockOrEBB -> BlockOrEBB -> Bool
$c/= :: BlockOrEBB -> BlockOrEBB -> Bool
/= :: 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
$cshowsPrec :: Int -> BlockOrEBB -> ShowS
showsPrec :: Int -> BlockOrEBB -> ShowS
$cshow :: BlockOrEBB -> String
show :: BlockOrEBB -> String
$cshowList :: [BlockOrEBB] -> ShowS
showList :: [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
$cfrom :: forall x. BlockOrEBB -> Rep BlockOrEBB x
from :: forall x. BlockOrEBB -> Rep BlockOrEBB x
$cto :: forall x. Rep BlockOrEBB x -> BlockOrEBB
to :: forall x. Rep BlockOrEBB x -> BlockOrEBB
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
$cnoThunks :: Context -> BlockOrEBB -> IO (Maybe ThunkInfo)
noThunks :: Context -> BlockOrEBB -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> BlockOrEBB -> IO (Maybe ThunkInfo)
wNoThunks :: Context -> BlockOrEBB -> IO (Maybe ThunkInfo)
$cshowTypeOf :: Proxy BlockOrEBB -> String
showTypeOf :: Proxy BlockOrEBB -> String
NoThunks)

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

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