Skip to content

Commit

Permalink
Stylish haskell
Browse files Browse the repository at this point in the history
  • Loading branch information
crocodile-dentist committed Jul 15, 2024
1 parent c81415b commit ddbd7f1
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,13 @@ import Ouroboros.Network.Block (MaxSlotNo (..), maxSlotNoFromWithOrigin,
pointSlot)
import Ouroboros.Network.BlockFetch
import Ouroboros.Network.ConnectionManager.Types (DataFlow (..))
import Ouroboros.Network.ConsensusMode
import Ouroboros.Network.Diffusion qualified as Diff
import Ouroboros.Network.Diffusion.P2P qualified as Diff.P2P
import Ouroboros.Network.ExitPolicy (RepromoteDelay (..))
import Ouroboros.Network.NodeToNode.Version (DiffusionMode (..))
import Ouroboros.Network.PeerSelection.Governor (PeerSelectionTargets (..),
PublicPeerSelectionState (..), ConsensusModePeerTargets)
import Ouroboros.Network.PeerSelection.Governor (ConsensusModePeerTargets,
PeerSelectionTargets (..), PublicPeerSelectionState (..))
import Ouroboros.Network.PeerSelection.PeerMetric
(PeerMetricsConfiguration (..), newPeerMetric)
import Ouroboros.Network.Protocol.Handshake (HandshakeArguments (..))
Expand Down Expand Up @@ -112,7 +113,6 @@ import Test.Ouroboros.Network.Diffusion.Node.NodeKernel (NodeKernel (..),
import Test.Ouroboros.Network.Diffusion.Node.NodeKernel qualified as Node
import Test.Ouroboros.Network.PeerSelection.RootPeersDNS (DNSLookupDelay,
DNSTimeout, mockDNSActions)
import Ouroboros.Network.ConsensusMode (ConsensusMode)


data Interfaces m = Interfaces
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import Data.Foldable (traverse_)
import Data.Function (on)
import Data.IP qualified as IP
import Data.List as List (foldl', groupBy, intercalate)
import Data.List.NonEmpty qualified as NonEmpty
import Data.List.Trace qualified as Trace
import Data.Map.Strict (Map)
import Data.Map.Strict qualified as Map
Expand All @@ -56,6 +57,7 @@ import System.Random (mkStdGen)
import Network.DNS qualified as DNS (defaultResolvConf)
import Network.Socket (SockAddr)

import Ouroboros.Network.ConsensusMode
import Ouroboros.Network.ExitPolicy (RepromoteDelay (..))
import Ouroboros.Network.PeerSelection.Bootstrap (UseBootstrapPeers (..),
requiresBootstrapPeers)
Expand Down Expand Up @@ -96,8 +98,6 @@ import Test.QuickCheck.Monoids
import Test.Tasty
import Test.Tasty.QuickCheck
import Text.Pretty.Simple
import Ouroboros.Network.ConsensusMode
import Data.List.NonEmpty qualified as NonEmpty

-- Exactly as named.
unfHydra :: Int
Expand Down Expand Up @@ -765,8 +765,8 @@ envEventCredits (TraceEnvSetTargets PeerSelectionTargets {
+ 10 * (targetNumberOfKnownPeers
+ targetNumberOfEstablishedPeers
+ targetNumberOfActivePeers)
-- todo: add big ledger peer terms?

-- todo: add big ledger peer terms?
envEventCredits (TraceEnvGenesisLsjAndTargets (_, targets))
= 80
+ 10 * (targetNumberOfKnownPeers
Expand Down Expand Up @@ -3749,7 +3749,7 @@ _governorFindingPublicRoots targetNumberOfRootPeers readDomains readUseBootstrap
debugStateVar,
readUseLedgerPeers = return DontUseLedgerPeers
}

publicRootPeersProvider
tracer
(curry IP.toSockAddr)
Expand Down Expand Up @@ -3910,7 +3910,7 @@ prop_issue_3515 = prop_governor_nolivelock $
( nullPeerSelectionTargets { targetNumberOfKnownPeers = 1 }, NoDelay) ]
targets'' =
[(ConsensusModePeerTargets { praosTargets, genesisSyncTargets = nullPeerSelectionTargets }, delay)
| (praosTargets, delay) <- targets']
| (praosTargets, delay) <- targets']

-- | issue #3494
--
Expand Down Expand Up @@ -4013,7 +4013,7 @@ prop_issue_3233 = prop_governor_nolivelock $
}, NoDelay)]
targets'' =
[(ConsensusModePeerTargets { praosTargets, genesisSyncTargets = nullPeerSelectionTargets }, delay)
| (praosTargets, delay) <- targets']
| (praosTargets, delay) <- targets']

-- | Verify that re-promote delay is applied with a fuzz.
--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import Ouroboros.Network.PeerSelection.Governor

import Data.Hashable
import Data.IP qualified as IP
import Ouroboros.Network.ConsensusMode
import Ouroboros.Network.PeerSelection.Bootstrap (UseBootstrapPeers (..))
import Ouroboros.Network.PeerSelection.LedgerPeers.Type (AfterSlot (..),
UseLedgerPeers (..))
Expand All @@ -37,7 +38,6 @@ import Ouroboros.Network.PeerSelection.RelayAccessPoint (DomainAccessPoint (..),
import Ouroboros.Network.Testing.Utils (ShrinkCarefully, prop_shrink_nonequal,
prop_shrink_valid)
import Test.QuickCheck
import Ouroboros.Network.ConsensusMode


--
Expand Down Expand Up @@ -74,7 +74,7 @@ instance Arbitrary ConsensusMode where
arbitrary = elements [PraosMode, GenesisMode]
shrink GenesisMode = [PraosMode]
shrink PraosMode = []

instance Arbitrary AfterSlot where
arbitrary = oneof [ pure Always
, After <$> arbitrary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,11 @@ import Ouroboros.Network.PeerSelection.State.LocalRootPeers qualified as LocalRo
import Ouroboros.Network.Testing.Data.Script (PickScript, Script (..),
ScriptDelay (..), TimedScript, arbitraryPickScript,
arbitraryScriptOf, initScript, initScript', interpretPickScript,
playTimedScript, prop_shrink_Script, singletonScript,
singletonTimedScript, stepScript, stepScriptSTM, stepScriptSTM', shrinkScriptWith)
import Ouroboros.Network.Testing.Utils
( ShrinkCarefully,
arbitrarySubset,
prop_shrink_nonequal,
prop_shrink_valid,
nightlyTest )
playTimedScript, prop_shrink_Script, shrinkScriptWith,
singletonScript, singletonTimedScript, stepScript, stepScriptSTM,
stepScriptSTM')
import Ouroboros.Network.Testing.Utils (ShrinkCarefully, arbitrarySubset,
nightlyTest, prop_shrink_nonequal, prop_shrink_valid)

import Test.Ouroboros.Network.PeerSelection.Instances
import Test.Ouroboros.Network.PeerSelection.LocalRootPeers as LocalRootPeers hiding
Expand Down Expand Up @@ -1076,14 +1073,14 @@ instance Arbitrary GovernorMockEnvironment where
(HotValency hotLocalRootsSize) = LocalRootPeers.hotTarget localRootPeers
(WarmValency warmLocalRootsSize) = LocalRootPeers.warmTarget localRootPeers
shrunkScript = shrink targetsWithDelay
checkTargets t =
checkTargets t =
targetNumberOfKnownPeers t >= publicConfiguredRootSize + warmLocalRootsSize
&& targetNumberOfEstablishedPeers t >= warmLocalRootsSize
&& targetNumberOfEstablishedPeers t <= targetNumberOfKnownPeers t
&& targetNumberOfActivePeers t >= hotLocalRootsSize
&& targetNumberOfActivePeers t <= targetNumberOfEstablishedPeers t
&& targetNumberOfRootPeers t <= targetNumberOfKnownPeers t
- warmLocalRootsSize
- warmLocalRootsSize
in
[shrunk
| shrunk@(shrunkTarget, _) <- shrunkScript,
Expand All @@ -1096,7 +1093,7 @@ instance Arbitrary GovernorMockEnvironment where
all checkTargets [praosTargets, genesisSyncTargets],
genesisBigKnown >= 10 && genesisBigEst <= genesisBigKnown && genesisBigAct <= genesisBigEst,
genesisBigEst * genesisBigAct /= 0]

shrinkLocalRootPeers a =
[ LocalRootPeers.fromGroups g
| g <- shrink (LocalRootPeers.toGroups a)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2478,7 +2478,7 @@ prop_diffusion_target_active_local_above ioSimTrace traceNumber =
$ evsList
in classifySimulatedTime lastTime
$ classifyNumberOfEvents (length evsList)
$ verify_target_active_above ev
$ verify_target_active_above ev
)
<$> events

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,17 @@ import Network.TypedProtocol.PingPong.Type qualified as PingPong
import Ouroboros.Network.ConnectionHandler (ConnectionHandlerTrace)
import Ouroboros.Network.ConnectionManager.Types (AbstractTransitionTrace,
ConnectionManagerTrace)
import Ouroboros.Network.ConsensusMode
import Ouroboros.Network.Diffusion.P2P qualified as Diff.P2P
import Ouroboros.Network.Driver.Limits (ProtocolSizeLimits (..),
ProtocolTimeLimits (..))
import Ouroboros.Network.InboundGovernor (InboundGovernorTrace,
RemoteTransitionTrace)
import Ouroboros.Network.Mux (MiniProtocolLimits (..))
import Ouroboros.Network.NodeToNode.Version (DiffusionMode (..))
import Ouroboros.Network.PeerSelection.Governor (DebugPeerSelection (..),
PeerSelectionTargets (..), TracePeerSelection, ConsensusModePeerTargets (..))
import Ouroboros.Network.PeerSelection.Governor (ConsensusModePeerTargets (..),
DebugPeerSelection (..), PeerSelectionTargets (..),
TracePeerSelection)
import Ouroboros.Network.PeerSelection.Governor qualified as PeerSelection
import Ouroboros.Network.PeerSelection.LedgerPeers (AfterSlot (..),
LedgerPeersConsensusInterface (..), LedgerStateJudgement (..),
Expand Down Expand Up @@ -396,7 +398,7 @@ genNodeArgs relays minConnected localRootPeers relay = flip suchThat hasUpstream
`suchThat` hasActive
SmallTargets genesisSyncTargets <- resize (length relays * 2) arbitrary
`suchThat` hasActive
let peerTargets = ConsensusModePeerTargets { praosTargets, genesisSyncTargets }
let peerTargets = ConsensusModePeerTargets { praosTargets, genesisSyncTargets }
dnsTimeout <- arbitrary
dnsLookupDelay <- arbitrary
chainSyncExitOnBlockNo
Expand Down Expand Up @@ -430,7 +432,7 @@ genNodeArgs relays minConnected localRootPeers relay = flip suchThat hasUpstream
fetchModeScript <- fmap (bool FetchModeBulkSync FetchModeDeadline) <$> arbitrary

naConsensusMode <- arbitrary
bootstrapPeersDomain <-
bootstrapPeersDomain <-
case naConsensusMode of
GenesisMode -> pure . singletonScript $ DontUseBootstrapPeers
PraosMode -> Script . NonEmpty.fromList <$> listOf1 arbitrary
Expand Down
40 changes: 20 additions & 20 deletions ouroboros-network/src/Ouroboros/Network/Diffusion/P2P.hs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DisambiguateRecordFields #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeOperators #-}

#if !defined(mingw32_HOST_OS)
#define POSIX
Expand Down Expand Up @@ -101,14 +101,14 @@ import Ouroboros.Network.NodeToNode (AcceptedConnectionsLimit (..),
NodeToNodeVersionData (..), RemoteAddress)
import Ouroboros.Network.NodeToNode qualified as NodeToNode
import Ouroboros.Network.PeerSelection.Bootstrap (UseBootstrapPeers)
import Ouroboros.Network.PeerSelection.Churn ( PeerChurnArgs(..) )
import Ouroboros.Network.PeerSelection.Churn (PeerChurnArgs (..))
import Ouroboros.Network.PeerSelection.Governor qualified as Governor
import Ouroboros.Network.PeerSelection.Governor.Types
(ChurnMode (ChurnModeNormal), DebugPeerSelection (..),
PeerSelectionActions, PeerSelectionCounters,
(ChurnMode (ChurnModeNormal), ConsensusModePeerTargets (..),
DebugPeerSelection (..), PeerSelectionActions, PeerSelectionCounters,
PeerSelectionInterfaces (..), PeerSelectionPolicy (..),
PeerSelectionState, TracePeerSelection (..),
emptyPeerSelectionCounters, emptyPeerSelectionState, ConsensusModePeerTargets (..))
emptyPeerSelectionCounters, emptyPeerSelectionState)
#ifdef POSIX
import Ouroboros.Network.PeerSelection.Governor.Types
(makeDebugPeerSelectionState)
Expand Down Expand Up @@ -248,17 +248,17 @@ nullTracers =
data ArgumentsExtra m = ArgumentsExtra {
-- | selection targets for the peer governor
--
daPeerTargets :: ConsensusModePeerTargets
daPeerTargets :: ConsensusModePeerTargets

, daReadLocalRootPeers :: STM m (LocalRootPeers.Config RelayAccessPoint)
, daReadPublicRootPeers :: STM m (Map RelayAccessPoint PeerAdvertise)
, daReadLocalRootPeers :: STM m (LocalRootPeers.Config RelayAccessPoint)
, daReadPublicRootPeers :: STM m (Map RelayAccessPoint PeerAdvertise)
-- | When syncing up, ie. ledgerStateJudgement == TooOld,
-- when this is True we will maintain connection with many big ledger peers
-- to get a strong guarantee that when syncing up we will finish with a true
-- ledger state. When false, we will fall back on the previous algorithms
-- that leverage UseBootstrapPeers flag
, daConsensusMode :: ConsensusMode
, daReadUseBootstrapPeers :: STM m UseBootstrapPeers
, daConsensusMode :: ConsensusMode
, daReadUseBootstrapPeers :: STM m UseBootstrapPeers
-- | Depending on configuration, node may provide us with
-- a snapshot of big ledger peers taken at some slot on the chain.
-- These peers may be selected by ledgerPeersThread when requested
Expand Down Expand Up @@ -828,8 +828,8 @@ runM Interfaces

peerSelectionTargetsVar <- newTVarIO $
case daConsensusMode of
PraosMode -> praosTargets daPeerTargets
GenesisMode -> genesisSyncTargets daPeerTargets
PraosMode -> praosTargets daPeerTargets
GenesisMode -> genesisSyncTargets daPeerTargets

countersVar <- newTVarIO emptyPeerSelectionCounters

Expand Down
20 changes: 10 additions & 10 deletions ouroboros-network/src/Ouroboros/Network/PeerSelection/Churn.hs
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,16 @@ data PeerChurnArgs m peeraddr = PeerChurnArgs {
pcaPeerRequestTimeout :: DiffTime,
-- ^ the timeout for outbound governor to find new (thus
-- cold) peers through peer sharing mechanism.
pcaMetrics :: PeerMetrics m peeraddr,
pcaModeVar :: StrictTVar m ChurnMode,
pcaRng :: StdGen,
pcaReadFetchMode :: STM m FetchMode,
peerTargets :: ConsensusModePeerTargets,
pcaPeerSelectionVar :: StrictTVar m PeerSelectionTargets,
pcaReadCounters :: STM m PeerSelectionCounters,
pcaReadUseBootstrap :: STM m UseBootstrapPeers,
pcaConsensusMode :: ConsensusMode,
getLocalRootHotTarget :: STM m HotValency }
pcaMetrics :: PeerMetrics m peeraddr,
pcaModeVar :: StrictTVar m ChurnMode,
pcaRng :: StdGen,
pcaReadFetchMode :: STM m FetchMode,
peerTargets :: ConsensusModePeerTargets,
pcaPeerSelectionVar :: StrictTVar m PeerSelectionTargets,
pcaReadCounters :: STM m PeerSelectionCounters,
pcaReadUseBootstrap :: STM m UseBootstrapPeers,
pcaConsensusMode :: ConsensusMode,
getLocalRootHotTarget :: STM m HotValency }

-- | Churn governor.
--
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE ScopedTypeVariables #-}

#if __GLASGOW_HASKELL__ < 904
{-# OPTIONS_GHC -Wno-name-shadowing #-}
Expand Down Expand Up @@ -72,8 +72,8 @@ import System.Random

import Ouroboros.Network.ConsensusMode
import Ouroboros.Network.PeerSelection.Bootstrap (UseBootstrapPeers (..))
import Ouroboros.Network.PeerSelection.Churn (ChurnCounters (..), PeerChurnArgs (..),
peerChurnGovernor)
import Ouroboros.Network.PeerSelection.Churn (ChurnCounters (..),
PeerChurnArgs (..), peerChurnGovernor)
import Ouroboros.Network.PeerSelection.Governor.ActivePeers qualified as ActivePeers
import Ouroboros.Network.PeerSelection.Governor.BigLedgerPeers qualified as BigLedgerPeers
import Ouroboros.Network.PeerSelection.Governor.EstablishedPeers qualified as EstablishedPeers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,21 +415,21 @@ data PeerSelectionActions peeraddr peerconn m = PeerSelectionActions {
data PeerSelectionInterfaces peeraddr peerconn m = PeerSelectionInterfaces {
-- | PeerSelectionCounters are shared with churn through a `StrictTVar`.
--
countersVar :: StrictTVar m PeerSelectionCounters,
countersVar :: StrictTVar m PeerSelectionCounters,

-- | PublicPeerSelectionState var.
--
publicStateVar :: StrictTVar m (PublicPeerSelectionState peeraddr),
publicStateVar :: StrictTVar m (PublicPeerSelectionState peeraddr),

-- | PeerSelectionState shared for debugging purposes (to support SIGUSR1
-- debug event tracing)
--
debugStateVar :: StrictTVar m (PeerSelectionState peeraddr peerconn),
debugStateVar :: StrictTVar m (PeerSelectionState peeraddr peerconn),

-- | `UseLedgerPeers` used by `peerSelectionGovernor` to support
-- `HiddenRelayOrBP`
--
readUseLedgerPeers :: STM m UseLedgerPeers
readUseLedgerPeers :: STM m UseLedgerPeers
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE DisambiguateRecordFields #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

module Ouroboros.Network.PeerSelection.PeerSelectionActions
( withPeerSelectionActions
Expand Down

0 comments on commit ddbd7f1

Please sign in to comment.