Skip to content

Commit 2524c4d

Browse files
committed
Run Fourmolu
1 parent fbab925 commit 2524c4d

File tree

4 files changed

+91
-77
lines changed
  • ouroboros-consensus-diffusion/src/ouroboros-consensus-diffusion/Ouroboros/Consensus/Node
  • ouroboros-consensus
    • src/ouroboros-consensus/Ouroboros/Consensus/MiniProtocol/ObjectDiffusion
    • test/consensus-test/Test/Consensus/MiniProtocol/ObjectDiffusion

4 files changed

+91
-77
lines changed

ouroboros-consensus-diffusion/src/ouroboros-consensus-diffusion/Ouroboros/Consensus/Node/Tracers.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,10 @@ data Tracers' remotePeer localPeer blk f = Tracers
8888
, csjTracer ::
8989
f (TraceLabelPeer remotePeer (CSJumping.TraceEventCsj remotePeer blk))
9090
, dbfTracer :: f (CSJumping.TraceEventDbf remotePeer)
91-
, perasCertDiffusionInboundTracer :: f (TraceLabelPeer remotePeer (TracePerasCertDiffusionInbound blk))
92-
, perasCertDiffusionOutboundTracer :: f (TraceLabelPeer remotePeer (TracePerasCertDiffusionOutbound blk))
91+
, perasCertDiffusionInboundTracer ::
92+
f (TraceLabelPeer remotePeer (TracePerasCertDiffusionInbound blk))
93+
, perasCertDiffusionOutboundTracer ::
94+
f (TraceLabelPeer remotePeer (TracePerasCertDiffusionOutbound blk))
9395
}
9496

