Skip to content

Commit 0554e5d

Browse files
authored
db-analyser --store-ledger: fix two bugs (#1512)
Suppose that `s0 < s1 < s2` are slots with blocks in the ImmutableDB, and no other slot `s` with `s0 < s < s2` has a block, and suppose that we run `db-analyser --store-ledger s2`. It is now expected that we store a ledger snapshot for slot `s2`, which was the case before #1412. However: - With `--v1-in-mem` or `--lmdb`, we store a ledger snapshot for slot `s1`. - With `--v2-in-mem`, we store a ledger snapshot for slot `s0`. This PR fixes two unrelated bugs causing this (one specific to the V2 LedgerDB), see the individual commits. Now, in all cases, we store a ledger snapshot for slot `s2`. Applied the `no changelog` label as only testing/internal code is affected.
2 parents 515ba88 + ee92daa commit 0554e5d

File tree

2 files changed

+8
-9
lines changed
  • ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Storage/LedgerDB
  • ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Tools/DBAnalyser

2 files changed

+8
-9
lines changed

ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Tools/DBAnalyser/Analysis.hs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -394,15 +394,15 @@ storeLedgerStateAt slotNo ledgerAppMode env = do
394394
LedgerDB.forkerClose frk
395395
case runExcept $ tickThenXApply OmitLedgerEvents ledgerCfg blk (oldLedger `withLedgerTables` tbs) of
396396
Right newLedger -> do
397-
when (blockSlot blk >= slotNo) $ storeLedgerState newLedger
397+
LedgerDB.push internal newLedger
398+
when (blockSlot blk >= slotNo) storeLedgerState
398399
when (blockSlot blk > slotNo) $ issueWarning blk
399400
when ((unBlockNo $ blockNo blk) `mod` 1000 == 0) $ reportProgress blk
400-
LedgerDB.push internal newLedger
401401
LedgerDB.tryFlush initLedgerDB
402402
return (continue blk, ())
403403
Left err -> do
404404
traceWith tracer $ LedgerErrorEvent (blockPoint blk) err
405-
storeLedgerState (oldLedger `withLedgerTables` tbs)
405+
storeLedgerState
406406
pure (Stop, ())
407407

408408
tickThenXApply = case ledgerAppMode of
@@ -419,14 +419,13 @@ storeLedgerStateAt slotNo ledgerAppMode env = do
419419
reportProgress blk = let event = BlockSlotEvent (blockNo blk) (blockSlot blk) (blockHash blk)
420420
in traceWith tracer event
421421

422-
storeLedgerState :: ExtLedgerState blk mk -> IO ()
423-
storeLedgerState ledgerState = case pointSlot pt of
422+
storeLedgerState :: IO ()
423+
storeLedgerState =
424+
IOLike.atomically (pointSlot <$> LedgerDB.currentPoint initLedgerDB) >>= \case
424425
NotOrigin slot -> do
425426
LedgerDB.takeSnapshotNOW internal LedgerDB.TakeAtVolatileTip (Just "db-analyser")
426427
traceWith tracer $ SnapshotStoredEvent slot
427428
Origin -> pure ()
428-
where
429-
pt = headerStatePoint $ headerState ledgerState
430429

431430
countBlocks ::
432431
forall blk .

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ mkInternals ::
180180
mkInternals bss h = TestInternals {
181181
takeSnapshotNOW = \whereTo suff -> getEnv h $ \env -> do
182182
st <- (case whereTo of
183-
TakeAtVolatileTip -> anchorHandle
184-
TakeAtImmutableTip -> currentHandle) <$> readTVarIO (ldbSeq env)
183+
TakeAtImmutableTip -> anchorHandle
184+
TakeAtVolatileTip -> currentHandle) <$> readTVarIO (ldbSeq env)
185185
Monad.void $ takeSnapshot
186186
(configCodec . getExtLedgerCfg . ledgerDbCfg $ ldbCfg env)
187187
(LedgerDBSnapshotEvent >$< ldbTracer env)

0 commit comments

Comments
 (0)