Skip to content

Commit 15ce0ca

Browse files
committed
Also instantiate HasBlockIO
1 parent 6b7f00c commit 15ce0ca

File tree

8 files changed

+51
-14
lines changed

8 files changed

+51
-14
lines changed

cabal.project

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ source-repository-package
118118
source-repository-package
119119
type: git
120120
location: https://github.com/jasagredo/lsm-tree
121-
tag: 55c4b99e3e569c168de38f6d351507236d027f49
121+
tag: 2491d82e325be54dfa3525175f3382b56404404c
122122
subdir:
123123
.
124124
blockio

ouroboros-consensus-cardano/src/byron/Ouroboros/Consensus/Byron/Node.hs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import Control.Monad (guard)
3636
import Data.Coerce (coerce)
3737
import Data.Maybe
3838
import Data.Text (Text)
39-
import Data.Void (Void)
39+
import Data.Void (Void, absurd)
4040
import Ouroboros.Consensus.Block
4141
import Ouroboros.Consensus.BlockchainTime (SystemStart (..))
4242
import Ouroboros.Consensus.Byron.Crypto.DSIGN
@@ -61,11 +61,18 @@ import Ouroboros.Consensus.Storage.ChainDB.Init (InitChainDB (..))
6161
import Ouroboros.Consensus.Storage.ImmutableDB (simpleChunkInfo)
6262
import Ouroboros.Consensus.Util ((....:))
6363
import Ouroboros.Network.Magic (NetworkMagic (..))
64+
import qualified Database.LSMTree as LSM
6465

6566
{-------------------------------------------------------------------------------
6667
Credentials
6768
-------------------------------------------------------------------------------}
6869

