From 9503dc6a1899e0cf37896f220bc79f6cd7083bce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20W=C3=B3jtowicz?= Date: Wed, 7 Aug 2024 12:44:52 +0200 Subject: [PATCH 1/5] Signalling OutboundConnectionsState to Consensus in Genesis * Added new type `MinBigLedgerPeersForTrustedState` to hold configurable parameter of how many hot active big ledger peers are needed to signal trusted state to consensus * Updated `outboundConnectionsState` with the appropriate logic for Genesis --- .../Network/PeerSelection/LedgerPeers/Type.hs | 14 +++++++ .../Network/PeerSelection/Governor.hs | 37 ++++++++++--------- .../Network/PeerSelection/Governor/Types.hs | 9 ++++- 3 files changed, 41 insertions(+), 19 deletions(-) diff --git a/ouroboros-network-api/src/Ouroboros/Network/PeerSelection/LedgerPeers/Type.hs b/ouroboros-network-api/src/Ouroboros/Network/PeerSelection/LedgerPeers/Type.hs index c420adbf272..b2a6190a834 100644 --- a/ouroboros-network-api/src/Ouroboros/Network/PeerSelection/LedgerPeers/Type.hs +++ b/ouroboros-network-api/src/Ouroboros/Network/PeerSelection/LedgerPeers/Type.hs @@ -24,6 +24,7 @@ module Ouroboros.Network.PeerSelection.LedgerPeers.Type , AfterSlot (..) , LedgerPeersKind (..) , LedgerPeerSnapshot (.., LedgerPeerSnapshot) + , MinBigLedgerPeersForTrustedState (..) , isLedgerPeersEnabled , compareLedgerPeerSnapshotApproximate ) where @@ -45,6 +46,19 @@ import Data.Aeson.Types import NoThunks.Class import Ouroboros.Network.PeerSelection.RelayAccessPoint +-- | Minimum number of hot big ledger peers in Genesis mode +-- for trusted state to be signalled to Consensus. This number +-- should be smaller than the `targetNumberOfActiveBigLedgerPeers` +-- but greater than 1. In Genesis, we may demote a big ledger peer +-- for underperformance, but not promote a replacement immediately +-- to guard against adversaries which may want to slow down our +-- progress. +-- +newtype MinBigLedgerPeersForTrustedState = + MinBigLedgerPeersForTrustedState { getMinBigLedgerPeersForTrustedState :: Int } + deriving stock (Eq, Show) + deriving newtype (FromJSON) + -- |The type of big ledger peers that is serialised or later -- provided by node configuration for the networking layer -- to connect to when syncing. diff --git a/ouroboros-network/src/Ouroboros/Network/PeerSelection/Governor.hs b/ouroboros-network/src/Ouroboros/Network/PeerSelection/Governor.hs index e37310f6df2..4fa59555c5f 100644 --- a/ouroboros-network/src/Ouroboros/Network/PeerSelection/Governor.hs +++ b/ouroboros-network/src/Ouroboros/Network/PeerSelection/Governor.hs @@ -81,7 +81,8 @@ import Ouroboros.Network.PeerSelection.Governor.KnownPeers qualified as KnownPee import Ouroboros.Network.PeerSelection.Governor.Monitor qualified as Monitor import Ouroboros.Network.PeerSelection.Governor.RootPeers qualified as RootPeers import Ouroboros.Network.PeerSelection.Governor.Types -import Ouroboros.Network.PeerSelection.LedgerPeers.Type (UseLedgerPeers (..)) +import Ouroboros.Network.PeerSelection.LedgerPeers.Type + (MinBigLedgerPeersForTrustedState (..), UseLedgerPeers (..)) import Ouroboros.Network.PeerSelection.LocalRootPeers (OutboundConnectionsState (..)) import Ouroboros.Network.PeerSelection.PeerSharing (PeerSharing (..)) @@ -742,26 +743,18 @@ outboundConnectionsState PeerSelectionView { viewEstablishedPeers = (viewEstablishedPeers, _), viewEstablishedBootstrapPeers = (viewEstablishedBootstrapPeers, _), - viewActiveBootstrapPeers = (viewActiveBootstrapPeers, _) + viewActiveBootstrapPeers = (viewActiveBootstrapPeers, _), + viewActiveBigLedgerPeers = (_, activeNumBigLedgerPeers) } PeerSelectionState { + consensusMode, localRootPeers, - bootstrapPeersFlag + bootstrapPeersFlag, + minBigLedgerPeersForTrustedState } = - case (associationMode, bootstrapPeersFlag) of - {- - -- genesis mode - -- TODO: issue #4846 - (LocalRootsOnly, _) - | numberOfActiveBigLedgerPeers >= targetNumberOfActiveBigLedgerPeers - -> TrustedStateWithExternalPeers - - | otherwise - -> UntrustedState - -} - - (LocalRootsOnly, _) + case (associationMode, bootstrapPeersFlag, consensusMode) of + (LocalRootsOnly, _, _) | -- we are only connected to trusted local root -- peers viewEstablishedPeers `Set.isSubsetOf` trustableLocalRootSet @@ -771,7 +764,7 @@ outboundConnectionsState -> UntrustedState -- bootstrap mode - (Unrestricted, UseBootstrapPeers {}) + (Unrestricted, UseBootstrapPeers {}, _) | -- we are only connected to trusted local root -- peers or bootstrap peers viewEstablishedPeers `Set.isSubsetOf` (viewEstablishedBootstrapPeers <> trustableLocalRootSet) @@ -783,7 +776,15 @@ outboundConnectionsState -> UntrustedState -- praos mode with public roots - (Unrestricted, DontUseBootstrapPeers) + (Unrestricted, DontUseBootstrapPeers, PraosMode) + -> UntrustedState + + -- Genesis mode + (Unrestricted, DontUseBootstrapPeers, GenesisMode) + | activeNumBigLedgerPeers >= getMinBigLedgerPeersForTrustedState minBigLedgerPeersForTrustedState + -> TrustedStateWithExternalPeers + + | otherwise -> UntrustedState where trustableLocalRootSet = LocalRootPeers.trustableKeysSet localRootPeers diff --git a/ouroboros-network/src/Ouroboros/Network/PeerSelection/Governor/Types.hs b/ouroboros-network/src/Ouroboros/Network/PeerSelection/Governor/Types.hs index 44a23a8226b..caf6625f879 100644 --- a/ouroboros-network/src/Ouroboros/Network/PeerSelection/Governor/Types.hs +++ b/ouroboros-network/src/Ouroboros/Network/PeerSelection/Governor/Types.hs @@ -583,7 +583,14 @@ data PeerSelectionState peeraddr peerconn = PeerSelectionState { -- | Internal state of ledger peer snapshot -- - ledgerPeerSnapshot :: Maybe LedgerPeerSnapshot + ledgerPeerSnapshot :: Maybe LedgerPeerSnapshot, + + -- | Use in Genesis mode to check whether we can signal to + -- consensus that we met criteria of trusted state to enter + -- deadline mode. This parameter comes from node configuration, + -- with a default value in the `Configuration` module. + -- + minBigLedgerPeersForTrustedState :: MinBigLedgerPeersForTrustedState -- TODO: need something like this to distinguish between lots of bad peers -- and us getting disconnected from the network locally. We don't want a -- network disconnect to cause us to flush our full known peer set by From 83b79e7f08c760fc2e2cc6888e8a26d9855dc365 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20W=C3=B3jtowicz?= Date: Wed, 7 Aug 2024 13:48:01 +0200 Subject: [PATCH 2/5] Thread configuration value from the top level --- .../src/Ouroboros/Network/Diffusion/P2P.hs | 19 ++++--- .../Network/PeerSelection/Governor.hs | 5 +- .../Network/PeerSelection/Governor/Types.hs | 54 ++++++++++--------- 3 files changed, 44 insertions(+), 34 deletions(-) diff --git a/ouroboros-network/src/Ouroboros/Network/Diffusion/P2P.hs b/ouroboros-network/src/Ouroboros/Network/Diffusion/P2P.hs index c1e62c788cc..9eb7a5960a4 100644 --- a/ouroboros-network/src/Ouroboros/Network/Diffusion/P2P.hs +++ b/ouroboros-network/src/Ouroboros/Network/Diffusion/P2P.hs @@ -117,12 +117,13 @@ import Ouroboros.Network.PeerSelection.LedgerPeers (TraceLedgerPeers, WithLedgerPeersArgs (..)) #ifdef POSIX import Ouroboros.Network.PeerSelection.LedgerPeers.Type (LedgerPeerSnapshot, - LedgerPeersConsensusInterface (..), UseLedgerPeers) + LedgerPeersConsensusInterface (..), MinBigLedgerPeersForTrustedState, + UseLedgerPeers) import Ouroboros.Network.PeerSelection.PeerMetric (PeerMetrics, fetchynessBlocks, upstreamyness) #else import Ouroboros.Network.PeerSelection.LedgerPeers.Type (LedgerPeerSnapshot, - UseLedgerPeers) + MinBigLedgerPeersForTrustedState, UseLedgerPeers) import Ouroboros.Network.PeerSelection.PeerMetric (PeerMetrics) #endif import Ouroboros.Network.ConsensusMode @@ -259,8 +260,12 @@ data ArgumentsExtra m = ArgumentsExtra { -- to get a strong guarantee that when syncing up we will finish with a true -- ledger state. When false, we will fall back on the previous algorithms -- that leverage UseBootstrapPeers flag - , daConsensusMode :: ConsensusMode - , daReadUseBootstrapPeers :: STM m UseBootstrapPeers + , daConsensusMode :: ConsensusMode + -- | For Genesis, this sets the floor for minimum number of + -- active big ledger peers we must be connected to in order + -- to be able to signal trusted state (OutboundConnectionsState) + , daMinBigLedgerPeersForTrustedState :: MinBigLedgerPeersForTrustedState + , daReadUseBootstrapPeers :: STM m UseBootstrapPeers -- | Depending on configuration, node may provide us with -- a snapshot of big ledger peers taken at some slot on the chain. -- These peers may be selected by ledgerPeersThread when requested @@ -648,6 +653,7 @@ runM Interfaces , daReadLocalRootPeers , daReadPublicRootPeers , daConsensusMode + , daMinBigLedgerPeersForTrustedState , daReadUseBootstrapPeers , daOwnPeerSharing , daReadUseLedgerPeers @@ -1026,6 +1032,7 @@ runM Interfaces dtTracePeerSelectionCounters fuzzRng daConsensusMode + daMinBigLedgerPeersForTrustedState peerSelectionActions peerSelectionPolicy PeerSelectionInterfaces { @@ -1102,7 +1109,7 @@ runM Interfaces -- InitiatorOnly mode, run peer selection only: InitiatorOnlyDiffusionMode -> withConnectionManagerInitiatorOnlyMode $ \connectionManager-> do - debugStateVar <- newTVarIO $ emptyPeerSelectionState fuzzRng daConsensusMode + debugStateVar <- newTVarIO $ emptyPeerSelectionState fuzzRng daConsensusMode daMinBigLedgerPeersForTrustedState diInstallSigUSR1Handler connectionManager debugStateVar daPeerMetrics withPeerStateActions' connectionManager $ \peerStateActions-> withPeerSelectionActions' @@ -1127,7 +1134,7 @@ runM Interfaces inboundInfoChannel $ \connectionManager -> withSockets' $ \sockets addresses -> do withServer sockets connectionManager inboundInfoChannel $ \inboundGovernorThread readInboundState -> do - debugStateVar <- newTVarIO $ emptyPeerSelectionState fuzzRng daConsensusMode + debugStateVar <- newTVarIO $ emptyPeerSelectionState fuzzRng daConsensusMode daMinBigLedgerPeersForTrustedState diInstallSigUSR1Handler connectionManager debugStateVar daPeerMetrics withPeerStateActions' connectionManager $ \peerStateActions -> withPeerSelectionActions' diff --git a/ouroboros-network/src/Ouroboros/Network/PeerSelection/Governor.hs b/ouroboros-network/src/Ouroboros/Network/PeerSelection/Governor.hs index 4fa59555c5f..8d38e98c077 100644 --- a/ouroboros-network/src/Ouroboros/Network/PeerSelection/Governor.hs +++ b/ouroboros-network/src/Ouroboros/Network/PeerSelection/Governor.hs @@ -477,11 +477,12 @@ peerSelectionGovernor :: ( Alternative (STM m) -> Tracer m PeerSelectionCounters -> StdGen -> ConsensusMode + -> MinBigLedgerPeersForTrustedState -- ^ Genesis parameter -> PeerSelectionActions peeraddr peerconn m -> PeerSelectionPolicy peeraddr m -> PeerSelectionInterfaces peeraddr peerconn m -> m Void -peerSelectionGovernor tracer debugTracer countersTracer fuzzRng consensusMode actions policy interfaces = +peerSelectionGovernor tracer debugTracer countersTracer fuzzRng consensusMode minActiveBigLedgerPeers actions policy interfaces = JobPool.withJobPool $ \jobPool -> peerSelectionGovernorLoop tracer @@ -491,7 +492,7 @@ peerSelectionGovernor tracer debugTracer countersTracer fuzzRng consensusMode ac policy interfaces jobPool - (emptyPeerSelectionState fuzzRng consensusMode) + (emptyPeerSelectionState fuzzRng consensusMode minActiveBigLedgerPeers) -- | Our pattern here is a loop with two sets of guarded actions: -- diff --git a/ouroboros-network/src/Ouroboros/Network/PeerSelection/Governor/Types.hs b/ouroboros-network/src/Ouroboros/Network/PeerSelection/Governor/Types.hs index caf6625f879..d03d4c710db 100644 --- a/ouroboros-network/src/Ouroboros/Network/PeerSelection/Governor/Types.hs +++ b/ouroboros-network/src/Ouroboros/Network/PeerSelection/Governor/Types.hs @@ -1214,35 +1214,37 @@ emptyPeerSelectionCounters = emptyPeerSelectionState :: StdGen -> ConsensusMode + -> MinBigLedgerPeersForTrustedState -> PeerSelectionState peeraddr peerconn -emptyPeerSelectionState rng consensusMode = +emptyPeerSelectionState rng consensusMode minActiveBigLedgerPeers = PeerSelectionState { - targets = nullPeerSelectionTargets, - localRootPeers = LocalRootPeers.empty, - publicRootPeers = PublicRootPeers.empty, - knownPeers = KnownPeers.empty, - establishedPeers = EstablishedPeers.empty, - activePeers = Set.empty, - publicRootBackoffs = 0, - publicRootRetryTime = Time 0, - inProgressPublicRootsReq = False, - bigLedgerPeerBackoffs = 0, - bigLedgerPeerRetryTime = Time 0, - inProgressBigLedgerPeersReq = False, - inProgressPeerShareReqs = 0, - inProgressPromoteCold = Set.empty, - inProgressPromoteWarm = Set.empty, - inProgressDemoteWarm = Set.empty, - inProgressDemoteHot = Set.empty, - inProgressDemoteToCold = Set.empty, - stdGen = rng, - ledgerStateJudgement = TooOld, + targets = nullPeerSelectionTargets, + localRootPeers = LocalRootPeers.empty, + publicRootPeers = PublicRootPeers.empty, + knownPeers = KnownPeers.empty, + establishedPeers = EstablishedPeers.empty, + activePeers = Set.empty, + publicRootBackoffs = 0, + publicRootRetryTime = Time 0, + inProgressPublicRootsReq = False, + bigLedgerPeerBackoffs = 0, + bigLedgerPeerRetryTime = Time 0, + inProgressBigLedgerPeersReq = False, + inProgressPeerShareReqs = 0, + inProgressPromoteCold = Set.empty, + inProgressPromoteWarm = Set.empty, + inProgressDemoteWarm = Set.empty, + inProgressDemoteHot = Set.empty, + inProgressDemoteToCold = Set.empty, + stdGen = rng, + ledgerStateJudgement = TooOld, consensusMode, - bootstrapPeersFlag = DontUseBootstrapPeers, - hasOnlyBootstrapPeers = False, - bootstrapPeersTimeout = Nothing, - inboundPeersRetryTime = Time 0, - ledgerPeerSnapshot = Nothing + bootstrapPeersFlag = DontUseBootstrapPeers, + hasOnlyBootstrapPeers = False, + bootstrapPeersTimeout = Nothing, + inboundPeersRetryTime = Time 0, + ledgerPeerSnapshot = Nothing, + minBigLedgerPeersForTrustedState = minActiveBigLedgerPeers } From 52d5123f45382f7705ae924698c59bb62c2e3552 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20W=C3=B3jtowicz?= Date: Wed, 7 Aug 2024 14:14:50 +0200 Subject: [PATCH 3/5] Integrate into testing framework --- .../sim-tests-lib/Test/Ouroboros/Network/Diffusion/Node.hs | 5 ++++- .../sim-tests-lib/Test/Ouroboros/Network/PeerSelection.hs | 6 ++++-- .../Test/Ouroboros/Network/PeerSelection/MockEnvironment.hs | 4 +++- .../sim-tests-lib/Test/Ouroboros/Network/Testnet.hs | 5 ++++- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/ouroboros-network/sim-tests-lib/Test/Ouroboros/Network/Diffusion/Node.hs b/ouroboros-network/sim-tests-lib/Test/Ouroboros/Network/Diffusion/Node.hs index cc32bfd08b4..45ef32e909d 100644 --- a/ouroboros-network/sim-tests-lib/Test/Ouroboros/Network/Diffusion/Node.hs +++ b/ouroboros-network/sim-tests-lib/Test/Ouroboros/Network/Diffusion/Node.hs @@ -94,7 +94,8 @@ import Simulation.Network.Snocket (AddressType (..), FD) import Ouroboros.Network.PeerSelection.Bootstrap (UseBootstrapPeers) import Ouroboros.Network.PeerSelection.LedgerPeers.Type - (LedgerPeersConsensusInterface, UseLedgerPeers) + (LedgerPeersConsensusInterface, + MinBigLedgerPeersForTrustedState (..), UseLedgerPeers) import Ouroboros.Network.PeerSelection.LocalRootPeers (OutboundConnectionsState) import Ouroboros.Network.PeerSelection.PeerAdvertise (PeerAdvertise (..)) import Ouroboros.Network.PeerSelection.PeerSharing (PeerSharing (..)) @@ -404,6 +405,8 @@ run blockGeneratorArgs limits ni na tracersExtra tracerBlockFetch = , Diff.P2P.daBulkChurnInterval = 300 , Diff.P2P.daReadLedgerPeerSnapshot = pure Nothing -- ^ tested independently , Diff.P2P.daConsensusMode = aConsensusMode na + , Diff.P2P.daMinBigLedgerPeersForTrustedState + = MinBigLedgerPeersForTrustedState 0 -- ^ todo: fix } appArgs :: Node.AppArgs BlockHeader Block m diff --git a/ouroboros-network/sim-tests-lib/Test/Ouroboros/Network/PeerSelection.hs b/ouroboros-network/sim-tests-lib/Test/Ouroboros/Network/PeerSelection.hs index 446b2aa4d1b..e436ef4eb56 100644 --- a/ouroboros-network/sim-tests-lib/Test/Ouroboros/Network/PeerSelection.hs +++ b/ouroboros-network/sim-tests-lib/Test/Ouroboros/Network/PeerSelection.hs @@ -3705,7 +3705,8 @@ selectGovState :: Eq a selectGovState f consensusMode = Signal.nub -- TODO: #3182 Rng seed should come from quickcheck. - . Signal.fromChangeEvents (f $! Governor.emptyPeerSelectionState (mkStdGen 42) consensusMode) + -- and `MinBigLedgerPeersForTrustedState` + . Signal.fromChangeEvents (f $! Governor.emptyPeerSelectionState (mkStdGen 42) consensusMode (MinBigLedgerPeersForTrustedState 0)) . Signal.selectEvents (\case GovernorDebug (TraceGovernorState _ _ st) -> Just $! f st _ -> Nothing) @@ -3744,7 +3745,7 @@ _governorFindingPublicRoots :: Int _governorFindingPublicRoots targetNumberOfRootPeers readDomains readUseBootstrapPeers readLedgerStateJudgement peerSharing olocVar consensusMode = do countersVar <- newTVarIO emptyPeerSelectionCounters publicStateVar <- makePublicPeerSelectionStateVar - debugStateVar <- newTVarIO $ emptyPeerSelectionState (mkStdGen 42) consensusMode + debugStateVar <- newTVarIO $ emptyPeerSelectionState (mkStdGen 42) consensusMode (MinBigLedgerPeersForTrustedState 0) dnsSemaphore <- newLedgerAndPublicRootDNSSemaphore let interfaces = PeerSelectionInterfaces { countersVar, @@ -3765,6 +3766,7 @@ _governorFindingPublicRoots targetNumberOfRootPeers readDomains readUseBootstrap -- TODO: #3182 Rng seed should come from quickcheck. (mkStdGen 42) consensusMode + (MinBigLedgerPeersForTrustedState 0) actions { requestPublicRootPeers = \_ -> transformPeerSelectionAction requestPublicRootPeers } diff --git a/ouroboros-network/sim-tests-lib/Test/Ouroboros/Network/PeerSelection/MockEnvironment.hs b/ouroboros-network/sim-tests-lib/Test/Ouroboros/Network/PeerSelection/MockEnvironment.hs index 2a5169b5f52..950b2ab6032 100644 --- a/ouroboros-network/sim-tests-lib/Test/Ouroboros/Network/PeerSelection/MockEnvironment.hs +++ b/ouroboros-network/sim-tests-lib/Test/Ouroboros/Network/PeerSelection/MockEnvironment.hs @@ -233,7 +233,8 @@ governorAction mockEnv@GovernorMockEnvironment { (useLedgerPeers mockEnv) usbVar <- playTimedScript (contramap TraceEnvSetUseBootstrapPeers tracerMockEnv) (useBootstrapPeers mockEnv) - debugStateVar <- StrictTVar.newTVarIO (emptyPeerSelectionState (mkStdGen 42) consensusMode) + -- todo: make MinBigLedgerPeersForTrustedState come from quickcheck + debugStateVar <- StrictTVar.newTVarIO (emptyPeerSelectionState (mkStdGen 42) consensusMode (MinBigLedgerPeersForTrustedState 0)) countersVar <- StrictTVar.newTVarIO emptyPeerSelectionCounters policy <- mockPeerSelectionPolicy mockEnv let initialPeerTargets = fst . NonEmpty.head $ targets' @@ -292,6 +293,7 @@ governorAction mockEnv@GovernorMockEnvironment { tracerTracePeerSelectionCounters (mkStdGen 42) consensusMode + (MinBigLedgerPeersForTrustedState 0) -- ^ todo: make this come from quickcheck actions policy interfaces diff --git a/ouroboros-network/sim-tests-lib/Test/Ouroboros/Network/Testnet.hs b/ouroboros-network/sim-tests-lib/Test/Ouroboros/Network/Testnet.hs index 1573cef015c..ef9fa856e61 100644 --- a/ouroboros-network/sim-tests-lib/Test/Ouroboros/Network/Testnet.hs +++ b/ouroboros-network/sim-tests-lib/Test/Ouroboros/Network/Testnet.hs @@ -3737,6 +3737,7 @@ selectDiffusionPeerSelectionState f = f $ Governor.emptyPeerSelectionState (mkStdGen 42) consensusMode + (MinBigLedgerPeersForTrustedState 0) -- ^ todo: fix selectDiffusionPeerSelectionState' :: Eq a => (forall peerconn. Governor.PeerSelectionState NtNAddr peerconn -> a) @@ -3744,7 +3745,9 @@ selectDiffusionPeerSelectionState' :: Eq a -> Signal a selectDiffusionPeerSelectionState' f = -- TODO: #3182 Rng seed should come from quickcheck. - Signal.fromChangeEvents (f $ Governor.emptyPeerSelectionState (mkStdGen 42) PraosMode) + Signal.fromChangeEvents (f $ Governor.emptyPeerSelectionState (mkStdGen 42) + PraosMode + (MinBigLedgerPeersForTrustedState 0)) . Signal.selectEvents (\case DiffusionDebugPeerSelectionTrace (TraceGovernorState _ _ st) -> Just (f st) From a6df139d3b8779ec1e7f30f2943e59412f98ac80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20W=C3=B3jtowicz?= Date: Wed, 7 Aug 2024 11:31:50 +0200 Subject: [PATCH 4/5] Changes to Configuration module * Renamed default peer selection target values in config module * Added default minimum number of big ledger peers we must be connected to when syncing in Genesis to be able to eventually leave untrusted state by signalling it to Consensus. --- .../Network/Diffusion/Configuration.hs | 42 +++++++++++++++---- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/ouroboros-network/src/Ouroboros/Network/Diffusion/Configuration.hs b/ouroboros-network/src/Ouroboros/Network/Diffusion/Configuration.hs index 5128bbbeeb1..9a94ff19ac4 100644 --- a/ouroboros-network/src/Ouroboros/Network/Diffusion/Configuration.hs +++ b/ouroboros-network/src/Ouroboros/Network/Diffusion/Configuration.hs @@ -5,14 +5,17 @@ module Ouroboros.Network.Diffusion.Configuration ( DefaultNumBootstrapPeers (..) + , MinBigLedgerPeersForTrustedState (..) , defaultNumBootstrapPeers , defaultAcceptedConnectionsLimit , defaultDiffusionMode , defaultPeerSharing , defaultBlockFetchConfiguration , defaultChainSyncTimeout - , defaultPraosTargets - , defaultGenesisSyncTargets + , defaultDeadlineTargets + , defaultSyncTargets + , defaultDeadlineChurnInterval + , defaultBulkChurnInterval -- re-exports , AcceptedConnectionsLimit (..) , BlockFetchConfiguration (..) @@ -25,6 +28,7 @@ module Ouroboros.Network.Diffusion.Configuration , PeerSharing (..) , ConsensusMode (..) , defaultConsensusMode + , defaultMinBigLedgerPeersForTrustedState , defaultMiniProtocolParameters , deactivateTimeout , closeConnectionTimeout @@ -37,6 +41,7 @@ module Ouroboros.Network.Diffusion.Configuration , ps_POLICY_PEER_SHARE_MAX_PEERS ) where +import Control.Monad.Class.MonadTime.SI import System.Random (randomRIO) import Ouroboros.Network.BlockFetch (BlockFetchConfiguration (..)) @@ -51,6 +56,8 @@ import Ouroboros.Network.NodeToNode (DiffusionMode (..), MiniProtocolParameters (..), defaultMiniProtocolParameters) import Ouroboros.Network.PeerSelection.Governor.Types (ConsensusModePeerTargets (..), PeerSelectionTargets (..)) +import Ouroboros.Network.PeerSelection.LedgerPeers.Type + (MinBigLedgerPeersForTrustedState (..)) import Ouroboros.Network.PeerSelection.PeerSharing (PeerSharing (..)) import Ouroboros.Network.PeerSharing (ps_POLICY_PEER_SHARE_MAX_PEERS, ps_POLICY_PEER_SHARE_STICKY_TIME) @@ -59,6 +66,7 @@ import Ouroboros.Network.Protocol.Handshake (handshake_QUERY_SHUTDOWN_DELAY) import Ouroboros.Network.Protocol.Limits (shortWait) import Ouroboros.Network.Server.RateLimiting (AcceptedConnectionsLimit (..)) + -- | Default number of bootstrap peers -- newtype DefaultNumBootstrapPeers = DefaultNumBootstrapPeers { getDefaultNumBootstrapPeers :: Int } @@ -73,8 +81,8 @@ defaultNumBootstrapPeers = DefaultNumBootstrapPeers 30 -- | Default peer targets in Praos mode -- -defaultPraosTargets :: PeerSelectionTargets -defaultPraosTargets = +defaultDeadlineTargets :: PeerSelectionTargets +defaultDeadlineTargets = PeerSelectionTargets { targetNumberOfRootPeers = 60, targetNumberOfKnownPeers = 85, @@ -87,14 +95,28 @@ defaultPraosTargets = -- | These targets are established when Genesis mode is enabled -- in node configuration and when the node is syncing up -- -defaultGenesisSyncTargets :: PeerSelectionTargets -defaultGenesisSyncTargets = - defaultPraosTargets { +defaultSyncTargets :: PeerSelectionTargets +defaultSyncTargets = + defaultDeadlineTargets { targetNumberOfActivePeers = 0, targetNumberOfKnownBigLedgerPeers = 100, targetNumberOfEstablishedBigLedgerPeers = 50, targetNumberOfActiveBigLedgerPeers = 30 } +-- | This parameter controls the minimum number of active connections +-- with big ledger peers that must be maintained when syncing in +-- Genesis mode such that trusted state can be signalled to Consensus. +-- Exiting syncing / entering deadline mode is predicated on this +-- condition. This should be below `targetNumberOfActiveBigLedgerPeers` +-- in `syncTargets` otherwise untrusted state will never be departed. +-- This value is lower than the target, because in Genesis we may +-- demote a big ledger peer for underperformance and not immediately +-- promote one from the warm set in case there are adversaries +-- whom are intentionally trying to slow us down. +-- +defaultMinBigLedgerPeersForTrustedState :: MinBigLedgerPeersForTrustedState +defaultMinBigLedgerPeersForTrustedState = MinBigLedgerPeersForTrustedState 5 + -- | Inbound governor targets -- defaultAcceptedConnectionsLimit :: AcceptedConnectionsLimit @@ -151,3 +173,9 @@ defaultChainSyncTimeout = do intersectTimeout = shortWait, mustReplyTimeout, idleTimeout = Just 3673 } + +defaultDeadlineChurnInterval :: DiffTime +defaultDeadlineChurnInterval = 3300 + +defaultBulkChurnInterval :: DiffTime +defaultBulkChurnInterval = 900 From f642bc3a0cff2e18268929487b46c4551c3c8058 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20W=C3=B3jtowicz?= Date: Mon, 12 Aug 2024 12:13:45 +0200 Subject: [PATCH 5/5] update changelogs --- ouroboros-network-api/CHANGELOG.md | 3 +++ ouroboros-network/CHANGELOG.md | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/ouroboros-network-api/CHANGELOG.md b/ouroboros-network-api/CHANGELOG.md index 25333156d6a..4f33f578f6c 100644 --- a/ouroboros-network-api/CHANGELOG.md +++ b/ouroboros-network-api/CHANGELOG.md @@ -15,6 +15,9 @@ * added `compareLedgerPeerSnapshotApproximate` function which compares two snapshots for approximate equality wrt stake distribution and fully qualified domain names. +* Added `MinBigLedgerPeersForTrustedState` type of values indicating + the minimum number of active big ledger peers needed to signal + trusted state when finishing syncing in Genesis mode. ## 0.8.0.0 -- 2024-08-07 diff --git a/ouroboros-network/CHANGELOG.md b/ouroboros-network/CHANGELOG.md index 6a36378de52..d9da9820e6c 100644 --- a/ouroboros-network/CHANGELOG.md +++ b/ouroboros-network/CHANGELOG.md @@ -19,7 +19,10 @@ or Genesis mode, which influences what `PeerSelectionTargets` both governors should use. Genesis may use two different sets of targets depending on ledger state, while Praos uses only one set. Either set - once active is appropriately churned. + once active is appropriately churned. +* Added `daMinBigLedgerPeersForTrustedState` to `ArgumentsExtra` when starting diffusion. + It is used by `outboundConnectionsState` when signaling trust state when syncing in + Genesis mode. Default value is provided by the Configuration module. ### Non-Breaking changes @@ -31,9 +34,12 @@ peers * Implemented separate configurable peer selection targets for Praos and Genesis consensus modes. Genesis mode may use more big ledger peers when + a node is syncing up. * Implemented verification of big ledger peer snapshot when syncing reaches the point at which the snapshot was taken. An error is raised when there's a mismatch detected. +* Added `defaultDeadlineChurnInterval` and `defaultBulkChurnInterval` to Configuration + module. Previously these were hard coded in node. ## 0.17.0.0 -- 2024-08-07