Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makes AcceptedConnectionsLimit configurable #3435

Merged
merged 1 commit into from
Dec 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion cardano-node/src/Cardano/Node/Configuration/POM.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import Cardano.Tracing.Config
import Ouroboros.Consensus.Mempool.API (MempoolCapacityBytesOverride (..), MempoolCapacityBytes (..))
import Ouroboros.Consensus.Storage.LedgerDB.DiskPolicy (SnapshotInterval (..))
import Ouroboros.Network.Block (MaxSlotNo (..))
import Ouroboros.Network.NodeToNode (DiffusionMode (..))
import Ouroboros.Network.NodeToNode (DiffusionMode (..), AcceptedConnectionsLimit (..))
import qualified Ouroboros.Consensus.Node as Consensus ( NetworkP2PMode (..) )

data NetworkP2PMode = EnabledP2PMode | DisabledP2PMode
Expand Down Expand Up @@ -127,6 +127,9 @@ data NodeConfiguration
--
, ncTimeWaitTimeout :: DiffTime

-- | Node AcceptedConnectionsLimit
, ncAcceptedConnectionsLimit :: !AcceptedConnectionsLimit

-- P2P governor targets
, ncTargetNumberOfRootPeers :: Int
, ncTargetNumberOfKnownPeers :: Int
Expand Down Expand Up @@ -179,6 +182,9 @@ data PartialNodeConfiguration
, pncProtocolIdleTimeout :: !(Last DiffTime)
, pncTimeWaitTimeout :: !(Last DiffTime)

-- AcceptedConnectionsLimit
, pncAcceptedConnectionsLimit :: !(Last AcceptedConnectionsLimit)

-- P2P governor targets
, pncTargetNumberOfRootPeers :: !(Last Int)
, pncTargetNumberOfKnownPeers :: !(Last Int)
Expand Down Expand Up @@ -241,6 +247,11 @@ instance FromJSON PartialNodeConfiguration where
pncProtocolIdleTimeout <- Last <$> v .:? "ProtocolIdleTimeout"
pncTimeWaitTimeout <- Last <$> v .:? "TimeWaitTimeout"


-- AcceptedConnectionsLimit
pncAcceptedConnectionsLimit
<- Last <$> v .:? "AcceptedConnectionsLimit"

-- P2P Governor parameters, with conservative defaults.
pncTargetNumberOfRootPeers <- Last <$> v .:? "TargetNumberOfRootPeers"
pncTargetNumberOfKnownPeers <- Last <$> v .:? "TargetNumberOfKnownPeers"
Expand Down Expand Up @@ -279,6 +290,7 @@ instance FromJSON PartialNodeConfiguration where
, pncMaybeMempoolCapacityOverride
, pncProtocolIdleTimeout
, pncTimeWaitTimeout
, pncAcceptedConnectionsLimit
, pncTargetNumberOfRootPeers
, pncTargetNumberOfKnownPeers
, pncTargetNumberOfEstablishedPeers
Expand Down Expand Up @@ -420,6 +432,14 @@ defaultPartialNodeConfiguration =
, pncMaybeMempoolCapacityOverride = mempty
, pncProtocolIdleTimeout = Last (Just 5)
, pncTimeWaitTimeout = Last (Just 60)
, pncAcceptedConnectionsLimit =
Last
$ Just
$ AcceptedConnectionsLimit
{ acceptedConnectionsHardLimit = 512
, acceptedConnectionsSoftLimit = 384
, acceptedConnectionsDelay = 5
}
, pncTargetNumberOfRootPeers = Last (Just 100)
, pncTargetNumberOfKnownPeers = Last (Just 100)
, pncTargetNumberOfEstablishedPeers = Last (Just 50)
Expand Down Expand Up @@ -467,6 +487,9 @@ makeNodeConfiguration pnc = do
ncTimeWaitTimeout <-
lastToEither "Missing TimeWaitTimeout"
$ pncTimeWaitTimeout pnc
ncAcceptedConnectionsLimit <-
lastToEither "Missing AcceptedConnectionsLimit" $
pncAcceptedConnectionsLimit pnc
enableP2P <-
lastToEither "Missing EnableP2P"
$ pncEnableP2P pnc
Expand Down Expand Up @@ -499,6 +522,7 @@ makeNodeConfiguration pnc = do
, ncMaybeMempoolCapacityOverride = getLast $ pncMaybeMempoolCapacityOverride pnc
, ncProtocolIdleTimeout
, ncTimeWaitTimeout
, ncAcceptedConnectionsLimit
, ncTargetNumberOfRootPeers
, ncTargetNumberOfKnownPeers
, ncTargetNumberOfEstablishedPeers
Expand Down
25 changes: 25 additions & 0 deletions cardano-node/src/Cardano/Node/Orphans.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE NamedFieldPuns #-}

