@@ -37,7 +37,7 @@ import Codec.Serialise.Decoding (Decoder)
37
37
import qualified Codec.Serialise.Decoding as Dec
38
38
import Codec.Serialise.Encoding (Encoding )
39
39
import Control.Monad (forM , void )
40
- import Control.Monad.Except (ExceptT (.. ))
40
+ import Control.Monad.Except (ExceptT (.. ), throwError , withExceptT )
41
41
import Control.Tracer
42
42
import Data.Bits
43
43
import qualified Data.ByteString.Builder as BS
@@ -196,10 +196,10 @@ diskSnapshotIsTemporary = not . diskSnapshotIsPermanent
196
196
197
197
data ReadSnapshotErr =
198
198
-- | Error while de-serialising data
199
- ReadSnaphotFailed ReadIncrementalErr
199
+ ReadSnapshotFailed ReadIncrementalErr
200
200
-- | Checksum of read snapshot differs from the one tracked by
201
201
-- the corresponding '.checksum' file
202
- | ReadSnaphotDataCorruption
202
+ | ReadSnapshotDataCorruption
203
203
-- | A '.checksum' file does not exist for a @'DiskSnapshot'@
204
204
| ReadSnapshotNoChecksumFile FsPath
205
205
-- | A '.checksum' file exists for a @'DiskSnapshot'@, but its contents is invalid
@@ -219,13 +219,11 @@ readSnapshot ::
219
219
-> ExceptT ReadSnapshotErr m (ExtLedgerState blk )
220
220
readSnapshot someHasFS decLedger decHash snapshotName = do
221
221
! snapshotCRC <- readCRC someHasFS (snapshotToChecksumPath snapshotName)
222
- ExceptT $
223
- readIncremental someHasFS decoder (snapshotToPath snapshotName) >>= \ case
224
- Left e -> pure $ Left (ReadSnaphotFailed e)
225
- Right (ledgerState, checksumAsRead) ->
226
- if checksumAsRead /= snapshotCRC
227
- then pure $ Left ReadSnaphotDataCorruption
228
- else pure (Right ledgerState)
222
+ (ledgerState, checksumAsRead) <- withExceptT ReadSnapshotFailed . ExceptT $
223
+ readIncremental someHasFS decoder (snapshotToPath snapshotName)
224
+ if checksumAsRead /= snapshotCRC
225
+ then throwError ReadSnapshotDataCorruption
226
+ else pure ledgerState
229
227
where
230
228
decoder :: Decoder s (ExtLedgerState blk )
231
229
decoder = decodeSnapshotBackwardsCompatible (Proxy @ blk ) decLedger decHash
0 commit comments