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

Migrate stake pool course content #24

Merged
merged 4 commits into from
Apr 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/stake-pool-course/assignments/assignment-1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
id: assignment-1
title: Assignment 1
sidebar_label: Assignment 1
image: ./img/og-developer-portal.png
---

Try to complete this task from what you have learned so far:

:::info
Create a transaction with only **one** input and **one** output sending all the funds to paymentwithstake.addr
:::
31 changes: 31 additions & 0 deletions docs/stake-pool-course/assignments/assignment-2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
id: assignment-2
title: Assignment 2
sidebar_label: Assignment 2
image: ./img/og-developer-portal.png
---

:::note
As explained before, core and relay nodes must run in separate machines. In
this assignment you will create a second server or Virtual Machine to host
your core node.
:::note

Complete the following tasks in a second server:

1. Create a second server on AWS or Virtual Machine in Virtual Box. This one will host your core node and hold your stake pool keys.
2. Install dependencies
3. Install cabal
4. Install GHC
5. Install libsodium
6. Create the directory .local/bin and add it to the PATH
7. Build the node from source in your new server or Virtual Machine.
8. Get Configuration files

Repeat what you learned on [Lesson 1](../lesson-1/install-cardano-node)


:::note
DO NOT START YOUR CORE NODE YET.
When you have completed tasks 1-8, continue to [KES-Periods](../assignments/kes_period)
:::
54 changes: 54 additions & 0 deletions docs/stake-pool-course/assignments/kes_period.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
id: kes_period
title: KES Periods
sidebar_label: KES periods
image: ./img/og-developer-portal.png
---

To create an operational certificate for a block-producing node, you need to create a _KES key pair_.

Here "KES" stands for _**K**ey **E**volving **S**ignature_, which means that after a certain _period_, the key will _evolve_ to a new key and discard its old version. This is useful, because it means that even if an attacker compromises the key and gets access to the signing key, he can only use that to sign blocks _from now on_, but not blocks dating from _earlier periods_, making it impossible for the attacker to rewrite history.

Unfortunately, there is a catch: A KES key can only evolve for a certain number of periods and becomes useless afterwards. This means that before that number of periods has passed, the node operator has to generate a new KES key pair, issue a new operational node certificate with that new key pair and restart the node with the new certificate.

In order to find out how long one period is and for how long a key can evolve, we can look into the _genesis file_. If that file is called `shelley_testnet-genesis.json`, we can type

```
cat shelley_testnet-genesis.json | grep KES

> "slotsPerKESPeriod": 3600,
> "maxKESEvolutions": 120,
```

and we see that in this example, the key will evolve after each period of 3600 slots and that it can evolve 120 times before it needs to be renewed.

Before we can create an operational certificate for our node, we need to figure out the start of the KES validity period, i.e. which KES evolution period we are in. We check the current slot \(assuming our relay node socket file is at `~/cardano-node/relay/db/node.socket`\):

```
export CARDANO_NODE_SOCKET_PATH=~/cardano-node/relay/db/node.socket
cardano-cli shelley query tip --testnet-magic 1097911063

{
"blockNo": 27470,
"headerHash": "bd954e753c1131a6cb7ab3a737ca7f78e2477bea93db54511cedefe8899ebed0",
"slotNo": 656260
}
```

In this example, we are currently in slot 656260, and we know from the genesis file that one period lasts for 3600 slots. So we calculate the current period by

```
expr 656260 / 3600
> 182
```

