Skip to content

Commit b8b7323

Browse files
committed
Compute idling based on feature flag and node node version
1 parent 4238d4e commit b8b7323

File tree

1 file changed

+12
-6
lines changed
  • ouroboros-consensus-diffusion/src/ouroboros-consensus-diffusion/Ouroboros/Consensus

1 file changed

+12
-6
lines changed

ouroboros-consensus-diffusion/src/ouroboros-consensus-diffusion/Ouroboros/Consensus/NodeKernel.hs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ import Ouroboros.Network.BlockFetch.Decision.Trace
148148
import Ouroboros.Network.NodeToNode
149149
( ConnectionId
150150
, MiniProtocolParameters (..)
151+
, NodeToNodeVersion (..)
151152
)
152153
import Ouroboros.Network.PeerSelection.Governor.Types
153154
( PublicPeerSelectionState
@@ -274,20 +275,24 @@ mkNodeKernelPeerStates csHandles pcdHandles = do
274275
pcdPeerStates <- traverse (readTVar . odihState) =<< odihcMap pcdHandles
275276
pure (NodeKernelPeerState <$> align csPeerStates pcdPeerStates)
276277

277-
nodeKernelPeerIsIdle :: NodeKernelPeerState blk -> Bool
278-
nodeKernelPeerIsIdle (NodeKernelPeerState these) =
278+
nodeKernelPeerIsIdle :: Set CardanoFeatureFlag -> NodeKernelPeerState blk -> Bool
279+
nodeKernelPeerIsIdle featureFlags (NodeKernelPeerState these) =
279280
case these of
280281
-- We have both ChainSync and PerasCertDiffusion connections => idle if both are idling
281282
These csState pcdState -> csIdling csState && odisIdling pcdState
282283
-- Only a ChainSync connection is available => idle if the ChainSync connection is idling
283-
This csState | not peerUsesPeras -> csIdling csState
284+
This csState | not perasIsEnabled -> csIdling csState
285+
This csState | not (peerUsesPeras csState) -> csIdling csState
284286
-- We will soon establish a PerasCertDiffusion connection => not idling
285287
This _ -> False
286288
-- We will soon establish a ChainSync connection => not idling
287289
That _ -> False
288290
where
289-
-- TODO: use the Peras feature flag or check negotiated NodeToNode version for the peer
290-
peerUsesPeras = False
291+
-- Is the Peras feature flag enabled?
292+
perasIsEnabled = PerasFlag `elem` featureFlags
293+
294+
-- Does the peer support the Peras mini-protocol?
295+
peerUsesPeras csState = csNodeToNodeVersion csState >= NodeToNodeV_16
291296

292297
initNodeKernel ::
293298
forall m addrNTN addrNTC blk.
@@ -304,6 +309,7 @@ initNodeKernel
304309
args@NodeKernelArgs
305310
{ registry
306311
, cfg
312+
, featureFlags
307313
, tracers
308314
, chainDB
309315
, initChainDB
@@ -363,7 +369,7 @@ initNodeKernel
363369
-- We don't have an established ChainSync connection with this peer.
364370
-- We conservatively assume that its candidate is not better than ours.
365371
GSM.WhetherCandidateIsBetter False
366-
, GSM.peerIsIdle = nodeKernelPeerIsIdle
372+
, GSM.peerIsIdle = nodeKernelPeerIsIdle featureFlags
367373
, GSM.durationUntilTooOld =
368374
gsmDurationUntilTooOld
369375
<&> \wd (_headers, lst) ->

0 commit comments

Comments
 (0)