Skip to content

Commit d408094

Browse files
committed
TOSQUASH add Jumping123 and Offered
This small alteration accomodate the fact that the ChainSync client cannot necessarily a MsgFindIntersect _immediately_ when the CSJ governor emits it.
1 parent 5a370f6 commit d408094

File tree

1 file changed

+90
-15
lines changed
  • ouroboros-consensus/src/unstable-consensus-testlib/Test

1 file changed

+90
-15
lines changed

ouroboros-consensus/src/unstable-consensus-testlib/Test/CsjModel.hs

+90-15
Original file line numberDiff line numberDiff line change
@@ -355,10 +355,11 @@ bisectionStep y bi found =
355355
rejected = rejected'
356356
}
357357

358-
-- | For 'jumpings' that just processed their latest response
358+
-- | For 'Jumpings' that have processed the latest reply from their
359+
-- peer
359360
--
360-
-- They were otherwise about to either become 'jumpeds' or send another request
361-
-- and stay in 'jumpings'.
361+
-- They were otherwise about to either become 'Jumpeds' or send
362+
-- another request and stay in 'Jumpings'.
362363
newJumpRequest ::
363364
Ord p
364365
=> JumpRequest p
@@ -383,7 +384,7 @@ newJumpRequest req (y, eBi) =
383384
Nothing
384385
)
385386

386-
-- | For possibly restarting 'jumpeds' and for pivoting 'jumpings' that just
387+
-- | For possibly restarting 'Jumpeds' and for pivoting 'Jumpings' that just
387388
-- processed their latest response
388389
--
389390
-- Note that the resulting 'notYetDetermined' has already been constrained by
@@ -548,14 +549,47 @@ data NonDynamo p =
548549
-- intersection with the jump request.
549550
--
550551
-- The 'JumpRequest' is present if a new request arose.
551-
Jumping !(CsjClientState p) !(Bisecting p) !(Maybe (JumpRequest p))
552+
Jumping !(CsjClientState p) !(Bisecting p) !(SentStatus p)
552553
|
553554
-- | Peers that are currently challenging the Dynamo
554555
--
555556
-- The extra @p@ is the same as for 'dynamo'.
556557
Objector !(Class p) !(CsjClientState p) !(Maybe p)
557558
deriving (Read, Show)
558559