70+
instance LSM.SerialiseKey Void where
71+
serialiseKey = absurd
72+
deserialiseKey = error "deserialiseKey: Void"
73+
74+
deriving via LSM.ResolveAsFirst Void instance LSM.ResolveValue Void
75+
6976
-- | Credentials needed to produce blocks in the Byron era.
7077
data ByronLeaderCredentials = ByronLeaderCredentials
7178
{ blcSignKey :: Crypto.SigningKey

ouroboros-consensus-diffusion/ouroboros-consensus-diffusion.cabal

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ library
8383
contra-tracer,
8484
deepseq,
8585
filepath,
86+
blockio,
87+
lsm-tree,
8688
fs-api ^>=0.4,
8789
hashable,
8890
io-classes:{io-classes, si-timers, strict-stm} ^>=1.8,

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ import Ouroboros.Consensus.Storage.LedgerDB.Args
128128
import Ouroboros.Consensus.Storage.LedgerDB.Snapshots
129129
import Ouroboros.Consensus.Util.Args
130130
import Ouroboros.Consensus.Util.IOLike
131+
import System.FS.BlockIO.API
132+
import System.FS.BlockIO.IO
131133
import Ouroboros.Consensus.Util.Orphans ()
132134
import Ouroboros.Consensus.Util.Time (secondsToNominalDiffTime)
133135
import Ouroboros.Network.BlockFetch
@@ -176,7 +178,8 @@ import System.FS.API (SomeHasFS (..))
176178
import System.FS.API.Types (MountPoint (..))
177179
import System.FS.IO (ioHasFS)
178180
import System.FilePath ((</>))
179-
import System.Random (StdGen, newStdGen, randomIO, split)
181+
import System.Random (StdGen, newStdGen, randomIO, split, genWord64, initStdGen)
182+
import qualified Database.LSMTree as LSM
180183

181184
{-------------------------------------------------------------------------------
182185
The arguments to the Consensus Layer node functionality
@@ -266,6 +269,8 @@ data LowLevelRunNodeArgs m addrNTN addrNTC blk
266269
, llrnMkVolatileHasFS :: ChainDB.RelativeMountPoint -> SomeHasFS m
267270
-- ^ File-system on which the directories for databases other than the ImmutableDB will
268271
-- be created.
272+
, llrnMkLSMFS :: FilePath -> m (SomeHasFSAndBlockIO m)
273+
, llrnGenSalt :: m LSM.Salt
269274
, llrnCustomiseChainDbArgs ::
270275
Complete ChainDbArgs m blk ->
271276
Complete ChainDbArgs m blk
@@ -526,6 +531,8 @@ runWith RunNodeArgs{..} encAddrNtN decAddrNtN LowLevelRunNodeArgs{..} =
526531
initLedger
527532
llrnMkImmutableHasFS
528533
llrnMkVolatileHasFS
534+
llrnMkLSMFS
535+
llrnGenSalt
529536
llrnLdbFlavorArgs
530537
llrnChainDbArgsDefaults
531538
( setLoEinChainDbArgs
@@ -814,13 +821,15 @@ openChainDB ::
814821
(ChainDB.RelativeMountPoint -> SomeHasFS m) ->
815822
-- | Volatile FS, see 'NodeDatabasePaths'
816823
(ChainDB.RelativeMountPoint -> SomeHasFS m) ->
824+
(FilePath -> m (SomeHasFSAndBlockIO m)) ->
825+
(m LSM.Salt) ->
817826
Complete LedgerDbFlavorArgs m ->
818827
-- | A set of default arguments (possibly modified from 'defaultArgs')
819828
Incomplete ChainDbArgs m blk ->
820829
-- | Customise the 'ChainDbArgs'
821830
(Complete ChainDbArgs m blk -> Complete ChainDbArgs m blk) ->
822831
m (ChainDB m blk, Complete ChainDbArgs m blk)
823-
openChainDB registry cfg initLedger fsImm fsVol flavorArgs defArgs customiseArgs =
832+
openChainDB registry cfg initLedger fsImm fsVol fsLSM genSalt flavorArgs defArgs customiseArgs =
824833
let args =
825834
customiseArgs $
826835
ChainDB.completeChainDbArgs
@@ -831,6 +840,8 @@ openChainDB registry cfg initLedger fsImm fsVol flavorArgs defArgs customiseArgs
831840
(nodeCheckIntegrity (configStorage cfg))
832841
fsImm
833842
fsVol
843+
fsLSM
844+
genSalt
834845
flavorArgs
835846
defArgs
836847
in (,args) <$> ChainDB.openDB args
@@ -1025,6 +1036,9 @@ stdLowLevelRunNodeArgsIO
10251036
, llrnPeerSelectionRng
10261037
, llrnMkImmutableHasFS = stdMkChainDbHasFS $ immutableDbPath srnDatabasePath
10271038
, llrnMkVolatileHasFS = stdMkChainDbHasFS $ nonImmutableDbPath srnDatabasePath
1039+
, llrnMkLSMFS = \s ->
1040+
uncurry SomeHasFSAndBlockIO <$> ioHasBlockIO (MountPoint $ nonImmutableDbPath srnDatabasePath </> s) defaultIOCtxParams
1041+
, llrnGenSalt = fst . genWord64 <$> initStdGen
10281042
, llrnChainDbArgsDefaults = updateChainDbDefaults ChainDB.defaultArgs
10291043
, llrnCustomiseChainDbArgs = id
10301044
, llrnCustomiseNodeKernelArgs

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import qualified Ouroboros.Consensus.Storage.VolatileDB as VolatileDB
4545
import Ouroboros.Consensus.Util.Args
4646
import Ouroboros.Consensus.Util.IOLike
4747
import System.FS.API
48+
import qualified Database.LSMTree as LSM
4849

4950
{-------------------------------------------------------------------------------
5051
Arguments
@@ -169,6 +170,10 @@ completeChainDbArgs ::
169170
(RelativeMountPoint -> SomeHasFS m) ->
170171
-- | Volatile FS, see 'NodeDatabasePaths'
171172
(RelativeMountPoint -> SomeHasFS m) ->
173+
-- | Make LSM fs
174+
(FilePath -> m (LedgerDB.SomeHasFSAndBlockIO m)) ->
175+
-- | Make LSM Salt
176+
(m LSM.Salt) ->
172177
Complete LedgerDbFlavorArgs m ->
173178
-- | A set of incomplete arguments, possibly modified wrt @defaultArgs@
174179
Incomplete ChainDbArgs m blk ->
@@ -181,6 +186,8 @@ completeChainDbArgs
181186
checkIntegrity
182187
mkImmFS
183188
mkVolFS
189+
mkLSMFS
190+
genSalt
184191
flavorArgs
185192
defArgs =
186193
defArgs
@@ -208,6 +215,8 @@ completeChainDbArgs
208215
(LedgerDB.ledgerDbCfgComputeLedgerEvents $ LedgerDB.lgrConfig (cdbLgrDbArgs defArgs))
209216
, LedgerDB.lgrFlavorArgs = flavorArgs
210217
, LedgerDB.lgrRegistry = registry
218+
, LedgerDB.lgrGenSalt = genSalt
219+
, LedgerDB.lgrMkLSMFS = mkLSMFS
211220
}
212221
, cdbsArgs =
213222
(cdbsArgs defArgs)

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -723,12 +723,6 @@ data TraceEvent blk
723723
| TraceChainSelStarvationEvent (TraceChainSelStarvationEvent blk)
724724
deriving Generic
725725

726-
deriving instance
727-
( Eq (Header blk)
728-
, LedgerSupportsProtocol blk
729-
, InspectLedger blk
730-
) =>
731-
Eq (TraceEvent blk)
732726
deriving instance
733727
( Show (Header blk)
734728
, LedgerSupportsProtocol blk

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@ openDB
9191
<$> allocate
9292
(lgrRegistry args)
9393
( \_ -> do
94-
hasBlockIO <- ioHasBlockIO (lgrHasFS args) defaultIOCtxParams
95-
salt <- fst . genWord64 <$> initStdGen
94+
SomeHasFSAndBlockIO fs blockio <- lgrMkLSMFS args "lsm"
95+
salt <- lgrGenSalt args
9696
LSM.openSession
9797
(LedgerDBFlavorImplEvent . FlavorImplSpecificTraceV2 . V2.LSMTrace >$< lgrTracer args)
98-
(lgrHasFS args)
99-
hasBlockIO
98+
fs
99+
blockio
100100
salt
101101
(mkFsPath [path])
102102
)

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ module Ouroboros.Consensus.Storage.LedgerDB.Args
2222
, QueryBatchSize (..)
2323
, defaultArgs
2424
, defaultQueryBatchSize
25+
, SomeHasFSAndBlockIO (..)
2526
) where
2627

2728
import Control.ResourceRegistry
@@ -39,6 +40,9 @@ import qualified Ouroboros.Consensus.Storage.LedgerDB.V1.Args as V1
3940
import qualified Ouroboros.Consensus.Storage.LedgerDB.V2.Args as V2
4041
import Ouroboros.Consensus.Util.Args
4142
import System.FS.API
43+
import qualified Database.LSMTree as LSM
44+
import System.FS.BlockIO.API
45+
import Data.Typeable
4246

4347
{-------------------------------------------------------------------------------
4448
Arguments
@@ -63,8 +67,13 @@ data LedgerDbArgs f m blk = LedgerDbArgs
6367
-- ^ If provided, the ledgerdb will start using said snapshot and fallback
6468
-- to genesis. It will ignore any other existing snapshots. Useful for
6569
-- db-analyser.
70+
, lgrGenSalt :: HKD f (m LSM.Salt)
71+
, lgrMkLSMFS :: HKD f (FilePath -> m (SomeHasFSAndBlockIO m))
6672
}
6773

74+
data SomeHasFSAndBlockIO m where
75+
SomeHasFSAndBlockIO :: (Eq h, Typeable h) => HasFS m h -> HasBlockIO m h -> SomeHasFSAndBlockIO m
76+
6877
-- | Default arguments
6978
defaultArgs ::
7079
Applicative m =>
@@ -82,6 +91,8 @@ defaultArgs =
8291
lgrFlavorArgs = LedgerDbFlavorArgsV2 (V2.V2Args V2.InMemoryHandleArgs)
8392
, lgrRegistry = NoDefault
8493
, lgrStartSnapshot = Nothing
94+
, lgrGenSalt = NoDefault
95+
, lgrMkLSMFS = NoDefault
8596
}
8697

8798
data LedgerDbFlavorArgs f m

0 commit comments

Comments
 (0)