Skip to content

Commit f02266f

Browse files
authored
Update aws hydra head opening instructions (#2163)
<!-- Describe your change here --> --- <!-- Consider each and tick it off one way or the other --> * [x] CHANGELOG updated or not needed * [x] Documentation updated or not needed * [x] Haddocks updated or not needed * [ ] No new TODOs introduced or explained herafter
2 parents 6b3f9d7 + 8d5d3ec commit f02266f

File tree

6 files changed

+172
-43
lines changed

6 files changed

+172
-43
lines changed

sample-node-config/aws/README.md

Lines changed: 80 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,46 +8,54 @@
88
This directory contains some [Terraform](https://www.hashicorp.com/products/terraform) and AWS based infrastructure code to setup a single [Hydra node](https://hydra.family/head-protocol/docs/getting-started/installation) connected to a [Cardano node](https://docs.cardano.org/getting-started/installing-the-cardano-node) running on `preview` testnet. It's not a complete turnkey solution and requires some tweaking and parameterisation to be completely usable but we thought it would be good starting point for new Hydra users.
99

1010
### Pre-requisites
11-
- you have access to an aws account with root privileges.
12-
- you have configured your local aws credentials.
13-
for this example in `~/.aws/credentials` we have:
11+
1. **AWS Account**: You need access to an AWS account with privileges to create EC2 instances and related resources.
12+
2. **AWS CLI & Terraform**: You must have the [AWS CLI](https://aws.amazon.com/cli/) and [Terraform](https://developer.hashicorp.com/terraform/downloads) installed and configured on your local machine.
13+
3. **AWS Credentials File**: Your local AWS credentials should be configured. For this example, we assume a profile in `~/.aws/credentials`:
1414
```
1515
[personal]
1616
aws_access_key_id=???
1717
aws_secret_access_key=???
1818
region=eu-west-3
1919
```
20-
> **personal** will be your AWS_PROFILE
21-
> so whenever you see _personal_ in the rest of the file you need to replace it with your own aws profile name.
20+
4. **EC2 Key Pair**: You must create an EC2 Key Pair in the AWS region you intend to use. When you create it, AWS will provide a `.pem` file. **Download and save this file securely.** You will need its name for the configuration.
21+
> Here and later we refer to your `AWS_PROFILE` name as **personal**.
22+
> Whenever you see _personal_ in the rest of the file you need to replace it with your own aws profile name.
2223
> Also you need to make sure to create a new key pair in the region eu-west-3 (TODO: abstract the region away?)
2324
> TODO: it would be cool to use aws_ssm to connect to the EC2 so that we don't depend on extra ssh keys manipulations.
2425
25-
- you have terraform and aws installed on your system.
26-
- you have built the required 2 folder structures under aws folder:
27-
+ credentials.
28-
+ aws.
26+
### Project Setup
27+
Before running Terraform, you need to create a specific directory and file structure within the `sample-node-config/aws/` directory.
2928
30-
## Project structure to build
29+
1. **Create Directories**:
30+
- `credentials/`: This will store your Cardano-related keys.
31+
- `aws/`: This will store your EC2 `.pem` file.
32+
33+
2. **Place Your Key**: Copy the `.pem` file you downloaded from AWS into the `aws/` directory. For example: `aws/my-key.pem`.
34+
35+
3. **Generate Cardano Keys**: Create your Cardano keys and place them in the `credentials/` directory. You should have at least `cardano.addr`, `cardano-key.sk`, and `hydra-key.sk`.
36+
37+
The final structure should look like this:
3138
```
3239
.
33-
+-- credentials
34-
| +-- arnaud.cardano.vk
35-
| +-- arnaud.hydra.vk
40+
+-- credentials/
41+
| +-- cardano.addr
3642
| +-- cardano-key.sk
3743
| +-- cardano-key.vk
38-
| +-- cardano.addr
3944
| +-- hydra-key.sk
4045
| +-- hydra-key.vk
4146
+-- aws
4247
| +-- personal.pem
4348
+-- terraform.tfvars
49+
+-- (other *.tf files)
4450
```
4551
4652
This should only be done once, when starting afresh.
4753
48-
These are folders you must create yourself:
49-
- ***credentials*** to store all blockchain related credential files.
50-
- ***aws*** to store your personal aws credentials.
54+
TODO: refer to how to generate addresses and .sk, .vk files.
55+
56+
### Terraform Configuration
57+
58+
Instead of altering `variables.tf`, you should specify your custom values in a `terraform.tfvars` file at the root of the `sample-node-config/aws/` directory.
5159
5260
At the root of the `aws` project, execute:
5361
```sh
@@ -56,21 +64,45 @@ $ ./setup/setup.sh
5664
[Note] all scripts inside the `/setup` folder are expected to be executed at the root of the `aws` project.
5765

5866
This will create a file called `terraform.tfvars`, used to complete the `variables.tf` definitions. For this example it would be defined as:
59-
```
67+
```toml
68+
# The AWS profile name from your ~/.aws/credentials file.
6069
profile = "iog"
70+
# The name of the EC2 Key Pair you created in the AWS console.
71+
# This must match the name of the key pair, not the filename.
6172
key_name = "personal"
6273
```
6374

6475
## Initialise Terraform
76+
6577
This should only be done once, when starting afresh.
6678
At the root of `aws` project execute:
79+
6780
```sh
68-
$ terraform init
81+
terraform init
6982
```
7083

7184
### Alter terraform variables
85+
86+
Instead of altering `variables.tf`, you should specify your custom values in a `terraform.tfvars` file at the root of the `sample-node-config/aws/` directory.
7287
Alter the file `variables.tf` found in `sample-node-config/aws/` to reflect your ami, region and instance_type. Defaults are already provided.
7388

89+
Example
90+
```toml
91+
# The AWS profile from your `~/.aws/credentials` file.
92+
profile = "default"
93+
# The name of the EC2 Key Pair you created in the AWS Console for your chosen region.
94+
key_name = "hydra-node-key"
95+
# The hydra network environment to use. Can be "preview", "preprod", or "mainnet".
96+
env = "preview"
97+
# The AWS region where you created your key pair and want to deploy resources.
98+
region = "eu-central-1"
99+
# The Amazon Machine Image (AMI) ID for a recent Ubuntu release in your chosen region.
100+
# You can find this in the AWS EC2 Console when launching a new instance.
101+
ami = "ami-012345fxxxxxxxx"
102+
# The type of EC2 instance to launch.
103+
instance_type = "r5a.xlarge"
104+
```
105+
74106
### Deploying the VM
75107
Then create a deployment plan and apply it:
76108
```sh
@@ -129,26 +161,38 @@ $ scripts/login.sh
129161
- ctrl B + D: detach session
130162
- tmux a: attach the detached-session
131163

164+
```shell
165+
source ~/.bash_env
166+
```
167+
132168
## Create marker utxo: get fuel from testnet
133169
Now that you are logged in to your VM, first thing we need is to spin up your `cardano-node` and create the marker utxo.
134-
For that we will need to execute:
170+
171+
172+
For that we will need to executea docker command. First, go to the `docker folder:
173+
```shell
174+
cd docker
135175
```
176+
177+
and then:
178+
```shell
136179
$ docker-compose up -d cardano-node
137180
$ fuel
138181
```
139182

140183
## Configuring Hydra Node
184+
141185
We need to make sure some files, which are not provided by default and which are required for starting the `hydra-node`, are in place at the home folder of your VM:
142186
* A Hydra signing key file `hydra-key.sk` which will be used in the Head to sign snapshots.
143-
This can be generated using [hydra-node](https://hydra.family/head-protocol/docs/getting-started/quickstart#hydra-keys),
187+
This can be generated using [hydra-node](https://hydra.family/head-protocol/docs/configuration#hydra-keys),
144188
* A cardano signing key file `cardano-key.sk` which is required to identify the parties on-chain and sign transactions.
145-
This is a standard Cardano key so one can reuse an existing key or [generate a new one](https://hydra.family/head-protocol/docs/getting-started/quickstart#cardano-keys),
189+
This is a standard Cardano key so one can reuse an existing key or [generate a new one](https://hydra.family/head-protocol/docs/configuration#cardano-keys),
146190
* 0 or more hydra verification keys and cardano verification keys for the other Head parties,
147191
* The IP addresses and ports of _peer_ nodes,
148192
* Configuration files for [promtail](https://grafana.com/docs/loki/latest/clients/promtail/) and [prometheus](https://prometheus.io/) which are run as part of the stack,
149193
* Configuration files for the off-chain ledger.
150194

151-
Then the [docker-compose.yaml](./docker/docker-compose.yaml) should be edited to reflect the above parameters as [command-line arguments](https://hydra.family/head-protocol/docs/getting-started/quickstart) to the `hydra-node` container.
195+
Then the [docker-compose.yaml](./docker/docker-compose.yaml) should be edited to reflect the above parameters as [command-line arguments](https://hydra.family/head-protocol/docs/configuration) to the `hydra-node` container.
152196

153197
i.e.:
154198
```
@@ -162,23 +206,26 @@ The [promtail-config.yml](./docker/promtail-config.yml) should be edited to poin
162206
For `cardano-node` and `hydra-node` services, make sure the `logging` options for `awslogs` are properly aligned with what is defined in your `cloudwatch.tf` and `variables.tf` files.
163207

164208
## Running the hydraw instance
209+
165210
Next, to run hydraw, execute:
166-
```
167-
$ up
211+
212+
```sh
213+
up
168214
```
169215

170216
> execute `down` to take it down
171217
172218
## Opening the Head
173219
Finally, execute the hydra-tui and open the head:
174-
```
175-
$ tui
220+
221+
```sh
222+
tui
176223
```
177224

178225
> If you take down your hydra-node instance once the head is open. you will loose access to your funds committed to the head.
179-
To get them back, currently you need to start the head from a point time in the past.
180-
For that you must run hydra-node the using parameter `--start-chain-from`.
181-
i.e.: --start-chain-from 2730515.c7a3629911ef004c873ef07313842df5d1331f61e0eb632432ac8c0636dfd391
226+
> To get them back, currently you need to start the head from a point time in the past.
227+
> For that you must run hydra-node the using parameter `--start-chain-from`.
228+
> i.e.: `-start-chain-from 2730515.c7a3629911ef004c873ef07313842df5d1331f61e0eb632432ac8c0636dfd391`
182229
183230
## Using Hydraw
184231

@@ -199,8 +246,9 @@ Terraform relies on plain SSH to connect to the VM, so this can be caused by the
199246
> Peers cannot see you connected
200247
Perhaps your node is out of sync with the L1.
201248
Check sync progress by running a `cardano-cli` query tip on your cardano node:
202-
```
203-
$ sync
249+
250+
```sh
251+
sync
204252
```
205253

206254
But others may come from the containers itself.

sample-node-config/aws/docker/docker-compose.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
services:
44
cardano-node:
5-
image: inputoutput/cardano-node:8.7.3
5+
image: ghcr.io/intersectmbo/cardano-node:10.4.1
66
restart: always
7+
container_name: cardano-node
78
logging:
89
driver: "awslogs"
910
options:
@@ -28,6 +29,7 @@ services:
2829
hydra-node:
2930
image: ghcr.io/input-output-hk/hydra-node@sha256:3b7f78962ff8fc212644e1ef4faf8742ead6f7c31353cdf5cc251d4d825edac7
3031
restart: always
32+
container_name: hydra-node
3133
logging:
3234
driver: "journald"
3335
# driver: "awslogs"
@@ -84,6 +86,7 @@ services:
8486

8587
hydra-tui:
8688
image: ghcr.io/cardano-scaling/hydra-tui:unstable
89+
container_name: hydra-tui
8790
profiles:
8891
- tui
8992
command:
@@ -99,6 +102,7 @@ services:
99102

100103
hydraw:
101104
image: ghcr.io/cardano-scaling/hydraw:latest
105+
container_name: hydraw
102106
profiles:
103107
- hydraw
104108
environment:

sample-node-config/aws/scripts/.bash_profile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function dcfile() {
5050
}
5151

5252
function ccli() {
53-
dc -f ~/docker/docker-compose.yaml exec cardano-node cardano-cli ${@}
53+
docker exec -it cardano-node cardano-cli ${@}
5454
}
5555

5656
function balance() {
@@ -60,3 +60,5 @@ function balance() {
6060
function xbalance() {
6161
ccli query utxo $(ctag) --address $(cat ~/credentials/external.addr)
6262
}
63+
64+
alias fuel='~/scripts/create-fuel.sh'

sample-node-config/aws/scripts/configure-testnet.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ echo "export NETWORK_MAGIC=$NETWORK_MAGIC" >> ~/.bash_env
2222

2323
# this is manually hardcoded from https://github.com/cardano-scaling/hydra/releases/tag/0.10.0
2424
# perhaps there would be a way to look those up in the Chain?
25-
export HYDRA_SCRIPTS_TX_ID=$(jq -r .$NETWORK.hydraScriptsTxId ~/scripts/configure.json)
25+
export HYDRA_SCRIPTS_TX_ID=$(jq -r '."'$NETWORK'".hydraScriptsTxId' ~/scripts/configure.json)
2626
echo "export HYDRA_SCRIPTS_TX_ID=$HYDRA_SCRIPTS_TX_ID" >> ~/.bash_env
2727

2828
# Mithril stuff
@@ -33,16 +33,16 @@ echo "export MITHRIL_IMAGE_ID=$MITHRIL_IMAGE_ID" >> ~/.bash_env
3333

3434
docker pull ghcr.io/input-output-hk/mithril-client:$MITHRIL_IMAGE_ID
3535

36-
export AGGREGATOR_ENDPOINT=$(jq -r .$NETWORK.mithril.aggregatorEndpoint ~/scripts/configure.json)
36+
export AGGREGATOR_ENDPOINT=$(jq -r '."'$NETWORK'".mithril.aggregatorEndpoint' ~/scripts/configure.json)
3737
echo "export AGGREGATOR_ENDPOINT=$AGGREGATOR_ENDPOINT" >> ~/.bash_env
3838

39-
export GENESIS_VERIFICATION_KEY_URL=$(jq -r .$NETWORK.mithril.genesisVerificationKeyURL ~/scripts/configure.json)
39+
export GENESIS_VERIFICATION_KEY_URL=$(jq -r '."'$NETWORK'".mithril.genesisVerificationKeyURL' ~/scripts/configure.json)
4040
echo "export GENESIS_VERIFICATION_KEY_URL=$GENESIS_VERIFICATION_KEY_URL" >> ~/.bash_env
4141

4242
export GENESIS_VERIFICATION_KEY=$(wget -q -O - $GENESIS_VERIFICATION_KEY_URL)
4343
echo "export GENESIS_VERIFICATION_KEY=$GENESIS_VERIFICATION_KEY" >> ~/.bash_env
4444

45-
export ANCILLARY_VERIFICATION_KEY_URL=$(jq -r .$NETWORK.mithril.ancillaryVerificationKeyURL ~/scripts/configure.json)
45+
export ANCILLARY_VERIFICATION_KEY_URL=$(jq -r '."'$NETWORK'".mithril.ancillaryVerificationKeyURL' ~/scripts/configure.json)
4646
echo "export GENESIS_VERIFICATION_KEY_URL=$GENESIS_VERIFICATION_KEY_URL" >> ~/.bash_env
4747

4848
export ANCILLARY_VERIFICATION_KEY=$(wget -q -O - $ANCILLARY_VERIFICATION_KEY_URL)
@@ -52,16 +52,16 @@ export SNAPSHOT_DIGEST=$(curl -s $AGGREGATOR_ENDPOINT/artifact/snapshots | jq -r
5252
echo "export SNAPSHOT_DIGEST=$SNAPSHOT_DIGEST" >> ~/.bash_env
5353

5454
mithril_client () {
55-
docker run --rm -e NETWORK=$NETWORK -e GENESIS_VERIFICATION_KEY=$GENESIS_VERIFICATION_KEY -e ANCILLARY_VERIFICATION_KEY=$ANCILLARY_VERIFICATION_KEY -e AGGREGATOR_ENDPOINT=$AGGREGATOR_ENDPOINT --name='mithril-client' -v $(pwd):/app/data -u $(id -u) ghcr.io/input-output-hk/mithril-client:$MITHRIL_IMAGE_ID $@
55+
docker run --rm --workdir /app/data -e NETWORK=$NETWORK -e GENESIS_VERIFICATION_KEY=$GENESIS_VERIFICATION_KEY -e ANCILLARY_VERIFICATION_KEY=$ANCILLARY_VERIFICATION_KEY -e AGGREGATOR_ENDPOINT=$AGGREGATOR_ENDPOINT --name='mithril-client' -v $(pwd):/app/data -u $(id -u) ghcr.io/input-output-hk/mithril-client:$MITHRIL_IMAGE_ID $@
5656
}
5757

5858
echo "Restoring snapshot $SNAPSHOT_DIGEST"
5959
# Show detailed information about a snapshot
60-
mithril_client --origin-tag HYDRA snapshot show $SNAPSHOT_DIGEST
60+
mithril_client cardano-db snapshot show $SNAPSHOT_DIGEST
6161
# Download the given snapshot and verify the certificate
6262
# This downloads and restores a snapshot
63-
mithril_client --origin-tag HYDRA snapshot download $SNAPSHOT_DIGEST
63+
mithril_client cardano-db download $SNAPSHOT_DIGEST
6464

6565
# FIXME
66-
# mv -f ./$NETWORK/${SNAPSHOT_DIGEST}/db network/
66+
mv -f ./db network/
6767

sample-node-config/aws/scripts/configure.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@
2626
},
2727
"tag": "--mainnet"
2828
}
29-
}
29+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Creates a "fuel" UTxO for a Hydra Head from the largest UTxO in the wallet.
4+
# This script is an adaptation of the one found in the gcp/scripts directory.
5+
6+
set -e
7+
8+
source ~/.bash_profile
9+
10+
# --- Configuration ---
11+
# The signing key for the wallet.
12+
SK_FILE=~/credentials/cardano-key.sk
13+
14+
# The address of the wallet.
15+
ADDR=$(cat ~/credentials/cardano.addr)
16+
17+
# The amount of lovelace to place in the fuel UTxO.
18+
# We'll use 10 ADA here. The rest will be returned as change.
19+
FUEL_AMOUNT=10000000
20+
21+
# The required datum hash for a fuel UTxO.
22+
FUEL_DATUM_HASH="a654fb60d21c1fed48db2c320aa6df9737ec0204c0ba53b9b94a09fb40e757f3"
23+
24+
echo "- Using address: ${ADDR}"
25+
echo "- Using signing key: ${SK_FILE}"
26+
27+
# --- Find largest UTxO to use as input ---
28+
echo ""
29+
echo "- Querying wallet UTxOs..."
30+
UTXO_JSON=$(ccli query utxo $(ctag) --address ${ADDR} --out-file /dev/stdout)
31+
32+
if [ -z "$UTXO_JSON" ] || [ "$UTXO_JSON" == "{}" ]; then
33+
echo "!! ERROR: No UTxOs found at address ${ADDR}."
34+
echo "!! Please use the faucet to fund this address first."
35+
exit 1
36+
fi
37+
38+
# Find the UTxO with the most lovelace to use as input
39+
TX_IN=$(echo "${UTXO_JSON}" | jq -r 'to_entries | max_by(.value.value.lovelace) | .key')
40+
TOTAL_LOVELACE=$(echo "${UTXO_JSON}" | jq -r ".\"${TX_IN}\".value.lovelace")
41+
42+
echo "- Found largest UTxO:"
43+
echo " - TxIn: ${TX_IN}"
44+
echo " - Lovelace: ${TOTAL_LOVELACE}"
45+
46+
if [ "${TOTAL_LOVELACE}" -lt "${FUEL_AMOUNT}" ]; then
47+
echo "!! ERROR: Insufficient funds. Largest UTxO has ${TOTAL_LOVELACE} lovelace, but need at least ${FUEL_AMOUNT}."
48+
exit 1
49+
fi
50+
51+
# --- Build, Sign, and Submit Transaction ---
52+
TMP_TX_FILE=$(mktemp)
53+
54+
echo ""
55+
echo "- Building transaction..."
56+
ccli transaction build \
57+
--babbage-era \
58+
--tx-in "${TX_IN}" \
59+
--tx-out "${ADDR}+${FUEL_AMOUNT}" \
60+
--tx-out-datum-hash "${FUEL_DATUM_HASH}" \
61+
--change-address "${ADDR}" \
62+
--out-file "${TMP_TX_FILE}.raw"
63+
64+
echo "- Signing transaction..."
65+
ccli transaction sign \
66+
--tx-body-file "${TMP_TX_FILE}.raw" \
67+
--signing-key-file "${SK_FILE}" \
68+
--out-file "${TMP_TX_FILE}.signed"
69+
70+
echo "- Submitting transaction..."
71+
ccli transaction submit --tx-file "${TMP_TX_FILE}.signed"
72+
73+
echo ""
74+
echo "✔ Transaction submitted successfully!"
75+
echo "Wait a minute and check your new balance with the 'balance' command."

0 commit comments

Comments
 (0)