{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE QuantifiedConstraints #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE StandaloneKindSignatures #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
module Ouroboros.Consensus.Storage.LedgerDB.API (
CanUpgradeLedgerTables (..)
, LedgerDB (..)
, LedgerDB'
, LedgerDbPrune (..)
, LedgerDbSerialiseConstraints
, LedgerSupportsInMemoryLedgerDB
, LedgerSupportsLedgerDB
, LedgerSupportsOnDiskLedgerDB
, ResolveBlock
, currentPoint
, InitDB (..)
, InitLog (..)
, initialize
, ReplayGoal (..)
, ReplayStart (..)
, TraceReplayEvent (..)
, TraceReplayProgressEvent (..)
, TraceReplayStartEvent (..)
, decorateReplayTracerWithGoal
, decorateReplayTracerWithStart
, LedgerDbCfg
, LedgerDbCfgF (..)
, configLedgerDb
, LedgerDbError (..)
, getReadOnlyForker
, getTipStatistics
, readLedgerTablesAtFor
, withPrivateTipForker
, withTipForker
, SnapCounters (..)
, TestInternals (..)
, TestInternals'
, WhereToTakeSnapshot (..)
) where
import Codec.Serialise
import qualified Control.Monad as Monad
import Control.Monad.Class.MonadTime.SI
import Control.Monad.Except
import Control.ResourceRegistry
import Control.Tracer
import Data.Functor.Contravariant ((>$<))
import Data.Kind
import qualified Data.Map.Strict as Map
import Data.MemPack
import Data.Set (Set)
import Data.Void (absurd)
import Data.Word
import GHC.Generics (Generic)
import NoThunks.Class
import Ouroboros.Consensus.Block
import Ouroboros.Consensus.Config
import Ouroboros.Consensus.HeaderStateHistory
import Ouroboros.Consensus.HeaderValidation
import Ouroboros.Consensus.Ledger.Abstract
import Ouroboros.Consensus.Ledger.Extended
import Ouroboros.Consensus.Ledger.Inspect
import Ouroboros.Consensus.Ledger.SupportsProtocol
import Ouroboros.Consensus.Protocol.Abstract
import Ouroboros.Consensus.Storage.ChainDB.Impl.BlockCache
import Ouroboros.Consensus.Storage.ImmutableDB.Stream
import Ouroboros.Consensus.Storage.LedgerDB.Forker
import Ouroboros.Consensus.Storage.LedgerDB.Snapshots
import Ouroboros.Consensus.Storage.Serialisation
import Ouroboros.Consensus.Util.Args
import Ouroboros.Consensus.Util.CallStack
import Ouroboros.Consensus.Util.IndexedMemPack
import Ouroboros.Consensus.Util.IOLike
import Ouroboros.Network.Block
import Ouroboros.Network.Protocol.LocalStateQuery.Type
import System.FS.API
type LedgerDbSerialiseConstraints blk =
( Serialise (HeaderHash blk)
, EncodeDisk blk (LedgerState blk EmptyMK)
, DecodeDisk blk (LedgerState blk EmptyMK)
, EncodeDisk blk (AnnTip blk)
, DecodeDisk blk (AnnTip blk)
, EncodeDisk blk (ChainDepState (BlockProtocol blk))
, DecodeDisk blk (ChainDepState (BlockProtocol blk))
, MemPack (TxIn (LedgerState blk))
, SerializeTablesWithHint (LedgerState blk)
, IndexedMemPack (LedgerState blk EmptyMK) (TxOut (LedgerState blk))
)
type LedgerDB :: (Type -> Type) -> LedgerStateKind -> Type -> Type
data LedgerDB m l blk = LedgerDB {
forall (m :: * -> *) (l :: LedgerStateKind) blk.
LedgerDB m l blk -> STM m (l EmptyMK)
getVolatileTip :: STM m (l EmptyMK)
, forall (m :: * -> *) (l :: LedgerStateKind) blk.
LedgerDB m l blk -> STM m (l EmptyMK)
getImmutableTip :: STM m (l EmptyMK)
, forall (m :: * -> *) (l :: LedgerStateKind) blk.
LedgerDB m l blk -> Point blk -> STM m (Maybe (l EmptyMK))
getPastLedgerState :: Point blk -> STM m (Maybe (l EmptyMK))
, ::
(l ~ ExtLedgerState blk)
=> STM m (HeaderStateHistory blk)
, forall (m :: * -> *) (l :: LedgerStateKind) blk.
LedgerDB m l blk
-> ResourceRegistry m
-> Target (Point blk)
-> m (Either GetForkerError (Forker m l blk))
getForkerAtTarget ::
ResourceRegistry m
-> Target (Point blk)
-> m (Either GetForkerError (Forker m l blk))
, forall (m :: * -> *) (l :: LedgerStateKind) blk.
LedgerDB m l blk
-> (l ~ ExtLedgerState blk) =>
ResourceRegistry m
-> (TraceValidateEvent blk -> m ())
-> BlockCache blk
-> Word64
-> [Header blk]
-> m (ValidateResult m l blk)
validateFork ::
(l ~ ExtLedgerState blk)
=> ResourceRegistry m
-> (TraceValidateEvent blk -> m ())
-> BlockCache blk
-> Word64
-> [Header blk]
-> m (ValidateResult m l blk)
, forall (m :: * -> *) (l :: LedgerStateKind) blk.
LedgerDB m l blk -> STM m (Set (RealPoint blk))
getPrevApplied :: STM m (Set (RealPoint blk))
, forall (m :: * -> *) (l :: LedgerStateKind) blk.
LedgerDB m l blk -> SlotNo -> STM m ()
garbageCollect :: SlotNo -> STM m ()
, forall (m :: * -> *) (l :: LedgerStateKind) blk.
LedgerDB m l blk
-> (l ~ ExtLedgerState blk) =>
Maybe (Time, Time) -> Word64 -> m SnapCounters
tryTakeSnapshot ::
(l ~ ExtLedgerState blk)
=> Maybe (Time, Time)
-> Word64
-> m SnapCounters
, forall (m :: * -> *) (l :: LedgerStateKind) blk.
LedgerDB m l blk -> m ()
tryFlush :: m ()
, forall (m :: * -> *) (l :: LedgerStateKind) blk.
LedgerDB m l blk -> m ()
closeDB :: m ()
}
deriving Context -> LedgerDB m l blk -> IO (Maybe ThunkInfo)
Proxy (LedgerDB m l blk) -> String
(Context -> LedgerDB m l blk -> IO (Maybe ThunkInfo))
-> (Context -> LedgerDB m l blk -> IO (Maybe ThunkInfo))
-> (Proxy (LedgerDB m l blk) -> String)
-> NoThunks (LedgerDB m l blk)
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
forall (m :: * -> *) (l :: LedgerStateKind) blk.
Context -> LedgerDB m l blk -> IO (Maybe ThunkInfo)
forall (m :: * -> *) (l :: LedgerStateKind) blk.
Proxy (LedgerDB m l blk) -> String
$cnoThunks :: forall (m :: * -> *) (l :: LedgerStateKind) blk.
Context -> LedgerDB m l blk -> IO (Maybe ThunkInfo)
noThunks :: Context -> LedgerDB m l blk -> IO (Maybe ThunkInfo)
$cwNoThunks :: forall (m :: * -> *) (l :: LedgerStateKind) blk.
Context -> LedgerDB m l blk -> IO (Maybe ThunkInfo)
wNoThunks :: Context -> LedgerDB m l blk -> IO (Maybe ThunkInfo)
$cshowTypeOf :: forall (m :: * -> *) (l :: LedgerStateKind) blk.
Proxy (LedgerDB m l blk) -> String
showTypeOf :: Proxy (LedgerDB m l blk) -> String
NoThunks via OnlyCheckWhnfNamed "LedgerDB" (LedgerDB m l blk)
type instance (LedgerDB m l blk) = HeaderHash blk
type LedgerDB' m blk = LedgerDB m (ExtLedgerState blk) blk
currentPoint ::
(GetTip l, HeaderHash l ~ HeaderHash blk, Functor (STM m))
=> LedgerDB m l blk
-> STM m (Point blk)
currentPoint :: forall (l :: LedgerStateKind) blk (m :: * -> *).
(GetTip l, HeaderHash l ~ HeaderHash blk, Functor (STM m)) =>
LedgerDB m l blk -> STM m (Point blk)
currentPoint LedgerDB m l blk
ldb = Point l -> Point blk
forall {k1} {k2} (b :: k1) (b' :: k2).
Coercible (HeaderHash b) (HeaderHash b') =>
Point b -> Point b'
castPoint (Point l -> Point blk)
-> (l EmptyMK -> Point l) -> l EmptyMK -> Point blk
forall b c a. (b -> c) -> (a -> b) -> a -> c
. l EmptyMK -> Point l
forall (mk :: MapKind). l mk -> Point l
forall (l :: LedgerStateKind) (mk :: MapKind).
GetTip l =>
l mk -> Point l
getTip (l EmptyMK -> Point blk) -> STM m (l EmptyMK) -> STM m (Point blk)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LedgerDB m l blk -> STM m (l EmptyMK)
forall (m :: * -> *) (l :: LedgerStateKind) blk.
LedgerDB m l blk -> STM m (l EmptyMK)
getVolatileTip LedgerDB m l blk
ldb
data WhereToTakeSnapshot = TakeAtImmutableTip | TakeAtVolatileTip deriving WhereToTakeSnapshot -> WhereToTakeSnapshot -> Bool
(WhereToTakeSnapshot -> WhereToTakeSnapshot -> Bool)
-> (WhereToTakeSnapshot -> WhereToTakeSnapshot -> Bool)
-> Eq WhereToTakeSnapshot
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: WhereToTakeSnapshot -> WhereToTakeSnapshot -> Bool
== :: WhereToTakeSnapshot -> WhereToTakeSnapshot -> Bool
$c/= :: WhereToTakeSnapshot -> WhereToTakeSnapshot -> Bool
/= :: WhereToTakeSnapshot -> WhereToTakeSnapshot -> Bool
Eq
data TestInternals m l blk = TestInternals {
forall {k} (m :: * -> *) (l :: k) blk.
TestInternals m l blk -> m ()
wipeLedgerDB :: m ()
, forall {k} (m :: * -> *) (l :: k) blk.
TestInternals m l blk
-> WhereToTakeSnapshot -> Maybe String -> m ()
takeSnapshotNOW :: WhereToTakeSnapshot -> Maybe String -> m ()
, forall {k} (m :: * -> *) (l :: k) blk.
TestInternals m l blk -> ExtLedgerState blk DiffMK -> m ()
push :: ExtLedgerState blk DiffMK -> m ()
, forall {k} (m :: * -> *) (l :: k) blk.
TestInternals m l blk -> blk -> m ()
reapplyThenPushNOW :: blk -> m ()
, forall {k} (m :: * -> *) (l :: k) blk.
TestInternals m l blk -> m ()
truncateSnapshots :: m ()
, forall {k} (m :: * -> *) (l :: k) blk.
TestInternals m l blk -> m ()
closeLedgerDB :: m ()
}
deriving Context -> TestInternals m l blk -> IO (Maybe ThunkInfo)
Proxy (TestInternals m l blk) -> String
(Context -> TestInternals m l blk -> IO (Maybe ThunkInfo))
-> (Context -> TestInternals m l blk -> IO (Maybe ThunkInfo))
-> (Proxy (TestInternals m l blk) -> String)
-> NoThunks (TestInternals m l blk)
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
forall (m :: * -> *) k (l :: k) blk.
Context -> TestInternals m l blk -> IO (Maybe ThunkInfo)
forall (m :: * -> *) k (l :: k) blk.
Proxy (TestInternals m l blk) -> String
$cnoThunks :: forall (m :: * -> *) k (l :: k) blk.
Context -> TestInternals m l blk -> IO (Maybe ThunkInfo)
noThunks :: Context -> TestInternals m l blk -> IO (Maybe ThunkInfo)
$cwNoThunks :: forall (m :: * -> *) k (l :: k) blk.
Context -> TestInternals m l blk -> IO (Maybe ThunkInfo)
wNoThunks :: Context -> TestInternals m l blk -> IO (Maybe ThunkInfo)
$cshowTypeOf :: forall (m :: * -> *) k (l :: k) blk.
Proxy (TestInternals m l blk) -> String
showTypeOf :: Proxy (TestInternals m l blk) -> String
NoThunks via OnlyCheckWhnfNamed "TestInternals" (TestInternals m l blk)
type TestInternals' m blk = TestInternals m (ExtLedgerState blk) blk
data LedgerDbCfgF f l = LedgerDbCfg {
forall (f :: * -> *) (l :: LedgerStateKind).
LedgerDbCfgF f l -> HKD f SecurityParam
ledgerDbCfgSecParam :: !(HKD f SecurityParam)
, forall (f :: * -> *) (l :: LedgerStateKind).
LedgerDbCfgF f l -> HKD f (LedgerCfg l)
ledgerDbCfg :: !(HKD f (LedgerCfg l))
, forall (f :: * -> *) (l :: LedgerStateKind).
LedgerDbCfgF f l -> ComputeLedgerEvents
ledgerDbCfgComputeLedgerEvents :: !ComputeLedgerEvents
}
deriving ((forall x. LedgerDbCfgF f l -> Rep (LedgerDbCfgF f l) x)
-> (forall x. Rep (LedgerDbCfgF f l) x -> LedgerDbCfgF f l)
-> Generic (LedgerDbCfgF f l)
forall x. Rep (LedgerDbCfgF f l) x -> LedgerDbCfgF f l
forall x. LedgerDbCfgF f l -> Rep (LedgerDbCfgF f l) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (f :: * -> *) (l :: LedgerStateKind) x.
Rep (LedgerDbCfgF f l) x -> LedgerDbCfgF f l
forall (f :: * -> *) (l :: LedgerStateKind) x.
LedgerDbCfgF f l -> Rep (LedgerDbCfgF f l) x
$cfrom :: forall (f :: * -> *) (l :: LedgerStateKind) x.
LedgerDbCfgF f l -> Rep (LedgerDbCfgF f l) x
from :: forall x. LedgerDbCfgF f l -> Rep (LedgerDbCfgF f l) x
$cto :: forall (f :: * -> *) (l :: LedgerStateKind) x.
Rep (LedgerDbCfgF f l) x -> LedgerDbCfgF f l
to :: forall x. Rep (LedgerDbCfgF f l) x -> LedgerDbCfgF f l
Generic)
type LedgerDbCfg l = Complete LedgerDbCfgF l
deriving instance NoThunks (LedgerCfg l) => NoThunks (LedgerDbCfg l)
configLedgerDb ::
ConsensusProtocol (BlockProtocol blk)
=> TopLevelConfig blk
-> ComputeLedgerEvents
-> LedgerDbCfg (ExtLedgerState blk)
configLedgerDb :: forall blk.
ConsensusProtocol (BlockProtocol blk) =>
TopLevelConfig blk
-> ComputeLedgerEvents -> LedgerDbCfg (ExtLedgerState blk)
configLedgerDb TopLevelConfig blk
config ComputeLedgerEvents
evs = LedgerDbCfg {
ledgerDbCfgSecParam :: HKD Identity SecurityParam
ledgerDbCfgSecParam = TopLevelConfig blk -> SecurityParam
forall blk.
ConsensusProtocol (BlockProtocol blk) =>
TopLevelConfig blk -> SecurityParam
configSecurityParam TopLevelConfig blk
config
, ledgerDbCfg :: HKD Identity (LedgerCfg (ExtLedgerState blk))
ledgerDbCfg = TopLevelConfig blk -> ExtLedgerCfg blk
forall blk. TopLevelConfig blk -> ExtLedgerCfg blk
ExtLedgerCfg TopLevelConfig blk
config
, ledgerDbCfgComputeLedgerEvents :: ComputeLedgerEvents
ledgerDbCfgComputeLedgerEvents = ComputeLedgerEvents
evs
}
data LedgerDbError blk =
ClosedDBError PrettyCallStack
| ClosedForkerError ForkerKey PrettyCallStack
deriving (Int -> LedgerDbError blk -> ShowS
[LedgerDbError blk] -> ShowS
LedgerDbError blk -> String
(Int -> LedgerDbError blk -> ShowS)
-> (LedgerDbError blk -> String)
-> ([LedgerDbError blk] -> ShowS)
-> Show (LedgerDbError blk)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k (blk :: k). Int -> LedgerDbError blk -> ShowS
forall k (blk :: k). [LedgerDbError blk] -> ShowS
forall k (blk :: k). LedgerDbError blk -> String
$cshowsPrec :: forall k (blk :: k). Int -> LedgerDbError blk -> ShowS
showsPrec :: Int -> LedgerDbError blk -> ShowS
$cshow :: forall k (blk :: k). LedgerDbError blk -> String
show :: LedgerDbError blk -> String
$cshowList :: forall k (blk :: k). [LedgerDbError blk] -> ShowS
showList :: [LedgerDbError blk] -> ShowS
Show)
deriving anyclass (Show (LedgerDbError blk)
Typeable (LedgerDbError blk)
(Typeable (LedgerDbError blk), Show (LedgerDbError blk)) =>
(LedgerDbError blk -> SomeException)
-> (SomeException -> Maybe (LedgerDbError blk))
-> (LedgerDbError blk -> String)
-> (LedgerDbError blk -> Bool)
-> Exception (LedgerDbError blk)
SomeException -> Maybe (LedgerDbError blk)
LedgerDbError blk -> Bool
LedgerDbError blk -> String
LedgerDbError blk -> SomeException
forall e.
(Typeable e, Show e) =>
(e -> SomeException)
-> (SomeException -> Maybe e)
-> (e -> String)
-> (e -> Bool)
-> Exception e
forall k (blk :: k).
(Typeable blk, Typeable k) =>
Show (LedgerDbError blk)
forall k (blk :: k).
(Typeable blk, Typeable k) =>
Typeable (LedgerDbError blk)
forall k (blk :: k).
(Typeable blk, Typeable k) =>
SomeException -> Maybe (LedgerDbError blk)
forall k (blk :: k).
(Typeable blk, Typeable k) =>
LedgerDbError blk -> Bool
forall k (blk :: k).
(Typeable blk, Typeable k) =>
LedgerDbError blk -> String
forall k (blk :: k).
(Typeable blk, Typeable k) =>
LedgerDbError blk -> SomeException
$ctoException :: forall k (blk :: k).
(Typeable blk, Typeable k) =>
LedgerDbError blk -> SomeException
toException :: LedgerDbError blk -> SomeException
$cfromException :: forall k (blk :: k).
(Typeable blk, Typeable k) =>
SomeException -> Maybe (LedgerDbError blk)
fromException :: SomeException -> Maybe (LedgerDbError blk)
$cdisplayException :: forall k (blk :: k).
(Typeable blk, Typeable k) =>
LedgerDbError blk -> String
displayException :: LedgerDbError blk -> String
$cbacktraceDesired :: forall k (blk :: k).
(Typeable blk, Typeable k) =>
LedgerDbError blk -> Bool
backtraceDesired :: LedgerDbError blk -> Bool
Exception)
withTipForker ::
IOLike m
=> LedgerDB m l blk
-> ResourceRegistry m
-> (Forker m l blk -> m a)
-> m a
withTipForker :: forall (m :: * -> *) (l :: LedgerStateKind) blk a.
IOLike m =>
LedgerDB m l blk
-> ResourceRegistry m -> (Forker m l blk -> m a) -> m a
withTipForker LedgerDB m l blk
ldb ResourceRegistry m
rr =
m (Forker m l blk)
-> (Forker m l blk -> m ()) -> (Forker m l blk -> m a) -> m a
forall a b c. m a -> (a -> m b) -> (a -> m c) -> m c
forall (m :: * -> *) a b c.
MonadThrow m =>
m a -> (a -> m b) -> (a -> m c) -> m c
bracket
(do
eFrk <- LedgerDB m l blk
-> ResourceRegistry m
-> Target (Point blk)
-> m (Either GetForkerError (Forker m l blk))
forall (m :: * -> *) (l :: LedgerStateKind) blk.
LedgerDB m l blk
-> ResourceRegistry m
-> Target (Point blk)
-> m (Either GetForkerError (Forker m l blk))
getForkerAtTarget LedgerDB m l blk
ldb ResourceRegistry m
rr Target (Point blk)
forall point. Target point
VolatileTip
case eFrk of
Left {} -> String -> m (Forker m l blk)
forall a. HasCallStack => String -> a
error String
"Unreachable, volatile tip MUST be in the LedgerDB"
Right Forker m l blk
frk -> Forker m l blk -> m (Forker m l blk)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Forker m l blk
frk
)
Forker m l blk -> m ()
forall (m :: * -> *) (l :: LedgerStateKind) blk.
Forker m l blk -> m ()
forkerClose
withPrivateTipForker ::
IOLike m
=> LedgerDB m l blk
-> (Forker m l blk -> m a) -> m a
withPrivateTipForker :: forall (m :: * -> *) (l :: LedgerStateKind) blk a.
IOLike m =>
LedgerDB m l blk -> (Forker m l blk -> m a) -> m a
withPrivateTipForker LedgerDB m l blk
ldb =
(ResourceRegistry m -> m (Forker m l blk))
-> (Forker m l blk -> m ()) -> (Forker m l blk -> m a) -> m a
forall (m :: * -> *) a r.
(MonadSTM m, MonadMask m, MonadThread m, HasCallStack) =>
(ResourceRegistry m -> m a) -> (a -> m ()) -> (a -> m r) -> m r
bracketWithPrivateRegistry
(\ResourceRegistry m
rr -> do
eFrk <- LedgerDB m l blk
-> ResourceRegistry m
-> Target (Point blk)
-> m (Either GetForkerError (Forker m l blk))
forall (m :: * -> *) (l :: LedgerStateKind) blk.
LedgerDB m l blk
-> ResourceRegistry m
-> Target (Point blk)
-> m (Either GetForkerError (Forker m l blk))
getForkerAtTarget LedgerDB m l blk
ldb ResourceRegistry m
rr Target (Point blk)
forall point. Target point
VolatileTip
case eFrk of
Left {} -> String -> m (Forker m l blk)
forall a. HasCallStack => String -> a
error String
"Unreachable, volatile tip MUST be in the LedgerDB"
Right Forker m l blk
frk -> Forker m l blk -> m (Forker m l blk)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Forker m l blk
frk
)
Forker m l blk -> m ()
forall (m :: * -> *) (l :: LedgerStateKind) blk.
Forker m l blk -> m ()
forkerClose
getTipStatistics ::
IOLike m
=> LedgerDB m l blk
-> m (Maybe Statistics)
getTipStatistics :: forall (m :: * -> *) (l :: LedgerStateKind) blk.
IOLike m =>
LedgerDB m l blk -> m (Maybe Statistics)
getTipStatistics LedgerDB m l blk
ldb = LedgerDB m l blk
-> (Forker m l blk -> m (Maybe Statistics)) -> m (Maybe Statistics)
forall (m :: * -> *) (l :: LedgerStateKind) blk a.
IOLike m =>
LedgerDB m l blk -> (Forker m l blk -> m a) -> m a
withPrivateTipForker LedgerDB m l blk
ldb Forker m l blk -> m (Maybe Statistics)
forall (m :: * -> *) (l :: LedgerStateKind) blk.
Forker m l blk -> m (Maybe Statistics)
forkerReadStatistics
getReadOnlyForker ::
MonadSTM m
=> LedgerDB m l blk
-> ResourceRegistry m
-> Target (Point blk)
-> m (Either GetForkerError (ReadOnlyForker m l blk))
getReadOnlyForker :: forall (m :: * -> *) (l :: LedgerStateKind) blk.
MonadSTM m =>
LedgerDB m l blk
-> ResourceRegistry m
-> Target (Point blk)
-> m (Either GetForkerError (ReadOnlyForker m l blk))
getReadOnlyForker LedgerDB m l blk
ldb ResourceRegistry m
rr Target (Point blk)
pt = (Forker m l blk -> ReadOnlyForker m l blk)
-> Either GetForkerError (Forker m l blk)
-> Either GetForkerError (ReadOnlyForker m l blk)
forall a b.
(a -> b) -> Either GetForkerError a -> Either GetForkerError b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Forker m l blk -> ReadOnlyForker m l blk
forall (m :: * -> *) (l :: LedgerStateKind) blk.
Forker m l blk -> ReadOnlyForker m l blk
readOnlyForker (Either GetForkerError (Forker m l blk)
-> Either GetForkerError (ReadOnlyForker m l blk))
-> m (Either GetForkerError (Forker m l blk))
-> m (Either GetForkerError (ReadOnlyForker m l blk))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LedgerDB m l blk
-> ResourceRegistry m
-> Target (Point blk)
-> m (Either GetForkerError (Forker m l blk))
forall (m :: * -> *) (l :: LedgerStateKind) blk.
LedgerDB m l blk
-> ResourceRegistry m
-> Target (Point blk)
-> m (Either GetForkerError (Forker m l blk))
getForkerAtTarget LedgerDB m l blk
ldb ResourceRegistry m
rr Target (Point blk)
pt
readLedgerTablesAtFor ::
IOLike m
=> LedgerDB m l blk
-> Point blk
-> LedgerTables l KeysMK
-> m (Either GetForkerError (LedgerTables l ValuesMK))
readLedgerTablesAtFor :: forall (m :: * -> *) (l :: LedgerStateKind) blk.
IOLike m =>
LedgerDB m l blk
-> Point blk
-> LedgerTables l KeysMK
-> m (Either GetForkerError (LedgerTables l ValuesMK))
readLedgerTablesAtFor LedgerDB m l blk
ldb Point blk
p LedgerTables l KeysMK
ks =
(ResourceRegistry m
-> m (Either GetForkerError (ReadOnlyForker m l blk)))
-> (Either GetForkerError (ReadOnlyForker m l blk) -> m ())
-> (Either GetForkerError (ReadOnlyForker m l blk)
-> m (Either GetForkerError (LedgerTables l ValuesMK)))
-> m (Either GetForkerError (LedgerTables l ValuesMK))
forall (m :: * -> *) a r.
(MonadSTM m, MonadMask m, MonadThread m, HasCallStack) =>
(ResourceRegistry m -> m a) -> (a -> m ()) -> (a -> m r) -> m r
bracketWithPrivateRegistry
(\ResourceRegistry m
rr -> (Forker m l blk -> ReadOnlyForker m l blk)
-> Either GetForkerError (Forker m l blk)
-> Either GetForkerError (ReadOnlyForker m l blk)
forall a b.
(a -> b) -> Either GetForkerError a -> Either GetForkerError b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Forker m l blk -> ReadOnlyForker m l blk
forall (m :: * -> *) (l :: LedgerStateKind) blk.
Forker m l blk -> ReadOnlyForker m l blk
readOnlyForker (Either GetForkerError (Forker m l blk)
-> Either GetForkerError (ReadOnlyForker m l blk))
-> m (Either GetForkerError (Forker m l blk))
-> m (Either GetForkerError (ReadOnlyForker m l blk))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LedgerDB m l blk
-> ResourceRegistry m
-> Target (Point blk)
-> m (Either GetForkerError (Forker m l blk))
forall (m :: * -> *) (l :: LedgerStateKind) blk.
LedgerDB m l blk
-> ResourceRegistry m
-> Target (Point blk)
-> m (Either GetForkerError (Forker m l blk))
getForkerAtTarget LedgerDB m l blk
ldb ResourceRegistry m
rr (Point blk -> Target (Point blk)
forall point. point -> Target point
SpecificPoint Point blk
p))
((ReadOnlyForker m l blk -> m ())
-> Either GetForkerError (ReadOnlyForker m l blk) -> m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ ReadOnlyForker m l blk -> m ()
forall (m :: * -> *) (l :: LedgerStateKind) blk.
ReadOnlyForker m l blk -> m ()
roforkerClose)
((Either GetForkerError (ReadOnlyForker m l blk)
-> m (Either GetForkerError (LedgerTables l ValuesMK)))
-> m (Either GetForkerError (LedgerTables l ValuesMK)))
-> (Either GetForkerError (ReadOnlyForker m l blk)
-> m (Either GetForkerError (LedgerTables l ValuesMK)))
-> m (Either GetForkerError (LedgerTables l ValuesMK))
forall a b. (a -> b) -> a -> b
$ \Either GetForkerError (ReadOnlyForker m l blk)
foEith -> Either GetForkerError (ReadOnlyForker m l blk)
-> (ReadOnlyForker m l blk -> m (LedgerTables l ValuesMK))
-> m (Either GetForkerError (LedgerTables l ValuesMK))
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
Monad.forM Either GetForkerError (ReadOnlyForker m l blk)
foEith (ReadOnlyForker m l blk
-> LedgerTables l KeysMK -> m (LedgerTables l ValuesMK)
forall (m :: * -> *) (l :: LedgerStateKind) blk.
ReadOnlyForker m l blk
-> LedgerTables l KeysMK -> m (LedgerTables l ValuesMK)
`roforkerReadTables` LedgerTables l KeysMK
ks)
data SnapCounters = SnapCounters {
SnapCounters -> Maybe Time
prevSnapshotTime :: !(Maybe Time)
, SnapCounters -> Word64
ntBlocksSinceLastSnap :: !Word64
}
data InitLog blk =
InitFromGenesis
| InitFromSnapshot DiskSnapshot (RealPoint blk)
| InitFailure DiskSnapshot (SnapshotFailure blk) (InitLog blk)
deriving (Int -> InitLog blk -> ShowS
[InitLog blk] -> ShowS
InitLog blk -> String
(Int -> InitLog blk -> ShowS)
-> (InitLog blk -> String)
-> ([InitLog blk] -> ShowS)
-> Show (InitLog blk)
forall blk. StandardHash blk => Int -> InitLog blk -> ShowS
forall blk. StandardHash blk => [InitLog blk] -> ShowS
forall blk. StandardHash blk => InitLog blk -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall blk. StandardHash blk => Int -> InitLog blk -> ShowS
showsPrec :: Int -> InitLog blk -> ShowS
$cshow :: forall blk. StandardHash blk => InitLog blk -> String
show :: InitLog blk -> String
$cshowList :: forall blk. StandardHash blk => [InitLog blk] -> ShowS
showList :: [InitLog blk] -> ShowS
Show, InitLog blk -> InitLog blk -> Bool
(InitLog blk -> InitLog blk -> Bool)
-> (InitLog blk -> InitLog blk -> Bool) -> Eq (InitLog blk)
forall blk. StandardHash blk => InitLog blk -> InitLog blk -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall blk. StandardHash blk => InitLog blk -> InitLog blk -> Bool
== :: InitLog blk -> InitLog blk -> Bool
$c/= :: forall blk. StandardHash blk => InitLog blk -> InitLog blk -> Bool
/= :: InitLog blk -> InitLog blk -> Bool
Eq, (forall x. InitLog blk -> Rep (InitLog blk) x)
-> (forall x. Rep (InitLog blk) x -> InitLog blk)
-> Generic (InitLog blk)
forall x. Rep (InitLog blk) x -> InitLog blk
forall x. InitLog blk -> Rep (InitLog blk) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall blk x. Rep (InitLog blk) x -> InitLog blk
forall blk x. InitLog blk -> Rep (InitLog blk) x
$cfrom :: forall blk x. InitLog blk -> Rep (InitLog blk) x
from :: forall x. InitLog blk -> Rep (InitLog blk) x
$cto :: forall blk x. Rep (InitLog blk) x -> InitLog blk
to :: forall x. Rep (InitLog blk) x -> InitLog blk
Generic)
type InitDB :: Type -> (Type -> Type) -> Type -> Type
data InitDB db m blk = InitDB {
forall db (m :: * -> *) blk. InitDB db m blk -> m db
initFromGenesis :: !(m db)
, forall db (m :: * -> *) blk.
InitDB db m blk
-> DiskSnapshot
-> m (Either (SnapshotFailure blk) (db, RealPoint blk))
initFromSnapshot :: !(DiskSnapshot -> m (Either (SnapshotFailure blk) (db, RealPoint blk)))
, forall db (m :: * -> *) blk. InitDB db m blk -> db -> m ()
closeDb :: !(db -> m ())
, forall db (m :: * -> *) blk.
InitDB db m blk
-> LedgerDbCfg (ExtLedgerState blk) -> blk -> db -> m db
initReapplyBlock :: !(LedgerDbCfg (ExtLedgerState blk) -> blk -> db -> m db)
, forall db (m :: * -> *) blk.
InitDB db m blk -> db -> LedgerState blk EmptyMK
currentTip :: !(db -> LedgerState blk EmptyMK)
, forall db (m :: * -> *) blk. InitDB db m blk -> db -> m db
pruneDb :: !(db -> m db)
, forall db (m :: * -> *) blk.
InitDB db m blk
-> db
-> m (LedgerDB m (ExtLedgerState blk) blk,
TestInternals m (ExtLedgerState blk) blk)
mkLedgerDb :: !(db -> m (LedgerDB m (ExtLedgerState blk) blk, TestInternals m (ExtLedgerState blk) blk))
}
initialize ::
forall m blk db.
( IOLike m
, LedgerSupportsProtocol blk
, InspectLedger blk
, HasCallStack
)
=> Tracer m (TraceReplayEvent blk)
-> Tracer m (TraceSnapshotEvent blk)
-> SomeHasFS m
-> LedgerDbCfg (ExtLedgerState blk)
-> StreamAPI m blk blk
-> Point blk
-> InitDB db m blk
-> Maybe DiskSnapshot
-> m (InitLog blk, db, Word64)
initialize :: forall (m :: * -> *) blk db.
(IOLike m, LedgerSupportsProtocol blk, InspectLedger blk,
HasCallStack) =>
Tracer m (TraceReplayEvent blk)
-> Tracer m (TraceSnapshotEvent blk)
-> SomeHasFS m
-> LedgerDbCfg (ExtLedgerState blk)
-> StreamAPI m blk blk
-> Point blk
-> InitDB db m blk
-> Maybe DiskSnapshot
-> m (InitLog blk, db, Word64)
initialize Tracer m (TraceReplayEvent blk)
replayTracer
Tracer m (TraceSnapshotEvent blk)
snapTracer
SomeHasFS m
hasFS
LedgerDbCfg (ExtLedgerState blk)
cfg
StreamAPI m blk blk
stream
Point blk
replayGoal
InitDB db m blk
dbIface
Maybe DiskSnapshot
fromSnapshot =
case Maybe DiskSnapshot
fromSnapshot of
Maybe DiskSnapshot
Nothing -> SomeHasFS m -> m [DiskSnapshot]
forall (m :: * -> *). Monad m => SomeHasFS m -> m [DiskSnapshot]
listSnapshots SomeHasFS m
hasFS m [DiskSnapshot]
-> ([DiskSnapshot] -> m (InitLog blk, db, Word64))
-> m (InitLog blk, db, Word64)
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (InitLog blk -> InitLog blk)
-> [DiskSnapshot] -> m (InitLog blk, db, Word64)
tryNewestFirst InitLog blk -> InitLog blk
forall a. a -> a
id
Just DiskSnapshot
snap -> (InitLog blk -> InitLog blk)
-> [DiskSnapshot] -> m (InitLog blk, db, Word64)
tryNewestFirst InitLog blk -> InitLog blk
forall a. a -> a
id [DiskSnapshot
snap]
where
InitDB {m db
initFromGenesis :: forall db (m :: * -> *) blk. InitDB db m blk -> m db
initFromGenesis :: m db
initFromGenesis, DiskSnapshot
-> m (Either (SnapshotFailure blk) (db, RealPoint blk))
initFromSnapshot :: forall db (m :: * -> *) blk.
InitDB db m blk
-> DiskSnapshot
-> m (Either (SnapshotFailure blk) (db, RealPoint blk))
initFromSnapshot :: DiskSnapshot
-> m (Either (SnapshotFailure blk) (db, RealPoint blk))
initFromSnapshot, db -> m ()
closeDb :: forall db (m :: * -> *) blk. InitDB db m blk -> db -> m ()
closeDb :: db -> m ()
closeDb} = InitDB db m blk
dbIface
tryNewestFirst :: (InitLog blk -> InitLog blk)
-> [DiskSnapshot]
-> m ( InitLog blk
, db
, Word64
)
tryNewestFirst :: (InitLog blk -> InitLog blk)
-> [DiskSnapshot] -> m (InitLog blk, db, Word64)
tryNewestFirst InitLog blk -> InitLog blk
acc [] = do
Tracer m (TraceReplayStartEvent blk)
-> TraceReplayStartEvent blk -> m ()
forall (m :: * -> *) a. Tracer m a -> a -> m ()
traceWith (TraceReplayStartEvent blk -> TraceReplayEvent blk
forall blk. TraceReplayStartEvent blk -> TraceReplayEvent blk
TraceReplayStartEvent (TraceReplayStartEvent blk -> TraceReplayEvent blk)
-> Tracer m (TraceReplayEvent blk)
-> Tracer m (TraceReplayStartEvent blk)
forall (f :: * -> *) a b. Contravariant f => (a -> b) -> f b -> f a
>$< Tracer m (TraceReplayEvent blk)
replayTracer) TraceReplayStartEvent blk
forall {k} (blk :: k). TraceReplayStartEvent blk
ReplayFromGenesis
let replayTracer'' :: Tracer
m
(ReplayStart blk -> ReplayGoal blk -> TraceReplayProgressEvent blk)
replayTracer'' = Point blk
-> Tracer m (ReplayGoal blk -> TraceReplayProgressEvent blk)
-> Tracer
m
(ReplayStart blk -> ReplayGoal blk -> TraceReplayProgressEvent blk)
forall blk (m :: * -> *).
Point blk
-> Tracer m (ReplayGoal blk -> TraceReplayProgressEvent blk)
-> Tracer
m
(ReplayStart blk -> ReplayGoal blk -> TraceReplayProgressEvent blk)
decorateReplayTracerWithStart (WithOrigin (Block SlotNo (HeaderHash blk)) -> Point blk
forall {k} (block :: k).
WithOrigin (Block SlotNo (HeaderHash block)) -> Point block
Point WithOrigin (Block SlotNo (HeaderHash blk))
forall t. WithOrigin t
Origin) Tracer m (ReplayGoal blk -> TraceReplayProgressEvent blk)
replayTracer'
initDb <- m db
initFromGenesis
eDB <- runExceptT $ replayStartingWith
replayTracer''
cfg
stream
initDb
(Point Origin)
dbIface
case eDB of
Left SnapshotFailure blk
err -> do
db -> m ()
closeDb db
initDb
String -> m (InitLog blk, db, Word64)
forall a. HasCallStack => String -> a
error (String -> m (InitLog blk, db, Word64))
-> String -> m (InitLog blk, db, Word64)
forall a b. (a -> b) -> a -> b
$ String
"Invariant violation: invalid immutable chain " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> SnapshotFailure blk -> String
forall a. Show a => a -> String
show SnapshotFailure blk
err
Right (db
db, Word64
replayed) -> do
db' <- InitDB db m blk -> db -> m db
forall db (m :: * -> *) blk. InitDB db m blk -> db -> m db
pruneDb InitDB db m blk
dbIface db
db
return ( acc InitFromGenesis
, db'
, replayed
)
tryNewestFirst InitLog blk -> InitLog blk
acc (DiskSnapshot
s:[DiskSnapshot]
ss) = do
eInitDb <- DiskSnapshot
-> m (Either (SnapshotFailure blk) (db, RealPoint blk))
initFromSnapshot DiskSnapshot
s
case eInitDb of
Left err :: SnapshotFailure blk
err@(InitFailureRead (ReadMetadataError FsPath
_ MetadataErr
MetadataFileDoesNotExist)) -> do
Tracer m (TraceSnapshotEvent blk) -> TraceSnapshotEvent blk -> m ()
forall (m :: * -> *) a. Tracer m a -> a -> m ()
traceWith Tracer m (TraceSnapshotEvent blk)
snapTracer (TraceSnapshotEvent blk -> m ()) -> TraceSnapshotEvent blk -> m ()
forall a b. (a -> b) -> a -> b
$ DiskSnapshot -> SnapshotFailure blk -> TraceSnapshotEvent blk
forall blk.
DiskSnapshot -> SnapshotFailure blk -> TraceSnapshotEvent blk
InvalidSnapshot DiskSnapshot
s SnapshotFailure blk
err
(InitLog blk -> InitLog blk)
-> [DiskSnapshot] -> m (InitLog blk, db, Word64)
tryNewestFirst (InitLog blk -> InitLog blk
acc (InitLog blk -> InitLog blk)
-> (InitLog blk -> InitLog blk) -> InitLog blk -> InitLog blk
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DiskSnapshot -> SnapshotFailure blk -> InitLog blk -> InitLog blk
forall blk.
DiskSnapshot -> SnapshotFailure blk -> InitLog blk -> InitLog blk
InitFailure DiskSnapshot
s SnapshotFailure blk
err) [DiskSnapshot]
ss
Left err :: SnapshotFailure blk
err@(InitFailureRead (ReadMetadataError FsPath
_ MetadataErr
MetadataBackendMismatch)) -> do
Tracer m (TraceSnapshotEvent blk) -> TraceSnapshotEvent blk -> m ()
forall (m :: * -> *) a. Tracer m a -> a -> m ()
traceWith Tracer m (TraceSnapshotEvent blk)
snapTracer (TraceSnapshotEvent blk -> m ()) -> TraceSnapshotEvent blk -> m ()
forall a b. (a -> b) -> a -> b
$ DiskSnapshot -> SnapshotFailure blk -> TraceSnapshotEvent blk
forall blk.
DiskSnapshot -> SnapshotFailure blk -> TraceSnapshotEvent blk
InvalidSnapshot DiskSnapshot
s SnapshotFailure blk
err
(InitLog blk -> InitLog blk)
-> [DiskSnapshot] -> m (InitLog blk, db, Word64)
tryNewestFirst (InitLog blk -> InitLog blk
acc (InitLog blk -> InitLog blk)
-> (InitLog blk -> InitLog blk) -> InitLog blk -> InitLog blk
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DiskSnapshot -> SnapshotFailure blk -> InitLog blk -> InitLog blk
forall blk.
DiskSnapshot -> SnapshotFailure blk -> InitLog blk -> InitLog blk
InitFailure DiskSnapshot
s SnapshotFailure blk
err) [DiskSnapshot]
ss
Left err :: SnapshotFailure blk
err@(InitFailureRead ReadSnapshotErr
ReadSnapshotDataCorruption) -> do
Tracer m (TraceSnapshotEvent blk) -> TraceSnapshotEvent blk -> m ()
forall (m :: * -> *) a. Tracer m a -> a -> m ()
traceWith Tracer m (TraceSnapshotEvent blk)
snapTracer (TraceSnapshotEvent blk -> m ()) -> TraceSnapshotEvent blk -> m ()
forall a b. (a -> b) -> a -> b
$ DiskSnapshot -> SnapshotFailure blk -> TraceSnapshotEvent blk
forall blk.
DiskSnapshot -> SnapshotFailure blk -> TraceSnapshotEvent blk
InvalidSnapshot DiskSnapshot
s SnapshotFailure blk
err
Bool -> m () -> m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
Monad.when (DiskSnapshot -> Bool
diskSnapshotIsTemporary DiskSnapshot
s) (m () -> m ()) -> m () -> m ()
forall a b. (a -> b) -> a -> b
$ do
Tracer m (TraceSnapshotEvent blk) -> TraceSnapshotEvent blk -> m ()
forall (m :: * -> *) a. Tracer m a -> a -> m ()
traceWith Tracer m (TraceSnapshotEvent blk)
snapTracer (TraceSnapshotEvent blk -> m ()) -> TraceSnapshotEvent blk -> m ()
forall a b. (a -> b) -> a -> b
$ DiskSnapshot -> TraceSnapshotEvent blk
forall blk. DiskSnapshot -> TraceSnapshotEvent blk
DeletedSnapshot DiskSnapshot
s
SomeHasFS m -> DiskSnapshot -> m ()
forall (m :: * -> *).
(Monad m, HasCallStack) =>
SomeHasFS m -> DiskSnapshot -> m ()
deleteSnapshot SomeHasFS m
hasFS DiskSnapshot
s
(InitLog blk -> InitLog blk)
-> [DiskSnapshot] -> m (InitLog blk, db, Word64)
tryNewestFirst (InitLog blk -> InitLog blk
acc (InitLog blk -> InitLog blk)
-> (InitLog blk -> InitLog blk) -> InitLog blk -> InitLog blk
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DiskSnapshot -> SnapshotFailure blk -> InitLog blk -> InitLog blk
forall blk.
DiskSnapshot -> SnapshotFailure blk -> InitLog blk -> InitLog blk
InitFailure DiskSnapshot
s SnapshotFailure blk
err) [DiskSnapshot]
ss
Left SnapshotFailure blk
err -> do
Bool -> m () -> m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
Monad.when (DiskSnapshot -> Bool
diskSnapshotIsTemporary DiskSnapshot
s Bool -> Bool -> Bool
|| SnapshotFailure blk
err SnapshotFailure blk -> SnapshotFailure blk -> Bool
forall a. Eq a => a -> a -> Bool
== SnapshotFailure blk
forall blk. SnapshotFailure blk
InitFailureGenesis) (m () -> m ()) -> m () -> m ()
forall a b. (a -> b) -> a -> b
$ do
Tracer m (TraceSnapshotEvent blk) -> TraceSnapshotEvent blk -> m ()
forall (m :: * -> *) a. Tracer m a -> a -> m ()
traceWith Tracer m (TraceSnapshotEvent blk)
snapTracer (TraceSnapshotEvent blk -> m ()) -> TraceSnapshotEvent blk -> m ()
forall a b. (a -> b) -> a -> b
$ DiskSnapshot -> TraceSnapshotEvent blk
forall blk. DiskSnapshot -> TraceSnapshotEvent blk
DeletedSnapshot DiskSnapshot
s
SomeHasFS m -> DiskSnapshot -> m ()
forall (m :: * -> *).
(Monad m, HasCallStack) =>
SomeHasFS m -> DiskSnapshot -> m ()
deleteSnapshot SomeHasFS m
hasFS DiskSnapshot
s
Tracer m (TraceSnapshotEvent blk) -> TraceSnapshotEvent blk -> m ()
forall (m :: * -> *) a. Tracer m a -> a -> m ()
traceWith Tracer m (TraceSnapshotEvent blk)
snapTracer (TraceSnapshotEvent blk -> m ())
-> (SnapshotFailure blk -> TraceSnapshotEvent blk)
-> SnapshotFailure blk
-> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DiskSnapshot -> SnapshotFailure blk -> TraceSnapshotEvent blk
forall blk.
DiskSnapshot -> SnapshotFailure blk -> TraceSnapshotEvent blk
InvalidSnapshot DiskSnapshot
s (SnapshotFailure blk -> m ()) -> SnapshotFailure blk -> m ()
forall a b. (a -> b) -> a -> b
$ SnapshotFailure blk
err
(InitLog blk -> InitLog blk)
-> [DiskSnapshot] -> m (InitLog blk, db, Word64)
tryNewestFirst (InitLog blk -> InitLog blk
acc (InitLog blk -> InitLog blk)
-> (InitLog blk -> InitLog blk) -> InitLog blk -> InitLog blk
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DiskSnapshot -> SnapshotFailure blk -> InitLog blk -> InitLog blk
forall blk.
DiskSnapshot -> SnapshotFailure blk -> InitLog blk -> InitLog blk
InitFailure DiskSnapshot
s SnapshotFailure blk
err) [DiskSnapshot]
ss
Right (db
initDb, RealPoint blk
pt) -> do
let pt' :: Point blk
pt' = RealPoint blk -> Point blk
forall blk. RealPoint blk -> Point blk
realPointToPoint RealPoint blk
pt
Tracer m (TraceReplayStartEvent blk)
-> TraceReplayStartEvent blk -> m ()
forall (m :: * -> *) a. Tracer m a -> a -> m ()
traceWith (TraceReplayStartEvent blk -> TraceReplayEvent blk
forall blk. TraceReplayStartEvent blk -> TraceReplayEvent blk
TraceReplayStartEvent (TraceReplayStartEvent blk -> TraceReplayEvent blk)
-> Tracer m (TraceReplayEvent blk)
-> Tracer m (TraceReplayStartEvent blk)
forall (f :: * -> *) a b. Contravariant f => (a -> b) -> f b -> f a
>$< Tracer m (TraceReplayEvent blk)
replayTracer) (DiskSnapshot -> ReplayStart blk -> TraceReplayStartEvent blk
forall {k} (blk :: k).
DiskSnapshot -> ReplayStart blk -> TraceReplayStartEvent blk
ReplayFromSnapshot DiskSnapshot
s (Point blk -> ReplayStart blk
forall {k} (blk :: k). Point blk -> ReplayStart blk
ReplayStart Point blk
pt'))
let replayTracer'' :: Tracer
m
(ReplayStart blk -> ReplayGoal blk -> TraceReplayProgressEvent blk)
replayTracer'' = Point blk
-> Tracer m (ReplayGoal blk -> TraceReplayProgressEvent blk)
-> Tracer
m
(ReplayStart blk -> ReplayGoal blk -> TraceReplayProgressEvent blk)
forall blk (m :: * -> *).
Point blk
-> Tracer m (ReplayGoal blk -> TraceReplayProgressEvent blk)
-> Tracer
m
(ReplayStart blk -> ReplayGoal blk -> TraceReplayProgressEvent blk)
decorateReplayTracerWithStart Point blk
pt' Tracer m (ReplayGoal blk -> TraceReplayProgressEvent blk)
replayTracer'
eDB <- ExceptT (SnapshotFailure blk) m (db, Word64)
-> m (Either (SnapshotFailure blk) (db, Word64))
forall e (m :: * -> *) a. ExceptT e m a -> m (Either e a)
runExceptT
(ExceptT (SnapshotFailure blk) m (db, Word64)
-> m (Either (SnapshotFailure blk) (db, Word64)))
-> ExceptT (SnapshotFailure blk) m (db, Word64)
-> m (Either (SnapshotFailure blk) (db, Word64))
forall a b. (a -> b) -> a -> b
$ Tracer
m
(ReplayStart blk -> ReplayGoal blk -> TraceReplayProgressEvent blk)
-> LedgerDbCfg (ExtLedgerState blk)
-> StreamAPI m blk blk
-> db
-> Point blk
-> InitDB db m blk
-> ExceptT (SnapshotFailure blk) m (db, Word64)
forall (m :: * -> *) blk db.
(IOLike m, LedgerSupportsProtocol blk, InspectLedger blk,
HasCallStack) =>
Tracer
m
(ReplayStart blk -> ReplayGoal blk -> TraceReplayProgressEvent blk)
-> LedgerDbCfg (ExtLedgerState blk)
-> StreamAPI m blk blk
-> db
-> Point blk
-> InitDB db m blk
-> ExceptT (SnapshotFailure blk) m (db, Word64)
replayStartingWith
Tracer
m
(ReplayStart blk -> ReplayGoal blk -> TraceReplayProgressEvent blk)
replayTracer''
LedgerDbCfg (ExtLedgerState blk)
cfg
StreamAPI m blk blk
stream
db
initDb
Point blk
pt'
InitDB db m blk
dbIface
case eDB of
Left SnapshotFailure blk
err -> do
Tracer m (TraceSnapshotEvent blk) -> TraceSnapshotEvent blk -> m ()
forall (m :: * -> *) a. Tracer m a -> a -> m ()
traceWith Tracer m (TraceSnapshotEvent blk)
snapTracer (TraceSnapshotEvent blk -> m ())
-> (SnapshotFailure blk -> TraceSnapshotEvent blk)
-> SnapshotFailure blk
-> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DiskSnapshot -> SnapshotFailure blk -> TraceSnapshotEvent blk
forall blk.
DiskSnapshot -> SnapshotFailure blk -> TraceSnapshotEvent blk
InvalidSnapshot DiskSnapshot
s (SnapshotFailure blk -> m ()) -> SnapshotFailure blk -> m ()
forall a b. (a -> b) -> a -> b
$ SnapshotFailure blk
err
Bool -> m () -> m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
Monad.when (DiskSnapshot -> Bool
diskSnapshotIsTemporary DiskSnapshot
s) (m () -> m ()) -> m () -> m ()
forall a b. (a -> b) -> a -> b
$ SomeHasFS m -> DiskSnapshot -> m ()
forall (m :: * -> *).
(Monad m, HasCallStack) =>
SomeHasFS m -> DiskSnapshot -> m ()
deleteSnapshot SomeHasFS m
hasFS DiskSnapshot
s
db -> m ()
closeDb db
initDb
(InitLog blk -> InitLog blk)
-> [DiskSnapshot] -> m (InitLog blk, db, Word64)
tryNewestFirst (InitLog blk -> InitLog blk
acc (InitLog blk -> InitLog blk)
-> (InitLog blk -> InitLog blk) -> InitLog blk -> InitLog blk
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DiskSnapshot -> SnapshotFailure blk -> InitLog blk -> InitLog blk
forall blk.
DiskSnapshot -> SnapshotFailure blk -> InitLog blk -> InitLog blk
InitFailure DiskSnapshot
s SnapshotFailure blk
err) [DiskSnapshot]
ss
Right (db
db, Word64
replayed) -> do
db' <- InitDB db m blk -> db -> m db
forall db (m :: * -> *) blk. InitDB db m blk -> db -> m db
pruneDb InitDB db m blk
dbIface db
db
return (acc (InitFromSnapshot s pt), db', replayed)
replayTracer' :: Tracer m (ReplayGoal blk -> TraceReplayProgressEvent blk)
replayTracer' = Point blk
-> Tracer m (TraceReplayProgressEvent blk)
-> Tracer m (ReplayGoal blk -> TraceReplayProgressEvent blk)
forall blk (m :: * -> *).
Point blk
-> Tracer m (TraceReplayProgressEvent blk)
-> Tracer m (ReplayGoal blk -> TraceReplayProgressEvent blk)
decorateReplayTracerWithGoal
Point blk
replayGoal
(TraceReplayProgressEvent blk -> TraceReplayEvent blk
forall blk. TraceReplayProgressEvent blk -> TraceReplayEvent blk
TraceReplayProgressEvent (TraceReplayProgressEvent blk -> TraceReplayEvent blk)
-> Tracer m (TraceReplayEvent blk)
-> Tracer m (TraceReplayProgressEvent blk)
forall (f :: * -> *) a b. Contravariant f => (a -> b) -> f b -> f a
>$< Tracer m (TraceReplayEvent blk)
replayTracer)
replayStartingWith ::
forall m blk db. (
IOLike m
, LedgerSupportsProtocol blk
, InspectLedger blk
, HasCallStack
)
=> Tracer m (ReplayStart blk -> ReplayGoal blk -> TraceReplayProgressEvent blk)
-> LedgerDbCfg (ExtLedgerState blk)
-> StreamAPI m blk blk
-> db
-> Point blk
-> InitDB db m blk
-> ExceptT (SnapshotFailure blk) m (db, Word64)
replayStartingWith :: forall (m :: * -> *) blk db.
(IOLike m, LedgerSupportsProtocol blk, InspectLedger blk,
HasCallStack) =>
Tracer
m
(ReplayStart blk -> ReplayGoal blk -> TraceReplayProgressEvent blk)
-> LedgerDbCfg (ExtLedgerState blk)
-> StreamAPI m blk blk
-> db
-> Point blk
-> InitDB db m blk
-> ExceptT (SnapshotFailure blk) m (db, Word64)
replayStartingWith Tracer
m
(ReplayStart blk -> ReplayGoal blk -> TraceReplayProgressEvent blk)
tracer LedgerDbCfg (ExtLedgerState blk)
cfg StreamAPI m blk blk
stream db
initDb Point blk
from InitDB{LedgerDbCfg (ExtLedgerState blk) -> blk -> db -> m db
initReapplyBlock :: forall db (m :: * -> *) blk.
InitDB db m blk
-> LedgerDbCfg (ExtLedgerState blk) -> blk -> db -> m db
initReapplyBlock :: LedgerDbCfg (ExtLedgerState blk) -> blk -> db -> m db
initReapplyBlock, db -> LedgerState blk EmptyMK
currentTip :: forall db (m :: * -> *) blk.
InitDB db m blk -> db -> LedgerState blk EmptyMK
currentTip :: db -> LedgerState blk EmptyMK
currentTip} = do
StreamAPI m blk blk
-> Point blk
-> (RealPoint blk -> SnapshotFailure blk)
-> (db, Word64)
-> (blk -> (db, Word64) -> m (db, Word64))
-> ExceptT (SnapshotFailure blk) m (db, Word64)
forall (m :: * -> *) blk e b a.
(Monad m, HasCallStack) =>
StreamAPI m blk b
-> Point blk
-> (RealPoint blk -> e)
-> a
-> (b -> a -> m a)
-> ExceptT e m a
streamAll StreamAPI m blk blk
stream Point blk
from
RealPoint blk -> SnapshotFailure blk
forall blk. RealPoint blk -> SnapshotFailure blk
InitFailureTooRecent
(db
initDb, Word64
0)
blk -> (db, Word64) -> m (db, Word64)
push
where
push :: blk
-> (db, Word64)
-> m (db, Word64)
push :: blk -> (db, Word64) -> m (db, Word64)
push blk
blk (!db
db, !Word64
replayed) = do
!db' <- LedgerDbCfg (ExtLedgerState blk) -> blk -> db -> m db
initReapplyBlock LedgerDbCfg (ExtLedgerState blk)
cfg blk
blk db
db
let !replayed' = Word64
replayed Word64 -> Word64 -> Word64
forall a. Num a => a -> a -> a
+ Word64
1
events = TopLevelConfig blk
-> LedgerState blk EmptyMK
-> LedgerState blk EmptyMK
-> [LedgerEvent blk]
forall blk (mk1 :: MapKind) (mk2 :: MapKind).
InspectLedger blk =>
TopLevelConfig blk
-> LedgerState blk mk1 -> LedgerState blk mk2 -> [LedgerEvent blk]
forall (mk1 :: MapKind) (mk2 :: MapKind).
TopLevelConfig blk
-> LedgerState blk mk1 -> LedgerState blk mk2 -> [LedgerEvent blk]
inspectLedger
(ExtLedgerCfg blk -> TopLevelConfig blk
forall blk. ExtLedgerCfg blk -> TopLevelConfig blk
getExtLedgerCfg (LedgerDbCfg (ExtLedgerState blk)
-> HKD Identity (LedgerCfg (ExtLedgerState blk))
forall (f :: * -> *) (l :: LedgerStateKind).
LedgerDbCfgF f l -> HKD f (LedgerCfg l)
ledgerDbCfg LedgerDbCfg (ExtLedgerState blk)
cfg))
(db -> LedgerState blk EmptyMK
currentTip db
db)
(db -> LedgerState blk EmptyMK
currentTip db
db')
traceWith tracer (ReplayedBlock (blockRealPoint blk) events)
return (db', replayed')
data TraceReplayEvent blk =
TraceReplayStartEvent (TraceReplayStartEvent blk)
| TraceReplayProgressEvent (TraceReplayProgressEvent blk)
deriving (Int -> TraceReplayEvent blk -> ShowS
[TraceReplayEvent blk] -> ShowS
TraceReplayEvent blk -> String
(Int -> TraceReplayEvent blk -> ShowS)
-> (TraceReplayEvent blk -> String)
-> ([TraceReplayEvent blk] -> ShowS)
-> Show (TraceReplayEvent blk)
forall blk.
(StandardHash blk, InspectLedger blk) =>
Int -> TraceReplayEvent blk -> ShowS
forall blk.
(StandardHash blk, InspectLedger blk) =>
[TraceReplayEvent blk] -> ShowS
forall blk.
(StandardHash blk, InspectLedger blk) =>
TraceReplayEvent blk -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall blk.
(StandardHash blk, InspectLedger blk) =>
Int -> TraceReplayEvent blk -> ShowS
showsPrec :: Int -> TraceReplayEvent blk -> ShowS
$cshow :: forall blk.
(StandardHash blk, InspectLedger blk) =>
TraceReplayEvent blk -> String
show :: TraceReplayEvent blk -> String
$cshowList :: forall blk.
(StandardHash blk, InspectLedger blk) =>
[TraceReplayEvent blk] -> ShowS
showList :: [TraceReplayEvent blk] -> ShowS
Show, TraceReplayEvent blk -> TraceReplayEvent blk -> Bool
(TraceReplayEvent blk -> TraceReplayEvent blk -> Bool)
-> (TraceReplayEvent blk -> TraceReplayEvent blk -> Bool)
-> Eq (TraceReplayEvent blk)
forall blk.
(StandardHash blk, InspectLedger blk) =>
TraceReplayEvent blk -> TraceReplayEvent blk -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall blk.
(StandardHash blk, InspectLedger blk) =>
TraceReplayEvent blk -> TraceReplayEvent blk -> Bool
== :: TraceReplayEvent blk -> TraceReplayEvent blk -> Bool
$c/= :: forall blk.
(StandardHash blk, InspectLedger blk) =>
TraceReplayEvent blk -> TraceReplayEvent blk -> Bool
/= :: TraceReplayEvent blk -> TraceReplayEvent blk -> Bool
Eq)
decorateReplayTracerWithGoal
:: Point blk
-> Tracer m (TraceReplayProgressEvent blk)
-> Tracer m (ReplayGoal blk -> TraceReplayProgressEvent blk)
decorateReplayTracerWithGoal :: forall blk (m :: * -> *).
Point blk
-> Tracer m (TraceReplayProgressEvent blk)
-> Tracer m (ReplayGoal blk -> TraceReplayProgressEvent blk)
decorateReplayTracerWithGoal Point blk
immTip = (((ReplayGoal blk -> TraceReplayProgressEvent blk)
-> ReplayGoal blk -> TraceReplayProgressEvent blk
forall a b. (a -> b) -> a -> b
$ Point blk -> ReplayGoal blk
forall {k} (blk :: k). Point blk -> ReplayGoal blk
ReplayGoal Point blk
immTip) ((ReplayGoal blk -> TraceReplayProgressEvent blk)
-> TraceReplayProgressEvent blk)
-> Tracer m (TraceReplayProgressEvent blk)
-> Tracer m (ReplayGoal blk -> TraceReplayProgressEvent blk)
forall (f :: * -> *) a b. Contravariant f => (a -> b) -> f b -> f a
>$<)
decorateReplayTracerWithStart
:: Point blk
-> Tracer m (ReplayGoal blk -> TraceReplayProgressEvent blk)
-> Tracer m (ReplayStart blk -> ReplayGoal blk -> TraceReplayProgressEvent blk)
decorateReplayTracerWithStart :: forall blk (m :: * -> *).
Point blk
-> Tracer m (ReplayGoal blk -> TraceReplayProgressEvent blk)
-> Tracer
m
(ReplayStart blk -> ReplayGoal blk -> TraceReplayProgressEvent blk)
decorateReplayTracerWithStart Point blk
start = (((ReplayStart blk -> ReplayGoal blk -> TraceReplayProgressEvent blk)
-> ReplayStart blk
-> ReplayGoal blk
-> TraceReplayProgressEvent blk
forall a b. (a -> b) -> a -> b
$ Point blk -> ReplayStart blk
forall {k} (blk :: k). Point blk -> ReplayStart blk
ReplayStart Point blk
start) ((ReplayStart blk
-> ReplayGoal blk -> TraceReplayProgressEvent blk)
-> ReplayGoal blk -> TraceReplayProgressEvent blk)
-> Tracer m (ReplayGoal blk -> TraceReplayProgressEvent blk)
-> Tracer
m
(ReplayStart blk -> ReplayGoal blk -> TraceReplayProgressEvent blk)
forall (f :: * -> *) a b. Contravariant f => (a -> b) -> f b -> f a
>$<)
newtype ReplayStart blk = ReplayStart (Point blk) deriving (ReplayStart blk -> ReplayStart blk -> Bool
(ReplayStart blk -> ReplayStart blk -> Bool)
-> (ReplayStart blk -> ReplayStart blk -> Bool)
-> Eq (ReplayStart blk)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall k (blk :: k).
StandardHash blk =>
ReplayStart blk -> ReplayStart blk -> Bool
$c== :: forall k (blk :: k).
StandardHash blk =>
ReplayStart blk -> ReplayStart blk -> Bool
== :: ReplayStart blk -> ReplayStart blk -> Bool
$c/= :: forall k (blk :: k).
StandardHash blk =>
ReplayStart blk -> ReplayStart blk -> Bool
/= :: ReplayStart blk -> ReplayStart blk -> Bool
Eq, Int -> ReplayStart blk -> ShowS
[ReplayStart blk] -> ShowS
ReplayStart blk -> String
(Int -> ReplayStart blk -> ShowS)
-> (ReplayStart blk -> String)
-> ([ReplayStart blk] -> ShowS)
-> Show (ReplayStart blk)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k (blk :: k).
StandardHash blk =>
Int -> ReplayStart blk -> ShowS
forall k (blk :: k). StandardHash blk => [ReplayStart blk] -> ShowS
forall k (blk :: k). StandardHash blk => ReplayStart blk -> String
$cshowsPrec :: forall k (blk :: k).
StandardHash blk =>
Int -> ReplayStart blk -> ShowS
showsPrec :: Int -> ReplayStart blk -> ShowS
$cshow :: forall k (blk :: k). StandardHash blk => ReplayStart blk -> String
show :: ReplayStart blk -> String
$cshowList :: forall k (blk :: k). StandardHash blk => [ReplayStart blk] -> ShowS
showList :: [ReplayStart blk] -> ShowS
Show)
newtype ReplayGoal blk = ReplayGoal (Point blk) deriving (ReplayGoal blk -> ReplayGoal blk -> Bool
(ReplayGoal blk -> ReplayGoal blk -> Bool)
-> (ReplayGoal blk -> ReplayGoal blk -> Bool)
-> Eq (ReplayGoal blk)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall k (blk :: k).
StandardHash blk =>
ReplayGoal blk -> ReplayGoal blk -> Bool
$c== :: forall k (blk :: k).
StandardHash blk =>
ReplayGoal blk -> ReplayGoal blk -> Bool
== :: ReplayGoal blk -> ReplayGoal blk -> Bool
$c/= :: forall k (blk :: k).
StandardHash blk =>
ReplayGoal blk -> ReplayGoal blk -> Bool
/= :: ReplayGoal blk -> ReplayGoal blk -> Bool
Eq, Int -> ReplayGoal blk -> ShowS
[ReplayGoal blk] -> ShowS
ReplayGoal blk -> String
(Int -> ReplayGoal blk -> ShowS)
-> (ReplayGoal blk -> String)
-> ([ReplayGoal blk] -> ShowS)
-> Show (ReplayGoal blk)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k (blk :: k).
StandardHash blk =>
Int -> ReplayGoal blk -> ShowS
forall k (blk :: k). StandardHash blk => [ReplayGoal blk] -> ShowS
forall k (blk :: k). StandardHash blk => ReplayGoal blk -> String
$cshowsPrec :: forall k (blk :: k).
StandardHash blk =>
Int -> ReplayGoal blk -> ShowS
showsPrec :: Int -> ReplayGoal blk -> ShowS
$cshow :: forall k (blk :: k). StandardHash blk => ReplayGoal blk -> String
show :: ReplayGoal blk -> String
$cshowList :: forall k (blk :: k). StandardHash blk => [ReplayGoal blk] -> ShowS
showList :: [ReplayGoal blk] -> ShowS
Show)
data TraceReplayStartEvent blk
=
ReplayFromGenesis
| ReplayFromSnapshot
DiskSnapshot
(ReplayStart blk)
deriving ((forall x.
TraceReplayStartEvent blk -> Rep (TraceReplayStartEvent blk) x)
-> (forall x.
Rep (TraceReplayStartEvent blk) x -> TraceReplayStartEvent blk)
-> Generic (TraceReplayStartEvent blk)
forall x.
Rep (TraceReplayStartEvent blk) x -> TraceReplayStartEvent blk
forall x.
TraceReplayStartEvent blk -> Rep (TraceReplayStartEvent blk) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall k (blk :: k) x.
Rep (TraceReplayStartEvent blk) x -> TraceReplayStartEvent blk
forall k (blk :: k) x.
TraceReplayStartEvent blk -> Rep (TraceReplayStartEvent blk) x
$cfrom :: forall k (blk :: k) x.
TraceReplayStartEvent blk -> Rep (TraceReplayStartEvent blk) x
from :: forall x.
TraceReplayStartEvent blk -> Rep (TraceReplayStartEvent blk) x
$cto :: forall k (blk :: k) x.
Rep (TraceReplayStartEvent blk) x -> TraceReplayStartEvent blk
to :: forall x.
Rep (TraceReplayStartEvent blk) x -> TraceReplayStartEvent blk
Generic, TraceReplayStartEvent blk -> TraceReplayStartEvent blk -> Bool
(TraceReplayStartEvent blk -> TraceReplayStartEvent blk -> Bool)
-> (TraceReplayStartEvent blk -> TraceReplayStartEvent blk -> Bool)
-> Eq (TraceReplayStartEvent blk)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall k (blk :: k).
StandardHash blk =>
TraceReplayStartEvent blk -> TraceReplayStartEvent blk -> Bool
$c== :: forall k (blk :: k).
StandardHash blk =>
TraceReplayStartEvent blk -> TraceReplayStartEvent blk -> Bool
== :: TraceReplayStartEvent blk -> TraceReplayStartEvent blk -> Bool
$c/= :: forall k (blk :: k).
StandardHash blk =>
TraceReplayStartEvent blk -> TraceReplayStartEvent blk -> Bool
/= :: TraceReplayStartEvent blk -> TraceReplayStartEvent blk -> Bool
Eq, Int -> TraceReplayStartEvent blk -> ShowS
[TraceReplayStartEvent blk] -> ShowS
TraceReplayStartEvent blk -> String
(Int -> TraceReplayStartEvent blk -> ShowS)
-> (TraceReplayStartEvent blk -> String)
-> ([TraceReplayStartEvent blk] -> ShowS)
-> Show (TraceReplayStartEvent blk)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k (blk :: k).
StandardHash blk =>
Int -> TraceReplayStartEvent blk -> ShowS
forall k (blk :: k).
StandardHash blk =>
[TraceReplayStartEvent blk] -> ShowS
forall k (blk :: k).
StandardHash blk =>
TraceReplayStartEvent blk -> String
$cshowsPrec :: forall k (blk :: k).
StandardHash blk =>
Int -> TraceReplayStartEvent blk -> ShowS
showsPrec :: Int -> TraceReplayStartEvent blk -> ShowS
$cshow :: forall k (blk :: k).
StandardHash blk =>
TraceReplayStartEvent blk -> String
show :: TraceReplayStartEvent blk -> String
$cshowList :: forall k (blk :: k).
StandardHash blk =>
[TraceReplayStartEvent blk] -> ShowS
showList :: [TraceReplayStartEvent blk] -> ShowS
Show)
data TraceReplayProgressEvent blk =
ReplayedBlock
(RealPoint blk)
[LedgerEvent blk]
(ReplayStart blk)
(ReplayGoal blk)
deriving ((forall x.
TraceReplayProgressEvent blk
-> Rep (TraceReplayProgressEvent blk) x)
-> (forall x.
Rep (TraceReplayProgressEvent blk) x
-> TraceReplayProgressEvent blk)
-> Generic (TraceReplayProgressEvent blk)
forall x.
Rep (TraceReplayProgressEvent blk) x
-> TraceReplayProgressEvent blk
forall x.
TraceReplayProgressEvent blk
-> Rep (TraceReplayProgressEvent blk) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall blk x.
Rep (TraceReplayProgressEvent blk) x
-> TraceReplayProgressEvent blk
forall blk x.
TraceReplayProgressEvent blk
-> Rep (TraceReplayProgressEvent blk) x
$cfrom :: forall blk x.
TraceReplayProgressEvent blk
-> Rep (TraceReplayProgressEvent blk) x
from :: forall x.
TraceReplayProgressEvent blk
-> Rep (TraceReplayProgressEvent blk) x
$cto :: forall blk x.
Rep (TraceReplayProgressEvent blk) x
-> TraceReplayProgressEvent blk
to :: forall x.
Rep (TraceReplayProgressEvent blk) x
-> TraceReplayProgressEvent blk
Generic, TraceReplayProgressEvent blk
-> TraceReplayProgressEvent blk -> Bool
(TraceReplayProgressEvent blk
-> TraceReplayProgressEvent blk -> Bool)
-> (TraceReplayProgressEvent blk
-> TraceReplayProgressEvent blk -> Bool)
-> Eq (TraceReplayProgressEvent blk)
forall blk.
(StandardHash blk, InspectLedger blk) =>
TraceReplayProgressEvent blk
-> TraceReplayProgressEvent blk -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall blk.
(StandardHash blk, InspectLedger blk) =>
TraceReplayProgressEvent blk
-> TraceReplayProgressEvent blk -> Bool
== :: TraceReplayProgressEvent blk
-> TraceReplayProgressEvent blk -> Bool
$c/= :: forall blk.
(StandardHash blk, InspectLedger blk) =>
TraceReplayProgressEvent blk
-> TraceReplayProgressEvent blk -> Bool
/= :: TraceReplayProgressEvent blk
-> TraceReplayProgressEvent blk -> Bool
Eq, Int -> TraceReplayProgressEvent blk -> ShowS
[TraceReplayProgressEvent blk] -> ShowS
TraceReplayProgressEvent blk -> String
(Int -> TraceReplayProgressEvent blk -> ShowS)
-> (TraceReplayProgressEvent blk -> String)
-> ([TraceReplayProgressEvent blk] -> ShowS)
-> Show (TraceReplayProgressEvent blk)
forall blk.
(StandardHash blk, InspectLedger blk) =>
Int -> TraceReplayProgressEvent blk -> ShowS
forall blk.
(StandardHash blk, InspectLedger blk) =>
[TraceReplayProgressEvent blk] -> ShowS
forall blk.
(StandardHash blk, InspectLedger blk) =>
TraceReplayProgressEvent blk -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall blk.
(StandardHash blk, InspectLedger blk) =>
Int -> TraceReplayProgressEvent blk -> ShowS
showsPrec :: Int -> TraceReplayProgressEvent blk -> ShowS
$cshow :: forall blk.
(StandardHash blk, InspectLedger blk) =>
TraceReplayProgressEvent blk -> String
show :: TraceReplayProgressEvent blk -> String
$cshowList :: forall blk.
(StandardHash blk, InspectLedger blk) =>
[TraceReplayProgressEvent blk] -> ShowS
showList :: [TraceReplayProgressEvent blk] -> ShowS
Show)
type LedgerSupportsInMemoryLedgerDB blk = (CanUpgradeLedgerTables (LedgerState blk))
class CanUpgradeLedgerTables l where
upgradeTables ::
l mk1
-> l mk2
-> LedgerTables l ValuesMK
-> LedgerTables l ValuesMK
instance CanUpgradeLedgerTables (LedgerState blk)
=> CanUpgradeLedgerTables (ExtLedgerState blk) where
upgradeTables :: forall (mk1 :: MapKind) (mk2 :: MapKind).
ExtLedgerState blk mk1
-> ExtLedgerState blk mk2
-> LedgerTables (ExtLedgerState blk) ValuesMK
-> LedgerTables (ExtLedgerState blk) ValuesMK
upgradeTables (ExtLedgerState LedgerState blk mk1
st0 HeaderState blk
_) (ExtLedgerState LedgerState blk mk2
st1 HeaderState blk
_) =
LedgerTables (LedgerState blk) ValuesMK
-> LedgerTables (ExtLedgerState blk) ValuesMK
forall (l :: LedgerStateKind) (l' :: LedgerStateKind)
(mk :: MapKind).
SameUtxoTypes l l' =>
LedgerTables l mk -> LedgerTables l' mk
castLedgerTables (LedgerTables (LedgerState blk) ValuesMK
-> LedgerTables (ExtLedgerState blk) ValuesMK)
-> (LedgerTables (ExtLedgerState blk) ValuesMK
-> LedgerTables (LedgerState blk) ValuesMK)
-> LedgerTables (ExtLedgerState blk) ValuesMK
-> LedgerTables (ExtLedgerState blk) ValuesMK
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LedgerState blk mk1
-> LedgerState blk mk2
-> LedgerTables (LedgerState blk) ValuesMK
-> LedgerTables (LedgerState blk) ValuesMK
forall (mk1 :: MapKind) (mk2 :: MapKind).
LedgerState blk mk1
-> LedgerState blk mk2
-> LedgerTables (LedgerState blk) ValuesMK
-> LedgerTables (LedgerState blk) ValuesMK
forall (l :: LedgerStateKind) (mk1 :: MapKind) (mk2 :: MapKind).
CanUpgradeLedgerTables l =>
l mk1
-> l mk2 -> LedgerTables l ValuesMK -> LedgerTables l ValuesMK
upgradeTables LedgerState blk mk1
st0 LedgerState blk mk2
st1 (LedgerTables (LedgerState blk) ValuesMK
-> LedgerTables (LedgerState blk) ValuesMK)
-> (LedgerTables (ExtLedgerState blk) ValuesMK
-> LedgerTables (LedgerState blk) ValuesMK)
-> LedgerTables (ExtLedgerState blk) ValuesMK
-> LedgerTables (LedgerState blk) ValuesMK
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LedgerTables (ExtLedgerState blk) ValuesMK
-> LedgerTables (LedgerState blk) ValuesMK
forall (l :: LedgerStateKind) (l' :: LedgerStateKind)
(mk :: MapKind).
SameUtxoTypes l l' =>
LedgerTables l mk -> LedgerTables l' mk
castLedgerTables
instance LedgerTablesAreTrivial l
=> CanUpgradeLedgerTables (TrivialLedgerTables l) where
upgradeTables :: forall (mk1 :: MapKind) (mk2 :: MapKind).
TrivialLedgerTables l mk1
-> TrivialLedgerTables l mk2
-> LedgerTables (TrivialLedgerTables l) ValuesMK
-> LedgerTables (TrivialLedgerTables l) ValuesMK
upgradeTables TrivialLedgerTables l mk1
_ TrivialLedgerTables l mk2
_ (LedgerTables (ValuesMK Map (TxIn (TrivialLedgerTables l)) (TxOut (TrivialLedgerTables l))
mk)) =
ValuesMK
(TxIn (TrivialLedgerTables l)) (TxOut (TrivialLedgerTables l))
-> LedgerTables (TrivialLedgerTables l) ValuesMK
forall (l :: LedgerStateKind) (mk :: MapKind).
mk (TxIn l) (TxOut l) -> LedgerTables l mk
LedgerTables (Map Void Void -> ValuesMK Void Void
forall k v. Map k v -> ValuesMK k v
ValuesMK ((Void -> Void) -> Map Void Void -> Map Void Void
forall a b k. (a -> b) -> Map k a -> Map k b
Map.map Void -> Void
forall a. Void -> a
absurd Map Void Void
Map (TxIn (TrivialLedgerTables l)) (TxOut (TrivialLedgerTables l))
mk))
type LedgerSupportsOnDiskLedgerDB blk =
( IndexedMemPack (LedgerState blk EmptyMK) (TxOut (LedgerState blk))
)
type LedgerSupportsLedgerDB blk =
( LedgerSupportsOnDiskLedgerDB blk
, LedgerSupportsInMemoryLedgerDB blk
)
data LedgerDbPrune = LedgerDbPruneAll | LedgerDbPruneKeeping SecurityParam
deriving Int -> LedgerDbPrune -> ShowS
[LedgerDbPrune] -> ShowS
LedgerDbPrune -> String
(Int -> LedgerDbPrune -> ShowS)
-> (LedgerDbPrune -> String)
-> ([LedgerDbPrune] -> ShowS)
-> Show LedgerDbPrune
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> LedgerDbPrune -> ShowS
showsPrec :: Int -> LedgerDbPrune -> ShowS
$cshow :: LedgerDbPrune -> String
show :: LedgerDbPrune -> String
$cshowList :: [LedgerDbPrune] -> ShowS
showList :: [LedgerDbPrune] -> ShowS
Show