Skip to content

Commit 093b45f

Browse files
Retrieve PeerInfo of the current peer where it is used
1 parent fe917f3 commit 093b45f

File tree

1 file changed

+7
-21
lines changed
  • ouroboros-network/src/Ouroboros/Network/BlockFetch/Decision

1 file changed

+7
-21
lines changed

ouroboros-network/src/Ouroboros/Network/BlockFetch/Decision/BulkSync.hs

+7-21
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,15 @@ import Data.Function (on)
135135
import qualified Data.List as List
136136
import Data.List.NonEmpty (nonEmpty)
137137
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)
140139
import Data.Ord (Down(Down))
141140

142141
import Cardano.Prelude (partitionEithers)
143142

144143
import Ouroboros.Network.AnchoredFragment (AnchoredFragment, headBlockNo)
145144
import qualified Ouroboros.Network.AnchoredFragment as AF
146145
import Ouroboros.Network.Block
147-
import Ouroboros.Network.BlockFetch.ClientState (FetchRequest (..), PeersOrder (..), PeerFetchInFlight (..))
146+
import Ouroboros.Network.BlockFetch.ClientState (FetchRequest (..), PeersOrder (..))
148147
import Ouroboros.Network.BlockFetch.ConsensusInterface (FetchMode(FetchModeBulkSync))
149148
import Ouroboros.Network.BlockFetch.DeltaQ (calculatePeerFetchInFlightLimits)
150149
import Ouroboros.Network.BlockFetch.ConsensusInterface (ChainSelStarvation(..))
@@ -208,15 +207,6 @@ fetchDecisionsBulkSyncM
208207
(map (peerInfoPeer . snd) candidatesAndPeers)
209208
peersOrder0
210209

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-
220210
-- Compute the actual block fetch decision. This contains only declines and
221211
-- at most one request. 'theDecision' is therefore a 'Maybe'.
222212
let (theDecision, declines) =
@@ -226,7 +216,6 @@ fetchDecisionsBulkSyncM
226216
fetchedBlocks
227217
fetchedMaxSlotNo
228218
peersOrder
229-
peersOrderCurrentInfo
230219
candidatesAndPeers
231220

232221
-- If there were no blocks in flight, then this will be the first request,
@@ -307,8 +296,6 @@ fetchDecisionsBulkSync ::
307296
(Point block -> Bool) ->
308297
MaxSlotNo ->
309298
PeersOrder peer ->
310-
-- | The current peer, if there is one.
311-
Maybe (PeerInfo header peer extra) ->
312299
-- | Association list of the candidate fragments and their associated peers.
313300
-- The candidate fragments are anchored in the current chain (not necessarily
314301
-- at the tip; and not necessarily forking off immediately).
@@ -326,7 +313,6 @@ fetchDecisionsBulkSync
326313
fetchedBlocks
327314
fetchedMaxSlotNo
328315
peersOrder
329-
mCurrentPeer
330316
candidatesAndPeers = combineWithDeclined $ do
331317
-- Step 1: Select the candidate to sync from. This already eliminates peers
332318
-- that have an implausible candidate. It returns the remaining candidates
@@ -355,7 +341,6 @@ fetchDecisionsBulkSync
355341
MaybeT $
356342
selectThePeer
357343
peersOrder
358-
mCurrentPeer
359344
theFragments
360345
candidatesAndPeers'
361346

@@ -435,8 +420,6 @@ selectThePeer ::
435420
Eq peer
436421
) =>
437422
PeersOrder peer ->
438-
-- | The current peer
439-
Maybe (PeerInfo header peer extra) ->
440423
-- | The candidate fragment that we have selected to sync from, as suffix of
441424
-- the immutable tip.
442425
FetchDecision (CandidateFragments header) ->
@@ -448,7 +431,6 @@ selectThePeer ::
448431
(Maybe (ChainSuffix header, PeerInfo header peer extra))
449432
selectThePeer
450433
peersOrder
451-
mCurrentPeer
452434
theFragments
453435
candidates = do
454436
-- Create a fetch request for the blocks in question. The request has exactly
@@ -459,9 +441,13 @@ selectThePeer
459441
let firstBlock = FetchRequest . map (AF.takeOldest 1) . take 1 . filter (not . AF.null)
460442
(grossRequest :: FetchDecision (FetchRequest header)) = firstBlock . snd <$> theFragments
461443

444+
peersOrderCurrentInfo = do
445+
currentPeer <- peersOrderCurrent peersOrder
446+
List.find ((currentPeer ==) . peerInfoPeer) $ map snd candidates
447+
462448
-- If there is a current peer, then that is the one we choose. Otherwise, we
463449
-- can choose any peer, so we choose a “good” one.
464-
case mCurrentPeer of
450+
case peersOrderCurrentInfo of
465451
Just thePeerInfo -> do
466452
case List.break (((==) `on` peerInfoPeer) thePeerInfo . snd) candidates of
467453
(_, []) -> tell (List [(FetchDeclineChainNotPlausible, thePeerInfo)]) >> return Nothing

0 commit comments

Comments
 (0)