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

Add hydra as a source #823

Open
wants to merge 62 commits into
base: main
Choose a base branch
from

Conversation

paweljakubas
Copy link

@paweljakubas paweljakubas commented Oct 8, 2024

The PR adds hydra as a source talking through websocket opened as hydra side.
The core of the solution is pinned around:

pub struct HydraMessage {
    pub seq: u64,
    pub head_id: Option<Vec<u8>>,
    pub payload: HydraMessagePayload,
    pub raw_json: Value,
}

pub enum HydraMessagePayload {
    #[serde(deserialize_with = "deserialize_tx_valid")]
    TxValid { tx: Vec<u8> },

    #[serde(other)]
    Other,
}

As a result of Hydra websocket communication hydra source offers :
(a) sequence number which orders communication msgs
(b) optional hydra tail id (optional as it is established only when all parties commit)
(c) payload which determines if a given msg is either valid tx (here cbor is extracted) or of other sort (fanning out, commiting, ..etc)
(d) raw json in case consumer wants to get more than is extracted in (c)

Intersection support if added. If one wants to consume from a given slot onwards the older msg are filtered out for the consumer.

In order to test the solution the following tests were added.

  1. Deserialisation tests
  2. Integration tests were hydra websocket communication was captured during two sessions of interaction. In Scenario_1 three participants opened the hydra head made 1 tx before fannout. In Scenario_2 three participants opened the hydra head made 3 txs before fannout. The sessions communication was dumped into files and then used in integration testing. In essence, to avoid attaching hydra node with all its cli challenges , mock hydra node (aka hydra emulation) was added.
  3. Intersection integration tests

@paweljakubas paweljakubas marked this pull request as draft October 8, 2024 14:02
@paweljakubas paweljakubas changed the title Test framework skeleton Add hydra as a source Oct 8, 2024
Anviking and others added 5 commits October 9, 2024 15:57
- use tokio-tungstenite to communicate with hydra node
- deserialize some messages and pass data to oura

To run, first start the hydra demo:

```bash
cd hydra/demo
./prepare-devnet.sh
docker compose up -d cardano-node
./seed-devnet.sh
docker compose up -d hydra-node-{1,2,3}
```

Then, in this repositroy, run:

```bash
cargo run daemon --config examples/hydra/daemon.toml
```
@scarmuega
Copy link
Member

this is looking really good! 🚀

Anviking and others added 17 commits October 15, 2024 18:23
This allows us to resume processing from a point specified in the
config.

Tested manually using the following steps:

1. Ensure hydra demo is running
2. `cargo run daemon --config examples/hydra/daemon.toml`
3. Read the `seq` and `head_id` of the last message printed
4. Set the following in `hydra/daemon.toml`:

```
[intersect]
type = "Point"
value = [
  7,
  "84e657e3dd5241caac75b749195f78684023583736cc08b2896290ab"
  ]
```

but with `7` and `84e657e3dd5241caac75b749195f78684023583736cc08b2896290ab`
being the actually observed `seq` and `head_id` values.

5. Restart `oura`
6. Observe that `oura` ignores all previously processed messages
Add basic intersect logic to hydra source
With this we see output from oura like:

```json
{"event":"apply","point":{"hash":"0000000000000000000000000000000000000000000000000000000000000000","slot":1},"record":{"peer":"2","seq":1,"tag":"PeerConnected","timestamp":"2024-10-15T11:48:00.516366926Z"}}
```
Forward all `raw_json` of hydra messages
I believe the `skip_deserializing` turn messages of these types into the `Other` payload anyway, so having them here is confusing.
Drop unneeded `Optional` from `payload` field
scratchpad
tests/hydra/logs.txt

Choose a reason for hiding this comment

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

Suggested change
tests/hydra/logs.txt

Comment on lines 115 to 119
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Snapshot {
number: u64,
confirmed_transaction_ids: Vec<String>,
}

Choose a reason for hiding this comment

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

Suggested change
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Snapshot {
number: u64,
confirmed_transaction_ids: Vec<String>,
}

This is currently unused


#[derive(Deserialize)]
pub struct Config {
pub hydra_socket_url: String,

Choose a reason for hiding this comment

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

Probably this is more correct:

Suggested change
pub hydra_socket_url: String,
pub hydra_socket_path: String,

@paweljakubas paweljakubas marked this pull request as ready for review November 19, 2024 10:43
@paweljakubas
Copy link
Author

hi @scarmuega ready for the review! cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants