Skip to content

Commit 6f7776b

Browse files
EstablishedPeers: Fixed an issue with unreachable peers when trying to promote other peers
1 parent 20aa2a2 commit 6f7776b

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

ouroboros-network/src/Ouroboros/Network/PeerSelection/Governor/EstablishedPeers.hs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ belowTarget
9696
belowTarget enableAction inboundPeers =
9797
belowTargetBigLedgerPeers enableAction
9898
<> belowTargetLocal inboundPeers
99-
<> belowTargetOther
99+
<> belowTargetOther inboundPeers
100100

101101

102102
-- | For locally configured root peers we have the explicit target that comes from local
@@ -200,6 +200,7 @@ belowTargetLocal inboundPeers
200200
, let potentialToPromote =
201201
-- These are local peers that are cold but not ready.
202202
localRootPeersSet
203+
Set.\\ unreachablePeers
203204
Set.\\ localEstablishedPeers
204205
Set.\\ KnownPeers.availableToConnect knownPeers
205206
, not (Set.null potentialToPromote)
@@ -239,7 +240,9 @@ belowTargetOther
239240
, Ord peeraddr
240241
, HasCallStack
241242
)
242-
=> PeerSelectionActions
243+
=> Map peeraddr PeerSharing
244+
-- ^ Inbound peers that have negotiated a duplex connection
245+
-> PeerSelectionActions
243246
extraState
244247
extraFlags
245248
extraPeers
@@ -256,7 +259,7 @@ belowTargetOther
256259
peeraddr
257260
peerconn
258261
m
259-
belowTargetOther actions@PeerSelectionActions {
262+
belowTargetOther inboundPeers actions@PeerSelectionActions {
260263
extraPeersAPI = PublicExtraPeersAPI {
261264
memberExtraPeers,
262265
extraPeersToSet
@@ -283,7 +286,7 @@ belowTargetOther actions@PeerSelectionActions {
283286
-- not cold and our invariant is that they are always in the connect set.
284287
-- We can also subtract the in progress ones since they are also already
285288
-- in the connect set and we cannot pick them again.
286-
, numAvailableToConnect - numFollowBackPeers - numEstablishedPeers - numConnectInProgress > 0
289+
, numAvailableToConnect - numUnreachablePeers - numEstablishedPeers - numConnectInProgress > 0
287290
= Guarded Nothing $ do
288291
-- The availableToPromote here is non-empty due to the second guard.
289292
-- The known peers map restricted to the connect set is the same size as
@@ -295,7 +298,7 @@ belowTargetOther actions@PeerSelectionActions {
295298
--
296299
let availableToPromote :: Set peeraddr
297300
availableToPromote = availableToConnect
298-
Set.\\ followBackPeers
301+
Set.\\ unreachablePeers
299302
Set.\\ EstablishedPeers.toSet establishedPeers
300303
Set.\\ inProgressPromoteCold
301304
numPeersToPromote = targetNumberOfEstablishedPeers
@@ -327,11 +330,15 @@ belowTargetOther actions@PeerSelectionActions {
327330
| otherwise
328331
= GuardedSkip Nothing
329332
where
330-
numFollowBackPeers = Set.size followBackPeers
333+
numUnreachablePeers = Set.size unreachablePeers
331334

332-
followBackPeers = Map.keysSet
333-
$ Map.filter (\(LocalRootConfig {followBack}) -> followBack)
334-
$ LocalRootPeers.toMap localRootPeers
335+
isUnreachablePeer addr (LocalRootConfig {followBack}) =
336+
followBack && not (Map.member addr inboundPeers)
337+
338+
unreachablePeers =
339+
Map.keysSet
340+
$ Map.filterWithKey isUnreachablePeer
341+
$ LocalRootPeers.toMap localRootPeers
335342

336343
PeerSelectionView {
337344
viewKnownBigLedgerPeers = (bigLedgerPeersSet, _),

0 commit comments

Comments
 (0)