Skip to main content

2. Reactive Core

· One min read

Status

Accepted

Context

We are looking for a way of expressing the Hydra Head protocol logic in a Hydra node.

The Hydra Head protocol is defined as a State machine in the paper, whose transitions are inputs that come from different sources which can emit outputs to other instances of the state machine or the mainchain. See the FC2021 paper for details

It should also be easy to review / feed-back to researchers.

We are familiar with React's redux way of structuring applications, which in turn is inspired by The Elm Architecture which itself is a simplification of Functional Reactive Programming principles.

We have experienced benefits with Event Sourcing in the domain of persistence in the past

Decision

Implements the Hydra Head core logic as a loop that:

  1. Consumes input events from an event queue,
  2. Applies each event to the current state yielding potentially an updated state and a sequence of effects,
  3. Execute all effects.

Consequences

The internal state is only ever changed through Events.

The core state machine transition function is pure and reviewing it requires minimal Haskell knowledge.

Side-effects are all handled at the level of the Node.