Skip to content

Commit

Permalink
Enable network versions for Allegra and Mary
Browse files Browse the repository at this point in the history
Fixes #2670.

Without these new versions, nodes forked to Allegra or Mary can no longer
communicate with other nodes or clients.
  • Loading branch information
mrBliss committed Nov 9, 2020
1 parent 7ab59dd commit 1f4735d
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ instance CardanoHardForkConstraints c
CardanoNodeToClientVersion2 -> "CardanoNodeToClientVersion2"
CardanoNodeToClientVersion3 -> "CardanoNodeToClientVersion3"
CardanoNodeToClientVersion4 -> "CardanoNodeToClientVersion4"
CardanoNodeToClientVersion5 -> "CardanoNodeToClientVersion5"
_ -> error $ "Unknown version: " <> show v
Original file line number Diff line number Diff line change
Expand Up @@ -301,19 +301,17 @@ instance CardanoHardForkConstraints c
[ (NodeToNodeV_1, CardanoNodeToNodeVersion1)
, (NodeToNodeV_2, CardanoNodeToNodeVersion2)
, (NodeToNodeV_3, CardanoNodeToNodeVersion2)
-- TODO #2670 enable these
-- , (NodeToNodeV_4, CardanoNodeToNodeVersion3)
-- , (NodeToNodeV_5, CardanoNodeToNodeVersion4)
, (NodeToNodeV_4, CardanoNodeToNodeVersion3)
, (NodeToNodeV_5, CardanoNodeToNodeVersion4)
]

supportedNodeToClientVersions _ = Map.fromList $
[ (NodeToClientV_1, CardanoNodeToClientVersion1)
, (NodeToClientV_2, CardanoNodeToClientVersion1)
, (NodeToClientV_3, CardanoNodeToClientVersion2)
, (NodeToClientV_4, CardanoNodeToClientVersion3)
-- TODO #2670 enable these
-- , (NodeToClientV_5, CardanoNodeToClientVersion4)
-- , (NodeToClientV_6, CardanoNodeToClientVersion5)
, (NodeToClientV_5, CardanoNodeToClientVersion4)
, (NodeToClientV_6, CardanoNodeToClientVersion5)
]

{-------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ data NodeToClientVersion
-- ^ enabled @CardanoNodeToClientVersion2@
| NodeToClientV_4
-- ^ enabled @CardanoNodeToClientVersion3@, adding more queries
| NodeToClientV_5
-- ^ enabled @CardanoNodeToClientVersion4@, i.e., Allegra
| NodeToClientV_6
-- ^ enabled @CardanoNodeToClientVersion5@, i.e., Mary
deriving (Eq, Ord, Enum, Bounded, Show, Typeable)

-- | We set 16ths bit to distinguish `NodeToNodeVersion` and
Expand All @@ -47,6 +51,8 @@ nodeToClientVersionCodec = CodecCBORTerm { encodeTerm, decodeTerm }
encodeTerm NodeToClientV_2 = CBOR.TInt (2 `setBit` nodeToClientVersionBit)
encodeTerm NodeToClientV_3 = CBOR.TInt (3 `setBit` nodeToClientVersionBit)
encodeTerm NodeToClientV_4 = CBOR.TInt (4 `setBit` nodeToClientVersionBit)
encodeTerm NodeToClientV_5 = CBOR.TInt (5 `setBit` nodeToClientVersionBit)
encodeTerm NodeToClientV_6 = CBOR.TInt (6 `setBit` nodeToClientVersionBit)

decodeTerm (CBOR.TInt tag) =
case ( tag `clearBit` nodeToClientVersionBit
Expand All @@ -56,6 +62,8 @@ nodeToClientVersionCodec = CodecCBORTerm { encodeTerm, decodeTerm }
(2, True) -> Right NodeToClientV_2
(3, True) -> Right NodeToClientV_3
(4, True) -> Right NodeToClientV_4
(5, True) -> Right NodeToClientV_5
(6, True) -> Right NodeToClientV_6
(n, _) -> Left ( T.pack "decode NodeToClientVersion: unknown tag: " <> T.pack (show tag)
, Just n)
decodeTerm _ = Left ( T.pack "decode NodeToClientVersion: unexpected term"
Expand Down
12 changes: 9 additions & 3 deletions ouroboros-network/src/Ouroboros/Network/NodeToNode/Version.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,20 @@ data NodeToNodeVersion
--
-- * Enable block size hints for Byron headers in ChainSync
-- * Enable Keep-Alive miniprotocol
-- * Enable @CardanoNodeToNodeVersion2@
-- * Enable @CardanoNodeToNodeVersion2@, i.e., Shelley
| NodeToNodeV_3
-- ^ Changes:
--
-- * Enable KeepAlive miniprotocol
| NodeToNodeV_4
-- ^ Changes:
--
-- * Added 'DiffusionMode' Handshake argument. Also from this version up
-- the node will use duplex connections.
-- * Added 'DiffusionMode' Handshake argument.
-- * Enable @CardanoNodeToNodeVersion3@, i.e., Allegra
| NodeToNodeV_5
-- ^ Changes:
--
-- * Enable @CardanoNodeToNodeVersion4@, i.e., Mary
deriving (Eq, Ord, Enum, Bounded, Show, Typeable)

nodeToNodeVersionCodec :: CodecCBORTerm (Text, Maybe Int) NodeToNodeVersion
Expand All @@ -50,11 +54,13 @@ nodeToNodeVersionCodec = CodecCBORTerm { encodeTerm, decodeTerm }
encodeTerm NodeToNodeV_2 = CBOR.TInt 2
encodeTerm NodeToNodeV_3 = CBOR.TInt 3
encodeTerm NodeToNodeV_4 = CBOR.TInt 4
encodeTerm NodeToNodeV_5 = CBOR.TInt 5

decodeTerm (CBOR.TInt 1) = Right NodeToNodeV_1
decodeTerm (CBOR.TInt 2) = Right NodeToNodeV_2
decodeTerm (CBOR.TInt 3) = Right NodeToNodeV_3
decodeTerm (CBOR.TInt 4) = Right NodeToNodeV_4
decodeTerm (CBOR.TInt 5) = Right NodeToNodeV_5
decodeTerm (CBOR.TInt n) = Left ( T.pack "decode NodeToNodeVersion: unknonw tag: "
<> T.pack (show n)
, Just n
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,11 @@ tests = testGroup "Ouroboros.Network.NodeToNode.Version"
]

instance Arbitrary NodeToNodeVersion where
arbitrary = oneof [ pure NodeToNodeV_1
, pure NodeToNodeV_2
, pure NodeToNodeV_3
, pure NodeToNodeV_4
]

shrink NodeToNodeV_4 = [NodeToNodeV_3]
shrink NodeToNodeV_3 = [NodeToNodeV_2]
shrink NodeToNodeV_2 = [NodeToNodeV_1]
shrink NodeToNodeV_1 = []
arbitrary = arbitraryBoundedEnum

shrink v
| v == minBound = []
| otherwise = [pred v]

instance Arbitrary NodeToNodeVersionData where
arbitrary =
Expand Down

0 comments on commit 1f4735d

Please sign in to comment.