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

Creates 'cardano-node' sublibrary #5082

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Creates 'cardano-node' sublibrary #5082

wants to merge 6 commits into from

Conversation

bolt12
Copy link
Contributor

@bolt12 bolt12 commented Feb 20, 2025

Two of the steps in #5065.

This PR:

  • Creates a sublibrary under ouroboros-network that contains all cardano-node specific data types and definitions.
  • Moves NetworkTopology data definition and auxiliary functions to the 'cardano-node' sublibrary.

The idea is that everything network related currently in cardano-node that requires integration, should live in this sublibrary. This will make maintance and future integration work easier.

@bolt12 bolt12 self-assigned this Feb 20, 2025
@bolt12 bolt12 requested a review from a team as a code owner February 20, 2025 13:09
@bolt12 bolt12 changed the title Moved Topology files to ouroboros-network Creates 'cardano-node' sublibrary Feb 21, 2025
Copy link
Contributor

@crocodile-dentist crocodile-dentist left a comment

Choose a reason for hiding this comment

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

lgtm

@@ -91,13 +91,14 @@ import Cardano.Network.PeerSelection.LocalRootPeers
import Cardano.Network.PeerSelection.PeerTrustable (PeerTrustable)
import Cardano.Network.Types (LedgerStateJudgement (..),
NumberOfBigLedgerPeers (..))
import Ouroboros.Cardano.Network.ExtraRootPeers qualified as Cardano
import Ouroboros.Cardano.Network.ExtraRootPeers qualified as ExtraPeers
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not make this imported qualified once as Cardano.ExtraPeers like Cardano.PublicRootPeers below? This pattern is in a few other places in this patch so I just mention it once here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I want to qualify ExtraPeers data type with Cardano to make it obvious it is an ExtraPeer for Cardano, but then I want to qualify ExtraPeers module definitions with ExtraPeers to make it obvious they are coming from ExtraPeers

Copy link
Contributor

Choose a reason for hiding this comment

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

It's also imported twice with different qualifications, are we sure it's a good idea?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it helps clarity when reading the code and understanding where things are coming from.. We also can't have everything qualified under Cardano since some record fields will clash

-- | This function returns false if non-trustable peers are configured
--
isValidTrustedPeerConfiguration :: CardanoNetworkTopology -> Bool
isValidTrustedPeerConfiguration
Copy link
Contributor

Choose a reason for hiding this comment

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

The node also has a check whether the options are compatible with Genesis, ie. we have UseBootstrapPeers enabled but so is Genesis - I'd have to take another look at the node code but maybe that can be moved here as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I see, I'll double check! I'll be making an integration branch soon and expect to catch more things to add here

Copy link
Contributor

@coot coot left a comment

Choose a reason for hiding this comment

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

Thanks @bolt12, some suggestions with possible improvements follow.

Comment on lines 10 to 11
import Data.Set qualified as Set
import Ouroboros.Cardano.Network.ExtraRootPeers (ExtraPeers (..))
Copy link
Contributor

Choose a reason for hiding this comment

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

We usually space seprate library imports from local ones:

Suggested change
import Data.Set qualified as Set
import Ouroboros.Cardano.Network.ExtraRootPeers (ExtraPeers (..))
import Data.Set qualified as Set
import Ouroboros.Cardano.Network.ExtraRootPeers (ExtraPeers (..))

Comment on lines 107 to 113

socketAddressType :: Socket.SockAddr -> Maybe AddressType
socketAddressType Socket.SockAddrInet {} = Just IPv4Address
socketAddressType Socket.SockAddrInet6 {} = Just IPv6Address
socketAddressType Socket.SockAddrUnix {} = Nothing


Copy link
Contributor

Choose a reason for hiding this comment

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

These double empty lines shouldn't be removed.

Comment on lines 4 to 5
{-# OPTIONS_GHC -Wno-orphans #-}
module Ouroboros.Cardano.Network.PublicRootPeers where
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
{-# OPTIONS_GHC -Wno-orphans #-}
module Ouroboros.Cardano.Network.PublicRootPeers where
{-# OPTIONS_GHC -Wno-orphans #-}
module Ouroboros.Cardano.Network.PublicRootPeers where

@@ -0,0 +1,132 @@
{-# LANGUAGE FlexibleInstances #-}
Copy link
Contributor

Choose a reason for hiding this comment

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

From which module in main this code is coming from?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

what do you mean? This is required for the instances that are defined in this module:

e.g.:

instance ( Ord peeraddr
         ) => Semigroup (CardanoPublicRootPeers peeraddr) where
  (<>) = merge

Comment on lines 1 to 5
module Ouroboros.Cardano.Network.Types where

data ChurnMode = ChurnModeBulkSync
| ChurnModeNormal
deriving Show
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not move this to Ouroboros.Cardano.PeerSelection.Churn? Types at this level is a bit general for churn specific stuff, isn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes that's a much better thing to do!

@@ -91,13 +91,14 @@ import Cardano.Network.PeerSelection.LocalRootPeers
import Cardano.Network.PeerSelection.PeerTrustable (PeerTrustable)
import Cardano.Network.Types (LedgerStateJudgement (..),
NumberOfBigLedgerPeers (..))
import Ouroboros.Cardano.Network.ExtraRootPeers qualified as Cardano
import Ouroboros.Cardano.Network.ExtraRootPeers qualified as ExtraPeers
Copy link
Contributor

Choose a reason for hiding this comment

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

It's also imported twice with different qualifications, are we sure it's a good idea?

Comment on lines -51 to +54
=> Gen (PublicRootPeers (Cardano.ExtraPeers peeraddr) peeraddr)
=> Gen (CardanoPublicRootPeers peeraddr)
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Comment on lines 7 to 10
import Data.Map qualified as Map
import Data.Map.Strict (Map)
import Ouroboros.Network.Diffusion.Configuration (DiffusionMode)
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's group imports

Suggested change
import Data.Map qualified as Map
import Data.Map.Strict (Map)
import Ouroboros.Network.Diffusion.Configuration (DiffusionMode)
import Data.Map qualified as Map
import Data.Map.Strict (Map)
import Ouroboros.Network.Diffusion.Configuration (DiffusionMode)

@@ -1797,7 +1796,6 @@ data TracePeerSelection extraDebugState extraFlags extraPeers peeraddr =
--

| TraceChurnWait DiffTime
| TraceChurnMode ChurnMode
Copy link
Contributor

Choose a reason for hiding this comment

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

So we have an extra tracer just for ChurnMode; When we'll be integrating with cardano-node it should be configured afterTracePeerSelection (no need for a separate option for enabling / disabling it).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes!

Comment on lines 16 to 18
import Control.Concurrent.Class.MonadSTM
import Data.Set (Set)
import Data.Set qualified as Set
Copy link
Contributor

Choose a reason for hiding this comment

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

We could organise the imports better.

@bolt12 bolt12 force-pushed the bolt12/topology branch 3 times, most recently from 8b6facd to cfcdb12 Compare February 25, 2025 16:20
@bolt12 bolt12 requested a review from coot February 25, 2025 16:29
This is a Cardano specific type and this is a step to remove any
lingering cardano-node details from the network code and move them to
the cardano-node sublibrary.
This is a Cardano specific type and this is a step to remove any
lingering cardano-node details from the network code and move them to
the cardano-node sublibrary.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

3 participants