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

Use JSON instances for NodeToNodeVersion & NodeToClientVersion #4691

Merged
merged 6 commits into from
Mar 26, 2023
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
31 changes: 31 additions & 0 deletions cardano-node/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,37 @@

### network changes

## 1.35.6 -- March 2023

### consensus changes

None

### ledger changes

None

### network changes

- 'EnableP2P' configuration option does not require
'TestEnableDevelopmentNetworkProtocols' any more. We support running at most
one p2p relay, if an SPO is running at least two relays.

- Added 'DemoteLocalAsynchronous' warning trace. It indicates that a remote
local root peer was demoted to cold (either due to connection error or
misbehaviour). (input-output-hk/ouroboros-network#4127)

- New P2P topology file format, see [issue #4563][#4563] or the [config
files][understanding-config-files] documentation. The old p2p topology
format will be supported for next two major releases of the node (the last
major version which will support it is `1.37`). (#4563)

- Fixed a tight loop when demoting a peer from hot to warm timeouts
(input-output-hk/ouroboros-network#4357).

[#4563]: https://github.com/input-output-hk/cardano-node/issues/4563
[understanding-config-files]: https://github.com/input-output-hk/cardano-node/blob/master/doc/getting-started/understanding-config-files.md

## 1.35.5 -- November 2022

### node changes
Expand Down
17 changes: 9 additions & 8 deletions cardano-node/src/Cardano/Node/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -492,11 +492,7 @@ handleSimpleNode runP p2pMode tracers nc onKernel = do
logStartupWarnings = do
(case p2pMode of
DisabledP2PMode -> return ()
EnabledP2PMode -> do
traceWith (startupTracer tracers) P2PWarning
unless (ncTestEnableDevelopmentNetworkProtocols nc)
$ traceWith (startupTracer tracers)
P2PWarningDevelopementNetworkProtocols
EnabledP2PMode -> traceWith (startupTracer tracers) P2PWarning
) :: IO () -- annoying, but unavoidable for GADT type inference

let developmentNtnVersions =
Expand All @@ -514,10 +510,15 @@ handleSimpleNode runP p2pMode tracers nc onKernel = do
(_, Nothing) -> Map.keys
$ supportedNodeToClientVersions (Proxy @blk)
when ( ncTestEnableDevelopmentNetworkProtocols nc
coot marked this conversation as resolved.
Show resolved Hide resolved
&& (not (null developmentNtnVersions) || not (null developmentNtcVersions)) )
&& not (null developmentNtnVersions))
$ traceWith (startupTracer tracers)
(WarningDevelopmentNetworkProtocols
developmentNtnVersions
(WarningDevelopmentNodeToNodeVersions
developmentNtnVersions)

when ( ncTestEnableDevelopmentNetworkProtocols nc
&& not (null developmentNtcVersions))
$ traceWith (startupTracer tracers)
(WarningDevelopmentNodeToClientVersions
developmentNtcVersions)

#ifdef UNIX
Expand Down
11 changes: 6 additions & 5 deletions cardano-node/src/Cardano/Node/Startup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,15 @@ data StartupTrace blk =
-- | Warn when 'EnableP2P' is set.
| P2PWarning

-- | Warn that peer-to-peer requires
-- 'TestEnableDevelopmentNetworkProtocols' to be set.
-- | Warn when 'TestEnableDevelopmentNetworkProtocols' is set and affects
-- node-to-node protocol.
--
| P2PWarningDevelopementNetworkProtocols
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean we no longer need the TestEnableDevelopmentNetworkProtocols flag?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't, but we might need it again in the future, so I think it's ok to keep it. There's no difference (for the user) if we parse it and not use it or not parse it at all.

| WarningDevelopmentNodeToNodeVersions [NodeToNodeVersion]

-- | Warn when 'TestEnableDevelopmentNetworkProtocols' is set.
-- | Warn when 'TestEnableDevelopmentNetworkProtocols' is set and affects
-- node-to-client protocol.
--
| WarningDevelopmentNetworkProtocols [NodeToNodeVersion] [NodeToClientVersion]
| WarningDevelopmentNodeToClientVersions [NodeToClientVersion]

| BICommon BasicInfoCommon
| BIShelley BasicInfoShelleyBased
Expand Down
20 changes: 7 additions & 13 deletions cardano-node/src/Cardano/Node/Tracing/StateRep.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE StandaloneDeriving #-}

{-# OPTIONS_GHC -Wno-orphans #-}

Expand Down Expand Up @@ -74,20 +73,14 @@ data AddedToCurrentChain
= AddedToCurrentChain !EpochNo !SlotNo !SyncPercentage
deriving (Generic, FromJSON, ToJSON)

deriving instance Generic NPV.NodeToClientVersion
coot marked this conversation as resolved.
Show resolved Hide resolved
deriving instance Generic NPV.NodeToNodeVersion

instance FromJSON NPV.NodeToClientVersion
instance FromJSON NPV.NodeToNodeVersion

data StartupState
= StartupSocketConfigError Text
| StartupDBValidation
| NetworkConfigUpdate
| NetworkConfigUpdateError Text
| P2PWarning
| P2PWarningDevelopementNetworkProtocols
| WarningDevelopmentNetworkProtocols [NPV.NodeToNodeVersion] [NPV.NodeToClientVersion]
| WarningDevelopmentNodeToNodeVersions [NPV.NodeToNodeVersion]
| WarningDevelopmentNodeToClientVersions [NPV.NodeToClientVersion]
deriving (Generic, FromJSON, ToJSON)

-- | The representation of the current state of node.
Expand Down Expand Up @@ -257,10 +250,11 @@ traceNodeStateStartup tr ev =
traceWith tr $ NodeStartup $ NetworkConfigUpdateError e
Startup.P2PWarning ->
traceWith tr $ NodeStartup P2PWarning
Startup.P2PWarningDevelopementNetworkProtocols ->
traceWith tr $ NodeStartup P2PWarningDevelopementNetworkProtocols
Startup.WarningDevelopmentNetworkProtocols n2ns n2cs ->
traceWith tr $ NodeStartup $ WarningDevelopmentNetworkProtocols n2ns n2cs
Startup.WarningDevelopmentNodeToNodeVersions ntnVersions ->
traceWith tr $ NodeStartup (WarningDevelopmentNodeToNodeVersions ntnVersions)
Startup.WarningDevelopmentNodeToClientVersions ntcVersions ->
traceWith tr $ NodeStartup (WarningDevelopmentNodeToClientVersions ntcVersions)
-- TODO: why other constructors are not traced?
coot marked this conversation as resolved.
Show resolved Hide resolved
_ -> return ()

traceNodeStateShutdown
Expand Down
81 changes: 50 additions & 31 deletions cardano-node/src/Cardano/Node/Tracing/Tracers/Startup.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RecordWildCards #-}
Expand All @@ -17,6 +18,7 @@ import qualified Cardano.Api as Api
import Prelude

import Data.Aeson (ToJSON (..), Value (..), (.=))
import qualified Data.Aeson as Aeson
import Data.List (intercalate)
import qualified Data.Map.Strict as Map
import Data.Text (Text, pack)
Expand Down Expand Up @@ -121,6 +123,27 @@ getStartupInfo nc (SomeConsensusProtocol whichP pForInfo) fp = do
-- -- StartupInfo Tracer
-- --------------------------------------------------------------------------------


-- | A tuple of consensus and network versions. It's used to derive a custom
-- `FromJSON` and `ToJSON` instances.
--
data ConsensusNetworkVersionTuple a b = ConsensusNetworkVersionTuple a b

-- TODO: provide JSON instance for `BlockNodeToClientVersion`
instance Show blkVersion => ToJSON (ConsensusNetworkVersionTuple NodeToClientVersion blkVersion) where
toJSON (ConsensusNetworkVersionTuple nodeToClientVersion blockVersion) =
Aeson.object [ "nodeToClientVersion" .= toJSON nodeToClientVersion
, "blockVersion" .= String (pack . show $ blockVersion)
coot marked this conversation as resolved.
Show resolved Hide resolved
]

-- TODO: provide JSON instance for `BlockNodeToNodeVersion`
instance Show blkVersion => ToJSON (ConsensusNetworkVersionTuple NodeToNodeVersion blkVersion) where
toJSON (ConsensusNetworkVersionTuple nodeToClientVersion blockVersion) =
Aeson.object [ "nodeToNodeVersion" .= toJSON nodeToClientVersion
, "blockVersion" .= String (pack . show $ blockVersion)
]


instance ( Show (BlockNodeToNodeVersion blk)
, Show (BlockNodeToClientVersion blk)
)
Expand All @@ -142,9 +165,9 @@ instance ( Show (BlockNodeToNodeVersion blk)
case dtal of
DMaximum ->
[ "nodeToNodeVersions" .=
toJSON (map show . Map.assocs $ supportedNodeToNodeVersions)
toJSON (map (uncurry ConsensusNetworkVersionTuple) . Map.assocs $ supportedNodeToNodeVersions)
, "nodeToClientVersions" .=
toJSON (map show . Map.assocs $ supportedNodeToClientVersions)
toJSON (map (uncurry ConsensusNetworkVersionTuple) . Map.assocs $ supportedNodeToClientVersions)
]
_ ->
[ "maxNodeToNodeVersion" .=
Expand Down Expand Up @@ -199,14 +222,15 @@ instance ( Show (BlockNodeToNodeVersion blk)
forMachine _dtal P2PWarning =
mconcat [ "kind" .= String "P2PWarning"
, "message" .= String p2pWarningMessage ]
forMachine _dtal P2PWarningDevelopementNetworkProtocols =
mconcat [ "kind" .= String "P2PWarningDevelopementNetworkProtocols"
, "message" .= String p2pWarningDevelopmentNetworkProtocolsMessage ]
forMachine _ver (WarningDevelopmentNetworkProtocols ntnVersions ntcVersions) =
mconcat [ "kind" .= String "WarningDevelopmentNetworkProtocols"
forMachine _ver (WarningDevelopmentNodeToNodeVersions ntnVersions) =
mconcat [ "kind" .= String "WarningDevelopmentNodeToNodeVersions"
, "message" .= String "enabled development network protocols"
, "nodeToNodeDevelopmentVersions" .= String (showT ntnVersions)
, "nodeToClientDevelopmentVersions" .= String (showT ntcVersions)
, "versions" .= String (showT ntnVersions)
]
forMachine _ver (WarningDevelopmentNodeToClientVersions ntcVersions) =
mconcat [ "kind" .= String "WarningDevelopmentNodeToClientVersions"
, "message" .= String "enabled development network protocols"
, "versions" .= String (showT ntcVersions)
]
forMachine _dtal (BINetwork BasicInfoNetwork {..}) =
mconcat [ "kind" .= String "BasicInfoNetwork"
Expand Down Expand Up @@ -264,10 +288,10 @@ instance MetaTrace (StartupTrace blk) where
Namespace [] ["NetworkConfigLegacy"]
namespaceFor P2PWarning {} =
Namespace [] ["P2PWarning"]
namespaceFor P2PWarningDevelopementNetworkProtocols {} =
Namespace [] ["P2PWarningDevelopementNetworkProtocols"]
namespaceFor WarningDevelopmentNetworkProtocols {} =
Namespace [] ["WarningDevelopmentNetworkProtocols"]
namespaceFor WarningDevelopmentNodeToNodeVersions {} =
Namespace [] ["WarningDevelopmentNodeToNodeVersions"]
namespaceFor WarningDevelopmentNodeToClientVersions {} =
Namespace [] ["WarningDevelopmentNodeToClientVersions"]
namespaceFor BICommon {} =
Namespace [] ["Common"]
namespaceFor BIShelley {} =
Expand All @@ -282,8 +306,8 @@ instance MetaTrace (StartupTrace blk) where
severityFor (Namespace _ ["NetworkConfigUpdateError"]) _ = Just Error
severityFor (Namespace _ ["NetworkConfigUpdateUnsupported"]) _ = Just Warning
severityFor (Namespace _ ["P2PWarning"]) _ = Just Warning
severityFor (Namespace _ ["P2PWarningDevelopementNetworkProtocols"]) _ = Just Warning
severityFor (Namespace _ ["WarningDevelopmentNetworkProtocols"]) _ = Just Warning
severityFor (Namespace _ ["WarningDevelopmentNodeToNodeVersions"]) _ = Just Warning
severityFor (Namespace _ ["WarningDevelopmentNodeToClientVersions"]) _ = Just Warning
severityFor _ _ = Just Info

documentFor (Namespace [] ["Info"]) = Just
Expand All @@ -310,9 +334,9 @@ instance MetaTrace (StartupTrace blk) where
""
documentFor (Namespace [] ["P2PWarning"]) = Just
""
documentFor (Namespace [] ["P2PWarningDevelopementNetworkProtocols"]) = Just
documentFor (Namespace [] ["WarningDevelopmentNodeToNodeVersions"]) = Just
""
documentFor (Namespace [] ["WarningDevelopmentNetworkProtocols"]) = Just
documentFor (Namespace [] ["WarningDevelopmentNodeToClientVersions"]) = Just
""
documentFor (Namespace [] ["Common"]) = Just $ mconcat
[ "_biConfigPath_: is the path to the config in use. "
Expand Down Expand Up @@ -358,8 +382,8 @@ instance MetaTrace (StartupTrace blk) where
, Namespace [] ["NetworkConfig"]
, Namespace [] ["NetworkConfigLegacy"]
, Namespace [] ["P2PWarning"]
, Namespace [] ["P2PWarningDevelopementNetworkProtocols"]
, Namespace [] ["WarningDevelopmentNetworkProtocols"]
, Namespace [] ["WarningDevelopmentNodeToNodeVersions"]
, Namespace [] ["WarningDevelopmentNodeToClientVersions"]
, Namespace [] ["Common"]
, Namespace [] ["ShelleyBased"]
, Namespace [] ["Byron"]
Expand Down Expand Up @@ -441,13 +465,12 @@ ppStartupInfoTrace NetworkConfigLegacy = p2pNetworkConfigLegacyMessage

ppStartupInfoTrace P2PWarning = p2pWarningMessage

ppStartupInfoTrace P2PWarningDevelopementNetworkProtocols =
p2pWarningDevelopmentNetworkProtocolsMessage

ppStartupInfoTrace (WarningDevelopmentNetworkProtocols ntnVersions ntcVersions) =
"enabled development network protocols: "
ppStartupInfoTrace (WarningDevelopmentNodeToNodeVersions ntnVersions) =
"enabled development node-to-node versions: "
<> showT ntnVersions
<> " "

ppStartupInfoTrace (WarningDevelopmentNodeToClientVersions ntcVersions) =
"enabled development node-to-client versions: "
<> showT ntcVersions

ppStartupInfoTrace (BINetwork BasicInfoNetwork {..}) =
Expand Down Expand Up @@ -477,12 +500,8 @@ ppStartupInfoTrace (BICommon BasicInfoCommon {..}) =

p2pWarningMessage :: Text
p2pWarningMessage =
"unsupported and unverified version of "
<> "`cardano-node` with peer-to-peer networking capabilities"

p2pWarningDevelopmentNetworkProtocolsMessage :: Text
p2pWarningDevelopmentNetworkProtocolsMessage =
"peer-to-peer requires TestEnableDevelopmentNetworkProtocols to be set to True"
"You are using an early release of peer-to-peer capabilities, "
<> "please report any issues."

p2pNetworkConfigLegacyMessage :: Text
p2pNetworkConfigLegacyMessage =
Expand Down
40 changes: 35 additions & 5 deletions cardano-node/src/Cardano/Tracing/OrphanInstances/Network.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module Cardano.Tracing.OrphanInstances.Network () where

import Control.Exception (Exception (..), SomeException (..))
import Control.Monad.Class.MonadTime (DiffTime, Time (..))
import Data.Aeson (Value (..))
import Data.Aeson (Value (..), FromJSON (..))
import qualified Data.Aeson as Aeson
import Data.Aeson.Types (listValue)
import Data.Bifunctor (Bifunctor (..))
Expand Down Expand Up @@ -67,9 +67,9 @@ import qualified Ouroboros.Network.InboundGovernor as InboundGovernor
import Ouroboros.Network.InboundGovernor.State (InboundGovernorCounters (..))
import Ouroboros.Network.KeepAlive (TraceKeepAliveClient (..))
import Ouroboros.Network.Magic (NetworkMagic (..))
import Ouroboros.Network.NodeToClient (NodeToClientVersion, NodeToClientVersionData (..))
import Ouroboros.Network.NodeToClient (NodeToClientVersion (..), NodeToClientVersionData (..))
import qualified Ouroboros.Network.NodeToClient as NtC
import Ouroboros.Network.NodeToNode (ErrorPolicyTrace (..), NodeToNodeVersion,
import Ouroboros.Network.NodeToNode (ErrorPolicyTrace (..), NodeToNodeVersion (..),
NodeToNodeVersionData (..), RemoteAddress, TraceSendRecv (..), WithAddr (..))
import qualified Ouroboros.Network.NodeToNode as NtN
import qualified Ouroboros.Network.PeerSelection.EstablishedPeers as EstablishedPeers
Expand Down Expand Up @@ -1756,10 +1756,40 @@ instance Show vNumber => ToJSON (HandshakeException vNumber) where
]

instance ToJSON NodeToNodeVersion where
toJSON x = String (pack $ show x)
toJSON NodeToNodeV_7 = Number 7
toJSON NodeToNodeV_8 = Number 8
toJSON NodeToNodeV_9 = Number 9
toJSON NodeToNodeV_10 = Number 10
toJSON NodeToNodeV_11 = Number 11

instance FromJSON NodeToNodeVersion where
parseJSON (Number 7) = return NodeToNodeV_7
parseJSON (Number 8) = return NodeToNodeV_8
parseJSON (Number 9) = return NodeToNodeV_9
parseJSON (Number 10) = return NodeToNodeV_10
parseJSON (Number 11) = return NodeToNodeV_11
parseJSON (Number x) = fail ("FromJSON.NodeToNodeVersion: unsupported node-to-node protocol version " ++ show x)
parseJSON x = fail ("FromJSON.NodeToNodeVersion: error parsing NodeToNodeVersion: " ++ show x)

instance ToJSON NodeToClientVersion where
toJSON x = String (pack $ show x)
toJSON NodeToClientV_9 = Number 9
toJSON NodeToClientV_10 = Number 10
toJSON NodeToClientV_11 = Number 11
toJSON NodeToClientV_12 = Number 12
toJSON NodeToClientV_13 = Number 13
toJSON NodeToClientV_14 = Number 14
toJSON NodeToClientV_15 = Number 15

instance FromJSON NodeToClientVersion where
parseJSON (Number 9) = return NodeToClientV_9
parseJSON (Number 10) = return NodeToClientV_10
parseJSON (Number 11) = return NodeToClientV_11
parseJSON (Number 12) = return NodeToClientV_12
parseJSON (Number 13) = return NodeToClientV_13
parseJSON (Number 14) = return NodeToClientV_14
parseJSON (Number 15) = return NodeToClientV_15
parseJSON (Number x) = fail ("FromJSON.NodeToClientVersion: unsupported node-to-client protocol version " ++ show x)
parseJSON x = fail ("FromJSON.NodeToClientVersion: error parsing NodeToClientVersion: " ++ show x)

instance ToJSON NodeToNodeVersionData where
toJSON (NodeToNodeVersionData (NetworkMagic m) dm) =
Expand Down
4 changes: 2 additions & 2 deletions cardano-node/src/Cardano/Tracing/Startup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ instance HasSeverityAnnotation (StartupTrace blk) where
getSeverityAnnotation (NetworkConfigUpdateError _) = Error
getSeverityAnnotation NetworkConfigUpdateUnsupported = Warning
getSeverityAnnotation P2PWarning = Warning
getSeverityAnnotation P2PWarningDevelopementNetworkProtocols = Warning
getSeverityAnnotation WarningDevelopmentNetworkProtocols {} = Warning
getSeverityAnnotation WarningDevelopmentNodeToNodeVersions {} = Warning
getSeverityAnnotation WarningDevelopmentNodeToClientVersions {} = Warning
getSeverityAnnotation _ = Info

instance HasPrivacyAnnotation (StartupTrace blk)
Expand Down
11 changes: 11 additions & 0 deletions doc/getting-started/understanding-config-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@ signal, `cardano-node` will re-read the file and restart all DNS resolution. Ple
One can disable ledger peers by setting the `useLedgerAfterSlot` to a negative
value.

If you are synchronizing the network for the first time, please connect to IOG
relays `relays-new.cardano-mainnet.iohkdev.io` by adding it to your local root
peers and set `useLedgerAfterSlot` to `0` (to disable ledger peers). You can
use different relays as long as you trust them to provide you the honest chain.
When the node is synced, you can remove it from the local root peers, you
should also manually check if other stake pool relays are on the same chain as
you are. Once you enabled ledger peers by setting `useLedgerAfterSlot` the
node will connect to relays registered on the chain, and churn through them by
randomly picking new peers (weighted by stake distribution) and forgetting 20%
least performing ones.

#### The genesis.json file

The genesis file is generated with the `cardano-cli` by reading a `genesis.spec.json` file, which is out of scope for this document.
Expand Down