Skip to content

Commit

Permalink
Merge pull request #4557 from input-output-hk/coot/swap-protocol-vers…
Browse files Browse the repository at this point in the history
…ions

Swap protocol versions and bump package versions
  • Loading branch information
coot authored May 15, 2023
2 parents 792dc13 + a6c72ab commit 130d7aa
Show file tree
Hide file tree
Showing 15 changed files with 75 additions and 148 deletions.
10 changes: 10 additions & 0 deletions ouroboros-network-api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
# Revision history for ouroboros-network-api

## 0.5.0.0 -- 2023-05-15

* Swapped `NodeToClientV_15` with `NodeToClientV_16`, e.g. handshake query
comes with `V_15` and Conway with `V_16`.
* Swapped `NodeToNodeV_11` with `NodeToNodeV_12`, e.g. handshake query moved to
`V_11` and Conway moved to `V_12`. `V_11` also comes with handshake support
for peer sharing.

## 0.4.0.0 -- 2023-05-08

Depracated release, use `0.5` instead.

### Breakin changes

* Added `NodeToNodeV_12` and `NodeToClientV_16` which support handshake query.
Expand Down
2 changes: 1 addition & 1 deletion ouroboros-network-api/ouroboros-network-api.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 3.0
name: ouroboros-network-api
version: 0.4.0.0
version: 0.5.0.0
synopsis: A networking api shared with ouroboros-consensus
description: A networking api shared with ouroboros-consensus.
license: Apache-2.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ data NodeToClientVersion
| NodeToClientV_14
-- ^ added @GetPoolDistr@, @GetPoolState@, @GetSnapshots@
| NodeToClientV_15
-- ^ added `query` to NodeToClientVersionData
| NodeToClientV_16
-- ^ enabled @CardanoNodeToClientVersion11@, i.e., Conway and
-- @GetStakeDelegDeposits@.
| NodeToClientV_16
-- ^ added `query` to NodeToClientVersionData
deriving (Eq, Ord, Enum, Bounded, Show, Typeable)

-- | We set 16ths bit to distinguish `NodeToNodeVersion` and
Expand Down Expand Up @@ -110,17 +110,17 @@ nodeToClientCodecCBORTerm v = CodecCBORTerm {encodeTerm, decodeTerm}
where
encodeTerm :: NodeToClientVersionData -> CBOR.Term
encodeTerm NodeToClientVersionData { networkMagic, query }
| v >= NodeToClientV_16
| v >= NodeToClientV_15
= CBOR.TList [CBOR.TInt (fromIntegral $ unNetworkMagic networkMagic), CBOR.TBool query]
| otherwise
= CBOR.TInt (fromIntegral $ unNetworkMagic networkMagic)

decodeTerm :: CBOR.Term -> Either Text NodeToClientVersionData
decodeTerm (CBOR.TList [CBOR.TInt x, CBOR.TBool query])
| v >= NodeToClientV_16
| v >= NodeToClientV_15
= decoder x query
decodeTerm (CBOR.TInt x)
| v < NodeToClientV_16
| v < NodeToClientV_15
= decoder x False
decodeTerm t
= Left $ T.pack $ "unknown encoding: " ++ show t
Expand Down
46 changes: 3 additions & 43 deletions ouroboros-network-api/src/Ouroboros/Network/NodeToNode/Version.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ data NodeToNodeVersion
| NodeToNodeV_11
-- ^ Changes:
--
-- * Enable @CardanoNodeToNodeVersion7@, i.e., Conway
-- * 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
-- ^ Changes:
--
-- * Adds `query` to NodeToClientVersionData.
-- * Enable @CardanoNodeToNodeVersion7@, i.e., Conway
deriving (Eq, Ord, Enum, Bounded, Show, Typeable)

nodeToNodeVersionCodec :: CodecCBORTerm (Text, Maybe Int) NodeToNodeVersion
Expand Down Expand Up @@ -140,7 +140,7 @@ instance Queryable NodeToNodeVersionData where

