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

Observer API backend #18

Merged
merged 37 commits into from
Feb 5, 2025
Merged

Observer API backend #18

merged 37 commits into from
Feb 5, 2025

Conversation

ch1bo
Copy link
Member

@ch1bo ch1bo commented Jan 31, 2025

Allows for multiple hydra-chain-observer instances to report into one hydra-explorer:

flowchart LR

  subgraph hydra 0.19.0
    plutus-19[hydra-plutus]
    tx-19[hydra-tx]
    node-19[hydra-node]
    observer-19-preview[hydra-chain-observer 0.19.0]
    plutus-19 --> tx-19
    tx-19 --> observer-19-preview
    tx-19 --> node-19
    node-19 --> observer-19-preview
  end
  preview -. chain sync .-> observer-19-preview

  subgraph hydra 0.20.0
    plutus-20[hydra-plutus]
    tx-20[hydra-tx]
    node-20[hydra-node]
    observer-20[hydra-chain-observer 0.20.0]
    plutus-20 --> tx-20
    tx-20 --> observer-20
    tx-20 --> node-20
    node-20 --> observer-20
  end
  mainnet -. chain sync .-> observer-20

  observer-19[hydra-chain-observer 0.19.0]
  mainnet -. chain sync .-> observer-19

  subgraph hydra-explorer 1.0.0
    explorer[hydra-explorer]
    explorer -. GET /heads .-> hydra-explorer-web
  end

  observer-19-preview -. POST /v1/observations/preview/19 .-> explorer
  observer-19 -. POST /v1/observations/mainnet/19 .-> explorer
  observer-20 -. POST /v1/observations/mainnet/20 .-> explorer
Loading
  • 📊 Adds an Observer REST API, next to the Client REST API. Re-organizing code to have both web servers running on different ports. See README with instructions on how to run it.
  • 📊 Adds NetworkId and HydraVersion to explorer state aggregation. The aggregation is quite conservative and does not update head state even though potential observations would tell different. This is how the aggregation works currently (we might want to change policy). Anyhow, added property tests to ensure this.

TODO:

  • /tick endpoint does not say which network the data is from. We should probably change it to a /networks endpoint or so into which we aggregate all observed networks with their latest slots and blocks? @ffakenz what do you think?

@ch1bo ch1bo force-pushed the observer-backend branch 5 times, most recently from 4f5507d to e3b9cda Compare January 31, 2025 20:30
Note that there is a lot of code that can be DRYed and the aggregation
is generally very conservative, not updating data if matching heads are
found even in presence of potentially different observation data.

Added property tests for network and version not being updated to make
that clear.
-- into a hydra-chain package with smaller dependency footprint.
import Hydra.Chain (OnChainTx (..))

-- XXX: Need to depend on hydra-tx:testlib for generators?
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@locallycompact You moved the generators into a testlib component. What is your opinion here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be deriving anyclass Generic

At the moment I don't mind anything. All options feel wrong for one reason or another, but given that two of the major dependencies of hydra both use hedgehog (cardano-ledger and cardano-api), it feels like the path of least resistance to just align there, switch to hedgehog and use named generators uniformly across all hydra projects in a sublibrary (either :gen or :testlib). Arbitrary classes, locally defined, feel great when everything is naturally generic, but when not it is inconsistent since we then need to rely on named generators.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant not to ask about Arbitrary vs named generators nor even QuickCheck vs hedgehog.

My question is rather.. why do generators need to be a :testlib? Doesn't it feel weird to depend on it from an application package?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sublibraries are just another kind of way that we have of selectively ignoring information. I think generators lend themselves well to being sublibraries since a) they typically have unique dependencies themselves distinct from the rest of the code, b) they are used generally only for testing, and noise otherwise when worrying about logic.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should engineer it such that we depend on a testlib from an application. We could never need to do that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So your suggestion is to move the Arbitrary ExplorerState instance (for which we need this import here) into yet another hydra-explorer:testlib component?

I see now why you brought up the hedgehog and moving away from Arbitrary classes, because moving things into a testlib here would be at odds with not wanting orphan instances (https://github.com/cardano-scaling/hydra/wiki/Coding-Standards#proposal-avoid-orphan-instances)

@ch1bo ch1bo requested a review from a team January 31, 2025 23:16
@ch1bo ch1bo marked this pull request as ready for review January 31, 2025 23:17
@noonio noonio linked an issue Feb 4, 2025 that may be closed by this pull request
4 tasks
@ch1bo ch1bo self-assigned this Feb 4, 2025
github-merge-queue bot pushed a commit to cardano-scaling/hydra that referenced this pull request Feb 4, 2025
Extends `hydra-chain-observer` to submit observations to a
`hydra-explorer` instance with the new observer API.

See
https://github.com/cardano-scaling/hydra-explorer/blob/observer-backend/README.md#architecture
for an architectural overview.

* 🔍 Adds `--explorer` option to `hydra-chain-observer` which submits
observations using HTTP. This uses the `OnChainTx` type, so there are
new roundtrip tests and golden files.
* 🔍 Make `hydra-chain-observer` aware of its `--version` (also via
embedding git revs using nix).
* 🔍 Switch on `--node-socket` or `--blockfrost-project-path` in
`hydra-chain-observer` instead of subcommands. This allows us to re-use
more code and the help text becomes easier to understand. See
hydra-chain-observer/README.md for how to invoke the binary now.

* 🔍 Extracts a `common.yaml` from API definitions so we can
reference it from `hydra-explorer` API specs / schemas
* 🔍 Moves observation code from `hydra-node` to `hydra-tx`, this
improves dependency closure for `hydra-explorer`, especially once we
move `Hydra.Chain` out of `hydra-node` (e.g. by inverting the dependency
of `hydra-chain-observer`?)
  - This requires
* Adds orphan instances to `hydra-cardano-api` as needed by the
`hydra-explorer`, see
cardano-scaling/hydra-explorer#18

TODO:
- [x] Client-side serialization tests against observer openapi

---

* [x] CHANGELOG updated
* [x] Documentation updated (README, no user guide)
* [x] Haddocks updated
* [x] No new TODOs
@ch1bo ch1bo force-pushed the observer-backend branch 3 times, most recently from 99e0e6d to edf490e Compare February 4, 2025 20:14
ch1bo added 3 commits February 4, 2025 21:31
This was always including a tick from preview, but we might not be
observing preview at all.
@ch1bo ch1bo merged commit 8ee0b5f into master Feb 5, 2025
1 check passed
@ch1bo ch1bo deleted the observer-backend branch February 5, 2025 12:10
@ffakenz ffakenz mentioned this pull request Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Hydra explorer supporting multiple hydra versions
3 participants