1616{-# LANGUAGE RankNTypes #-}
1717{-# LANGUAGE ScopedTypeVariables #-}
1818{-# LANGUAGE StandaloneDeriving #-}
19+ {-# LANGUAGE TypeApplications #-}
1920{-# LANGUAGE TypeFamilies #-}
2021{-# LANGUAGE UndecidableInstances #-}
2122{-# OPTIONS_GHC -Wno-orphans #-}
@@ -61,18 +62,17 @@ import qualified Ouroboros.Consensus.Storage.LedgerDB as LedgerDB
6162import Ouroboros.Consensus.Storage.LedgerDB.Snapshots
6263import Ouroboros.Consensus.Storage.LedgerDB.V1 as V1
6364import Ouroboros.Consensus.Storage.LedgerDB.V1.Args hiding
64- ( LedgerDbFlavorArgs
65+ ( LedgerDbBackendArgs
6566 )
67+ import qualified Ouroboros.Consensus.Storage.LedgerDB.V1.BackingStore as V1
68+ import qualified Ouroboros.Consensus.Storage.LedgerDB.V1.BackingStore.Impl.InMemory as V1.InMemory
69+ import qualified Ouroboros.Consensus.Storage.LedgerDB.V1.BackingStore.Impl.LMDB as LMDB
6670import Ouroboros.Consensus.Storage.LedgerDB.V1.Snapshots as V1
6771import Ouroboros.Consensus.Storage.LedgerDB.V2 as V2
68- import Ouroboros.Consensus.Storage.LedgerDB.V2.Args hiding
69- ( LedgerDbFlavorArgs
70- )
71- import qualified Ouroboros.Consensus.Storage.LedgerDB.V2.Args as V2
72- import qualified Ouroboros.Consensus.Storage.LedgerDB.V2.InMemory as InMemory
72+ import Ouroboros.Consensus.Storage.LedgerDB.V2.Backend as V2
73+ import qualified Ouroboros.Consensus.Storage.LedgerDB.V2.InMemory as V2.InMemory
7374import qualified Ouroboros.Consensus.Storage.LedgerDB.V2.LSM as LSM
7475import Ouroboros.Consensus.Util hiding (Some )
75- import Ouroboros.Consensus.Util.Args
7676import Ouroboros.Consensus.Util.IOLike
7777import qualified Ouroboros.Network.AnchoredSeq as AS
7878import Ouroboros.Network.Protocol.LocalStateQuery.Type
@@ -176,7 +176,7 @@ initialEnvironment fsOps getDiskDir mkTestArguments cdb rr = do
176176-------------------------------------------------------------------------------}
177177
178178data TestArguments m = TestArguments
179- { argFlavorArgs :: ! (Complete LedgerDbFlavorArgs m )
179+ { argFlavorArgs :: ! (LedgerDbBackendArgs m TestBlock )
180180 , argLedgerDbCfg :: ! (LedgerDbCfg (ExtLedgerState TestBlock ))
181181 }
182182
@@ -212,7 +212,8 @@ inMemV1TestArguments ::
212212 TestArguments IO
213213inMemV1TestArguments secParam _ _ =
214214 TestArguments
215- { argFlavorArgs = LedgerDbFlavorArgsV1 $ V1Args DisableFlushing InMemoryBackingStoreArgs
215+ { argFlavorArgs =
216+ LedgerDbBackendArgsV1 $ V1Args DisableFlushing $ V1. SomeBackendArgs V1.InMemory. InMemArgs
216217 , argLedgerDbCfg = extLedgerDbConfig secParam
217218 }
218219
@@ -223,7 +224,7 @@ inMemV2TestArguments ::
223224 TestArguments IO
224225inMemV2TestArguments secParam _ _ =
225226 TestArguments
226- { argFlavorArgs = LedgerDbFlavorArgsV2 $ V2Args InMemoryHandleArgs
227+ { argFlavorArgs = LedgerDbBackendArgsV2 $ SomeBackendArgs V2.InMemory. InMemArgs
227228 , argLedgerDbCfg = extLedgerDbConfig secParam
228229 }
229230
@@ -235,10 +236,9 @@ lsmTestArguments ::
235236lsmTestArguments secParam salt fp =
236237 TestArguments
237238 { argFlavorArgs =
238- LedgerDbFlavorArgsV2 $
239- V2Args $
240- LSMHandleArgs $
241- LSMArgs (mkFsPath $ FilePath. splitDirectories fp) salt (LSM. stdMkBlockIOFS fp)
239+ LedgerDbBackendArgsV2 $
240+ SomeBackendArgs $
241+ LSM. LSMArgs (mkFsPath $ FilePath. splitDirectories fp) salt (LSM. stdMkBlockIOFS fp)
242242 , argLedgerDbCfg = extLedgerDbConfig secParam
243243 }
244244
@@ -250,9 +250,10 @@ lmdbTestArguments ::
250250lmdbTestArguments secParam _ fp =
251251 TestArguments
252252 { argFlavorArgs =
253- LedgerDbFlavorArgsV1 $
253+ LedgerDbBackendArgsV1 $
254254 V1Args DisableFlushing $
255- LMDBBackingStoreArgs fp (testLMDBLimits 16 ) Dict. Dict
255+ V1. SomeBackendArgs $
256+ LMDB. LMDBBackingStoreArgs fp (testLMDBLimits 16 ) Dict. Dict
256257 , argLedgerDbCfg = extLedgerDbConfig secParam
257258 }
258259
@@ -527,7 +528,7 @@ blockNotFound =
527528-------------------------------------------------------------------------------}
528529
529530openLedgerDB ::
530- Complete LedgerDbFlavorArgs IO ->
531+ LedgerDbBackendArgs IO TestBlock ->
531532 ChainDB IO ->
532533 LedgerDbCfg (ExtLedgerState TestBlock ) ->
533534 SomeHasFS IO ->
@@ -549,8 +550,8 @@ openLedgerDB flavArgs env cfg fs rr = do
549550 rr
550551 DefaultQueryBatchSize
551552 Nothing
552- (ldb, _, od) <- case flavArgs of
553- LedgerDbFlavorArgsV1 bss ->
553+ (ldb, _, od) <- case lgrBackendArgs args of
554+ LedgerDbBackendArgsV1 bss ->
554555 let snapManager = V1. snapshotManager args
555556 initDb =
556557 V1. mkInitDb
@@ -560,34 +561,22 @@ openLedgerDB flavArgs env cfg fs rr = do
560561 snapManager
561562 (praosGetVolatileSuffix $ ledgerDbCfgSecParam cfg)
562563 in openDBInternal args initDb snapManager stream replayGoal
563- LedgerDbFlavorArgsV2 bss -> do
564- (snapManager, bss') <- case bss of
565- V2. V2Args V2. InMemoryHandleArgs -> pure (InMemory. snapshotManager args, V2. InMemoryHandleEnv )
566- V2. V2Args (V2. LSMHandleArgs (V2. LSMArgs path salt mkFS)) -> do
567- (rk1, V2. SomeHasFSAndBlockIO fs' blockio) <- mkFS (lgrRegistry args)
568- session <-
569- allocate
570- (lgrRegistry args)
571- ( \ _ ->
572- LSM. openSession
573- (LedgerDBFlavorImplEvent . FlavorImplSpecificTraceV2 . V2. LSMTrace >$< lgrTracer args)
574- fs'
575- blockio
576- salt
577- path
578- )
579- LSM. closeSession
580- pure
581- ( LSM. snapshotManager (snd session) args
582- , V2. LSMHandleEnv (V2. LSMResources (fst session) (snd session) rk1)
583- )
584- let initDb =
585- V2. mkInitDb
586- args
587- bss'
588- getBlock
589- snapManager
590- (praosGetVolatileSuffix $ ledgerDbCfgSecParam cfg)
564+ LedgerDbBackendArgsV2 (V2. SomeBackendArgs bArgs) -> do
565+ res <-
566+ mkResources
567+ (Proxy @ TestBlock )
568+ (LedgerDBFlavorImplEvent . FlavorImplSpecificTraceV2 >$< lgrTracer args)
569+ bArgs
570+ (lgrRegistry args)
571+ (lgrHasFS args)
572+ let snapManager =
573+ V2. snapshotManager
574+ (Proxy @ TestBlock )
575+ res
576+ (configCodec . getExtLedgerCfg . ledgerDbCfg $ lgrConfig args)
577+ (LedgerDBSnapshotEvent >$< lgrTracer args)
578+ (lgrHasFS args)
579+ let initDb = V2. mkInitDb args getBlock snapManager (praosGetVolatileSuffix $ ledgerDbCfgSecParam cfg) res
591580 openDBInternal args initDb snapManager stream replayGoal
592581 withRegistry $ \ reg -> do
593582 vr <- validateFork ldb reg (const $ pure () ) BlockCache. empty 0 (map getHeader volBlocks)
@@ -623,6 +612,7 @@ instance RunModel Model (StateT Environment IO) where
623612 Environment _ _ chainDb mkArgs fs _ cleanup rr <- get
624613 (ldb, testInternals, getNumOpenHandles) <- lift $ do
625614 let args = mkArgs secParam salt
615+ -- TODO after a drop and restore we restart the db but the session has been closed below where I wrote blahblahblah
626616 openLedgerDB (argFlavorArgs args) chainDb (argLedgerDbCfg args) fs rr
627617 put (Environment ldb testInternals chainDb mkArgs fs getNumOpenHandles cleanup rr)
628618 pure $ pure ()
@@ -659,6 +649,7 @@ instance RunModel Model (StateT Environment IO) where
659649 Environment _ testInternals chainDb _ _ _ _ _ <- get
660650 lift $ do
661651 atomically $ modifyTVar (dbChain chainDb) (drop (fromIntegral n))
652+ -- blahblahblah
662653 closeLedgerDB testInternals
663654 perform state (Init secParam salt) lk
664655 perform _ OpenAndCloseForker _ = do
0 commit comments