@@ -54,10 +54,19 @@ import Ouroboros.Consensus.MiniProtocol.ChainSync.Client.State
5454  ( ChainSyncJumpingState  (.. )
5555  , DisengagedInitState  (.. )
5656  )
57+ import  Ouroboros.Consensus.MiniProtocol.ObjectDiffusion.Inbound.State 
58+   ( ObjectDiffusionInboundHandle  (.. )
59+   , ObjectDiffusionInboundHandleCollection 
60+   , initObjectDiffusionInboundState 
61+   , newObjectDiffusionInboundHandleCollection 
62+   , odihcAddHandle 
63+   )
64+ import  Ouroboros.Consensus.MiniProtocol.ObjectDiffusion.PerasCert  (PerasCertDiffusionInboundHandle )
5765import  qualified  Ouroboros.Consensus.Node.GSM  as  GSM 
5866import  Ouroboros.Consensus.Node.Genesis  (setGetLoEFragment )
5967import  Ouroboros.Consensus.Node.GsmState 
6068import  Ouroboros.Consensus.NodeId 
69+ import  Ouroboros.Consensus.NodeKernel  (chainSyncState , mkNodeKernelPeerStates , nodeKernelPeerIsIdle )
6170import  Ouroboros.Consensus.Peras.Weight  (emptyPerasWeightSnapshot )
6271import  qualified  Ouroboros.Consensus.Storage.ChainDB  as  ChainDB 
6372import  Ouroboros.Consensus.Storage.ChainDB.API  (ChainDB )
@@ -108,12 +117,14 @@ run = withRegistry \registry -> do
108117  let  addBlk =  ChainDB. addBlock_ chainDB Punishment. noPunishment
109118
110119  chainSyncHandles <-  atomically newChainSyncClientHandleCollection
120+   perasCertDiffusionHandles <-  atomically newObjectDiffusionInboundHandleCollection
111121
112122  _ <- 
113123    forkLinkedThread registry " GSM" $ 
114124      GSM. enterPreSyncing $ 
115125        mkGsmEntryPoints
116126          chainSyncHandles
127+           perasCertDiffusionHandles
117128          chainDB
118129          (atomically .  writeTVar varGsmState)
119130
@@ -132,6 +143,11 @@ run = withRegistry \registry -> do
132143  --  this would happen via ChainSync and BlockFetch.
133144
134145  _ <-  forkLinkedThread registry " Peer1" $  do 
146+     --  Initialize a PerasCertDiffusion client handle for Peer1 so that the GSM knows it's idling
147+     atomically $ 
148+       mkTestPerasCertDiffusionInboundHandle
149+         >>=  odihcAddHandle perasCertDiffusionHandles peer1
150+ 
135151    --  First, let Peer1 connect, serving block A (without idling).
136152    let  initialFrag = 
137153          attachSlotTimeToFragment cfg $ 
@@ -158,6 +174,11 @@ run = withRegistry \registry -> do
158174        }
159175
160176  _ <-  forkLinkedThread registry " Peer2" $  do 
177+     --  Initialize a PerasCertDiffusion client handle for Peer2 so that the GSM knows it's idling
178+     atomically $ 
179+       mkTestPerasCertDiffusionInboundHandle
180+         >>=  odihcAddHandle perasCertDiffusionHandles peer2
181+ 
161182    --  Let Peer2 connect and send B.
162183    hdl <- 
163184      atomically $ 
@@ -236,6 +257,17 @@ mkTestChainSyncClientHandle frag = do
236257      , cschJumpInfo =  varJumpInfo
237258      }
238259
260+ mkTestPerasCertDiffusionInboundHandle  :: 
261+   forall  m . 
262+   IOLike  m  => 
263+   STM  m  (PerasCertDiffusionInboundHandle  m  TestBlock )
264+ mkTestPerasCertDiffusionInboundHandle =  do 
265+   varState <-  newTVar initObjectDiffusionInboundState
266+   pure 
267+     ObjectDiffusionInboundHandle 
268+       { odihState =  varState
269+       }
270+ 
239271openChainDB  :: 
240272  forall  m . 
241273  IOLike  m  => 
@@ -273,17 +305,18 @@ mkGsmEntryPoints ::
273305  forall  m . 
274306  (IOLike  m , SI. MonadTimerm ) => 
275307  ChainSyncClientHandleCollection  CoreNodeId  m  TestBlock  -> 
308+   ObjectDiffusionInboundHandleCollection  CoreNodeId  m  TestBlock  -> 
276309  ChainDB  m  TestBlock  -> 
277310  (GsmState  ->  m  () ) -> 
278311  GSM. GsmEntryPointsm 
279- mkGsmEntryPoints varChainSyncHandles  chainDB writeGsmState = 
312+ mkGsmEntryPoints chainSyncHandles perasCertDiffusionHandles  chainDB writeGsmState = 
280313  GSM. realGsmEntryPoints
281314    (id , nullTracer)
282315    GSM. GsmView
283316      { GSM. getCandidateOverSelection =  pure  candidateOverSelection
284-       , GSM. peerIsIdle =  csIdling 
317+       , GSM. peerIsIdle =  nodeKernelPeerIsIdle 
285318      , GSM. equivalent =  (==)  `on`  AF. headPoint
286-       , GSM. getPeerStates =  traverse  readTVar  =<<   fmap  cschState  <$>  cschcMap varChainSyncHandles 
319+       , GSM. getPeerStates =  mkNodeKernelPeerStates chainSyncHandles perasCertDiffusionHandles 
287320      , GSM. getCurrentSelection =  ChainDB. getCurrentChain chainDB
288321      , --  Make sure that we stay in CaughtUp for the duration of the test once we
289322        --  have entered it.
@@ -304,7 +337,7 @@ mkGsmEntryPoints varChainSyncHandles chainDB writeGsmState =
304337        GSM. WhetherCandidateIsBetter$ 
305338          preferAnchoredCandidate (configBlock cfg) weights selection candFrag
306339   where 
307-     candFrag =  csCandidate candidateState
340+     candFrag =  csCandidate (chainSyncState  candidateState) 
308341
309342    --  TODO https://github.com/tweag/cardano-peras/issues/67
310343    weights =  emptyPerasWeightSnapshot
0 commit comments