Skip to content

Commit f55c811

Browse files
committed
Added WarmValency option to the Topology file
Now the Topology allows the user to not only specify the HotValency of its node's local root peers, via 'valency' ('hotValency' is now also valid) field, but also is able to specify the WarmValency, via 'warmValency' field. This field is optional and defaults to the value set in the 'valency'/'hotValency' field. The 'warmValency' value set should be greater than or equal to the one specified in 'valency'/'hotValency' otherwise 'valency'/'hotValency' will be truncated to this value. We recommend users to set 'warmValency' value to 'hotValency' + 1 in order to keep at least 1 backup peer to be promoted to hot in case something happens. Check IntersectMBO/ouroboros-network#4565 for more context on this WarmValency addition.
1 parent d3e1fb3 commit f55c811

File tree

10 files changed

+69
-27
lines changed

10 files changed

+69
-27
lines changed

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

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,11 @@ import Cardano.Node.Configuration.Topology (TopologyError (..))
4343
import Cardano.Node.Startup (StartupTrace (..))
4444
import Cardano.Node.Types
4545

46+
import Cardano.Tracing.OrphanInstances.Network ()
47+
import Control.Applicative (Alternative (..))
4648
import Ouroboros.Network.NodeToNode (PeerAdvertise (..))
4749
import Ouroboros.Network.PeerSelection.LedgerPeers (UseLedgerAfter (..))
50+
import Ouroboros.Network.PeerSelection.LocalRootPeers (HotValency (..), WarmValency (..))
4851
import Ouroboros.Network.PeerSelection.RelayAccessPoint (RelayAccessPoint (..))
4952

5053
data NodeSetup = NodeSetup
@@ -112,28 +115,35 @@ rootConfigToRelayAccessPoint RootConfig { rootAccessPoints, rootAdvertise } =
112115

113116
-- | A local root peers group. Local roots are treated by the outbound
114117
-- governor in a special way. The node will make sure that a node has the
115-
-- requested number ('valency') of connections to the local root peer group.
118+
-- requested number ('valency'/'hotValency') of connections to the local root peer group.
119+
-- 'warmValency' value is the value of warm/established connections that the node
120+
-- will attempt to maintain. By default this value will be equal to 'hotValency'.
116121
--
117122
data LocalRootPeersGroup = LocalRootPeersGroup
118123
{ localRoots :: RootConfig
119-
, valency :: Int
124+
, hotValency :: HotValency
125+
, warmValency :: WarmValency
120126
} deriving (Eq, Show)
121127

122128
-- | Does not use the 'FromJSON' instance of 'RootConfig', so that
123-
-- 'accessPoints', 'advertise' and 'valency' fields are attached to the same
124-
-- object.
129+
-- 'accessPoints', 'advertise', 'valency' and 'warmValency' fields are attached to the
130+
-- same object.
125131
instance FromJSON LocalRootPeersGroup where
126-
parseJSON = withObject "LocalRootPeersGroup" $ \o ->
132+
parseJSON = withObject "LocalRootPeersGroup" $ \o -> do
133+
hv@(HotValency v) <- o .: "valency"
134+
<|> o .: "hotValency"
127135
LocalRootPeersGroup
128136
<$> parseJSON (Object o)
129-
<*> o .: "valency"
137+
<*> pure hv
138+
<*> o .:? "warmValency" .!= WarmValency v
130139

131140
instance ToJSON LocalRootPeersGroup where
132141
toJSON lrpg =
133142
object
134143
[ "accessPoints" .= rootAccessPoints (localRoots lrpg)
135144
, "advertise" .= rootAdvertise (localRoots lrpg)
136-
, "valency" .= valency lrpg
145+
, "hotValency" .= hotValency lrpg
146+
, "warmValency" .= warmValency lrpg
137147
]
138148

139149
newtype LocalRootPeersGroups = LocalRootPeersGroups
@@ -185,10 +195,12 @@ instance FromJSON (Legacy a) => FromJSON (Legacy [a]) where
185195
parseJSON = fmap (Legacy . map getLegacy) . parseJSONList
186196

