Skip to content

Commit

Permalink
filterNot -> drop
Browse files Browse the repository at this point in the history
  • Loading branch information
Niols committed Jul 15, 2024
1 parent 8db3f2d commit 270c02e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ module Ouroboros.Network.BlockFetch.Decision
-- ** Components of the decision-making process
, filterPlausibleCandidates
, selectForkSuffixes
, filterNotAlreadyFetched
, filterNotAlreadyInFlightWithPeer
, dropAlreadyFetched
, dropAlreadyInFlightWithPeer
, prioritisePeerChains
, fetchRequestDecisions
) where
Expand All @@ -31,7 +31,7 @@ import Ouroboros.Network.BlockFetch.ClientState (FetchRequest (..), PeersOrder (
import Ouroboros.Network.BlockFetch.ConsensusInterface (FetchMode (..), ChainSelStarvation)

import Ouroboros.Network.BlockFetch.Decision.Deadline (FetchDecisionPolicy (..), PeerInfo, FetchDecision, FetchDecline (..),
filterPlausibleCandidates, filterNotAlreadyFetched, filterNotAlreadyInFlightWithPeer,
filterPlausibleCandidates, dropAlreadyFetched, dropAlreadyInFlightWithPeer,
selectForkSuffixes, fetchDecisionsDeadline, prioritisePeerChains, fetchRequestDecisions)
import Ouroboros.Network.BlockFetch.Decision.BulkSync (fetchDecisionsBulkSyncM)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ fetchDecisionsBulkSync
-- guaranteed to be non-empty.
let (theFragments :: FetchDecision (CandidateFragments header)) =
pure theCandidate
>>= filterNotAlreadyFetched fetchedBlocks fetchedMaxSlotNo
>>= dropAlreadyFetched fetchedBlocks fetchedMaxSlotNo

-- Step 3: Select the peer to sync from. This eliminates peers that cannot
-- serve a reasonable batch of the candidate, then chooses the peer to sync
Expand Down Expand Up @@ -543,7 +543,7 @@ fetchTheCandidate
-- Keep blocks that are not already in-flight with this peer. NOTE: We
-- already filtered most of them (and more), but now we also filter
-- out then ones that are in-flight AND ignored.
fragments <- filterNotAlreadyInFlightWithPeer inflight =<< theFragments
fragments <- dropAlreadyInFlightWithPeer inflight =<< theFragments

-- Trim the fragments to the peer's candidate, keeping only blocks that
-- they may actually serve.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,11 @@ fetchDecisionsDeadline fetchDecisionPolicy@FetchDecisionPolicy {
. map swizzleIG

-- Filter to keep blocks that are not already in-flight for this peer.
. filterNotAlreadyInFlightWithPeer'
. dropAlreadyInFlightWithPeer'
. map swizzleI

-- Filter to keep blocks that have not already been downloaded.
. filterNotAlreadyFetched'
. dropAlreadyFetched'
fetchedBlocks
fetchedMaxSlotNo

Expand Down Expand Up @@ -541,31 +541,31 @@ of individual blocks without their relationship to each other.
-- Typically this is a single fragment forming a suffix of the chain, but in
-- the general case we can get a bunch of discontiguous chain fragments.
--
-- See also 'filterNotAlreadyInFlightWithPeer'.
filterNotAlreadyFetched ::
-- See also 'dropAlreadyInFlightWithPeer'.
dropAlreadyFetched ::
(HasHeader header, HeaderHash header ~ HeaderHash block) =>
(Point block -> Bool) ->
MaxSlotNo ->
ChainSuffix header ->
FetchDecision (CandidateFragments header)
filterNotAlreadyFetched alreadyDownloaded fetchedMaxSlotNo candidate =
dropAlreadyFetched alreadyDownloaded fetchedMaxSlotNo candidate =
if null fragments
then Left FetchDeclineAlreadyFetched
else Right (candidate, fragments)
where
fragments = filterWithMaxSlotNo notAlreadyFetched fetchedMaxSlotNo (getChainSuffix candidate)
notAlreadyFetched = not . alreadyDownloaded . castPoint . blockPoint

filterNotAlreadyFetched' ::
dropAlreadyFetched' ::
(HasHeader header, HeaderHash header ~ HeaderHash block) =>
(Point block -> Bool) ->
MaxSlotNo ->
[(FetchDecision (ChainSuffix header), peerinfo)] ->
[(FetchDecision (CandidateFragments header), peerinfo)]
filterNotAlreadyFetched' alreadyDownloaded fetchedMaxSlotNo =
dropAlreadyFetched' alreadyDownloaded fetchedMaxSlotNo =
map
( \(mcandidate, peer) ->
((filterNotAlreadyFetched alreadyDownloaded fetchedMaxSlotNo =<< mcandidate), peer)
((dropAlreadyFetched alreadyDownloaded fetchedMaxSlotNo =<< mcandidate), peer)
)

-- | Find the fragments of the chain suffix that we still need to fetch because
Expand All @@ -575,28 +575,28 @@ filterNotAlreadyFetched' alreadyDownloaded fetchedMaxSlotNo =
-- Typically this is a single fragment forming a suffix of the chain, but in
-- the general case we can get a bunch of discontiguous chain fragments.
--
-- See also 'filterNotAlreadyFetched'
filterNotAlreadyInFlightWithPeer ::
-- See also 'dropAlreadyFetched'
dropAlreadyInFlightWithPeer ::
(HasHeader header) =>
PeerFetchInFlight header ->
CandidateFragments header ->
FetchDecision (CandidateFragments header)
filterNotAlreadyInFlightWithPeer inflight (candidate, chainfragments) =
dropAlreadyInFlightWithPeer inflight (candidate, chainfragments) =
if null fragments
then Left FetchDeclineInFlightThisPeer
else Right (candidate, fragments)
where
fragments = concatMap (filterWithMaxSlotNo notAlreadyInFlight (peerFetchMaxSlotNo inflight)) chainfragments
notAlreadyInFlight b = blockPoint b `Map.notMember` peerFetchBlocksInFlight inflight

filterNotAlreadyInFlightWithPeer' ::
dropAlreadyInFlightWithPeer' ::
(HasHeader header) =>
[(FetchDecision (CandidateFragments header), PeerFetchInFlight header, peerinfo)] ->
[(FetchDecision (CandidateFragments header), peerinfo)]
filterNotAlreadyInFlightWithPeer' =
dropAlreadyInFlightWithPeer' =
map
( \(mcandidatefragments, inflight, peer) ->
((filterNotAlreadyInFlightWithPeer inflight =<< mcandidatefragments), peer)
((dropAlreadyInFlightWithPeer inflight =<< mcandidatefragments), peer)
)

-- | Filter a fragment. This is an optimised variant that will behave the same
Expand Down Expand Up @@ -840,7 +840,7 @@ fetchRequestDecisions fetchDecisionPolicy chains =

-- This is only for avoiding duplication between fetch requests in this
-- round of decisions. Avoiding duplication with blocks that are already
-- in flight is handled by filterNotAlreadyInFlightWithOtherPeers
-- in flight is handled by dropAlreadyInFlightWithOtherPeers
(blocksFetchedThisRound', maxSlotNoFetchedThisRound') =
case decision of
Left _ ->
Expand Down

0 comments on commit 270c02e

Please sign in to comment.