Skip to content

Commit ef45d1a

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 1b20700 commit ef45d1a

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
@@ -304,7 +304,14 @@ data TestInternals m l blk = TestInternals
304304
{ wipeLedgerDB :: m ()
305305
, takeSnapshotNOW :: WhereToTakeSnapshot -> Maybe String -> m ()
306306
, push :: ExtLedgerState blk DiffMK -> m ()
307+
-- ^ Push a ledger state, and prune the 'LedgerDB' w.r.t. the security parameter.
308+
--
309+
-- This does not modify the set of previously applied points.
307310
, reapplyThenPushNOW :: blk -> m ()
311+
-- ^ Apply block to the tip ledger state (using reapplication), and prune the
312+
-- 'LedgerDB' w.r.t. the security parameter.
313+
--
314+
-- This does not modify the set of previously applied points.
308315
, truncateSnapshots :: m ()
309316
, closeLedgerDB :: m ()
310317
, getNumLedgerTablesHandles :: m Word64

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
@@ -212,8 +212,9 @@ mkInternals bss h =
212212
eFrk <- newForkerAtTarget h reg VolatileTip
213213
case eFrk of
214214
Left{} -> error "Unreachable, Volatile tip MUST be in LedgerDB"
215-
Right frk ->
215+
Right frk -> do
216216
forkerPush frk st >> atomically (forkerCommit frk) >> forkerClose frk
217+
getEnv h pruneLedgerSeq
217218
, reapplyThenPushNOW = \blk -> getEnv h $ \env -> withRegistry $ \reg -> do
218219
eFrk <- newForkerAtTarget h reg VolatileTip
219220
case eFrk of
@@ -228,6 +229,7 @@ mkInternals bss h =
228229
blk
229230
(st `withLedgerTables` tables)
230231
forkerPush frk st' >> atomically (forkerCommit frk) >> forkerClose frk
232+
pruneLedgerSeq env
231233
, wipeLedgerDB = getEnv h $ destroySnapshots . ldbHasFS
232234
, closeLedgerDB =
233235
let LDBHandle tvar = h
@@ -250,6 +252,12 @@ mkInternals bss h =
250252
InMemoryHandleArgs -> InMemory.takeSnapshot
251253
LSMHandleArgs x -> absurd x
252254

255+
pruneLedgerSeq :: LedgerDBEnv m (ExtLedgerState blk) blk -> m ()
256+
pruneLedgerSeq env =
257+
join $ atomically $ stateTVar (ldbSeq env) $ prune (LedgerDbPruneKeeping k)
258+
where
259+
k = ledgerDbCfgSecParam $ ldbCfg env
260+
253261
-- | Testing only! Truncate all snapshots in the DB.
254262
implIntTruncateSnapshots :: MonadThrow m => SomeHasFS m -> m ()
255263
implIntTruncateSnapshots sfs@(SomeHasFS fs) = do

0 commit comments

Comments
 (0)