Skip to content

Commit 13e5533

Browse files
committed
LedgerDB.V2.TestInternals: prune LedgerSeq
This is used in db-analyser only, where everything happens synchronously in a single thread, so it is fine to immediately prune. V1 already does this.
1 parent 11a32d0 commit 13e5533

File tree

2 files changed

+19
-3
lines changed
  • ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Storage/LedgerDB

2 files changed

+19
-3
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,14 @@ data TestInternals m l blk = TestInternals
305305
{ wipeLedgerDB :: m ()
306306
, takeSnapshotNOW :: WhereToTakeSnapshot -> Maybe String -> m ()
307307
, push :: ExtLedgerState blk DiffMK -> m ()
308+
-- ^ Push a ledger state, and prune the 'LedgerDB' w.r.t. the security parameter.
309+
--
310+
-- This does not modify the set of previously applied points.
308311
, reapplyThenPushNOW :: blk -> m ()
312+
-- ^ Apply block to the tip ledger state (using reapplication), and prune the
313+
-- 'LedgerDB' w.r.t. the security parameter.
314+
--
315+
-- This does not modify the set of previously applied points.
309316
, truncateSnapshots :: m ()
310317
, closeLedgerDB :: m ()
311318
}

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE BangPatterns #-}
12
{-# LANGUAGE CPP #-}
23
{-# LANGUAGE DataKinds #-}
34
{-# LANGUAGE DeriveAnyClass #-}
@@ -210,8 +211,9 @@ mkInternals bss h =
210211
eFrk <- newForkerAtTarget h reg VolatileTip
211212
case eFrk of
212213
Left{} -> error "Unreachable, Volatile tip MUST be in LedgerDB"
213-
Right frk ->
214+
Right frk -> do
214215
forkerPush frk st >> atomically (forkerCommit frk) >> forkerClose frk
216+
getEnv h pruneLedgerSeq
215217
, reapplyThenPushNOW = \blk -> getEnv h $ \env -> withRegistry $ \reg -> do
216218
eFrk <- newForkerAtTarget h reg VolatileTip
217219
case eFrk of
@@ -226,6 +228,7 @@ mkInternals bss h =
226228
blk
227229
(st `withLedgerTables` tables)
228230
forkerPush frk st' >> atomically (forkerCommit frk) >> forkerClose frk
231+
pruneLedgerSeq env
229232
, wipeLedgerDB = getEnv h $ destroySnapshots . ldbHasFS
230233
, closeLedgerDB =
231234
let LDBHandle tvar = h
@@ -244,6 +247,12 @@ mkInternals bss h =
244247
InMemoryHandleArgs -> InMemory.takeSnapshot
245248
LSMHandleArgs x -> absurd x
246249

250+
pruneLedgerSeq :: LedgerDBEnv m (ExtLedgerState blk) blk -> m ()
251+
pruneLedgerSeq env =
252+
join $ atomically $ stateTVar (ldbSeq env) $ prune (LedgerDbPruneKeeping k)
253+
where
254+
k = ledgerDbCfgSecParam $ ldbCfg env
255+
247256
-- | Testing only! Truncate all snapshots in the DB.
248257
implIntTruncateSnapshots :: MonadThrow m => SomeHasFS m -> m ()
249258
implIntTruncateSnapshots sfs@(SomeHasFS fs) = do
@@ -412,8 +421,8 @@ implTryTakeSnapshot bss env mTime nrBlocks =
412421
-- periodically flush the accumulated differences to the disk. However, in the
413422
-- second version there is no need to do so, and because of that, this function
414423
-- does nothing in this case.
415-
implTryFlush :: Applicative m => LedgerDBEnv m l blk -> m ()
416-
implTryFlush _ = pure ()
424+
implTryFlush :: (Applicative m, GetTip l) => LedgerDBEnv m l blk -> m ()
425+
implTryFlush env = pure ()
417426

418427
implCloseDB :: IOLike m => LedgerDBHandle m l blk -> m ()
419428
implCloseDB (LDBHandle varState) = do

0 commit comments

Comments
 (0)