Skip to content

Commit

Permalink
Allways close chainsync servers reader state
Browse files Browse the repository at this point in the history
  • Loading branch information
karknu committed Jan 18, 2021
1 parent ca53ae7 commit 9cc87ef
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 16 deletions.
Expand Up @@ -7,6 +7,7 @@
module Ouroboros.Consensus.MiniProtocol.ChainSync.Server
( chainSyncHeadersServer
, chainSyncBlocksServer
, chainSyncHeaderServerReader
, Tip
-- * Trace events
, TraceChainSyncServerEvent (..)
Expand All @@ -29,6 +30,14 @@ import Ouroboros.Consensus.Node.NetworkProtocolVersion
import Ouroboros.Consensus.Util.IOLike
import Ouroboros.Consensus.Util.ResourceRegistry (ResourceRegistry)


chainSyncHeaderServerReader
:: ChainDB m blk
-> ResourceRegistry m
-> m (Reader m blk (WithPoint blk (SerialisedHeader blk)))
chainSyncHeaderServerReader chainDB registry = ChainDB.newReader chainDB registry getSerialisedHeaderWithPoint


-- | Chain Sync Server for block headers for a given a 'ChainDB'.
--
-- The node-to-node protocol uses the chain sync mini-protocol with chain
Expand All @@ -41,13 +50,12 @@ chainSyncHeadersServer
)
=> Tracer m (TraceChainSyncServerEvent blk)
-> ChainDB m blk
-> Reader m blk (WithPoint blk (SerialisedHeader blk))
-> NodeToNodeVersion
-> ResourceRegistry m
-> ChainSyncServer (SerialisedHeader blk) (Point blk) (Tip blk) m ()
chainSyncHeadersServer tracer chainDB _version registry =
ChainSyncServer $ do
rdr <- ChainDB.newReader chainDB registry getSerialisedHeaderWithPoint
let ChainSyncServer server = chainSyncServerForReader tracer chainDB rdr
chainSyncHeadersServer tracer chainDB rdr _version =
ChainSyncServer $
let ChainSyncServer server = chainSyncServerForReader tracer chainDB rdr in
server

-- | Chain Sync Server for blocks for a given a 'ChainDB'.
Expand Down Expand Up @@ -92,7 +100,7 @@ chainSyncServerForReader tracer chainDB rdr =
idle = ServerStIdle {
recvMsgRequestNext = handleRequestNext,
recvMsgFindIntersect = handleFindIntersect,
recvMsgDoneClient = ChainDB.readerClose rdr
recvMsgDoneClient = pure ()
}

idle' :: ChainSyncServer b (Point blk) (Tip blk) m ()
Expand Down
25 changes: 15 additions & 10 deletions ouroboros-consensus/src/Ouroboros/Consensus/Network/NodeToNode.hs
Expand Up @@ -88,6 +88,7 @@ import Ouroboros.Consensus.Node.Run
import Ouroboros.Consensus.Node.Serialisation
import qualified Ouroboros.Consensus.Node.Tracers as Node
import Ouroboros.Consensus.NodeKernel
import qualified Ouroboros.Consensus.Storage.ChainDB.API as ChainDB
import Ouroboros.Consensus.Util (ShowProxy)
import Ouroboros.Consensus.Util.IOLike
import Ouroboros.Consensus.Util.Orphans ()
Expand All @@ -112,8 +113,8 @@ data Handlers m peer blk = Handlers {
-- closure include these and not need to be explicit about them here.

, hChainSyncServer
:: NodeToNodeVersion
-> ResourceRegistry m
:: ChainDB.Reader m blk (ChainDB.WithPoint blk (SerialisedHeader blk))
-> NodeToNodeVersion
-> ChainSyncServer (SerialisedHeader blk) (Point blk) (Tip blk) m ()

-- TODO block fetch client does not have GADT view of the handlers.
Expand Down Expand Up @@ -488,14 +489,18 @@ mkApps kernel Tracers {..} Codecs {..} genChainSyncTimeout Handlers {..} =
labelThisThread "ChainSyncServer"
withRegistry $ \registry -> do
chainSyncTimeout <- genChainSyncTimeout
runPeerWithLimits
(contramap (TraceLabelPeer them) tChainSyncSerialisedTracer)
cChainSyncCodecSerialised
(byteLimitsChainSync (const 0)) -- TODO: Real Bytelimits, see #1727
(timeLimitsChainSync chainSyncTimeout)
channel
$ chainSyncServerPeer
$ hChainSyncServer version registry
bracket
(chainSyncHeaderServerReader (getChainDB kernel) registry)
ChainDB.readerClose
(\rdr -> runPeerWithLimits
(contramap (TraceLabelPeer them) tChainSyncSerialisedTracer)
cChainSyncCodecSerialised
(byteLimitsChainSync (const 0)) -- TODO: Real Bytelimits, see #1727
(timeLimitsChainSync chainSyncTimeout)
channel
$ chainSyncServerPeer
$ hChainSyncServer rdr version
)

aBlockFetchClient
:: NodeToNodeVersion
Expand Down

0 comments on commit 9cc87ef

Please sign in to comment.