nodeToNodeCodecCBORTerm :: NodeToNodeVersion -> CodecCBORTerm Text NodeToNodeVersionData
nodeToNodeCodecCBORTerm version
| version >= NodeToNodeV_12 =
| version >= NodeToNodeV_11 =
let encodeTerm :: NodeToNodeVersionData -> CBOR.Term
encodeTerm NodeToNodeVersionData { networkMagic, diffusionMode, peerSharing, query }
= CBOR.TList $
Expand Down Expand Up @@ -181,46 +181,6 @@ nodeToNodeCodecCBORTerm version
decodeTerm _ t
= Left $ T.pack $ "unknown encoding: " ++ show t
in CodecCBORTerm {encodeTerm, decodeTerm = decodeTerm version }
| version >= NodeToNodeV_11 =
let encodeTerm :: NodeToNodeVersionData -> CBOR.Term
encodeTerm NodeToNodeVersionData { networkMagic, diffusionMode, peerSharing }
= CBOR.TList $
[ CBOR.TInt (fromIntegral $ unNetworkMagic networkMagic)
, CBOR.TBool (case diffusionMode of
InitiatorOnlyDiffusionMode -> True
InitiatorAndResponderDiffusionMode -> False)
, CBOR.TInt (case peerSharing of
NoPeerSharing -> 0
PeerSharingPrivate -> 1
PeerSharingPublic -> 2)
]

decodeTerm :: NodeToNodeVersion -> CBOR.Term -> Either Text NodeToNodeVersionData
decodeTerm _ (CBOR.TList [CBOR.TInt x, CBOR.TBool diffusionMode, CBOR.TInt peerSharing])
| x >= 0
, x <= 0xffffffff
, peerSharing >= 0
, peerSharing <= 2
= Right
NodeToNodeVersionData {
networkMagic = NetworkMagic (fromIntegral x),
diffusionMode = if diffusionMode
then InitiatorOnlyDiffusionMode
else InitiatorAndResponderDiffusionMode,
peerSharing = case peerSharing of
0 -> NoPeerSharing
1 -> PeerSharingPrivate
2 -> PeerSharingPublic
_ -> error "decodeTerm: impossible happened!",
query = False
}
| x < 0 || x > 0xffffffff
= Left $ T.pack $ "networkMagic out of bound: " <> show x
| otherwise -- peerSharing < 0 || peerSharing > 2
= Left $ T.pack $ "peerSharing out of bound: " <> show peerSharing
decodeTerm _ t
= Left $ T.pack $ "unknown encoding: " ++ show t
in CodecCBORTerm {encodeTerm, decodeTerm = decodeTerm version }
| otherwise =
let encodeTerm :: NodeToNodeVersionData -> CBOR.Term
encodeTerm NodeToNodeVersionData { networkMagic, diffusionMode }
Expand Down
4 changes: 4 additions & 0 deletions ouroboros-network-framework/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Revision history for ouroboros-network-framework

## 0.6.0.1 -- 2023-05-15

* Updated to use `ouroboros-network-api-0.5.0.0`.

## 0.6.0.0 -- 2023-05-08

### Breaking changes
Expand Down
4 changes: 2 additions & 2 deletions ouroboros-network-framework/ouroboros-network-framework.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 3.0
name: ouroboros-network-framework
version: 0.6.0.0
version: 0.6.0.1
synopsis: Ouroboros network framework
description: Ouroboros network framework.
license: Apache-2.0
Expand Down Expand Up @@ -93,7 +93,7 @@ library
, network >=3.1.2.2 && < 3.2
, network-mux ^>=0.4
, ouroboros-network-api
^>=0.4
^>=0.5
, ouroboros-network-testing
, typed-protocols >=0.1 && < 0.2
, typed-protocols-cborg
Expand Down
10 changes: 9 additions & 1 deletion ouroboros-network-protocols/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
# Revision history for ouroboros-network-protocols

## 0.5.0.2 -- 2023-05-15

## Non-breaking changes

* Updated to use `ouroboros-network-api-0.5.0.0`.

## 0.5.0.1 -- 2023-05-08

* Updated to newer version of `ouroboros-network-api`.
## Non-breaking changes

* Updated to use `ouroboros-network-api-0.4.0.0`.

## 0.5.0.0 -- 2023-04-28

Expand Down
5 changes: 3 additions & 2 deletions ouroboros-network-protocols/ouroboros-network-protocols.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 3.0
name: ouroboros-network-protocols
version: 0.5.0.1
version: 0.5.0.2
synopsis: Ouroboros Network Protocols
description: Ouroboros Network Protocols.
license: Apache-2.0
Expand Down Expand Up @@ -100,7 +100,8 @@ library
io-classes ^>=1.1,
si-timers,

