Skip to content

Commit 92c8800

Browse files
committed
Define mk*Args for all backends
1 parent 94340a8 commit 92c8800

File tree

7 files changed

+53
-30
lines changed
  • ouroboros-consensus-diffusion/src/ouroboros-consensus-diffusion/Ouroboros/Consensus
  • ouroboros-consensus

7 files changed

+53
-30
lines changed

ouroboros-consensus-diffusion/src/ouroboros-consensus-diffusion/Ouroboros/Consensus/Node.hs

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,11 @@ import Ouroboros.Network.Protocol.ChainSync.Codec (timeLimitsChainSync)
173173
import Ouroboros.Network.RethrowPolicy
174174
import qualified SafeWildCards
175175
import System.Exit (ExitCode (..))
176-
import System.FS.API (SomeHasFS (..), mkFsPath)
176+
import System.FS.API (SomeHasFS (..))
177177
import System.FS.API.Types (MountPoint (..))
178178
import System.FS.IO (ioHasFS)
179-
import System.FilePath (splitDirectories, (</>))
180-
import System.Random (StdGen, genWord64, newStdGen, randomIO, split)
179+
import System.FilePath ((</>))
180+
import System.Random (StdGen, newStdGen, randomIO, split)
181181

182182
{-------------------------------------------------------------------------------
183183
The arguments to the Consensus Layer node functionality
@@ -1050,20 +1050,6 @@ stdLowLevelRunNodeArgsIO
10501050
, llrnPublicPeerSelectionStateVar =
10511051
Diffusion.dcPublicPeerSelectionVar srnDiffusionConfiguration
10521052
, llrnLdbFlavorArgs = srnLedgerDbBackendArgs
1053-
-- case srnLedgerDbBackendArgs of
1054-
-- V1LMDB args -> LedgerDbFlavorArgsV1 args
1055-
-- V2InMemory -> LedgerDbFlavorArgsV2 (V2.V2Args V2.InMemoryHandleArgs)
1056-
-- V2LSM path ->
1057-
-- LedgerDbFlavorArgsV2
1058-
-- ( V2.V2Args
1059-
-- ( V2.LSMHandleArgs
1060-
-- ( V2.LSMArgs
1061-
-- (mkFsPath $ splitDirectories path)
1062-
-- lsmSalt
1063-
-- (LSM.stdMkBlockIOFS (nonImmutableDbPath srnDatabasePath))
1064-
-- )
1065-
-- )
1066-
-- )
10671053
}
10681054
where
10691055
networkMagic :: NetworkMagic

ouroboros-consensus/ouroboros-consensus.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ library ouroboros-consensus-lsm
373373
Ouroboros.Consensus.Storage.LedgerDB.V2.LSM
374374

375375
build-depends:
376+
FailT,
376377
base >=4.14 && <4.22,
377378
blockio,
378379
cardano-binary,

ouroboros-consensus/src/ouroboros-consensus-lmdb/Ouroboros/Consensus/Storage/LedgerDB/V1/BackingStore/Impl/LMDB.hs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ module Ouroboros.Consensus.Storage.LedgerDB.V1.BackingStore.Impl.LMDB
2222
, Backend (..)
2323
, Args (LMDBBackingStoreArgs)
2424
, LMDBLimits (LMDBLimits, lmdbMapSize, lmdbMaxDatabases, lmdbMaxReaders)
25+
, mkLMDBArgs
2526

2627
-- * Streaming
2728
, YieldArgs (YieldLMDB)
@@ -64,9 +65,11 @@ import Ouroboros.Consensus.Ledger.Basics
6465
import qualified Ouroboros.Consensus.Ledger.Tables.Diff as Diff
6566
import Ouroboros.Consensus.Ledger.Tables.Utils (emptyLedgerTables)
6667
import Ouroboros.Consensus.Storage.LedgerDB.API
68+
import Ouroboros.Consensus.Storage.LedgerDB.Args
6769
import Ouroboros.Consensus.Storage.LedgerDB.Snapshots
6870
( SnapshotBackend (..)
6971
)
72+
import qualified Ouroboros.Consensus.Storage.LedgerDB.V1.Args as V1
7073
import Ouroboros.Consensus.Storage.LedgerDB.V1.BackingStore
7174
import qualified Ouroboros.Consensus.Storage.LedgerDB.V1.BackingStore.API as API
7275
import qualified Ouroboros.Consensus.Storage.LedgerDB.V1.BackingStore.Impl.LMDB.Bridge as Bridge
@@ -842,6 +845,20 @@ instance
842845
limits
843846
(LiveLMDBFS $ FS.SomeHasFS $ ioHasFS $ FS.MountPoint fs)
844847

