Skip to content

Commit ec7f8b8

Browse files
fraser-iohkjasagredo
authored andcommitted
remove DoDiskSnapshotChecksum flag
1 parent 9aa13da commit ec7f8b8

File tree

13 files changed

+41
-78
lines changed

13 files changed

+41
-78
lines changed

ouroboros-consensus-cardano/app/snapshot-converter.hs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ data Config = Config
6565
-- ^ Which format the output snapshot must be in
6666
, outpath :: FilePath
6767
-- ^ Path to the output snapshot
68-
, checkChecksum :: Flag "DoDiskSnapshotChecksum"
69-
-- ^ Whether to check checksums match
7068
}
7169

7270
getCommandLineConfig :: IO (Config, BlockType)
@@ -106,12 +104,6 @@ parseConfig =
106104
, metavar "PATH-OUT"
107105
]
108106
)
109-
<*> flag DoDiskSnapshotChecksum NoDoDiskSnapshotChecksum
110-
( mconcat
111-
[ long "no-read-checksum"
112-
, help "Disable checking checksums"
113-
]
114-
)
115107

116108
-- Helpers
117109

@@ -189,8 +181,9 @@ load config@Config{inpath = pathToDiskSnapshot -> Just (fs@(SomeHasFS hasFS), pa
189181
<$> withExceptT
190182
(SnapshotError . InitFailureRead . ReadSnapshotFailed)
191183
(readExtLedgerState fs (decodeDiskExtLedgerState ccfg) decode path)
192-
Monad.when (getFlag checkChecksum) $ do
193-
let crcPath = path <.> "checksum"
184+
let crcPath = path <.> "checksum"
185+
crcFileExists <- Trans.lift $ doesFileExist hasFS crcPath
186+
Monad.when crcFileExists $ do
194187
snapshotCRC <-
195188
withExceptT (ReadSnapshotCRCError crcPath) $
196189
readCRC hasFS crcPath
@@ -199,7 +192,7 @@ load config@Config{inpath = pathToDiskSnapshot -> Just (fs@(SomeHasFS hasFS), pa
199192
pure (forgetLedgerTables st, projectLedgerTables st)
200193
Mem -> do
201194
checkSnapshotFileStructure Mem path fs
202-
(ls, _) <- withExceptT SnapshotError $ V2.loadSnapshot rr ccfg fs checkChecksum ds
195+
(ls, _) <- withExceptT SnapshotError $ V2.loadSnapshot rr ccfg fs ds
203196
let h = V2.currentHandle ls
204197
(V2.state h,) <$> Trans.lift (V2.readAll (V2.tables h))
205198
LMDB -> do
@@ -211,11 +204,8 @@ load config@Config{inpath = pathToDiskSnapshot -> Just (fs@(SomeHasFS hasFS), pa
211204
(V1.LMDBBackingStoreArgs tempFP defaultLMDBLimits Dict.Dict)
212205
ccfg
213206
(V1.SnapshotsFS fs)
214-
checkChecksum
215207
ds
216208
(V1.current dbch,) <$> Trans.lift (V1.bsReadAll bstore (V1.changelogLastFlushedState dbch))
217-
where
218-
Config { checkChecksum } = config
219209
load _ _ _ _ = error "Malformed input path!"
220210

221211
store ::

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

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import qualified Ouroboros.Consensus.Storage.ChainDB.Impl.Args as ChainDB
3434
import qualified Ouroboros.Consensus.Storage.ImmutableDB as ImmutableDB
3535
import qualified Ouroboros.Consensus.Storage.ImmutableDB.Stream as ImmutableDB
3636
import qualified Ouroboros.Consensus.Storage.LedgerDB as LedgerDB
37-
import qualified Ouroboros.Consensus.Storage.LedgerDB.Snapshots as LedgerDB
3837
import qualified Ouroboros.Consensus.Storage.LedgerDB.V1 as LedgerDB.V1
3938
import qualified Ouroboros.Consensus.Storage.LedgerDB.V1.Args as LedgerDB.V1
4039
import qualified Ouroboros.Consensus.Storage.LedgerDB.V1.BackingStore.Impl.LMDB as LMDB
@@ -161,20 +160,7 @@ analyse dbaConfig args =
161160
}
162161
chainDbArgs = maybeValidateAll $ ChainDB.updateTracer chainDBTracer args''
163162
immutableDbArgs = ChainDB.cdbImmDbArgs chainDbArgs
164-
args''' =
165-
args'' {
166-
ChainDB.cdbLgrDbArgs =
167-
(\x -> x {
168-
LedgerDB.lgrSnapshotPolicyArgs =
169-
(\y -> y {
170-
LedgerDB.spaDoChecksum = LedgerDB.Flag True
171-
})
172-
$ LedgerDB.lgrSnapshotPolicyArgs x
173-
}
174-
)
175-
(ChainDB.cdbLgrDbArgs args'')
176-
}
177-
ldbArgs = ChainDB.cdbLgrDbArgs args'''
163+
ldbArgs = ChainDB.cdbLgrDbArgs args''
178164

179165
withImmutableDB immutableDbArgs $ \(immutableDB, internal) -> do
180166
SomeAnalysis (Proxy :: Proxy startFrom) ana <- pure $ runAnalysis analysis

ouroboros-consensus-cardano/test/tools-test/Main.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import qualified Cardano.Tools.DBSynthesizer.Run as DBSynthesizer
88
import Cardano.Tools.DBSynthesizer.Types
99
import Ouroboros.Consensus.Block
1010
import Ouroboros.Consensus.Cardano.Block
11-
import Ouroboros.Consensus.Storage.LedgerDB.Snapshots
1211
import qualified Test.Cardano.Tools.Headers
1312
import Test.Tasty
1413
import Test.Tasty.HUnit

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import Ouroboros.Consensus.Storage.ImmutableDB.Stream
2626
import Ouroboros.Consensus.Storage.LedgerDB.API
2727
import Ouroboros.Consensus.Storage.LedgerDB.Args
2828
import Ouroboros.Consensus.Storage.LedgerDB.Forker
29-
import Ouroboros.Consensus.Storage.LedgerDB.Snapshots
3029
import Ouroboros.Consensus.Storage.LedgerDB.TraceEvent
3130
import qualified Ouroboros.Consensus.Storage.LedgerDB.V1 as V1
3231
import qualified Ouroboros.Consensus.Storage.LedgerDB.V2 as V2
@@ -123,7 +122,6 @@ openDBInternal args@(LedgerDbArgs { lgrHasFS = SomeHasFS fs }) initDb stream rep
123122
replayGoal
124123
initDb
125124
lgrStartSnapshot
126-
doDiskSnapshotChecksum
127125
(ledgerDb, internal) <- mkLedgerDb initDb db
128126
return (ledgerDb, replayCounter, internal)
129127

@@ -137,5 +135,3 @@ openDBInternal args@(LedgerDbArgs { lgrHasFS = SomeHasFS fs }) initDb stream rep
137135

138136
replayTracer = LedgerReplayEvent >$< lgrTracer
139137
snapTracer = LedgerDBSnapshotEvent >$< lgrTracer
140-
141-
SnapshotPolicyArgs _ _ doDiskSnapshotChecksum = lgrSnapshotPolicyArgs args

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

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ type InitDB :: Type -> (Type -> Type) -> Type -> Type
465465
data InitDB db m blk = InitDB {
466466
initFromGenesis :: !(m db)
467467
-- ^ Create a DB from the genesis state
468-
, initFromSnapshot :: !(Flag "DoDiskSnapshotChecksum" -> DiskSnapshot -> m (Either (SnapshotFailure blk) (db, RealPoint blk)))
468+
, initFromSnapshot :: !(DiskSnapshot -> m (Either (SnapshotFailure blk) (db, RealPoint blk)))
469469
-- ^ Create a DB from a Snapshot
470470
, closeDb :: !(db -> m ())
471471
-- ^ Closing the database, to be reopened again with a different snapshot or
@@ -516,7 +516,6 @@ initialize ::
516516
-> Point blk
517517
-> InitDB db m blk
518518
-> Maybe DiskSnapshot
519-
-> Flag "DoDiskSnapshotChecksum"
520519
-> m (InitLog blk, db, Word64)
521520
initialize replayTracer
522521
snapTracer
@@ -525,22 +524,20 @@ initialize replayTracer
525524
stream
526525
replayGoal
527526
dbIface
528-
fromSnapshot
529-
doDoDiskSnapshotChecksum =
527+
fromSnapshot =
530528
case fromSnapshot of
531-
Nothing -> listSnapshots hasFS >>= tryNewestFirst doDoDiskSnapshotChecksum id
532-
Just snap -> tryNewestFirst doDoDiskSnapshotChecksum id [snap]
529+
Nothing -> listSnapshots hasFS >>= tryNewestFirst id
530+
Just snap -> tryNewestFirst id [snap]
533531
where
534532
InitDB {initFromGenesis, initFromSnapshot, closeDb} = dbIface
535533

536-
tryNewestFirst :: Flag "DoDiskSnapshotChecksum"
537-
-> (InitLog blk -> InitLog blk)
534+
tryNewestFirst :: (InitLog blk -> InitLog blk)
538535
-> [DiskSnapshot]
539536
-> m ( InitLog blk
540537
, db
541538
, Word64
542539
)
543-
tryNewestFirst _ acc [] = do
540+
tryNewestFirst acc [] = do
544541
-- We're out of snapshots. Start at genesis
545542
traceWith (TraceReplayStartEvent >$< replayTracer) ReplayFromGenesis
546543
let replayTracer'' = decorateReplayTracerWithStart (Point Origin) replayTracer'
@@ -564,29 +561,38 @@ initialize replayTracer
564561
, replayed
565562
)
566563

567-
tryNewestFirst doChecksum acc (s:ss) = do
568-
eInitDb <- initFromSnapshot doChecksum s
564+
tryNewestFirst acc (s:ss) = do
565+
eInitDb <- initFromSnapshot s
569566
case eInitDb of
570567
-- If the snapshot is missing a metadata file, issue a warning and try
571568
-- the next oldest snapshot
572569
Left err@(InitFailureRead (ReadMetadataError _ MetadataFileDoesNotExist)) -> do
573570
traceWith snapTracer $ SnapshotMetadataMissing s
574-
tryNewestFirst doChecksum (acc . InitFailure s err) ss
571+
tryNewestFirst (acc . InitFailure s err) ss
575572

576573
-- If the snapshot's backend is incorrect, issue a warning and try
577574
-- the next oldest snapshot
578575
Left err@(InitFailureRead (ReadMetadataError _ MetadataBackendMismatch)) -> do
579576
traceWith snapTracer $ SnapshotMetadataBackendMismatch s
580-
tryNewestFirst doChecksum (acc . InitFailure s err) ss
577+
tryNewestFirst (acc . InitFailure s err) ss
578+
579+
-- If the snapshot has a checksum that doesn't match the actual data,
580+
-- issue a warning, delete it, and try the next oldest snapshot
581+
Left err@(InitFailureRead ReadSnapshotDataCorruption) -> do
582+
traceWith snapTracer $ InvalidSnapshot s err
583+
Monad.when (diskSnapshotIsTemporary s) $ do
584+
traceWith snapTracer $ DeletedSnapshot s
585+
deleteSnapshot hasFS s
586+
tryNewestFirst (acc . InitFailure s err) ss
581587

582588
-- If we fail to use this snapshot for any other reason, delete it and
583589
-- try an older one
584590
Left err -> do
585-
Monad.when (diskSnapshotIsTemporary s || err == InitFailureGenesis) $
591+
Monad.when (diskSnapshotIsTemporary s || err == InitFailureGenesis) $ do
592+
traceWith snapTracer $ DeletedSnapshot s
586593
deleteSnapshot hasFS s
587594
traceWith snapTracer . InvalidSnapshot s $ err
588-
-- reset checksum flag to the initial state after failure
589-
tryNewestFirst doChecksum (acc . InitFailure s err) ss
595+
tryNewestFirst (acc . InitFailure s err) ss
590596

591597
Right (initDb, pt) -> do
592598
let pt' = realPointToPoint pt
@@ -605,7 +611,7 @@ initialize replayTracer
605611
traceWith snapTracer . InvalidSnapshot s $ err
606612
Monad.when (diskSnapshotIsTemporary s) $ deleteSnapshot hasFS s
607613
closeDb initDb
608-
tryNewestFirst doChecksum (acc . InitFailure s err) ss
614+
tryNewestFirst (acc . InitFailure s err) ss
609615
Right (db, replayed) -> do
610616
db' <- pruneDb dbIface db
611617
return (acc (InitFromSnapshot s pt), db', replayed)

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -474,26 +474,19 @@ data SnapshotPolicy = SnapshotPolicy {
474474
--
475475
-- See also 'defaultSnapshotPolicy'
476476
, onDiskShouldTakeSnapshot :: Maybe DiffTime -> Word64 -> Bool
477-
478-
-- | Whether or not to checksum the ledger snapshots to detect data
479-
-- corruption on disk. "yes" if @'DoDiskSnapshotChecksum'@; "no" if
480-
-- @'NoDoDiskSnapshotChecksum'@.
481-
, onDiskShouldChecksumSnapshots :: Flag "DoDiskSnapshotChecksum"
482477
}
483478
deriving NoThunks via OnlyCheckWhnf SnapshotPolicy
484479

485480
data SnapshotPolicyArgs = SnapshotPolicyArgs {
486481
spaInterval :: !(SnapshotInterval)
487482
, spaNum :: !(NumOfDiskSnapshots)
488-
, spaDoChecksum :: !(Flag "DoDiskSnapshotChecksum")
489483
}
490484

491485
defaultSnapshotPolicyArgs :: SnapshotPolicyArgs
492486
defaultSnapshotPolicyArgs =
493487
SnapshotPolicyArgs
494488
DefaultSnapshotInterval
495489
DefaultNumOfDiskSnapshots
496-
DoDiskSnapshotChecksum
497490

498491
-- | Default on-disk policy suitable to use with cardano-node
499492
--
@@ -503,11 +496,10 @@ defaultSnapshotPolicy ::
503496
-> SnapshotPolicy
504497
defaultSnapshotPolicy
505498
(SecurityParam k)
506-
(SnapshotPolicyArgs requestedInterval reqNumOfSnapshots onDiskShouldChecksumSnapshots) =
499+
(SnapshotPolicyArgs requestedInterval reqNumOfSnapshots) =
507500
SnapshotPolicy {
508501
onDiskNumSnapshots
509502
, onDiskShouldTakeSnapshot
510-
, onDiskShouldChecksumSnapshots
511503
}
512504
where
513505
onDiskNumSnapshots :: Word

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ mkInitDb args bss getBlock =
9393
bsClose
9494
pure (chlog, backingStore)
9595
, initFromSnapshot =
96-
runExceptT .: loadSnapshot bsTracer baArgs (configCodec . getExtLedgerCfg . ledgerDbCfg $ lgrConfig) lgrHasFS'
96+
runExceptT . loadSnapshot bsTracer baArgs (configCodec . getExtLedgerCfg . ledgerDbCfg $ lgrConfig) lgrHasFS'
9797
, closeDb = bsClose . snd
9898
, initReapplyBlock = \cfg blk (chlog, bstore) -> do
9999
!chlog' <- reapplyThenPush cfg blk (readKeySets bstore) chlog

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,9 @@ loadSnapshot ::
254254
-> Complete BackingStoreArgs m
255255
-> CodecConfig blk
256256
-> SnapshotsFS m
257-
-> Flag "DoDiskSnapshotChecksum"
258257
-> DiskSnapshot
259258
-> ExceptT (SnapshotFailure blk) m ((DbChangelog' blk, LedgerBackingStore m (ExtLedgerState blk)), RealPoint blk)
260-
loadSnapshot tracer bss ccfg fs@(SnapshotsFS fs') doChecksum s = do
259+
loadSnapshot tracer bss ccfg fs@(SnapshotsFS fs') s = do
261260
(extLedgerSt, checksumAsRead) <- withExceptT (InitFailureRead . ReadSnapshotFailed) $
262261
readExtLedgerState fs' (decodeDiskExtLedgerState ccfg) decode (snapshotToStatePath s)
263262
snapshotMeta <- withExceptT (InitFailureRead . ReadMetadataError (snapshotToMetadataPath s)) $
@@ -267,9 +266,8 @@ loadSnapshot tracer bss ccfg fs@(SnapshotsFS fs') doChecksum s = do
267266
(LMDBBackingStoreArgs _ _ _, UTxOHDLMDBSnapshot) -> pure ()
268267
(_, _) ->
269268
throwError $ InitFailureRead $ ReadMetadataError (snapshotToMetadataPath s) MetadataBackendMismatch
270-
Monad.when (getFlag doChecksum) $ do
271-
Monad.when (checksumAsRead /= snapshotChecksum snapshotMeta) $
272-
throwError $ InitFailureRead $ ReadSnapshotDataCorruption
269+
Monad.when (checksumAsRead /= snapshotChecksum snapshotMeta) $
270+
throwError $ InitFailureRead $ ReadSnapshotDataCorruption
273271
case pointToWithOriginRealPoint (castPoint (getTip extLedgerSt)) of
274272
Origin -> throwError InitFailureGenesis
275273
NotOrigin pt -> do

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,10 @@ mkInitDb args flavArgs getBlock =
133133

134134
loadSnapshot :: CodecConfig blk
135135
-> SomeHasFS m
136-
-> Flag "DoDiskSnapshotChecksum"
137136
-> DiskSnapshot
138137
-> m (Either (SnapshotFailure blk) (LedgerSeq' m blk, RealPoint blk))
139-
loadSnapshot ccfg fs f ds = case bss of
140-
InMemoryHandleArgs -> runExceptT $ InMemory.loadSnapshot lgrRegistry ccfg fs f ds
138+
loadSnapshot ccfg fs ds = case bss of
139+
InMemoryHandleArgs -> runExceptT $ InMemory.loadSnapshot lgrRegistry ccfg fs ds
141140
LSMHandleArgs x -> absurd x
142141

143142
implMkLedgerDb ::

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,9 @@ loadSnapshot ::
194194
=> ResourceRegistry m
195195
-> CodecConfig blk
196196
-> SomeHasFS m
197-
-> Flag "DoDiskSnapshotChecksum"
198197
-> DiskSnapshot
199198
-> ExceptT (SnapshotFailure blk) m (LedgerSeq' m blk, RealPoint blk)
200-
loadSnapshot _rr ccfg fs doChecksum ds = do
199+
loadSnapshot _rr ccfg fs ds = do
201200
snapshotMeta <- withExceptT (InitFailureRead . ReadMetadataError (snapshotToMetadataPath ds)) $
202201
loadSnapshotMetadata fs ds
203202
Monad.when (snapshotBackend snapshotMeta /= UTxOHDMemSnapshot) $ do
@@ -215,8 +214,7 @@ loadSnapshot _rr ccfg fs doChecksum ds = do
215214
(fsPathFromList
216215
$ fsPathToList (snapshotToDirPath ds)
217216
<> [fromString "tables", fromString "tvar"])
218-
Monad.when (getFlag doChecksum) $ do
219-
let computedCRC = crcOfConcat checksumAsRead crcTables
220-
Monad.when (computedCRC /= snapshotChecksum snapshotMeta) $
221-
throwE $ InitFailureRead $ ReadSnapshotDataCorruption
217+
let computedCRC = crcOfConcat checksumAsRead crcTables
218+
Monad.when (computedCRC /= snapshotChecksum snapshotMeta) $
219+
throwE $ InitFailureRead $ ReadSnapshotDataCorruption
222220
(,pt) <$> lift (empty extLedgerSt values (newInMemoryLedgerTablesHandle fs))

ouroboros-consensus/src/unstable-consensus-testlib/Test/Util/ChainDB.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ fromMinimalChainDbArgs MinimalChainDbArgs {..} = ChainDbArgs {
116116
LedgerDB.SnapshotPolicyArgs
117117
LedgerDB.DefaultSnapshotInterval
118118
LedgerDB.DefaultNumOfDiskSnapshots
119-
LedgerDB.DoDiskSnapshotChecksum
120119
-- Keep 2 ledger snapshots, and take a new snapshot at least every 2 *
121120
-- k seconds, where k is the security parameter.
122121
, lgrGenesis = return mcdbInitLedger

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ toSnapshotPolicy :: TestSetup -> SnapshotPolicy
4949
toSnapshotPolicy ts = defaultSnapshotPolicy (tsK ts) snapshotPolicyArgs
5050
where
5151
snapshotPolicyArgs =
52-
SnapshotPolicyArgs (tsSnapshotInterval ts) DefaultNumOfDiskSnapshots DoDiskSnapshotChecksum
52+
SnapshotPolicyArgs (tsSnapshotInterval ts) DefaultNumOfDiskSnapshots
5353

5454
-- | The result of the represented call to 'onDiskShouldTakeSnapshot'
5555
shouldTakeSnapshot :: TestSetup -> Bool

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
@@ -424,7 +424,7 @@ openLedgerDB flavArgs env cfg fs = do
424424
replayGoal <- fmap (realPointToPoint . last . Map.keys) . atomically $ readTVar (dbBlocks env)
425425
rr <- unsafeNewRegistry
426426
let args = LedgerDbArgs
427-
(SnapshotPolicyArgs DisableSnapshots DefaultNumOfDiskSnapshots NoDoDiskSnapshotChecksum)
427+
(SnapshotPolicyArgs DisableSnapshots DefaultNumOfDiskSnapshots)
428428
(pure genesis)
429429
fs
430430
cfg

0 commit comments

Comments
 (0)