{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE RankNTypes                #-}
{-# LANGUAGE RecordWildCards           #-}
{-# LANGUAGE ScopedTypeVariables       #-}
{-# LANGUAGE TypeApplications          #-}

module Ouroboros.Consensus.Storage.ChainDB.Impl.Args (
    ChainDbArgs (..)
  , ChainDbSpecificArgs (..)
  , RelativeMountPoint (..)
  , defaultArgs
    -- * Internal
  , fromChainDbArgs
  ) where

import           Data.Time.Clock (DiffTime, secondsToDiffTime)

import           Control.Tracer (Tracer, contramap, nullTracer)

import           Ouroboros.Consensus.Block
import           Ouroboros.Consensus.Config
import           Ouroboros.Consensus.Fragment.InFuture (CheckInFuture)
import           Ouroboros.Consensus.Ledger.Extended
import           Ouroboros.Consensus.Util.Args
import           Ouroboros.Consensus.Util.ResourceRegistry (ResourceRegistry)

import           Ouroboros.Consensus.Storage.FS.API

import           Ouroboros.Consensus.Storage.ChainDB.Impl.LgrDB (LedgerDB')
import qualified Ouroboros.Consensus.Storage.ChainDB.Impl.LgrDB as LgrDB
import           Ouroboros.Consensus.Storage.ChainDB.Impl.Types
                     (TraceEvent (..))
import           Ouroboros.Consensus.Storage.ImmutableDB (ChunkInfo)
import qualified Ouroboros.Consensus.Storage.ImmutableDB as ImmutableDB
import           Ouroboros.Consensus.Storage.LedgerDB.DiskPolicy
                     (DiskPolicy (..))
import qualified Ouroboros.Consensus.Storage.VolatileDB as VolatileDB

{-------------------------------------------------------------------------------
  Arguments
-------------------------------------------------------------------------------}

data ChainDbArgs f m blk = ChainDbArgs {

      -- HasFS instances
      ChainDbArgs f m blk -> SomeHasFS m
cdbHasFSImmutableDB       :: SomeHasFS m
    , ChainDbArgs f m blk -> SomeHasFS m
cdbHasFSVolatileDB        :: SomeHasFS m
    , ChainDbArgs f m blk -> SomeHasFS m
cdbHasFSLgrDB             :: SomeHasFS m

      -- Policy
    , ChainDbArgs f m blk -> ValidationPolicy
cdbImmutableDbValidation  :: ImmutableDB.ValidationPolicy
    , ChainDbArgs f m blk -> BlockValidationPolicy
cdbVolatileDbValidation   :: VolatileDB.BlockValidationPolicy
    , ChainDbArgs f m blk -> BlocksPerFile
cdbMaxBlocksPerFile       :: VolatileDB.BlocksPerFile
    , ChainDbArgs f m blk -> DiskPolicy
cdbDiskPolicy             :: LgrDB.DiskPolicy

      -- Integration
    , ChainDbArgs f m blk -> HKD f (TopLevelConfig blk)
cdbTopLevelConfig         :: HKD f (TopLevelConfig blk)
    , ChainDbArgs f m blk -> HKD f ChunkInfo
cdbChunkInfo              :: HKD f ChunkInfo
    , ChainDbArgs f m blk -> HKD f (blk -> Bool)
cdbCheckIntegrity         :: HKD f (blk -> Bool)
    , ChainDbArgs f m blk -> HKD f (m (ExtLedgerState blk))
cdbGenesis                :: HKD f (m (ExtLedgerState blk))
    , ChainDbArgs f m blk -> HKD f (CheckInFuture m blk)
cdbCheckInFuture          :: HKD f (CheckInFuture m blk)
    , ChainDbArgs f m blk -> CacheConfig
cdbImmutableDbCacheConfig :: ImmutableDB.CacheConfig

      -- Misc
    , ChainDbArgs f m blk -> Tracer m (TraceEvent blk)
cdbTracer                 :: Tracer m (TraceEvent blk)
    , ChainDbArgs f m blk -> Tracer m (LedgerDB' blk)
cdbTraceLedger            :: Tracer m (LedgerDB' blk)
    , ChainDbArgs f m blk -> HKD f (ResourceRegistry m)
cdbRegistry               :: HKD f (ResourceRegistry m)
    , ChainDbArgs f m blk -> DiffTime
cdbGcDelay                :: DiffTime
    , ChainDbArgs f m blk -> DiffTime
cdbGcInterval             :: DiffTime
    , ChainDbArgs f m blk -> Word
cdbBlocksToAddSize        :: Word
      -- ^ Size of the queue used to store asynchronously added blocks. This
      -- is the maximum number of blocks that could be kept in memory at the
      -- same time when the background thread processing the blocks can't keep
      -- up.
    }

-- | Arguments specific to the ChainDB, not to the ImmutableDB, VolatileDB, or
-- LedgerDB.
data ChainDbSpecificArgs f m blk = ChainDbSpecificArgs {
      ChainDbSpecificArgs f m blk -> Word
cdbsBlocksToAddSize :: Word
    , ChainDbSpecificArgs f m blk -> HKD f (CheckInFuture m blk)
cdbsCheckInFuture   :: HKD f (CheckInFuture m blk)
    , ChainDbSpecificArgs f m blk -> DiffTime
cdbsGcDelay         :: DiffTime
      -- ^ Delay between copying a block to the ImmutableDB and triggering a
      -- garbage collection for the corresponding slot on the VolatileDB.
      --
      -- The goal of the delay is to ensure that the write to the ImmutableDB
      -- has been flushed to disk before deleting the block from the
      -- VolatileDB, so that a crash won't result in the loss of the block.
    , ChainDbSpecificArgs f m blk -> DiffTime
cdbsGcInterval      :: DiffTime
      -- ^ Batch all scheduled GCs so that at most one GC happens every
      -- 'cdbsGcInterval'.
    , ChainDbSpecificArgs f m blk -> HKD f (ResourceRegistry m)
cdbsRegistry        :: HKD f (ResourceRegistry m)
    , ChainDbSpecificArgs f m blk -> Tracer m (TraceEvent blk)
cdbsTracer          :: Tracer m (TraceEvent blk)
    }

-- | Default arguments
--
-- The following fields must still be defined:
--
-- * 'cdbsTracer'
-- * 'cdbsRegistry'
-- * 'cdbsCheckInFuture'
--
-- We a 'cdbsGcDelay' of 60 seconds and a 'cdbsGcInterval' of 10 seconds, this
-- means (see the properties in "Test.Ouroboros.Storage.ChainDB.GcSchedule"):
--
-- * The length of the 'GcSchedule' queue is @<= ⌈gcDelay / gcInterval⌉ + 1@,
--   i.e., @<= 7@.
-- * The overlap (number of blocks in both the VolatileDB and the ImmutableDB)
--   is the number of blocks synced in @gcDelay + gcInterval@ = 70s. E.g, when
--   bulk syncing at 1k-2k blocks/s, this means 70k-140k blocks. During normal
--   operation, we receive 1 block/20s (for Byron /and/ for Shelley), meaning
--   at most 4 blocks.
-- * The unnecessary overlap (the blocks that we haven't GC'ed yet but could
--   have, because of batching) < the number of blocks sync in @gcInterval@.
--   E.g., when syncing at 1k-2k blocks/s, this means 10k-20k blocks. During
--   normal operation, we receive 1 block/20s, meaning at most 1 block.
defaultSpecificArgs :: Monad m => ChainDbSpecificArgs Defaults m blk
defaultSpecificArgs :: ChainDbSpecificArgs Defaults m blk
defaultSpecificArgs = ChainDbSpecificArgs :: forall (f :: * -> *) (m :: * -> *) blk.
Word
-> HKD f (CheckInFuture m blk)
-> DiffTime
-> DiffTime
-> HKD f (ResourceRegistry m)
-> Tracer m (TraceEvent blk)
-> ChainDbSpecificArgs f m blk
ChainDbSpecificArgs {
      cdbsBlocksToAddSize :: Word
cdbsBlocksToAddSize = Word
10
    , cdbsCheckInFuture :: HKD Defaults (CheckInFuture m blk)
cdbsCheckInFuture   = HKD Defaults (CheckInFuture m blk)
forall t. Defaults t
NoDefault
    , cdbsGcDelay :: DiffTime
cdbsGcDelay         = Integer -> DiffTime
secondsToDiffTime Integer
60
    , cdbsGcInterval :: DiffTime
cdbsGcInterval      = Integer -> DiffTime
secondsToDiffTime Integer
10
    , cdbsRegistry :: HKD Defaults (ResourceRegistry m)
cdbsRegistry        = HKD Defaults (ResourceRegistry m)
forall t. Defaults t
NoDefault
    , cdbsTracer :: Tracer m (TraceEvent blk)
cdbsTracer          = Tracer m (TraceEvent blk)
forall (m :: * -> *) a. Applicative m => Tracer m a
nullTracer
    }

-- | Default arguments
--
-- See 'ImmutableDB.defaultArgs', 'VolatileDB.defaultArgs', 'LgrDB.defaultArgs',
-- and 'defaultSpecificArgs' for a list of which fields are not given a default
-- and must therefore be set explicitly.
defaultArgs ::
     forall m blk.
     Monad m
  => (RelativeMountPoint -> SomeHasFS m)
  -> DiskPolicy
  -> ChainDbArgs Defaults m blk
defaultArgs :: (RelativeMountPoint -> SomeHasFS m)
-> DiskPolicy -> ChainDbArgs Defaults m blk
defaultArgs RelativeMountPoint -> SomeHasFS m
mkFS DiskPolicy
diskPolicy =
  ImmutableDbArgs Defaults m blk
-> VolatileDbArgs Defaults m blk
-> LgrDbArgs Defaults m blk
-> ChainDbSpecificArgs Defaults m blk
-> ChainDbArgs Defaults m blk
forall (f :: * -> *) (m :: * -> *) blk.
ImmutableDbArgs f m blk
-> VolatileDbArgs f m blk
-> LgrDbArgs f m blk
-> ChainDbSpecificArgs f m blk
-> ChainDbArgs f m blk
toChainDbArgs (SomeHasFS m -> ImmutableDbArgs Defaults m blk
forall (m :: * -> *) blk.
Applicative m =>
SomeHasFS m -> ImmutableDbArgs Defaults m blk
ImmutableDB.defaultArgs SomeHasFS m
immFS)
                (SomeHasFS m -> VolatileDbArgs Defaults m blk
forall (m :: * -> *) blk.
Applicative m =>
SomeHasFS m -> VolatileDbArgs Defaults m blk
VolatileDB.defaultArgs  SomeHasFS m
volFS)
                (SomeHasFS m -> DiskPolicy -> LgrDbArgs Defaults m blk
forall (m :: * -> *) blk.
Applicative m =>
SomeHasFS m -> DiskPolicy -> LgrDbArgs Defaults m blk
LgrDB.defaultArgs       SomeHasFS m
lgrFS DiskPolicy
diskPolicy)
                ChainDbSpecificArgs Defaults m blk
forall (m :: * -> *) blk.
Monad m =>
ChainDbSpecificArgs Defaults m blk
defaultSpecificArgs
  where
    immFS, volFS, lgrFS :: SomeHasFS m

    immFS :: SomeHasFS m
immFS = RelativeMountPoint -> SomeHasFS m
mkFS (RelativeMountPoint -> SomeHasFS m)
-> RelativeMountPoint -> SomeHasFS m
forall a b. (a -> b) -> a -> b
$ FilePath -> RelativeMountPoint
RelativeMountPoint FilePath
"immutable"
    volFS :: SomeHasFS m
volFS = RelativeMountPoint -> SomeHasFS m
mkFS (RelativeMountPoint -> SomeHasFS m)
-> RelativeMountPoint -> SomeHasFS m
forall a b. (a -> b) -> a -> b
$ FilePath -> RelativeMountPoint
RelativeMountPoint FilePath
"volatile"
    lgrFS :: SomeHasFS m
lgrFS = RelativeMountPoint -> SomeHasFS m
mkFS (RelativeMountPoint -> SomeHasFS m)
-> RelativeMountPoint -> SomeHasFS m
forall a b. (a -> b) -> a -> b
$ FilePath -> RelativeMountPoint
RelativeMountPoint FilePath
"ledger"

-- | Internal: split 'ChainDbArgs' into 'ImmutableDbArgs', 'VolatileDbArgs,
-- 'LgrDbArgs', and 'ChainDbSpecificArgs'.
fromChainDbArgs ::
     forall m blk f. MapHKD f
  => ChainDbArgs f m blk
  -> ( ImmutableDB.ImmutableDbArgs f m blk
     , VolatileDB.VolatileDbArgs   f m blk
     , LgrDB.LgrDbArgs             f m blk
     , ChainDbSpecificArgs         f m blk
     )
fromChainDbArgs :: ChainDbArgs f m blk
-> (ImmutableDbArgs f m blk, VolatileDbArgs f m blk,
    LgrDbArgs f m blk, ChainDbSpecificArgs f m blk)
fromChainDbArgs ChainDbArgs{Word
Tracer m (LedgerDB' blk)
Tracer m (TraceEvent blk)
DiffTime
DiskPolicy
HKD f (m (ExtLedgerState blk))
HKD f (TopLevelConfig blk)
HKD f ChunkInfo
HKD f (ResourceRegistry m)
HKD f (CheckInFuture m blk)
HKD f (blk -> Bool)
SomeHasFS m
BlockValidationPolicy
BlocksPerFile
ValidationPolicy
CacheConfig
cdbBlocksToAddSize :: Word
cdbGcInterval :: DiffTime
cdbGcDelay :: DiffTime
cdbRegistry :: HKD f (ResourceRegistry m)
cdbTraceLedger :: Tracer m (LedgerDB' blk)
cdbTracer :: Tracer m (TraceEvent blk)
cdbImmutableDbCacheConfig :: CacheConfig
cdbCheckInFuture :: HKD f (CheckInFuture m blk)
cdbGenesis :: HKD f (m (ExtLedgerState blk))
cdbCheckIntegrity :: HKD f (blk -> Bool)
cdbChunkInfo :: HKD f ChunkInfo
cdbTopLevelConfig :: HKD f (TopLevelConfig blk)
cdbDiskPolicy :: DiskPolicy
cdbMaxBlocksPerFile :: BlocksPerFile
cdbVolatileDbValidation :: BlockValidationPolicy
cdbImmutableDbValidation :: ValidationPolicy
cdbHasFSLgrDB :: SomeHasFS m
cdbHasFSVolatileDB :: SomeHasFS m
cdbHasFSImmutableDB :: SomeHasFS m
cdbBlocksToAddSize :: forall (f :: * -> *) (m :: * -> *) blk. ChainDbArgs f m blk -> Word
cdbGcInterval :: forall (f :: * -> *) (m :: * -> *) blk.
ChainDbArgs f m blk -> DiffTime
cdbGcDelay :: forall (f :: * -> *) (m :: * -> *) blk.
ChainDbArgs f m blk -> DiffTime
cdbRegistry :: forall (f :: * -> *) (m :: * -> *) blk.
ChainDbArgs f m blk -> HKD f (ResourceRegistry m)
cdbTraceLedger :: forall (f :: * -> *) (m :: * -> *) blk.
ChainDbArgs f m blk -> Tracer m (LedgerDB' blk)
cdbTracer :: forall (f :: * -> *) (m :: * -> *) blk.
ChainDbArgs f m blk -> Tracer m (TraceEvent blk)
cdbImmutableDbCacheConfig :: forall (f :: * -> *) (m :: * -> *) blk.
ChainDbArgs f m blk -> CacheConfig
cdbCheckInFuture :: forall (f :: * -> *) (m :: * -> *) blk.
ChainDbArgs f m blk -> HKD f (CheckInFuture m blk)
cdbGenesis :: forall (f :: * -> *) (m :: * -> *) blk.
ChainDbArgs f m blk -> HKD f (m (ExtLedgerState blk))
cdbCheckIntegrity :: forall (f :: * -> *) (m :: * -> *) blk.
ChainDbArgs f m blk -> HKD f (blk -> Bool)
cdbChunkInfo :: forall (f :: * -> *) (m :: * -> *) blk.
ChainDbArgs f m blk -> HKD f ChunkInfo
cdbTopLevelConfig :: forall (f :: * -> *) (m :: * -> *) blk.
ChainDbArgs f m blk -> HKD f (TopLevelConfig blk)
cdbDiskPolicy :: forall (f :: * -> *) (m :: * -> *) blk.
ChainDbArgs f m blk -> DiskPolicy
cdbMaxBlocksPerFile :: forall (f :: * -> *) (m :: * -> *) blk.
ChainDbArgs f m blk -> BlocksPerFile
cdbVolatileDbValidation :: forall (f :: * -> *) (m :: * -> *) blk.
ChainDbArgs f m blk -> BlockValidationPolicy
cdbImmutableDbValidation :: forall (f :: * -> *) (m :: * -> *) blk.
ChainDbArgs f m blk -> ValidationPolicy
cdbHasFSLgrDB :: forall (f :: * -> *) (m :: * -> *) blk.
ChainDbArgs f m blk -> SomeHasFS m
cdbHasFSVolatileDB :: forall (f :: * -> *) (m :: * -> *) blk.
ChainDbArgs f m blk -> SomeHasFS m
cdbHasFSImmutableDB :: forall (f :: * -> *) (m :: * -> *) blk.
ChainDbArgs f m blk -> SomeHasFS m
..} = (
      ImmutableDbArgs :: forall (f :: * -> *) (m :: * -> *) blk.
CacheConfig
-> HKD f (blk -> Bool)
-> HKD f ChunkInfo
-> HKD f (CodecConfig blk)
-> SomeHasFS m
-> HKD f (ResourceRegistry m)
-> Tracer m (TraceEvent blk)
-> ValidationPolicy
-> ImmutableDbArgs f m blk
ImmutableDB.ImmutableDbArgs {
          immCacheConfig :: CacheConfig
immCacheConfig      = CacheConfig
cdbImmutableDbCacheConfig
        , immCheckIntegrity :: HKD f (blk -> Bool)
immCheckIntegrity   = HKD f (blk -> Bool)
cdbCheckIntegrity
        , immChunkInfo :: HKD f ChunkInfo
immChunkInfo        = HKD f ChunkInfo
cdbChunkInfo
        , immCodecConfig :: HKD f (CodecConfig blk)
immCodecConfig      = Proxy (f (CodecConfig blk))
-> (TopLevelConfig blk -> CodecConfig blk)
-> HKD f (TopLevelConfig blk)
-> HKD f (CodecConfig blk)
forall (f :: * -> *) (proxy :: * -> *) b a.
MapHKD f =>
proxy (f b) -> (a -> b) -> HKD f a -> HKD f b
mapHKD (Proxy (f (CodecConfig blk))
forall k (t :: k). Proxy t
Proxy @(f (CodecConfig blk))) TopLevelConfig blk -> CodecConfig blk
forall blk. TopLevelConfig blk -> CodecConfig blk
configCodec HKD f (TopLevelConfig blk)
cdbTopLevelConfig
        , immHasFS :: SomeHasFS m
immHasFS            = SomeHasFS m
cdbHasFSImmutableDB
        , immRegistry :: HKD f (ResourceRegistry m)
immRegistry         = HKD f (ResourceRegistry m)
cdbRegistry
        , immTracer :: Tracer m (TraceEvent blk)
immTracer           = (TraceEvent blk -> TraceEvent blk)
-> Tracer m (TraceEvent blk) -> Tracer m (TraceEvent blk)
forall (f :: * -> *) a b. Contravariant f => (a -> b) -> f b -> f a
contramap TraceEvent blk -> TraceEvent blk
forall blk. TraceEvent blk -> TraceEvent blk
TraceImmutableDBEvent Tracer m (TraceEvent blk)
cdbTracer
        , immValidationPolicy :: ValidationPolicy
immValidationPolicy = ValidationPolicy
cdbImmutableDbValidation
        }
    , VolatileDbArgs :: forall (f :: * -> *) (m :: * -> *) blk.
HKD f (blk -> Bool)
-> HKD f (CodecConfig blk)
-> SomeHasFS m
-> BlocksPerFile
-> Tracer m (TraceEvent blk)
-> BlockValidationPolicy
-> VolatileDbArgs f m blk
VolatileDB.VolatileDbArgs {
          volCheckIntegrity :: HKD f (blk -> Bool)
volCheckIntegrity   = HKD f (blk -> Bool)
cdbCheckIntegrity
        , volCodecConfig :: HKD f (CodecConfig blk)
volCodecConfig      = Proxy (f (CodecConfig blk))
-> (TopLevelConfig blk -> CodecConfig blk)
-> HKD f (TopLevelConfig blk)
-> HKD f (CodecConfig blk)
forall (f :: * -> *) (proxy :: * -> *) b a.
MapHKD f =>
proxy (f b) -> (a -> b) -> HKD f a -> HKD f b
mapHKD (Proxy (f (CodecConfig blk))
forall k (t :: k). Proxy t
Proxy @(f (CodecConfig blk))) TopLevelConfig blk -> CodecConfig blk
forall blk. TopLevelConfig blk -> CodecConfig blk
configCodec HKD f (TopLevelConfig blk)
cdbTopLevelConfig
        , volHasFS :: SomeHasFS m
volHasFS            = SomeHasFS m
cdbHasFSVolatileDB
        , volMaxBlocksPerFile :: BlocksPerFile
volMaxBlocksPerFile = BlocksPerFile
cdbMaxBlocksPerFile
        , volValidationPolicy :: BlockValidationPolicy
volValidationPolicy = BlockValidationPolicy
cdbVolatileDbValidation
        , volTracer :: Tracer m (TraceEvent blk)
volTracer           = (TraceEvent blk -> TraceEvent blk)
-> Tracer m (TraceEvent blk) -> Tracer m (TraceEvent blk)
forall (f :: * -> *) a b. Contravariant f => (a -> b) -> f b -> f a
contramap TraceEvent blk -> TraceEvent blk
forall blk. TraceEvent blk -> TraceEvent blk
TraceVolatileDBEvent Tracer m (TraceEvent blk)
cdbTracer
        }
    , LgrDbArgs :: forall (f :: * -> *) (m :: * -> *) blk.
DiskPolicy
-> HKD f (m (ExtLedgerState blk))
-> SomeHasFS m
-> HKD f (TopLevelConfig blk)
-> Tracer m (LedgerDB' blk)
-> Tracer m (TraceEvent blk)
-> LgrDbArgs f m blk
LgrDB.LgrDbArgs {
          lgrTopLevelConfig :: HKD f (TopLevelConfig blk)
lgrTopLevelConfig   = HKD f (TopLevelConfig blk)
cdbTopLevelConfig
        , lgrHasFS :: SomeHasFS m
lgrHasFS            = SomeHasFS m
cdbHasFSLgrDB
        , lgrDiskPolicy :: DiskPolicy
lgrDiskPolicy       = DiskPolicy
cdbDiskPolicy
        , lgrGenesis :: HKD f (m (ExtLedgerState blk))
lgrGenesis          = HKD f (m (ExtLedgerState blk))
cdbGenesis
        , lgrTracer :: Tracer m (TraceEvent blk)
lgrTracer           = (TraceEvent blk -> TraceEvent blk)
-> Tracer m (TraceEvent blk) -> Tracer m (TraceEvent blk)
forall (f :: * -> *) a b. Contravariant f => (a -> b) -> f b -> f a
contramap TraceEvent blk -> TraceEvent blk
forall blk. TraceEvent blk -> TraceEvent blk
TraceLedgerEvent Tracer m (TraceEvent blk)
cdbTracer
        , lgrTraceLedger :: Tracer m (LedgerDB' blk)
lgrTraceLedger      = Tracer m (LedgerDB' blk)
cdbTraceLedger
        }
    , ChainDbSpecificArgs :: forall (f :: * -> *) (m :: * -> *) blk.
Word
-> HKD f (CheckInFuture m blk)
-> DiffTime
-> DiffTime
-> HKD f (ResourceRegistry m)
-> Tracer m (TraceEvent blk)
-> ChainDbSpecificArgs f m blk
ChainDbSpecificArgs {
          cdbsTracer :: Tracer m (TraceEvent blk)
cdbsTracer          = Tracer m (TraceEvent blk)
cdbTracer
        , cdbsRegistry :: HKD f (ResourceRegistry m)
cdbsRegistry        = HKD f (ResourceRegistry m)
cdbRegistry
        , cdbsGcDelay :: DiffTime
cdbsGcDelay         = DiffTime
cdbGcDelay
        , cdbsGcInterval :: DiffTime
cdbsGcInterval      = DiffTime
cdbGcInterval
        , cdbsCheckInFuture :: HKD f (CheckInFuture m blk)
cdbsCheckInFuture   = HKD f (CheckInFuture m blk)
cdbCheckInFuture
        , cdbsBlocksToAddSize :: Word
cdbsBlocksToAddSize = Word
cdbBlocksToAddSize
        }
    )

-- | Internal: construct 'ChainDbArgs' from 'ImmutableDbArgs', 'VolatileDbArgs,
-- 'LgrDbArgs', and 'ChainDbSpecificArgs'.
--
-- Useful in 'defaultArgs'
toChainDbArgs ::
     ImmutableDB.ImmutableDbArgs f m blk
  -> VolatileDB.VolatileDbArgs   f m blk
  -> LgrDB.LgrDbArgs             f m blk
  -> ChainDbSpecificArgs         f m blk
  -> ChainDbArgs                 f m blk
toChainDbArgs :: ImmutableDbArgs f m blk
-> VolatileDbArgs f m blk
-> LgrDbArgs f m blk
-> ChainDbSpecificArgs f m blk
-> ChainDbArgs f m blk
toChainDbArgs ImmutableDB.ImmutableDbArgs {Tracer m (TraceEvent blk)
HKD f (CodecConfig blk)
HKD f ChunkInfo
HKD f (ResourceRegistry m)
HKD f (blk -> Bool)
SomeHasFS m
ValidationPolicy
CacheConfig
immValidationPolicy :: ValidationPolicy
immTracer :: Tracer m (TraceEvent blk)
immRegistry :: HKD f (ResourceRegistry m)
immHasFS :: SomeHasFS m
immCodecConfig :: HKD f (CodecConfig blk)
immChunkInfo :: HKD f ChunkInfo
immCheckIntegrity :: HKD f (blk -> Bool)
immCacheConfig :: CacheConfig
immValidationPolicy :: forall (f :: * -> *) (m :: * -> *) blk.
ImmutableDbArgs f m blk -> ValidationPolicy
immTracer :: forall (f :: * -> *) (m :: * -> *) blk.
ImmutableDbArgs f m blk -> Tracer m (TraceEvent blk)
immRegistry :: forall (f :: * -> *) (m :: * -> *) blk.
ImmutableDbArgs f m blk -> HKD f (ResourceRegistry m)
immHasFS :: forall (f :: * -> *) (m :: * -> *) blk.
ImmutableDbArgs f m blk -> SomeHasFS m
immCodecConfig :: forall (f :: * -> *) (m :: * -> *) blk.
ImmutableDbArgs f m blk -> HKD f (CodecConfig blk)
immChunkInfo :: forall (f :: * -> *) (m :: * -> *) blk.
ImmutableDbArgs f m blk -> HKD f ChunkInfo
immCheckIntegrity :: forall (f :: * -> *) (m :: * -> *) blk.
ImmutableDbArgs f m blk -> HKD f (blk -> Bool)
immCacheConfig :: forall (f :: * -> *) (m :: * -> *) blk.
ImmutableDbArgs f m blk -> CacheConfig
..}
              VolatileDB.VolatileDbArgs {Tracer m (TraceEvent blk)
HKD f (CodecConfig blk)
HKD f (blk -> Bool)
SomeHasFS m
BlockValidationPolicy
BlocksPerFile
volValidationPolicy :: BlockValidationPolicy
volTracer :: Tracer m (TraceEvent blk)
volMaxBlocksPerFile :: BlocksPerFile
volHasFS :: SomeHasFS m
volCodecConfig :: HKD f (CodecConfig blk)
volCheckIntegrity :: HKD f (blk -> Bool)
volTracer :: forall (f :: * -> *) (m :: * -> *) blk.
VolatileDbArgs f m blk -> Tracer m (TraceEvent blk)
volValidationPolicy :: forall (f :: * -> *) (m :: * -> *) blk.
VolatileDbArgs f m blk -> BlockValidationPolicy
volMaxBlocksPerFile :: forall (f :: * -> *) (m :: * -> *) blk.
VolatileDbArgs f m blk -> BlocksPerFile
volHasFS :: forall (f :: * -> *) (m :: * -> *) blk.
VolatileDbArgs f m blk -> SomeHasFS m
volCodecConfig :: forall (f :: * -> *) (m :: * -> *) blk.
VolatileDbArgs f m blk -> HKD f (CodecConfig blk)
volCheckIntegrity :: forall (f :: * -> *) (m :: * -> *) blk.
VolatileDbArgs f m blk -> HKD f (blk -> Bool)
..}
              LgrDB.LgrDbArgs {Tracer m (LedgerDB' blk)
Tracer m (TraceEvent blk)
DiskPolicy
HKD f (m (ExtLedgerState blk))
HKD f (TopLevelConfig blk)
SomeHasFS m
lgrTracer :: Tracer m (TraceEvent blk)
lgrTraceLedger :: Tracer m (LedgerDB' blk)
lgrTopLevelConfig :: HKD f (TopLevelConfig blk)
lgrHasFS :: SomeHasFS m
lgrGenesis :: HKD f (m (ExtLedgerState blk))
lgrDiskPolicy :: DiskPolicy
lgrTraceLedger :: forall (f :: * -> *) (m :: * -> *) blk.
LgrDbArgs f m blk -> Tracer m (LedgerDB' blk)
lgrTracer :: forall (f :: * -> *) (m :: * -> *) blk.
LgrDbArgs f m blk -> Tracer m (TraceEvent blk)
lgrGenesis :: forall (f :: * -> *) (m :: * -> *) blk.
LgrDbArgs f m blk -> HKD f (m (ExtLedgerState blk))
lgrDiskPolicy :: forall (f :: * -> *) (m :: * -> *) blk.
LgrDbArgs f m blk -> DiskPolicy
lgrHasFS :: forall (f :: * -> *) (m :: * -> *) blk.
LgrDbArgs f m blk -> SomeHasFS m
lgrTopLevelConfig :: forall (f :: * -> *) (m :: * -> *) blk.
LgrDbArgs f m blk -> HKD f (TopLevelConfig blk)
..}
              ChainDbSpecificArgs {Word
Tracer m (TraceEvent blk)
DiffTime
HKD f (ResourceRegistry m)
HKD f (CheckInFuture m blk)
cdbsTracer :: Tracer m (TraceEvent blk)
cdbsRegistry :: HKD f (ResourceRegistry m)
cdbsGcInterval :: DiffTime
cdbsGcDelay :: DiffTime
cdbsCheckInFuture :: HKD f (CheckInFuture m blk)
cdbsBlocksToAddSize :: Word
cdbsTracer :: forall (f :: * -> *) (m :: * -> *) blk.
ChainDbSpecificArgs f m blk -> Tracer m (TraceEvent blk)
cdbsRegistry :: forall (f :: * -> *) (m :: * -> *) blk.
ChainDbSpecificArgs f m blk -> HKD f (ResourceRegistry m)
cdbsGcInterval :: forall (f :: * -> *) (m :: * -> *) blk.
ChainDbSpecificArgs f m blk -> DiffTime
cdbsGcDelay :: forall (f :: * -> *) (m :: * -> *) blk.
ChainDbSpecificArgs f m blk -> DiffTime
cdbsCheckInFuture :: forall (f :: * -> *) (m :: * -> *) blk.
ChainDbSpecificArgs f m blk -> HKD f (CheckInFuture m blk)
cdbsBlocksToAddSize :: forall (f :: * -> *) (m :: * -> *) blk.
ChainDbSpecificArgs f m blk -> Word
..} = ChainDbArgs :: forall (f :: * -> *) (m :: * -> *) blk.
SomeHasFS m
-> SomeHasFS m
-> SomeHasFS m
-> ValidationPolicy
-> BlockValidationPolicy
-> BlocksPerFile
-> DiskPolicy
-> HKD f (TopLevelConfig blk)
-> HKD f ChunkInfo
-> HKD f (blk -> Bool)
-> HKD f (m (ExtLedgerState blk))
-> HKD f (CheckInFuture m blk)
-> CacheConfig
-> Tracer m (TraceEvent blk)
-> Tracer m (LedgerDB' blk)
-> HKD f (ResourceRegistry m)
-> DiffTime
-> DiffTime
-> Word
-> ChainDbArgs f m blk
ChainDbArgs{
      -- HasFS instances
      cdbHasFSImmutableDB :: SomeHasFS m
cdbHasFSImmutableDB       = SomeHasFS m
immHasFS
    , cdbHasFSVolatileDB :: SomeHasFS m
cdbHasFSVolatileDB        = SomeHasFS m
volHasFS
    , cdbHasFSLgrDB :: SomeHasFS m
cdbHasFSLgrDB             = SomeHasFS m
lgrHasFS
      -- Policy
    , cdbImmutableDbValidation :: ValidationPolicy
cdbImmutableDbValidation  = ValidationPolicy
immValidationPolicy
    , cdbVolatileDbValidation :: BlockValidationPolicy
cdbVolatileDbValidation   = BlockValidationPolicy
volValidationPolicy
    , cdbMaxBlocksPerFile :: BlocksPerFile
cdbMaxBlocksPerFile       = BlocksPerFile
volMaxBlocksPerFile
    , cdbDiskPolicy :: DiskPolicy
cdbDiskPolicy             = DiskPolicy
lgrDiskPolicy
      -- Integration
    , cdbTopLevelConfig :: HKD f (TopLevelConfig blk)
cdbTopLevelConfig         = HKD f (TopLevelConfig blk)
lgrTopLevelConfig
    , cdbChunkInfo :: HKD f ChunkInfo
cdbChunkInfo              = HKD f ChunkInfo
immChunkInfo
    , cdbCheckIntegrity :: HKD f (blk -> Bool)
cdbCheckIntegrity         = HKD f (blk -> Bool)
immCheckIntegrity
    , cdbGenesis :: HKD f (m (ExtLedgerState blk))
cdbGenesis                = HKD f (m (ExtLedgerState blk))
lgrGenesis
    , cdbCheckInFuture :: HKD f (CheckInFuture m blk)
cdbCheckInFuture          = HKD f (CheckInFuture m blk)
cdbsCheckInFuture
    , cdbImmutableDbCacheConfig :: CacheConfig
cdbImmutableDbCacheConfig = CacheConfig
immCacheConfig
      -- Misc
    , cdbTracer :: Tracer m (TraceEvent blk)
cdbTracer                 = Tracer m (TraceEvent blk)
cdbsTracer
    , cdbTraceLedger :: Tracer m (LedgerDB' blk)
cdbTraceLedger            = Tracer m (LedgerDB' blk)
lgrTraceLedger
    , cdbRegistry :: HKD f (ResourceRegistry m)
cdbRegistry               = HKD f (ResourceRegistry m)
cdbsRegistry
    , cdbGcDelay :: DiffTime
cdbGcDelay                = DiffTime
cdbsGcDelay
    , cdbGcInterval :: DiffTime
cdbGcInterval             = DiffTime
cdbsGcInterval
    , cdbBlocksToAddSize :: Word
cdbBlocksToAddSize        = Word
cdbsBlocksToAddSize
    }

{-------------------------------------------------------------------------------
  Relative mount points
-------------------------------------------------------------------------------}

-- | A relative path for a 'MountPoint'
--
-- The root is determined by context.
newtype RelativeMountPoint = RelativeMountPoint FilePath