Skip to content

Commit 1a84a00

Browse files
committed
Reject legacy snapshots
1 parent 6f0481a commit 1a84a00

File tree

5 files changed

+35
-3
lines changed

5 files changed

+35
-3
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!--
2+
A new scriv changelog fragment.
3+
4+
Uncomment the section that is right (remove the HTML comment wrapper).
5+
For top level release notes, leave all the headers commented out.
6+
-->
7+
8+
<!--
9+
### Patch
10+
11+
- A bullet item for the Patch category.
12+
13+
-->
14+
<!--
15+
### Non-Breaking
16+
17+
- A bullet item for the Non-Breaking category.
18+
19+
-->
20+
### Breaking
21+
22+
- Legacy snapshots will be rejected and deleted, instead of crashing consensus.

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,10 @@ loadSnapshot ::
450450
Session m ->
451451
DiskSnapshot ->
452452
ExceptT (SnapshotFailure blk) m (LedgerSeq' m blk, RealPoint blk)
453-
loadSnapshot tracer rr ccfg fs session ds =
453+
loadSnapshot tracer rr ccfg fs@(SomeHasFS hfs) session ds =
454454
do
455+
fileEx <- lift $ doesFileExist hfs (snapshotToDirPath ds)
456+
Monad.when fileEx $ throwE $ InitFailureRead ReadSnapshotIsLegacy
455457
snapshotMeta <-
456458
withExceptT (InitFailureRead . ReadMetadataError (snapshotToMetadataPath ds)) $
457459
loadSnapshotMetadata fs ds

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ data ReadSnapshotErr
185185
ReadSnapshotDataCorruption
186186
| -- | An error occurred while reading the snapshot metadata file
187187
ReadMetadataError FsPath MetadataErr
188+
| -- | We were given a legacy snapshot
189+
ReadSnapshotIsLegacy
188190
deriving (Eq, Show)
189191

190192
data TablesCodecVersion = TablesCodecVersion1

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ import Ouroboros.Consensus.Util.Args (Complete)
163163
import Ouroboros.Consensus.Util.Enclose
164164
import Ouroboros.Consensus.Util.IOLike
165165
import System.FS.API
166+
import qualified System.FS.API as FS
166167

167168
snapshotManager ::
168169
( IOLike m
@@ -293,7 +294,9 @@ loadSnapshot ::
293294
(SnapshotFailure blk)
294295
m
295296
((DbChangelog' blk, ResourceKey m, LedgerBackingStore m (ExtLedgerState blk)), RealPoint blk)
296-
loadSnapshot tracer bArgs@(SomeBackendArgs bss) ccfg fs@(SnapshotsFS fs') reg s = do
297+
loadSnapshot tracer bArgs@(SomeBackendArgs bss) ccfg fs@(SnapshotsFS fs'@(SomeHasFS hfs)) reg s = do
298+
fileEx <- Trans.lift $ FS.doesFileExist hfs (snapshotToDirPath s)
299+
Monad.when fileEx $ throwError $ InitFailureRead ReadSnapshotIsLegacy
297300
(extLedgerSt, checksumAsRead) <-
298301
withExceptT (InitFailureRead . ReadSnapshotFailed) $
299302
readExtLedgerState fs' (decodeDiskExtLedgerState ccfg) decode (snapshotToStatePath s)

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,10 @@ loadSnapshot ::
323323
SomeHasFS m ->
324324
DiskSnapshot ->
325325
ExceptT (SnapshotFailure blk) m (LedgerSeq' m blk, RealPoint blk)
326-
loadSnapshot tracer _rr ccfg fs ds = do
326+
loadSnapshot tracer _rr ccfg fs@(SomeHasFS hfs) ds = do
327+
fileEx <- lift $ doesFileExist hfs (snapshotToDirPath ds)
328+
Monad.when fileEx $ throwE $ InitFailureRead ReadSnapshotIsLegacy
329+
327330
snapshotMeta <-
328331
withExceptT (InitFailureRead . ReadMetadataError (snapshotToMetadataPath ds)) $
329332
loadSnapshotMetadata fs ds

0 commit comments

Comments
 (0)