Skip to content

Commit b3904ed

Browse files
committed
Add versioning to ledger tables
1 parent bec1fb6 commit b3904ed

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
@@ -82,6 +83,7 @@ import Control.Monad.Except
8283
import Control.Tracer
8384
import Data.Aeson (FromJSON (..), ToJSON (..), (.:), (.=))
8485
import qualified Data.Aeson as Aeson
86+
import Data.Aeson.Types (Parser)
8587
import Data.Functor.Identity
8688
import qualified Data.List as List
8789
import Data.Maybe (isJust, mapMaybe)
@@ -162,9 +164,24 @@ data ReadSnapshotErr
162164
ReadMetadataError FsPath MetadataErr
163165
deriving (Eq, Show)
164166

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

@@ -173,13 +190,15 @@ instance ToJSON SnapshotMetadata where
173190
Aeson.object
174191
[ "backend" .= snapshotBackend sm
175192
, "checksum" .= getCRC (snapshotChecksum sm)
193+
, "tablesCodecVersion" .= toJSON (snapshotTablesCodecVersion sm)
176194
]
177195

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

184203
data SnapshotBackend
185204
= 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
@@ -207,6 +207,7 @@ writeSnapshot fs@(SomeHasFS hasFs) encLedger ds st = do
207207
SnapshotMetadata
208208
{ snapshotBackend = UTxOHDMemSnapshot
209209
, snapshotChecksum = maybe crc1 (crcOfConcat crc1) crc2
210+
, snapshotTablesCodecVersion = TablesCodecVersion1
210211
}
211212

212213
implTakeSnapshot ::

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
@@ -391,6 +391,7 @@ writeSnapshot fs@(SomeHasFS hasFs) encLedger ds st = do
391391
SnapshotMetadata
392392
{ snapshotBackend = UTxOHDLSMSnapshot
393393
, snapshotChecksum = maybe crc1 (crcOfConcat crc1) crc2
394+
, snapshotTablesCodecVersion = TablesCodecVersion1
394395
}
395396

396397
-- | 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)