{-# LANGUAGE NamedFieldPuns #-}
module Ouroboros.Network.Diffusion.Configuration
( DefaultNumBootstrapPeers (..)
, MinBigLedgerPeersForTrustedState (..)
, defaultNumBootstrapPeers
, defaultAcceptedConnectionsLimit
, defaultDiffusionMode
, defaultPeerSharing
, defaultBlockFetchConfiguration
, defaultChainSyncTimeout
, defaultDeadlineTargets
, defaultSyncTargets
, defaultDeadlineChurnInterval
, defaultBulkChurnInterval
, AcceptedConnectionsLimit (..)
, BlockFetchConfiguration (..)
, ChainSyncTimeout (..)
, ConsensusModePeerTargets (..)
, DiffusionMode (..)
, MiniProtocolParameters (..)
, P2P (..)
, PeerSelectionTargets (..)
, PeerSharing (..)
, ConsensusMode (..)
, defaultConsensusMode
, defaultMinBigLedgerPeersForTrustedState
, defaultMiniProtocolParameters
, deactivateTimeout
, closeConnectionTimeout
, peerMetricsConfiguration
, defaultTimeWaitTimeout
, defaultProtocolIdleTimeout
, defaultResetTimeout
, handshake_QUERY_SHUTDOWN_DELAY
, ps_POLICY_PEER_SHARE_STICKY_TIME
, ps_POLICY_PEER_SHARE_MAX_PEERS
) where
import Control.Monad.Class.MonadTime.SI
import System.Random (randomRIO)
import Ouroboros.Network.BlockFetch (BlockFetchConfiguration (..),
GenesisBlockFetchConfiguration (..))
import Ouroboros.Network.ConnectionManager.Core (defaultProtocolIdleTimeout,
defaultResetTimeout, defaultTimeWaitTimeout)
import Ouroboros.Network.ConsensusMode
import Ouroboros.Network.Diffusion (P2P (..))
import Ouroboros.Network.Diffusion.Policies (closeConnectionTimeout,
deactivateTimeout, maxChainSyncTimeout, minChainSyncTimeout,
peerMetricsConfiguration)
import Ouroboros.Network.NodeToNode (DiffusionMode (..),
MiniProtocolParameters (..), defaultMiniProtocolParameters)
import Ouroboros.Network.PeerSelection.Governor.Types
(ConsensusModePeerTargets (..), PeerSelectionTargets (..))
import Ouroboros.Network.PeerSelection.LedgerPeers.Type
(MinBigLedgerPeersForTrustedState (..))
import Ouroboros.Network.PeerSelection.PeerSharing (PeerSharing (..))
import Ouroboros.Network.PeerSharing (ps_POLICY_PEER_SHARE_MAX_PEERS,
ps_POLICY_PEER_SHARE_STICKY_TIME)
import Ouroboros.Network.Protocol.ChainSync.Codec (ChainSyncTimeout (..))
import Ouroboros.Network.Protocol.Handshake (handshake_QUERY_SHUTDOWN_DELAY)
import Ouroboros.Network.Protocol.Limits (shortWait)
import Ouroboros.Network.Server.RateLimiting (AcceptedConnectionsLimit (..))
newtype DefaultNumBootstrapPeers = DefaultNumBootstrapPeers { DefaultNumBootstrapPeers -> Int
getDefaultNumBootstrapPeers :: Int }
deriving (DefaultNumBootstrapPeers -> DefaultNumBootstrapPeers -> Bool
(DefaultNumBootstrapPeers -> DefaultNumBootstrapPeers -> Bool)
-> (DefaultNumBootstrapPeers -> DefaultNumBootstrapPeers -> Bool)
-> Eq DefaultNumBootstrapPeers
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: DefaultNumBootstrapPeers -> DefaultNumBootstrapPeers -> Bool
== :: DefaultNumBootstrapPeers -> DefaultNumBootstrapPeers -> Bool
$c/= :: DefaultNumBootstrapPeers -> DefaultNumBootstrapPeers -> Bool
/= :: DefaultNumBootstrapPeers -> DefaultNumBootstrapPeers -> Bool
Eq, Int -> DefaultNumBootstrapPeers -> ShowS
[DefaultNumBootstrapPeers] -> ShowS
DefaultNumBootstrapPeers -> String
(Int -> DefaultNumBootstrapPeers -> ShowS)
-> (DefaultNumBootstrapPeers -> String)
-> ([DefaultNumBootstrapPeers] -> ShowS)
-> Show DefaultNumBootstrapPeers
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DefaultNumBootstrapPeers -> ShowS
showsPrec :: Int -> DefaultNumBootstrapPeers -> ShowS
$cshow :: DefaultNumBootstrapPeers -> String
show :: DefaultNumBootstrapPeers -> String
$cshowList :: [DefaultNumBootstrapPeers] -> ShowS
showList :: [DefaultNumBootstrapPeers] -> ShowS
Show)
defaultNumBootstrapPeers :: DefaultNumBootstrapPeers
defaultNumBootstrapPeers :: DefaultNumBootstrapPeers
defaultNumBootstrapPeers = Int -> DefaultNumBootstrapPeers
DefaultNumBootstrapPeers Int
30
defaultDeadlineTargets :: PeerSelectionTargets
defaultDeadlineTargets :: PeerSelectionTargets
defaultDeadlineTargets =
PeerSelectionTargets {
targetNumberOfRootPeers :: Int
targetNumberOfRootPeers = Int
60,
targetNumberOfKnownPeers :: Int
targetNumberOfKnownPeers = Int
85,
targetNumberOfEstablishedPeers :: Int
targetNumberOfEstablishedPeers = Int
40,
targetNumberOfActivePeers :: Int
targetNumberOfActivePeers = Int
15,
targetNumberOfKnownBigLedgerPeers :: Int
targetNumberOfKnownBigLedgerPeers = Int
15,
targetNumberOfEstablishedBigLedgerPeers :: Int
targetNumberOfEstablishedBigLedgerPeers = Int
10,
targetNumberOfActiveBigLedgerPeers :: Int
targetNumberOfActiveBigLedgerPeers = Int
5 }
defaultSyncTargets :: PeerSelectionTargets
defaultSyncTargets :: PeerSelectionTargets
defaultSyncTargets =
PeerSelectionTargets
defaultDeadlineTargets {
targetNumberOfActivePeers = 0,
targetNumberOfKnownBigLedgerPeers = 100,
targetNumberOfEstablishedBigLedgerPeers = 50,
targetNumberOfActiveBigLedgerPeers = 30 }
defaultMinBigLedgerPeersForTrustedState :: MinBigLedgerPeersForTrustedState
defaultMinBigLedgerPeersForTrustedState :: MinBigLedgerPeersForTrustedState
defaultMinBigLedgerPeersForTrustedState = Int -> MinBigLedgerPeersForTrustedState
MinBigLedgerPeersForTrustedState Int
5
defaultAcceptedConnectionsLimit :: AcceptedConnectionsLimit
defaultAcceptedConnectionsLimit :: AcceptedConnectionsLimit
defaultAcceptedConnectionsLimit =
AcceptedConnectionsLimit {
acceptedConnectionsHardLimit :: Word32
acceptedConnectionsHardLimit = Word32
512,
acceptedConnectionsSoftLimit :: Word32
acceptedConnectionsSoftLimit = Word32
384,
acceptedConnectionsDelay :: DiffTime
acceptedConnectionsDelay = DiffTime
5 }
defaultDiffusionMode :: P2P
defaultDiffusionMode :: P2P
defaultDiffusionMode = P2P
NonP2P
defaultPeerSharing :: PeerSharing
defaultPeerSharing :: PeerSharing
defaultPeerSharing = PeerSharing
PeerSharingDisabled
defaultBlockFetchConfiguration :: Int -> BlockFetchConfiguration
defaultBlockFetchConfiguration :: Int -> BlockFetchConfiguration
defaultBlockFetchConfiguration Int
bfcSalt =
BlockFetchConfiguration {
bfcMaxConcurrencyBulkSync :: Word
bfcMaxConcurrencyBulkSync = Word
1,
bfcMaxConcurrencyDeadline :: Word
bfcMaxConcurrencyDeadline = Word
1,
bfcMaxRequestsInflight :: Word
bfcMaxRequestsInflight = Word16 -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word16 -> Word) -> Word16 -> Word
forall a b. (a -> b) -> a -> b
$ MiniProtocolParameters -> Word16
blockFetchPipeliningMax MiniProtocolParameters
defaultMiniProtocolParameters,
bfcDecisionLoopIntervalGenesis :: DiffTime
bfcDecisionLoopIntervalGenesis = DiffTime
0.04,
bfcDecisionLoopIntervalPraos :: DiffTime
bfcDecisionLoopIntervalPraos = DiffTime
0.01,
bfcGenesisBFConfig :: GenesisBlockFetchConfiguration
bfcGenesisBFConfig = GenesisBlockFetchConfiguration
{ gbfcGracePeriod :: DiffTime
gbfcGracePeriod = DiffTime
10 },
Int
bfcSalt :: Int
bfcSalt :: Int
bfcSalt }
defaultChainSyncTimeout :: IO ChainSyncTimeout
defaultChainSyncTimeout :: IO ChainSyncTimeout
defaultChainSyncTimeout = do
mustReplyTimeout <- DiffTime -> Maybe DiffTime
forall a. a -> Maybe a
Just (DiffTime -> Maybe DiffTime)
-> (Double -> DiffTime) -> Double -> Maybe DiffTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> DiffTime
forall a b. (Real a, Fractional b) => a -> b
realToFrac (Double -> Maybe DiffTime) -> IO Double -> IO (Maybe DiffTime)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Double, Double) -> IO Double
forall a (m :: * -> *). (Random a, MonadIO m) => (a, a) -> m a
randomRIO ( DiffTime -> Double
forall a b. (Real a, Fractional b) => a -> b
realToFrac DiffTime
minChainSyncTimeout :: Double
, DiffTime -> Double
forall a b. (Real a, Fractional b) => a -> b
realToFrac DiffTime
maxChainSyncTimeout :: Double
)
return ChainSyncTimeout { canAwaitTimeout = shortWait,
intersectTimeout = shortWait,
mustReplyTimeout,
idleTimeout = Just 3673 }
defaultDeadlineChurnInterval :: DiffTime
defaultDeadlineChurnInterval :: DiffTime
defaultDeadlineChurnInterval = DiffTime
3300
defaultBulkChurnInterval :: DiffTime
defaultBulkChurnInterval :: DiffTime
defaultBulkChurnInterval = DiffTime
900