Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow API client to control the server output #380

Closed
2 tasks done
ghost opened this issue Jun 2, 2022 · 7 comments · Fixed by #794
Closed
2 tasks done

Allow API client to control the server output #380

ghost opened this issue Jun 2, 2022 · 7 comments · Fixed by #794
Labels
green 💚 Low complexity or well understood feature 💬 feature A feature on our roadmap
Milestone

Comments

@ghost
Copy link

ghost commented Jun 2, 2022

Why

Clients might have different requirements about the data they want from our API Server:

  • Some might not want to be fed the history of previous messages when they connect
  • Some might want to send/receive transactions in JSON or CBOR

What

  • Provide a way for the client to specify what kind of output they want to see when they connect to API Server
  • Server configures the connection according to the options.
  • Client can control:
    • Configurable transaction format
    • Configurable latching of history

How

We will use websocket path to decide on these two items:

  • If a path contains QueryParam history and it's value is 1 then the server will serve complete history
  • If a path contains QueryParam tx-output and it's value is cbor then the tx should be displayed as cbor

Example: ?history=0&tx-output=cbor

Related issues:

@ghost ghost added the 💭 idea An idea or feature request label Jun 2, 2022
@ch1bo ch1bo added 💬 feature A feature on our roadmap amber ⚠️ Medium complexity or partly unclear feature feedback needed and removed 💭 idea An idea or feature request labels Jun 7, 2022
@ch1bo ch1bo moved this to Later in Hydra Head Roadmap Jun 21, 2022
@ch1bo
Copy link
Collaborator

ch1bo commented Jun 28, 2022

Another idea by @KtorZ is to use the sub-protocol negotiation in the WebSocket standard.

@matiwinnetou
Copy link
Contributor

matiwinnetou commented Feb 22, 2023

+1, this is something that we are observing when building application build on Hydra and this would help.

We are trying to build something like hydra-java-client library and already at the beginning hitting issues described by @abailly-iohk .

Something like request message id and response message id with lack of history and protocol similar to what ogmios is using is something that we would like.

History could be optionally provided but client needs to be interested in this (somehow).

@v0d1ch v0d1ch self-assigned this Mar 9, 2023
@v0d1ch
Copy link
Contributor

v0d1ch commented Mar 15, 2023

I took a look at related code and these are my findings:

  • We can utilize either websocket subprotocols (or path) to make a decision on the api server level what content should we serve
  • It is not that easy to pick appropriate json instance we want to serve
  • There is a simple monkey-patch solution where we could just overwrite the fields we want in already prepared json
  • For replaying of history the easiest would be to introduce a new argument to hydra-node that signals this

So overall I would say the work is pretty easy if we go with the simple solution which is not really ideal but can work.
A proper solution can turn out to be a bit of a rabbit hole because of how things are setup in code (IsTx and friends) and one can spend a lot of time golfing with the types but that might lead to better situation in our code.

Personally I would do a dirty solution to have something working and then improve later.

cc @ch1bo

@ch1bo
Copy link
Collaborator

ch1bo commented Mar 16, 2023

For replaying of history the easiest would be to introduce a new argument to hydra-node that signals this

Not sure if this is an option. I can imagine that some clients of the hydra-node do require the history to work (e.g. hydra-tui) while others don't want it. So IMO it must be per client / connection configurable.

Maybe optional query parameters on the websocket path could work? For example, wss://host:port/?history=0&tx-output=cbor could be interpreted as a websocket which does not send the history and output transactions as CBOR.

@ch1bo ch1bo added 💭 idea An idea or feature request and removed 💬 feature A feature on our roadmap labels Mar 16, 2023
@v0d1ch
Copy link
Contributor

v0d1ch commented Mar 16, 2023

We are loading the history before running the server and then we share the TChan for reading/writing https://github.com/input-output-hk/hydra/blob/master/hydra-node/src/Hydra/API/Server.hs#L79
I'll work on a solution to make the path decide what we want to serve from the api.

@ch1bo
Copy link
Collaborator

ch1bo commented Mar 16, 2023

@v0d1ch Yeah that's no problem. We need to store/load the history nontheless (in case one client requests it). We only need to make the forwardHistory optional.

@v0d1ch
Copy link
Contributor

v0d1ch commented Mar 16, 2023

Ok since things have changed from the time this idea was created I am keeping the old wording here just as a reference and I'll update the original to be inline with the actual changes I plan on doing.

## Why

Clients might have different requirements about the data they want from our API Server:
* Some might not want to be fed the history of previous messages when they connect
* Some might want to send/receive transactions in JSON or CBOR

## What

* Provide a _negotiation phase_ when a client connect to API Server
* Server sends `Greeting` message as before, possibly with a version
* Client sends a `Greeting` message with options set
* Server configures the connection according to the options.
* _(optional)_: Server sends _Available options_ in its initial `Greeting` message
* Then, we want to use this negotiation mechanism in the two example configurations we encountered so far:
  + Configurable transaction format
  + Configurable latching of history

## How

- [ ] Create a negotiation mechanism
- [ ] #371
- [ ] #379 

@v0d1ch v0d1ch changed the title Allow API client and server to negotiate features Allow API client to control the server output Mar 16, 2023
@ch1bo ch1bo added 💬 feature A feature on our roadmap and removed 💭 idea An idea or feature request feedback needed labels Mar 21, 2023
@ch1bo ch1bo added this to the 0.10.0 milestone Mar 21, 2023
@ch1bo ch1bo added green 💚 Low complexity or well understood feature and removed amber ⚠️ Medium complexity or partly unclear feature labels Mar 21, 2023
@ch1bo ch1bo moved this from Later to Now in Hydra Head Roadmap Mar 22, 2023
@github-project-automation github-project-automation bot moved this from Now to Done in Hydra Head Roadmap Apr 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
green 💚 Low complexity or well understood feature 💬 feature A feature on our roadmap
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants