1
1
{-# LANGUAGE DeriveAnyClass #-}
2
2
{-# LANGUAGE FlexibleContexts #-}
3
+ {-# LANGUAGE GADTs #-}
3
4
{-# LANGUAGE LambdaCase #-}
4
5
{-# LANGUAGE OverloadedStrings #-}
5
6
{-# LANGUAGE RecordWildCards #-}
7
+ {-# LANGUAGE ScopedTypeVariables #-}
6
8
{-# LANGUAGE TupleSections #-}
7
9
{-# LANGUAGE TypeApplications #-}
8
10
{-# LANGUAGE ViewPatterns #-}
@@ -30,11 +32,12 @@ import Ouroboros.Consensus.Config
30
32
import Ouroboros.Consensus.Ledger.Basics
31
33
import Ouroboros.Consensus.Ledger.Extended
32
34
import Ouroboros.Consensus.Node.ProtocolInfo
35
+ import Ouroboros.Consensus.Storage.LedgerDB.API
33
36
import Ouroboros.Consensus.Storage.LedgerDB.Snapshots
34
37
import qualified Ouroboros.Consensus.Storage.LedgerDB.V1.BackingStore.Impl.LMDB as V1
38
+ import Ouroboros.Consensus.Storage.LedgerDB.V2.LSM
35
39
import Ouroboros.Consensus.Util.CRC
36
- import Ouroboros.Consensus.Util.IOLike
37
- import Ouroboros.Consensus.Util.StreamingLedgerTables
40
+ import Ouroboros.Consensus.Util.IOLike hiding (yield )
38
41
import System.Console.ANSI
39
42
import qualified System.Directory as D
40
43
import System.Exit
@@ -45,6 +48,7 @@ import System.FilePath (splitDirectories)
45
48
import qualified System.FilePath as F
46
49
import System.IO
47
50
import System.ProgressBar
51
+ import System.Random
48
52
49
53
data Format
50
54
= Mem FilePath
@@ -215,24 +219,29 @@ instance StandardHash blk => Show (Error blk) where
215
219
[" Error when reading entries in the UTxO tables: " , show df]
216
220
show Cancelled = " Cancelled"
217
221
218
- data InEnv = InEnv
222
+ data InEnv backend = InEnv
219
223
{ inState :: LedgerState (CardanoBlock StandardCrypto ) EmptyMK
220
224
, inFilePath :: FilePath
221
225
, inStream ::
222
226
LedgerState (CardanoBlock StandardCrypto ) EmptyMK ->
223
227
ResourceRegistry IO ->
224
- IO (YieldArgs ( LedgerState ( CardanoBlock StandardCrypto )) IO )
228
+ IO (SomeBackend YieldArgs )
225
229
, inProgressMsg :: String
226
230
, inCRC :: CRC
227
231
, inSnapReadCRC :: Maybe CRC
228
232
}
229
233
230
- data OutEnv = OutEnv
234
+ data SomeBackend c where
235
+ SomeBackend ::
236
+ StreamingBackend IO backend (LedgerState (CardanoBlock StandardCrypto )) =>
237
+ c IO backend (LedgerState (CardanoBlock StandardCrypto )) -> SomeBackend c
238
+
239
+ data OutEnv backend = OutEnv
231
240
{ outFilePath :: FilePath
232
241
, outStream ::
233
242
LedgerState (CardanoBlock StandardCrypto ) EmptyMK ->
234
243
ResourceRegistry IO ->
235
- IO (SinkArgs ( LedgerState ( CardanoBlock StandardCrypto )) IO )
244
+ IO (SomeBackend SinkArgs )
236
245
, outCreateExtra :: Maybe FilePath
237
246
, outDeleteExtra :: Maybe FilePath
238
247
, outProgressMsg :: String
@@ -356,7 +365,7 @@ main = withStdTerminalHandles $ do
356
365
InEnv
357
366
st
358
367
fp
359
- (fromInMemory (fp F. </> " tables" F. </> " tvar" ))
368
+ (\ a b -> SomeBackend <$> mkInMemYieldArgs (fp F. </> " tables" F. </> " tvar" ) a b )
360
369
(" InMemory@[" <> fp <> " ]" )
361
370
c
362
371
mtd
@@ -375,7 +384,7 @@ main = withStdTerminalHandles $ do
375
384
InEnv
376
385
st
377
386
fp
378
- (fromLMDB (fp F. </> " tables" ) defaultLMDBLimits)
387
+ (\ a b -> SomeBackend <$> V1. mkLMDBYieldArgs (fp F. </> " tables" ) defaultLMDBLimits a b )
379
388
(" LMDB@[" <> fp <> " ]" )
380
389
c
381
390
mtd
@@ -394,7 +403,9 @@ main = withStdTerminalHandles $ do
394
403
InEnv
395
404
st
396
405
fp
397
- (fromLSM lsmDbPath (last $ splitDirectories fp))
406
+ ( \ a b ->
407
+ SomeBackend <$> mkLSMYieldArgs lsmDbPath (last $ splitDirectories fp) stdMkBlockIOFS newStdGen a b
408
+ )
398
409
(" LSM@[" <> lsmDbPath <> " ]" )
399
410
c
400
411
mtd
@@ -412,7 +423,7 @@ main = withStdTerminalHandles $ do
412
423
pure $
413
424
OutEnv
414
425
fp
415
- (toInMemory (fp F. </> " tables" F. </> " tvar" ))
426
+ (\ a b -> SomeBackend <$> mkInMemSinkArgs (fp F. </> " tables" F. </> " tvar" ) a b )
416
427
(Just " tables" )
417
428
(Nothing )
418
429
(" InMemory@[" <> fp <> " ]" )
@@ -429,7 +440,7 @@ main = withStdTerminalHandles $ do
429
440
pure $
430
441
OutEnv
431
442
fp
432
- (toLMDB fp defaultLMDBLimits)
443
+ (\ a b -> SomeBackend <$> V1. mkLMDBSinkArgs fp defaultLMDBLimits a b )
433
444
Nothing
434
445
Nothing
435
446
(" LMDB@[" <> fp <> " ]" )
@@ -446,12 +457,32 @@ main = withStdTerminalHandles $ do
446
457
pure $
447
458
OutEnv
448
459
fp
449
- (toLSM lsmDbPath (last $ splitDirectories fp))
460
+ ( \ a b ->
461
+ SomeBackend <$> mkLSMSinkArgs lsmDbPath (last $ splitDirectories fp) stdMkBlockIOFS newStdGen a b
462
+ )
450
463
Nothing
451
464
(Just lsmDbPath)
452
465
(" LSM@[" <> lsmDbPath <> " ]" )
453
466
UTxOHDLSMSnapshot
454
467
468
+ stream ::
469
+ LedgerState (CardanoBlock StandardCrypto ) EmptyMK ->
470
+ ( LedgerState (CardanoBlock StandardCrypto ) EmptyMK ->
471
+ ResourceRegistry IO ->
472
+ IO (SomeBackend YieldArgs )
473
+ ) ->
474
+ ( LedgerState (CardanoBlock StandardCrypto ) EmptyMK ->
475
+ ResourceRegistry IO ->
476
+ IO (SomeBackend SinkArgs )
477
+ ) ->
478
+ ExceptT DeserialiseFailure IO (Maybe CRC , Maybe CRC )
479
+ stream st mYieldArgs mSinkArgs =
480
+ ExceptT $
481
+ withRegistry $ \ reg -> do
482
+ (SomeBackend (yArgs :: YieldArgs IO backend1 l )) <- mYieldArgs st reg
483
+ (SomeBackend (sArgs :: SinkArgs IO backend2 l )) <- mSinkArgs st reg
484
+ runExceptT $ yield (Proxy @ backend1 ) yArgs st $ sink (Proxy @ backend2 ) sArgs st
485
+
455
486
-- Helpers
456
487
457
488
-- UI
0 commit comments