Skip to content

Commit

Permalink
This patch updates cardano-node
Browse files Browse the repository at this point in the history
with changes in ouroboros-network api.
Changes includes:
- new format for topology files
- new configuration options:
    * RespondersIdleTimeout
    * ProtocolIdleTimeout
    * WaitTimeTimeout
    * TargetNumberOfRootPeers
    * TargetNumberOfKnownPeers
    * TargetNumberOfEstablishedPeers
    * TargetNumberOfActivePeers
- new tracers
    * LocalRootPeers
    * PeerSelection
    * DebugPeerSelection
    * PeerSelectionActons
    * ConnectionManager
    * InboundGovernor (Armando)
    * PeerSelectionCounters (Armando)
- old tracers where removed

ConnectionManager tracer

* it was turned off if ekg direct was defined
* renamed "numberConns" from ConnectionManagerCounters to "prunableConns"  (in ekg)

- leave a thunk in the Mark snapshot
- cardano-node using p2p-governor and connection manager

Inbound Governor Tracers

* Added new constructors
* Removed ekg established counter

- connection-manager: dump state on SIGUSR1
- Fixed trace severity (#3176)
- update ouroboros-network
  • Loading branch information
coot authored and karknu committed Sep 8, 2021
1 parent 4c59442 commit 0b1ea7c
Show file tree
Hide file tree
Showing 20 changed files with 1,308 additions and 281 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ import Ouroboros.Network.DeltaQ (defaultGSV)
import Ouroboros.Network.Driver (runPeerWithLimits)
import Ouroboros.Network.KeepAlive
import Ouroboros.Network.Magic
import Ouroboros.Network.Mux (MuxPeer (..), RunMiniProtocol (..), continueForever)
import Ouroboros.Network.Mux (MuxPeer (..), OuroborosApplication (..),
OuroborosBundle, RunMiniProtocol (..),
continueForever)
import Ouroboros.Network.NodeToClient (chainSyncPeerNull, IOManager)
import Ouroboros.Network.NodeToNode (NetworkConnectTracers (..))
import qualified Ouroboros.Network.NodeToNode as NtN
Expand Down Expand Up @@ -80,6 +82,12 @@ benchmarkConnectTxSubmit ioManager handshakeTracer submissionTracer codecConfig
(addrAddress <$> Nothing)
(addrAddress remoteAddr)
where
mkApp :: OuroborosBundle mode addr bs m a b
-> OuroborosApplication mode addr bs m a b
mkApp bundle =
OuroborosApplication $ \connId controlMessageSTM ->
foldMap (\p -> p connId controlMessageSTM) bundle

n2nVer :: NodeToNodeVersion
n2nVer = NodeToNodeV_7
blkN2nVer :: BlockNodeToNodeVersion blk
Expand All @@ -96,6 +104,7 @@ benchmarkConnectTxSubmit ioManager handshakeTracer submissionTracer codecConfig
{ NtN.networkMagic = networkMagic
, NtN.diffusionMode = NtN.InitiatorOnlyDiffusionMode
}) $
mkApp $
NtN.nodeToNodeProtocols NtN.defaultMiniProtocolParameters ( \them _ ->
NtN.NodeToNodeProtocols
{ NtN.chainSyncProtocol = InitiatorProtocolOnly $
Expand Down
5 changes: 3 additions & 2 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ source-repository-package
source-repository-package
type: git
location: https://github.com/input-output-hk/ouroboros-network
tag: 877ce057ff6fb086474c8eaad53f2b7f0e0fce6b
--sha256: 1kp0qysfy3hl96a3a61rijascq36f1imh3z4jy0vyiygb6qrv47z
tag: a6d84582d8516f894c1607c3f4d70a8c60239f74
--sha256: 1narqq9qxz8hf1mspvwrr2l26497c1906l2y1db2sa8b6v8lr9sq
subdir:
io-sim
io-classes
Expand All @@ -229,6 +229,7 @@ source-repository-package
ouroboros-network-framework
ouroboros-network-testing
typed-protocols
typed-protocols-cborg
typed-protocols-examples

source-repository-package
Expand Down
2 changes: 1 addition & 1 deletion cardano-api/src/Cardano/Api/IPC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ connectToLocalNodeWithVersion LocalNodeConnectInfo {
} clients =
Net.withIOManager $ \iomgr ->
Net.connectTo
(Net.localSnocket iomgr localNodeSocketPath)
(Net.localSnocket iomgr)
Net.NetworkConnectTracers {
Net.nctMuxTracer = nullTracer,
Net.nctHandshakeTracer = nullTracer
Expand Down
1 change: 1 addition & 0 deletions cardano-node/cardano-node.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ library
, tracer-transformers
, transformers
, transformers-except
, typed-protocols
, unordered-containers
, yaml

Expand Down
73 changes: 73 additions & 0 deletions cardano-node/src/Cardano/Node/Configuration/POM.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import Prelude (String)

import Control.Monad (fail)
import Data.Aeson
import Data.Time.Clock (DiffTime)
import Data.Yaml (decodeFileThrow)
import Generic.Data (gmappend)
import Generic.Data.Orphans ()
Expand Down Expand Up @@ -83,6 +84,21 @@ data NodeConfiguration
, ncLoggingSwitch :: !Bool
, ncLogMetrics :: !Bool
, ncTraceConfig :: !TraceOptions

-- | Protocol idleness timeout, see
-- 'Ouroboros.Network.Diffusion.daProtocolIdleTimeout'.
--
, ncProtocolIdleTimeout :: DiffTime
-- | Wait time timeout, see
-- 'Ouroboros.Netowrk.Diffusion.daTimeWaitTimeout'.
--
, ncTimeWaitTimeout :: DiffTime

-- P2P governor targets
, ncTargetNumberOfRootPeers :: Int
, ncTargetNumberOfKnownPeers :: Int
, ncTargetNumberOfEstablishedPeers :: Int
, ncTargetNumberOfActivePeers :: Int
} deriving (Eq, Show)


Expand Down Expand Up @@ -119,6 +135,16 @@ data PartialNodeConfiguration
, pncLoggingSwitch :: !(Last Bool)
, pncLogMetrics :: !(Last Bool)
, pncTraceConfig :: !(Last TraceOptions)

-- Network timeouts
, pncProtocolIdleTimeout :: !(Last DiffTime)
, pncTimeWaitTimeout :: !(Last DiffTime)

-- P2P governor targets
, pncTargetNumberOfRootPeers :: !(Last Int)
, pncTargetNumberOfKnownPeers :: !(Last Int)
, pncTargetNumberOfEstablishedPeers :: !(Last Int)
, pncTargetNumberOfActivePeers :: !(Last Int)
} deriving (Eq, Generic, Show)

instance AdjustFilePaths PartialNodeConfiguration where
Expand Down Expand Up @@ -167,6 +193,17 @@ instance FromJSON PartialNodeConfiguration where
<*> parseShelleyProtocol v
<*> parseAlonzoProtocol v
<*> parseHardForkProtocol v)
-- Network timeouts
pncProtocolIdleTimeout <- Last <$> v .:? "ProtocolIdleTimeout"
pncTimeWaitTimeout <- Last <$> v .:? "TimeWaitTimeout"

