Skip to content

Commit

Permalink
outbound-governor: inboundPeersRetryTime
Browse files Browse the repository at this point in the history
  • Loading branch information
coot committed May 6, 2024
1 parent e9405b8 commit 5fa16ed
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
9 changes: 9 additions & 0 deletions ouroboros-network/src/Ouroboros/Network/Diffusion/Policies.hs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ peerMetricsConfiguration = PeerMetricsConfiguration {
}


-- | Minimal delay between adding inbound peers to known set of outbound
-- governor.
--
-- It is set to 60s, the same as the peer sharing request timeout.
--
inboundPeersRetryDelay :: DiffTime
inboundPeersRetryDelay = 60


-- | Maximal number of light peers included at once.
--
maxInboundPeers :: Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,8 @@ peerSelectionGovernorLoop tracer

-- All the alternative non-blocking internal decisions.
<> RootPeers.belowTarget actions blockedAt st
<> KnownPeers.belowTarget actions inboundPeers policy st
<> KnownPeers.belowTarget actions blockedAt
inboundPeers policy st
<> KnownPeers.aboveTarget policy st
<> EstablishedPeers.belowTarget actions policy st
<> EstablishedPeers.aboveTarget actions policy st
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ import Ouroboros.Network.Protocol.PeerSharing.Type (PeerSharingAmount)
belowTarget
:: (MonadAsync m, MonadTimer m, Ord peeraddr, Hashable peeraddr)
=> PeerSelectionActions peeraddr peerconn m
-> Time -- ^ blocked at
-> Map peeraddr PeerSharing
-> MkGuardedDecision peeraddr peerconn m
belowTarget actions@PeerSelectionActions { peerSharing }
blockedAt
inboundPeers
policy@PeerSelectionPolicy {
policyMaxInProgressPeerShareReqs,
Expand All @@ -69,6 +71,7 @@ belowTarget actions@PeerSelectionActions { peerSharing }
establishedPeers,
inProgressPeerShareReqs,
inProgressDemoteToCold,
inboundPeersRetryTime,
targets = PeerSelectionTargets {
targetNumberOfKnownPeers
},
Expand All @@ -90,6 +93,8 @@ belowTarget actions@PeerSelectionActions { peerSharing }
-- No inbound peers should be used when the node is using bootstrap peers.
, not (requiresBootstrapPeers bootstrapPeersFlag ledgerStateJudgement)

, blockedAt >= inboundPeersRetryTime

-- Use inbound peers either if it won the coin flip or if there are no
-- available peers to do peer sharing.
, useInboundPeers || Set.null availableForPeerShare
Expand All @@ -105,7 +110,7 @@ belowTarget actions@PeerSelectionActions { peerSharing }
availablePeers
(Policies.maxInboundPeers `min` (targetNumberOfKnownPeers - numKnownPeers))
let selectedMap = inboundPeers `Map.restrictKeys` selected
return $ \_now -> Decision {
return $ \now -> Decision {
decisionTrace = [TracePickInboundPeers
targetNumberOfKnownPeers
numKnownPeers
Expand All @@ -116,7 +121,9 @@ belowTarget actions@PeerSelectionActions { peerSharing }
$ KnownPeers.insert
(Map.map (\ps -> (Just ps, Just DoAdvertisePeer)) selectedMap)
knownPeers,
inboundPeersRetryTime = Policies.inboundPeersRetryDelay `addTime` now,
stdGen = stdGen'

},
decisionJobs = []
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,12 @@ data PeerSelectionState peeraddr peerconn = PeerSelectionState {

-- | Has the governor fully reset its state
--
bootstrapPeersTimeout :: !(Maybe Time)
bootstrapPeersTimeout :: !(Maybe Time),

-- | Time to query of inbound peers time.
--
inboundPeersRetryTime :: !Time


-- 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
Expand Down Expand Up @@ -1209,7 +1214,8 @@ emptyPeerSelectionState rng =
ledgerStateJudgement = TooOld,
bootstrapPeersFlag = DontUseBootstrapPeers,
hasOnlyBootstrapPeers = False,
bootstrapPeersTimeout = Nothing
bootstrapPeersTimeout = Nothing,
inboundPeersRetryTime = Time 0
}


Expand Down

0 comments on commit 5fa16ed

Please sign in to comment.