Skip to content

Commit a770aeb

Browse files
committed
Store NodeToNodeVersion in NodeKernelPeerState components
1 parent 22dabda commit a770aeb

File tree

8 files changed

+35
-11
lines changed

8 files changed

+35
-11
lines changed

ouroboros-consensus-diffusion/src/ouroboros-consensus-diffusion/Ouroboros/Consensus/Network/NodeToNode.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,7 @@ mkApps kernel rng Tracers{..} mkCodecs ByteLimits{..} chainSyncTimeouts lopBucke
869869
channel = do
870870
labelThisThread "PerasCertDiffusionClient"
871871
bracketObjectDiffusionInbound
872+
version
872873
(getPerasCertDiffusionHandles kernel)
873874
them
874875
$ \state -> do

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ module Ouroboros.Consensus.NodeKernel
3232
, toConsensusMode
3333
) where
3434

35-
import Cardano.Base.FeatureFlags (CardanoFeatureFlag)
35+
import Cardano.Base.FeatureFlags (CardanoFeatureFlag (..))
3636
import Cardano.Network.ConsensusMode (ConsensusMode (..))
3737
import Cardano.Network.PeerSelection.Bootstrap (UseBootstrapPeers)
3838
import Cardano.Network.PeerSelection.LocalRootPeers

ouroboros-consensus-diffusion/test/consensus-test/Test/Consensus/Genesis/Tests/DensityDisconnect.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ prop_densityDisconnectStatic =
192192
{ csCandidate = frag
193193
, csLatestSlot = SJust (AF.headSlot frag)
194194
, csIdling = False
195+
, csNodeToNodeVersion = maxBound
195196
}
196197
gen = do
197198
gt <- genChains (QC.choose (1, 4))
@@ -431,6 +432,7 @@ evolveBranches EvolvingPeers{k, sgen, peers = initialPeers, fullTree} =
431432
{ csCandidate = attachTimeUsingTestConfig csCandidate
432433
, csIdling = False
433434
, csLatestSlot = SJust (AF.headSlot csCandidate)
435+
, csNodeToNodeVersion = maxBound
434436
}
435437
-- Run GDD.
436438
(loeFrag, suffixes) =

ouroboros-consensus-diffusion/test/consensus-test/Test/Consensus/Genesis/Tests/LoE/CaughtUp.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,16 +142,15 @@ run = withRegistry \registry -> do
142142

143143
-- Then, send C.
144144
atomically $ modifyTVar (cschState hdl) $ \s ->
145-
ChainSyncState
145+
s
146146
{ csCandidate = csCandidate s AF.:> attachSlotTime cfg (getHeader blkC)
147147
, csLatestSlot = pure $ NotOrigin $ blockSlot blkC
148-
, csIdling = csIdling s
149148
}
150149
addBlk blkC
151150

