Skip to content

Commit 41fdeaf

Browse files
committed
validation: Only run BlockTx validation when DB fully synced
1 parent bb4b52a commit 41fdeaf

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

cardano-db/app/Cardano/Db/App/Validate/BlockTxs.hs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ import qualified System.Random as Random
2424

2525
validateEpochBlockTxs :: IO ()
2626
validateEpochBlockTxs = do
27+
fullySynced <- runDbNoLogging queryIsFullySynced
2728
mLatestEpoch <- runDbNoLogging queryLatestCachedEpochNo
2829
case mLatestEpoch of
2930
Nothing -> putStrLn "Epoch table is empty"
30-
Just latest -> validateLatestBlockTxs latest
31+
Just latest -> validateLatestBlockTxs fullySynced latest
3132

3233
-- -----------------------------------------------------------------------------
3334

@@ -37,10 +38,15 @@ data ValidateError = ValidateError
3738
, veTxCountExpected :: !Word64
3839
}
3940

40-
validateLatestBlockTxs :: Word64 -> IO ()
41-
validateLatestBlockTxs latestEpoch = do
42-
validateBlockTxs latestEpoch
43-
validateBlockTxs =<< Random.randomRIO (0, latestEpoch - 1)
41+
validateLatestBlockTxs :: Bool -> Word64 -> IO ()
42+
validateLatestBlockTxs fullySynced latestEpoch = do
43+
if not fullySynced
44+
then putStrLn "Not fully synced so not running BlockTx validation"
45+
else do
46+
-- This validation seems to be quite DB intensive, so only run it
47+
-- when the DB is fully synced.
48+
validateBlockTxs latestEpoch
49+
validateBlockTxs =<< Random.randomRIO (0, latestEpoch - 1)
4450

4551
validateBlockTxs :: Word64 -> IO ()
4652
validateBlockTxs epoch = do

0 commit comments

Comments
 (0)