Skip to content

Commit 8b64183

Browse files
committed
pass resources through
1 parent 12e0592 commit 8b64183

File tree

3 files changed

+39
-20
lines changed

3 files changed

+39
-20
lines changed

ouroboros-consensus-diffusion/app/conformance-test-runner/Main.hs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
module Main (main) where
22

3+
import qualified Data.Map.Merge.Lazy as M
4+
import Test.Consensus.PeerSimulator.Resources (PeerSimulatorResources(..), makePeerSimulatorResources)
5+
import Control.Tracer (nullTracer)
6+
import qualified Data.List.NonEmpty as NonEmpty
37
import Data.Aeson (encode, throwDecode)
48
import qualified Data.ByteString.Lazy.Char8 as BSL8
59
import Data.Coerce
@@ -77,29 +81,34 @@ main = do
7781
let simPeerMap = buildPeerMap (optPort opts) pointSchedule
7882
BSL8.writeFile (optOutputTopologyFile opts) (encode $ makeTopology simPeerMap)
7983

84+
zipMaps :: Ord k => Map k a -> Map k b -> Map k (a, b)
85+
zipMaps = M.merge M.dropMissing M.dropMissing $ M.zipWithMatched $ const (,)
86+
8087
runServer :: IO ()
8188
runServer = do
8289
let peerMap = buildPeerMap 6001 testPointSchedule
8390

91+
peerSim <- makePeerSimulatorResources nullTracer undefined $ NonEmpty.fromList $ M.keys peerMap
92+
8493
peerServers <-
85-
for peerMap $ \port -> do
94+
for (zipMaps peerMap $ psrPeers peerSim) $ \(port, res) -> do
8695
-- Make a TMVar for the chainsync and blockfetch channels exposed through
8796
-- the miniprotocols. These get threaded into the server, which will fill
8897
-- them once the NUT has connected.
89-
csChannelTMV <- newEmptyTMVarIO
90-
bfChannelTMV <- newEmptyTMVarIO
98+
csChannelTMV <- newTVarIO False
99+
bfChannelTMV <- newTVarIO False
91100

92101
putStrLn $ "starting server on " <> show port
93102
let sockAddr = Socket.SockAddrInet port $ Socket.tupleToHostAddress (127, 0, 0, 1)
94-
thread <- async $ run csChannelTMV bfChannelTMV sockAddr
103+
thread <- async $ run res csChannelTMV bfChannelTMV sockAddr
95104
pure ((csChannelTMV, bfChannelTMV), thread)
96105

97106
-- Now, take each of the resulting TMVars. This effectively blocks until the
98107
-- NUT has connected.
99108
_peerChannels <- atomically $ do
100109
for peerServers $ \((csChanTMV, bfChanTMV), _thread) -> do
101-
csChan <- readTMVar csChanTMV
102-
bfChan <- readTMVar bfChanTMV
110+
csChan <- readTVar csChanTMV
111+
bfChan <- readTVar bfChanTMV
103112
pure (csChan, bfChan)
104113

105114
for_ peerServers $ uninterruptibleCancel . snd

ouroboros-consensus-diffusion/app/conformance-test-runner/MiniProtocols.hs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
-- picked up by the peer simulator.
1717
module MiniProtocols (peerSimServer) where
1818

