Skip to content

Commit

Permalink
Add HeadId to "Greetings" message (#1622)
Browse files Browse the repository at this point in the history
<!-- 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
  • Loading branch information
ffakenz authored Sep 12, 2024
1 parent beeb63e commit 7d9499c
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 102 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ changes.
- Conway formatted transactions can be submitted to the `hydra-node`, while past eras are still supported (except deprecated features like protocol updates).
- This includes support for `PlutusV3` scripts, but most of the governance-related features have no meaning in the Hydra L2.

- Added head id information into the Greetings message.

- Adds a manual recipient address entry to `hydra-tui` and fixes event handling. [#1607](https://github.com/cardano-scaling/hydra/pull/1607)

## [0.18.1] - 2024-08-15
Expand Down
114 changes: 57 additions & 57 deletions hydra-node/golden/ReasonablySized (ServerOutput (Tx ConwayEra)).json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions hydra-node/json-schemas/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,8 @@ components:
$ref: "api.yaml#/components/schemas/Party"
headStatus:
$ref: "api.yaml#/components/schemas/HeadStatus"
hydraHeadId:
$ref: "api.yaml#/components/schemas/HeadId"
snapshotUtxo:
$ref: "api.yaml#/components/schemas/UTxO"
timestamp:
Expand Down
2 changes: 1 addition & 1 deletion hydra-node/src/Hydra/API/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ withAPIServer config party persistence tracer chain pparams callback action =
. simpleCors
$ websocketsOr
defaultConnectionOptions
(wsApp party tracer history callback headStatusP snapshotUtxoP responseChannel)
(wsApp party tracer history callback headStatusP headIdP snapshotUtxoP responseChannel)
(httpApp tracer chain pparams (atomically $ getLatest headIdP) (atomically $ getLatest snapshotUtxoP) callback)
)
( do
Expand Down
11 changes: 9 additions & 2 deletions hydra-node/src/Hydra/API/ServerOutput.hs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,13 @@ data ServerOutput tx
-- node. Currently used for knowing what signing key the server uses (it
-- only knows one), 'HeadStatus' and optionally (if 'HeadIsOpen' or
-- 'SnapshotConfirmed' message is emitted) UTxO's present in the Hydra Head.
Greetings {me :: Party, headStatus :: HeadStatus, snapshotUtxo :: Maybe (UTxOType tx), hydraNodeVersion :: String}
Greetings
{ me :: Party
, headStatus :: HeadStatus
, hydraHeadId :: Maybe HeadId
, snapshotUtxo :: Maybe (UTxOType tx)
, hydraNodeVersion :: String
}
| PostTxOnChainFailed {postChainTx :: PostChainTx tx, postTxError :: PostTxError tx}
| IgnoredHeadInitializing
{ headId :: HeadId
Expand Down Expand Up @@ -175,10 +181,11 @@ instance (ArbitraryIsTx tx, IsChainState tx) => Arbitrary (ServerOutput tx) wher
SnapshotConfirmed headId s ms -> SnapshotConfirmed <$> shrink headId <*> shrink s <*> shrink ms
GetUTxOResponse headId u -> GetUTxOResponse <$> shrink headId <*> shrink u
InvalidInput r i -> InvalidInput <$> shrink r <*> shrink i
Greetings me headStatus snapshotUtxo hydraNodeVersion ->
Greetings me headStatus hydraHeadId snapshotUtxo hydraNodeVersion ->
Greetings
<$> shrink me
<*> shrink headStatus
<*> shrink hydraHeadId
<*> shrink snapshotUtxo
<*> shrink hydraNodeVersion
PostTxOnChainFailed p e -> PostTxOnChainFailed <$> shrink p <*> shrink e
Expand Down
10 changes: 8 additions & 2 deletions hydra-node/src/Hydra/API/WSServer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Hydra.API.ClientInput (ClientInput)
import Hydra.API.Projection (Projection (..))
import Hydra.API.ServerOutput (
HeadStatus,
ServerOutput (Greetings, InvalidInput, hydraNodeVersion),
ServerOutput (Greetings, InvalidInput, hydraHeadId, hydraNodeVersion),
ServerOutputConfig (..),
TimedServerOutput (..),
WithUTxO (..),
Expand All @@ -31,6 +31,7 @@ import Hydra.Chain.Direct.State ()
import Hydra.Logging (Tracer, traceWith)
import Hydra.Options qualified as Options
import Hydra.Tx (Party, UTxOType)
import Hydra.Tx.HeadId (HeadId (..))
import Network.WebSockets (
PendingConnection (pendingRequest),
RequestHead (..),
Expand All @@ -52,12 +53,14 @@ wsApp ::
(ClientInput tx -> IO ()) ->
-- | Read model to enhance 'Greetings' messages with 'HeadStatus'.
Projection STM.STM (ServerOutput tx) HeadStatus ->
-- | Read model to enhance 'Greetings' messages with 'HeadId'.
Projection STM.STM (ServerOutput tx) (Maybe HeadId) ->
-- | Read model to enhance 'Greetings' messages with snapshot UTxO.
Projection STM.STM (ServerOutput tx) (Maybe (UTxOType tx)) ->
TChan (TimedServerOutput tx) ->
PendingConnection ->
IO ()
wsApp party tracer history callback headStatusP snapshotUtxoP responseChannel pending = do
wsApp party tracer history callback headStatusP headIdP snapshotUtxoP responseChannel pending = do
traceWith tracer NewAPIConnection
let path = requestPath $ pendingRequest pending
queryParams <- uriQuery <$> mkURIBs path
Expand All @@ -81,6 +84,7 @@ wsApp party tracer history callback headStatusP snapshotUtxoP responseChannel pe
forwardGreetingOnly con = do
seq <- atomically $ nextSequenceNumber history
headStatus <- atomically getLatestHeadStatus
hydraHeadId <- atomically getLatestHeadId
snapshotUtxo <- atomically getLatestSnapshotUtxo
time <- getCurrentTime

Expand All @@ -93,13 +97,15 @@ wsApp party tracer history callback headStatusP snapshotUtxoP responseChannel pe
Greetings
{ me = party
, headStatus
, hydraHeadId
, snapshotUtxo
, hydraNodeVersion = showVersion Options.hydraNodeVersion
} ::
ServerOutput tx
}

Projection{getLatest = getLatestHeadStatus} = headStatusP
Projection{getLatest = getLatestHeadId} = headIdP
Projection{getLatest = getLatestSnapshotUtxo} = snapshotUtxoP

mkServerOutputConfig qp =
Expand Down

0 comments on commit 7d9499c

Please sign in to comment.