Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove NodeToNodeV_12 older #4985

Merged
merged 3 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ouroboros-network-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
and `reRelativeStake` -> `recomputeRelativeStake`
* Added `NodeToClientVersionV18`
* Using `typed-protocols-0.3.0.0`.
* Removed `NodeToNodeV_12` and older as these are unable
to cross the hard fork boundary.
* Removed `WhetherReceivingTentativeBlocks` used to
distinguish whether a node version is pipelining-enabled,
used in older `NodeToNodeVersion`

### Non-breaking changes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
module Ouroboros.Network.BlockFetch.ConsensusInterface
( FetchMode (..)
, BlockFetchConsensusInterface (..)
, WhetherReceivingTentativeBlocks (..)
, FromConsensus (..)
) where

Expand Down Expand Up @@ -86,8 +85,7 @@ data BlockFetchConsensusInterface peer header block m =
-- That function and 'readFetchedBlocks' are required to be linked. Upon
-- successful completion of @addFetchedBlock@ it must be the case that
-- 'readFetchedBlocks' reports the block.
mkAddFetchedBlock :: WhetherReceivingTentativeBlocks
-> STM m (Point block -> block -> m ()),
mkAddFetchedBlock :: STM m (Point block -> block -> m ()),

-- | The highest stored/downloaded slot number.
--
Expand Down Expand Up @@ -152,13 +150,6 @@ data BlockFetchConsensusInterface peer header block m =
blockForgeUTCTime :: FromConsensus block -> STM m UTCTime
}


-- | Whether the block fetch peer is sending tentative blocks, which are
-- understood to possibly be invalid
data WhetherReceivingTentativeBlocks
= ReceivingTentativeBlocks
| NotReceivingTentativeBlocks

{-------------------------------------------------------------------------------
Syntactic indicator of key precondition about Consensus time conversions
-------------------------------------------------------------------------------}
Expand Down
239 changes: 77 additions & 162 deletions ouroboros-network-api/src/Ouroboros/Network/NodeToNode/Version.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}

module Ouroboros.Network.NodeToNode.Version
Expand All @@ -9,7 +10,6 @@ module Ouroboros.Network.NodeToNode.Version
, ConnectionMode (..)
, nodeToNodeVersionCodec
, nodeToNodeCodecCBORTerm
, isPipeliningEnabled
) where

import Data.Text (Text)
Expand All @@ -20,8 +20,6 @@ import Codec.CBOR.Term qualified as CBOR

import Control.DeepSeq
import GHC.Generics
import Ouroboros.Network.BlockFetch.ConsensusInterface
(WhetherReceivingTentativeBlocks (..))
import Ouroboros.Network.CodecCBORTerm
import Ouroboros.Network.Handshake.Acceptable (Accept (..), Acceptable (..))
import Ouroboros.Network.Handshake.Queryable (Queryable (..))
Expand All @@ -30,38 +28,39 @@ import Ouroboros.Network.PeerSelection.PeerSharing (PeerSharing (..))

-- | Enumeration of node to node protocol versions.
--
data NodeToNodeVersion
= NodeToNodeV_7
-- ^ Changes:
--
-- * new 'KeepAlive' codec
-- * Enable @CardanoNodeToNodeVersion5@, i.e., Alonzo
| NodeToNodeV_8
-- ^ Changes:
--
-- * Enable block diffusion pipelining in ChainSync and BlockFetch logic.
| NodeToNodeV_9
-- ^ Changes:
--
-- * Enable @CardanoNodeToNodeVersion6@, i.e., Babbage
| NodeToNodeV_10
-- ^ Changes:
--
-- * Enable full duplex connections.
| NodeToNodeV_11
-- ^ Changes:
--
-- * Adds a new extra parameter to handshake: PeerSharing
-- This version is needed to support the new Peer Sharing miniprotocol
-- older versions that are negotiated will appear as not participating
-- in Peer Sharing to newer versions.
-- * Adds `query` to NodeToClientVersionData.
| NodeToNodeV_12
-- ^ No changes.
--
-- (In the past, this enabled Conway, but the negotiated 'NodeToNodeVersion'
-- no longer en-/disables eras.)
| NodeToNodeV_13
data NodeToNodeVersion =
-- commented out versions that can't cross into the current HF era
-- NodeToNodeV_7
-- -- ^ Changes:
-- --
-- -- * new 'KeepAlive' codec
-- -- * Enable @CardanoNodeToNodeVersion5@, i.e., Alonzo
-- | NodeToNodeV_8
-- -- ^ Changes:
-- --
-- -- * Enable block diffusion pipelining in ChainSync and BlockFetch logic.
-- | NodeToNodeV_9
-- -- ^ Changes:
-- --
-- -- * Enable @CardanoNodeToNodeVersion6@, i.e., Babbage
-- | NodeToNodeV_10
-- -- ^ Changes:
-- --
-- -- * Enable full duplex connections.
-- | NodeToNodeV_11
-- -- ^ Changes:
-- --
-- -- * Adds a new extra parameter to handshake: PeerSharing
-- -- This version is needed to support the new Peer Sharing miniprotocol
-- -- older versions that are negotiated will appear as not participating
-- -- in Peer Sharing to newer versions.
-- -- * Adds `query` to NodeToClientVersionData.
-- | NodeToNodeV_12
-- -- ^ No changes.
-- --
-- -- (In the past, this enabled Conway, but the negotiated 'NodeToNodeVersion'
-- -- no longer en-/disables eras.)
NodeToNodeV_13
-- ^ Changes:
--
-- * Removed PeerSharingPrivate constructor
Expand All @@ -73,22 +72,10 @@ data NodeToNodeVersion
nodeToNodeVersionCodec :: CodecCBORTerm (Text, Maybe Int) NodeToNodeVersion
nodeToNodeVersionCodec = CodecCBORTerm { encodeTerm, decodeTerm }
where
encodeTerm NodeToNodeV_7 = CBOR.TInt 7
encodeTerm NodeToNodeV_8 = CBOR.TInt 8
encodeTerm NodeToNodeV_9 = CBOR.TInt 9
encodeTerm NodeToNodeV_10 = CBOR.TInt 10
encodeTerm NodeToNodeV_11 = CBOR.TInt 11
encodeTerm NodeToNodeV_12 = CBOR.TInt 12
encodeTerm NodeToNodeV_13 = CBOR.TInt 13