ouroboros-network-api,
ouroboros-network-api
^>=0.5,
serialise,
typed-protocols >=0.1.0.4 && <1.0,
typed-protocols-cborg
Expand Down
56 changes: 15 additions & 41 deletions ouroboros-network-protocols/test-cddl/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ tests CDDLSpecs { cddlChainSync
, cddlKeepAlive
, cddlLocalStateQuery
, cddlHandshakeNodeToNodeV7To10
, cddlHandshakeNodeToNodeV11
, cddlHandshakeNodeToNodeV12ToLast
, cddlHandshakeNodeToNodeV11ToLast
, cddlHandshakeNodeToClient
, cddlPeerSharing
} =
Expand All @@ -150,12 +149,9 @@ tests CDDLSpecs { cddlChainSync
[ testProperty "NodeToNode.Handshake V7 to V10"
(prop_encodeHandshakeNodeToNodeV7To10
cddlHandshakeNodeToNodeV7To10)
, testProperty "NodeToNode.Handshake V11"
(prop_encodeHandshakeNodeToNodeV11
cddlHandshakeNodeToNodeV11)
, testProperty "NodeToNode.Handshake V12 to Last"
(prop_encodeHandshakeNodeToNodeV12ToLast
cddlHandshakeNodeToNodeV12ToLast)
, testProperty "NodeToNode.Handshake V11 to Last"
(prop_encodeHandshakeNodeToNodeV11ToLast
cddlHandshakeNodeToNodeV11ToLast)
, -- If this fails whilst adding a new node-to-client version, ensure that
-- all the necessary changes are included:
--
Expand Down Expand Up @@ -189,7 +185,7 @@ tests CDDLSpecs { cddlChainSync
cddlHandshakeNodeToNodeV7To10)
, testCase "NodeToNode.Handshake V11"
(unit_decodeHandshakeNodeToNode
cddlHandshakeNodeToNodeV11)
cddlHandshakeNodeToNodeV11ToLast)
, testCase "NodeToClient.Handshake"
(unit_decodeHandshakeNodeToClient
cddlHandshakeNodeToClient)
Expand Down Expand Up @@ -219,8 +215,7 @@ newtype CDDLSpec ps = CDDLSpec BL.ByteString
data CDDLSpecs = CDDLSpecs {
cddlHandshakeNodeToClient :: CDDLSpec (Handshake NodeToClientVersion CBOR.Term),
cddlHandshakeNodeToNodeV7To10 :: CDDLSpec (Handshake NodeToNodeVersion CBOR.Term),
cddlHandshakeNodeToNodeV11 :: CDDLSpec (Handshake NodeToNodeVersion CBOR.Term),
cddlHandshakeNodeToNodeV12ToLast :: CDDLSpec (Handshake NodeToNodeVersion CBOR.Term),
cddlHandshakeNodeToNodeV11ToLast :: CDDLSpec (Handshake NodeToNodeVersion CBOR.Term),
cddlChainSync :: CDDLSpec (ChainSync
BlockHeader
(Point BlockHeader)
Expand All @@ -247,8 +242,7 @@ readCDDLSpecs = do
common <- BL.readFile (dir </> "common.cddl")
handshakeNodeToClient <- BL.readFile (dir </> "handshake-node-to-client.cddl")
handshakeNodeToNodeV7To10 <- BL.readFile (dir </> "handshake-node-to-node.cddl")
handshakeNodeToNodeV11 <- BL.readFile (dir </> "handshake-node-to-node-v11.cddl")
handshakeNodeToNodeV12ToLast <- BL.readFile (dir </> "handshake-node-to-node-v12.cddl")
handshakeNodeToNodeV11ToLast <- BL.readFile (dir </> "handshake-node-to-node-v11.cddl")
chainSync <- BL.readFile (dir </> "chain-sync.cddl")
blockFetch <- BL.readFile (dir </> "block-fetch.cddl")
txSubmission2 <- BL.readFile (dir </> "tx-submission2.cddl")
Expand All @@ -262,8 +256,7 @@ readCDDLSpecs = do
return CDDLSpecs {
cddlHandshakeNodeToClient = CDDLSpec $ handshakeNodeToClient,
cddlHandshakeNodeToNodeV7To10 = CDDLSpec $ handshakeNodeToNodeV7To10,
cddlHandshakeNodeToNodeV11 = CDDLSpec $ handshakeNodeToNodeV11,
cddlHandshakeNodeToNodeV12ToLast = CDDLSpec $ handshakeNodeToNodeV12ToLast,
cddlHandshakeNodeToNodeV11ToLast = CDDLSpec $ handshakeNodeToNodeV11ToLast,
cddlChainSync = CDDLSpec $ chainSync
<> common,
cddlBlockFetch = CDDLSpec $ blockFetch
Expand Down Expand Up @@ -399,15 +392,8 @@ newtype NtNHandshakeV7To10 =
(AnyMessageAndAgency (Handshake NodeToNodeVersion CBOR.Term))
deriving Show

-- | Newtype for testing Handshake CDDL Specification from version 11 onward.
--
newtype NtNHandshakeV11 =
NtNHandshakeV11
(AnyMessageAndAgency (Handshake NodeToNodeVersion CBOR.Term))
deriving Show

newtype NtNHandshakeV12ToLast =
NtNHandshakeV12ToLast
newtype NtNHandshakeV11ToLast =
NtNHandshakeV11ToLast
(AnyMessageAndAgency (Handshake NodeToNodeVersion CBOR.Term))
deriving Show

Expand Down Expand Up @@ -463,15 +449,10 @@ instance Arbitrary NtNHandshakeV7To10 where
let genVersion = elements [minBound .. NodeToNodeV_10]
NtNHandshakeV7To10 <$> genNtNHandshake genVersion

instance Arbitrary NtNHandshakeV11 where
arbitrary = do
let genVersion = elements [NodeToNodeV_11]
NtNHandshakeV11 <$> genNtNHandshake genVersion

instance Arbitrary NtNHandshakeV12ToLast where
instance Arbitrary NtNHandshakeV11ToLast where
arbitrary = do
let genVersion = elements [NodeToNodeV_12 ..]
NtNHandshakeV12ToLast <$> genNtNHandshake genVersion
NtNHandshakeV11ToLast <$> genNtNHandshake genVersion


prop_encodeHandshakeNodeToNodeV7To10
Expand All @@ -481,18 +462,11 @@ prop_encodeHandshakeNodeToNodeV7To10
prop_encodeHandshakeNodeToNodeV7To10 spec (NtNHandshakeV7To10 x) =
validateEncoder spec nodeToNodeHandshakeCodec x

prop_encodeHandshakeNodeToNodeV11
:: CDDLSpec (Handshake NodeToNodeVersion CBOR.Term)
-> NtNHandshakeV11
-> Property
prop_encodeHandshakeNodeToNodeV11 spec (NtNHandshakeV11 x) =
validateEncoder spec nodeToNodeHandshakeCodec x

prop_encodeHandshakeNodeToNodeV12ToLast
prop_encodeHandshakeNodeToNodeV11ToLast
:: CDDLSpec (Handshake NodeToNodeVersion CBOR.Term)
-> NtNHandshakeV12ToLast
-> NtNHandshakeV11ToLast
-> Property
prop_encodeHandshakeNodeToNodeV12ToLast spec (NtNHandshakeV12ToLast x) =
prop_encodeHandshakeNodeToNodeV11ToLast spec (NtNHandshakeV11ToLast x) =
validateEncoder spec nodeToNodeHandshakeCodec x

-- TODO: add our regular tests for `Handshake NodeToClientVerision CBOR.Term`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ versionTable = { * oldVersionNumber => oldNodeToClientVersionData
}


; Version 16 introduces the version query flag
; Version 15 introduces the version query flag
; as of version 2 (which is no longer supported) we set 15th bit to 1
; 16
versionNumber = 32784
; 15 / 16
versionNumber = 32783 / 32784

; as of version 2 (which is no longer supported) we set 15th bit to 1
; 9 / 10 / 11 / 12 / 13 / 14 / 15
oldVersionNumber = 32777 / 32778 / 32779 / 32780 / 32781 / 32782 / 32783
; 9 / 10 / 11 / 12 / 13 / 14
oldVersionNumber = 32777 / 32778 / 32779 / 32780 / 32781 / 32782

anyVersionNumber = versionNumber / oldVersionNumber

; As of version 16
; As of version 15 and higher
nodeToClientVersionData = [networkMagic, query]

oldNodeToClientVersionData = networkMagic
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
;
; NodeToNode Handshake, v11
;

handshakeMessage
= msgProposeVersions
/ msgAcceptVersion
/ msgRefuse
/ msgQueryReply

msgProposeVersions = [0, versionTable]
msgAcceptVersion = [1, versionNumber, nodeToNodeVersionData]
msgRefuse = [2, refuseReason]
msgQueryReply = [3, versionTable]

versionTable = { * versionNumber => nodeToNodeVersionData }

versionNumber = 11
versionNumber = 11 / 12

nodeToNodeVersionData = [ networkMagic, initiatorAndResponderDiffusionMode, peerSharing ]
nodeToNodeVersionData = [ networkMagic, initiatorAndResponderDiffusionMode, peerSharing, query ]

; range between 0 and 0xffffffff
networkMagic = 0..4294967295
initiatorAndResponderDiffusionMode = bool
; range between 0 and 2
peerSharing = 0..2
query = bool

refuseReason
= refuseReasonVersionMismatch
Expand All @@ -32,4 +34,3 @@ refuseReasonVersionMismatch = [0, [ *versionNumber ] ]
refuseReasonHandshakeDecodeError = [1, versionNumber, tstr]
refuseReasonRefused = [2, versionNumber, tstr]


Loading

0 comments on commit 130d7aa

Please sign in to comment.