From d664784e79f98fff5c2f268dfc2a6db5c4c02964 Mon Sep 17 00:00:00 2001 From: Franco Testagrossa Date: Thu, 9 May 2024 18:03:58 +0200 Subject: [PATCH] Fix PeerHandshakeFailure type to fit the api spec --- ...ySized (ServerOutput (Tx BabbageEra)).json | 86 ++++++------- ...d (TimedServerOutput (Tx BabbageEra)).json | 116 +++++++++--------- hydra-node/src/Hydra/API/ServerOutput.hs | 4 +- hydra-node/src/Hydra/Network/Message.hs | 2 +- .../Network/Ouroboros/VersionedProtocol.hs | 6 +- 5 files changed, 108 insertions(+), 106 deletions(-) diff --git a/hydra-node/golden/ReasonablySized (ServerOutput (Tx BabbageEra)).json b/hydra-node/golden/ReasonablySized (ServerOutput (Tx BabbageEra)).json index f353d59b654..3f41d8a5945 100644 --- a/hydra-node/golden/ReasonablySized (ServerOutput (Tx BabbageEra)).json +++ b/hydra-node/golden/ReasonablySized (ServerOutput (Tx BabbageEra)).json @@ -4208,17 +4208,17 @@ "tag": "PeerConnected" }, { - "ourVersion": -1, + "ourVersion": 5, "remoteHost": { "hostname": "0.0.0.6", "port": 4 }, "tag": "PeerHandshakeFailure", "theirVersions": [ - 2, - 3, - 3, - -3 + 0, + 1, + 1, + 3 ] }, { @@ -4234,18 +4234,18 @@ "utxo": {} }, { - "ourVersion": -5, + "ourVersion": 1, "remoteHost": { "hostname": "0.0.0.7", "port": 1 }, "tag": "PeerHandshakeFailure", "theirVersions": [ - -2, + 4, + 6, + 2, 5, - -4, - -1, - 1 + 3 ] }, { @@ -5433,19 +5433,19 @@ } }, { - "ourVersion": 2, + "ourVersion": 0, "remoteHost": { "hostname": "0.0.0.0", "port": 6 }, "tag": "PeerHandshakeFailure", "theirVersions": [ - -4, - 1, - 6, 2, - 2, - -4 + 5, + 4, + 0, + 0, + 2 ] }, { @@ -6635,17 +6635,17 @@ "tag": "SnapshotConfirmed" }, { - "ourVersion": 4, + "ourVersion": 2, "remoteHost": { "hostname": "0.0.0.2", "port": 3 }, "tag": "PeerHandshakeFailure", "theirVersions": [ - 1, - 5, - -3, - -3 + 3, + 3, + 3, + 3 ] }, { @@ -7311,19 +7311,19 @@ } }, { - "ourVersion": -3, + "ourVersion": 3, "remoteHost": { "hostname": "0.0.0.2", "port": 5 }, "tag": "PeerHandshakeFailure", "theirVersions": [ - 5, - -6, - -3, + 3, 0, - 1, - -4 + 5, + 6, + 5, + 2 ] }, { @@ -7866,15 +7866,15 @@ "tag": "SnapshotConfirmed" }, { - "ourVersion": -1, + "ourVersion": 5, "remoteHost": { "hostname": "0.0.0.0", "port": 5 }, "tag": "PeerHandshakeFailure", "theirVersions": [ - -4, - 0 + 2, + 6 ] }, { @@ -9259,18 +9259,18 @@ } }, { - "ourVersion": -4, + "ourVersion": 2, "remoteHost": { "hostname": "0.0.0.1", "port": 4 }, "tag": "PeerHandshakeFailure", "theirVersions": [ - 1, - 6, - -4, - -4, - 1 + 0, + 4, + 2, + 2, + 4 ] }, { @@ -11582,19 +11582,19 @@ } }, { - "ourVersion": -2, + "ourVersion": 6, "remoteHost": { "hostname": "0.0.0.3", "port": 2 }, "tag": "PeerHandshakeFailure", "theirVersions": [ + 4, + 3, 6, - 5, - 2, - -2, - 0, - 6 + 4, + 6, + 5 ] }, { @@ -11803,7 +11803,7 @@ "tag": "Greetings" }, { - "ourVersion": -5, + "ourVersion": 1, "remoteHost": { "hostname": "0.0.0.2", "port": 5 diff --git a/hydra-node/golden/ReasonablySized (TimedServerOutput (Tx BabbageEra)).json b/hydra-node/golden/ReasonablySized (TimedServerOutput (Tx BabbageEra)).json index baf1f5b8c1f..3da14a35493 100644 --- a/hydra-node/golden/ReasonablySized (TimedServerOutput (Tx BabbageEra)).json +++ b/hydra-node/golden/ReasonablySized (TimedServerOutput (Tx BabbageEra)).json @@ -3925,7 +3925,7 @@ "timestamp": "1864-05-08T06:04:01.587637911503Z" }, { - "ourVersion": 6, + "ourVersion": 4, "remoteHost": { "hostname": "0.0.0.1", "port": 8 @@ -3933,10 +3933,10 @@ "seq": 4, "tag": "PeerHandshakeFailure", "theirVersions": [ - 3, - 0, - 4, - 3 + 1, + 6, + 2, + 1 ], "timestamp": "1864-05-07T10:28:53.182385547253Z" }, @@ -5268,7 +5268,7 @@ "timestamp": "1864-05-03T15:27:04.320534221929Z" }, { - "ourVersion": -6, + "ourVersion": 0, "remoteHost": { "hostname": "0.0.0.5", "port": 1 @@ -5276,8 +5276,8 @@ "seq": 0, "tag": "PeerHandshakeFailure", "theirVersions": [ - 1, - 6 + 3, + 4 ], "timestamp": "1864-05-06T15:34:27.310182781162Z" }, @@ -6676,7 +6676,7 @@ "timestamp": "1864-05-03T16:22:17.077330794905Z" }, { - "ourVersion": 2, + "ourVersion": 0, "remoteHost": { "hostname": "0.0.0.0", "port": 7 @@ -6684,9 +6684,9 @@ "seq": 1, "tag": "PeerHandshakeFailure", "theirVersions": [ - 4, - 3, - -2 + 5, + 1, + 4 ], "timestamp": "1864-05-09T14:50:40.388021859267Z" }, @@ -6807,7 +6807,7 @@ "timestamp": "1864-05-05T15:51:29.178983210767Z" }, { - "ourVersion": -2, + "ourVersion": 4, "remoteHost": { "hostname": "0.0.0.7", "port": 2 @@ -6815,9 +6815,9 @@ "seq": 0, "tag": "PeerHandshakeFailure", "theirVersions": [ - 6, - 3, - 0 + 4, + 1, + 6 ], "timestamp": "1864-05-10T10:27:16.963499159086Z" }, @@ -8365,7 +8365,7 @@ "timestamp": "1864-05-14T17:26:23.655592966279Z" }, { - "ourVersion": -6, + "ourVersion": 6, "remoteHost": { "hostname": "0.0.0.4", "port": 5 @@ -8373,12 +8373,12 @@ "seq": 6, "tag": "PeerHandshakeFailure", "theirVersions": [ - -5, + 1, + 0, + 3, 2, - -3, - -4, - -6, - 3 + 0, + 6 ], "timestamp": "1864-05-05T21:18:37.078873886392Z" }, @@ -8999,7 +8999,7 @@ "timestamp": "1864-05-06T01:24:45.004289918319Z" }, { - "ourVersion": 1, + "ourVersion": 5, "remoteHost": { "hostname": "0.0.0.3", "port": 0 @@ -9007,11 +9007,11 @@ "seq": 6, "tag": "PeerHandshakeFailure", "theirVersions": [ - 4, - -3, 2, + 3, 0, - -5 + 6, + 1 ], "timestamp": "1864-05-03T14:05:18.125556818835Z" }, @@ -11411,7 +11411,7 @@ "utxo": {} }, { - "ourVersion": 0, + "ourVersion": 6, "remoteHost": { "hostname": "0.0.0.7", "port": 0 @@ -11419,8 +11419,8 @@ "seq": 2, "tag": "PeerHandshakeFailure", "theirVersions": [ - 1, - 1, + 6, + 3, 6 ], "timestamp": "1864-05-10T11:59:43.37512534474Z" @@ -14708,7 +14708,7 @@ } }, { - "ourVersion": -1, + "ourVersion": 5, "remoteHost": { "hostname": "0.0.0.0", "port": 4 @@ -14716,12 +14716,12 @@ "seq": 1, "tag": "PeerHandshakeFailure", "theirVersions": [ - -2, - 2, - 3, + 4, + 0, + 1, + 1, 3, - -3, - -6 + 0 ], "timestamp": "1864-05-13T09:59:59.520149062213Z" }, @@ -14743,7 +14743,7 @@ "timestamp": "1864-05-03T12:08:23.60605693487Z" }, { - "ourVersion": -5, + "ourVersion": 1, "remoteHost": { "hostname": "0.0.0.5", "port": 8 @@ -14751,11 +14751,11 @@ "seq": 5, "tag": "PeerHandshakeFailure", "theirVersions": [ - -5, + 6, + 6, + 3, 0, - 5, - -6, - -6 + 0 ], "timestamp": "1864-05-03T03:31:04.368982641954Z" }, @@ -15100,7 +15100,7 @@ "utxo": {} }, { - "ourVersion": -5, + "ourVersion": 1, "remoteHost": { "hostname": "0.0.0.1", "port": 0 @@ -15108,11 +15108,11 @@ "seq": 2, "tag": "PeerHandshakeFailure", "theirVersions": [ - -1, - -3, - -1, + 5, 3, - -3 + 5, + 1, + 3 ], "timestamp": "1864-05-03T07:24:28.386883228293Z" }, @@ -15735,7 +15735,7 @@ } }, { - "ourVersion": -1, + "ourVersion": 5, "remoteHost": { "hostname": "0.0.0.8", "port": 4 @@ -15743,7 +15743,7 @@ "seq": 3, "tag": "PeerHandshakeFailure", "theirVersions": [ - 2 + 0 ], "timestamp": "1864-05-03T23:32:42.062017151009Z" }, @@ -16637,7 +16637,7 @@ } }, { - "ourVersion": -2, + "ourVersion": 4, "remoteHost": { "hostname": "0.0.0.8", "port": 8 @@ -16645,10 +16645,10 @@ "seq": 3, "tag": "PeerHandshakeFailure", "theirVersions": [ - 4, - 3, - -1, - -3 + 2, + 1, + 5, + 5 ], "timestamp": "1864-05-07T13:43:49.275003110466Z" }, @@ -18283,7 +18283,7 @@ "timestamp": "1864-05-08T04:53:48.891869060509Z" }, { - "ourVersion": -2, + "ourVersion": 4, "remoteHost": { "hostname": "0.0.0.8", "port": 3 @@ -18291,9 +18291,9 @@ "seq": 0, "tag": "PeerHandshakeFailure", "theirVersions": [ - -2, - -3, - 4 + 4, + 3, + 2 ], "timestamp": "1864-05-13T19:16:27.763926072788Z" }, @@ -18882,7 +18882,7 @@ "utxo": {} }, { - "ourVersion": 4, + "ourVersion": 2, "remoteHost": { "hostname": "0.0.0.1", "port": 4 @@ -18890,7 +18890,7 @@ "seq": 3, "tag": "PeerHandshakeFailure", "theirVersions": [ - -2 + 4 ], "timestamp": "1864-05-06T11:36:54.462503754082Z" } diff --git a/hydra-node/src/Hydra/API/ServerOutput.hs b/hydra-node/src/Hydra/API/ServerOutput.hs index c980a9fcf27..af263430acc 100644 --- a/hydra-node/src/Hydra/API/ServerOutput.hs +++ b/hydra-node/src/Hydra/API/ServerOutput.hs @@ -55,8 +55,8 @@ data ServerOutput tx | PeerDisconnected {peer :: NodeId} | PeerHandshakeFailure { remoteHost :: Host - , ourVersion :: Int - , theirVersions :: [Int] + , ourVersion :: Natural + , theirVersions :: [Natural] } | HeadIsInitializing {headId :: HeadId, parties :: [Party]} | Committed {headId :: HeadId, party :: Party, utxo :: UTxOType tx} diff --git a/hydra-node/src/Hydra/Network/Message.hs b/hydra-node/src/Hydra/Network/Message.hs index 116382979ee..6bee09e4ceb 100644 --- a/hydra-node/src/Hydra/Network/Message.hs +++ b/hydra-node/src/Hydra/Network/Message.hs @@ -22,7 +22,7 @@ instance Arbitrary msg => Arbitrary (NetworkEvent msg) where arbitrary = genericArbitrary type HydraVersionedProtocolNumber :: Type -newtype HydraVersionedProtocolNumber = MkHydraVersionedProtocolNumber {hydraVersionedProtocolNumber :: Int} +newtype HydraVersionedProtocolNumber = MkHydraVersionedProtocolNumber {hydraVersionedProtocolNumber :: Natural} deriving stock (Eq, Show, Generic, Ord) deriving anyclass (ToJSON, FromJSON) diff --git a/hydra-node/src/Hydra/Network/Ouroboros/VersionedProtocol.hs b/hydra-node/src/Hydra/Network/Ouroboros/VersionedProtocol.hs index ddddde723d3..6ca0d7f6e7d 100644 --- a/hydra-node/src/Hydra/Network/Ouroboros/VersionedProtocol.hs +++ b/hydra-node/src/Hydra/Network/Ouroboros/VersionedProtocol.hs @@ -4,6 +4,8 @@ import Hydra.Prelude import Codec.CBOR.Term qualified as CBOR import Data.Text qualified as T +import GHC.Natural (naturalFromInteger, naturalToInteger) +import GHC.Num (integerToInt) import Hydra.Network (Host (..)) import Hydra.Network.Message (HydraVersionedProtocolNumber (..)) import Network.TypedProtocol.Pipelined () @@ -15,10 +17,10 @@ hydraVersionedProtocolCodec :: CodecCBORTerm (String, Maybe Int) HydraVersionedP hydraVersionedProtocolCodec = CodecCBORTerm{encodeTerm, decodeTerm} where encodeTerm :: HydraVersionedProtocolNumber -> CBOR.Term - encodeTerm x = CBOR.TInt $ hydraVersionedProtocolNumber x + encodeTerm x = CBOR.TInt $ integerToInt . naturalToInteger $ hydraVersionedProtocolNumber x decodeTerm :: CBOR.Term -> Either (String, Maybe Int) HydraVersionedProtocolNumber - decodeTerm (CBOR.TInt x) = Right $ MkHydraVersionedProtocolNumber x + decodeTerm (CBOR.TInt x) = Right $ MkHydraVersionedProtocolNumber (naturalFromInteger (toInteger x)) decodeTerm _ = Left ("unknown tag", Nothing) type HydraVersionedProtocolData :: Type