Skip to content

Commit db3c59a

Browse files
committed
Add event sourcing docs to architecture section
1 parent a489156 commit db3c59a

File tree

5 files changed

+9
-5
lines changed

5 files changed

+9
-5
lines changed

docs/docs/dev/architecture/architecture-c4.puml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ title "Hydra Components"
55
AddElementTag("external", $bgColor="#23aa12")
66

77
Container_Boundary(hydra_node, "Hydra Node") {
8+
Component(events, "Events", "", "Event source and sink", $link="https://github.com/cardano-scaling/hydra/blob/master/hydra-node/src/Hydra/Events.hs")
89
Component(persistence, "Persistence", "JSON/FS", "Persists state of the head on disk", $link="https://github.com/cardano-scaling/hydra/blob/master/hydra-node/src/Hydra/Persistence.hs")
910
Component(head_logic, "Head Logic", "", "Maintains internal Head state and processes events", $link="https://github.com/cardano-scaling/hydra/blob/master/hydra-node/src/Hydra/HeadLogic.hs")
1011
Component(api_server, "API Server", "", "Handle client commands & queries and serves outputs", $link="https://github.com/cardano-scaling/hydra/blob/master/hydra-node/src/Hydra/API/Server.hs")
@@ -15,6 +16,7 @@ Container_Boundary(hydra_node, "Hydra Node") {
1516
Component(monitoring, "Monitoring", "", "Exposes Prometheus metrics", $link="https://github.com/cardano-scaling/hydra/blob/master/hydra-node/src/Hydra/Logging/Monitoring.hs")
1617
Component(ledger, "Cardano Ledger", "", "Maintains Layer 2 State", $tags="external")
1718

19+
Lay_U(head_logic, events)
1820
Lay_U(head_logic, persistence)
1921
Lay_U(head_logic, logging)
2022
Lay_U(head_logic, monitoring)

docs/docs/dev/event-source.md renamed to docs/docs/dev/architecture/event-sourcing.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
## Event sourcing
1+
# Event sourcing
22

33
The `hydra-node` is an event sourced application. This means that the main logic is processing _inputs_ (also called commands) and produces _events_. These events are saved and loaded to persist application state across restarts. Also, most events are transformed to _outputs_ and can be observed on the `hydra-node` API.
44

55
On application startup, the [`hydrate`](https://hydra.family/head-protocol/haddock/hydra-node/Hydra-Node.html#v:hydrate) function is called to load all events using a given [`EventSource`](https://hydra.family/head-protocol/haddock/hydra-node/Hydra-Events.html#t:EventSource) and while doing so, re-emits those events to all provided [`EventSink`](https://hydra.family/head-protocol/haddock/hydra-node/Hydra-Events.html#t:EventSink) instances. The resulting [`HydraNode`](https://hydra.family/head-protocol/haddock/hydra-node/Hydra-Node.html#t:HydraNode) will then enter the main loop of `hydra-node` and process inputs into state changes and effects via function [`stepHydraNode`](https://hydra.family/head-protocol/haddock/hydra-node/Hydra-Node.html#v:stepHydraNode). All state changes of a Hydra node are based on [`StateEvent`](https://hydra.family/head-protocol/haddock/hydra-node/Hydra-Events.html#t:StateEvent) values and consequently get emitted to all `eventSinks` of the `HydraNode` handle. Also, the `eventSource` of the same may be used later to to load events on-demand, for example to produce a history of server outputs.
66

7-
- TODO: explain `StateEvent` data type and `EventSource` / `EventSink` interfaces
8-
97
## Default event source and sinks
108

119
The default event source and sink used by the `hydra-node` is `FileBased`, which uses an append-only plain JSON file to persist events in a file name `state`. This single file is located in the `hydra-node` persistence directory, which is specified by the `--persistence-dir` command line option.

docs/docs/dev/architecture/hydra-components.svg

Lines changed: 1 addition & 1 deletion
Loading

docs/docs/dev/architecture/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ $ plantuml -Tsvg architecture-c4.puml
2121

2222
:::
2323

24+
### Event sourcing
25+
26+
The `hydra-node` is an event sourced application. This means that the main logic is processing _inputs_ (also called commands) and produces _events_. These events are saved and loaded to persist application state across restarts. Also, most events are transformed to _outputs_ and can be observed on the API. See [Event Sourcing](./architecture/event-sourcing) for details.
27+
2428
### Network
2529

2630
The _network_ component is responsible for communication between Hydra nodes related to the off-chain part of the Hydra protocol. See [Networking](./architecture/networking) for details.

docs/sidebars.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ module.exports = {
6969
type: "category",
7070
link: { type: "doc", id: "dev/architecture/index" },
7171
label: "Architecture",
72-
items: ["dev/architecture/networking"],
72+
items: ["dev/architecture/event-sourcing", "dev/architecture/networking"],
7373
},
7474
{
7575
type: "doc",

0 commit comments

Comments
 (0)