Skip to content

Commit dd7491d

Browse files
committed
LedgerDB: remove replayed blocks counter
It is no longer needed by the predictable snapshotting logic.
1 parent 66cd5d7 commit dd7491d

File tree

7 files changed

+24
-34
lines changed

7 files changed

+24
-34
lines changed

ouroboros-consensus-cardano/changelog.d/20250630_100310_alexander.esgen_predictable_snapshots.md

Whitespace-only changes.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ openLedgerDB ::
7373
, LedgerDB.TestInternals' IO blk
7474
)
7575
openLedgerDB args = do
76-
(ldb, _, od) <- case LedgerDB.lgrBackendArgs args of
76+
(ldb, od) <- case LedgerDB.lgrBackendArgs args of
7777
LedgerDB.LedgerDbBackendArgsV1 bss ->
7878
let snapManager = LedgerDB.V1.snapshotManager args
7979
initDb =

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Storage/ChainDB/Impl.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ openDBInternal args launchBgTasks = runWithTempRegistry $ do
164164
traceWith tracer $ TraceOpenEvent StartedOpeningLgrDB
165165
(ledgerDbGetVolatileSuffix, setGetCurrentChainForLedgerDB) <-
166166
mkLedgerDbGetVolatileSuffix
167-
(lgrDB, _replayed) <-
167+
lgrDB <-
168168
LedgerDB.openDB
169169
argsLgrDb
170170
(ImmutableDB.streamAPI immutableDB)

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ module Ouroboros.Consensus.Storage.LedgerDB
1616
) where
1717

1818
import Data.Functor.Contravariant ((>$<))
19-
import Data.Word
2019
import Ouroboros.Consensus.Block
2120
import Ouroboros.Consensus.Config
2221
import Ouroboros.Consensus.HardFork.Abstract
@@ -61,7 +60,7 @@ openDB ::
6160
-- | How to get blocks from the ChainDB
6261
ResolveBlock m blk ->
6362
GetVolatileSuffix m blk ->
64-
m (LedgerDB' m blk, Word64)
63+
m (LedgerDB' m blk)
6564
openDB
6665
args
6766
stream
@@ -113,11 +112,9 @@ doOpenDB ::
113112
SnapshotManager m n blk st ->
114113
StreamAPI m blk blk ->
115114
Point blk ->
116-
m (LedgerDB' m blk, Word64)
115+
m (LedgerDB' m blk)
117116
doOpenDB args initDb snapManager stream replayGoal =
118-
f <$> openDBInternal args initDb snapManager stream replayGoal
119-
where
120-
f (ldb, replayCounter, _) = (ldb, replayCounter)
117+
fst <$> openDBInternal args initDb snapManager stream replayGoal
121118

122119
-- | Open the ledger DB and expose internals for testing purposes
123120
openDBInternal ::
@@ -131,10 +128,10 @@ openDBInternal ::
131128
SnapshotManager m n blk st ->
132129
StreamAPI m blk blk ->
133130
Point blk ->
134-
m (LedgerDB' m blk, Word64, TestInternals' m blk)
131+
m (LedgerDB' m blk, TestInternals' m blk)
135132
openDBInternal args@(LedgerDbArgs{lgrHasFS = SomeHasFS fs}) initDb snapManager stream replayGoal = do
136133
createDirectoryIfMissing fs True (mkFsPath [])
137-
(_initLog, db, replayCounter) <-
134+
(_initLog, db) <-
138135
initialize
139136
replayTracer
140137
snapTracer
@@ -145,7 +142,7 @@ openDBInternal args@(LedgerDbArgs{lgrHasFS = SomeHasFS fs}) initDb snapManager s
145142
snapManager
146143
lgrStartSnapshot
147144
(ledgerDb, internal) <- mkLedgerDb initDb db
148-
return (ledgerDb, replayCounter, internal)
145+
return (ledgerDb, internal)
149146
where
150147
LedgerDbArgs
151148
{ lgrConfig

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

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ initialize ::
501501
InitDB db m blk ->
502502
SnapshotManager m n blk st ->
503503
Maybe DiskSnapshot ->
504-
m (InitLog blk, db, Word64)
504+
m (InitLog blk, db)
505505
initialize
506506
replayTracer
507507
snapTracer
@@ -523,7 +523,6 @@ initialize
523523
m
524524
( InitLog blk
525525
, db
526-
, Word64
527526
)
528527
tryNewestFirst acc [] = do
529528
-- We're out of snapshots. Start at genesis
@@ -544,7 +543,7 @@ initialize
544543
Left err -> do
545544
abortLedgerDbInit initDb
546545
error $ "Invariant violation: invalid immutable chain " <> show err
547-
Right (db, replayed) -> return (acc InitFromGenesis, db, replayed)
546+
Right db -> return (acc InitFromGenesis, db)
548547
tryNewestFirst acc (s : ss) = do
549548
eInitDb <- initFromSnapshot s
550549
case eInitDb of
@@ -596,7 +595,7 @@ initialize
596595
Monad.when (diskSnapshotIsTemporary s) $ deleteSnapshot snapManager s
597596
abortLedgerDbInit initDb
598597
tryNewestFirst (acc . InitFailure s err) ss
599-
Right (db, replayed) -> return (acc (InitFromSnapshot s pt), db, replayed)
598+
Right db -> return (acc (InitFromSnapshot s pt), db)
600599

601600
replayTracer' =
602601
decorateReplayTracerWithGoal
@@ -620,32 +619,27 @@ replayStartingWith ::
620619
db ->
621620
Point blk ->
622621
InitDB db m blk ->
623-
ExceptT (SnapshotFailure blk) m (db, Word64)
622+
ExceptT (SnapshotFailure blk) m db
624623
replayStartingWith tracer cfg stream initDb from InitDB{initReapplyBlock, currentTip} = do
625624
streamAll
626625
stream
627626
from
628627
InitFailureTooRecent
629-
(initDb, 0)
628+
initDb
630629
push
631630
where
632-
push ::
633-
blk ->
634-
(db, Word64) ->
635-
m (db, Word64)
636-
push blk (!db, !replayed) = do
631+
push :: blk -> db -> m db
632+
push blk !db = do
637633
!db' <- initReapplyBlock cfg blk db
638634

639-
let !replayed' = replayed + 1
640-
641-
events =
635+
let events =
642636
inspectLedger
643637
(getExtLedgerCfg (ledgerDbCfg cfg))
644638
(currentTip db)
645639
(currentTip db')
646640

647641
traceWith tracer (ReplayedBlock (blockRealPoint blk) events)
648-
return (db', replayed')
642+
return db'
649643

650644
{-------------------------------------------------------------------------------
651645
Trace replay events

ouroboros-consensus/test/consensus-test/Test/Consensus/MiniProtocol/LocalStateQuery/Server.hs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -239,13 +239,12 @@ initLedgerDB s c = do
239239
, lgrStartSnapshot = Nothing
240240
}
241241
ldb <-
242-
fst
243-
<$> LedgerDB.openDB
244-
args
245-
streamAPI
246-
(Chain.headPoint c)
247-
(\rpt -> pure $ fromMaybe (error "impossible") $ Chain.findBlock ((rpt ==) . blockRealPoint) c)
248-
(LedgerDB.praosGetVolatileSuffix s)
242+
LedgerDB.openDB
243+
args
244+
streamAPI
245+
(Chain.headPoint c)
246+
(\rpt -> pure $ fromMaybe (error "impossible") $ Chain.findBlock ((rpt ==) . blockRealPoint) c)
247+
(LedgerDB.praosGetVolatileSuffix s)
249248

250249
result <-
251250
LedgerDB.validateFork

ouroboros-consensus/test/storage-test/Test/Ouroboros/Storage/LedgerDB/StateMachine.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ openLedgerDB flavArgs env cfg fs rr = do
550550
rr
551551
DefaultQueryBatchSize
552552
Nothing
553-
(ldb, _, od) <- case lgrBackendArgs args of
553+
(ldb, od) <- case lgrBackendArgs args of
554554
LedgerDbBackendArgsV1 bss ->
555555
let snapManager = V1.snapshotManager args
556556
initDb =

0 commit comments

Comments
 (0)