Skip to content

Commit

Permalink
Moved UseLedger type to avoid circular imports
Browse files Browse the repository at this point in the history
- The moving of UseLedger was needed in order to import `Cardano.Node.Protocol (ProtocolInstantiationError)`
- Added new constructors to Startup Tracer
  • Loading branch information
bolt12 committed Jun 17, 2023
1 parent 9119612 commit 16d9e12
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 30 deletions.
23 changes: 0 additions & 23 deletions cardano-node/src/Cardano/Node/Configuration/TopologyP2P.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ module Cardano.Node.Configuration.TopologyP2P
, NodeHostIPv6Address(..)
, NodeSetup(..)
, PeerAdvertise(..)
, UseLedger(..)
, nodeAddressToSockAddr
, readTopologyFile
, readTopologyFileOrError
Expand All @@ -27,7 +26,6 @@ where
import Control.Exception (IOException)
import qualified Control.Exception as Exception
import Control.Exception.Base (Exception (..))
import Control.Monad (MonadPlus (..))
import Data.Aeson
import Data.Bifunctor (Bifunctor (..))
import qualified Data.ByteString as BS
Expand All @@ -39,7 +37,6 @@ import Data.Word (Word64)
import "contra-tracer" Control.Tracer (Tracer, traceWith)

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

import Cardano.Node.Configuration.NodeAddress
import Cardano.Node.Configuration.Topology (TopologyError (..))
Expand All @@ -50,26 +47,6 @@ import Ouroboros.Network.NodeToNode (PeerAdvertise (..))
import Ouroboros.Network.PeerSelection.LedgerPeers (UseLedgerAfter (..))
import Ouroboros.Network.PeerSelection.RelayAccessPoint (RelayAccessPoint (..))



-- | A newtype wrapper around 'UseLedgerAfter' which provides 'FromJSON' and
-- 'ToJSON' instances.
--
-- 'UseLedgerAfter' is used to configure from which slot a p2p node can use on
-- chain root peers.
--
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)
Expand Down
12 changes: 12 additions & 0 deletions cardano-node/src/Cardano/Node/Startup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import Cardano.Logging
import Cardano.Node.Configuration.POM (NodeConfiguration (..), ncProtocol)
import Cardano.Node.Configuration.Socket
import Cardano.Node.Protocol.Types (SomeConsensusProtocol (..))
import Cardano.Node.Protocol (ProtocolInstantiationError)

import Cardano.Git.Rev (gitRev)
import Paths_cardano_node (version)
Expand Down Expand Up @@ -77,6 +78,17 @@ data StartupTrace blk =

| StartupDBValidation

-- | Log that the block forging is being updated
| BlockForgingUpdate

-- | Protocol instantiation error when updating block forging
| BlockForgingUpdateError ProtocolInstantiationError

-- | Mismatched block type
| BlockForgingBlockTypeMismatch
Api.SomeBlockType -- ^ expected
Api.SomeBlockType -- ^ provided

-- | Log that the network configuration is being updated.
--
| NetworkConfigUpdate
Expand Down
2 changes: 1 addition & 1 deletion cardano-node/src/Cardano/Node/Tracing/Tracers/Diffusion.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Data.Text (pack)
import Network.Mux (MuxTrace (..), WithMuxBearer (..))
import Network.TypedProtocol.Codec (AnyMessageAndAgency (..))

import Cardano.Node.Configuration.TopologyP2P (UseLedger (..))
import Cardano.Node.Types (UseLedger(..))

import qualified Data.List as List
import qualified Ouroboros.Network.Diffusion as ND
Expand Down
39 changes: 38 additions & 1 deletion cardano-node/src/Cardano/Node/Tracing/Tracers/Startup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ import Cardano.Git.Rev (gitRev)

import Cardano.Node.Configuration.POM (NodeConfiguration, ncProtocol)
import Cardano.Node.Configuration.Socket
import Cardano.Node.Configuration.TopologyP2P
import Cardano.Node.Protocol (SomeConsensusProtocol (..))
import Cardano.Node.Startup
import Cardano.Node.Types (UseLedger(..))


