@@ -355,10 +355,11 @@ bisectionStep y bi found =
355
355
rejected = rejected'
356
356
}
357
357
358
- -- | For 'jumpings' that just processed their latest response
358
+ -- | For 'Jumpings' that have processed the latest reply from their
359
+ -- peer
359
360
--
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 '.
362
363
newJumpRequest ::
363
364
Ord p
364
365
=> JumpRequest p
@@ -383,7 +384,7 @@ newJumpRequest req (y, eBi) =
383
384
Nothing
384
385
)
385
386
386
- -- | For possibly restarting 'jumpeds ' and for pivoting 'jumpings ' that just
387
+ -- | For possibly restarting 'Jumpeds ' and for pivoting 'Jumpings ' that just
387
388
-- processed their latest response
388
389
--
389
390
-- Note that the resulting 'notYetDetermined' has already been constrained by
@@ -548,14 +549,47 @@ data NonDynamo p =
548
549
-- intersection with the jump request.
549
550
--
550
551
-- 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 )
552
553
|
553
554
-- | Peers that are currently challenging the Dynamo
554
555
--
555
556
-- The extra @p@ is the same as for 'dynamo'.
556
557
Objector ! (Class p ) ! (CsjClientState p ) ! (Maybe p )
557
558
deriving (Read , Show )
558
559
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 )
559
593
560
594
objectorClasses :: Ord p => CsjState pid p -> Set (Class p )
561
595
objectorClasses x =
@@ -580,6 +614,10 @@ data CsjStimulus p =
580
614
|
581
615
-- | The peer disconnected, including LoP, GDD, etc
582
616
Disconnect
617
+ |
618
+ -- | The ChainSync client sent the CSJ's latest 'MsgFindIntersect'
619
+ -- to the peer
620
+ Offered
583
621
|
584
622
-- | The peer starved ChainSel
585
623
Starvation
@@ -663,7 +701,7 @@ csjReactions env x pid = fmap (issueNextJump env . backfill) . \case
663
701
rejected = Nothing
664
702
}
665
703
in
666
- (Jumping y bi Nothing , Just (nextMsgFindIntersect bi))
704
+ (Jumping y bi NotYetSent , Just (nextMsgFindIntersect bi))
667
705
in (
668
706
CsjState {
669
707
dynamo = dynamo x
@@ -692,11 +730,11 @@ csjReactions env x pid = fmap (issueNextJump env . backfill) . \case
692
730
-- recent headers, and there could be thousands of them.
693
731
694
732
MsgIntersectionFound p ->
695
- onJumping (intersectionFound p)
733
+ onAlreadySent (intersectionFound p)
696
734
<|>
697
735
onActive (finishPromotion p)
698
736
MsgIntersectionNotFound ->
699
- onJumping intersectionNotFound
737
+ onAlreadySent intersectionNotFound
700
738
<|>
701
739
-- The Jumper failed its promotion.
702
740
onActive (const L. Nothing )
@@ -709,6 +747,8 @@ csjReactions env x pid = fmap (issueNextJump env . backfill) . \case
709
747
710
748
Disconnect -> pure disconnect
711
749
750
+ Offered -> onNotYetSent
751
+
712
752
Starvation -> do
713
753
Dynamo pid' clss y _mbQ <- toLazy $ dynamo x
714
754
let shouldNotDemote =
@@ -812,9 +852,35 @@ csjReactions env x pid = fmap (issueNextJump env . backfill) . \case
812
852
[(pid, Continue )]
813
853
)
814
854
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
818
884
L. Nothing -> disengage
819
885
L. Just (y', eBi') -> case eBi' of
820
886
Left clss -> (
@@ -843,7 +909,7 @@ csjReactions env x pid = fmap (issueNextJump env . backfill) . \case
843
909
nonDynamos =
844
910
Map. insert
845
911
pid
846
- (Jumping y' bi' Nothing )
912
+ (Jumping y' bi' NotYetSent )
847
913
(nonDynamos x)
848
914
,
849
915
queue = queue x
@@ -1150,12 +1216,21 @@ issueNextJump env (x, msgs) =
1150
1216
case newJumpRequest2 req y (Just clss) of
1151
1217
Left clss' -> (Jumped clss' y, acc)
1152
1218
Right bi -> (
1153
- Jumping y bi Nothing
1219
+ Jumping y bi NotYetSent
1154
1220
,
1155
1221
(pid, nextMsgFindIntersect bi) : acc
1156
1222
)
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
+ )
1159
1234
Objector clss y mbQ ->
1160
1235
-- This 'min' ensures the Objector's class is a point
1161
1236
-- in the new jump.
0 commit comments