{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeFamilies #-}
module Cardano.Tools.DBAnalyser.HasAnalysis
( HasAnalysis (..)
, HasProtocolInfo (..)
, SizeInBytes
, WithLedgerState (..)
) where
import Cardano.Tools.DBAnalyser.Types (LedgerDBBackend)
import Data.Map.Strict (Map)
import Ouroboros.Consensus.Block
import Ouroboros.Consensus.HeaderValidation (HasAnnTip (..))
import Ouroboros.Consensus.Ledger.Abstract
import Ouroboros.Consensus.Node.ProtocolInfo
import Ouroboros.Consensus.Storage.Serialisation (SizeInBytes)
import Ouroboros.Consensus.Util.Condense (Condense)
import TextBuilder (TextBuilder)
data WithLedgerState blk = WithLedgerState
{ forall blk. WithLedgerState blk -> blk
wlsBlk :: blk
, forall blk. WithLedgerState blk -> LedgerState blk ValuesMK
wlsStateBefore :: LedgerState blk ValuesMK
, forall blk. WithLedgerState blk -> LedgerState blk ValuesMK
wlsStateAfter :: LedgerState blk ValuesMK
}
class (HasAnnTip blk, GetPrevHash blk, Condense (HeaderHash blk)) => HasAnalysis blk where
countTxOutputs :: blk -> Int
blockTxSizes :: blk -> [SizeInBytes]
knownEBBs :: proxy blk -> Map (HeaderHash blk) (ChainHash blk)
emitTraces :: WithLedgerState blk -> [String]
blockStats :: blk -> [TextBuilder]
blockApplicationMetrics :: [(TextBuilder, WithLedgerState blk -> IO TextBuilder)]
class HasProtocolInfo blk where
data Args blk
mkProtocolInfo :: Args blk -> IO (ProtocolInfo blk)
mkProtocolInfo = ((ProtocolInfo blk, Maybe LedgerDBBackend) -> ProtocolInfo blk)
-> IO (ProtocolInfo blk, Maybe LedgerDBBackend)
-> IO (ProtocolInfo blk)
forall a b. (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (ProtocolInfo blk, Maybe LedgerDBBackend) -> ProtocolInfo blk
forall a b. (a, b) -> a
fst (IO (ProtocolInfo blk, Maybe LedgerDBBackend)
-> IO (ProtocolInfo blk))
-> (Args blk -> IO (ProtocolInfo blk, Maybe LedgerDBBackend))
-> Args blk
-> IO (ProtocolInfo blk)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Args blk -> IO (ProtocolInfo blk, Maybe LedgerDBBackend)
forall blk.
HasProtocolInfo blk =>
Args blk -> IO (ProtocolInfo blk, Maybe LedgerDBBackend)
mkProtocolInfoAndBackend
mkProtocolInfoAndBackend :: Args blk -> IO (ProtocolInfo blk, Maybe LedgerDBBackend)
mkProtocolInfoAndBackend Args blk
args = (\ProtocolInfo blk
pInfo -> (ProtocolInfo blk
pInfo, Maybe LedgerDBBackend
forall a. Maybe a
Nothing)) (ProtocolInfo blk -> (ProtocolInfo blk, Maybe LedgerDBBackend))
-> IO (ProtocolInfo blk)
-> IO (ProtocolInfo blk, Maybe LedgerDBBackend)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Args blk -> IO (ProtocolInfo blk)
forall blk.
HasProtocolInfo blk =>
Args blk -> IO (ProtocolInfo blk)
mkProtocolInfo Args blk
args
{-# MINIMAL mkProtocolInfo | mkProtocolInfoAndBackend #-}