19+
import Ouroboros.Network.Protocol.BlockFetch.Server
20+
import Ouroboros.Network.Util.ShowProxy (ShowProxy)
21+
import Ouroboros.Network.Protocol.ChainSync.Server
22+
import Test.Consensus.PeerSimulator.Resources (PeerResources (..), ChainSyncResources (..), BlockFetchResources (..))
1923
import qualified Codec.CBOR.Decoding as CBOR
2024
import qualified Codec.CBOR.Encoding as CBOR
2125
import Control.Monad (forever)
@@ -59,10 +63,13 @@ peerSimServer ::
5963
( IOLike m
6064
, SerialiseNodeToNodeConstraints blk
6165
, SupportedNetworkProtocolVersion blk
66+
, ShowProxy blk
67+
, ShowProxy (Header blk)
6268
, MonadSay m
6369
) =>
64-
StrictTMVar m (Mux.Channel m BL.ByteString) ->
65-
StrictTMVar m (Mux.Channel m BL.ByteString) ->
70+
PeerResources m blk ->
71+
StrictTVar m Bool ->
72+
StrictTVar m Bool ->
6673
CodecConfig blk ->
6774
(NodeToNodeVersion -> addr -> CBOR.Encoding) ->
6875
(NodeToNodeVersion -> forall s. CBOR.Decoder s addr) ->
@@ -71,7 +78,7 @@ peerSimServer ::
7178
NodeToNodeVersion
7279
NodeToNodeVersionData
7380
(OuroborosApplicationWithMinimalCtx 'Mux.ResponderMode addr BL.ByteString m Void ())
74-
peerSimServer csChanTMV bfChanTMV codecCfg encAddr decAddr networkMagic = do
81+
peerSimServer res csChanTMV bfChanTMV codecCfg encAddr decAddr networkMagic = do
7582
forAllVersions application
7683
where
7784
forAllVersions ::
@@ -115,19 +122,19 @@ peerSimServer csChanTMV bfChanTMV codecCfg encAddr decAddr networkMagic = do
115122
$ MiniProtocolCb
116123
$ \_ctx channel -> do
117124
say "hello from cs"
118-
atomically $
119-
putTMVar csChanTMV channel
120-
pure ((), Nothing)
125+
atomically $ writeTVar csChanTMV True
126+
runPeer nullTracer cChainSyncCodec channel
127+
$ chainSyncServerPeer $ csrServer $ prChainSync res
121128
, mkMiniProtocol
122129
Mux.StartOnDemand
123130
N2N.blockFetchMiniProtocolNum
124131
N2N.blockFetchProtocolLimits
125132
$ MiniProtocolCb
126133
$ \_ctx channel -> do
127134
say "hello from bf"
128-
atomically $
129-
putTMVar bfChanTMV channel
130-
pure ((), Nothing)
135+
atomically $ writeTVar bfChanTMV True
136+
runPeer nullTracer cBlockFetchCodec channel
137+
$ blockFetchServerPeer $ bfrServer $ prBlockFetch res
131138
, mkMiniProtocol
132139
Mux.StartOnDemand
133140
N2N.txSubmissionMiniProtocolNum
@@ -138,8 +145,8 @@ peerSimServer csChanTMV bfChanTMV codecCfg encAddr decAddr networkMagic = do
138145
where
139146
Consensus.N2N.Codecs
140147
{ cKeepAliveCodec
141-
-- , cChainSyncCodecSerialised
142-
-- , cBlockFetchCodecSerialised
148+
, cChainSyncCodec
149+
, cBlockFetchCodec
143150
} =
144151
Consensus.N2N.defaultCodecs codecCfg blockVersion encAddr decAddr version
145152

ouroboros-consensus-diffusion/app/conformance-test-runner/Server.hs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
module Server (run) where
99

10+
import Test.Consensus.PeerSimulator.Resources (PeerResources)
1011
import Control.ResourceRegistry
1112
import Control.Tracer
1213
import qualified Data.ByteString.Lazy as BL
@@ -68,15 +69,17 @@ run ::
6869
, ConfigSupportsNode blk
6970
, blk ~ SimpleBlock SimpleMockCrypto SimplePraosRuleExt
7071
) =>
72+
PeerResources IO blk ->
7173
-- | A TMVar for the chainsync channel that we will fill in once the node connects.
72-
StrictTMVar IO (Mux.Channel IO BL.ByteString) ->
74+
StrictTVar IO Bool ->
7375
-- | A TMVar for the blockfetch channel that we will fill in once the node connects.
74-
StrictTMVar IO (Mux.Channel IO BL.ByteString) ->
76+
StrictTVar IO Bool ->
7577
SockAddr ->
7678
IO Void
77-
run csChanTMV bfChanTMV sockAddr = withRegistry \_registry ->
79+
run res csChanTMV bfChanTMV sockAddr = withRegistry \_registry ->
7880
serve sockAddr
7981
$ peerSimServer @_ @(SimpleBlock SimpleMockCrypto SimplePraosRuleExt)
82+
res
8083
csChanTMV
8184
bfChanTMV
8285
SimpleCodecConfig

0 commit comments

Comments
 (0)