getStartupInfo
Expand Down Expand Up @@ -202,6 +202,17 @@ instance ( Show (BlockNodeToNodeVersion blk)
forMachine _dtal StartupDBValidation =
mconcat [ "kind" .= String "StartupDBValidation"
, "message" .= String "start db validation" ]
forMachine _dtal BlockForgingUpdate =
mconcat [ "kind" .= String "BlockForgingUpdate" ]
forMachine _dtal (BlockForgingUpdateError err) =
mconcat [ "kind" .= String "BlockForgingUpdateError"
, "error" .= String (showT err)
]
forMachine _dtal (BlockForgingBlockTypeMismatch expected provided) =
mconcat [ "kind" .= String "BlockForgingBlockTypeMismatch"
, "expected" .= String (showT expected)
, "provided" .= String (showT provided)
]
forMachine _dtal NetworkConfigUpdate =
mconcat [ "kind" .= String "NetworkConfigUpdate"
, "message" .= String "network configuration update" ]
Expand Down Expand Up @@ -281,6 +292,12 @@ instance MetaTrace (StartupTrace blk) where
Namespace [] ["SocketConfigError"]
namespaceFor StartupDBValidation {} =
Namespace [] ["DBValidation"]
namespaceFor BlockForgingUpdate =
Namespace [] ["BlockForgingUpdate"]
namespaceFor BlockForgingUpdateError {} =
Namespace [] ["BlockForgingUpdateError"]
namespaceFor BlockForgingBlockTypeMismatch {} =
Namespace [] ["BlockForgingBlockTypeMismatch"]
namespaceFor NetworkConfigUpdate {} =
Namespace [] ["NetworkConfigUpdate"]
namespaceFor NetworkConfigUpdateUnsupported {} =
Expand Down Expand Up @@ -315,6 +332,8 @@ instance MetaTrace (StartupTrace blk) where
severityFor (Namespace _ ["P2PWarning"]) _ = Just Warning
severityFor (Namespace _ ["WarningDevelopmentNodeToNodeVersions"]) _ = Just Warning
severityFor (Namespace _ ["WarningDevelopmentNodeToClientVersions"]) _ = Just Warning
severityFor (Namespace _ ["BlockForgingUpdateError"]) _ = Just Error
severityFor (Namespace _ ["BlockForgingBlockTypeMismatch"]) _ = Just Error
severityFor _ _ = Just Info

documentFor (Namespace [] ["Info"]) = Just
Expand All @@ -329,6 +348,12 @@ instance MetaTrace (StartupTrace blk) where
""
documentFor (Namespace [] ["DBValidation"]) = Just
""
documentFor (Namespace [] ["BlockForgingUpdate"]) = Just
""
documentFor (Namespace [] ["BlockForgingUpdateError"]) = Just
""
documentFor (Namespace [] ["BlockForgingBlockTypeMismatch"]) = Just
""
documentFor (Namespace [] ["NetworkConfigUpdate"]) = Just
""
documentFor (Namespace [] ["NetworkConfigUpdateUnsupported"]) = Just
Expand Down Expand Up @@ -383,6 +408,8 @@ instance MetaTrace (StartupTrace blk) where
, Namespace [] ["NetworkMagic"]
, Namespace [] ["SocketConfigError"]
, Namespace [] ["DBValidation"]
, Namespace [] ["BlockForgingUpdate"]
, Namespace [] ["BlockForgingBlockTypeMismatch"]
, Namespace [] ["NetworkConfigUpdate"]
, Namespace [] ["NetworkConfigUpdateUnsupported"]
, Namespace [] ["NetworkConfigUpdateError"]
Expand Down Expand Up @@ -453,6 +480,16 @@ ppStartupInfoTrace (StartupSocketConfigError err) =

ppStartupInfoTrace StartupDBValidation = "Performing DB validation"

ppStartupInfoTrace BlockForgingUpdate = "Performing block forging reconfiguration"
ppStartupInfoTrace (BlockForgingUpdateError err) =
"Block forging reconfiguration error "
<> showT err
ppStartupInfoTrace (BlockForgingBlockTypeMismatch expected provided) =
"Block forging reconfiguration block type mismatch: expected "
<> showT expected
<> " provided "
<> showT provided

ppStartupInfoTrace NetworkConfigUpdate = "Performing topology configuration update"
ppStartupInfoTrace NetworkConfigUpdateUnsupported =
"Network topology reconfiguration is not supported in non-p2p mode"
Expand Down
23 changes: 23 additions & 0 deletions cardano-node/src/Cardano/Node/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module Cardano.Node.Types
, MaxConcurrencyBulkSync(..)
, MaxConcurrencyDeadline(..)
-- * Networking
, UseLedger(..)
, TopologyFile(..)
, NodeDiffusionMode (..)
-- * Consensus protocol configuration
Expand All @@ -38,6 +39,8 @@ import Data.Text (Text)
import qualified Data.Text as Text
import Data.Word (Word16, Word8)

import Control.Monad (MonadPlus (..))

import Cardano.Api
import Cardano.Crypto (RequiresNetworkMagic (..))
import qualified Cardano.Crypto.Hash as Crypto
Expand All @@ -46,6 +49,7 @@ import Cardano.Node.Configuration.Socket (SocketConfig (..))
--TODO: things will probably be clearer if we don't use these newtype wrappers and instead
-- use records with named fields in the CLI code.
import Ouroboros.Network.NodeToNode (DiffusionMode (..))
import Ouroboros.Network.PeerSelection.LedgerPeers (UseLedgerAfter (..))

-- | Errors for the cardano-config module.
data ConfigError =
Expand Down Expand Up @@ -274,6 +278,25 @@ data NodeHardForkProtocolConfiguration =
}
deriving (Eq, Show)

