Skip to content

Commit

Permalink
Add Flag "DiskSnapshotChecksum" to DiskPolicyArgs
Browse files Browse the repository at this point in the history
  • Loading branch information
geo2a committed Dec 5, 2024
1 parent 4c4d820 commit d68903c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pattern DiskSnapshotChecksum, NoDiskSnapshotChecksum :: Flag "DiskSnapshotChecks
pattern DiskSnapshotChecksum = Flag True
pattern NoDiskSnapshotChecksum = Flag False

data DiskPolicyArgs = DiskPolicyArgs SnapshotInterval NumOfDiskSnapshots
data DiskPolicyArgs = DiskPolicyArgs SnapshotInterval NumOfDiskSnapshots (Flag "DiskSnapshotChecksum")

-- | On-disk policy
--
Expand Down Expand Up @@ -97,6 +97,8 @@ data DiskPolicy = DiskPolicy {
-- See also 'mkDiskPolicy'
, onDiskShouldTakeSnapshot :: TimeSinceLast DiffTime -> Word64 -> Bool

-- | Whether or not to checksum the ledger snapshots to detect data corruption on disk.
-- "yes" if @'DiskSnapshotChecksum'@; "no" if @'NoDiskSnapshotChecksum'@.
, onDiskShouldChecksumSnapshots :: Flag "DiskSnapshotChecksum"
}
deriving NoThunks via OnlyCheckWhnf DiskPolicy
Expand All @@ -107,10 +109,10 @@ data TimeSinceLast time = NoSnapshotTakenYet | TimeSinceLast time
-- | Default on-disk policy arguments suitable to use with cardano-node
--
defaultDiskPolicyArgs :: DiskPolicyArgs
defaultDiskPolicyArgs = DiskPolicyArgs DefaultSnapshotInterval DefaultNumOfDiskSnapshots
defaultDiskPolicyArgs = DiskPolicyArgs DefaultSnapshotInterval DefaultNumOfDiskSnapshots DiskSnapshotChecksum

mkDiskPolicy :: SecurityParam -> DiskPolicyArgs -> DiskPolicy
mkDiskPolicy (SecurityParam k) (DiskPolicyArgs reqInterval reqNumOfSnapshots) =
mkDiskPolicy (SecurityParam k) (DiskPolicyArgs reqInterval reqNumOfSnapshots onDiskShouldChecksumSnapshots) =
DiskPolicy {..}
where
onDiskNumSnapshots :: Word
Expand All @@ -137,8 +139,6 @@ mkDiskPolicy (SecurityParam k) (DiskPolicyArgs reqInterval reqNumOfSnapshots) =
timeSinceLast >= snapshotInterval
|| substantialAmountOfBlocksWereProcessed blocksSinceLast timeSinceLast

onDiskShouldChecksumSnapshots = DiskSnapshotChecksum

-- | We want to create a snapshot after a substantial amount of blocks were
-- processed (hard-coded to 50k blocks). Given the fact that during bootstrap
-- a fresh node will see a lot of blocks over a short period of time, we want
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ fromMinimalChainDbArgs MinimalChainDbArgs {..} = ChainDbArgs {
, volValidationPolicy = VolatileDB.ValidateAll
}
, cdbLgrDbArgs = LgrDbArgs {
lgrDiskPolicyArgs = LedgerDB.DiskPolicyArgs LedgerDB.DefaultSnapshotInterval LedgerDB.DefaultNumOfDiskSnapshots
lgrDiskPolicyArgs = LedgerDB.DiskPolicyArgs LedgerDB.DefaultSnapshotInterval LedgerDB.DefaultNumOfDiskSnapshots LedgerDB.DiskSnapshotChecksum
-- Keep 2 ledger snapshots, and take a new snapshot at least every 2 *
-- k seconds, where k is the security parameter.
, lgrGenesis = return mcdbInitLedger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE PatternSynonyms #-}

module Test.Ouroboros.Storage.LedgerDB.DiskPolicy (tests) where

Expand All @@ -13,7 +14,7 @@ import Ouroboros.Consensus.Storage.LedgerDB (DiskPolicy (..),
NumOfDiskSnapshots (..), SnapshotInterval (..),
TimeSinceLast (..), mkDiskPolicy)
import Ouroboros.Consensus.Storage.LedgerDB.DiskPolicy
(DiskPolicyArgs (DiskPolicyArgs))
(DiskPolicyArgs (DiskPolicyArgs), pattern DiskSnapshotChecksum)
import Test.QuickCheck
import Test.Tasty
import Test.Tasty.QuickCheck
Expand Down Expand Up @@ -49,7 +50,7 @@ toDiskPolicy :: TestSetup -> DiskPolicy
toDiskPolicy ts = mkDiskPolicy (tsK ts) diskPolicyArgs
where
diskPolicyArgs =
DiskPolicyArgs (tsSnapshotInterval ts) DefaultNumOfDiskSnapshots
DiskPolicyArgs (tsSnapshotInterval ts) DefaultNumOfDiskSnapshots DiskSnapshotChecksum

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

0 comments on commit d68903c

Please sign in to comment.