Skip to content

Commit 173a8a6

Browse files
authored
Merge pull request #5 from euonymos/euonymos/docs
Minor docs improvements
2 parents 8d42451 + be56562 commit 173a8a6

File tree

9 files changed

+117
-93
lines changed

9 files changed

+117
-93
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@
1111
/.psci_modules/
1212
/.spago/
1313
/.spago2nix/
14+
.psc-ide-port

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ docker-cleanup:
4141
docker volume rm -f cluster_hydra-persist-a cluster_hydra-persist-b
4242

4343
gen-keys: requires-nix-shell
44-
@hydra-node gen-hydra-key --output-file ${example-keys}/hydra-a
45-
@hydra-node gen-hydra-key --output-file ${example-keys}/hydra-b
44+
@hydra-node gen-hydra-key --output-file ${example-keys}/hydra-a
45+
@hydra-node gen-hydra-key --output-file ${example-keys}/hydra-b
4646
@cardano-cli address key-gen \
4747
--signing-key-file ${example-keys}/cardano-a.sk \
4848
--verification-key-file ${example-keys}/cardano-a.vk

README.md

Lines changed: 104 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,54 @@
22

33
[Cardano Hydra](https://hydra.family/head-protocol/)
44
SDK (Software Development Kit) for PureScript. This library offers
5-
various interfaces to facilitate rapid development of Hydra-based
6-
applications.
5+
various interfaces to facilitate the rapid development
6+
of Hydra-based applications.
77

88
**Table of Contents**
99

1010
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
1111
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
1212

1313
- [Compatibility](#compatibility)
14-
- [Applications](#applications)
1514
- [Preliminaries](#preliminaries)
16-
- [Getting Started](#getting-started)
17-
- [Functionality](#functionality)
1815
- [Development Workflows](#development-workflows)
16+
- [Getting Started with Example](#getting-started-with-example)
17+
- [SDK Core Functionality](#sdk-core-functionality)
18+
- [SDK Additionals: AppManager](#sdk-additionals-appmanager)
19+
- [Applications](#applications)
1920

2021
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
2122

22-
### Compatibility
23+
## Compatibility
2324

2425
| hydra-sdk | hydra-node | cardano-node |
2526
| ----------- | ------------ | ------------ |
2627
| **`0.1.0`** | **`0.19.0`** | **`10.1.2`** |
2728

28-
### Applications
29-
30-
Please refer to [hydra-auction-offchain](https://github.com/mlabs-haskell/hydra-auction-offchain)
31-
for a full-fledged example that utilizes this SDK.
3229

33-
### Preliminaries
30+
## Preliminaries
3431

3532
Since using this SDK implies a certain degree of understanding of the Hydra
3633
protocol, it is advisable to get familiar with the ["Hydra: Fast Isomorphic State Channels" paper](https://iohk.io/en/research/library/papers/hydra-fast-isomorphic-state-channels/)
3734
and the [Hydra Head protocol documentation](https://hydra.family/head-protocol/docs/)
3835
before proceeding with the **Getting Started** guide below.
3936

40-
### Getting Started
37+
## Development Workflows
38+
39+
Before executing most of the commands listed below, first enter the Nix
40+
development shell by running `nix develop`.
41+
42+
* **Build docs and open them in the browser**: `make docs`
43+
* **Build the project**: `make build`
44+
* **Format code**: `make format`
45+
46+
## Getting Started with Example
4147

4248
The simplest way to get a sense of how this SDK can help build Hydra-based
4349
applications is to run our minimal example and then adapt or extend it to suit
44-
your specific requirements. Follow the step-by-step guide below to spin up
50+
your specific requirements.
51+
52+
Go to `example/minimal` and follow the step-by-step guide below to spin up
4553
a cluster of two nodes, with each node running the minimal example logic.
4654

4755
1. Enter the Nix development environment by running `nix develop` from the root
@@ -51,38 +59,45 @@ necessary executables required to continue with the setup procedure.
5159
2. In [example/minimal/docker/cluster/](example/minimal/docker/cluster/) you
5260
can find configuration files for both nodes. The only field that needs to be
5361
updated here is the `blockfrostApiKey`, which should be set to a valid
54-
Blockfrost API key **for preprod**. Visit the [Blockfrost website](https://blockfrost.io/)
55-
to generate a fresh API key.
62+
Blockfrost API key **for preprod**.
63+
Visit the [Blockfrost website](https://blockfrost.io/) to generate a fresh API key.
5664

5765
3. Execute `make gen-keys` to generate the necessary Cardano and Hydra keys
5866
required by the underlying Hydra nodes. Cardano keys are used to authenticate
5967
on-chain transactions, while the Hydra keys are used for multi-signing snapshots
6068
within a Hydra Head. This command will output two Cardano preprod addresses
6169
that must be pre-funded with sufficient tADA to run properly functioning Hydra
62-
nodes. Use the [Testnets faucet](https://docs.cardano.org/cardano-testnets/tools/faucet/)
70+
nodes.
71+
Use the [Testnets faucet](https://docs.cardano.org/cardano-testnets/tools/faucet/)
6372
to request tADA.
6473

65-
4. Finally, execute `make run-example` to launch a Hydra Head with two
66-
participants running the minimal example logic.
74+
4. Finally, execute `make run-example` to launch a Hydra Head
75+
with two participants both running the minimal example logic.
6776

68-
NOTE: Hydra nodes require a fully-synchronized Cardano node to operate
77+
NOTE: Hydra nodes require a fully synchronized Cardano node to operate
6978
correctly. No additional setup actions need to be performed to
7079
configure the Cardano node as it is already included in the Docker
71-
Compose configuration. However it may take several hours on the first
72-
run to synchronize the node. Keep in mind that Hydra nodes
73-
are configured to run only once the Cardano node is fully
74-
synchronized, and the `cardano-node` output is suppressed to not
75-
interfere with useful Hydra Head logs. As a result, there will be no
76-
output during synchronization. Instead, use `docker logs` or run
77-
`cardano-cli query tip` from within the `cardano-node` Docker
78-
container to track the synchronization progress.
79-
80-
### Functionality
81-
82-
The `HydraSdk.Process` module provides an interface for spinning up a hydra-node
80+
Compose configuration.
81+
However, node synchronization may take several hours on the first run.
82+
Keep in mind that Hydra nodes are configured to run only once
83+
the Cardano node is fully synchronized,
84+
and the `cardano-node` output is suppressed to not
85+
interfere with useful Hydra Head logs.
86+
As a result, there will be no output during synchronization.
87+
Instead, use `docker logs` or run `cardano-cli query tip`
88+
from within the `cardano-node` Docker container
89+
to track the synchronization progress.
90+
91+
## SDK Core Functionality
92+
93+
The SDK exposes the following top-level modules which constitus it API which
94+
is considered to be relatvely stable. You also can use `Internal` modules
95+
at yor own risk.
96+
97+
* `HydraSdk.Process` module provides an interface for spinning up a hydra-node
8398
as a Node.js subprocess.
8499

85-
The `HydraSdk.NodeApi` module exports functions for connecting to the Hydra Node
100+
* `HydraSdk.NodeApi` module exports functions for connecting to the Hydra Node
86101
WebSocket API and sending HTTP requests. The primary function provided by this
87102
module is `mkHydraNodeApiWebSocket`, which establishes a WebSocket connection to
88103
the hydra-node, attaches specified handlers for incoming messages, and returns a
@@ -91,21 +106,65 @@ Hydra Node API. It also allows to specify retry strategies for Hydra
91106
transactions that may be silently dropped by cardano-node, particularly for
92107
Close and Contest transactions.
93108

94-
The `HydraSdk.Types` module re-exports various Hydra domain-specific types
109+
* `HydraSdk.Types` module re-exports various Hydra domain-specific types
95110
(such as `HydraHeadStatus` and `HydraNodeApi_InMessage`), along with other
96111
utility types (e.g., `HostPort` and `Network`) used by the components of this
97112
library.
98113

99-
`HydraSdk.Extra.AppManager` provides an opinionated interface for managing
100-
multiple Hydra application instances, with each instance running a separate
101-
hydra-node process, as implemented in [hydra-auction-offchain](https://github.com/mlabs-haskell/hydra-auction-offchain).
102-
For more information, refer to the [AppManager README](src/Extra/README.md).
114+
* Lastly, `HydraSdk.Lib` module contains useful helpers like codecs for many types,
115+
logging action and some others.
116+
117+
## SDK Additionals: AppManager
118+
119+
Under `Extra` folder, modules with additional functionality are located,
120+
currently being the only one for managing multiple app instances.
121+
122+
Originally the SDK was designed for Hydra applications, where Hydra Heads were
123+
operated by designated delegates. In that model a delegate can be anyone who wants
124+
to participate as a provider of computational resources to host Hydra
125+
nodes. Delegates must form a group upfront to maintain Hydra
126+
consensus. Upon forming a group, all members need to specify
127+
information about their peers - such as Hydra node addresses, public
128+
keys, etc. That way there exists a strict correspondence between
129+
delegate configurations to start a functioning Hydra Head.
130+
131+
Each application instance should monitor its underlying Hydra node and
132+
have access to information about other Hydra Head participants.
133+
AppManager is an opinionated interface for managing multiple app
134+
instances within a delegate group. This interface is utilized by
135+
applications like `hydra-auction-offchain`, enabling delegates to host
136+
multiple Layer-2 auctions simultaneously.
137+
138+
At the core of AppManager is the concept of slots. When delegates
139+
decide to form a group, they agree on the configurations for their
140+
future Hydra nodes. Since each delegate have to specify information
141+
about their peers (hydra-node address, public keys, etc.), there must
142+
be strict correspondence between delegate configurations to start
143+
a working Hydra Head. This is where slots come into play. Each slot
144+
represents a set of delegate configurations sufficient to spin up a
145+
properly configured Hydra Head. In hydra-auction-offchain, slot
146+
numbers are implicitly derived from the configurations provided to
147+
the delegate-server, with the first configuration corresponding to
148+
slot 0, the second to slot 1, and so forth. Users are expected to
149+
reserve slots before making an initial Layer-1 commitment, such as
150+
announcing an auction. Upon reservation, they receive secrets from
151+
each delegate, which can later be provided to host a Layer-2
152+
application in the reserved slot.
153+
154+
One clear drawback of this approach is the potential for malicious
155+
actors to reserve all available slots within a delegate group,
156+
effectively paralyzing its operations. In real-world applications, a
157+
flooding detection mechanism should be implemented to prevent this
158+
scenario, although there seems to be no obvious incentive for anyone
159+
to carry out such an attack.
160+
161+
Coming with the limitations mentioned, this approach simplifies things
162+
since it neither requires communication and synchronization between
163+
delegates during runtime nor does it rely on a central server to
164+
orchestrate the initialization of Hydra Heads, making it a great fit
165+
for hydra-auction-offchain and hopefully other Hydra applications.
166+
167+
## Applications
103168

104-
### Development Workflows
105-
106-
Before executing most of the commands listed below, first enter the Nix
107-
development shell by running `nix develop`.
108-
109-
**Build the project** (requires Nix shell): `make build`
110-
**Format code** (requires Nix shell): `make format`
111-
**Build docs and open them in the browser**: `make docs`
169+
Please refer to [hydra-auction-offchain](https://github.com/mlabs-haskell/hydra-auction-offchain)
170+
for a full-fledged example that utilizes this SDK.

src/Extra/AppManager.purs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
--| An opinionated interface for managing multiple Hydra application instances,
2+
--| with each instance running a separate hydra-node process.
3+
--| Please refer to README.md for more details.
4+
15
module HydraSdk.Extra.AppManager
26
( module ExportAppManager
37
) where

src/Extra/README.md

Lines changed: 0 additions & 46 deletions
This file was deleted.

src/Lib.purs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
-- | Useful stuff for building an application with HydraSdk.
12
module HydraSdk.Lib
23
( module ExportAVar
34
, module ExportCodec

src/NodeApi.purs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
-- | API to comminicate with the Hydra Node via HTTP/WebSockets.
12
module HydraSdk.NodeApi
23
( module ExportHttp
34
, module ExportWebSocket

src/Process.purs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
-- | API for spinning up a hydra-node in a Node.js' subprocess.
12
module HydraSdk.Process
23
( module ExportHydraNode
34
) where

src/Types.purs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
--| Re-exports various Hydra domain-specific types
2+
--| (such as `HydraHeadStatus` and `HydraNodeApi_InMessage`),
3+
--| along with other utility types (e.g., `HostPort` and `Network`).
14
module HydraSdk.Types
25
( module ExportArgonautJson
36
, module ExportCommitRequest

0 commit comments

Comments
 (0)