Skip to content

Commit

Permalink
Merge pull request #4921 from IntersectMBO/mwojtowicz/config-default-…
Browse files Browse the repository at this point in the history
…targets-renaming

OutboundConnectionsState logic for Genesis
  • Loading branch information
crocodile-dentist authored Aug 12, 2024
2 parents 7f6bf41 + f642bc3 commit e6737af
Show file tree
Hide file tree
Showing 11 changed files with 145 additions and 66 deletions.
3 changes: 3 additions & 0 deletions ouroboros-network-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module Ouroboros.Network.PeerSelection.LedgerPeers.Type
, AfterSlot (..)
, LedgerPeersKind (..)
, LedgerPeerSnapshot (.., LedgerPeerSnapshot)
, MinBigLedgerPeersForTrustedState (..)
, isLedgerPeersEnabled
, compareLedgerPeerSnapshotApproximate
) where
Expand All @@ -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.
Expand Down
8 changes: 7 additions & 1 deletion ouroboros-network/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (..))
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -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 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -292,6 +293,7 @@ governorAction mockEnv@GovernorMockEnvironment {
tracerTracePeerSelectionCounters
(mkStdGen 42)
consensusMode
(MinBigLedgerPeersForTrustedState 0) -- ^ todo: make this come from quickcheck
actions
policy
interfaces
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3737,14 +3737,17 @@ selectDiffusionPeerSelectionState f =
f $ Governor.emptyPeerSelectionState
(mkStdGen 42)
consensusMode
(MinBigLedgerPeersForTrustedState 0) -- ^ todo: fix

selectDiffusionPeerSelectionState' :: Eq a
=> (forall peerconn. Governor.PeerSelectionState NtNAddr peerconn -> a)
-> Events DiffusionTestTrace
-> 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)
Expand Down
42 changes: 35 additions & 7 deletions ouroboros-network/src/Ouroboros/Network/Diffusion/Configuration.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 (..)
Expand All @@ -25,6 +28,7 @@ module Ouroboros.Network.Diffusion.Configuration
, PeerSharing (..)
, ConsensusMode (..)
, defaultConsensusMode
, defaultMinBigLedgerPeersForTrustedState
, defaultMiniProtocolParameters
, deactivateTimeout
, closeConnectionTimeout
Expand All @@ -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 (..))
Expand All @@ -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)
Expand All @@ -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 }
Expand All @@ -73,8 +81,8 @@ defaultNumBootstrapPeers = DefaultNumBootstrapPeers 30

-- | Default peer targets in Praos mode
--
defaultPraosTargets :: PeerSelectionTargets
defaultPraosTargets =
defaultDeadlineTargets :: PeerSelectionTargets
defaultDeadlineTargets =
PeerSelectionTargets {
targetNumberOfRootPeers = 60,
targetNumberOfKnownPeers = 85,
Expand All @@ -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
Expand Down Expand Up @@ -151,3 +173,9 @@ defaultChainSyncTimeout = do
intersectTimeout = shortWait,
mustReplyTimeout,
idleTimeout = Just 3673 }

defaultDeadlineChurnInterval :: DiffTime
defaultDeadlineChurnInterval = 3300

defaultBulkChurnInterval :: DiffTime
defaultBulkChurnInterval = 900
19 changes: 13 additions & 6 deletions ouroboros-network/src/Ouroboros/Network/Diffusion/P2P.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -648,6 +653,7 @@ runM Interfaces
, daReadLocalRootPeers
, daReadPublicRootPeers
, daConsensusMode
, daMinBigLedgerPeersForTrustedState
, daReadUseBootstrapPeers
, daOwnPeerSharing
, daReadUseLedgerPeers
Expand Down Expand Up @@ -1026,6 +1032,7 @@ runM Interfaces
dtTracePeerSelectionCounters
fuzzRng
daConsensusMode
daMinBigLedgerPeersForTrustedState
peerSelectionActions
peerSelectionPolicy
PeerSelectionInterfaces {
Expand Down Expand Up @@ -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'
Expand All @@ -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'
Expand Down
Loading

0 comments on commit e6737af

Please sign in to comment.