Skip to content

Commit c5476f6

Browse files
committed
Add versioning to ledger tables
1 parent 3823bfd commit c5476f6

File tree

6 files changed

+24
-1
lines changed

6 files changed

+24
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ main = withStdTerminalHandles $ do
287287
let crcOut = maybe inCRC (crcOfConcat inCRC) mCRCOut
288288

289289
lift $ putStr "Generating new metadata file..." >> hFlush stdout
290-
putMetadata outFilePath (SnapshotMetadata outBackend crcOut)
290+
putMetadata outFilePath (SnapshotMetadata outBackend crcOut TablesCodecVersion1)
291291

292292
lift $ putColored Green True "Done"
293293

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ module Ouroboros.Consensus.Storage.LedgerDB.Snapshots
2828
, SnapshotFailure (..)
2929
, SnapshotMetadata (..)
3030
, SnapshotPolicyArgs (..)
31+
, TablesCodecVersion (..)
3132
, defaultSnapshotPolicyArgs
3233

3334
-- * Codec
@@ -83,6 +84,7 @@ import Control.Monad.Except
8384
import Control.Tracer
8485
import Data.Aeson (FromJSON (..), ToJSON (..), (.:), (.=))
8586
import qualified Data.Aeson as Aeson
87+
import Data.Aeson.Types (Parser)
8688
import Data.Functor.Identity
8789
import qualified Data.List as List
8890
import Data.Maybe (isJust, mapMaybe)
@@ -163,9 +165,24 @@ data ReadSnapshotErr
163165
ReadMetadataError FsPath MetadataErr
164166
deriving (Eq, Show)
165167

168+
data TablesCodecVersion = TablesCodecVersion1
169+
deriving (Eq, Show)
170+
171+
instance ToJSON TablesCodecVersion where
172+
toJSON TablesCodecVersion1 = Aeson.Number 1
173+
174+
instance FromJSON TablesCodecVersion where
175+
parseJSON v = enforceVersion =<< parseJSON v
176+
177+
enforceVersion :: Word8 -> Parser TablesCodecVersion
178+
enforceVersion v = case v of
179+
1 -> pure TablesCodecVersion1
180+
_ -> fail "Unknown or outdated tables codec version"
181+
166182
data SnapshotMetadata = SnapshotMetadata
167183
{ snapshotBackend :: SnapshotBackend
168184
, snapshotChecksum :: CRC
185+
, snapshotTablesCodecVersion :: TablesCodecVersion
169186
}
170187
deriving (Eq, Show)
171188

@@ -174,13 +191,15 @@ instance ToJSON SnapshotMetadata where
174191
Aeson.object
175192
[ "backend" .= snapshotBackend sm
176193
, "checksum" .= getCRC (snapshotChecksum sm)
194+
, "tablesCodecVersion" .= snapshotTablesCodecVersion sm
177195
]
178196

179197
instance FromJSON SnapshotMetadata where
180198
parseJSON = Aeson.withObject "SnapshotMetadata" $ \o ->
181199
SnapshotMetadata
182200
<$> o .: "backend"
183201
<*> fmap CRC (o .: "checksum")
202+
<*> o .: "tablesCodecVersion"
184203

185204
data SnapshotBackend
186205
= UTxOHDMemSnapshot

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ writeSnapshot fs@(SomeHasFS hasFS) backingStore encLedger snapshot cs = do
260260
SnapshotMetadata
261261
{ snapshotBackend = bsSnapshotBackend backingStore
262262
, snapshotChecksum = crc
263+
, snapshotTablesCodecVersion = TablesCodecVersion1
263264
}
264265
bsCopy
265266
backingStore

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ implTakeSnapshot ccfg tracer shfs@(SomeHasFS hasFS) suffix st = do
300300
SnapshotMetadata
301301
{ snapshotBackend = UTxOHDMemSnapshot
302302
, snapshotChecksum = maybe crc1 (crcOfConcat crc1) crc2
303+
, snapshotTablesCodecVersion = TablesCodecVersion1
303304
}
304305

305306
-- | Read snapshot from disk.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ implTakeSnapshot ccfg tracer shfs@(SomeHasFS hasFs) suffix st =
398398
SnapshotMetadata
399399
{ snapshotBackend = UTxOHDLSMSnapshot
400400
, snapshotChecksum = maybe crc1 (crcOfConcat crc1) crc2
401+
, snapshotTablesCodecVersion = TablesCodecVersion1
401402
}
402403

403404
-- | Delete snapshot from disk and also from the LSM tree database.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ instance Arbitrary SnapshotMetadata where
3535
SnapshotMetadata
3636
<$> arbitrary
3737
<*> fmap CRC arbitrary
38+
<*> pure TablesCodecVersion1

0 commit comments

Comments
 (0)