560+
data SentStatus p =
561+
-- | The CSJ governor is waiting for the ChainSync client to
562+
-- report the peer's reply to the 'MsgFindIntersect' that was
563+
-- sent
564+
--
565+
-- The CSJ governor will not emit more 'MsgFindIntersect' in this
566+
-- state.
567+
--
568+
-- The argument is 'Just' if a new 'JumpRequest' arose before the
569+
-- CSJ governor was informed of the peer's reply to the latest
570+
-- jump.
571+
--
572+
-- When the reply arrives, the peer either continues bisecting
573+
-- with 'NotYetSet' (pivoting if there's a new jump request) or it
574+
-- finishes bisecting with 'Jumped' (and perhaps is immediately
575+
-- promoted). (Or it might disengage.)
576+
AlreadySent !(Maybe (JumpRequest p))
577+
|
578+
-- | The CSJ governor has emitted at least one 'MsgFindIntersect'
579+
-- to this 'Jumping' peer and is waiting for the ChainSync client
580+
-- to indicate that it has sent the most recently emitted
581+
-- 'MsgFindIntersect' by signaling 'Offered'
582+
--
583+
-- The CSJ governer might emit more 'MsgFindIntersect' until that
584+
-- 'Offered' happens.
585+
--
586+
-- The most interesting motivation for 'NotYetSet' is if the
587+
-- Dynamo was demoted while blocked on the forecast range. It will
588+
-- be stuck until the forecast horizon advances far enough, and
589+
-- during that time the CSJ governor will consider it to be
590+
-- 'NotYetSent', without needing any details beyond that.
591+
NotYetSent
592+
deriving (Read, Show)
559593

560594
objectorClasses :: Ord p => CsjState pid p -> Set (Class p)
561595
objectorClasses x =
@@ -580,6 +614,10 @@ data CsjStimulus p =
580614
|
581615
-- | The peer disconnected, including LoP, GDD, etc
582616
Disconnect
617+
|
618+
-- | The ChainSync client sent the CSJ's latest 'MsgFindIntersect'
619+
-- to the peer
620+
Offered
583621
|
584622
-- | The peer starved ChainSel
585623
Starvation
@@ -663,7 +701,7 @@ csjReactions env x pid = fmap (issueNextJump env . backfill) . \case
663701
rejected = Nothing
664702
}
665703
in
666-
(Jumping y bi Nothing, Just (nextMsgFindIntersect bi))
704+
(Jumping y bi NotYetSent, Just (nextMsgFindIntersect bi))
667705
in (
668706
CsjState {
669707
dynamo = dynamo x
@@ -692,11 +730,11 @@ csjReactions env x pid = fmap (issueNextJump env . backfill) . \case
692730
-- recent headers, and there could be thousands of them.
693731

694732
MsgIntersectionFound p ->
695-
onJumping (intersectionFound p)
733+
onAlreadySent (intersectionFound p)
696734
<|>
697735
onActive (finishPromotion p)
698736
MsgIntersectionNotFound ->
699-
onJumping intersectionNotFound
737+
onAlreadySent intersectionNotFound
700738
<|>
701739
-- The Jumper failed its promotion.
702740
onActive (const L.Nothing)
@@ -709,6 +747,8 @@ csjReactions env x pid = fmap (issueNextJump env . backfill) . \case
709747

710748
Disconnect -> pure disconnect
711749

750+
Offered -> onNotYetSent
751+
712752
Starvation -> do
713753
Dynamo pid' clss y _mbQ <- toLazy $ dynamo x
714754
let shouldNotDemote =
@@ -812,9 +852,35 @@ csjReactions env x pid = fmap (issueNextJump env . backfill) . \case
812852
[(pid, Continue)]
813853
)
814854

815-
onJumping f = do
816-
Jumping y bi mbNext <- Map.lookup pid (nonDynamos x)
817-
pure $ case maybe id newJumpRequest mbNext <$> f y bi of
855+
onNotYetSent = do
856+
Jumping y bi sent <- Map.lookup pid (nonDynamos x)
857+
case sent of
858+
AlreadySent _mbNext -> L.Nothing
859+
NotYetSent -> pure ()
860+
pure (
861+
CsjState {
862+
dynamo = dynamo x
863+
,
864+
latestJump = latestJump x
865+
,
866+
nonDynamos =
867+
Map.insert
868+
pid
869+
(Jumping y bi (AlreadySent Nothing))
870+
(nonDynamos x)
871+
,
872+
queue = queue x
873+
}
874+
,
875+
[]
876+
)
877+
878+
onAlreadySent f = do
879+
Jumping y bi sent <- Map.lookup pid (nonDynamos x)
880+
k <- case sent of
881+
AlreadySent mbNext -> pure $ maybe id newJumpRequest mbNext
882+
NotYetSent -> L.Nothing
883+
pure $ case k <$> f y bi of
818884
L.Nothing -> disengage
819885
L.Just (y', eBi') -> case eBi' of
820886
Left clss -> (
@@ -843,7 +909,7 @@ csjReactions env x pid = fmap (issueNextJump env . backfill) . \case
843909
nonDynamos =
844910
Map.insert
845911
pid
846-
(Jumping y' bi' Nothing)
912+
(Jumping y' bi' NotYetSent)
847913
(nonDynamos x)
848914
,
849915
queue = queue x
@@ -1150,12 +1216,21 @@ issueNextJump env (x, msgs) =
11501216
case newJumpRequest2 req y (Just clss) of
11511217
Left clss' -> (Jumped clss' y, acc)
11521218
Right bi -> (
1153-
Jumping y bi Nothing
1219+
Jumping y bi NotYetSent
11541220
,
11551221
(pid, nextMsgFindIntersect bi) : acc
11561222
)
1157-
Jumping y bi _next ->
1158-
(Jumping y bi (Just req), [])
1223+
Jumping y bi sent -> case sent of
1224+
AlreadySent _mbNext ->
1225+
(Jumping y bi (AlreadySent (Just req)), [])
1226+
NotYetSent ->
1227+
case newJumpRequest req (y, Right bi) of
1228+
(y', Left clss') -> (Jumped clss' y', acc)
1229+
(y', Right bi') -> (
1230+
Jumping y' bi' NotYetSent
1231+
,
1232+
(pid, nextMsgFindIntersect bi') : acc
1233+
)
11591234
Objector clss y mbQ ->
11601235
-- This 'min' ensures the Objector's class is a point
11611236
-- in the new jump.

0 commit comments

Comments
 (0)