187197
instance FromJSON (Legacy LocalRootPeersGroup) where
188-
parseJSON = withObject "LocalRootPeersGroup" $ \o ->
198+
parseJSON = withObject "LocalRootPeersGroup" $ \o -> do
199+
hv@(HotValency v) <- o .: "hotValency"
189200
fmap Legacy $ LocalRootPeersGroup
190201
<$> o .: "localRoots"
191-
<*> o .: "valency"
202+
<*> pure hv
203+
<*> pure (WarmValency v)
192204

193205
instance FromJSON (Legacy LocalRootPeersGroups) where
194206
parseJSON = withObject "LocalRootPeersGroups" $ \o ->

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ import Cardano.Node.Protocol.Types
120120
import Cardano.Node.Queries
121121
import Cardano.Node.TraceConstraints (TraceConstraints)
122122
import Cardano.Tracing.Tracers
123+
import Ouroboros.Network.PeerSelection.LocalRootPeers (HotValency, WarmValency)
123124
import Ouroboros.Network.PeerSelection.PeerSharing (PeerSharing (..))
124125

125126
{- HLINT ignore "Fuse concatMap/map" -}
@@ -434,7 +435,7 @@ handleSimpleNode blockType runP p2pMode tracers nc onKernel = do
434435
$ NetworkConfig localRoots
435436
publicRoots
436437
(useLedgerAfterSlot nt)
437-
(localRootsVar :: StrictTVar IO [(Int, Map RelayAccessPoint PeerAdvertise)]) <- newTVarIO localRoots
438+
localRootsVar <- newTVarIO localRoots
438439
publicRootsVar <- newTVarIO publicRoots
439440
useLedgerVar <- newTVarIO (useLedgerAfterSlot nt)
440441
void $
@@ -557,7 +558,7 @@ installP2PSigHUPHandler :: Tracer IO (StartupTrace blk)
557558
-> Api.BlockType blk
558559
-> NodeConfiguration
559560
-> NodeKernel IO RemoteAddress (ConnectionId LocalAddress) blk
560-
-> StrictTVar IO [(Int, Map RelayAccessPoint PeerAdvertise)]
561+
-> StrictTVar IO [(HotValency, WarmValency, Map RelayAccessPoint PeerAdvertise)]
561562
-> StrictTVar IO (Map RelayAccessPoint PeerAdvertise)
562563
-> StrictTVar IO UseLedgerAfter
563564
-> IO ()
@@ -646,7 +647,7 @@ updateBlockForging startupTracer blockType nodeKernel nc = do
646647

647648
updateTopologyConfiguration :: Tracer IO (StartupTrace blk)
648649
-> NodeConfiguration
649-
-> StrictTVar IO [(Int, Map RelayAccessPoint PeerAdvertise)]
650+
-> StrictTVar IO [(HotValency, WarmValency, Map RelayAccessPoint PeerAdvertise)]
650651
-> StrictTVar IO (Map RelayAccessPoint PeerAdvertise)
651652
-> StrictTVar IO UseLedgerAfter
652653
-> IO ()
@@ -719,7 +720,7 @@ checkVRFFilePermissions (File vrfPrivKey) = do
719720

720721
mkP2PArguments
721722
:: NodeConfiguration
722-
-> STM IO [(Int, Map RelayAccessPoint PeerAdvertise)]
723+
-> STM IO [(HotValency, WarmValency, Map RelayAccessPoint PeerAdvertise)]
723724
-- ^ non-overlapping local root peers groups; the 'Int' denotes the
724725
-- valency of its group.
725726
-> STM IO (Map RelayAccessPoint PeerAdvertise)
@@ -786,11 +787,12 @@ producerAddressesNonP2P nt =
786787