-- P2P Governor parameters, with conservative defaults.
pncTargetNumberOfRootPeers <- Last <$> v .:? "TargetNumberOfRootPeers"
pncTargetNumberOfKnownPeers <- Last <$> v .:? "TargetNumberOfKnownPeers"
pncTargetNumberOfEstablishedPeers <- Last <$> v .:? "TargetNumberOfEstablishedPeers"
pncTargetNumberOfActivePeers <- Last <$> v .:? "TargetNumberOfActivePeers"


pure PartialNodeConfiguration {
pncProtocolConfig
, pncSocketPath
Expand All @@ -188,6 +225,12 @@ instance FromJSON PartialNodeConfiguration where
, pncValidateDB = mempty
, pncShutdownIPC = mempty
, pncShutdownOnSlotSynced = mempty
, pncProtocolIdleTimeout
, pncTimeWaitTimeout
, pncTargetNumberOfRootPeers
, pncTargetNumberOfKnownPeers
, pncTargetNumberOfEstablishedPeers
, pncTargetNumberOfActivePeers
}
where
parseByronProtocol v = do
Expand Down Expand Up @@ -309,6 +352,12 @@ defaultPartialNodeConfiguration =
, pncMaxConcurrencyDeadline = mempty
, pncLogMetrics = mempty
, pncTraceConfig = mempty
, pncProtocolIdleTimeout = Last (Just 5)
, pncTimeWaitTimeout = Last (Just 60)
, pncTargetNumberOfRootPeers = Last (Just 5)
, pncTargetNumberOfKnownPeers = Last (Just 5)
, pncTargetNumberOfEstablishedPeers = Last (Just 2)
, pncTargetNumberOfActivePeers = Last (Just 1)
}

lastOption :: Parser a -> Parser (Last a)
Expand All @@ -332,6 +381,24 @@ makeNodeConfiguration pnc = do
traceConfig <- lastToEither "Missing TraceConfig" $ pncTraceConfig pnc
diffusionMode <- lastToEither "Missing DiffusionMode" $ pncDiffusionMode pnc
snapshotInterval <- lastToEither "Missing SnapshotInterval" $ pncSnapshotInterval pnc
ncTargetNumberOfRootPeers <-
lastToEither "Missing TargetNumberOfRootPeers"
$ pncTargetNumberOfRootPeers pnc
ncTargetNumberOfKnownPeers <-
lastToEither "Missing TargetNumberOfKnownPeers"
$ pncTargetNumberOfKnownPeers pnc
ncTargetNumberOfEstablishedPeers <-
lastToEither "Missing TargetNumberOfEstablishedPeers"
$ pncTargetNumberOfEstablishedPeers pnc
ncTargetNumberOfActivePeers <-
lastToEither "Missing TargetNumberOfActivePeers"
$ pncTargetNumberOfActivePeers pnc
ncProtocolIdleTimeout <-
lastToEither "Missing ProtocolIdleTimeout"
$ pncProtocolIdleTimeout pnc
ncTimeWaitTimeout <-
lastToEither "Missing TimeWaitTimeout"
$ pncTimeWaitTimeout pnc

testEnableDevelopmentNetworkProtocols <-
lastToEither "Missing TestEnableDevelopmentNetworkProtocols" $
Expand All @@ -358,6 +425,12 @@ makeNodeConfiguration pnc = do
, ncLogMetrics = logMetrics
, ncTraceConfig = if loggingSwitch then traceConfig
else TracingOff
, ncProtocolIdleTimeout
, ncTimeWaitTimeout
, ncTargetNumberOfRootPeers
, ncTargetNumberOfKnownPeers
, ncTargetNumberOfEstablishedPeers
, ncTargetNumberOfActivePeers
}

ncProtocol :: NodeConfiguration -> Protocol
Expand Down
72 changes: 47 additions & 25 deletions cardano-node/src/Cardano/Node/Configuration/Topology.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}

module Cardano.Node.Configuration.Topology
Expand All @@ -8,6 +9,8 @@ module Cardano.Node.Configuration.Topology
, NodeHostIPv6Address(..)
, NodeSetup(..)
, RemoteAddress(..)
, PeerAdvertise(..)
, UseLedger(..)
, nodeAddressToSockAddr
, readTopologyFile
, remoteAddressToNodeAddress
Expand All @@ -24,8 +27,11 @@ import qualified Data.ByteString.Lazy.Char8 as LBS
import qualified Data.Text as Text

import Cardano.Node.Configuration.POM (NodeConfiguration (..))
import Cardano.Slotting.Slot (SlotNo (..))
import Cardano.Node.Types

import Ouroboros.Network.NodeToNode (PeerAdvertise (..))
import Ouroboros.Network.PeerSelection.LedgerPeers (UseLedgerAfter (..))
import Ouroboros.Consensus.Util.Condense (Condense (..))


Expand All @@ -40,29 +46,25 @@ data RemoteAddress = RemoteAddress
-- ^ Either a dns address or an ip address.
, raPort :: !PortNumber
-- ^ Port number of the destination.
, raValency :: !Int
, raAdvertise :: !PeerAdvertise
-- ^ Advertise the peer through gossip protocol.
-- ^ If a DNS address is given valency governs
-- to how many resolved IP addresses
-- should we maintain active (hot) connection;
-- if an IP address is given valency is used as
-- a Boolean value, @0@ means to ignore the address;
} deriving (Eq, Ord, Show)
} deriving (Eq, Show)


-- | Parse 'raAddress' field as an IP address; if it parses and the valency is
-- non zero return corresponding NodeAddress.
--
remoteAddressToNodeAddress
:: RemoteAddress
-> Maybe (Either NodeIPAddress
(NodeDnsAddress, Int))
remoteAddressToNodeAddress (RemoteAddress _addrText _port 0) =
Nothing
remoteAddressToNodeAddress (RemoteAddress addrText port valency) =
case readMaybe (Text.unpack addrText) of
Nothing -> Just $ Right (NodeAddress (NodeHostDnsAddress addrText) port
, valency)
Just addr -> Just $ Left (NodeAddress (NodeHostIPAddress addr) port)
-> Either (NodeIPAddress, PeerAdvertise)
(NodeDnsAddress, PeerAdvertise)
remoteAddressToNodeAddress RemoteAddress { raAddress, raPort, raAdvertise } =
case readMaybe (Text.unpack raAddress) of
Nothing -> Right ( NodeAddress (NodeHostDnsAddress raAddress) raPort
, raAdvertise )
Just addr -> Left ( NodeAddress (NodeHostIPAddress addr) raPort
, raAdvertise )


