Skip to content

Commit c6c2e18

Browse files
Niolsneilmayhew
authored andcommitted
Improve and clarify CSJ documentation
1 parent fac6489 commit c6c2e18

File tree

1 file changed

+24
-14
lines changed
  • ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/MiniProtocol/ChainSync/Client

1 file changed

+24
-14
lines changed

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/MiniProtocol/ChainSync/Client/Jumping.hs

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
--
116116
-- > j ╔════════╗
117117
-- > ╭────────── ║ Dynamo ║ ◀─────────╮
118-
-- > │ ╭─╚════════╝ │f
118+
-- > │ ╭─ ╚════════╝ │f
119119
-- > ▼ │ ▲ │
120120
-- > ┌────────────┐ │ │ k ┌──────────┐
121121
-- > │ Disengaged │ ◀─│─────────│────────── │ Objector │
@@ -124,48 +124,58 @@
124124
-- > l│ g│ │e b │ │ │
125125
-- > │ │ │ ╭─────╯ i│ │c
126126
-- > ╭╌╌╌▼╌╌╌▼╌╌╌╌╌╌╌╌╌╌╌╌╌│╌╌╌╌╌╌╌╌╌╌│╌▼╌╌╌╮
127-
-- > ┆ ╔═══════╗ a ┌──────┐ d ┌─────┐ |
128-
-- > ┆ ║ Happy ║ ───▶ │ LFI* │ ───▶ │ FI* │ |
129-
-- > ┆ ╚═══════╝ ◀─╮ └──────┘ └─────┘ |
130-
-- > ┆ Jumper ╰─────┴────────────╯h |
127+
-- > ┆ ╔═══════╗ a ┌──────┐ d ┌─────┐
128+
-- > ┆ ║ Happy ║ ───▶ │ LFI* │ ───▶ │ FI* │
129+
-- > ┆ ╚═══════╝ ◀─╮ └──────┘ └─────┘
130+
-- > ┆ Jumper ╰─────┴────────────╯h
131131
-- > ╰╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╯
132132
--
133133
-- *: LookingForIntersection and FoundIntersection, abbreviated for this
134134
-- drawing only; this abbreviation will not be used elsewhere.
135135
--
136+
-- In the following walk-through, we will point to transitions in the drawing
137+
-- between parentheses, like so: (a) (b+c) (e|f). We will use `+` to express
138+
-- that both transitions happen simultaneously (for different peers) and `|` to
139+
-- express a choice.
140+
--
136141
-- A new peer starts as the dynamo if there is no other peer or as a Happy
137142
-- jumper otherwise. The dynamo periodically requests jumps from happy
138-
-- jumpers who, in the ideal case, accept them.
143+
-- jumpers who, in the ideal case, accept them and remain happy jumpers.
139144
--
140145
-- In the event that a jumper rejects a jump, it goes from Happy to LFI* (a).
141146
-- From there starts a back-and-forth of intersection search messages until
142147
-- the exact point of disagreement with the dynamo is found.
143148
--
144149
-- Once the exact point of disagreement is found, and if there is no objector
145150
-- yet, the jumper becomes the objector (b). If there is an objector, then we
146-
-- compare the intersections of the objector and the jumper. If the jumper's
147-
-- intersection is strictly older, then the jumper replaces the objector (b+c).
151+
-- compare the intersection of the objector with the dynamo and the intersection
152+
-- of the jumper with the dynamo. If the jumper's intersection is strictly
153+
-- older, then the jumper replaces the objector, who is marked as FI* (b+c).
148154
-- Otherwise, the jumper is marked as FI* (d).
149155
--
150156
-- If the dynamo disconnects or is disengaged, one peer is elected as the new
151-
-- dynamo (e|f) and all other peers revert to being happy jumpers (g+h).
157+
-- dynamo (e|f) and all the other peers revert to being happy jumpers (g+h).
152158
--
153159
-- If the objector disconnects or is disengaged, and there are FI* jumpers, then
154160
-- the one with the oldest intersection with the dynamo gets elected (i).
161+
-- Otherwise, we are left with no dynamo.
155162
--
156163
-- If the dynamo rolls back to a point older than the last jump it requested, it
157-
-- is disengaged (j) and a new dynamo is elected (e|f).
164+
-- is disengaged (j), a new dynamo is elected (e|f), and all the other peers
165+
-- revert to being happy jumpers (g+h).
158166
--
159167
-- If the objector agrees with the dynamo, it is disengaged (k). If there are
160168
-- FI* jumpers, then one of them gets elected as the new objector (i).
169+
-- Otherwise, we are left with no dynamo.
161170
--
162-
-- If dynamo or objector claim to have no more headers, they are disengaged
163-
-- (j|k).
171+
-- If the dynamo or the objector claim to have no more headers, they are
172+
-- disengaged (j|k), triggering the same chain of effect as described in the two
173+
-- previous points.
164174
--
165175
-- The BlockFetch logic can ask to change the dynamo if it is not serving blocks
166176
-- fast enough. If there are other non-disengaged peers, the dynamo (and the
167-
-- objector if there is one) is demoted to a jumper (l+g) and a new dynamo is
168-
-- elected.
177+
-- objector if there is one, and all the other peers) is demoted to a happy
178+
-- jumper (l+g+h) and a new dynamo is elected (e).
169179
--
170180
module Ouroboros.Consensus.MiniProtocol.ChainSync.Client.Jumping (
171181
Context

0 commit comments

Comments
 (0)