Skip to content

Commit

Permalink
Make sure we allways have a PeerGSV
Browse files Browse the repository at this point in the history
Even without support for the keep alive protocol blockfetch still
requires a corresponding PeerGSV per active peer.
  • Loading branch information
karknu committed Jul 7, 2020
1 parent e6ddc41 commit a5f12f8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
28 changes: 19 additions & 9 deletions ouroboros-consensus/src/Ouroboros/Consensus/Network/NodeToNode.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ module Ouroboros.Consensus.Network.NodeToNode (
import Codec.CBOR.Decoding (Decoder)
import Codec.CBOR.Encoding (Encoding)
import Codec.Serialise (Serialise)
import Control.Monad (forever)
import Control.Monad.Class.MonadTimer (MonadTimer)
import Control.Tracer
import Data.ByteString.Lazy (ByteString)
Expand Down Expand Up @@ -392,6 +393,7 @@ mkApps
, Ord remotePeer
, Exception e
, LedgerSupportsProtocol blk
, TranslateNetworkProtocolVersion blk
)
=> NodeKernel m remotePeer localPeer blk -- ^ Needed for bracketing only
-> Tracers m remotePeer blk e
Expand Down Expand Up @@ -522,15 +524,23 @@ mkApps kernel Tracers {..} Codecs {..} genChainSyncTimeout Handlers {..} =
aKeepAliveClient version them channel = do
labelThisThread "KeepAliveClient"
startTs <- newTVarM Nothing
bracketKeepAliveClient (getFetchClientRegistry kernel) them $ \dqCtx -> do
runPeerWithLimits
nullTracer
cKeepAliveCodec
(byteLimitsKeepAlive (const 0)) -- TODO: Real Bytelimits, see #1727
timeLimitsKeepAlive
channel
$ keepAliveClientPeer
$ hKeepAliveClient version them dqCtx (KeepAliveInterval 10) startTs
let version' = nodeToNodeProtocolVersion (Proxy @blk) version
kacApp = case version' of
-- Version 1 and 2 doesn't support keep alive protocol but Blockfetch
-- still requires a PeerGSV per peer.
NodeToNodeV_1 -> \_ -> forever (threadDelay 1000) >> return ()
NodeToNodeV_2 -> \_ -> forever (threadDelay 1000) >> return ()
_ -> \dqCtx -> do
runPeerWithLimits
nullTracer
cKeepAliveCodec
(byteLimitsKeepAlive (const 0)) -- TODO: Real Bytelimits, see #1727
timeLimitsKeepAlive
channel
$ keepAliveClientPeer
$ hKeepAliveClient version them dqCtx (KeepAliveInterval 10) startTs

bracketKeepAliveClient (getFetchClientRegistry kernel) them kacApp

aKeepAliveServer
:: BlockNodeToNodeVersion blk
Expand Down
9 changes: 2 additions & 7 deletions ouroboros-network/src/Ouroboros/Network/NodeToNode.hs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ nodeToNodeProtocols MiniProtocolParameters {
blockFetchPipeliningMax,
txSubmissionMaxUnacked
}
protocols version =
protocols _version =
OuroborosApplication $ \connectionId shouldStopSTM ->
case protocols connectionId shouldStopSTM of
NodeToNodeProtocols {
Expand All @@ -238,12 +238,7 @@ nodeToNodeProtocols MiniProtocolParameters {
[ chainSyncMiniProtocol chainSyncProtocol
, blockFetchMiniProtocol blockFetchProtocol
, txSubmissionMiniProtocol txSubmissionProtocol
] <>
[ keepAliveMiniProtocol keepAliveProtocol
| case version of
NodeToNodeV_1 -> False
NodeToNodeV_2 -> False
_ -> True
, keepAliveMiniProtocol keepAliveProtocol
]
where
chainSyncMiniProtocol chainSyncProtocol = MiniProtocol {
Expand Down

0 comments on commit a5f12f8

Please sign in to comment.