With this we are able to generate an operational certificate for our stake pool \(assuming the same file names as [here](https://github.com/carloslodelar/SPO/tree/baec64ba9efba39d4b60b7824fb4d7b962f2c3e7/stake-pool-operations/060_node_keys.md)\):

```
cardano-cli shelley node issue-op-cert \
--kes-verification-key-file kes.vkey \
--cold-signing-key-file cold.skey \
--operational-certificate-issue-counter cold.counter \
--kes-period 182 \
--out-file node.cert
```
52 changes: 52 additions & 0 deletions docs/stake-pool-course/handbook/apply-logging-prometheus.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
id: configure-topology-files
title: Monitoring a Node with Prometheus
sidebar_label: Monitoring a node with prometheus
description: Monitoring a Node with Prometheus
image: ./img/og-developer-portal.png
---

Open the port 12798, as it is the default port for prometheus, as from the `config.json` file.
When you start the node, it makes Prometheus metrics available at port 12798 (or whatever port you specified in `config.json`). You can then setup a monitoring server or monitor your node from your local machine.

## Add Node Exporter to your server
You can get the best out of prometheus if you have both Prometheus on your local machine or monitoring server and Prometheus Node Exporter on your node's server. How to do this depends on your platform and setup, but you can find documentation:

* [Prometheus](https://prometheus.io/docs/prometheus/latest/getting_started/)

* [Node exporter](https://prometheus.io/docs/guides/node-exporter/)

## Setup Prometheus in your local machine or monitoring server
Prometheus needs to be configured to monitor your Cardano Node. A minimalistic configuration file doing this could look like this:

global:
scrape_interval: 15s
external_labels:
monitor: 'codelab-monitor'

scrape_configs:
- job_name: 'cardano' # To scrape data from the cardano node
scrape_interval: 5s
static_configs:
- targets: ['a.b.c.d:12798']
- job_name: 'node' # To scrape data from a node exporter to monitor your linux host metrics.
scrape_interval: 5s
static_configs:
- targets: ['a.b.c.d:9100']


You have to replace `a.b.c.d` with the public IP-address of your Cardano Node server, which you can find on the dashboard under _IPv4 Public IP_.

## Start prometheus

./prometheus --config.file=prometheus.yml

## Start Prometheus node exporter on your node's server, for example:

./node_exporter

On your browser open `a.b.c.d:9090`, pick one or more interesting metrics to graph and enjoy!

:::note
**NOTE**: Security configurations you should perform on your monitoring server are out of scope for this tutorial.
:::
52 changes: 52 additions & 0 deletions docs/stake-pool-course/handbook/configure-topology-files.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
id: configure-topology-files
title: Configure Topology Files
sidebar_label: Configure topology files
description: Learn how to Create Stake Pool Keys
image: ./img/og-developer-portal.png
---

Before you start your nodes, you need to prepare the topology files for block-producing and relay nodes.

## Configure the block-producing node

Make the __block-producing__ node to "talk" only to __YOUR__ relay node. Do not forget to configure your firewall also:

nano mainnet-topology.json

{
"Producers": [
{
"addr": "<RELAY IP ADDRESS>",
"port": <PORT>,
"valency": 1
}
]
}

## Configure the relay node:

Make your __relay node__ `talk` to your __block-producing__ node and __other relays__ in the network by editing the `topology.json` file:


nano mainnet-topology.json

{
"Producers": [
{
"addr": "<BLOCK-PRODUCING IP ADDRESS>",
"port": <PORT>,
"valency": 1
},
{
"addr": "<IP ADDRESS>",
"port": <PORT>,
"valency": 1
},
{
"addr": "<IP ADDRESS>",
"port": <PORT>,
"valency": 1
}
]
}
155 changes: 155 additions & 0 deletions docs/stake-pool-course/handbook/create-simple-transaction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
---
id: create-simple-transaction
title: Create Simple Transaction
sidebar_label: Create simple transaction
description: Learn how to Create Simple Transaction
image: ./img/og-developer-portal.png
---

Creating a transaction requires various steps:

* Get the protocol parameters
* Calculate the fee
* Define the time-to-live (TTL) for the transaction
* Build the transaction
* Sign the transaction
* Submit the transaction

## Get protocol parameters

Get the protocol parameters and save them to `protocol.json` with:

```
cardano-cli query protocol-parameters \
--mainnet \
--out-file protocol.json
```

## Get the transaction hash and index of the **UTXO** to spend:

```
cardano-cli query utxo \
--address $(cat payment.addr) \
--mainnet
```

## Draft the transaction

Create a draft for the transaction and save it in tx.draft

:::note
Note that for `--tx-in` we use the following syntax: `TxHash#TxIx` where `TxHash` is the transaction hash and `TxIx` is the index; for `--tx-out` we use: `TxOut+Lovelace` where `TxOut` is the hex encoded address followed by the amount in `Lovelace`. For the transaction draft --tx-out, --invalid-hereafter and --fee can be set to zero.
:::note

cardano-cli transaction build-raw \
--tx-in 4e3a6e7fdcb0d0efa17bf79c13aed2b4cb9baf37fb1aa2e39553d5bd720c5c99#4 \
--tx-out $(cat payment2.addr)+0 \
--tx-out $(cat payment.addr)+0 \
--invalid-hereafter 0 \
--fee 0 \
--out-file tx.draft

## Calculate the fee

A simple transaction needs one input, a valid UTXO from `payment.addr`, and two outputs:

* Output1: The address that receives the transaction.
* Output2: The address that receives the change of the transaction.

Note that to calculate the fee you need to include the draft transaction
```
cardano-cli transaction calculate-min-fee \
--tx-body-file tx.draft \
--tx-in-count 1 \
--tx-out-count 2 \
--witness-count 1 \
--byron-witness-count 0 \
--mainnet \
--protocol-params-file protocol.json
```

## Calculate the change to send back to payment.addr

all amounts must be in Lovelace:

expr <UTXO BALANCE> - <AMOUNT TO SEND> - <TRANSACTION FEE>

For example, if we send 10 ADA from a UTxO containing 20 ADA, the change to send back to `payment.addr` after paying the fee is: 9.832035 ADA
```
expr 20000000 - 10000000 - 167965
9832035
```

## Determine the TTL (time to Live) for the transaction

To build the transaction we need to specify the **TTL (Time to live)**, this is the slot height limit for our transaction to be included in a block, if it is not in a block by that slot the transaction will be cancelled. So TTL = slot + N slots. Where N is the amount of slots you want to add to give the transaction a window to be included in a block.

Query the tip of the blockchain:

cardano-cli query tip --mainnet

Look for the value of `slotNo`
```
{
"blockNo": 16829,
"headerHash": "3e6f59b10d605e7f59ba8383cb0ddcd42480ddcc0a85d41bad1e4648eb5465ad",
"slotNo": 369200
}
```
Calculate your TTL, for example: 369200 + 200 slots = 369400

## Build the transaction

We write the transaction in a file, we will name it `tx.raw`.
```
cardano-cli transaction build-raw \
--tx-in 4e3a6e7fdcb0d0efa17bf79c13aed2b4cb9baf37fb1aa2e39553d5bd720c5c99#4 \
--tx-out $(cat payment2.addr)+10000000 \
--tx-out $(cat payment.addr)+9832035 \
--invalid-hereafter 369400 \
--fee 167965 \
--out-file tx.raw
```

## Sign the transaction

Sign the transaction with the signing key **payment.skey** and save the signed transaction in **tx.signed**
```
cardano-cli transaction sign \
--tx-body-file tx.raw \
--signing-key-file payment.skey \
--mainnet \
--out-file tx.signed
```

## Submit the transaction
```
cardano-cli transaction submit \
--tx-file tx.signed \
--mainnet
```

## Check the balances

We must give it some time to get incorporated into the blockchain, but eventually, we will see the effect:
```
cardano-cli query utxo \
--address $(cat payment.addr) \
--mainnet

> TxHash TxIx Amount
> ----------------------------------------------------------------------------------------
> b64ae44e1195b04663ab863b62337e626c65b0c9855a9fbb9ef4458f81a6f5ee 1 9832035 lovelace

cardano-cli query utxo \
--address $(cat payment2.addr) \
--mainnet

> TxHash TxIx Amount
> ----------------------------------------------------------------------------------------
> b64ae44e1195b04663ab863b62337e626c65b0c9855a9fbb9ef4458f81a6f5ee 0 10000000 lovelace
```

:::note
**Note**`--mainnet` identifies the Cardano mainnet, for testnets use `--testnet-magic 1097911063` instead.
:::note
Loading