848+
-- | Create arguments for initializing the LedgerDB using the LMDB backend.
849+
mkLMDBArgs ::
850+
( MonadIOPrim m
851+
, HasLedgerTables (LedgerState blk)
852+
, IOLike m
853+
) =>
854+
V1.FlushFrequency -> FilePath -> LMDBLimits -> a -> (LedgerDbBackendArgs m blk, a)
855+
mkLMDBArgs flushing lmdbPath limits =
856+
(,) $
857+
LedgerDbBackendArgsV1 $
858+
V1.V1Args flushing $
859+
SomeBackendArgs $
860+
LMDBBackingStoreArgs lmdbPath limits Dict.Dict
861+
845862
class (MonadIO m, PrimState m ~ PrimState IO) => MonadIOPrim m
846863
instance (MonadIO m, PrimState m ~ PrimState IO) => MonadIOPrim m
847864

ouroboros-consensus/src/ouroboros-consensus-lsm/Ouroboros/Consensus/Storage/LedgerDB/V2/LSM.hs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ import Ouroboros.Consensus.Ledger.SupportsProtocol
7171
import qualified Ouroboros.Consensus.Ledger.Tables.Diff as Diff
7272
import Ouroboros.Consensus.Ledger.Tables.Utils
7373
import Ouroboros.Consensus.Storage.LedgerDB.API
74+
import Ouroboros.Consensus.Storage.LedgerDB.Args
7475
import Ouroboros.Consensus.Storage.LedgerDB.Snapshots
7576
import Ouroboros.Consensus.Storage.LedgerDB.V2
7677
import Ouroboros.Consensus.Storage.LedgerDB.V2.Backend
@@ -448,10 +449,19 @@ stdMkBlockIOFS fastStoragePath rr = do
448449

449450
data LSM
450451

