Skip to content

Commit 4d7f5f0

Browse files
authored
tui displays node peers from environment (#2087)
<!-- Describe your change here --> Closes #2044 By including the Environment of the running hydra-node in the Greetings message, clients can now use this information to display the expected peers the node should be connected with. --- <!-- Consider each and tick it off one way or the other --> * [x] CHANGELOG updated or not needed * [x] Documentation updated or not needed * [x] Haddocks updated or not needed * [x] No new TODOs introduced or explained herafter
1 parent 4dc738d commit 4d7f5f0

File tree

16 files changed

+155
-448
lines changed

16 files changed

+155
-448
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ changes.
1212

1313
- Hydra API server responds with the correct `Content-Type` header `application-json`.
1414

15+
- Add `Environment` to `Greetings` message, enabling clients to access runtime settings.
16+
1517
## [0.22.2] - 2025.06.30
1618

1719
* Fix wrong hydra-script-tx-ids in networks.json
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"samples": [
3+
{
4+
"env": {
5+
"configuredPeers": "",
6+
"contestationPeriod": 43200,
7+
"depositPeriod": 61129,
8+
"otherParties": [],
9+
"participants": [
10+
"01000000000001000101000101010101000101000001000000010100"
11+
],
12+
"party": {
13+
"vkey": "35719d612496ce0f320cd39e4693a2997194cec954ec602064f67a5c81150136"
14+
},
15+
"signingKey": "c659b97ce8782bc64476a5e82a14cbd38d0413cb15b18fa87d281b44272fa476"
16+
},
17+
"headStatus": "Closed",
18+
"hydraHeadId": "01000001000001000000000001000101",
19+
"hydraNodeVersion": "",
20+
"me": {
21+
"vkey": "3d8fb298d77d2fda814e9530b5539758751d27ad1c234080e04ec2e15dea1490"
22+
},
23+
"tag": "Greetings"
24+
}
25+
],
26+
"seed": -307089451
27+
}

hydra-node/golden/ServerOutput/Greetings.json

Lines changed: 0 additions & 435 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"samples": [
3+
"3eadfbc424301d997974d754f31cab05549b401f23888912e5ef263010cd83ff",
4+
"fcec437392209b6cb455d1a498d4b637d1fd7813f39ad774e6080fbd603628fb",
5+
"2f6e6edcd13b4e697a13b1285ccc04e8b3768c9f251168333e3262fff21b4e87",
6+
"1e26d64fa949a34916a24673aa0a00bd8d98594ac122a14196ecd99965a32672",
7+
"fad6a4694d7ce44c9cae9ea0002d858e2a3eb12252161dff03580d6c5bfe7acf"
8+
],
9+
"seed": 504743142
10+
}

hydra-node/json-schemas/api.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,7 @@ components:
809809
- me
810810
- headStatus
811811
- hydraNodeVersion
812+
- env
812813
properties:
813814
tag:
814815
type: string
@@ -825,6 +826,8 @@ components:
825826
$ref: "api.yaml#/components/schemas/UTCTime"
826827
hydraNodeVersion:
827828
$ref: "api.yaml#/components/schemas/HydraNodeVersion"
829+
env:
830+
$ref: "api.yaml#/components/schemas/Environment"
828831

829832
# Client inputs
830833

@@ -2788,6 +2791,45 @@ components:
27882791
description: |
27892792
Current hydra-node version.
27902793
2794+
DepositPeriod:
2795+
type: number
2796+
description: |
2797+
A length of time, measured in whole seconds, to be used in deposit validity.
2798+
example: 60
2799+
2800+
Environment:
2801+
type: object
2802+
description: |
2803+
Running context derived from hydra-node run options.
2804+
required:
2805+
- party
2806+
- signingKey
2807+
- otherParties
2808+
- participants
2809+
- contestationPeriod
2810+
- depositPeriod
2811+
- configuredPeers
2812+
additionalProperties: false
2813+
properties:
2814+
party:
2815+
$ref: "api.yaml#/components/schemas/Party"
2816+
signingKey:
2817+
$ref: "api.yaml#/components/schemas/Signature"
2818+
otherParties:
2819+
type: array
2820+
items:
2821+
$ref: "api.yaml#/components/schemas/Party"
2822+
participants:
2823+
type: array
2824+
items:
2825+
$ref: "api.yaml#/components/schemas/OnChainId"
2826+
contestationPeriod:
2827+
$ref: "api.yaml#/components/schemas/ContestationPeriod"
2828+
depositPeriod:
2829+
$ref: "api.yaml#/components/schemas/DepositPeriod"
2830+
configuredPeers:
2831+
type: string
2832+
27912833
SequenceNumber:
27922834
type: integer
27932835
minimum: 0

