Skip to content

Commit

Permalink
churn: implemented explicit synchronisation
Browse files Browse the repository at this point in the history
Chrun now explicitly synchronises with outbound governor using
`PeerSelectionCounters`.  Each churn action can timeout.

Co-authored-by: Armando Santos (@bolt12)
Co-authored-by: Marcin Szamotulski (@coot)
  • Loading branch information
coot committed Apr 6, 2024
1 parent 859aa61 commit e3feca1
Show file tree
Hide file tree
Showing 8 changed files with 415 additions and 157 deletions.
3 changes: 3 additions & 0 deletions ouroboros-network/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

### Non-Breaking changes

* Improved Churn governor by synchronizing according to the counters instead
of relying on `threadDelay`.

## 0.14.0.0 -- 2024-04-04

### Breaking changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,8 @@ traceNum TraceBootstrapPeersFlagChangedWhilstInSensitiveState = 51
traceNum TraceUseBootstrapPeersChanged {} = 52
traceNum TraceOutboundGovernorCriticalFailure {} = 53
traceNum TraceDebugState {} = 54
traceNum TraceChurnAction {} = 55
traceNum TraceChurnTimeout {} = 56

allTraceNames :: Map Int String
allTraceNames =
Expand Down Expand Up @@ -768,6 +770,8 @@ allTraceNames =
, (52, "TraceUseBootstrapPeersChanged")
, (53, "TraceOutboundGovernorCriticalFailure")
, (54, "TraceDebugState")
, (55, "TraceChurnAction")
, (55, "TraceChurnTimeout")
]


Expand Down Expand Up @@ -3333,10 +3337,12 @@ _governorFindingPublicRoots targetNumberOfRootPeers readDomains readUseBootstrap
(ioDNSActions LookupReqAAndAAAA) $ \requestPublicRootPeers -> do
publicStateVar <- makePublicPeerSelectionStateVar
debugVar <- newTVarIO $ emptyPeerSelectionState (mkStdGen 42) []
countersVar <- newTVarIO $ emptyPeerSelectionCounters []
peerSelectionGovernor
tracer tracer tracer
-- TODO: #3182 Rng seed should come from quickcheck.
(mkStdGen 42)
countersVar
publicStateVar
debugVar
actions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ governorAction mockEnv = do
usbVar <- playTimedScript (contramap TraceEnvSetUseBootstrapPeers tracerMockEnv)
(useBootstrapPeers mockEnv)
debugVar <- StrictTVar.newTVarIO (emptyPeerSelectionState (mkStdGen 42) [])
countersVar <- StrictTVar.newTVarIO (emptyPeerSelectionCounters [])
policy <- mockPeerSelectionPolicy mockEnv
actions <- mockPeerSelectionActions tracerMockEnv mockEnv (readTVar usbVar) (readTVar lsjVar) policy
exploreRaces -- explore races within the governor
Expand All @@ -221,6 +222,7 @@ governorAction mockEnv = do
tracerDebugPeerSelection
tracerTracePeerSelectionCounters
(mkStdGen 42)
countersVar
publicStateVar
debugVar
actions
Expand Down Expand Up @@ -655,6 +657,8 @@ tracerTracePeerSelection = contramap f tracerTestTraceEvent
f a@(TraceUseBootstrapPeersChanged !_) = GovernorEvent a
f a@(TraceOutboundGovernorCriticalFailure !_) = GovernorEvent a
f a@(TraceDebugState !_ !_) = GovernorEvent a
f a@(TraceChurnAction !_) = GovernorEvent a
f a@(TraceChurnTimeout !_) = GovernorEvent a

tracerDebugPeerSelection :: Tracer (IOSim s) (DebugPeerSelection PeerAddr)
tracerDebugPeerSelection = GovernorDebug `contramap` tracerTestTraceEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,10 @@ prop_peer_selection_trace_coverage defaultBearerInfo diffScript =
"TraceOutboundGovernorCriticalFailure"
peerSelectionTraceMap TraceDebugState {} =
"TraceDebugState"
peerSelectionTraceMap TraceChurnAction {} =
"TraceChurnTimeout"
peerSelectionTraceMap TraceChurnTimeout {} =
"TraceChurnTimeout"

eventsSeenNames = map peerSelectionTraceMap events

Expand Down
7 changes: 6 additions & 1 deletion ouroboros-network/src/Ouroboros/Network/Diffusion/P2P.hs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ import Ouroboros.Network.PeerSelection.Governor.Types
(ChurnMode (ChurnModeNormal), DebugPeerSelection (..),
PeerSelectionActions, PeerSelectionCounters (..),
PeerSelectionPolicy (..), PeerSelectionState,
TracePeerSelection (..), emptyPeerSelectionState)
TracePeerSelection (..), emptyPeerSelectionState,
emptyPeerSelectionCounters)
#ifdef POSIX
import Ouroboros.Network.PeerSelection.Governor.Types
(makeDebugPeerSelectionState)
Expand Down Expand Up @@ -807,6 +808,8 @@ runM Interfaces
min 2 (targetNumberOfActivePeers daPeerSelectionTargets)
}

countersVar <- newTVarIO (emptyPeerSelectionCounters [])

-- Design notes:
-- - We split the following code into two parts:
-- - Part (a): plumb data flow (in particular arguments and tracersr)
Expand Down Expand Up @@ -996,6 +999,7 @@ runM Interfaces
peerSelectionTracer
dtTracePeerSelectionCounters
fuzzRng
countersVar
daPublicPeerSelectionVar
dbgVar
peerSelectionActions
Expand All @@ -1015,6 +1019,7 @@ runM Interfaces
daBlockFetchMode
daPeerSelectionTargets
peerSelectionTargetsVar
countersVar
daReadUseBootstrapPeers

--
Expand Down
Loading

0 comments on commit e3feca1

Please sign in to comment.