1
+ {-# LANGUAGE BangPatterns #-}
1
2
{-# LANGUAGE CPP #-}
2
3
{-# LANGUAGE DataKinds #-}
3
4
{-# LANGUAGE DeriveAnyClass #-}
@@ -35,6 +36,7 @@ import Data.Set (Set)
35
36
import qualified Data.Set as Set
36
37
import Data.Void
37
38
import Data.Word
39
+ import qualified Debug.Trace as DT
38
40
import GHC.Generics
39
41
import NoThunks.Class
40
42
import Ouroboros.Consensus.Block
@@ -209,8 +211,9 @@ mkInternals bss h =
209
211
eFrk <- newForkerAtTarget h reg VolatileTip
210
212
case eFrk of
211
213
Left {} -> error " Unreachable, Volatile tip MUST be in LedgerDB"
212
- Right frk ->
214
+ Right frk -> do
213
215
forkerPush frk st >> atomically (forkerCommit frk) >> forkerClose frk
216
+ getEnv h pruneLedgerSeq
214
217
, reapplyThenPushNOW = \ blk -> getEnv h $ \ env -> withRegistry $ \ reg -> do
215
218
eFrk <- newForkerAtTarget h reg VolatileTip
216
219
case eFrk of
@@ -225,6 +228,7 @@ mkInternals bss h =
225
228
blk
226
229
(st `withLedgerTables` tables)
227
230
forkerPush frk st' >> atomically (forkerCommit frk) >> forkerClose frk
231
+ pruneLedgerSeq env
228
232
, wipeLedgerDB = getEnv h $ destroySnapshots . ldbHasFS
229
233
, closeLedgerDB =
230
234
let LDBHandle tvar = h
@@ -243,6 +247,12 @@ mkInternals bss h =
243
247
InMemoryHandleArgs -> InMemory. takeSnapshot
244
248
LSMHandleArgs x -> absurd x
245
249
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
+
246
256
-- | Testing only! Truncate all snapshots in the DB.
247
257
implIntTruncateSnapshots :: MonadThrow m => SomeHasFS m -> m ()
248
258
implIntTruncateSnapshots sfs@ (SomeHasFS fs) = do
@@ -413,8 +423,11 @@ implTryTakeSnapshot bss env mTime nrBlocks =
413
423
-- periodically flush the accumulated differences to the disk. However, in the
414
424
-- second version there is no need to do so, and because of that, this function
415
425
-- does nothing in this case.
416
- implTryFlush :: Applicative m => LedgerDBEnv m l blk -> m ()
417
- implTryFlush _ = pure ()
426
+ implTryFlush :: (MonadSTM m , GetTip l ) => LedgerDBEnv m l blk -> m ()
427
+ implTryFlush env = do
428
+ LedgerSeq ldb <- readTVarIO $ ldbSeq env
429
+ ! _ <- DT. traceM $ " ledger seq len: " <> show (AS. length ldb)
430
+ pure ()
418
431
419
432
implCloseDB :: IOLike m => LedgerDBHandle m l blk -> m ()
420
433
implCloseDB (LDBHandle varState) = do
0 commit comments