Skip to content

Commit

Permalink
Makes AcceptedConnectionsLimit configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
bolt12 committed Dec 13, 2021
1 parent 04f50a1 commit 67c14d1
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
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

0 comments on commit 67c14d1

Please sign in to comment.