diff --git a/bench/tx-generator/src/Cardano/Benchmarking/Command.hs b/bench/tx-generator/src/Cardano/Benchmarking/Command.hs index 0f5c865d5b8..1aaecb41eae 100644 --- a/bench/tx-generator/src/Cardano/Benchmarking/Command.hs +++ b/bench/tx-generator/src/Cardano/Benchmarking/Command.hs @@ -58,6 +58,7 @@ import GHC.Weak as Weak (deRefWeak) import System.Posix.Signals as Sig (Handler (CatchInfo), SignalInfo (..), SignalSpecificInfo (..), installHandler, sigINT, sigTERM) +import Foreign.C (Errno(..)) #if MIN_VERSION_base(4,18,0) import Data.Maybe as Maybe (fromMaybe) import GHC.Conc.Sync as Conc (threadLabel) diff --git a/bench/tx-generator/tx-generator.cabal b/bench/tx-generator/tx-generator.cabal index b8275a8da51..0f39bddd5e7 100644 --- a/bench/tx-generator/tx-generator.cabal +++ b/bench/tx-generator/tx-generator.cabal @@ -158,6 +158,7 @@ library , transformers-except , unordered-containers , yaml + , microlens default-language: Haskell2010 default-extensions: OverloadedStrings diff --git a/cardano-node/ChangeLog.md b/cardano-node/ChangeLog.md index 7e3aff8ac10..76e7cfd2474 100644 --- a/cardano-node/ChangeLog.md +++ b/cardano-node/ChangeLog.md @@ -9,6 +9,11 @@ - `--mempool-capacity-override` and `--no-mempool-capacity-override` can be set in the configuration file via the key `MempoolCapacityBytesOverride`. - `--snapshot-interval` can be set in the configuration file via the key `SnapshotInterval`. - `--num-of-disk-snapshots` can be set in the configuration file via the key `NumOfDiskSnapshots`. +- Ledger peer snapshot path entry added to topology JSON parser, + which a new decoder function `readPeerSnapshotFile` processes + at startup and SIGHUP. Data is available to the diffusion layer + via TVar. + - Use metric names of old-tracing in new-tracing as well, and fix some metrics in new tracing. diff --git a/cardano-node/src/Cardano/Node/Configuration/POM.hs b/cardano-node/src/Cardano/Node/Configuration/POM.hs index 3ce3341e431..476b1fc8c35 100644 --- a/cardano-node/src/Cardano/Node/Configuration/POM.hs +++ b/cardano-node/src/Cardano/Node/Configuration/POM.hs @@ -37,8 +37,7 @@ import Ouroboros.Consensus.Node (NodeDatabasePaths (..)) import qualified Ouroboros.Consensus.Node as Consensus (NetworkP2PMode (..)) import Ouroboros.Consensus.Storage.LedgerDB.DiskPolicy (NumOfDiskSnapshots (..), SnapshotInterval (..)) -import Ouroboros.Network.NodeToNode (AcceptedConnectionsLimit (..), DiffusionMode (..)) -import Ouroboros.Network.PeerSelection.PeerSharing (PeerSharing (..)) +import Ouroboros.Network.Diffusion.Configuration as Configuration import Control.Monad (when) import Data.Aeson @@ -150,13 +149,26 @@ data NodeConfiguration , ncAcceptedConnectionsLimit :: !AcceptedConnectionsLimit -- P2P governor targets - , ncTargetNumberOfRootPeers :: Int - , ncTargetNumberOfKnownPeers :: Int - , ncTargetNumberOfEstablishedPeers :: Int - , ncTargetNumberOfActivePeers :: Int - , ncTargetNumberOfKnownBigLedgerPeers :: Int - , ncTargetNumberOfEstablishedBigLedgerPeers :: Int - , ncTargetNumberOfActiveBigLedgerPeers :: Int + , ncDeadlineTargetOfRootPeers :: !Int + , ncDeadlineTargetOfKnownPeers :: !Int + , ncDeadlineTargetOfEstablishedPeers :: !Int + , ncDeadlineTargetOfActivePeers :: !Int + , ncDeadlineTargetOfKnownBigLedgerPeers :: !Int + , ncDeadlineTargetOfEstablishedBigLedgerPeers :: !Int + , ncDeadlineTargetOfActiveBigLedgerPeers :: !Int + , ncSyncTargetOfActivePeers :: !Int + , ncSyncTargetOfKnownBigLedgerPeers :: !Int + , ncSyncTargetOfEstablishedBigLedgerPeers :: !Int + , ncSyncTargetOfActiveBigLedgerPeers :: !Int + , ncSyncMinTrusted :: !MinBigLedgerPeersForTrustedState + + -- Used to determine which set of peer targets to use + -- by the diffusion layer when syncing + , ncConsensusMode :: !ConsensusMode + + -- Minimum number of active big ledger peers we must be connected to + -- in Genesis mode + , ncMinBigLedgerPeersForTrustedState :: MinBigLedgerPeersForTrustedState -- Enable experimental P2P mode , ncEnableP2P :: SomeNetworkP2PMode @@ -185,7 +197,7 @@ data PartialNodeConfiguration , pncProtocolConfig :: !(Last NodeProtocolConfiguration) -- Node parameters, not protocol-specific: - , pncDiffusionMode :: !(Last DiffusionMode ) + , pncDiffusionMode :: !(Last DiffusionMode) , pncNumOfDiskSnapshots :: !(Last NumOfDiskSnapshots) , pncSnapshotInterval :: !(Last SnapshotInterval) , pncExperimentalProtocolsEnabled :: !(Last Bool) @@ -213,13 +225,23 @@ data PartialNodeConfiguration , pncAcceptedConnectionsLimit :: !(Last AcceptedConnectionsLimit) -- P2P governor targets - , pncTargetNumberOfRootPeers :: !(Last Int) - , pncTargetNumberOfKnownPeers :: !(Last Int) - , pncTargetNumberOfEstablishedPeers :: !(Last Int) - , pncTargetNumberOfActivePeers :: !(Last Int) - , pncTargetNumberOfKnownBigLedgerPeers :: !(Last Int) - , pncTargetNumberOfEstablishedBigLedgerPeers :: !(Last Int) - , pncTargetNumberOfActiveBigLedgerPeers :: !(Last Int) + , pncDeadlineTargetOfRootPeers :: !(Last Int) + , pncDeadlineTargetOfKnownPeers :: !(Last Int) + , pncDeadlineTargetOfEstablishedPeers :: !(Last Int) + , pncDeadlineTargetOfActivePeers :: !(Last Int) + , pncDeadlineTargetOfKnownBigLedgerPeers :: !(Last Int) + , pncDeadlineTargetOfEstablishedBigLedgerPeers :: !(Last Int) + , pncDeadlineTargetOfActiveBigLedgerPeers :: !(Last Int) + , pncSyncTargetOfActivePeers :: !(Last Int) + , pncSyncTargetOfKnownBigLedgerPeers :: !(Last Int) + , pncSyncTargetOfEstablishedBigLedgerPeers :: !(Last Int) + , pncSyncTargetOfActiveBigLedgerPeers :: !(Last Int) + -- Minimum number of active big ledger peers we must be connected to + -- in Genesis mode + , pncMinBigLedgerPeersForTrustedState :: !(Last MinBigLedgerPeersForTrustedState) + + -- Consensus mode for diffusion layer + , pncConsensusMode :: !(Last ConsensusMode) -- Enable experimental P2P mode , pncEnableP2P :: !(Last NetworkP2PMode) @@ -301,13 +323,22 @@ instance FromJSON PartialNodeConfiguration where <- Last <$> v .:? "AcceptedConnectionsLimit" -- P2P Governor parameters, with conservative defaults. - pncTargetNumberOfRootPeers <- Last <$> v .:? "TargetNumberOfRootPeers" - pncTargetNumberOfKnownPeers <- Last <$> v .:? "TargetNumberOfKnownPeers" - pncTargetNumberOfEstablishedPeers <- Last <$> v .:? "TargetNumberOfEstablishedPeers" - pncTargetNumberOfActivePeers <- Last <$> v .:? "TargetNumberOfActivePeers" - pncTargetNumberOfKnownBigLedgerPeers <- Last <$> v .:? "TargetNumberOfKnownBigLedgerPeers" - pncTargetNumberOfEstablishedBigLedgerPeers <- Last <$> v .:? "TargetNumberOfEstablishedBigLedgerPeers" - pncTargetNumberOfActiveBigLedgerPeers <- Last <$> v .:? "TargetNumberOfActiveBigLedgerPeers" + pncDeadlineTargetOfRootPeers <- Last <$> v .:? "TargetNumberOfRootPeers" + pncDeadlineTargetOfKnownPeers <- Last <$> v .:? "TargetNumberOfKnownPeers" + pncDeadlineTargetOfEstablishedPeers <- Last <$> v .:? "TargetNumberOfEstablishedPeers" + pncDeadlineTargetOfActivePeers <- Last <$> v .:? "TargetNumberOfActivePeers" + pncDeadlineTargetOfKnownBigLedgerPeers <- Last <$> v .:? "TargetNumberOfKnownBigLedgerPeers" + pncDeadlineTargetOfEstablishedBigLedgerPeers <- Last <$> v .:? "TargetNumberOfEstablishedBigLedgerPeers" + pncDeadlineTargetOfActiveBigLedgerPeers <- Last <$> v .:? "TargetNumberOfActiveBigLedgerPeers" + pncSyncTargetOfActivePeers <- Last <$> v .:? "SyncTargetNumberOfActivePeers" + pncSyncTargetOfKnownBigLedgerPeers <- Last <$> v .:? "SyncTargetNumberOfKnownBigLedgerPeers" + pncSyncTargetOfEstablishedBigLedgerPeers <- Last <$> v .:? "SyncTargetNumberOfEstablishedBigLedgerPeers" + pncSyncTargetOfActiveBigLedgerPeers <- Last <$> v .:? "SyncTargetNumberOfActiveBigLedgerPeers" + -- Minimum number of active big ledger peers we must be connected to + -- in Genesis mode + pncMinBigLedgerPeersForTrustedState <- Last <$> v .:? "MinBigLedgerPeersForTrustedState" + + pncConsensusMode <- Last <$> v .:? "ConsensusMode" pncChainSyncIdleTimeout <- Last <$> v .:? "ChainSyncIdleTimeout" @@ -321,7 +352,7 @@ instance FromJSON PartialNodeConfiguration where -- Peer Sharing -- DISABLED BY DEFAULT - pncPeerSharing <- Last <$> v .:? "PeerSharing" .!= Just PeerSharingDisabled + pncPeerSharing <- Last <$> v .:? "PeerSharing" pure PartialNodeConfiguration { pncProtocolConfig @@ -348,13 +379,19 @@ instance FromJSON PartialNodeConfiguration where , pncTimeWaitTimeout , pncChainSyncIdleTimeout , pncAcceptedConnectionsLimit - , pncTargetNumberOfRootPeers - , pncTargetNumberOfKnownPeers - , pncTargetNumberOfEstablishedPeers - , pncTargetNumberOfActivePeers - , pncTargetNumberOfKnownBigLedgerPeers - , pncTargetNumberOfEstablishedBigLedgerPeers - , pncTargetNumberOfActiveBigLedgerPeers + , pncDeadlineTargetOfRootPeers + , pncDeadlineTargetOfKnownPeers + , pncDeadlineTargetOfEstablishedPeers + , pncDeadlineTargetOfActivePeers + , pncDeadlineTargetOfKnownBigLedgerPeers + , pncDeadlineTargetOfEstablishedBigLedgerPeers + , pncDeadlineTargetOfActiveBigLedgerPeers + , pncSyncTargetOfActivePeers + , pncSyncTargetOfKnownBigLedgerPeers + , pncSyncTargetOfEstablishedBigLedgerPeers + , pncSyncTargetOfActiveBigLedgerPeers + , pncMinBigLedgerPeersForTrustedState + , pncConsensusMode , pncEnableP2P , pncPeerSharing } @@ -523,17 +560,37 @@ defaultPartialNodeConfiguration = , acceptedConnectionsSoftLimit = 384 , acceptedConnectionsDelay = 5 } - , pncTargetNumberOfRootPeers = Last (Just 85) - , pncTargetNumberOfKnownPeers = Last (Just 85) - , pncTargetNumberOfEstablishedPeers = Last (Just 40) - , pncTargetNumberOfActivePeers = Last (Just 15) + , pncDeadlineTargetOfRootPeers = Last (Just deadlineRoots) + , pncDeadlineTargetOfKnownPeers = Last (Just deadlineKnown) + , pncDeadlineTargetOfEstablishedPeers = Last (Just deadlineEstablished) + , pncDeadlineTargetOfActivePeers = Last (Just deadlineActive) , pncChainSyncIdleTimeout = mempty - , pncTargetNumberOfKnownBigLedgerPeers = Last (Just 15) - , pncTargetNumberOfEstablishedBigLedgerPeers = Last (Just 10) - , pncTargetNumberOfActiveBigLedgerPeers = Last (Just 5) - , pncEnableP2P = Last (Just EnabledP2PMode) - , pncPeerSharing = Last (Just PeerSharingDisabled) + , pncDeadlineTargetOfKnownBigLedgerPeers = Last (Just deadlineBigKnown) + , pncDeadlineTargetOfEstablishedBigLedgerPeers = Last (Just deadlineBigEst) + , pncDeadlineTargetOfActiveBigLedgerPeers = Last (Just deadlineBigAct) + , pncSyncTargetOfActivePeers = Last (Just syncActive) + , pncSyncTargetOfKnownBigLedgerPeers = Last (Just syncBigKnown) + , pncSyncTargetOfEstablishedBigLedgerPeers = Last (Just syncBigEst) + , pncSyncTargetOfActiveBigLedgerPeers = Last (Just syncBigAct) + , pncMinBigLedgerPeersForTrustedState = Last (Just defaultMinBigLedgerPeersForTrustedState) + , pncConsensusMode = Last (Just defaultConsensusMode) + , pncEnableP2P = Last (Just EnabledP2PMode) + , pncPeerSharing = Last (Just defaultPeerSharing) } + where + Configuration.PeerSelectionTargets { + targetNumberOfRootPeers = deadlineRoots, + targetNumberOfKnownPeers = deadlineKnown, + targetNumberOfEstablishedPeers = deadlineEstablished, + targetNumberOfActivePeers = deadlineActive, + targetNumberOfKnownBigLedgerPeers = deadlineBigKnown, + targetNumberOfEstablishedBigLedgerPeers = deadlineBigEst, + targetNumberOfActiveBigLedgerPeers = deadlineBigAct } = defaultDeadlineTargets + Configuration.PeerSelectionTargets { + targetNumberOfActivePeers = syncActive, + targetNumberOfKnownBigLedgerPeers = syncBigKnown, + targetNumberOfEstablishedBigLedgerPeers = syncBigEst, + targetNumberOfActiveBigLedgerPeers = syncBigAct } = defaultSyncTargets lastOption :: Parser a -> Parser (Last a) lastOption = fmap Last . optional @@ -555,27 +612,45 @@ makeNodeConfiguration pnc = do shutdownConfig <- lastToEither "Missing ShutdownConfig" $ pncShutdownConfig pnc socketConfig <- lastToEither "Missing SocketConfig" $ pncSocketConfig pnc - ncTargetNumberOfRootPeers <- + ncDeadlineTargetOfRootPeers <- lastToEither "Missing TargetNumberOfRootPeers" - $ pncTargetNumberOfRootPeers pnc - ncTargetNumberOfKnownPeers <- + $ pncDeadlineTargetOfRootPeers pnc + ncDeadlineTargetOfKnownPeers <- lastToEither "Missing TargetNumberOfKnownPeers" - $ pncTargetNumberOfKnownPeers pnc - ncTargetNumberOfEstablishedPeers <- + $ pncDeadlineTargetOfKnownPeers pnc + ncDeadlineTargetOfEstablishedPeers <- lastToEither "Missing TargetNumberOfEstablishedPeers" - $ pncTargetNumberOfEstablishedPeers pnc - ncTargetNumberOfActivePeers <- + $ pncDeadlineTargetOfEstablishedPeers pnc + ncDeadlineTargetOfActivePeers <- lastToEither "Missing TargetNumberOfActivePeers" - $ pncTargetNumberOfActivePeers pnc - ncTargetNumberOfKnownBigLedgerPeers <- + $ pncDeadlineTargetOfActivePeers pnc + ncDeadlineTargetOfKnownBigLedgerPeers <- lastToEither "Missing TargetNumberOfKnownBigLedgerPeers" - $ pncTargetNumberOfKnownBigLedgerPeers pnc - ncTargetNumberOfEstablishedBigLedgerPeers <- + $ pncDeadlineTargetOfKnownBigLedgerPeers pnc + ncDeadlineTargetOfEstablishedBigLedgerPeers <- lastToEither "Missing TargetNumberOfEstablishedBigLedgerPeers" - $ pncTargetNumberOfEstablishedBigLedgerPeers pnc - ncTargetNumberOfActiveBigLedgerPeers <- + $ pncDeadlineTargetOfEstablishedBigLedgerPeers pnc + ncDeadlineTargetOfActiveBigLedgerPeers <- lastToEither "Missing TargetNumberOfActiveBigLedgerPeers" - $ pncTargetNumberOfActiveBigLedgerPeers pnc + $ pncDeadlineTargetOfActiveBigLedgerPeers pnc + ncSyncTargetOfActivePeers <- + lastToEither "Missing SyncTargetNumberOfActivePeers" + $ pncSyncTargetOfActivePeers pnc + ncSyncTargetOfKnownBigLedgerPeers <- + lastToEither "Missing SyncTargetNumberOfKnownBigLedgerPeers" + $ pncSyncTargetOfKnownBigLedgerPeers pnc + ncSyncTargetOfEstablishedBigLedgerPeers <- + lastToEither "Missing SyncTargetNumberOfEstablishedBigLedgerPeers" + $ pncSyncTargetOfEstablishedBigLedgerPeers pnc + ncSyncTargetOfActiveBigLedgerPeers <- + lastToEither "Missing SyncTargetNumberOfActiveBigLedgerPeers" + $ pncSyncTargetOfActiveBigLedgerPeers pnc + ncMinBigLedgerPeersForTrustedState <- + lastToEither "Missing MinBigLedgerPeersForTrustedState" + $ pncMinBigLedgerPeersForTrustedState pnc + ncConsensusMode <- + lastToEither "Missing ConsensusMode" + $ pncConsensusMode pnc ncProtocolIdleTimeout <- lastToEither "Missing ProtocolIdleTimeout" $ pncProtocolIdleTimeout pnc @@ -634,17 +709,23 @@ makeNodeConfiguration pnc = do , ncTimeWaitTimeout , ncChainSyncIdleTimeout , ncAcceptedConnectionsLimit - , ncTargetNumberOfRootPeers - , ncTargetNumberOfKnownPeers - , ncTargetNumberOfEstablishedPeers - , ncTargetNumberOfActivePeers - , ncTargetNumberOfKnownBigLedgerPeers - , ncTargetNumberOfEstablishedBigLedgerPeers - , ncTargetNumberOfActiveBigLedgerPeers + , ncDeadlineTargetOfRootPeers + , ncDeadlineTargetOfKnownPeers + , ncDeadlineTargetOfEstablishedPeers + , ncDeadlineTargetOfActivePeers + , ncDeadlineTargetOfKnownBigLedgerPeers + , ncDeadlineTargetOfEstablishedBigLedgerPeers + , ncDeadlineTargetOfActiveBigLedgerPeers + , ncSyncTargetOfActivePeers + , ncSyncTargetOfKnownBigLedgerPeers + , ncSyncTargetOfEstablishedBigLedgerPeers + , ncSyncTargetOfActiveBigLedgerPeers + , ncMinBigLedgerPeersForTrustedState , ncEnableP2P = case enableP2P of EnabledP2PMode -> SomeNetworkP2PMode Consensus.EnabledP2PMode DisabledP2PMode -> SomeNetworkP2PMode Consensus.DisabledP2PMode , ncPeerSharing + , ncConsensusMode } ncProtocol :: NodeConfiguration -> Protocol diff --git a/cardano-node/src/Cardano/Node/Configuration/TopologyP2P.hs b/cardano-node/src/Cardano/Node/Configuration/TopologyP2P.hs index dfad181fa7f..62f1cb78b19 100644 --- a/cardano-node/src/Cardano/Node/Configuration/TopologyP2P.hs +++ b/cardano-node/src/Cardano/Node/Configuration/TopologyP2P.hs @@ -17,6 +17,7 @@ module Cardano.Node.Configuration.TopologyP2P , PeerAdvertise(..) , nodeAddressToSockAddr , readTopologyFile + , readPeerSnapshotFile , readTopologyFileOrError , rootConfigToRelayAccessPoint ) @@ -27,9 +28,11 @@ import Cardano.Node.Configuration.POM (NodeConfiguration (..)) import Cardano.Node.Configuration.Topology (TopologyError (..)) import Cardano.Node.Types import Cardano.Tracing.OrphanInstances.Network () +import Ouroboros.Network.ConsensusMode import Ouroboros.Network.NodeToNode (PeerAdvertise (..)) import Ouroboros.Network.PeerSelection.Bootstrap (UseBootstrapPeers (..)) -import Ouroboros.Network.PeerSelection.LedgerPeers.Type (UseLedgerPeers (..)) +import Ouroboros.Network.PeerSelection.LedgerPeers.Type (LedgerPeerSnapshot (..), + UseLedgerPeers (..)) import Ouroboros.Network.PeerSelection.PeerTrustable (PeerTrustable (..)) import Ouroboros.Network.PeerSelection.RelayAccessPoint (RelayAccessPoint (..)) import Ouroboros.Network.PeerSelection.State.LocalRootPeers (HotValency (..), @@ -39,6 +42,7 @@ import Control.Applicative (Alternative (..)) import Control.Exception (IOException) import qualified Control.Exception as Exception import Control.Exception.Base (Exception (..)) +import Control.Monad.Trans.Except.Extra import Data.Aeson import qualified Data.ByteString as BS import qualified Data.ByteString.Lazy.Char8 as LBS @@ -171,6 +175,7 @@ data NetworkTopology = RealNodeTopology { ntLocalRootPeersGroups :: !LocalRootPe , ntPublicRootPeers :: ![PublicRootPeers] , ntUseLedgerPeers :: !UseLedgerPeers , ntUseBootstrapPeers :: !UseBootstrapPeers + , ntPeerSnapshotPath :: !(Maybe PeerSnapshotFile) } deriving (Eq, Show) @@ -179,7 +184,8 @@ instance FromJSON NetworkTopology where RealNodeTopology <$> (o .: "localRoots" ) <*> (o .: "publicRoots" ) <*> (o .:? "useLedgerAfterSlot" .!= DontUseLedgerPeers ) - <*> (o .:? "bootstrapPeers" .!= DontUseBootstrapPeers) + <*> (o .:? "bootstrapPeers" .!= DontUseBootstrapPeers ) + <*> (o .:? "peerSnapshotFile") instance ToJSON NetworkTopology where toJSON top = @@ -188,10 +194,12 @@ instance ToJSON NetworkTopology where , ntPublicRootPeers , ntUseLedgerPeers , ntUseBootstrapPeers + , ntPeerSnapshotPath } -> object [ "localRoots" .= ntLocalRootPeersGroups , "publicRoots" .= ntPublicRootPeers , "useLedgerAfterSlot" .= ntUseLedgerPeers , "bootstrapPeers" .= ntUseBootstrapPeers + , "peerSnapshotFile" .= ntPeerSnapshotPath ] -- | Read the `NetworkTopology` configuration from the specified file. @@ -207,8 +215,14 @@ readTopologyFile nc = do return $ case eitherDecode bs' of Left err -> Left (handlerJSON err) Right t - | isValidTrustedPeerConfiguration t -> Right t - | otherwise -> Left handlerBootstrap + | isValidTrustedPeerConfiguration t -> + if isGenesisCompatible (ncConsensusMode nc) (ntUseBootstrapPeers t) + then return (Right t) + else do + traceWith tr $ NetworkConfigUpdateError genesisIncompatible + return . Right $ t { ntUseBootstrapPeers = DontUseBootstrapPeers } + | otherwise -> + Left handlerBootstrap where handler :: IOException -> Text handler e = Text.pack $ "Cardano.Node.Configuration.Topology.readTopologyFile: " @@ -223,6 +237,9 @@ readTopologyFile nc = do , "configuration flag. " , Text.pack err ] + genesisIncompatible + = Text.pack $ "Cardano.Node.Configuration.Topology.readTopologyFile: " + <> "Bootstrap peers are not used in Genesis consensus mode." handlerBootstrap :: Text handlerBootstrap = mconcat [ "You seem to have not configured any trustable peers. " @@ -230,6 +247,8 @@ readTopologyFile nc = do , "in bootstrap mode. Make sure you provide at least one bootstrap peer " , "source. " ] + isGenesisCompatible GenesisMode (UseBootstrapPeers{}) = False + isGenesisCompatible _ _ = True readTopologyFileOrError :: NodeConfiguration -> IO NetworkTopology readTopologyFileOrError nc = @@ -238,6 +257,12 @@ readTopologyFileOrError nc = <> Text.unpack err) pure +readPeerSnapshotFile :: PeerSnapshotFile -> IO LedgerPeerSnapshot +readPeerSnapshotFile (PeerSnapshotFile psf) = either error pure =<< runExceptT + (handleLeftT (left . ("Cardano.Node.Configuration.TopologyP2P.readPeerSnapshotFile: " <>)) $ do + bs <- BS.readFile psf `catchIOExceptT` displayException + hoistEither (eitherDecode . LBS.fromStrict $ bs)) + -- -- Checking for chance of progress in bootstrap phase -- @@ -245,7 +270,7 @@ readTopologyFileOrError nc = -- | This function returns false if non-trustable peers are configured -- isValidTrustedPeerConfiguration :: NetworkTopology -> Bool -isValidTrustedPeerConfiguration (RealNodeTopology (LocalRootPeersGroups lprgs) _ _ ubp) = +isValidTrustedPeerConfiguration (RealNodeTopology (LocalRootPeersGroups lprgs) _ _ ubp _) = case ubp of DontUseBootstrapPeers -> True UseBootstrapPeers [] -> anyTrustable diff --git a/cardano-node/src/Cardano/Node/Parsers.hs b/cardano-node/src/Cardano/Node/Parsers.hs index d77bb991e28..e8d4b7ec619 100644 --- a/cardano-node/src/Cardano/Node/Parsers.hs +++ b/cardano-node/src/Cardano/Node/Parsers.hs @@ -117,13 +117,19 @@ nodeRunParser = do , pncTimeWaitTimeout = mempty , pncChainSyncIdleTimeout = mempty , pncAcceptedConnectionsLimit = mempty - , pncTargetNumberOfRootPeers = mempty - , pncTargetNumberOfKnownPeers = mempty - , pncTargetNumberOfEstablishedPeers = mempty - , pncTargetNumberOfActivePeers = mempty - , pncTargetNumberOfKnownBigLedgerPeers = mempty - , pncTargetNumberOfEstablishedBigLedgerPeers = mempty - , pncTargetNumberOfActiveBigLedgerPeers = mempty + , pncDeadlineTargetOfRootPeers = mempty + , pncDeadlineTargetOfKnownPeers = mempty + , pncDeadlineTargetOfEstablishedPeers = mempty + , pncDeadlineTargetOfActivePeers = mempty + , pncDeadlineTargetOfKnownBigLedgerPeers = mempty + , pncDeadlineTargetOfEstablishedBigLedgerPeers = mempty + , pncDeadlineTargetOfActiveBigLedgerPeers = mempty + , pncSyncTargetOfActivePeers = mempty + , pncSyncTargetOfKnownBigLedgerPeers = mempty + , pncSyncTargetOfEstablishedBigLedgerPeers = mempty + , pncSyncTargetOfActiveBigLedgerPeers = mempty + , pncMinBigLedgerPeersForTrustedState = mempty + , pncConsensusMode = mempty , pncEnableP2P = mempty , pncPeerSharing = mempty } diff --git a/cardano-node/src/Cardano/Node/Run.hs b/cardano-node/src/Cardano/Node/Run.hs index 3b88274a99e..dbc4023129b 100644 --- a/cardano-node/src/Cardano/Node/Run.hs +++ b/cardano-node/src/Cardano/Node/Run.hs @@ -78,7 +78,7 @@ import Ouroboros.Network.NodeToClient (LocalAddress (..), LocalSocket import Ouroboros.Network.NodeToNode (AcceptedConnectionsLimit (..), ConnectionId, PeerSelectionTargets (..), RemoteAddress) import Ouroboros.Network.PeerSelection.Bootstrap (UseBootstrapPeers (..)) -import Ouroboros.Network.PeerSelection.LedgerPeers.Type (UseLedgerPeers) +import Ouroboros.Network.PeerSelection.LedgerPeers.Type (LedgerPeerSnapshot(..), UseLedgerPeers) import Ouroboros.Network.PeerSelection.PeerSharing (PeerSharing (..)) import Ouroboros.Network.PeerSelection.PeerTrustable (PeerTrustable) import Ouroboros.Network.PeerSelection.RelayAccessPoint (RelayAccessPoint (..)) @@ -91,7 +91,7 @@ import Control.Concurrent (killThread, mkWeakThreadId, myThreadId) import Control.Concurrent.Class.MonadSTM.Strict import Control.Exception (try) import qualified Control.Exception as Exception -import Control.Monad (forM_, unless, void, when) +import Control.Monad (forM, forM_, unless, void, when) import Control.Monad.Class.MonadThrow (MonadThrow (..)) import Control.Monad.IO.Class (MonadIO (..)) import Control.Monad.Trans.Except (ExceptT, runExceptT) @@ -435,16 +435,24 @@ handleSimpleNode blockType runP p2pMode tracers nc onKernel = do nt@TopologyP2P.RealNodeTopology { ntUseLedgerPeers , ntUseBootstrapPeers + , ntPeerSnapshotPath } <- TopologyP2P.readTopologyFileOrError nc let (localRoots, publicRoots) = producerAddresses nt traceWith (startupTracer tracers) $ NetworkConfig localRoots publicRoots ntUseLedgerPeers - localRootsVar <- newTVarIO localRoots - publicRootsVar <- newTVarIO publicRoots - useLedgerVar <- newTVarIO ntUseLedgerPeers + ntPeerSnapshotPath + localRootsVar <- newTVarIO localRoots + publicRootsVar <- newTVarIO publicRoots + useLedgerVar <- newTVarIO ntUseLedgerPeers useBootstrapVar <- newTVarIO ntUseBootstrapPeers + ledgerPeerSnapshotPathVar <- newTVarIO ntPeerSnapshotPath + ledgerPeerSnapshotVar <- newTVarIO =<< updateLedgerPeerSnapshot + (startupTracer tracers) + (readTVar ledgerPeerSnapshotPathVar) + (const . pure $ ()) + let nodeArgs = RunNodeArgs { rnGenesisConfig = disableGenesisConfig , rnTraceConsensus = consensusTracers tracers @@ -478,6 +486,11 @@ handleSimpleNode blockType runP p2pMode tracers nc onKernel = do updateTopologyConfiguration (startupTracer tracers) nc localRootsVar publicRootsVar useLedgerVar useBootstrapVar + ledgerPeerSnapshotPathVar + void $ updateLedgerPeerSnapshot + (startupTracer tracers) + (readTVar ledgerPeerSnapshotPathVar) + (writeTVar ledgerPeerSnapshotVar) traceWith (startupTracer tracers) (BlockForgingUpdate NotEffective) ) Nothing @@ -489,6 +502,7 @@ handleSimpleNode blockType runP p2pMode tracers nc onKernel = do (readTVar publicRootsVar) (readTVar useLedgerVar) (readTVar useBootstrapVar) + (readTVar ledgerPeerSnapshotVar) in Node.run nodeArgs { @@ -496,6 +510,7 @@ handleSimpleNode blockType runP p2pMode tracers nc onKernel = do -- reinstall `SIGHUP` handler installP2PSigHUPHandler (startupTracer tracers) blockType nc nodeKernel localRootsVar publicRootsVar useLedgerVar useBootstrapVar + ledgerPeerSnapshotPathVar ledgerPeerSnapshotVar rnNodeKernelHook nodeArgs registry nodeKernel } StdRunNodeArgs @@ -665,17 +680,24 @@ installP2PSigHUPHandler :: Tracer IO (StartupTrace blk) -> StrictTVar IO (Map RelayAccessPoint PeerAdvertise) -> StrictTVar IO UseLedgerPeers -> StrictTVar IO UseBootstrapPeers + -> StrictTVar IO (Maybe PeerSnapshotFile) + -> StrictTVar IO (Maybe LedgerPeerSnapshot) -> IO () #ifndef UNIX -installP2PSigHUPHandler _ _ _ _ _ _ _ _ = return () +installP2PSigHUPHandler _ _ _ _ _ _ _ _ _ _ = return () #else installP2PSigHUPHandler startupTracer blockType nc nodeKernel localRootsVar publicRootsVar useLedgerVar - useBootstrapPeersVar = + useBootstrapPeersVar ledgerPeerSnapshotPathVar ledgerPeerSnapshotVar = void $ Signals.installHandler Signals.sigHUP (Signals.Catch $ do updateBlockForging startupTracer blockType nodeKernel nc - updateTopologyConfiguration startupTracer nc localRootsVar publicRootsVar useLedgerVar useBootstrapPeersVar + updateTopologyConfiguration startupTracer nc localRootsVar publicRootsVar + useLedgerVar useBootstrapPeersVar ledgerPeerSnapshotPathVar + void $ updateLedgerPeerSnapshot + startupTracer + (readTVar ledgerPeerSnapshotPathVar) + (writeTVar ledgerPeerSnapshotVar) ) Nothing #endif @@ -760,9 +782,10 @@ updateTopologyConfiguration :: Tracer IO (StartupTrace blk) -> StrictTVar IO (Map RelayAccessPoint PeerAdvertise) -> StrictTVar IO UseLedgerPeers -> StrictTVar IO UseBootstrapPeers + -> StrictTVar IO (Maybe PeerSnapshotFile) -> IO () updateTopologyConfiguration startupTracer nc localRootsVar publicRootsVar useLedgerVar - useBootsrapPeersVar = do + useBootsrapPeersVar ledgerPeerSnapshotPathVar = do traceWith startupTracer NetworkConfigUpdate result <- try $ readTopologyFileOrError nc case result of @@ -772,17 +795,31 @@ updateTopologyConfiguration startupTracer nc localRootsVar publicRootsVar useLed $ pack "Error reading topology configuration file:" <> err Right nt@RealNodeTopology { ntUseLedgerPeers , ntUseBootstrapPeers + , ntPeerSnapshotPath } -> do let (localRoots, publicRoots) = producerAddresses nt traceWith startupTracer - $ NetworkConfig localRoots publicRoots ntUseLedgerPeers + $ NetworkConfig localRoots publicRoots ntUseLedgerPeers ntPeerSnapshotPath atomically $ do writeTVar localRootsVar localRoots writeTVar publicRootsVar publicRoots writeTVar useLedgerVar ntUseLedgerPeers writeTVar useBootsrapPeersVar ntUseBootstrapPeers + writeTVar ledgerPeerSnapshotPathVar ntPeerSnapshotPath #endif +updateLedgerPeerSnapshot :: Tracer IO (StartupTrace blk) + -> STM IO (Maybe PeerSnapshotFile) + -> (Maybe LedgerPeerSnapshot -> STM IO ()) + -> IO (Maybe LedgerPeerSnapshot) +updateLedgerPeerSnapshot startupTracer readLedgerPeerPath writeVar = do + mPeerSnapshotFile <- atomically readLedgerPeerPath + mLedgerPeerSnapshot <- forM mPeerSnapshotFile $ \f -> do + lps@(LedgerPeerSnapshot (wOrigin, _)) <- readPeerSnapshotFile f + lps <$ traceWith startupTracer (LedgerPeerSnapshotLoaded wOrigin) + atomically . writeVar $ mLedgerPeerSnapshot + pure mLedgerPeerSnapshot + -------------------------------------------------------------------------------- -- Helper functions -------------------------------------------------------------------------------- @@ -849,45 +886,63 @@ mkP2PArguments -> STM IO (Map RelayAccessPoint PeerAdvertise) -> STM IO UseLedgerPeers -> STM IO UseBootstrapPeers + -> STM IO (Maybe LedgerPeerSnapshot) -> Diffusion.ExtraArguments 'Diffusion.P2P IO mkP2PArguments NodeConfiguration { - ncTargetNumberOfRootPeers, - ncTargetNumberOfKnownPeers, - ncTargetNumberOfEstablishedPeers, - ncTargetNumberOfActivePeers, - ncTargetNumberOfKnownBigLedgerPeers, - ncTargetNumberOfEstablishedBigLedgerPeers, - ncTargetNumberOfActiveBigLedgerPeers, + ncDeadlineTargetOfRootPeers, + ncDeadlineTargetOfKnownPeers, + ncDeadlineTargetOfEstablishedPeers, + ncDeadlineTargetOfActivePeers, + ncDeadlineTargetOfKnownBigLedgerPeers, + ncDeadlineTargetOfEstablishedBigLedgerPeers, + ncDeadlineTargetOfActiveBigLedgerPeers, + ncSyncTargetOfActivePeers, + ncSyncTargetOfKnownBigLedgerPeers, + ncSyncTargetOfEstablishedBigLedgerPeers, + ncSyncTargetOfActiveBigLedgerPeers, + ncMinBigLedgerPeersForTrustedState, ncProtocolIdleTimeout, ncTimeWaitTimeout, - ncPeerSharing + ncPeerSharing, + ncConsensusMode } daReadLocalRootPeers daReadPublicRootPeers daReadUseLedgerPeers - daReadUseBootstrapPeers = + daReadUseBootstrapPeers + daReadLedgerPeerSnapshot = Diffusion.P2PArguments P2P.ArgumentsExtra - { P2P.daPeerSelectionTargets + { P2P.daPeerTargets = Configuration.ConsensusModePeerTargets { + Configuration.deadlineTargets, + Configuration.syncTargets } , P2P.daReadLocalRootPeers , P2P.daReadPublicRootPeers , P2P.daReadUseLedgerPeers , P2P.daReadUseBootstrapPeers + , P2P.daReadLedgerPeerSnapshot , P2P.daProtocolIdleTimeout = ncProtocolIdleTimeout , P2P.daTimeWaitTimeout = ncTimeWaitTimeout - , P2P.daDeadlineChurnInterval = 3300 - , P2P.daBulkChurnInterval = 900 + , P2P.daDeadlineChurnInterval = Configuration.defaultDeadlineChurnInterval + , P2P.daBulkChurnInterval = Configuration.defaultBulkChurnInterval , P2P.daOwnPeerSharing = ncPeerSharing + , P2P.daConsensusMode = ncConsensusMode + , P2P.daMinBigLedgerPeersForTrustedState = ncMinBigLedgerPeersForTrustedState } where - daPeerSelectionTargets = PeerSelectionTargets { - targetNumberOfRootPeers = ncTargetNumberOfRootPeers, - targetNumberOfKnownPeers = ncTargetNumberOfKnownPeers, - targetNumberOfEstablishedPeers = ncTargetNumberOfEstablishedPeers, - targetNumberOfActivePeers = ncTargetNumberOfActivePeers, - targetNumberOfKnownBigLedgerPeers = ncTargetNumberOfKnownBigLedgerPeers, - targetNumberOfEstablishedBigLedgerPeers = ncTargetNumberOfEstablishedBigLedgerPeers, - targetNumberOfActiveBigLedgerPeers = ncTargetNumberOfActiveBigLedgerPeers + deadlineTargets = Configuration.defaultDeadlineTargets { + targetNumberOfRootPeers = ncDeadlineTargetOfRootPeers, + targetNumberOfKnownPeers = ncDeadlineTargetOfKnownPeers, + targetNumberOfEstablishedPeers = ncDeadlineTargetOfEstablishedPeers, + targetNumberOfActivePeers = ncDeadlineTargetOfActivePeers, + targetNumberOfKnownBigLedgerPeers = ncDeadlineTargetOfKnownBigLedgerPeers, + targetNumberOfEstablishedBigLedgerPeers = ncDeadlineTargetOfEstablishedBigLedgerPeers, + targetNumberOfActiveBigLedgerPeers = ncDeadlineTargetOfActiveBigLedgerPeers } + syncTargets = Configuration.defaultSyncTargets { + targetNumberOfActivePeers = ncSyncTargetOfActivePeers, + targetNumberOfKnownBigLedgerPeers = ncSyncTargetOfKnownBigLedgerPeers, + targetNumberOfEstablishedBigLedgerPeers = ncSyncTargetOfEstablishedBigLedgerPeers, + targetNumberOfActiveBigLedgerPeers = ncSyncTargetOfActiveBigLedgerPeers } mkNonP2PArguments :: IPSubscriptionTarget diff --git a/cardano-node/src/Cardano/Node/Startup.hs b/cardano-node/src/Cardano/Node/Startup.hs index 9f75890bafc..d2f2e30c09a 100644 --- a/cardano-node/src/Cardano/Node/Startup.hs +++ b/cardano-node/src/Cardano/Node/Startup.hs @@ -19,6 +19,8 @@ import Cardano.Node.Configuration.POM (NodeConfiguration (..), ncProto import Cardano.Node.Configuration.Socket import Cardano.Node.Protocol (ProtocolInstantiationError) import Cardano.Node.Protocol.Types (SomeConsensusProtocol (..)) +import Cardano.Node.Types (PeerSnapshotFile) +import Cardano.Slotting.Slot (SlotNo, WithOrigin) import qualified Ouroboros.Consensus.BlockchainTime.WallClock.Types as WCT import Ouroboros.Consensus.Cardano.Block import Ouroboros.Consensus.Cardano.CanHardFork (shelleyLedgerConfig) @@ -109,6 +111,7 @@ data StartupTrace blk = | NetworkConfig [(HotValency, WarmValency, Map RelayAccessPoint (PeerAdvertise, PeerTrustable))] (Map RelayAccessPoint PeerAdvertise) UseLedgerPeers + (Maybe PeerSnapshotFile) -- | Warn when 'DisabledP2P' is set. | NonP2PWarning @@ -127,6 +130,7 @@ data StartupTrace blk = | BIShelley BasicInfoShelleyBased | BIByron BasicInfoByron | BINetwork BasicInfoNetwork + | LedgerPeerSnapshotLoaded (WithOrigin SlotNo) data EnabledBlockForging = EnabledBlockForging | DisabledBlockForging diff --git a/cardano-node/src/Cardano/Node/Tracing/Tracers/Diffusion.hs b/cardano-node/src/Cardano/Node/Tracing/Tracers/Diffusion.hs index 72d69e6a1f6..d059a04cd5e 100644 --- a/cardano-node/src/Cardano/Node/Tracing/Tracers/Diffusion.hs +++ b/cardano-node/src/Cardano/Node/Tracing/Tracers/Diffusion.hs @@ -851,6 +851,10 @@ instance LogFormatting TraceLedgerPeers where , "domainAccessPoint" .= show dap , "error" .= show reason ] + forMachine _dtal UsingBigLedgerPeerSnapshot = + mconcat + [ "kind" .= String "UsingBigLedgerPeerSnapshot" + ] instance MetaTrace TraceLedgerPeers where namespaceFor PickedLedgerPeer {} = @@ -885,6 +889,8 @@ instance MetaTrace TraceLedgerPeers where Namespace [] ["TraceLedgerPeersResult"] namespaceFor TraceLedgerPeersFailure {} = Namespace [] ["TraceLedgerPeersFailure"] + namespaceFor UsingBigLedgerPeerSnapshot {} = + Namespace [] ["UsingBigLedgerPeerSnapshot"] severityFor (Namespace _ ["PickedPeer"]) _ = Just Debug severityFor (Namespace _ ["PickedPeers"]) _ = Just Info @@ -900,6 +906,7 @@ instance MetaTrace TraceLedgerPeers where severityFor (Namespace _ ["TraceLedgerPeersDomains"]) _ = Just Debug severityFor (Namespace _ ["TraceLedgerPeersResult"]) _ = Just Debug severityFor (Namespace _ ["TraceLedgerPeersFailure"]) _ = Just Debug + severityFor (Namespace _ ["UsingBigLedgerPeerSnapshot"]) _ = Just Debug severityFor _ _ = Nothing documentFor (Namespace _ ["PickedPeer"]) = Just @@ -928,6 +935,9 @@ instance MetaTrace TraceLedgerPeers where "" documentFor (Namespace _ ["TraceLedgerPeersFailure"]) = Just "" + documentFor (Namespace _ ["UsingBigLedgerPeerSnapshot"]) = Just $ mconcat + [ "Trace for when a request for big ledger peers is fulfilled from the snapshot file" + , " defined in the topology configuration file."] documentFor _ = Nothing allNamespaces = [ @@ -943,4 +953,5 @@ instance MetaTrace TraceLedgerPeers where , Namespace [] ["TraceLedgerPeersDomains"] , Namespace [] ["TraceLedgerPeersResult"] , Namespace [] ["TraceLedgerPeersFailure"] + , Namespace [] ["UsingBigLedgerPeerSnapshot"] ] diff --git a/cardano-node/src/Cardano/Node/Tracing/Tracers/P2P.hs b/cardano-node/src/Cardano/Node/Tracing/Tracers/P2P.hs index aa36f94107f..72ac9a57399 100644 --- a/cardano-node/src/Cardano/Node/Tracing/Tracers/P2P.hs +++ b/cardano-node/src/Cardano/Node/Tracing/Tracers/P2P.hs @@ -554,6 +554,9 @@ instance LogFormatting (TracePeerSelection SockAddr) where , "upstreamyness" .= dpssUpstreamyness ds , "fetchynessBlocks" .= dpssFetchynessBlocks ds ] + forMachine _dtal (TraceVerifyPeerSnapshot result) = + mconcat [ "kind" .= String "VerifyPeerSnapshot" + , "result" .= result] forHuman = pack . show @@ -678,6 +681,8 @@ instance MetaTrace (TracePeerSelection SockAddr) where Namespace [] ["ChurnTimeout"] namespaceFor TraceDebugState {} = Namespace [] ["DebugState"] + namespaceFor TraceVerifyPeerSnapshot {} = + Namespace [] ["VerifyPeerSnapshot"] severityFor (Namespace [] ["LocalRootPeersChanged"]) _ = Just Notice severityFor (Namespace [] ["TargetsChanged"]) _ = Just Notice @@ -713,6 +718,7 @@ instance MetaTrace (TracePeerSelection SockAddr) where severityFor (Namespace [] ["ChurnAction"]) _ = Just Info severityFor (Namespace [] ["ChurnTimeout"]) _ = Just Notice severityFor (Namespace [] ["DebugState"]) _ = Just Info + severityFor (Namespace [] ["VerifyPeerSnapshot"]) _ = Just Error severityFor _ _ = Nothing documentFor (Namespace [] ["LocalRootPeersChanged"]) = Just "" @@ -771,6 +777,8 @@ instance MetaTrace (TracePeerSelection SockAddr) where "Outbound Governor was killed unexpectedly" documentFor (Namespace [] ["DebugState"]) = Just "peer selection internal state" + documentFor (Namespace [] ["VerifyPeerSnapshot"]) = Just + "Verification outcome of big ledger peer snapshot" documentFor _ = Nothing metricsDocFor (Namespace [] ["ChurnAction"]) = @@ -816,6 +824,7 @@ instance MetaTrace (TracePeerSelection SockAddr) where , Namespace [] ["PickInboundPeers"] , Namespace [] ["OutboundGovernorCriticalFailure"] , Namespace [] ["DebugState"] + , Namespace [] ["VerifyPeerSnapshot"] ] -------------------------------------------------------------------------------- diff --git a/cardano-node/src/Cardano/Node/Tracing/Tracers/Startup.hs b/cardano-node/src/Cardano/Node/Tracing/Tracers/Startup.hs index 65e82a1d844..f10c00da248 100644 --- a/cardano-node/src/Cardano/Node/Tracing/Tracers/Startup.hs +++ b/cardano-node/src/Cardano/Node/Tracing/Tracers/Startup.hs @@ -26,6 +26,7 @@ import Cardano.Node.Configuration.POM (NodeConfiguration, ncProtocol) import Cardano.Node.Configuration.Socket import Cardano.Node.Protocol (SomeConsensusProtocol (..)) import Cardano.Node.Startup +import Cardano.Node.Types (PeerSnapshotFile (..)) import Cardano.Slotting.Slot (EpochSize (..)) import qualified Ouroboros.Consensus.BlockchainTime.WallClock.Types as WCT import Ouroboros.Consensus.Byron.Ledger.Conversions (fromByronEpochSlots, @@ -215,17 +216,24 @@ instance ( Show (BlockNodeToNodeVersion blk) forMachine _dtal NetworkConfigUpdate = mconcat [ "kind" .= String "NetworkConfigUpdate" , "message" .= String "network configuration update" ] + forMachine _dtal (LedgerPeerSnapshotLoaded wOrigin) = + mconcat [ "kind" .= String "LedgerPeerSnapshotLoaded" + , "message" .= String (showT wOrigin)] forMachine _dtal NetworkConfigUpdateUnsupported = mconcat [ "kind" .= String "NetworkConfigUpdate" , "message" .= String "network topology reconfiguration is not supported in non-p2p mode" ] forMachine _dtal (NetworkConfigUpdateError err) = mconcat [ "kind" .= String "NetworkConfigUpdateError" , "error" .= String err ] - forMachine _dtal (NetworkConfig localRoots publicRoots useLedgerPeers) = + forMachine _dtal (NetworkConfig localRoots publicRoots useLedgerPeers peerSnapshotFileMaybe) = mconcat [ "kind" .= String "NetworkConfig" , "localRoots" .= toJSON localRoots , "publicRoots" .= toJSON publicRoots , "useLedgerAfter" .= useLedgerPeers + , "peerSnapshotFile" .= + case peerSnapshotFileMaybe of + Nothing -> Null + Just (PeerSnapshotFile path) -> String (pack path) ] forMachine _dtal NonP2PWarning = mconcat [ "kind" .= String "NonP2PWarning" @@ -305,6 +313,8 @@ instance MetaTrace (StartupTrace blk) where Namespace [] ["BlockForgingBlockTypeMismatch"] namespaceFor NetworkConfigUpdate {} = Namespace [] ["NetworkConfigUpdate"] + namespaceFor LedgerPeerSnapshotLoaded {} = + Namespace [] ["LedgerPeerSnapshotLoaded"] namespaceFor NetworkConfigUpdateUnsupported {} = Namespace [] ["NetworkConfigUpdateUnsupported"] namespaceFor NetworkConfigUpdateError {} = @@ -512,7 +522,7 @@ ppStartupInfoTrace NetworkConfigUpdate = "Performing topology configuration upda ppStartupInfoTrace NetworkConfigUpdateUnsupported = "Network topology reconfiguration is not supported in non-p2p mode" ppStartupInfoTrace (NetworkConfigUpdateError err) = err -ppStartupInfoTrace (NetworkConfig localRoots publicRoots useLedgerPeers) = +ppStartupInfoTrace (NetworkConfig localRoots publicRoots useLedgerPeers peerSnapshotFile) = pack $ intercalate "\n" [ "\nLocal Root Groups:" @@ -528,8 +538,15 @@ ppStartupInfoTrace (NetworkConfig localRoots publicRoots useLedgerPeers) = ++ show (unSlotNo slotNo) UseLedgerPeers Always -> "Use ledger peers in any slot." + , case peerSnapshotFile of + Nothing -> "Topology configuration does not specify ledger peer snapshot file" + Just p -> "Topology configuration specifies ledger peer snapshot file: " + <> show (unPeerSnapshotFile p) ] +ppStartupInfoTrace (LedgerPeerSnapshotLoaded wOrigin) = + "Topology: Peer snapshot containing ledger peers " <> showT wOrigin <> " loaded." + ppStartupInfoTrace NonP2PWarning = nonP2PWarningMessage ppStartupInfoTrace (WarningDevelopmentNodeToNodeVersions ntnVersions) = diff --git a/cardano-node/src/Cardano/Node/Types.hs b/cardano-node/src/Cardano/Node/Types.hs index 87cc9c72685..4dd3ae44332 100644 --- a/cardano-node/src/Cardano/Node/Types.hs +++ b/cardano-node/src/Cardano/Node/Types.hs @@ -14,6 +14,7 @@ module Cardano.Node.Types , ConfigYamlFilePath(..) , DbFile(..) , GenesisFile(..) + , PeerSnapshotFile (..) , ProtocolFilepaths (..) , GenesisHash(..) , MaxConcurrencyBulkSync(..) @@ -80,6 +81,14 @@ newtype GenesisFile = GenesisFile deriving stock (Eq, Ord) deriving newtype (IsString, Show) +-- | Path containing a serialized ledger peer snapshot +-- for use by diffusion layer to facilitate bootstrapping +-- a node in Genesis consensus mode +-- +newtype PeerSnapshotFile = PeerSnapshotFile { unPeerSnapshotFile :: FilePath } + deriving stock (Eq, Show) + deriving newtype (FromJSON, ToJSON) + instance FromJSON GenesisFile where parseJSON (String genFp) = pure . GenesisFile $ Text.unpack genFp parseJSON invalid = fail $ "Parsing of GenesisFile failed due to type mismatch. " diff --git a/cardano-node/src/Cardano/Tracing/OrphanInstances/Network.hs b/cardano-node/src/Cardano/Tracing/OrphanInstances/Network.hs index 5ca65ab077a..52004c2bd8b 100644 --- a/cardano-node/src/Cardano/Tracing/OrphanInstances/Network.hs +++ b/cardano-node/src/Cardano/Tracing/OrphanInstances/Network.hs @@ -243,6 +243,7 @@ instance HasSeverityAnnotation TraceLedgerPeers where TraceLedgerPeersDomains {} -> Debug TraceLedgerPeersResult {} -> Debug TraceLedgerPeersFailure {} -> Debug + UsingBigLedgerPeerSnapshot {} -> Debug instance HasPrivacyAnnotation (WithAddr addr ErrorPolicyTrace) @@ -484,6 +485,9 @@ instance HasSeverityAnnotation (TracePeerSelection addr) where TraceDebugState {} -> Info + TraceVerifyPeerSnapshot True -> Info + TraceVerifyPeerSnapshot False -> Error + instance HasPrivacyAnnotation (DebugPeerSelection addr) instance HasSeverityAnnotation (DebugPeerSelection addr) where getSeverityAnnotation _ = Debug @@ -1440,7 +1444,10 @@ instance ToObject TraceLedgerPeers where , "domainAccessPoint" .= show dap , "error" .= show reason ] - + toObject _verb UsingBigLedgerPeerSnapshot = + mconcat + [ "kind" .= String "UsingBigLedgerPeerSnapshot" + ] instance Show addr => ToObject (WithAddr addr ErrorPolicyTrace) where @@ -1959,6 +1966,9 @@ instance ToObject (TracePeerSelection SockAddr) where , "ledgerStateJudgement" .= dpssLedgerStateJudgement ds , "associationMode" .= dpssAssociationMode ds ] + toObject _verb (TraceVerifyPeerSnapshot result) = + mconcat [ "kind" .= String "VerifyPeerSnapshot" + , "result" .= result ] -- Connection manager abstract state. For explanation of each state see -- @@ -2191,6 +2201,7 @@ instance ToJSON NodeToClientVersion where toJSON NodeToClientV_16 = Number 16 toJSON NodeToClientV_17 = Number 17 toJSON NodeToClientV_18 = Number 18 + toJSON NodeToClientV_19 = Number 19 -- NB: When adding a new version here, update FromJSON below as well! instance FromJSON NodeToClientVersion where @@ -2204,6 +2215,7 @@ instance FromJSON NodeToClientVersion where parseJSON (Number 16) = return NodeToClientV_16 parseJSON (Number 17) = return NodeToClientV_17 parseJSON (Number 18) = return NodeToClientV_18 + parseJSON (Number 19) = return NodeToClientV_19 parseJSON (Number x) = fail ("FromJSON.NodeToClientVersion: unsupported node-to-client protocol version " ++ show x) parseJSON x = fail ("FromJSON.NodeToClientVersion: error parsing NodeToClientVersion: " ++ show x) diff --git a/cardano-node/test/Test/Cardano/Node/Gen.hs b/cardano-node/test/Test/Cardano/Node/Gen.hs index f7851a7aca0..44546e5c73e 100644 --- a/cardano-node/test/Test/Cardano/Node/Gen.hs +++ b/cardano-node/test/Test/Cardano/Node/Gen.hs @@ -25,6 +25,7 @@ import Cardano.Node.Configuration.NodeAddress (NodeAddress' (..), Node import Cardano.Node.Configuration.TopologyP2P (LocalRootPeersGroup (..), LocalRootPeersGroups (..), NetworkTopology (..), NodeSetup (..), PeerAdvertise (..), PublicRootPeers (..), RootConfig (..)) +import Cardano.Node.Types import Cardano.Slotting.Slot (SlotNo (..)) import Ouroboros.Network.PeerSelection.Bootstrap import Ouroboros.Network.PeerSelection.LedgerPeers.Type (AfterSlot (..), @@ -55,6 +56,7 @@ genNetworkTopology = <*> Gen.list (Range.linear 0 10) genPublicRootPeers <*> genUseLedgerPeers <*> genUseBootstrapPeers + <*> genPeerSnapshotPath ] -- | Generate valid encodings of p2p topology files @@ -205,5 +207,12 @@ genUseBootstrapPeers = do domains <- Gen.list (Range.linear 0 6) genRelayAddress Gen.element [ DontUseBootstrapPeers , UseBootstrapPeers domains ] +genPeerSnapshotPath :: Gen (Maybe PeerSnapshotFile) +genPeerSnapshotPath = + Gen.element + [ Nothing + , Just . PeerSnapshotFile $ "dummy" + ] + genPeerTrustable :: Gen PeerTrustable genPeerTrustable = Gen.element [ IsNotTrustable, IsTrustable ] diff --git a/cardano-node/test/Test/Cardano/Node/POM.hs b/cardano-node/test/Test/Cardano/Node/POM.hs index 2b2c416d704..d0cebeeb00f 100644 --- a/cardano-node/test/Test/Cardano/Node/POM.hs +++ b/cardano-node/test/Test/Cardano/Node/POM.hs @@ -17,9 +17,7 @@ import qualified Ouroboros.Consensus.Node as Consensus (NetworkP2PMode (..)) import Ouroboros.Consensus.Storage.LedgerDB.DiskPolicy (NumOfDiskSnapshots (..), SnapshotInterval (..)) import Ouroboros.Network.Block (SlotNo (..)) -import Ouroboros.Network.NodeToNode (AcceptedConnectionsLimit (..), - DiffusionMode (InitiatorAndResponderDiffusionMode)) -import Ouroboros.Network.PeerSelection.PeerSharing (PeerSharing (..)) +import Ouroboros.Network.Diffusion.Configuration import Data.Monoid (Last (..)) import Data.Text (Text) @@ -136,15 +134,21 @@ testPartialYamlConfig = , pncTimeWaitTimeout = mempty , pncChainSyncIdleTimeout = mempty , pncAcceptedConnectionsLimit = mempty - , pncTargetNumberOfRootPeers = mempty - , pncTargetNumberOfKnownPeers = mempty - , pncTargetNumberOfEstablishedPeers = mempty - , pncTargetNumberOfActivePeers = mempty - , pncTargetNumberOfKnownBigLedgerPeers = mempty - , pncTargetNumberOfEstablishedBigLedgerPeers = mempty - , pncTargetNumberOfActiveBigLedgerPeers = mempty + , pncDeadlineTargetOfRootPeers = mempty + , pncDeadlineTargetOfKnownPeers = mempty + , pncDeadlineTargetOfEstablishedPeers = mempty + , pncDeadlineTargetOfActivePeers = mempty + , pncDeadlineTargetOfKnownBigLedgerPeers = mempty + , pncDeadlineTargetOfEstablishedBigLedgerPeers = mempty + , pncDeadlineTargetOfActiveBigLedgerPeers = mempty + , pncSyncTargetNumberOfActivePeers = mempty + , pncSyncTargetNumberOfKnownBigLedgerPeers = mempty + , pncSyncTargetNumberOfEstablishedBigLedgerPeers = mempty + , pncSyncTargetNumberOfActiveBigLedgerPeers = mempty + , pncMinBigLedgerPeersForTrustedState = mempty , pncEnableP2P = Last (Just DisabledP2PMode) , pncPeerSharing = Last (Just PeerSharingDisabled) + , pncConsensusMode = mempty } -- | Example partial configuration theoretically created @@ -176,15 +180,21 @@ testPartialCliConfig = , pncTimeWaitTimeout = mempty , pncChainSyncIdleTimeout = mempty , pncAcceptedConnectionsLimit = mempty - , pncTargetNumberOfRootPeers = mempty - , pncTargetNumberOfKnownPeers = mempty - , pncTargetNumberOfEstablishedPeers = mempty - , pncTargetNumberOfActivePeers = mempty - , pncTargetNumberOfKnownBigLedgerPeers = mempty - , pncTargetNumberOfEstablishedBigLedgerPeers = mempty - , pncTargetNumberOfActiveBigLedgerPeers = mempty + , pncDeadlineTargetNumberOfRootPeers = mempty + , pncDeadlineTargetNumberOfKnownPeers = mempty + , pncDeadlineTargetNumberOfEstablishedPeers = mempty + , pncDeadlineTargetNumberOfActivePeers = mempty + , pncDeadlineTargetNumberOfKnownBigLedgerPeers = mempty + , pncDeadlineTargetNumberOfEstablishedBigLedgerPeers = mempty + , pncDeadlineTargetNumberOfActiveBigLedgerPeers = mempty + , pncSyncTargetNumberOfActivePeers = mempty + , pncSyncTargetNumberOfKnownBigLedgerPeers = mempty + , pncSyncTargetNumberOfEstablishedBigLedgerPeers = mempty + , pncSyncTargetNumberOfActiveBigLedgerPeers = mempty + , pncMinBigLedgerPeersForTrustedState = Last (Just defaultMinBigLedgerPeersForTrustedState) , pncEnableP2P = Last (Just DisabledP2PMode) , pncPeerSharing = Last (Just PeerSharingDisabled) + , pncConsensusMode = Last (Just PraosMode) } -- | Expected final NodeConfiguration @@ -222,15 +232,21 @@ eExpectedConfig = do , acceptedConnectionsSoftLimit = 384 , acceptedConnectionsDelay = 5 } - , ncTargetNumberOfRootPeers = 85 - , ncTargetNumberOfKnownPeers = 85 - , ncTargetNumberOfEstablishedPeers = 40 - , ncTargetNumberOfActivePeers = 15 - , ncTargetNumberOfKnownBigLedgerPeers = 15 - , ncTargetNumberOfEstablishedBigLedgerPeers = 10 - , ncTargetNumberOfActiveBigLedgerPeers = 5 + , ncDeadlineTargetNumberOfRootPeers = 60 + , ncDeadlineTargetNumberOfKnownPeers = 85 + , ncDeadlineTargetNumberOfEstablishedPeers = 40 + , ncDeadlineTargetNumberOfActivePeers = 15 + , ncDeadlineTargetNumberOfKnownBigLedgerPeers = 15 + , ncDeadlineTargetNumberOfEstablishedBigLedgerPeers = 10 + , ncDeadlineTargetNumberOfActiveBigLedgerPeers = 5 + , ncSyncTargetNumberOfActivePeers = 0 + , ncSyncTargetNumberOfKnownBigLedgerPeers = 100 + , ncSyncTargetNumberOfEstablishedBigLedgerPeers = 50 + , ncSyncTargetNumberOfActiveBigLedgerPeers = 30 + , ncMinBigLedgerPeersForTrustedState = defaultMinBigLedgerPeersForTrustedState , ncEnableP2P = SomeNetworkP2PMode Consensus.DisabledP2PMode , ncPeerSharing = PeerSharingDisabled + , ncConsensusMode = PraosMode } -- ----------------------------------------------------------------------------- diff --git a/configuration/cardano/mainnet-config.json b/configuration/cardano/mainnet-config.json index 388d0c43722..aaa3ed4a90f 100644 --- a/configuration/cardano/mainnet-config.json +++ b/configuration/cardano/mainnet-config.json @@ -16,6 +16,7 @@ "RequiresNetworkMagic": "RequiresNoMagic", "ShelleyGenesisFile": "mainnet-shelley-genesis.json", "ShelleyGenesisHash": "1a3be38bcbb7911969283716ad7aa550250226b76a61fc51cc9a9a35d9276d81", + "ConsensusMode": "PraosMode" "TargetNumberOfActivePeers": 20, "TargetNumberOfEstablishedPeers": 50, "TargetNumberOfKnownPeers": 150, diff --git a/configuration/cardano/mainnet-config.yaml b/configuration/cardano/mainnet-config.yaml index ef803181d62..e7a5a3c80cc 100644 --- a/configuration/cardano/mainnet-config.yaml +++ b/configuration/cardano/mainnet-config.yaml @@ -34,6 +34,7 @@ MaxKnownMajorProtocolVersion: 2 ##### Network Configuration ##### +ConsensusMode: PraosMode PeerSharing: True TargetNumberOfActivePeers: 20 TargetNumberOfEstablishedPeers: 50 diff --git a/configuration/cardano/shelley_qa-config.json b/configuration/cardano/shelley_qa-config.json index 925aefa76aa..2151c1908dc 100644 --- a/configuration/cardano/shelley_qa-config.json +++ b/configuration/cardano/shelley_qa-config.json @@ -17,6 +17,7 @@ "RequiresNetworkMagic": "RequiresMagic", "ShelleyGenesisFile": "shelley_qa-shelley-genesis.json", "ShelleyGenesisHash": "73a9f6bdb0aa97f5e63190a6f14a702bd64a21f2bec831cbfc28f6037128b952", + "ConsensusMode": "PraosMode" "TargetNumberOfActivePeers": 20, "TargetNumberOfEstablishedPeers": 50, "TargetNumberOfKnownPeers": 150,