From bfa1b7c2c0eaf58171afb99b3a282bbd0b6d05e0 Mon Sep 17 00:00:00 2001 From: Karl Knutsson Date: Tue, 18 Sep 2018 18:07:02 +0200 Subject: [PATCH 1/2] CO-363 Exit recovery mode when streaming Exit recovery mode when streaming is supported. The most difficult block received is tracked and use it to decide if we should exit recovery mode similar to they way batch mode leaves recovery. --- lib/src/Pos/Network/Block/Retrieval.hs | 35 ++++++++++++++++++++------ 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/lib/src/Pos/Network/Block/Retrieval.hs b/lib/src/Pos/Network/Block/Retrieval.hs index 3eab7760a6a..7899ca0f6ef 100644 --- a/lib/src/Pos/Network/Block/Retrieval.hs +++ b/lib/src/Pos/Network/Block/Retrieval.hs @@ -9,8 +9,8 @@ module Pos.Network.Block.Retrieval import Universum -import Control.Concurrent.STM (putTMVar, swapTMVar, tryReadTBQueue, - tryReadTMVar, tryTakeTMVar) +import Control.Concurrent.STM (TVar, newTVar, putTMVar, swapTMVar, + swapTVar, tryReadTBQueue, tryReadTMVar, tryTakeTMVar) import Control.Exception.Safe (handleAny) import Control.Lens (to) import Control.Monad.STM (retry) @@ -341,16 +341,37 @@ streamProcessBlocks -> m () streamProcessBlocks genesisConfig txpConfig diffusion nodeId desired checkpoints = do logInfo "streaming start" - r <- Diffusion.streamBlocks diffusion nodeId desired checkpoints writeCallback + mostDifficultBlock <- atomically $ newTVar Nothing + r <- Diffusion.streamBlocks diffusion nodeId desired checkpoints (writeCallback mostDifficultBlock) case r of Nothing -> do logInfo "streaming not supported, reverting to batch mode" getProcessBlocks genesisConfig txpConfig diffusion nodeId desired checkpoints Just _ -> do logInfo "streaming done" - return () + + recHeaderVar <- view (lensOf @RecoveryHeaderTag) + exitedRecovery <- atomically $ do + mbMostDifficult <- readTVar mostDifficultBlock + mbRecHeader <- tryReadTMVar recHeaderVar + case (mbMostDifficult, mbRecHeader) of + (Nothing, _) -> pure False -- We have not gotten a single block + (Just _, Nothing) -> pure False -- We where not in recovery? + (Just mostDifficult, Just (_, recHeader)) -> + if (mostDifficult ^. difficultyL) >= (recHeader ^. difficultyL) + then isJust <$> tryTakeTMVar recHeaderVar + else pure False + + if exitedRecovery + then do + logInfo "Recovery mode exited gracefully on receiving block we needed" + return () + else do -- Streaming stopped but we didn't make any progress + _ <- dropRecoveryHeaderAndRepeat genesisConfig diffusion nodeId + return () where - writeCallback :: [Block] -> m () - writeCallback [] = return () - writeCallback (block:blocks) = + writeCallback :: (TVar (Maybe Block)) -> [Block] -> m () + writeCallback _ [] = return () + writeCallback mostDifficultBlock (block:blocks) = do + _ <- atomically $ swapTVar mostDifficultBlock (Just block) handleBlocks genesisConfig txpConfig (OldestFirst (NE.reverse $ block :| blocks)) diffusion From 74de41d0817138a45d745da3d266f8f140ef9fc7 Mon Sep 17 00:00:00 2001 From: Karl Knutsson Date: Mon, 24 Sep 2018 16:38:48 +0200 Subject: [PATCH 2/2] WIP: acceptance workarounds Don't merge! --- scripts/launch/connect-to-cluster/default.nix | 6 +++--- scripts/test/acceptance/default.nix | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/launch/connect-to-cluster/default.nix b/scripts/launch/connect-to-cluster/default.nix index e2cdd2564a9..bed58254d68 100755 --- a/scripts/launch/connect-to-cluster/default.nix +++ b/scripts/launch/connect-to-cluster/default.nix @@ -7,9 +7,9 @@ , system ? builtins.currentSystem , pkgs ? import localLib.fetchNixPkgs { inherit system config; } , gitrev ? localLib.commitIdFromGitRepo ./../../../.git -, walletListen ? "127.0.0.1:8090" -, walletDocListen ? "127.0.0.1:8091" -, ekgListen ? "127.0.0.1:8000" +, walletListen ? "localhost:8090" +, walletDocListen ? "localhost:8091" +, ekgListen ? "localhost:8000" , ghcRuntimeArgs ? "-N2 -qg -A1m -I0 -T" , additionalNodeArgs ? "" , confFile ? null diff --git a/scripts/test/acceptance/default.nix b/scripts/test/acceptance/default.nix index 10e6a1fcdd7..f1aee81b63a 100644 --- a/scripts/test/acceptance/default.nix +++ b/scripts/test/acceptance/default.nix @@ -46,7 +46,7 @@ in ${utf8LocaleSetting} echo Launching wallet node: ${wallet} - ${wallet} &> ${stateDir}/logs/wallet.log & + ${wallet} --runtime-args " --legacy-wallet +RTS -M6G" &> ${stateDir}/logs/wallet.log & wallet_pid=$! start_time=$(date +%s)