787788
producerAddresses
788789
:: NetworkTopology
789-
-> ([(Int, Map RelayAccessPoint PeerAdvertise)], Map RelayAccessPoint PeerAdvertise)
790+
-> ([(HotValency, WarmValency, Map RelayAccessPoint PeerAdvertise)], Map RelayAccessPoint PeerAdvertise)
790791
producerAddresses nt =
791792
case nt of
792793
RealNodeTopology lrpg prp _ ->
793-
( map (\lrp -> ( valency lrp
794+
( map (\lrp -> ( hotValency lrp
795+
, warmValency lrp
794796
, Map.fromList $ rootConfigToRelayAccessPoint
795797
$ localRoots lrp
796798
)

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import Cardano.Node.Protocol (ProtocolInstantiationError)
5252
import Cardano.Node.Protocol.Types (SomeConsensusProtocol (..))
5353

5454
import Cardano.Git.Rev (gitRev)
55+
import Ouroboros.Network.PeerSelection.LocalRootPeers (HotValency, WarmValency)
5556
import Paths_cardano_node (version)
5657

5758
data StartupTrace blk =
@@ -108,7 +109,7 @@ data StartupTrace blk =
108109
-- | Log peer-to-peer network configuration, either on startup or when its
109110
-- updated.
110111
--
111-
| NetworkConfig [(Int, Map RelayAccessPoint PeerAdvertise)]
112+
| NetworkConfig [(HotValency, WarmValency, Map RelayAccessPoint PeerAdvertise)]
112113
(Map RelayAccessPoint PeerAdvertise)
113114
UseLedgerAfter
114115

cardano-node/src/Cardano/Node/Tracing/Tracers/P2P.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,9 @@ instance LogFormatting (TracePeerSelection SockAddr) where
268268
, "actualEstablished" .= actualKnown
269269
, "selectedPeers" .= toJSONList (toList sp)
270270
]
271-
forMachine _dtal (TracePromoteColdLocalPeers tLocalEst aLocalEst sp) =
271+
forMachine _dtal (TracePromoteColdLocalPeers tLocalEst sp) =
272272
mconcat [ "kind" .= String "PromoteColdLocalPeers"
273273
, "targetLocalEstablished" .= tLocalEst
274-
, "actualLocalEstablished" .= aLocalEst
275274
, "selectedPeers" .= toJSONList (toList sp)
276275
]
277276
forMachine _dtal (TracePromoteColdFailed tEst aEst p d err) =

cardano-node/src/Cardano/Node/Tracing/Tracers/Startup.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ ppStartupInfoTrace (NetworkConfig localRoots publicRoots useLedgerAfter) =
512512
pack
513513
$ intercalate "\n"
514514
[ "\nLocal Root Groups:"
515-
, " " ++ intercalate "\n " (map (\(x,y) -> show (x, Map.assocs y))
515+
, " " ++ intercalate "\n " (map (\(x,y,z) -> show (x, y, Map.assocs z))
516516
localRoots)
517517
, "Public Roots:"
518518
, " " ++ intercalate "\n " (map show $ Map.assocs publicRoots)

cardano-node/src/Cardano/Tracing/OrphanInstances/Network.hs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
{-# LANGUAGE PolyKinds #-}
88
{-# LANGUAGE QuantifiedConstraints #-}
99
{-# LANGUAGE ScopedTypeVariables #-}
10+
{-# LANGUAGE StandaloneDeriving #-}
1011
{-# LANGUAGE TypeApplications #-}
1112
{-# LANGUAGE TypeFamilies #-}
1213
{-# LANGUAGE UndecidableInstances #-}
1314

1415
{-# OPTIONS_GHC -Wno-orphans #-}
16+
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
1517

1618
module Cardano.Tracing.OrphanInstances.Network () where
1719

@@ -82,7 +84,8 @@ import Ouroboros.Network.PeerSelection.Governor (DebugPeerSelection (.
8284
TracePeerSelection (..))
8385
import qualified Ouroboros.Network.PeerSelection.KnownPeers as KnownPeers
8486
import Ouroboros.Network.PeerSelection.LedgerPeers
85-
import Ouroboros.Network.PeerSelection.LocalRootPeers (LocalRootPeers)
87+
import Ouroboros.Network.PeerSelection.LocalRootPeers (HotValency (..), LocalRootPeers,
88+
WarmValency (..))
8689
import qualified Ouroboros.Network.PeerSelection.LocalRootPeers as LocalRootPeers
8790
import Ouroboros.Network.PeerSelection.PeerStateActions (PeerSelectionActionsTrace (..))
8891
import Ouroboros.Network.PeerSelection.RootPeersDNS (TraceLocalRootPeers (..),
@@ -425,6 +428,7 @@ instance HasSeverityAnnotation (TracePeerSelection addr) where
425428
TraceGovernorWakeup {} -> Info
426429
TraceChurnWait {} -> Info
427430
TraceChurnMode {} -> Info
431+
TraceKnownInboundConnection {} -> Info
428432

429433
instance HasPrivacyAnnotation (DebugPeerSelection addr)
430434
instance HasSeverityAnnotation (DebugPeerSelection addr) where
@@ -1357,6 +1361,17 @@ instance ToObject peer => ToObject (WithMuxBearer peer MuxTrace) where
13571361

13581362
instance Aeson.ToJSONKey RelayAccessPoint where
13591363

1364+
instance ToJSON HotValency where
1365+
toJSON (HotValency v) = toJSON v
1366+
instance ToJSON WarmValency where
1367+
toJSON (WarmValency v) = toJSON v
1368+
1369+
instance FromJSON HotValency where
1370+
parseJSON v = HotValency <$> parseJSON v
1371+
1372+
instance FromJSON WarmValency where
1373+
parseJSON v = WarmValency <$> parseJSON v
1374+
13601375
instance Show exception => ToObject (TraceLocalRootPeers RemoteAddress exception) where
13611376
toObject _verb (TraceLocalRootDomains groups) =
13621377
mconcat [ "kind" .= String "LocalRootDomains"
@@ -1513,10 +1528,9 @@ instance ToObject (TracePeerSelection SockAddr) where
15131528
, "actualEstablished" .= actualKnown
15141529
, "selectedPeers" .= Aeson.toJSONList (toList sp)
15151530
]
1516-
toObject _verb (TracePromoteColdLocalPeers tLocalEst aLocalEst sp) =
1531+
toObject _verb (TracePromoteColdLocalPeers tLocalEst sp) =
15171532
mconcat [ "kind" .= String "PromoteColdLocalPeers"
15181533
, "targetLocalEstablished" .= tLocalEst
1519-
, "actualLocalEstablished" .= aLocalEst
15201534
, "selectedPeers" .= Aeson.toJSONList (toList sp)
15211535
]
15221536
toObject _verb (TracePromoteColdFailed tEst aEst p d err) =
@@ -1624,6 +1638,10 @@ instance ToObject (TracePeerSelection SockAddr) where
16241638
toObject _verb (TraceChurnMode c) =
16251639
mconcat [ "kind" .= String "ChurnMode"
16261640
, "event" .= show c ]
1641+
toObject _verb (TraceKnownInboundConnection addr sharing) =
1642+
mconcat [ "kind" .= String "KnownInboundConnection"
1643+
, "peer" .= show addr
1644+
, "peerSharing" .= show sharing ]
16271645

16281646
-- Connection manager abstract state. For explanation of each state see
16291647
-- <https://hydra.iohk.io/job/Cardano/ouroboros-network/native.network-docs.x86_64-linux/latest/download/2>

cardano-node/test/Test/Cardano/Node/Gen.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import Cardano.Node.Configuration.TopologyP2P (LocalRootPeersGroup (..
3131
import Cardano.Node.Types (UseLedger (..))
3232
import Cardano.Slotting.Slot (SlotNo (..))
3333
import Ouroboros.Network.PeerSelection.LedgerPeers (UseLedgerAfter (..))
34+
import Ouroboros.Network.PeerSelection.LocalRootPeers (HotValency (..), WarmValency (..))
3435
import Ouroboros.Network.PeerSelection.RelayAccessPoint (DomainAccessPoint (..),
3536
RelayAccessPoint (..))
3637

@@ -175,8 +176,9 @@ genRootConfig = do
175176
genLocalRootPeersGroup :: Gen LocalRootPeersGroup
176177
genLocalRootPeersGroup = do
177178
ra <- genRootConfig
178-
val <- Gen.int (Range.linear 0 (length (rootAccessPoints ra)))
179-
return (LocalRootPeersGroup ra val)
179+
hval <- Gen.int (Range.linear 0 (length (rootAccessPoints ra)))
180+
wval <- WarmValency <$> Gen.int (Range.linear 0 hval)
181+
return (LocalRootPeersGroup ra (HotValency hval) wval)
180182

181183
genLocalRootPeersGroups :: Gen LocalRootPeersGroups
182184
genLocalRootPeersGroups =

cardano-testnet/src/Testnet/Start/Byron.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import Testnet.Process.Run
5959
import Testnet.Property.Assert
6060
import Testnet.Property.Utils
6161

62+
import Ouroboros.Network.PeerSelection.LocalRootPeers (HotValency (..), WarmValency (..))
6263

6364
{- HLINT ignore "Reduce duplication" -}
6465
{- HLINT ignore "Redundant <&>" -}
@@ -181,7 +182,8 @@ mkTopologyConfig i numBftNodes' allPorts True = J.encode topologyP2P
181182
localRootPeerGroups =
182183
P2P.LocalRootPeersGroups
183184
[ P2P.LocalRootPeersGroup rootConfig
184-
(numBftNodes' - 1)
185+
(HotValency (numBftNodes' - 1))
186+
(WarmValency (numBftNodes' - 1))
185187
]
186188

187189
topologyP2P :: P2P.NetworkTopology

cardano-testnet/src/Testnet/Start/Cardano.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ import Testnet.Runtime as TR
7070
import Testnet.Start.Byron hiding (TestnetOptions (..))
7171
import Testnet.Start.Shelley
7272

73+
import Ouroboros.Network.PeerSelection.LocalRootPeers (HotValency (..), WarmValency (..))
74+
7375
{- HLINT ignore "Redundant flip" -}
7476
{- HLINT ignore "Redundant id" -}
7577
{- HLINT ignore "Use let" -}
@@ -173,7 +175,8 @@ mkTopologyConfig numNodes allPorts port True = J.encode topologyP2P
173175
localRootPeerGroups =
174176
P2P.LocalRootPeersGroups
175177
[ P2P.LocalRootPeersGroup rootConfig
176-
(numNodes - 1)
178+
(HotValency (numNodes - 1))
179+
(WarmValency (numNodes - 1))
177180
]
178181

179182
topologyP2P :: P2P.NetworkTopology

cardano-testnet/src/Testnet/Start/Shelley.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ import Testnet.Process.Run
6666
import Testnet.Property.Assert
6767
import Testnet.Runtime hiding (allNodes)
6868

69+
import Ouroboros.Network.PeerSelection.LocalRootPeers (HotValency (..), WarmValency (..))
70+
6971

7072
{- HLINT ignore "Redundant <&>" -}
7173
{- HLINT ignore "Redundant flip" -}
@@ -145,7 +147,8 @@ mkTopologyConfig numPraosNodes allPorts port True = J.encode topologyP2P
145147
localRootPeerGroups =
146148
P2P.LocalRootPeersGroups
147149
[ P2P.LocalRootPeersGroup rootConfig
148-
(numPraosNodes - 1)
150+
(HotValency (numPraosNodes - 1))
151+
(WarmValency (numPraosNodes - 1))
149152
]
150153

151154
topologyP2P :: P2P.NetworkTopology

0 commit comments

Comments
 (0)