hydra-node/src/Hydra/API/Server.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ withAPIServer config env party eventSource tracer chain pparams serverOutputFilt
125125
. simpleCors
126126
$ websocketsOr
127127
defaultConnectionOptions
128-
(wsApp party tracer historyTimedOutputs callback headStateP headIdP responseChannel serverOutputFilter)
128+
(wsApp env party tracer historyTimedOutputs callback headStateP headIdP responseChannel serverOutputFilter)
129129
( httpApp
130130
tracer
131131
chain

hydra-node/src/Hydra/API/ServerOutput.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import Hydra.HeadLogic.State (ClosedState (..), HeadState (..), InitialState (..
1616
import Hydra.HeadLogic.State qualified as HeadState
1717
import Hydra.Ledger (ValidationError)
1818
import Hydra.Network (Host, ProtocolVersion)
19+
import Hydra.Node.Environment (Environment (..))
1920
import Hydra.Prelude hiding (seq)
2021
import Hydra.Tx (HeadId, Party, Snapshot, SnapshotNumber, getSnapshot)
2122
import Hydra.Tx qualified as Tx
@@ -101,6 +102,7 @@ data Greetings tx = Greetings
101102
, hydraHeadId :: Maybe HeadId
102103
, snapshotUtxo :: Maybe (UTxOType tx)
103104
, hydraNodeVersion :: String
105+
, env :: Environment
104106
}
105107
deriving (Generic)
106108

@@ -126,6 +128,8 @@ instance IsChainState tx => FromJSON (Greetings tx) where
126128
instance ArbitraryIsTx tx => Arbitrary (Greetings tx) where
127129
arbitrary = genericArbitrary
128130

131+
instance (ArbitraryIsTx tx, IsChainState tx) => ToADTArbitrary (Greetings tx)
132+
129133
data InvalidInput = InvalidInput
130134
{ reason :: String
131135
, input :: Text

hydra-node/src/Hydra/API/WSServer.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import Hydra.HeadLogic (ClosedState (ClosedState, readyToFanoutSent), HeadState,
4444
import Hydra.HeadLogic.State qualified as HeadState
4545
import Hydra.Logging (Tracer, traceWith)
4646
import Hydra.NetworkVersions qualified as NetworkVersions
47+
import Hydra.Node.Environment (Environment (..))
4748
import Hydra.Tx (Party)
4849
import Hydra.Tx.HeadId (HeadId (..))
4950
import Network.WebSockets (
@@ -60,6 +61,7 @@ import Text.URI.QQ (queryKey, queryValue)
6061
wsApp ::
6162
forall tx.
6263
IsChainState tx =>
64+
Environment ->
6365
Party ->
6466
Tracer IO APIServerLog ->
6567
ConduitT () (TimedServerOutput tx) (ResourceT IO) () ->
@@ -72,7 +74,7 @@ wsApp ::
7274
ServerOutputFilter tx ->
7375
PendingConnection ->
7476
IO ()
75-
wsApp party tracer history callback headStateP headIdP responseChannel ServerOutputFilter{txContainsAddr} pending = do
77+
wsApp env party tracer history callback headStateP headIdP responseChannel ServerOutputFilter{txContainsAddr} pending = do
7678
traceWith tracer NewAPIConnection
7779
let path = requestPath $ pendingRequest pending
7880
queryParams <- uriQuery <$> mkURIBs path
@@ -105,6 +107,7 @@ wsApp party tracer history callback headStateP headIdP responseChannel ServerOut
105107
, hydraHeadId
106108
, snapshotUtxo = getSnapshotUtxo headState
107109
, hydraNodeVersion = showVersion NetworkVersions.hydraNodeVersion
110+
, env
108111
}
109112

110113
Projection{getLatest} = headStateP

hydra-node/src/Hydra/Node/Environment.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ data Environment = Environment
2424
-- ^ Configured peers for the network layer, used for comparison on etcd errors.
2525
}
2626
deriving stock (Generic, Show, Eq)
27+
deriving anyclass (ToJSON, FromJSON)
2728

2829
instance Arbitrary Environment where
2930
arbitrary = genericArbitrary

hydra-node/test/Hydra/API/ServerOutputSpec.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import Test.QuickCheck (conjoin, withMaxSuccess)
2020
spec :: Spec
2121
spec = parallel $ do
2222
roundtripAndGoldenADTSpecsWithSettings defaultSettings{sampleSize = 1} $ Proxy @(MinimumSized (ServerOutput Tx))
23+
roundtripAndGoldenADTSpecsWithSettings defaultSettings{sampleSize = 1} $ Proxy @(MinimumSized (Greetings Tx))
2324

2425
-- NOTE: Kupo and maybe other downstream projects use this file as a test vector.
2526
it "golden SnapshotConfirmed is good" $ do

0 commit comments

Comments
 (0)