451-
mkLSMArgs :: FilePath -> StdGen -> FilePath -> (Args IO LSM, StdGen)
452-
mkLSMArgs fp gen fastStorage =
452+
-- | Create arguments for initializing the LedgerDB using the LSM-trees backend.
453+
mkLSMArgs ::
454+
( LedgerSupportsProtocol blk
455+
, LedgerDbSerialiseConstraints blk
456+
) =>
457+
Proxy blk -> FilePath -> FilePath -> StdGen -> (LedgerDbBackendArgs IO blk, StdGen)
458+
mkLSMArgs _ fp fastStorage gen =
453459
let (lsmSalt, gen') = genWord64 gen
454-
in (LSMArgs (mkFsPath $ splitDirectories fp) lsmSalt (stdMkBlockIOFS fastStorage), gen')
460+
in ( LedgerDbBackendArgsV2 $
461+
SomeBackendArgs $
462+
LSMArgs (mkFsPath $ splitDirectories fp) lsmSalt (stdMkBlockIOFS fastStorage)
463+
, gen'
464+
)
455465

456466
instance
457467
( LedgerSupportsProtocol blk

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Storage/ChainDB/Impl/Args.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ import qualified Ouroboros.Consensus.Storage.ImmutableDB as ImmutableDB
4242
import Ouroboros.Consensus.Storage.LedgerDB (LedgerDbBackendArgs)
4343
import qualified Ouroboros.Consensus.Storage.LedgerDB as LedgerDB
4444
import Ouroboros.Consensus.Storage.LedgerDB.Snapshots
45+
import qualified Ouroboros.Consensus.Storage.LedgerDB.V2.Backend as LedgerDB
46+
import qualified Ouroboros.Consensus.Storage.LedgerDB.V2.InMemory as InMemory
4547
import qualified Ouroboros.Consensus.Storage.VolatileDB as VolatileDB
4648
import Ouroboros.Consensus.Util.Args
4749
import Ouroboros.Consensus.Util.IOLike
@@ -142,7 +144,7 @@ defaultArgs =
142144
ChainDbArgs
143145
ImmutableDB.defaultArgs
144146
VolatileDB.defaultArgs
145-
LedgerDB.defaultArgs
147+
(LedgerDB.defaultArgs $ LedgerDB.SomeBackendArgs InMemory.InMemArgs)
146148
defaultSpecificArgs
147149

148150
ensureValidateAll ::

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Storage/LedgerDB/Args.hs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,11 @@ import Ouroboros.Consensus.Block
3131
import Ouroboros.Consensus.Config.SecurityParam
3232
import Ouroboros.Consensus.Ledger.Abstract
3333
import Ouroboros.Consensus.Ledger.Extended
34-
import Ouroboros.Consensus.Ledger.SupportsProtocol
3534
import Ouroboros.Consensus.Storage.LedgerDB.API
3635
import Ouroboros.Consensus.Storage.LedgerDB.Snapshots
3736
import Ouroboros.Consensus.Storage.LedgerDB.TraceEvent
3837
import qualified Ouroboros.Consensus.Storage.LedgerDB.V1.Args as V1
3938
import qualified Ouroboros.Consensus.Storage.LedgerDB.V2.Backend as V2
40-
import Ouroboros.Consensus.Storage.LedgerDB.V2.InMemory
4139
import Ouroboros.Consensus.Util.Args
4240
import Ouroboros.Consensus.Util.IOLike
4341
import Ouroboros.Network.AnchoredSeq (AnchoredSeq)
@@ -71,13 +69,10 @@ data LedgerDbArgs f m blk = LedgerDbArgs
7169

7270
-- | Default arguments
7371
defaultArgs ::
74-
( IOLike m
75-
, LedgerDbSerialiseConstraints blk
76-
, LedgerSupportsProtocol blk
77-
, LedgerSupportsInMemoryLedgerDB (LedgerState blk)
78-
) =>
72+
Applicative m =>
73+
V2.SomeBackendArgs m blk ->
7974
Incomplete LedgerDbArgs m blk
80-
defaultArgs =
75+
defaultArgs backendArgs =
8176
LedgerDbArgs
8277
{ lgrSnapshotPolicyArgs = defaultSnapshotPolicyArgs
8378
, lgrGenesis = NoDefault
@@ -87,7 +82,7 @@ defaultArgs =
8782
, lgrTracer = nullTracer
8883
, -- This value is the closest thing to a pre-UTxO-HD node, and as such it
8984
-- will be the default for end-users.
90-
lgrBackendArgs = LedgerDbBackendArgsV2 $ V2.SomeBackendArgs InMemArgs
85+
lgrBackendArgs = LedgerDbBackendArgsV2 backendArgs
9186
, lgrRegistry = NoDefault
9287
, lgrStartSnapshot = Nothing
9388
}

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Storage/LedgerDB/V2/InMemory.hs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ module Ouroboros.Consensus.Storage.LedgerDB.V2.InMemory
2020
, Mem
2121
, YieldArgs (YieldInMemory)
2222
, SinkArgs (SinkInMemory)
23+
, mkInMemoryArgs
2324
) where
2425

2526
import Cardano.Binary as CBOR
@@ -57,6 +58,7 @@ import Ouroboros.Consensus.Ledger.SupportsProtocol
5758
import qualified Ouroboros.Consensus.Ledger.Tables.Diff as Diff
5859
import Ouroboros.Consensus.Ledger.Tables.Utils
5960
import Ouroboros.Consensus.Storage.LedgerDB.API
61+
import Ouroboros.Consensus.Storage.LedgerDB.Args
6062
import Ouroboros.Consensus.Storage.LedgerDB.Snapshots
6163
import Ouroboros.Consensus.Storage.LedgerDB.V2.Backend
6264
import Ouroboros.Consensus.Storage.LedgerDB.V2.LedgerSeq
@@ -302,6 +304,16 @@ instance
302304
snapshotManager _ _ =
303305
Ouroboros.Consensus.Storage.LedgerDB.V2.InMemory.snapshotManager
304306

307+
-- | Create arguments for initializing the LedgerDB using the InMemory backend.
308+
mkInMemoryArgs ::
309+
( IOLike m
310+
, LedgerDbSerialiseConstraints blk
311+
, LedgerSupportsProtocol blk
312+
, LedgerSupportsInMemoryLedgerDB (LedgerState blk)
313+
) =>
314+
a -> (LedgerDbBackendArgs m blk, a)
315+
mkInMemoryArgs = (,) $ LedgerDbBackendArgsV2 $ SomeBackendArgs InMemArgs
316+
305317
instance IOLike m => StreamingBackend m Mem l where
306318
data YieldArgs m Mem l
307319
= -- \| Yield an in-memory snapshot

0 commit comments

Comments
 (0)