Skip to content

Commit

Permalink
Add PeerHandshakeFailure to ServerOutput
Browse files Browse the repository at this point in the history
  • Loading branch information
locallycompact committed Apr 29, 2024
1 parent 1ea5d34 commit 7018e2a
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 22 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ changes.

- `hydra-node` logs will now report `NetworkEvents` to distinguish between `ConnectivityEvent`s and `ReceivedMessage`s on the network.

- Hydra now uses a versioned protocol for handshaking. In the event of a node
attempting to connect using a different version of the networking protocol, a
`HandshakeFailure` event will be recorded in the logs.

## [0.17.0] - UNRELEASED

- **BREAKING** `hydra-node` `/commit` enpoint now also accepts a _blueprint/draft_
Expand Down
48 changes: 48 additions & 0 deletions hydra-node/json-schemas/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ channels:
- $ref: "api.yaml#/components/messages/Greetings"
- $ref: "api.yaml#/components/messages/PeerConnected"
- $ref: "api.yaml#/components/messages/PeerDisconnected"
- $ref: "api.yaml#/components/messages/PeerHandshakeFailure"
- $ref: "api.yaml#/components/messages/HeadIsInitializing"
- $ref: "api.yaml#/components/messages/Committed"
- $ref: "api.yaml#/components/messages/HeadIsOpen"
Expand Down Expand Up @@ -333,6 +334,13 @@ components:
payload:
$ref: "api.yaml#/components/schemas/PeerDisconnected"

PeerHandshakeFailure:
title: PeerHandshakeFailure
description: |
A peer has failed to negotiate a protocol.
payload:
$ref: "api.yaml#/components/schemas/PeerHandshakeFailure"

HeadIsInitializing:
title: HeadIsInitializing
description: |
Expand Down Expand Up @@ -494,6 +502,7 @@ components:
- $ref: "api.yaml#/components/schemas/Greetings"
- $ref: "api.yaml#/components/schemas/PeerConnected"
- $ref: "api.yaml#/components/schemas/PeerDisconnected"
- $ref: "api.yaml#/components/schemas/PeerHandshakeFailure"
- $ref: "api.yaml#/components/schemas/HeadIsInitializing"
- $ref: "api.yaml#/components/schemas/Committed"
- $ref: "api.yaml#/components/schemas/HeadIsOpen"
Expand Down Expand Up @@ -571,6 +580,25 @@ components:
timestamp:
$ref: "api.yaml#/components/schemas/UTCTime"

PeerHandshakeFailure:
type: object
required:
- tag
- host
- seq
- timestamp
properties:
tag:
type: string
enum: ["PeerHandshakeFailure"]
host:
type: object
$ref: "api.yaml#/components/schemas/IP"
seq:
$ref: "api.yaml#/components/schemas/SequenceNumber"
timestamp:
$ref: "api.yaml#/components/schemas/UTCTime"

HeadIsInitializing:
type: object
required:
Expand Down Expand Up @@ -1976,3 +2004,23 @@ components:

# NOTE: We don't want anyone to depend on this!
ChainState: {}

IP:
type: object
oneOf:
- title: IPv4
type: object
properties:
tag:
type: string
enum: ["IPv4"]
ipv4:
type: string
- title: IPv6
type: string
properties:
tag:
type: string
enum: ["IPv6"]
ipv6:
type: string
38 changes: 16 additions & 22 deletions hydra-node/json-schemas/logs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1645,6 +1645,20 @@ definitions:
nodeId:
type: string

- title: HandshakeFailure
type: object
additionalProperties: false
required:
- tag
- host
properties:
tag:
type: string
enum: ["HandshakeFailure"]
host:
type: object
$ref: "api.yaml#/components/schemas/IP"

- title: ReceivedMessage
type: object
additionalProperties: false
Expand Down Expand Up @@ -2110,26 +2124,6 @@ definitions:
items:
$ref: "api.yaml#/components/schemas/TxId"

IP:
type: object
oneOf:
- title: IPv4
type: object
properties:
tag:
type: string
enum: ["IPv4"]
ipv4:
type: string
- title: IPv6
type: string
properties:
tag:
type: string
enum: ["IPv6"]
ipv6:
type: string