{-# OPTIONS_GHC -Wno-orphans #-}

Expand All @@ -17,6 +18,7 @@ import Cardano.BM.Data.Tracer (TracingVerbosity (..))
import qualified Cardano.Chain.Update as Update
import Cardano.Ledger.Crypto (StandardCrypto)
import qualified Cardano.Ledger.Shelley.CompactAddr as Shelley
import Ouroboros.Network.NodeToNode (AcceptedConnectionsLimit (..))

instance FromJSON TracingVerbosity where
parseJSON (String str) = case str of
Expand All @@ -42,3 +44,26 @@ instance FromJSON Update.ApplicationName where
parseJSON invalid =
fail $ "Parsing of application name failed due to type mismatch. "
<> "Encountered: " <> show invalid

instance ToJSON AcceptedConnectionsLimit where
toJSON AcceptedConnectionsLimit
{ acceptedConnectionsHardLimit
, acceptedConnectionsSoftLimit
, acceptedConnectionsDelay
} =
object [ "AcceptedConnectionsLimit" .=
object [ "hardLimit" .=
toJSON acceptedConnectionsHardLimit
, "softLimit" .=
toJSON acceptedConnectionsSoftLimit
, "delay" .=
toJSON acceptedConnectionsDelay
]
]

instance FromJSON AcceptedConnectionsLimit where
parseJSON = withObject "AcceptedConnectionsLimit" $ \v ->
AcceptedConnectionsLimit
<$> v .: "hardLimit"
<*> v .: "softLimit"
<*> v .: "delay"
1 change: 1 addition & 0 deletions cardano-node/src/Cardano/Node/Parsers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ nodeRunParser = do
, pncMaybeMempoolCapacityOverride = maybeMempoolCapacityOverride
, pncProtocolIdleTimeout = mempty
, pncTimeWaitTimeout = mempty
, pncAcceptedConnectionsLimit = mempty
, pncTargetNumberOfRootPeers = mempty
, pncTargetNumberOfKnownPeers = mempty
, pncTargetNumberOfEstablishedPeers = mempty
Expand Down
11 changes: 10 additions & 1 deletion cardano-node/test/Test/Cardano/Node/POM.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import Cardano.Node.Configuration.POM
import Cardano.Node.Types
import Cardano.Tracing.Config (TraceOptions (..))
import Ouroboros.Network.Block (MaxSlotNo (..), SlotNo (..))
import Ouroboros.Network.NodeToNode (DiffusionMode (InitiatorAndResponderDiffusionMode))
import Ouroboros.Network.NodeToNode (DiffusionMode (InitiatorAndResponderDiffusionMode),
AcceptedConnectionsLimit(..))
import Ouroboros.Consensus.Storage.LedgerDB.DiskPolicy (SnapshotInterval (..))
import qualified Ouroboros.Consensus.Node as Consensus ( NetworkP2PMode (..) )

Expand Down Expand Up @@ -69,6 +70,7 @@ testPartialYamlConfig =
, pncMaybeMempoolCapacityOverride = mempty
, pncProtocolIdleTimeout = mempty
, pncTimeWaitTimeout = mempty
, pncAcceptedConnectionsLimit = mempty
, pncTargetNumberOfRootPeers = mempty
, pncTargetNumberOfKnownPeers = mempty
, pncTargetNumberOfEstablishedPeers = mempty
Expand Down Expand Up @@ -104,6 +106,7 @@ testPartialCliConfig =
, pncMaybeMempoolCapacityOverride = mempty
, pncProtocolIdleTimeout = mempty
, pncTimeWaitTimeout = mempty
, pncAcceptedConnectionsLimit = mempty
, pncTargetNumberOfRootPeers = mempty
, pncTargetNumberOfKnownPeers = mempty
, pncTargetNumberOfEstablishedPeers = mempty
Expand Down Expand Up @@ -140,6 +143,12 @@ expectedConfig =
, ncMaybeMempoolCapacityOverride = Nothing
, ncProtocolIdleTimeout = 5
, ncTimeWaitTimeout = 60
, ncAcceptedConnectionsLimit =
AcceptedConnectionsLimit
{ acceptedConnectionsHardLimit = 512
, acceptedConnectionsSoftLimit = 384
, acceptedConnectionsDelay = 5
}
, ncTargetNumberOfRootPeers = 100
, ncTargetNumberOfKnownPeers = 100
, ncTargetNumberOfEstablishedPeers = 50
Expand Down