instance Condense RemoteAddress where
Expand All @@ -74,30 +76,46 @@ instance FromJSON RemoteAddress where
RemoteAddress
<$> v .: "addr"
<*> ((fromIntegral :: Int -> PortNumber) <$> v .: "port")
<*> v .: "valency"
<*> (bool DoNotAdvertisePeer DoAdvertisePeer <$> v .: "advertise")

instance ToJSON RemoteAddress where
toJSON ra =
object
[ "addr" .= raAddress ra
, "port" .= (fromIntegral (raPort ra) :: Int)
, "valency" .= raValency ra
, "advertise" .= case raAdvertise ra of
DoNotAdvertisePeer -> False
DoAdvertisePeer -> True
]

newtype UseLedger = UseLedger UseLedgerAfter deriving (Eq, Show)

instance FromJSON UseLedger where
parseJSON (Data.Aeson.Number n) =
if n >= 0 then return $ UseLedger $ UseLedgerAfter $ SlotNo $ floor n
else return $ UseLedger DontUseLedger
parseJSON _ = mzero

instance ToJSON UseLedger where
toJSON (UseLedger (UseLedgerAfter (SlotNo n))) = Number $ fromIntegral n
toJSON (UseLedger DontUseLedger) = Number (-1)

data NodeSetup = NodeSetup
{ nodeId :: !Word64
, nodeIPv4Address :: !(Maybe NodeIPv4Address)
, nodeIPv6Address :: !(Maybe NodeIPv6Address)
, producers :: ![RemoteAddress]
, useLedger :: !UseLedger
} deriving (Eq, Show)

instance FromJSON NodeSetup where
parseJSON = withObject "NodeSetup" $ \o ->
NodeSetup
<$> o .: "nodeId"
<*> o .: "nodeIPv4Address"
<*> o .: "nodeIPv6Address"
<*> o .: "producers"
<$> o .: "nodeId"
<*> o .: "nodeIPv4Address"
<*> o .: "nodeIPv6Address"
<*> o .: "producers"
<*> o .:? "useLedgerAfterSlot" .!= UseLedger DontUseLedger

instance ToJSON NodeSetup where
toJSON ns =
Expand All @@ -106,23 +124,27 @@ instance ToJSON NodeSetup where
, "nodeIPv4Address" .= nodeIPv4Address ns
, "nodeIPv6Address" .= nodeIPv6Address ns
, "producers" .= producers ns
, "useLedgerAfterSlot" .= useLedger ns
]

data NetworkTopology = MockNodeTopology ![NodeSetup]
| RealNodeTopology ![RemoteAddress]
| RealNodeTopology ![RemoteAddress] !UseLedger
deriving (Eq, Show)

instance FromJSON NetworkTopology where
parseJSON = withObject "NetworkTopology" $ \o -> asum
[ MockNodeTopology <$> o .: "MockProducers"
, RealNodeTopology <$> o .: "Producers"
[ MockNodeTopology <$> o .: "MockProducers"
, RealNodeTopology <$> o .: "Producers"
<*> o .:? "useLedgerAfterSlot" .!= UseLedger DontUseLedger
]

instance ToJSON NetworkTopology where
toJSON top =
case top of
MockNodeTopology nss -> object [ "MockProducers" .= toJSON nss ]
RealNodeTopology ras -> object [ "Producers" .= toJSON ras ]
RealNodeTopology ras ul -> object [ "Producers" .= toJSON ras
, "useLedgerAfterSlot" .= toJSON ul
]

-- | Read the `NetworkTopology` configuration from the specified file.
-- While running a real protocol, this gives your node its own address and
Expand Down
6 changes: 6 additions & 0 deletions cardano-node/src/Cardano/Node/Parsers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ nodeRunParser = do
, pncLoggingSwitch = mempty
, pncLogMetrics = mempty
, pncTraceConfig = mempty
, pncProtocolIdleTimeout = mempty
, pncTimeWaitTimeout = mempty
, pncTargetNumberOfRootPeers = mempty
, pncTargetNumberOfKnownPeers = mempty
, pncTargetNumberOfEstablishedPeers = mempty
, pncTargetNumberOfActivePeers = mempty
}

parseSocketPath :: Text -> Parser SocketPath
Expand Down
Loading

0 comments on commit 0b1ea7c

Please sign in to comment.