decodeTerm (CBOR.TInt 7) = Right NodeToNodeV_7
decodeTerm (CBOR.TInt 8) = Right NodeToNodeV_8
decodeTerm (CBOR.TInt 9) = Right NodeToNodeV_9
decodeTerm (CBOR.TInt 10) = Right NodeToNodeV_10
decodeTerm (CBOR.TInt 11) = Right NodeToNodeV_11
decodeTerm (CBOR.TInt 12) = Right NodeToNodeV_12
decodeTerm (CBOR.TInt 13) = Right NodeToNodeV_13
decodeTerm (CBOR.TInt n) = Left ( T.pack "decode NodeToNodeVersion: unknonw tag: "
decodeTerm (CBOR.TInt n) = Left ( T.pack "decode NodeToNodeVersion: unknown tag: "
<> T.pack (show n)
, Just n
)
Expand Down Expand Up @@ -157,121 +144,49 @@ instance Queryable NodeToNodeVersionData where
queryVersion = query

nodeToNodeCodecCBORTerm :: NodeToNodeVersion -> CodecCBORTerm Text NodeToNodeVersionData
nodeToNodeCodecCBORTerm version
| version >= NodeToNodeV_13 =
let encodeTerm :: NodeToNodeVersionData -> CBOR.Term
encodeTerm NodeToNodeVersionData { networkMagic, diffusionMode, peerSharing, query }
= CBOR.TList
[ CBOR.TInt (fromIntegral $ unNetworkMagic networkMagic)
, CBOR.TBool (case diffusionMode of
InitiatorOnlyDiffusionMode -> True
InitiatorAndResponderDiffusionMode -> False)
, CBOR.TInt (case peerSharing of
PeerSharingDisabled -> 0
PeerSharingEnabled -> 1)
, CBOR.TBool query
]

decodeTerm :: CBOR.Term -> Either Text NodeToNodeVersionData
decodeTerm (CBOR.TList [CBOR.TInt x, CBOR.TBool diffusionMode, CBOR.TInt peerSharing, CBOR.TBool query])
| x >= 0
, x <= 0xffffffff
, Just ps <- case peerSharing of
0 -> Just PeerSharingDisabled
1 -> Just PeerSharingEnabled
_ -> Nothing
= Right
NodeToNodeVersionData {
networkMagic = NetworkMagic (fromIntegral x),
diffusionMode = if diffusionMode
then InitiatorOnlyDiffusionMode
else InitiatorAndResponderDiffusionMode,
peerSharing = ps,
query = query
}
| x < 0 || x > 0xffffffff
= Left $ T.pack $ "networkMagic out of bound: " <> show x
| otherwise -- peerSharing < 0 || peerSharing > 1
= Left $ T.pack $ "peerSharing is out of bound: " <> show peerSharing
decodeTerm t
= Left $ T.pack $ "unknown encoding: " ++ show t
in CodecCBORTerm { encodeTerm, decodeTerm }
| version >= NodeToNodeV_11
, version <= NodeToNodeV_12 =
let encodeTerm :: NodeToNodeVersionData -> CBOR.Term
encodeTerm NodeToNodeVersionData { networkMagic, diffusionMode, query }
= CBOR.TList
[ CBOR.TInt (fromIntegral $ unNetworkMagic networkMagic)
, CBOR.TBool (case diffusionMode of
InitiatorOnlyDiffusionMode -> True
InitiatorAndResponderDiffusionMode -> False)
-- There's a bug in this versions where the
-- agreed PeerSharing value on the remote side
-- is whatever that got proposed, so we have to
-- disable peer sharing with such nodes to avoid
-- protocol violations
, CBOR.TInt 0 -- 0 corresponds to PeerSharingDisabled
, CBOR.TBool query
]
nodeToNodeCodecCBORTerm =
\case
NodeToNodeV_13 -> v13

decodeTerm :: CBOR.Term -> Either Text NodeToNodeVersionData
decodeTerm (CBOR.TList [CBOR.TInt x, CBOR.TBool diffusionMode, CBOR.TInt _, CBOR.TBool query])
| x >= 0
, x <= 0xffffffff
= Right
NodeToNodeVersionData {
networkMagic = NetworkMagic (fromIntegral x),
diffusionMode = if diffusionMode
then InitiatorOnlyDiffusionMode
else InitiatorAndResponderDiffusionMode,
peerSharing = PeerSharingDisabled,
query = query
}
| x < 0 || x > 0xffffffff
= Left $ T.pack $ "networkMagic out of bound: " <> show x
decodeTerm t
= Left $ T.pack $ "unknown encoding: " ++ show t
in CodecCBORTerm { encodeTerm, decodeTerm }
| otherwise =
let encodeTerm :: NodeToNodeVersionData -> CBOR.Term
encodeTerm NodeToNodeVersionData { networkMagic, diffusionMode }
= CBOR.TList
[ CBOR.TInt (fromIntegral $ unNetworkMagic networkMagic)
, CBOR.TBool (case diffusionMode of
InitiatorOnlyDiffusionMode -> True
InitiatorAndResponderDiffusionMode -> False)
]

decodeTerm :: CBOR.Term -> Either Text NodeToNodeVersionData
decodeTerm (CBOR.TList [CBOR.TInt x, CBOR.TBool diffusionMode])
| x >= 0
, x <= 0xffffffff
= Right
NodeToNodeVersionData {
networkMagic = NetworkMagic (fromIntegral x)
, diffusionMode = if diffusionMode
then InitiatorOnlyDiffusionMode
else InitiatorAndResponderDiffusionMode
-- By default older versions do not participate in Peer
-- Sharing, since they do not support the new miniprotocol
, peerSharing = PeerSharingDisabled
, query = False
}
| otherwise
= Left $ T.pack $ "networkMagic out of bound: " <> show x
decodeTerm t
= Left $ T.pack $ "unknown encoding: " ++ show t
in CodecCBORTerm { encodeTerm, decodeTerm }
where
v13 = CodecCBORTerm { encodeTerm = encodeTerm13, decodeTerm = decodeTerm13 }

encodeTerm13 :: NodeToNodeVersionData -> CBOR.Term
encodeTerm13 NodeToNodeVersionData { networkMagic, diffusionMode, peerSharing, query }
= CBOR.TList
[ CBOR.TInt (fromIntegral $ unNetworkMagic networkMagic)
, CBOR.TBool (case diffusionMode of
InitiatorOnlyDiffusionMode -> True
InitiatorAndResponderDiffusionMode -> False)
, CBOR.TInt (case peerSharing of
PeerSharingDisabled -> 0
PeerSharingEnabled -> 1)
, CBOR.TBool query
]

decodeTerm13 :: CBOR.Term -> Either Text NodeToNodeVersionData
decodeTerm13 (CBOR.TList [CBOR.TInt x, CBOR.TBool diffusionMode, CBOR.TInt peerSharing, CBOR.TBool query])
| x >= 0
, x <= 0xffffffff
, Just ps <- case peerSharing of
0 -> Just PeerSharingDisabled
1 -> Just PeerSharingEnabled
_ -> Nothing
= Right
NodeToNodeVersionData {
networkMagic = NetworkMagic (fromIntegral x),
diffusionMode = if diffusionMode
then InitiatorOnlyDiffusionMode
else InitiatorAndResponderDiffusionMode,
peerSharing = ps,
query = query
}
| x < 0 || x > 0xffffffff
= Left $ T.pack $ "networkMagic out of bound: " <> show x
| otherwise -- peerSharing < 0 || peerSharing > 1
= Left $ T.pack $ "peerSharing is out of bound: " <> show peerSharing
decodeTerm13 t
= Left $ T.pack $ "unknown encoding: " ++ show t


data ConnectionMode = UnidirectionalMode | DuplexMode

-- | Check whether a version enabling diffusion pipelining has been
-- negotiated.
--
-- TODO: this ought to be defined in `ouroboros-consensus` or
-- `ouroboros-consensus-diffusion`
isPipeliningEnabled :: NodeToNodeVersion -> WhetherReceivingTentativeBlocks
isPipeliningEnabled v
| v >= NodeToNodeV_8 = ReceivingTentativeBlocks
| otherwise = NotReceivingTentativeBlocks
Loading
Loading