Skip to content

Commit

Permalink
Merge #1871
Browse files Browse the repository at this point in the history
1871: Don't wait forever in TokNext TokMustReply r=dcoutts a=karknu

In the (TokNext TokMustReply) state the responder has indicated that it
currently doesn't have a new tip for us and we should wait.
This patch limits the time we wait to 70s which means that we don't end
up waiting forever incase of network problems.

Co-authored-by: Karl Knutsson <[email protected]>
  • Loading branch information
iohk-bors[bot] and karknu authored Mar 31, 2020
2 parents 9e9de91 + 3786275 commit 821ef36
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,7 @@ runThreadNetwork ThreadNetworkArgs
-- node
nullDebugProtocolTracers
(customProtocolCodecs pInfoConfig)
Nothing
(protocolHandlers nodeArgs nodeKernel)

-- In practice, a robust wallet/user can persistently add a transaction
Expand Down
2 changes: 2 additions & 0 deletions ouroboros-consensus/src/Ouroboros/Consensus/Node.hs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ run tracers protocolTracers chainDbTracer diffusionTracers diffusionArguments
nodeKernel
protocolTracers
(protocolCodecs (getTopLevelConfig nodeKernel) version)
(Just 70) -- timeout after waiting this long for the next header
-- 70s allows for 3 slots (3 * 20s)
(protocolHandlers nodeArgs nodeKernel)

mkDiffusionApplications
Expand Down
7 changes: 4 additions & 3 deletions ouroboros-consensus/src/Ouroboros/Consensus/NodeNetwork.hs
Original file line number Diff line number Diff line change
Expand Up @@ -497,9 +497,10 @@ consensusNetworkApps
=> NodeKernel m peer blk
-> ProtocolTracers m peer localPeer blk failure
-> ProtocolCodecs blk failure m bytesCS bytesCS bytesBF bytesBF bytesTX bytesLCS bytesLTX bytesLSQ
-> Maybe DiffTime -- Workaround for #1882, test cases that can't cope with timeouts
-> ProtocolHandlers m peer blk
-> NetworkApplication m peer localPeer bytesCS bytesBF bytesTX bytesLCS bytesLTX bytesLSQ ()
consensusNetworkApps kernel ProtocolTracers {..} ProtocolCodecs {..} ProtocolHandlers {..} =
consensusNetworkApps kernel ProtocolTracers {..} ProtocolCodecs {..} chainSyncTimeout ProtocolHandlers {..} =
NetworkApplication {
naChainSyncClient,
naChainSyncServer,
Expand Down Expand Up @@ -534,7 +535,7 @@ consensusNetworkApps kernel ProtocolTracers {..} ProtocolCodecs {..} ProtocolHan
(contramap (TraceLabelPeer them) ptChainSyncTracer)
pcChainSyncCodec
(byteLimitsChainSync (const 0)) -- TODO: Real Bytelimits, see #1727
timeLimitsChainSync
(timeLimitsChainSync chainSyncTimeout)
channel
$ chainSyncClientPeerPipelined
$ phChainSyncClient varCandidate
Expand All @@ -548,7 +549,7 @@ consensusNetworkApps kernel ProtocolTracers {..} ProtocolCodecs {..} ProtocolHan
(contramap (TraceLabelPeer them) ptChainSyncSerialisedTracer)
pcChainSyncCodecSerialised
(byteLimitsChainSync (const 0)) -- TODO: Real Bytelimits, see #1727
timeLimitsChainSync
(timeLimitsChainSync chainSyncTimeout)
channel
$ chainSyncServerPeer
$ phChainSyncServer registry
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ byteLimitsChainSync = ProtocolSizeLimits stateToLimit
--
-- `TokIdle` No timeout
-- `TokNext TokCanAwait` `longWait` timeout
-- `TokNext TokMustReply` No timeout
-- `TokIntersect` `longWait timeout
timeLimitsChainSync :: ProtocolTimeLimits (ChainSync header tip)
timeLimitsChainSync = ProtocolTimeLimits stateToLimit
-- `TokNext TokMustReply` consensusTimeout timeout
-- `TokIntersect` `longWait` timeout
timeLimitsChainSync :: Maybe DiffTime -> ProtocolTimeLimits (ChainSync header tip)
timeLimitsChainSync consensusTimeout = ProtocolTimeLimits stateToLimit
where
stateToLimit :: forall (pr :: PeerRole) (st :: ChainSync header tip).
PeerHasAgency pr st -> Maybe DiffTime
stateToLimit (ClientAgency TokIdle) = waitForever
stateToLimit (ServerAgency (TokNext TokCanAwait)) = shortWait
stateToLimit (ServerAgency (TokNext TokMustReply)) = waitForever
stateToLimit (ServerAgency (TokNext TokMustReply)) = consensusTimeout
stateToLimit (ServerAgency TokIntersect) = shortWait

-- | The main CBOR 'Codec' for the 'ChainSync' protocol.
Expand Down

0 comments on commit 821ef36

Please sign in to comment.