@@ -186,12 +186,12 @@ module Ouroboros.Consensus.MiniProtocol.ChainSync.Client.Jumping (
186
186
, TraceCsjReason (.. )
187
187
, TraceEventCsj (.. )
188
188
, TraceEventDbf (.. )
189
+ , engageClient
189
190
, getDynamo
190
191
, makeContext
191
192
, mkJumping
192
193
, noJumping
193
194
, registerClient
194
- , reregisterClient
195
195
, rotateDynamo
196
196
, unregisterClient
197
197
) where
@@ -212,6 +212,8 @@ import Data.Void (absurd)
212
212
import GHC.Generics (Generic )
213
213
import Ouroboros.Consensus.Block (HasHeader (getHeaderFields ), Header ,
214
214
Point (.. ), castPoint , pointSlot , succWithOrigin )
215
+ import Ouroboros.Consensus.Node.GsmState (GsmState )
216
+ import qualified Ouroboros.Consensus.Node.GsmState as GSM
215
217
import Ouroboros.Consensus.Ledger.SupportsProtocol
216
218
(LedgerSupportsProtocol )
217
219
import Ouroboros.Consensus.MiniProtocol.ChainSync.Client.State
@@ -781,48 +783,42 @@ registerClient ::
781
783
( LedgerSupportsProtocol blk ,
782
784
IOLike m
783
785
) =>
786
+ GsmState ->
784
787
Context m peer blk ->
785
788
peer ->
786
789
StrictTVar m (ChainSyncState blk ) ->
787
790
-- | A function to make a client handle from a jumping state.
788
791
(StrictTVar m (ChainSyncJumpingState m blk ) -> ChainSyncClientHandle m blk ) ->
789
792
STM m (PeerContext m peer blk , Maybe (TraceEventCsj peer blk ))
790
- registerClient context peer csState mkHandle = do
791
- (csjState, mbEv) <- getDynamo (handlesCol context) >>= \ case
792
- Nothing -> do
793
- fragment <- csCandidate <$> readTVar csState
794
- pure (Dynamo DynamoStarted $ pointSlot $ AF. anchorPoint fragment, Just InitializedAsDynamo )
795
- Just (_, handle) -> do
796
- mJustInfo <- readTVar (cschJumpInfo handle)
797
- (\ x -> (x, Nothing )) <$> newJumper mJustInfo (Happy FreshJumper Nothing )
793
+ registerClient gsmState context peer csState mkHandle = do
794
+ (csjState, mbEv) <- case gsmState of
795
+ GSM. CaughtUp -> pure (Disengaged DisengagedDone , Nothing )
796
+ GSM. PreSyncing -> engageClient context csState
797
+ GSM. Syncing -> engageClient context csState
798
798
cschJumping <- newTVar csjState
799
799
let handle = mkHandle cschJumping
800
800
cschcAddHandle (handlesCol context) peer handle
801
801
pure (context {peer, handle}, mbEv)
802
802
803
- -- | Same as 'registerClient', but for a peer that had been previously disengaged.
803
+ -- | Adds a client to the overall CSJ state
804
804
--
805
- -- This is specifically used for when the GSM transitions from
806
- -- 'Ouroboros.Consensus.Node.GsmState.CaughtUp' back to
807
- -- 'Ouroboros.Consensus.Node.GsmState.PreSyncing'.
808
- reregisterClient ::
805
+ -- This client can be either a fresh peer or a peer that had previously
806
+ -- disengaged.
807
+ engageClient ::
809
808
( LedgerSupportsProtocol blk ,
810
809
IOLike m
811
810
) =>
812
- PeerContext m peer blk ->
813
- STM m (Maybe ( TraceEventCsj peer blk ))
814
- reregisterClient peerContext = do
815
- let h = handle peerContext
816
- (csjState, mbEv) <- getDynamo (handlesCol peerContext ) >>= \ case
811
+ Context m peer blk ->
812
+ StrictTVar m (ChainSyncState blk ) ->
813
+ STM m ( ChainSyncJumpingState m blk , Maybe ( TraceEventCsj peer blk ))
814
+ engageClient context csState = do
815
+ getDynamo (handlesCol context ) >>= \ case
817
816
Nothing -> do
818
- fragment <- csCandidate <$> readTVar (cschState h)
817
+ fragment <- csCandidate <$> readTVar csState
819
818
pure (Dynamo DynamoStarted $ pointSlot $ AF. anchorPoint fragment, Just InitializedAsDynamo )
820
- Just (_, dynHandle ) -> do
821
- mJustInfo <- readTVar (cschJumpInfo dynHandle )
819
+ Just (_, handle ) -> do
820
+ mJustInfo <- readTVar (cschJumpInfo handle )
822
821
(\ x -> (x, Nothing )) <$> newJumper mJustInfo (Happy FreshJumper Nothing )
823
- writeTVar (cschJumping h) csjState
824
- cschcAddHandle (handlesCol peerContext) (peer peerContext) h
825
- pure mbEv
826
822
827
823
-- | Unregister a client from a 'PeerContext'; this might trigger the election
828
824
-- of a new dynamo or objector if the peer was one of these two.
0 commit comments