9597
instance

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/MiniProtocol/ObjectDiffusion/Inbound.hs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{-# LANGUAGE BangPatterns #-}
22
{-# LANGUAGE CPP #-}
33
{-# LANGUAGE DataKinds #-}
4+
{-# LANGUAGE DeriveAnyClass #-}
45
{-# LANGUAGE DeriveGeneric #-}
6+
{-# LANGUAGE DerivingStrategies #-}
57
{-# LANGUAGE GADTs #-}
68
{-# LANGUAGE ImportQualifiedPost #-}
79
{-# LANGUAGE KindSignatures #-}
810
{-# LANGUAGE RecordWildCards #-}
911
{-# LANGUAGE ScopedTypeVariables #-}
1012
{-# OPTIONS_GHC -Wno-partial-fields #-}
11-
{-# LANGUAGE DerivingStrategies #-}
12-
{-# LANGUAGE DeriveAnyClass #-}
1313

1414
module Ouroboros.Consensus.MiniProtocol.ObjectDiffusion.Inbound
1515
( objectDiffusionInbound
@@ -34,21 +34,21 @@ import Data.Sequence.Strict (StrictSeq)
3434
import Data.Sequence.Strict qualified as Seq
3535
import Data.Set (Set)
3636
import Data.Set qualified as Set
37+
import Data.Word (Word64)
3738
import GHC.Generics (Generic)
3839
import Network.TypedProtocol.Core (N (Z), Nat (..), natToInt)
3940
import NoThunks.Class (NoThunks (..), unsafeNoThunks)
4041
import Ouroboros.Consensus.MiniProtocol.ObjectDiffusion.ObjectPool.API
4142
import Ouroboros.Network.NodeToNode.Version (NodeToNodeVersion)
4243
import Ouroboros.Network.Protocol.ObjectDiffusion.Inbound
4344
import Ouroboros.Network.Protocol.ObjectDiffusion.Type
44-
import Data.Word (Word64)
4545

4646
-- Note: This module is inspired from TxSubmission inbound side.
4747

4848
newtype NumObjectsProcessed
4949
= NumObjectsProcessed
50-
{ getNumObjectsProcessed :: Word64
51-
}
50+
{ getNumObjectsProcessed :: Word64
51+
}
5252
deriving (Eq, Show)
5353

5454
data TraceObjectDiffusionInbound objectId object
@@ -243,15 +243,15 @@ objectDiffusionInbound tracer (maxFifoLength, maxNumIdsToReq, maxNumObjectsToReq
243243
else do
244244
traceWith tracer (TraceObjectInboundCannotRequestMoreObjects (natToInt n))
245245
-- In this case we can theoretically only collect replies or request
246-
-- new object IDs.
246+
-- new object IDs.
247247
--
248248
-- But it's important not to pipeline more requests for objectIds now
249249
-- because if we did, then immediately after sending the request (but
250250
-- having not yet received a response to either this or the other
251-
-- pipelined requests), we would directly re-enter this code path,
251+
-- pipelined requests), we would directly re-enter this code path,
252252
-- resulting us in filling the pipeline with an unbounded number of
253253
-- requests.
254-
--
254+
--
255255
-- So we instead block until we collect a reply.
256256
pure $
257257
CollectPipelined

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/MiniProtocol/ObjectDiffusion/PerasCert.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
-- | This module defines type aliases for the ObjectDiffusion protocol applied
22
-- to PerasCert diffusion.
3-
--
43
module Ouroboros.Consensus.MiniProtocol.ObjectDiffusion.PerasCert
54
( TracePerasCertDiffusionInbound
65
, TracePerasCertDiffusionOutbound

ouroboros-consensus/test/consensus-test/Test/Consensus/MiniProtocol/ObjectDiffusion/Smoke.hs

Lines changed: 79 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{-# LANGUAGE DerivingVia #-}
22
{-# LANGUAGE FlexibleContexts #-}
3+
{-# LANGUAGE FlexibleInstances #-}
34
{-# LANGUAGE FunctionalDependencies #-}
45
{-# LANGUAGE GADTs #-}
56
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
67
{-# LANGUAGE KindSignatures #-}
78
{-# LANGUAGE RankNTypes #-}
89
{-# LANGUAGE ScopedTypeVariables #-}
9-
{-# LANGUAGE FlexibleInstances #-}
1010

1111
-- | Smoke tests for the object diffusion protocol. This uses a trivial object
1212
-- pool and checks that a few objects can indeed be transferred from the
@@ -22,8 +22,8 @@ module Test.Consensus.MiniProtocol.ObjectDiffusion.Smoke
2222
import Control.Monad.IOSim (runSimStrictShutdown)
2323
import Control.ResourceRegistry (forkLinkedThread, waitAnyThread, withRegistry)
2424
import Control.Tracer (Tracer, nullTracer, traceWith)
25-
import Data.Functor.Contravariant (contramap)
2625
import Data.Containers.ListUtils (nubOrdOn)
26+
import Data.Functor.Contravariant (contramap)
2727
import Network.TypedProtocol.Channel (Channel, createConnectedChannels)
2828
import Network.TypedProtocol.Codec (AnyMessage)
2929
import Network.TypedProtocol.Driver.Simple (runPeer, runPipelinedPeer)
@@ -168,9 +168,9 @@ mkMockPoolInterfaces objects = do
168168

169169
newtype ProtocolConstants
170170
= ProtocolConstants (NumObjectsOutstanding, NumObjectIdsReq, NumObjectsReq)
171-
deriving (Show)
171+
deriving Show
172172

173-
instance Arbitrary ProtocolConstants
173+
instance Arbitrary ProtocolConstants where
174174
-- REVIEW: not sure about those constraints at all, and don't have the
175175
-- brainspace right now to reason about them
176176
arbitrary = do
@@ -179,17 +179,22 @@ instance Arbitrary ProtocolConstants
179179
maxObjectsToReq <- choose (2, maxIdsToReq)
180180
pure $
181181
ProtocolConstants
182-
( NumObjectsOutstanding maxFifoSize,
183-
NumObjectIdsReq maxIdsToReq,
184-
NumObjectsReq maxObjectsToReq
182+
( NumObjectsOutstanding maxFifoSize
183+
, NumObjectIdsReq maxIdsToReq
184+
, NumObjectsReq maxObjectsToReq
185185
)
186186

187187
nodeToNodeVersion :: NodeToNodeVersion
188188
nodeToNodeVersion = NodeToNodeV_14
189189

190190
prop_smoke_init_inbound :: ProtocolConstants -> ListWithUniqueIds SmokeObject idTy -> Property
191191
prop_smoke_init_inbound protocolConstants (ListWithUniqueIds objects) =
192-
prop_smoke_object_diffusion protocolConstants objects runOutboundPeer runInboundPeer (mkMockPoolInterfaces objects)
192+
prop_smoke_object_diffusion
193+
protocolConstants
194+
objects
195+
runOutboundPeer
196+
runInboundPeer
197+
(mkMockPoolInterfaces objects)
193198
where
194199
runOutboundPeer outbound outboundChannel tracer =
195200
runPeer
@@ -207,9 +212,15 @@ prop_smoke_init_inbound protocolConstants (ListWithUniqueIds objects) =
207212
(objectDiffusionInboundClientPeerPipelined inbound)
208213
>> pure ()
209214

210-
prop_smoke_init_outbound :: ProtocolConstants -> ListWithUniqueIds SmokeObject SmokeObjectId -> Property
215+
prop_smoke_init_outbound ::
216+
ProtocolConstants -> ListWithUniqueIds SmokeObject SmokeObjectId -> Property
211217
prop_smoke_init_outbound protocolConstants (ListWithUniqueIds objects) =
212-
prop_smoke_object_diffusion protocolConstants objects runOutboundPeer runInboundPeer (mkMockPoolInterfaces objects)
218+
prop_smoke_object_diffusion
219+
protocolConstants
220+
objects
221+
runOutboundPeer
222+
runInboundPeer
223+
(mkMockPoolInterfaces objects)
213224
where
214225
runOutboundPeer outbound outboundChannel tracer =
215226
runPeer
@@ -264,59 +275,61 @@ prop_smoke_object_diffusion ::
264275
Property
265276
prop_smoke_object_diffusion
266277
(ProtocolConstants (maxFifoSize, maxIdsToReq, maxObjectsToReq))
267-
objects runOutboundPeer runInboundPeer mkPoolInterfaces
268-
=
269-
let
270-
simulationResult = runSimStrictShutdown $ do
271-
let tracer = nullTracer
272-
273-
traceWith tracer "========== [ Starting ObjectDiffusion smoke test ] =========="
274-
traceWith tracer (show objects)
275-
276-
(outboundPoolReader, inboundPoolWriter, getAllInboundPoolContent) <- mkPoolInterfaces
277-
controlMessage <- uncheckedNewTVarM Continue
278-
279-
let
280-
inbound =
281-
objectDiffusionInbound
282-
tracer
283-
( maxFifoSize
284-
, maxIdsToReq
285-
, maxObjectsToReq
286-
)
287-
inboundPoolWriter
288-
nodeToNodeVersion
289-
290-
outbound =
291-
objectDiffusionOutbound
292-
tracer
293-
maxFifoSize
294-
outboundPoolReader
295-
nodeToNodeVersion
296-
(readTVar controlMessage)
297-
298-
withRegistry $ \reg -> do
299-
(outboundChannel, inboundChannel) <- createConnectedChannels
300-
outboundThread <-
301-
forkLinkedThread reg "ObjectDiffusion Outbound peer thread" $
302-
runOutboundPeer outbound outboundChannel tracer
303-
inboundThread <-
304-
forkLinkedThread reg "ObjectDiffusion Inbound peer thread" $
305-
runInboundPeer inbound inboundChannel tracer
306-
controlMessageThread <- forkLinkedThread reg "ObjectDiffusion Control thread" $ do
307-
threadDelay 1000 -- give a head start to the other threads
308-
atomically $ writeTVar controlMessage Terminate
309-
threadDelay 1000 -- wait for the other threads to finish
310-
waitAnyThread [outboundThread, inboundThread, controlMessageThread]
311-
312-
traceWith tracer "========== [ ObjectDiffusion smoke test finished ] =========="
313-
poolContent <- getAllInboundPoolContent
314-
315-
traceWith tracer "inboundPoolContent:"
316-
traceWith tracer (show poolContent)
317-
traceWith tracer "========== ======================================= =========="
318-
pure poolContent
319-
in
320-
case simulationResult of
321-
Right inboundPoolContent -> inboundPoolContent === objects
322-
Left msg -> counterexample (show msg) $ property False
278+
objects
279+
runOutboundPeer
280+
runInboundPeer
281+
mkPoolInterfaces =
282+
let
283+
simulationResult = runSimStrictShutdown $ do
284+
let tracer = nullTracer
285+
286+
traceWith tracer "========== [ Starting ObjectDiffusion smoke test ] =========="
287+
traceWith tracer (show objects)
288+
289+
(outboundPoolReader, inboundPoolWriter, getAllInboundPoolContent) <- mkPoolInterfaces
290+
controlMessage <- uncheckedNewTVarM Continue
291+
292+
let
293+
inbound =
294+
objectDiffusionInbound
295+
tracer
296+
( maxFifoSize
297+
, maxIdsToReq
298+
, maxObjectsToReq
299+
)
300+
inboundPoolWriter
301+
nodeToNodeVersion
302+
303+
outbound =
304+
objectDiffusionOutbound
305+
tracer
306+
maxFifoSize
307+
outboundPoolReader
308+
nodeToNodeVersion
309+
(readTVar controlMessage)
310+
311+
withRegistry $ \reg -> do
312+
(outboundChannel, inboundChannel) <- createConnectedChannels
313+
outboundThread <-
314+
forkLinkedThread reg "ObjectDiffusion Outbound peer thread" $
315+
runOutboundPeer outbound outboundChannel tracer
316+
inboundThread <-
317+
forkLinkedThread reg "ObjectDiffusion Inbound peer thread" $
318+
runInboundPeer inbound inboundChannel tracer
319+
controlMessageThread <- forkLinkedThread reg "ObjectDiffusion Control thread" $ do
320+
threadDelay 1000 -- give a head start to the other threads
321+
atomically $ writeTVar controlMessage Terminate
322+
threadDelay 1000 -- wait for the other threads to finish
323+
waitAnyThread [outboundThread, inboundThread, controlMessageThread]
324+
325+
traceWith tracer "========== [ ObjectDiffusion smoke test finished ] =========="
326+
poolContent <- getAllInboundPoolContent
327+
328+
traceWith tracer "inboundPoolContent:"
329+
traceWith tracer (show poolContent)
330+
traceWith tracer "========== ======================================= =========="
331+
pure poolContent
332+
in
333+
case simulationResult of
334+
Right inboundPoolContent -> inboundPoolContent === objects
335+
Left msg -> counterexample (show msg) $ property False

0 commit comments

Comments
 (0)