Skip to content

Commit

Permalink
validation: Only run BlockTx validation when DB fully synced
Browse files Browse the repository at this point in the history
  • Loading branch information
erikd committed May 18, 2020
1 parent c8e18f4 commit 1a8dbc9
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions cardano-db/app/Cardano/Db/App/Validate/BlockTxs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ import qualified System.Random as Random

validateEpochBlockTxs :: IO ()
validateEpochBlockTxs = do
fullySynced <- runDbNoLogging queryIsFullySynced
mLatestEpoch <- runDbNoLogging queryLatestCachedEpochNo
case mLatestEpoch of
Nothing -> putStrLn "Epoch table is empty"
Just latest -> validateLatestBlockTxs latest
Just latest -> validateLatestBlockTxs fullySynced latest

-- -----------------------------------------------------------------------------

Expand All @@ -37,10 +38,15 @@ data ValidateError = ValidateError
, veTxCountExpected :: !Word64
}

validateLatestBlockTxs :: Word64 -> IO ()
validateLatestBlockTxs latestEpoch = do
validateBlockTxs latestEpoch
validateBlockTxs =<< Random.randomRIO (0, latestEpoch - 1)
validateLatestBlockTxs :: Bool -> Word64 -> IO ()
validateLatestBlockTxs fullySynced latestEpoch = do
if not fullySynced
then putStrLn "Not fully synced so not running BlockTx validation"
else do
-- This validation seems to be quite DB intensive, so only run it
-- when the DB is fully synced.
validateBlockTxs latestEpoch
validateBlockTxs =<< Random.randomRIO (0, latestEpoch - 1)

validateBlockTxs :: Word64 -> IO ()
validateBlockTxs epoch = do
Expand Down

0 comments on commit 1a8dbc9

Please sign in to comment.