@@ -135,16 +135,15 @@ import Data.Function (on)
135
135
import qualified Data.List as List
136
136
import Data.List.NonEmpty (nonEmpty )
137
137
import qualified Data.List.NonEmpty as NE
138
- import Data.Maybe (listToMaybe , mapMaybe , maybeToList , isNothing )
139
- import qualified Data.Set as Set
138
+ import Data.Maybe (mapMaybe , maybeToList , isNothing )
140
139
import Data.Ord (Down (Down ))
141
140
142
141
import Cardano.Prelude (partitionEithers )
143
142
144
143
import Ouroboros.Network.AnchoredFragment (AnchoredFragment , headBlockNo )
145
144
import qualified Ouroboros.Network.AnchoredFragment as AF
146
145
import Ouroboros.Network.Block
147
- import Ouroboros.Network.BlockFetch.ClientState (FetchRequest (.. ), PeersOrder (.. ), PeerFetchInFlight ( .. ) )
146
+ import Ouroboros.Network.BlockFetch.ClientState (FetchRequest (.. ), PeersOrder (.. ))
148
147
import Ouroboros.Network.BlockFetch.ConsensusInterface (FetchMode (FetchModeBulkSync ))
149
148
import Ouroboros.Network.BlockFetch.DeltaQ (calculatePeerFetchInFlightLimits )
150
149
import Ouroboros.Network.BlockFetch.ConsensusInterface (ChainSelStarvation (.. ))
@@ -208,15 +207,6 @@ fetchDecisionsBulkSyncM
208
207
(map (peerInfoPeer . snd ) candidatesAndPeers)
209
208
peersOrder0
210
209
211
- let peersOrderCurrentInfo = do
212
- currentPeer <- peersOrderCurrent
213
- listToMaybe
214
- [ peerCurrentInfo
215
- | (_, peerCurrentInfo@ (_, inflight, _, peer, _)) <- candidatesAndPeers
216
- , peer == currentPeer
217
- , not (Set. null (peerFetchBlocksInFlight inflight))
218
- ]
219
-
220
210
-- Compute the actual block fetch decision. This contains only declines and
221
211
-- at most one request. 'theDecision' is therefore a 'Maybe'.
222
212
let (theDecision, declines) =
@@ -226,7 +216,6 @@ fetchDecisionsBulkSyncM
226
216
fetchedBlocks
227
217
fetchedMaxSlotNo
228
218
peersOrder
229
- peersOrderCurrentInfo
230
219
candidatesAndPeers
231
220
232
221
-- If there were no blocks in flight, then this will be the first request,
@@ -307,8 +296,6 @@ fetchDecisionsBulkSync ::
307
296
(Point block -> Bool ) ->
308
297
MaxSlotNo ->
309
298
PeersOrder peer ->
310
- -- | The current peer, if there is one.
311
- Maybe (PeerInfo header peer extra ) ->
312
299
-- | Association list of the candidate fragments and their associated peers.
313
300
-- The candidate fragments are anchored in the current chain (not necessarily
314
301
-- at the tip; and not necessarily forking off immediately).
@@ -326,7 +313,6 @@ fetchDecisionsBulkSync
326
313
fetchedBlocks
327
314
fetchedMaxSlotNo
328
315
peersOrder
329
- mCurrentPeer
330
316
candidatesAndPeers = combineWithDeclined $ do
331
317
-- Step 1: Select the candidate to sync from. This already eliminates peers
332
318
-- that have an implausible candidate. It returns the remaining candidates
@@ -355,7 +341,6 @@ fetchDecisionsBulkSync
355
341
MaybeT $
356
342
selectThePeer
357
343
peersOrder
358
- mCurrentPeer
359
344
theFragments
360
345
candidatesAndPeers'
361
346
@@ -435,8 +420,6 @@ selectThePeer ::
435
420
Eq peer
436
421
) =>
437
422
PeersOrder peer ->
438
- -- | The current peer
439
- Maybe (PeerInfo header peer extra ) ->
440
423
-- | The candidate fragment that we have selected to sync from, as suffix of
441
424
-- the immutable tip.
442
425
FetchDecision (CandidateFragments header ) ->
@@ -448,7 +431,6 @@ selectThePeer ::
448
431
(Maybe (ChainSuffix header , PeerInfo header peer extra ))
449
432
selectThePeer
450
433
peersOrder
451
- mCurrentPeer
452
434
theFragments
453
435
candidates = do
454
436
-- Create a fetch request for the blocks in question. The request has exactly
@@ -459,9 +441,13 @@ selectThePeer
459
441
let firstBlock = FetchRequest . map (AF. takeOldest 1 ) . take 1 . filter (not . AF. null )
460
442
(grossRequest :: FetchDecision (FetchRequest header )) = firstBlock . snd <$> theFragments
461
443
444
+ peersOrderCurrentInfo = do
445
+ currentPeer <- peersOrderCurrent peersOrder
446
+ List. find ((currentPeer == ) . peerInfoPeer) $ map snd candidates
447
+
462
448
-- If there is a current peer, then that is the one we choose. Otherwise, we
463
449
-- can choose any peer, so we choose a “good” one.
464
- case mCurrentPeer of
450
+ case peersOrderCurrentInfo of
465
451
Just thePeerInfo -> do
466
452
case List. break (((==) `on` peerInfoPeer) thePeerInfo . snd ) candidates of
467
453
(_, [] ) -> tell (List [(FetchDeclineChainNotPlausible , thePeerInfo)]) >> return Nothing
0 commit comments