Skip to content
This repository has been archived by the owner on Aug 18, 2020. It is now read-only.

Commit

Permalink
Merge #3920
Browse files Browse the repository at this point in the history
3920: Karknu/rcd 43 mitigation r=cleverca22 a=karknu

## Description

Improvement that makes the network disconnect in RCD-43 less likely to happen.

## Linked issue

<!--- Put here the relevant issue from YouTrack -->



Co-authored-by: Erik de Castro Lopo <erikd@mega-nerd.com>
Co-authored-by: Karl Knutsson <karl.knutsson@iohk.io>
Co-authored-by: Kosyrev Serge <serge.kosyrev@iohk.io>
Co-authored-by: Duncan Coutts <duncan.coutts@iohk.io>
  • Loading branch information
5 people committed Dec 1, 2018
2 parents 8b3fdd5 + e1bca52 commit f6b209b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions db/cardano-sl-db.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ library
, ekg-core
, ether >= 0.5
, exceptions
, extra
, filepath
, formatting
, lens
Expand Down
16 changes: 12 additions & 4 deletions db/src/Pos/DB/Block/Epoch.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import Data.Binary (decode, encode)
import qualified Data.ByteString.Char8 as BS
import qualified Data.ByteString.Lazy as LBS
import Data.Either (partitionEithers)
import Data.List.Extra (chunksOf)
import Formatting (build, int, sformat, shown, (%))
import System.Directory (removeFile)
import System.FilePath ((</>))
Expand Down Expand Up @@ -363,7 +364,12 @@ consolidateOneEpoch ccp epochSlots = do

-- After the check point is written, delete old blunds for the epoch we have just
-- consolidated.
lift $ mapM_ deleteOldBlund sihs
lift $ mapM_ deleter $ chunksOf 1000 sihs
where
deleter :: ConsolidateM ctx m => [SlotIndexHash] -> m ()
deleter xs = do
mapM_ deleteOldBlund xs
sleepSeconds 2

deleteOldBlund :: ConsolidateM ctx m => SlotIndexHash -> m ()
deleteOldBlund (SlotIndexHash _ hh) = do
Expand All @@ -389,16 +395,18 @@ consolidateEpochBlocks fpath xs = ExceptT $ do
(liftIO . hClose)
(\hdl -> do
liftIO $ BS.hPutStr hdl epochFileHeader
mapM (consolidate hdl) xs
mapM (consolidate hdl) $ zip [0 .. ] xs
)
pure $ case partitionEithers ys of
([], zs) -> Right $ epochIndexToOffset zs
(e:_, _) -> Left e
where
consolidate
:: ConsolidateM ctx m
=> Handle -> SlotIndexHash -> m (Either ConsolidateError SlotIndexLength)
consolidate hdl (SlotIndexHash lsi hh) = do
=> Handle -> (Int, SlotIndexHash) -> m (Either ConsolidateError SlotIndexLength)
consolidate hdl (indx, SlotIndexHash lsi hh) = do
when (indx `mod` 1000 == 0) $
sleepSeconds 2
mblund <- getSerializedBlund hh
case mblund of
Nothing ->
Expand Down
10 changes: 10 additions & 0 deletions db/src/Pos/DB/Rocks/Functions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import qualified Database.RocksDB as Rocks
import System.Directory (createDirectoryIfMissing, doesDirectoryExist,
removeDirectoryRecursive)
import System.FilePath (takeDirectory, (</>))
import qualified System.Info (os)

import Pos.Binary.Class (Bi, serialize')
import Pos.DB.BatchOp (rocksWriteBatch)
Expand Down Expand Up @@ -82,6 +83,7 @@ openNodeDBs recreate fp = do
let gStatePath = fp </> "gState"
let lrcPath = fp </> "lrc"
let miscPath = fp </> "misc"

mapM_ ensureDirectoryExists
[ blocksDir
, _blockDataDir
Expand All @@ -91,6 +93,11 @@ openNodeDBs recreate fp = do
, lrcPath
, miscPath
]

when (System.Info.os == "darwin") $
-- Prevent indexing of blocks on OSX
ensureEmptyFileExists (fp </> ".metadata_never_index")

_blockIndexDB <- openRocksDB blocksIndexPath
_gStateDB <- openRocksDB gStatePath
_lrcDB <- openRocksDB lrcPath
Expand All @@ -101,6 +108,9 @@ openNodeDBs recreate fp = do
ensureDirectoryExists :: MonadIO m => FilePath -> m ()
ensureDirectoryExists = liftIO . createDirectoryIfMissing True

ensureEmptyFileExists :: MonadIO m => FilePath -> m ()
ensureEmptyFileExists file = liftIO $ withFile file AppendMode (\_ -> return ())

-- | Safely close all databases from 'NodeDBs'.
closeNodeDBs :: MonadIO m => NodeDBs -> m ()
closeNodeDBs NodeDBs {..} =
Expand Down
2 changes: 2 additions & 0 deletions pkgs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16188,6 +16188,7 @@ license = stdenv.lib.licenses.mit;
, ekg-core
, ether
, exceptions
, extra
, filepath
, formatting
, hedgehog
Expand Down Expand Up @@ -16241,6 +16242,7 @@ directory
ekg-core
ether
exceptions
extra
filepath
formatting
lens
Expand Down

0 comments on commit f6b209b

Please sign in to comment.