Skip to content

Commit b24e05c

Browse files
Groom comments
1 parent d7c1196 commit b24e05c

File tree

1 file changed

+29
-44
lines changed
  • ouroboros-network/src/Ouroboros/Network/BlockFetch/Decision

1 file changed

+29
-44
lines changed

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

Lines changed: 29 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
-- specific to the bulk sync mode. This logic reuses parts of the logic for the
1212
-- deadline mode, but it is inherently different.
1313
--
14-
-- Natural language specification
15-
-- ------------------------------
16-
--
1714
-- Definitions:
1815
--
1916
-- - Let @inflight :: peer -> Set blk@ be the outstanding blocks, those that
@@ -53,14 +50,14 @@
5350
-- 2. Select @thePeer :: peer@. If @inflight(currentPeer)@ is not empty, then
5451
-- this is @currentPeer@. Otherwise:
5552
--
56-
-- - Let @grossRequest@ be the oldest blocks on @theCandidate@ that have not
57-
-- already been downloaded and total less than 20 mebibytes.
53+
-- - Let @grossRequest@ be the oldest block on @theCandidate@ that has not
54+
-- already been downloaded.
5855
--
5956
-- - If @grossRequest@ is empty, then terminate this iteration. Otherwise,
60-
-- pick the best peer (according to @peersOrder@) offering all of the
61-
-- blocks in @grossRequest@.
57+
-- pick the best peer (according to @peersOrder@) offering the
58+
-- block in @grossRequest@.
6259
--
63-
-- 3. Craft that actual request to @thePeer@ asking blocks of @theCandidate@:
60+
-- 3. Craft the actual request to @thePeer@ asking blocks of @theCandidate@:
6461
--
6562
-- - If the byte size of @inflight(thePeer)@ is below the low-water mark,
6663
-- then terminate this iteration.
@@ -69,19 +66,16 @@
6966
-- which blocks are actually already currently in-flight with @thePeer@.
7067
--
7168
-- 4. If we went through the election of a new peer, replace @currentPeer@ and
72-
-- reset @currentStart@. REVIEW: Maybe this should just be done directly in
73-
-- step 2.
69+
-- reset @currentStart@.
7470
--
7571
-- Terminate this iteration.
7672
--
77-
-- About ignored in-flight requests
78-
-- --------------------------------
73+
-- About the influence of in-flight requests
74+
-- -----------------------------------------
7975
--
8076
-- One can note that in-flight requests are ignored when finding a new peer, but
8177
-- considered when crafting the actual request to a chosen peer. This is by
82-
-- design. The goal of this algorithm is to keep talking to the same peer unless
83-
-- it proves to be too weak; in that case, @inflight(p)@ will be empty for all
84-
-- @p /= currentPeer@.
78+
-- design. We explain the rationale here.
8579
--
8680
-- If a peer proves too slow, then we give up on it (see point 0. above), even
8781
-- if it has requests in-flight. In subsequent selections of peers (point 2.),
@@ -102,38 +96,30 @@
10296
-- Interactions with ChainSync Jumping (CSJ)
10397
-- -----------------------------------------
10498
--
105-
-- This decision logic is not so obviously coupled with CSJ, but it is in some
106-
-- subtle ways:
107-
--
108-
-- - Because we always require our peers to be able to serve a gross request of
109-
-- oldest blocks, peers with longer chains have a better chance to pass this
110-
-- criteria and to be selected as current peer. The CSJ dynamo, being always
111-
-- ahead of jumpers, has therefore more chances to be selected as the current
112-
-- peer. It is still possible for a jumper or a disengaged peer to be
113-
-- selected.
99+
-- Because we always require our peers to be able to serve a gross request
100+
-- with an old block, peers with longer chains have a better chance to pass
101+
-- this criteria and to be selected as current peer. The CSJ dynamo, being
102+
-- always ahead of jumpers, has therefore more chances to be selected as the
103+
-- current peer. It is still possible for a jumper or a disengaged peer to be
104+
-- selected.
114105
--
115-
-- - If the current peer is the CSJ dynamo, but it is a dishonest peer serving
116-
-- headers fast but retaining blocks, it might be able to drastically leash
117-
-- us, because its ChainSync client will be stuck behind the forecast horizon
118-
-- (and therefore not subject to ChainSync punishments such as the Limit on
119-
-- Patience). This is why we need to consider starvation of ChainSel and
120-
-- demote peers that let us starve.
106+
-- If the current peer is the CSJ dynamo and it is a dishonest peer that retains
107+
-- blocks, it will get multiple opportunities to do so since it will be selected
108+
-- as the current peer more often. We therefore rotate the dynamo every time it
109+
-- is the current peer and it fails to serve blocks promptly.
121110
--
122111
-- About the gross request
123112
-- -----------------------
124113
--
125-
-- Morally, we want to select a peer that is able to serve us a batch of oldest
126-
-- blocks of @theCandidate@. However, the actual requests depend not only on the
127-
-- size of the blocks to fetch, but also on the network performances of the peer
128-
-- and what requests it already has in-flight. Looking at what peer can create
129-
-- an actual request for @theCandidate@ can be misleading: indeed, our
130-
-- @currentPeer@ might not be able to create a request simply because it is
131-
-- already busy answering other requests from us. This calls for the
132-
-- introduction of an objective criterium, which the gross request provides.
114+
-- We want to select a peer that is able to serve us a batch of oldest blocks
115+
-- of @theCandidate@. However, not every peer will be able to deliver these
116+
-- batches as they might be on different chains. We therefore select a peer only
117+
-- if its candidate fragment contains the block in the gross request. In this
118+
-- way, we ensure that the peer can serve at least one block that we wish to
119+
-- fetch.
133120
--
134-
-- If the gross request is included in a peer's candidate, it means that this
135-
-- peer can serve at least 1 block that we wish to fetch. The actual request might
136-
-- be bigger than that because the peer can have more blocks.
121+
-- If the peer cannot offer any more blocks after that, it will be rotated out
122+
-- soon.
137123
--
138124
module Ouroboros.Network.BlockFetch.Decision.BulkSync (
139125
fetchDecisionsBulkSyncM
@@ -419,7 +405,6 @@ selectTheCandidate
419405
-- consider longest fragments first.
420406
. List.sortOn (Down . headBlockNo . fst)
421407
where
422-
-- Very ad-hoc helper.
423408
-- Write all of the declined peers, and find the candidate fragment
424409
-- if there is any.
425410
separateDeclinedAndStillInRace ::
@@ -485,8 +470,8 @@ selectThePeer
485470
Right () -> return $ Just (thePeerCandidate, thePeerInfo)
486471

487472
Nothing -> do
488-
-- For each peer, check whether its candidate contains the gross request in
489-
-- its entirety, otherwise decline it. This will guarantee that the
473+
-- For each peer, check whether its candidate contains the head of the
474+
-- gross request, otherwise decline it. This will guarantee that the
490475
-- remaining peers can serve the refined request that we will craft later.
491476
peers <-
492477
filterM

0 commit comments

Comments
 (0)