Skip to content

Commit 875b40f

Browse files
committed
peer sharing: default configuration value
The default configuration value of peer sharing option depends now on `pncStartAsNonProducingNode` option and `ncProtocolFiles`. If a node runs as a relay, peer sharing is on by default, if it is running as a block producer, peer sharing is off by default. The default value can be overridden.
1 parent 37cf96b commit 875b40f

File tree

2 files changed

+35
-13
lines changed

2 files changed

+35
-13
lines changed

cardano-node/src/Cardano/Node/Configuration/POM.hs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ data PartialNodeConfiguration
227227
, pncConfigFile :: !(Last ConfigYamlFilePath)
228228
, pncTopologyFile :: !(Last TopologyFile)
229229
, pncDatabaseFile :: !(Last NodeDatabasePaths)
230+
-- | pncProtocolFiles can only be supplied with command line arguments.
230231
, pncProtocolFiles :: !(Last ProtocolFilepaths)
231232
, pncValidateDB :: !(Last Bool)
232233
, pncShutdownConfig :: !(Last ShutdownConfig)
@@ -652,7 +653,7 @@ defaultPartialNodeConfiguration =
652653
, pncDiffusionMode = Last $ Just InitiatorAndResponderDiffusionMode
653654
, pncExperimentalProtocolsEnabled = Last $ Just False
654655
, pncTopologyFile = Last . Just $ TopologyFile "configuration/cardano/mainnet-topology.json"
655-
, pncProtocolFiles = mempty
656+
, pncProtocolFiles = Last . Just $ ProtocolFilepaths Nothing Nothing Nothing Nothing Nothing Nothing
656657
, pncValidateDB = Last $ Just False
657658
, pncShutdownConfig = Last . Just $ ShutdownConfig Nothing Nothing
658659
, pncStartAsNonProducingNode = Last $ Just False
@@ -704,8 +705,8 @@ defaultPartialNodeConfiguration =
704705
, pncConsensusMode = Last (Just Ouroboros.defaultConsensusMode)
705706
-- https://ouroboros-network.cardano.intersectmbo.org/ouroboros-network/Ouroboros-Network-Diffusion-Configuration.html#v:defaultConsensusMode
706707
, pncEnableP2P = Last (Just EnabledP2PMode)
707-
, pncPeerSharing = Last (Just Ouroboros.defaultPeerSharing)
708-
-- https://ouroboros-network.cardano.intersectmbo.org/ouroboros-network/Ouroboros-Network-Diffusion-Configuration.html#v:defaultPeerSharing
708+
, pncPeerSharing = mempty
709+
-- the default is defined in `makeNodeConfiguration`
709710
, pncGenesisConfigFlags = Last (Just defaultGenesisConfigFlags)
710711
-- https://ouroboros-consensus.cardano.intersectmbo.org/haddocks/ouroboros-consensus-diffusion/Ouroboros-Consensus-Node-Genesis.html#v:defaultGenesisConfigFlags
711712
, pncResponderCoreAffinityPolicy = Last $ Just NoResponderCoreAffinity
@@ -722,6 +723,7 @@ makeNodeConfiguration pnc = do
722723
validateDB <- lastToEither "Missing ValidateDB" $ pncValidateDB pnc
723724
startAsNonProducingNode <- lastToEither "Missing StartAsNonProducingNode" $ pncStartAsNonProducingNode pnc
724725
protocolConfig <- lastToEither "Missing ProtocolConfig" $ pncProtocolConfig pnc
726+
protocolFiles <- lastToEither "Missing ProtocolFiles" $ pncProtocolFiles pnc
725727
loggingSwitch <- lastToEither "Missing LoggingSwitch" $ pncLoggingSwitch pnc
726728
logMetrics <- lastToEither "Missing LogMetrics" $ pncLogMetrics pnc
727729
traceConfig <- first Text.unpack $ partialTraceSelectionToEither $ pncTraceConfig pnc
@@ -801,9 +803,14 @@ makeNodeConfiguration pnc = do
801803
$ getLast
802804
$ pncChainSyncIdleTimeout pnc
803805

804-
ncPeerSharing <-
805-
lastToEither "Missing PeerSharing"
806-
$ pncPeerSharing pnc
806+
let ncPeerSharing =
807+
case pncPeerSharing pnc of
808+
Last Nothing ->
809+
if not startAsNonProducingNode
810+
|| hasProtocolFile protocolFiles
811+
then PeerSharingDisabled
812+
else PeerSharingEnabled
813+
Last (Just peerSharing) -> peerSharing
807814

808815
mGenesisConfigFlags <- case ncConsensusMode of
809816
PraosMode -> pure Nothing
@@ -848,13 +855,7 @@ makeNodeConfiguration pnc = do
848855
{ ncConfigFile = configFile
849856
, ncTopologyFile = topologyFile
850857
, ncDatabaseFile = databaseFile
851-
, ncProtocolFiles =
852-
-- TODO: ncProtocolFiles should be Maybe ProtocolFiles
853-
-- as relay nodes don't need the protocol files because
854-
-- they are not minting blocks.
855-
case getLast $ pncProtocolFiles pnc of
856-
Just pFiles -> pFiles
857-
Nothing -> ProtocolFilepaths Nothing Nothing Nothing Nothing Nothing Nothing
858+
, ncProtocolFiles = protocolFiles
858859
, ncValidateDB = validateDB
859860
, ncShutdownConfig = shutdownConfig
860861
, ncStartAsNonProducingNode = startAsNonProducingNode

cardano-node/src/Cardano/Node/Types.hs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module Cardano.Node.Types
1717
, PeerSnapshotFile (..)
1818
, CheckpointsFile(..)
1919
, ProtocolFilepaths (..)
20+
, hasProtocolFile
2021
, GenesisHash(..)
2122
, CheckpointsHash(..)
2223
, MaxConcurrencyBulkSync(..)
@@ -50,6 +51,7 @@ import Ouroboros.Network.NodeToNode (DiffusionMode (..))
5051
import Control.Exception
5152
import Data.Aeson
5253
import Data.ByteString (ByteString)
54+
import Data.Maybe (isJust)
5355
import Data.Monoid (Last (..))
5456
import Data.String (IsString)
5557
import Data.Text (Text)
@@ -174,6 +176,25 @@ data ProtocolFilepaths =
174176
, shelleyBulkCredsFile :: !(Maybe FilePath)
175177
} deriving (Eq, Show)
176178

179+
-- | If any of the 'ProtocolFilepath` is given `PeerSharing` option will be
180+
-- disabled by default.
181+
--
182+
hasProtocolFile :: ProtocolFilepaths -> Bool
183+
hasProtocolFile ProtocolFilepaths {
184+
byronCertFile,
185+
byronKeyFile,
186+
shelleyKESFile,
187+
shelleyVRFFile,
188+
shelleyCertFile,
189+
shelleyBulkCredsFile
190+
}
191+
= isJust byronCertFile
192+
|| isJust byronKeyFile
193+
|| isJust shelleyKESFile
194+
|| isJust shelleyVRFFile
195+
|| isJust shelleyCertFile
196+
|| isJust shelleyBulkCredsFile
197+
177198
newtype GenesisHash = GenesisHash (Crypto.Hash Crypto.Blake2b_256 ByteString)
178199
deriving newtype (Eq, Show, ToJSON, FromJSON)
179200

0 commit comments

Comments
 (0)