152151
-- Finally, roll back to the initial fragment and idle.
153-
atomically $ modifyTVar (cschState hdl) $ \_s ->
154-
ChainSyncState
152+
atomically $ modifyTVar (cschState hdl) $ \s ->
153+
s
155154
{ csCandidate = initialFrag
156155
, csLatestSlot = pure $ AF.headSlot initialFrag
157156
, csIdling = True
@@ -169,7 +168,7 @@ run = withRegistry \registry -> do
169168

170169
-- Finally, idle.
171170
atomically $ modifyTVar (cschState hdl) $ \s ->
172-
ChainSyncState
171+
s
173172
{ csCandidate = csCandidate s
174173
, csLatestSlot = csLatestSlot s
175174
, csIdling = True
@@ -223,6 +222,7 @@ mkTestChainSyncClientHandle frag = do
223222
{ csCandidate = frag
224223
, csIdling = False
225224
, csLatestSlot = pure $ AF.headSlot frag
225+
, csNodeToNodeVersion = maxBound
226226
}
227227
varJumping <- newTVar $ Disengaged DisengagedDone
228228
varJumpInfo <- newTVar Nothing

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/MiniProtocol/ChainSync/Client.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ bracketChainSyncClient
385385
{ csCandidate = AF.Empty AF.AnchorGenesis
386386
, csLatestSlot = SNothing
387387
, csIdling = False
388+
, csNodeToNodeVersion = version
388389
}
389390

390391
withCSJCallbacks ::

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/MiniProtocol/ChainSync/Client/State.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import Ouroboros.Consensus.Ledger.SupportsProtocol
3737
( LedgerSupportsProtocol
3838
)
3939
import Ouroboros.Consensus.Node.GsmState (GsmState)
40+
import Ouroboros.Consensus.Node.NetworkProtocolVersion (NodeToNodeVersion)
4041
import Ouroboros.Consensus.Util.IOLike
4142
( IOLike
4243
, NoThunks (..)
@@ -74,6 +75,11 @@ data ChainSyncState blk = ChainSyncState
7475
-- processing it further, and the latest slot may refer to a header beyond
7576
-- the forecast horizon while the candidate fragment isn't extended yet, to
7677
-- signal to GDD that the density is known up to this slot.
78+
, csNodeToNodeVersion :: !NodeToNodeVersion
79+
-- ^ Negotiated version of the protocol with the peer.
80+
--
81+
-- This is used to determine later on whether other mini-protocols are
82+
-- expected to run in parallel with this one.
7783
}
7884
deriving stock Generic
7985

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/MiniProtocol/ObjectDiffusion/Inbound/State.hs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import GHC.Generics (Generic)
2424
import NoThunks.Class (NoThunks)
2525
import Ouroboros.Consensus.Block (BlockSupportsProtocol, HasHeader, Header)
2626
import Ouroboros.Consensus.MiniProtocol.Util.Idling (Idling (..))
27+
import Ouroboros.Consensus.Node.NetworkProtocolVersion (NodeToNodeVersion)
2728
import Ouroboros.Consensus.Util.IOLike
2829
( IOLike (..)
2930
, MonadSTM (..)
@@ -39,7 +40,12 @@ import Ouroboros.Consensus.Util.IOLike
3940
-- NOTE: 'blk' is not needed for now, but we keep it for future use.
4041
data ObjectDiffusionInboundState blk = ObjectDiffusionInboundState
4142
{ odisIdling :: !Bool
42-
-- ^ Whether we have received all objects from a peer
43+
-- ^ Whether the client is currently idling
44+
, odisNodeToNodeVersion :: !NodeToNodeVersion
45+
-- ^ Negotiated version of the protocol with the peer.
46+
--
47+
-- This is used to determine later on whether other mini-protocols are
48+
-- expected to run in parallel with this one.
4349
}
4450
deriving stock Generic
4551

@@ -49,8 +55,12 @@ deriving anyclass instance
4955
) =>
5056
NoThunks (ObjectDiffusionInboundState blk)
5157

52-
initObjectDiffusionInboundState :: ObjectDiffusionInboundState blk
53-
initObjectDiffusionInboundState = ObjectDiffusionInboundState{odisIdling = True}
58+
initObjectDiffusionInboundState :: NodeToNodeVersion -> ObjectDiffusionInboundState blk
59+
initObjectDiffusionInboundState version =
60+
ObjectDiffusionInboundState
61+
{ odisIdling = True
62+
, odisNodeToNodeVersion = version
63+
}
5464

5565
-- | An interface to an ObjectDiffusion inbound client that's used by other components.
5666
data ObjectDiffusionInboundHandle m blk = ObjectDiffusionInboundHandle
@@ -101,12 +111,13 @@ data ObjectDiffusionInboundStateView m = ObjectDiffusionInboundStateView
101111
bracketObjectDiffusionInbound ::
102112
forall m peer blk a.
103113
(IOLike m, HasHeader blk, NoThunks (Header blk)) =>
114+
NodeToNodeVersion ->
104115
ObjectDiffusionInboundHandleCollection peer m blk ->
105116
peer ->
106117
(ObjectDiffusionInboundStateView m -> m a) ->
107118
m a
108-
bracketObjectDiffusionInbound handles peer body = do
109-
odiState <- newTVarIO initObjectDiffusionInboundState
119+
bracketObjectDiffusionInbound version handles peer body = do
120+
odiState <- newTVarIO (initObjectDiffusionInboundState version)
110121
bracket (acquireContext odiState) releaseContext body
111122
where
112123
acquireContext odiState = atomically $ do

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Util/Orphans.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import NoThunks.Class
3131
, OnlyCheckWhnfNamed (..)
3232
, allNoThunks
3333
)
34+
import Ouroboros.Consensus.Node.NetworkProtocolVersion (NodeToNodeVersion)
3435
import Ouroboros.Network.Util.ShowProxy
3536
import System.FS.API (SomeHasFS)
3637
import System.FS.API.Types (FsPath, Handle)
@@ -85,6 +86,8 @@ instance NoThunks a => NoThunks (MultiSet a) where
8586
showTypeOf _ = "MultiSet"
8687
wNoThunks ctxt = wNoThunks ctxt . MultiSet.toMap
8788

89+
instance NoThunks NodeToNodeVersion
90+
8891
{-------------------------------------------------------------------------------
8992
fs-api
9093
-------------------------------------------------------------------------------}

0 commit comments

Comments
 (0)