RunOptions:
type: object
required:
Expand Down Expand Up @@ -2164,15 +2158,15 @@ definitions:
type: string
host:
type: object
$ref: "logs.yaml#/definitions/IP"
$ref: "api.yaml#/components/schemas/IP"
port:
type: integer
peers:
type: array
items:
$ref: "api.yaml#/components/schemas/Peer"
apiHost:
$ref: "logs.yaml#/definitions/IP"
$ref: "api.yaml#/components/schemas/IP"
apiPort:
type: integer
monitoringPort:
Expand Down
4 changes: 4 additions & 0 deletions hydra-node/src/Hydra/API/ServerOutput.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import Hydra.HeadId (HeadId)
import Hydra.HeadLogic.State (HeadState)
import Hydra.Ledger (IsTx, UTxOType, ValidationError)
import Hydra.Network (NodeId)
import Hydra.Network.Ouroboros (Host)
import Hydra.OnChainId (OnChainId)
import Hydra.Party (Party)
import Hydra.Prelude hiding (seq)
Expand Down Expand Up @@ -53,6 +54,7 @@ instance IsChainState tx => FromJSON (TimedServerOutput tx) where
data ServerOutput tx
= PeerConnected {peer :: NodeId}
| PeerDisconnected {peer :: NodeId}
| PeerHandshakeFailure {host :: Host}
| HeadIsInitializing {headId :: HeadId, parties :: [Party]}
| Committed {headId :: HeadId, party :: Party, utxo :: UTxOType tx}
| HeadIsOpen {headId :: HeadId, utxo :: UTxOType tx}
Expand Down Expand Up @@ -129,6 +131,7 @@ instance
shrink = \case
PeerConnected p -> PeerConnected <$> shrink p
PeerDisconnected p -> PeerDisconnected <$> shrink p
PeerHandshakeFailure p -> PeerHandshakeFailure <$> shrink p
HeadIsInitializing headId xs -> HeadIsInitializing <$> shrink headId <*> shrink xs
Committed headId p u -> Committed <$> shrink headId <*> shrink p <*> shrink u
HeadIsOpen headId u -> HeadIsOpen <$> shrink headId <*> shrink u
Expand Down Expand Up @@ -178,6 +181,7 @@ prepareServerOutput ServerOutputConfig{utxoInSnapshot} response =
case output response of
PeerConnected{} -> encodedResponse
PeerDisconnected{} -> encodedResponse
PeerHandshakeFailure{} -> encodedResponse
HeadIsInitializing{} -> encodedResponse
Committed{} -> encodedResponse
HeadIsOpen{} -> encodedResponse
Expand Down
2 changes: 2 additions & 0 deletions hydra-node/src/Hydra/HeadLogic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ onConnectionEvent = \case
causes [ClientEffect (ServerOutput.PeerConnected nodeId)]
Disconnected{nodeId} ->
causes [ClientEffect (ServerOutput.PeerDisconnected nodeId)]
HandshakeFailure{host} ->
causes [ClientEffect (ServerOutput.PeerHandshakeFailure host)]

-- * The Coordinated Head protocol

Expand Down
2 changes: 2 additions & 0 deletions hydra-node/src/Hydra/Network/Message.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Cardano.Crypto.Util (SignableRepresentation, getSignableRepresentation)
import Hydra.Crypto (Signature)
import Hydra.Ledger (IsTx (TxIdType), UTxOType)
import Hydra.Network (NodeId)
import Hydra.Network.Ouroboros (Host)
import Hydra.Party (Party)
import Hydra.Snapshot (Snapshot, SnapshotNumber)

Expand All @@ -24,6 +25,7 @@ instance Arbitrary msg => Arbitrary (NetworkEvent msg) where
data Connectivity
= Connected {nodeId :: NodeId}
| Disconnected {nodeId :: NodeId}
| HandshakeFailure {host :: Host}
deriving stock (Generic, Eq, Show)
deriving anyclass (ToJSON, FromJSON)

Expand Down

0 comments on commit 7018e2a

Please sign in to comment.