Skip to content

Commit

Permalink
Added central configuration module
Browse files Browse the repository at this point in the history
  • Loading branch information
crocodile-dentist committed Feb 22, 2024
1 parent 020fda4 commit bb125ce
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ouroboros-network/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
`Ouroboros.Network.Peersharing`
* Added `PeerSharingAPI` with all the things necessary to run peer sharing.

* Coalesced various diffusion configuration parameters in a new Configuration module which were scattered around previously

## 0.11.0.0 -- 2023-01-22

### Breaking changes
Expand Down
1 change: 1 addition & 0 deletions ouroboros-network/ouroboros-network.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ library
Ouroboros.Network.BlockFetch.State
Ouroboros.Network.DeltaQ
Ouroboros.Network.Diffusion
Ouroboros.Network.Diffusion.Configuration
Ouroboros.Network.Diffusion.P2P
Ouroboros.Network.Diffusion.NonP2P
Ouroboros.Network.Diffusion.Policies
Expand Down
109 changes: 109 additions & 0 deletions ouroboros-network/src/Ouroboros/Network/Diffusion/Configuration.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
{-# LANGUAGE NamedFieldPuns #-}

module Ouroboros.Network.Diffusion.Configuration
( module Ouroboros.Network.Diffusion.Configuration
-- re-exports
, AcceptedConnectionsLimit (..)
, BlockFetchConfiguration (..)
, ChainSyncTimeout (..)
, MiniProtocolParameters (..)
, P2P (..)
, PeerSelectionTargets (..)
, PeerSharing (..)
, 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 System.Random (randomRIO)

import Ouroboros.Network.BlockFetch (BlockFetchConfiguration (..))
import Ouroboros.Network.ConnectionManager.Core (defaultProtocolIdleTimeout,
defaultResetTimeout, defaultTimeWaitTimeout)
import Ouroboros.Network.Diffusion (P2P (..))
import Ouroboros.Network.Diffusion.Policies (closeConnectionTimeout,
deactivateTimeout, peerMetricsConfiguration)
import Ouroboros.Network.NodeToNode (MiniProtocolParameters (..),
defaultMiniProtocolParameters)
import Ouroboros.Network.PeerSelection.Governor.Types
(PeerSelectionTargets (..))
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 DefaultQtyBootstrapPeers = DefaultQtyBootstrapPeers { getDefaultQtyBootstrapPeers :: Int }
deriving (Eq, Show)

-- For reviewers, I heard 30 being repeated but it could be something else
defaultQtyBootstrapPeers :: DefaultQtyBootstrapPeers
defaultQtyBootstrapPeers = DefaultQtyBootstrapPeers 30

defaultPeerSelectionTargets :: PeerSelectionTargets
defaultPeerSelectionTargets =
PeerSelectionTargets {
targetNumberOfRootPeers = 85,
targetNumberOfKnownPeers = 85,
targetNumberOfEstablishedPeers = 40,
targetNumberOfActivePeers = 15,
targetNumberOfKnownBigLedgerPeers = 15,
targetNumberOfEstablishedBigLedgerPeers = 10,
targetNumberOfActiveBigLedgerPeers = 5 }

defaultAcceptedConnectionsLimit :: AcceptedConnectionsLimit
defaultAcceptedConnectionsLimit =
AcceptedConnectionsLimit {
acceptedConnectionsHardLimit = 512,
acceptedConnectionsSoftLimit = 384,
acceptedConnectionsDelay = 5 }

defaultDiffusionMode :: P2P
defaultDiffusionMode = NonP2P

defaultPeerSharing :: PeerSharing
defaultPeerSharing = PeerSharingDisabled

defaultBlockFetchConfiguration :: Int -> BlockFetchConfiguration
defaultBlockFetchConfiguration bfcSalt =
BlockFetchConfiguration {
bfcMaxConcurrencyBulkSync = 1,
bfcMaxConcurrencyDeadline = 1,
bfcMaxRequestsInflight = fromIntegral $ blockFetchPipeliningMax defaultMiniProtocolParameters,
bfcDecisionLoopInterval = 0.01, -- 10ms
bfcSalt }

defaultChainSyncTimeout :: IO ChainSyncTimeout
defaultChainSyncTimeout = do
-- These values approximately correspond to false positive
-- thresholds for streaks of empty slots with 99% probability,
-- 99.9% probability up to 99.999% probability.
-- t = T_s [log (1-Y) / log (1-f)]
-- Y = [0.99, 0.999...]
-- T_s = slot length of 1s.
-- f = 0.05
-- The timeout is randomly picked per bearer to avoid all bearers
-- going down at the same time in case of a long streak of empty
-- slots.
-- To avoid global synchronosation the timeout is picked uniformly
-- from the interval 135 - 269, corresponds to the a 99.9% to
-- 99.9999% thresholds.
-- TODO: The timeout should be drawn at random everytime chainsync
-- enters the must reply state. A static per connection timeout
-- leads to selection preassure for connections with a large
-- timeout, see #4244.
mustReplyTimeout <- Just . realToFrac <$> randomRIO (135,269 :: Double)
return ChainSyncTimeout { canAwaitTimeout = shortWait,
intersectTimeout = shortWait,
mustReplyTimeout,
idleTimeout = Just 3673 }

0 comments on commit bb125ce

Please sign in to comment.