-- | A newtype wrapper around 'UseLedgerAfter' which provides 'FromJSON' and
-- 'ToJSON' instances.
--
-- 'UseLedgerAfter' is used to configure from which slot a p2p node can use on
-- chain root peers.
--
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)


newtype TopologyFile = TopologyFile
{ unTopology :: FilePath }
deriving newtype (Show, Eq)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ import Network.TypedProtocol.Core (PeerHasAgency (..))
import Network.Mux (MiniProtocolNum (..), MuxTrace (..), WithMuxBearer (..))
import Network.Socket (SockAddr (..))

import Cardano.Node.Configuration.TopologyP2P (UseLedger (..))
import Cardano.Node.Queries (ConvertTxId)
import Cardano.Node.Types (UseLedger(..))
import Cardano.Tracing.OrphanInstances.Common
import Cardano.Tracing.Render

Expand Down
3 changes: 2 additions & 1 deletion cardano-node/test/Test/Cardano/Node/Gen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ import qualified Data.Aeson.KeyMap as Aeson.KeyMap
import qualified Data.ByteString.Lazy as LBS
import qualified Data.Vector as Vector

import Cardano.Node.Types (UseLedger(..))
import Cardano.Node.Configuration.NodeAddress (NodeAddress' (..), NodeHostIPAddress (..),
NodeHostIPv4Address (..), NodeHostIPv6Address (..), NodeIPAddress,
NodeIPv4Address, NodeIPv6Address)
import Cardano.Node.Configuration.TopologyP2P (LocalRootPeersGroup (..),
LocalRootPeersGroups (..), NetworkTopology (..), NodeSetup (..),
PeerAdvertise (..), PublicRootPeers (..), RootConfig (..), UseLedger (..))
PeerAdvertise (..), PublicRootPeers (..), RootConfig (..))
import Cardano.Slotting.Slot (SlotNo (..))
import Ouroboros.Network.PeerSelection.LedgerPeers (UseLedgerAfter (..))
import Ouroboros.Network.PeerSelection.RelayAccessPoint (DomainAccessPoint (..),
Expand Down
3 changes: 2 additions & 1 deletion cardano-testnet/src/Testnet/Start/Byron.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import Cardano.Api hiding (Value)

import qualified Cardano.Node.Configuration.Topology as NonP2P
import qualified Cardano.Node.Configuration.TopologyP2P as P2P
import Cardano.Node.Types (UseLedger(..))
import qualified Data.Aeson as J
import qualified Data.HashMap.Lazy as HM
import qualified Data.List as L
Expand Down Expand Up @@ -188,7 +189,7 @@ mkTopologyConfig i numBftNodes' allPorts True = J.encode topologyP2P
P2P.RealNodeTopology
localRootPeerGroups
[]
(P2P.UseLedger DontUseLedger)
(UseLedger DontUseLedger)


testnet :: TestnetOptions -> H.Conf -> H.Integration [String]
Expand Down
3 changes: 2 additions & 1 deletion cardano-testnet/src/Testnet/Start/Cardano.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import Ouroboros.Network.PeerSelection.RelayAccessPoint (RelayAccessPo

import qualified Cardano.Node.Configuration.Topology as NonP2P
import qualified Cardano.Node.Configuration.TopologyP2P as P2P
import Cardano.Node.Types (UseLedger(..))

import qualified Hedgehog as H
import qualified Hedgehog.Extras.Stock.Aeson as J
Expand Down Expand Up @@ -179,7 +180,7 @@ mkTopologyConfig numNodes allPorts port True = J.encode topologyP2P
P2P.RealNodeTopology
localRootPeerGroups
[]
(P2P.UseLedger DontUseLedger)
(UseLedger DontUseLedger)

cardanoTestnet :: CardanoTestnetOptions -> H.Conf -> H.Integration TestnetRuntime
cardanoTestnet testnetOptions H.Conf {H.tempAbsPath} = do
Expand Down
3 changes: 2 additions & 1 deletion cardano-testnet/src/Testnet/Start/Shelley.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import Ouroboros.Network.PeerSelection.RelayAccessPoint (RelayAccessPo
import Cardano.Api hiding (Value)
import qualified Cardano.Node.Configuration.Topology as NonP2P
import qualified Cardano.Node.Configuration.TopologyP2P as P2P
import Cardano.Node.Types (UseLedger(..))
import qualified Data.Aeson as J
import qualified Data.HashMap.Lazy as HM
import qualified Data.List as L
Expand Down Expand Up @@ -152,7 +153,7 @@ mkTopologyConfig numPraosNodes allPorts port True = J.encode topologyP2P
P2P.RealNodeTopology
localRootPeerGroups
[]
(P2P.UseLedger DontUseLedger)
(UseLedger DontUseLedger)

shelleyTestnet :: ShelleyTestnetOptions -> H.Conf -> H.Integration TestnetRuntime
shelleyTestnet testnetOptions H.Conf {H.tempAbsPath} = do
Expand Down

0 comments on commit 16d9e12

Please sign in to comment.