Skip to content

Commit 7d9499c

Browse files
authored
Add HeadId to "Greetings" message (#1622)
<!-- Describe your change here --> Closes #1557 --- <!-- 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 beeb63e commit 7d9499c

File tree

7 files changed

+119
-102
lines changed

7 files changed

+119
-102
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ changes.
1414
- Conway formatted transactions can be submitted to the `hydra-node`, while past eras are still supported (except deprecated features like protocol updates).
1515
- This includes support for `PlutusV3` scripts, but most of the governance-related features have no meaning in the Hydra L2.
1616

17+
- Added head id information into the Greetings message.
18+
1719
- Adds a manual recipient address entry to `hydra-tui` and fixes event handling. [#1607](https://github.com/cardano-scaling/hydra/pull/1607)
1820

1921
## [0.18.1] - 2024-08-15

hydra-node/golden/ReasonablySized (ServerOutput (Tx ConwayEra)).json

Lines changed: 57 additions & 57 deletions
Large diffs are not rendered by default.

hydra-node/golden/ReasonablySized (TimedServerOutput (Tx ConwayEra)).json

Lines changed: 40 additions & 40 deletions
Large diffs are not rendered by default.

hydra-node/json-schemas/api.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,8 @@ components:
624624
$ref: "api.yaml#/components/schemas/Party"
625625
headStatus:
626626
$ref: "api.yaml#/components/schemas/HeadStatus"
627+
hydraHeadId:
628+
$ref: "api.yaml#/components/schemas/HeadId"
627629
snapshotUtxo:
628630
$ref: "api.yaml#/components/schemas/UTxO"
629631
timestamp:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ withAPIServer config party persistence tracer chain pparams callback action =
106106
. simpleCors
107107
$ websocketsOr
108108
defaultConnectionOptions
109-
(wsApp party tracer history callback headStatusP snapshotUtxoP responseChannel)
109+
(wsApp party tracer history callback headStatusP headIdP snapshotUtxoP responseChannel)
110110
(httpApp tracer chain pparams (atomically $ getLatest headIdP) (atomically $ getLatest snapshotUtxoP) callback)
111111
)
112112
( do

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,13 @@ data ServerOutput tx
120120
-- node. Currently used for knowing what signing key the server uses (it
121121
-- only knows one), 'HeadStatus' and optionally (if 'HeadIsOpen' or
122122
-- 'SnapshotConfirmed' message is emitted) UTxO's present in the Hydra Head.
123-
Greetings {me :: Party, headStatus :: HeadStatus, snapshotUtxo :: Maybe (UTxOType tx), hydraNodeVersion :: String}
123+
Greetings
124+
{ me :: Party
125+
, headStatus :: HeadStatus
126+
, hydraHeadId :: Maybe HeadId
127+
, snapshotUtxo :: Maybe (UTxOType tx)
128+
, hydraNodeVersion :: String
129+
}
124130
| PostTxOnChainFailed {postChainTx :: PostChainTx tx, postTxError :: PostTxError tx}
125131
| IgnoredHeadInitializing
126132
{ headId :: HeadId
@@ -175,10 +181,11 @@ instance (ArbitraryIsTx tx, IsChainState tx) => Arbitrary (ServerOutput tx) wher
175181
SnapshotConfirmed headId s ms -> SnapshotConfirmed <$> shrink headId <*> shrink s <*> shrink ms
176182
GetUTxOResponse headId u -> GetUTxOResponse <$> shrink headId <*> shrink u
177183
InvalidInput r i -> InvalidInput <$> shrink r <*> shrink i
178-
Greetings me headStatus snapshotUtxo hydraNodeVersion ->
184+
Greetings me headStatus hydraHeadId snapshotUtxo hydraNodeVersion ->
179185
Greetings
180186
<$> shrink me
181187
<*> shrink headStatus
188+
<*> shrink hydraHeadId
182189
<*> shrink snapshotUtxo
183190
<*> shrink hydraNodeVersion
184191
PostTxOnChainFailed p e -> PostTxOnChainFailed <$> shrink p <*> shrink e

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import Hydra.API.ClientInput (ClientInput)
1515
import Hydra.API.Projection (Projection (..))
1616
import Hydra.API.ServerOutput (
1717
HeadStatus,
18-
ServerOutput (Greetings, InvalidInput, hydraNodeVersion),
18+
ServerOutput (Greetings, InvalidInput, hydraHeadId, hydraNodeVersion),
1919
ServerOutputConfig (..),
2020
TimedServerOutput (..),
2121
WithUTxO (..),
@@ -31,6 +31,7 @@ import Hydra.Chain.Direct.State ()
3131
import Hydra.Logging (Tracer, traceWith)
3232
import Hydra.Options qualified as Options
3333
import Hydra.Tx (Party, UTxOType)
34+
import Hydra.Tx.HeadId (HeadId (..))
3435
import Network.WebSockets (
3536
PendingConnection (pendingRequest),
3637
RequestHead (..),
@@ -52,12 +53,14 @@ wsApp ::
5253
(ClientInput tx -> IO ()) ->
5354
-- | Read model to enhance 'Greetings' messages with 'HeadStatus'.
5455
Projection STM.STM (ServerOutput tx) HeadStatus ->
56+
-- | Read model to enhance 'Greetings' messages with 'HeadId'.
57+
Projection STM.STM (ServerOutput tx) (Maybe HeadId) ->
5558
-- | Read model to enhance 'Greetings' messages with snapshot UTxO.
5659
Projection STM.STM (ServerOutput tx) (Maybe (UTxOType tx)) ->
5760
TChan (TimedServerOutput tx) ->
5861
PendingConnection ->
5962
IO ()
60-
wsApp party tracer history callback headStatusP snapshotUtxoP responseChannel pending = do
63+
wsApp party tracer history callback headStatusP headIdP snapshotUtxoP responseChannel pending = do
6164
traceWith tracer NewAPIConnection
6265
let path = requestPath $ pendingRequest pending
6366
queryParams <- uriQuery <$> mkURIBs path
@@ -81,6 +84,7 @@ wsApp party tracer history callback headStatusP snapshotUtxoP responseChannel pe
8184
forwardGreetingOnly con = do
8285
seq <- atomically $ nextSequenceNumber history
8386
headStatus <- atomically getLatestHeadStatus
87+
hydraHeadId <- atomically getLatestHeadId
8488
snapshotUtxo <- atomically getLatestSnapshotUtxo
8589
time <- getCurrentTime
8690

@@ -93,13 +97,15 @@ wsApp party tracer history callback headStatusP snapshotUtxoP responseChannel pe
9397
Greetings
9498
{ me = party
9599
, headStatus
100+
, hydraHeadId
96101
, snapshotUtxo
97102
, hydraNodeVersion = showVersion Options.hydraNodeVersion
98103
} ::
99104
ServerOutput tx
100105
}
101106

102107
Projection{getLatest = getLatestHeadStatus} = headStatusP
108+
Projection{getLatest = getLatestHeadId} = headIdP
103109
Projection{getLatest = getLatestSnapshotUtxo} = snapshotUtxoP
104110

105111
mkServerOutputConfig qp =

0 commit comments

Comments
 (0)