Skip to content

Commit 68402ed

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 68402ed

File tree

2 files changed

+16
-1
lines changed
  • ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Storage/LedgerDB

2 files changed

+16
-1
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: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,9 @@ mkInternals bss h =
210210
eFrk <- newForkerAtTarget h reg VolatileTip
211211
case eFrk of
212212
Left{} -> error "Unreachable, Volatile tip MUST be in LedgerDB"
213-
Right frk ->
213+
Right frk -> do
214214
forkerPush frk st >> atomically (forkerCommit frk) >> forkerClose frk
215+
getEnv h pruneLedgerSeq
215216
, reapplyThenPushNOW = \blk -> getEnv h $ \env -> withRegistry $ \reg -> do
216217
eFrk <- newForkerAtTarget h reg VolatileTip
217218
case eFrk of
@@ -226,6 +227,7 @@ mkInternals bss h =
226227
blk
227228
(st `withLedgerTables` tables)
228229
forkerPush frk st' >> atomically (forkerCommit frk) >> forkerClose frk
230+
pruneLedgerSeq env
229231
, wipeLedgerDB = getEnv h $ destroySnapshots . ldbHasFS
230232
, closeLedgerDB =
231233
let LDBHandle tvar = h
@@ -244,6 +246,12 @@ mkInternals bss h =
244246
InMemoryHandleArgs -> InMemory.takeSnapshot
245247
LSMHandleArgs x -> absurd x
246248

249+
pruneLedgerSeq :: LedgerDBEnv m (ExtLedgerState blk) blk -> m ()
250+
pruneLedgerSeq env =
251+
join $ atomically $ stateTVar (ldbSeq env) $ prune (LedgerDbPruneKeeping k)
252+
where
253+
k = ledgerDbCfgSecParam $ ldbCfg env
254+
247255
-- | Testing only! Truncate all snapshots in the DB.
248256
implIntTruncateSnapshots :: MonadThrow m => SomeHasFS m -> m ()
249257
implIntTruncateSnapshots sfs@(SomeHasFS fs) = do

0 commit comments

Comments
 (0)