@@ -119,6 +119,8 @@ module Ouroboros.Consensus.Storage.LedgerDB.API
119119 , LedgerSupportsLedgerDB
120120 , LedgerSupportsLMDBLedgerDB
121121 , LedgerSupportsLSMLedgerDB
122+ , LedgerSupportsV1LedgerDB
123+ , LedgerSupportsV2LedgerDB
122124 , LSMTxOut
123125 , HasLSMTxOut (.. )
124126 , ResolveBlock
@@ -197,7 +199,6 @@ import Ouroboros.Consensus.Util.IOLike
197199import Ouroboros.Consensus.Util.IndexedMemPack
198200import Ouroboros.Network.Block
199201import Ouroboros.Network.Protocol.LocalStateQuery.Type
200- import System.FS.API
201202
202203{- ------------------------------------------------------------------------------
203204 Main API
@@ -299,15 +300,15 @@ currentPoint ldb = castPoint . getTip <$> getVolatileTip ldb
299300data WhereToTakeSnapshot = TakeAtImmutableTip | TakeAtVolatileTip deriving Eq
300301
301302data TestInternals m l blk = TestInternals
302- { wipeLedgerDB :: m ()
303- , takeSnapshotNOW :: WhereToTakeSnapshot -> Maybe String -> m ()
304- , push :: ExtLedgerState blk DiffMK -> m ()
303+ { push :: ExtLedgerState blk DiffMK -> m ()
305304 , reapplyThenPushNOW :: blk -> m ()
306- , truncateSnapshots :: m ()
307305 , closeLedgerDB :: m ()
308306 , getNumLedgerTablesHandles :: m Word64
309307 -- ^ Get the number of referenced 'LedgerTablesHandle's for V2. For V1, this
310308 -- always returns 0.
309+ , takeSnapshotNOW :: WhereToTakeSnapshot -> Maybe String -> m ()
310+ , truncateSnapshots :: m ()
311+ , wipeLedgerDB :: m ()
311312 }
312313 deriving NoThunks via OnlyCheckWhnfNamed " TestInternals" (TestInternals m l blk )
313314
@@ -492,34 +493,32 @@ data InitDB db m blk = InitDB
492493-- obtained in this way will (hopefully) share much of their memory footprint
493494-- with their predecessors.
494495initialize ::
495- forall m blk db .
496+ forall m n blk db st .
496497 ( IOLike m
497498 , LedgerSupportsProtocol blk
498499 , InspectLedger blk
499500 , HasCallStack
500501 ) =>
501502 Tracer m (TraceReplayEvent blk ) ->
502503 Tracer m (TraceSnapshotEvent blk ) ->
503- SomeHasFS m ->
504504 LedgerDbCfg (ExtLedgerState blk ) ->
505505 StreamAPI m blk blk ->
506506 Point blk ->
507507 InitDB db m blk ->
508+ SnapshotManagement m n blk st ->
508509 Maybe DiskSnapshot ->
509- (SomeHasFS m -> DiskSnapshot -> m () ) ->
510510 m (InitLog blk , db , Word64 )
511511initialize
512512 replayTracer
513513 snapTracer
514- hasFS
515514 cfg
516515 stream
517516 replayGoal
518517 dbIface
519- fromSnapshot
520- deleteSnapshot =
518+ snapManager
519+ fromSnapshot =
521520 case fromSnapshot of
522- Nothing -> listSnapshots hasFS >>= tryNewestFirst id
521+ Nothing -> listSnapshots snapManager >>= tryNewestFirst id
523522 Just snap -> tryNewestFirst id [snap]
524523 where
525524 InitDB {initFromGenesis, initFromSnapshot, closeDb} = dbIface
@@ -579,15 +578,15 @@ initialize
579578 traceWith snapTracer $ InvalidSnapshot s err
580579 Monad. when (diskSnapshotIsTemporary s) $ do
581580 traceWith snapTracer $ DeletedSnapshot s
582- deleteSnapshot hasFS s
581+ deleteSnapshot snapManager s
583582 tryNewestFirst (acc . InitFailure s err) ss
584583
585584 -- If we fail to use this snapshot for any other reason, delete it and
586585 -- try an older one
587586 Left err -> do
588587 Monad. when (diskSnapshotIsTemporary s || err == InitFailureGenesis ) $ do
589588 traceWith snapTracer $ DeletedSnapshot s
590- deleteSnapshot hasFS s
589+ deleteSnapshot snapManager s
591590 traceWith snapTracer . InvalidSnapshot s $ err
592591 tryNewestFirst (acc . InitFailure s err) ss
593592 Right (initDb, pt) -> do
@@ -606,7 +605,7 @@ initialize
606605 case eDB of
607606 Left err -> do
608607 traceWith snapTracer . InvalidSnapshot s $ err
609- Monad. when (diskSnapshotIsTemporary s) $ deleteSnapshot hasFS s
608+ Monad. when (diskSnapshotIsTemporary s) $ deleteSnapshot snapManager s
610609 closeDb initDb
611610 tryNewestFirst (acc . InitFailure s err) ss
612611 Right (db, replayed) -> do
@@ -729,7 +728,11 @@ data TraceReplayProgressEvent blk
729728 Updating ledger tables
730729-------------------------------------------------------------------------------}
731730
732- type LedgerSupportsInMemoryLedgerDB blk = (CanUpgradeLedgerTables (LedgerState blk ))
731+ type LedgerSupportsInMemoryLedgerDB l =
732+ (CanUpgradeLedgerTables l , SerializeTablesWithHint l )
733+
734+ type LedgerSupportsV1LedgerDB l =
735+ (LedgerSupportsInMemoryLedgerDB l , LedgerSupportsLMDBLedgerDB l )
733736
734737-- | When pushing differences on InMemory Ledger DBs, we will sometimes need to
735738-- update ledger tables to the latest era. For unary blocks this is a no-op, but
@@ -768,16 +771,19 @@ instance
768771 Supporting On-Disk backing stores
769772-------------------------------------------------------------------------------}
770773
771- type LedgerSupportsLMDBLedgerDB blk =
772- (IndexedMemPack (LedgerState blk EmptyMK ) (TxOut ( LedgerState blk )) )
774+ type LedgerSupportsLMDBLedgerDB l =
775+ (IndexedMemPack (l EmptyMK ) (TxOut l ), MemPackIdx l EmptyMK ~ l EmptyMK )
773776
774- type LedgerSupportsLSMLedgerDB blk =
775- ( LSM. SerialiseKey (TxIn ( LedgerState blk ) )
776- , LSM. SerialiseValue (LSMTxOut ( LedgerState blk ) )
777- , LSM. ResolveValue (LSMTxOut ( LedgerState blk ) )
778- , HasLSMTxOut ( LedgerState blk )
777+ type LedgerSupportsLSMLedgerDB l =
778+ ( LSM. SerialiseKey (TxIn l )
779+ , LSM. SerialiseValue (LSMTxOut l )
780+ , LSM. ResolveValue (LSMTxOut l )
781+ , HasLSMTxOut l
779782 )
780783
784+ type LedgerSupportsV2LedgerDB l =
785+ (LedgerSupportsInMemoryLedgerDB l , LedgerSupportsLSMLedgerDB l )
786+
781787-- | LSM trees need to be able to serialize and deserialize values several
782788-- times, without any context. Therefore the approach of using a ledger state to
783789-- hint the era in which values need to be deserialized cannot work with LSM.
@@ -793,10 +799,12 @@ class HasLSMTxOut l where
793799 toLSMTxOut :: Proxy l -> TxOut l -> LSMTxOut l
794800 fromLSMTxOut :: l EmptyMK -> LSMTxOut l -> TxOut l
795801
796- type LedgerSupportsLedgerDB blk =
797- ( LedgerSupportsLMDBLedgerDB blk
798- , LedgerSupportsInMemoryLedgerDB blk
799- , LedgerSupportsLSMLedgerDB blk
802+ type LedgerSupportsLedgerDB blk = LedgerSupportsLedgerDB' (LedgerState blk ) blk
803+
804+ type LedgerSupportsLedgerDB' l blk =
805+ ( LedgerSupportsLMDBLedgerDB l
806+ , LedgerSupportsInMemoryLedgerDB l
807+ , LedgerSupportsLSMLedgerDB l
800808 , LedgerDbSerialiseConstraints blk
801809 )
802810
0 commit comments