# Cryptobounty Certification Program

**Problems:**\
\
**Wyoming needs blockchain developers, PoW/PoS operators, and a workforce with a strong fundamental understanding of blockchain technologies.**&#x20;

\
**Currently, the University of Wyoming is trying to solve this through its blockchain and computer science programs, aided by a shift in school philosophy, along with the implementation of the IOHK Blockchain Research and Development Lab.**\
\
**Currently, blockchain education at the Highschool level is rare at best, with only a school or two attempting it at any capacity in the state of Wyoming.**\
\
**The University has expressed the desire to form developmental pathways for Highschool students that will allow them to participate in UW’s Proof of Stake and Proof of Work programs.**\
\
**High School curricular and CTE programs (which is what STEM falls under currently) are required to show accountability for students that have participated in a certain number of semesters in a program. Currently there are no suitable High School level certifications that can be expected to be taught at the Secondary education level that pertain to Blockchain or PoS/PoW infrastructure operations.**

**The University of Wyoming runs a Cardano stakepool and will need people capable of running and expanding their efforts in validating blocks on Cardano and other chains.**\
\
\
**Solutions:**\
\
**With industry help (Cryptobounty LLC), we would like to take steps to establish pathways for students to gain Highschool level certifications in Proof of Stake operations on Cardano.**\
\
**We will attempt to achieve this through developing a micro-certification program, similar to the Computer Science Educator micro-credentialing program developed by the state and University to aid in Computer science education.**\
\
**We will issue proof of stake micro-certificates as NFTs on Cardano. Once a student acquires all of the micro-cert NFTs in Stakepool Operation, they may trade those micro-certs in for a Stakpool Operators certificate, which will be recognized by the University and the Wyoming Department of Education.**\
\
**Benefits:** <br>

**Because there is currently funding in place trying to solve some of these problems, scholarships need to be developed for students that both obtain these certificates and enroll in an applicable UW program.**\
\
**Also, everything we develop will be open-source and can be easily forked and used as a template for other ambitious Secondary/Post-Secondary problems.**\
\
**This micro-certification NFT method can also easily be ported and used for many other things, such as learning a programming language, understanding eUTXO, minting NFTs, etc.**\ <br>

**Methods:**\
\
**We will develop a gitbook containing the micro-certification process for becoming a Cryptobounty Certified Stakepool Operator. This gitbook will be developed by High School students. This is going to be a living document, and will be kept up to date so it may best serve our needs over time.** \
\
\
\
\ <br>


# Cryptobounty Certified Pool Operator

The Cryptobounty Certified Pool Operator certification is aimed at High-School students that have developed expertise in specific areas of Cardano Stakepool operation.

Students with this certification will have demonstrated proficiency and obtained micro-certifications in the following areas:

* Node Security
* Key Management
* Node Configuration
* Node Management
* Node Monitoring

![](https://3553762444-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MkPr8yUlY3O49_8F3B5%2F-MkWbT5F0nNrzvTXQBC9%2F-MkWbbKbLTbVeOjDPbvU%2Fmicrocert%20example.jpg?alt=media\&token=c0cbfd7f-3de8-41e4-b6bb-2937bcdbdd83)


# Node Security

Part of maintaing node security is keeping up to date with Linux firewall management, OS hardening, and SSH hardening.

The Node Security Micro-Certification will be awarded to students that show proficiency in the following areas. ![image](https://user-images.githubusercontent.com/73705450/134786492-28f93603-5a4c-4aab-8ec6-eaa54cf880e4.png)

## Linux Firewall Managment

* block producer rules
* relay rules&#x20;

## Linux OS Hardening

## SSH Hardening

* keys&#x20;
* port change&#x20;
* intrusion prevention&#x20;
* 2 factor&#x20;


# Key Management

The Micro-Certification for key management is given to students that have achieved proficiency in the following topics:

![image](https://user-images.githubusercontent.com/73705450/134786679-6cd154b3-94c6-4e2b-8d5c-6089739ce1a9.png)

## Key Security

## Operating With Cold Keys

## Managing Hot Keys


# Node Configuration

Node configuration is a set of default parameters. They will be extended for different deployment environments.

The Micro-Certification for Node Configuration will be awarded to students who show proficiency in the following areas.

## Topology Configuration

## Genesis File Configuration

## Understanding the Node Configuration File

## Building the Node

## Starting the Node


# Node Management

A Micro-Credential will be awarded to students that show proficiency in the following facets of Node Management

![image](https://user-images.githubusercontent.com/73705450/134786529-d7026e1f-9382-4b06-abc4-b6dc21ba05c6.png)

## Chrony Configuration

## Node Automation and Process Management With Systemd

## Cardano-Cli basics


# Node Monitoring

![](https://3553762444-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MkPr8yUlY3O49_8F3B5%2F-MkTcrDV3htTtIGKRpzB%2F-MkTdj0D5Z6Ub4aDYA_o%2Fbnty1schoolmonitoring.png?alt=media\&token=bd1293e6-21fa-4fd6-81a1-6ded7048d4d5)

## Grafana Information

Grafana is a several platform open source analytics and interactive visualization application. It can provide charts, graphs, and alerts when connected to supported data sources.

## RTView Information

RTView is an application that allows you to see the state of running Cardano nodes in real-time.

## GLiveview Information

Guild LiveView (GLiveView) is a local monitoring tool to be used in addition to remote monitoring tools like Prometheus, Grafana, or IOG's RTView.

## Prometheus

Prometheus is important to monitoring your node because it queries your node and collects data


# General OS Hardening (Ubuntu 20.04 LTS)

```
ssh root@yourIPaddress
```

## Patching Software

```
sudo apt update
sudo apt upgrade
```

### Making New User

You will disable the root user becasue you have sudo

```
adduser "you"
```

Add that user to sudo group

```
usermod -aG sudo "you"
```

Change the logged root to create an account

```
su - username
```

Check to see if your user is part of sudo group

```
sudo whoami
```

If it returns root you now have sudo privlages

```
exit
exit
```

Now move the root account and log out of ssh. Log back in with the created user account.

```
ssh user@yourIPaddress
```

#### Locking root

Remove the root account from logging to ssh

```
sudo nano /etc/ssh/sshd_config
```

Find "PermitRootLogin" and change to "PermitRootLogin no"

Save and exit

Now restart ssh

```
sudo service ssh restart
```

Make sure if you try to log in with root again you get "permission denied"

**Change ssh port and lockout policy**

Check if firewall is enabled

```
sudo ufw status
```

Type in this if it is active

```
sudo ufw allow ssh
```

If you changed the port add this one too

```
sudo ufw allow ---
```

Now change the port

```
sudo nano /etc/ssh/sshd_config
```

Uncomment these lines and type in

```
Port ---
MaxAuthTries 5
```

You can change the max tries if need be. If the password is wrong more than 5 times it will lock out you IP address

Save and Exit

Restart ssh

```
sudo service ssh restart
```

To log back in you need to

```
ssh user@yourIPaddress -p "yourport"
```

**SSH Settings**

```
sudo nano /etc/ssh/sshd_config
```

First thing you are going to enable is Protocol 2

![image](https://user-images.githubusercontent.com/55625996/134785667-4b2dfdee-db1b-4a8c-b13d-778ca4f526cb.png)

```
sudo system restart ssh
```

Timeout Idle value

If you're AFK while connected to ssh there could be an issue. You can decrease or increase the time you can be idle.

```
ClientAliveInterval 180
```


# SSH Hardening

If you use Linux you most likely use SSH. SSH allows you to make connections without a password.

## Enable passwordless Authentication

```
PubkeyAuthentication yes
```

## Disable Password Authentication

```
PasswordAuthentication no
```

## Disable Empty Passwords

Some user accounts are created without passwords, administrators of linux machines can create standard users without passwords. SSH does not prevent empty passwords from being allowed.

```
PermitEmptyPasswords no
```

## Disable Root Login

```
PermitRootLogin no
```

## Defult SSH Port

```
Port 12345
```

## Allow Users and Groups\*\*

```
AllowUsers user1 user2
AllowGroups group1 group2
```

## Disable X11 Forwarding

X11 Forwarding allows anyone to tunnel GUI applications with SSH. You probably dont want that.

```
X11Forwarding no
```

## Disable Gateway Ports

```
GatewayPorts no
```

## Disable PermitUserEnvironment

```
PermitUserEnvironment no
```

## Disable Weak Cryptographic Algorithims

```
Ciphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr
KexAlgorithms curve25519-sha256@libssh.org,ecdh-sha2-nistp521
MACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512,hmac-sha2-256
```

```
Ciphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes256-ctr
KexAlgorithms curve25519-sha256@libssh.org,ecdh-sha2-nistp521
MACs hmac-sha2-512-etm@openssh.com,hmac-sha2-512****
```

> You can test support algorithims using nmap
>
> ```
> nmap -sV --script ssh2-enum-algos -p PORT TARGET
> ```

## Regenerate Host Keys

```
rm /etc/ssh/ssh_host_*
ssh-keygen -t rsa -b 4096 -f /etc/ssh/ssh_host_rsa_key -N ""
ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N ""
```

## Disable Host Keys

```
#HostKey /etc/ssh/ssh_host_dsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key
```

## Disable Small Diffie-Hellman Key Sizes

```
awk '$5 >= 3071' /etc/ssh/moduli > /etc/ssh/moduli.safe
mv /etc/ssh/moduli.safe /etc/ssh/moduli
```

## Disable SSHv1

```
Protocol 2
```


# Starting the Node

## Starting the Node

Follow these steps to get a relay node running and/or a block producer node

## Relay

```
cardano-node run \
--topology mainnet-topology.json \
--database-path /db \
--socket-path /db/node.socket \
--host-addr <PUBLIC IPv4 ADDRESS> \
--port <PORT> \
--config mainnet-config.json
```

## Block Producer

```
cardano-node run \
--topology mainnet-topology.json \
--database-path /db \
--socket-path /db/node.socket \
--host-addr <PUBLIC IP> \
--port <PORT> \
--config mainnet-config.json \
--shelley-kes-key kes.skey \
--shelley-vrf-key vrf.skey \
--shelley-operational-certificate node.cert
```


# Up and running the Systemd

{% hint style="info" %}
The "TopologyUpdater" service, is intended to be a temporary solution to allow everyone to activate their relay nodes without having to postpone and wait for manual topology completion requests.
{% endhint %}

The topologyUpdater shell script must be executed on the relay node as a cronjob exactly every 60 minutes. After 4 consecutive requests (3 hours) the node is considered a new relay node in listed in the topology file. If the node is turned off, it's automatically delisted after 3 hours.

## Download and Configure

If you have run prereqs.sh, this should already be available in your scripts folder and would make this step unnecessary.

```bash
cd $CNODE_HOME/scripts
curl -s -o topologyUpdater.sh https://raw.githubusercontent.com/cardano-community/guild-operators/master/scripts/cnode-helper-scripts/topologyUpdater.sh
curl -s -o env https://raw.githubusercontent.com/cardano-community/guild-operators/master/scripts/cnode-helper-scripts/env
chmod 750 topologyUpdater.sh
./topologyUpdater.sh
```

## Examine and modify the variables within topologyUpdater.sh script

the script may come with some adjustments, that may or may not be valid for your environment. One of the common changes would be to the complete CUSTOM\_PEERS section as below to include your local relays/BP nodes, and any additional peers you'd like to be always available at minimum. Take some time to update the variables in User Variables section in env & topologyUpdater.sh

## Systemd Service

The script can be deployed as a background service in different ways but the most recommended and easiest way is if prereqs.sh was used, utilize the deploy-as-systemd.sh script to setup and schedule the execution. This will deploy both push & fetch service files as well as timers for a scheduled 60 min node alive message and cnode restart at the user set time, with the default being 24 hours, when running the deploy script.

```bash
> cnode-tu-push.service : pushes a node alive message to Topology Updater API
> cnode-tu-push.timer : schedules the push service to execute once every hour
> cnode-tu-fetch.service : fetches a fresh topology file before the cnode.service file is started/restarted
> cnode-tu-restart.service : handles the restart of cardano-node (cnode.sh)
> cnode-tu-restart.timer : schedules the cardano-node restart service, default every 24h
```

this command can be used to to check the push and restart service schedule.

```bash
systemctl list-timers
```

## Crontab job

Another way to deploy the topologyUpdater.sh script is as a crontab job. Add the script to be executed once per hour at a minute of your choice. The example below will handle both the fetch and push in a single call to the script once an hour. In addition to the below crontab job for topologyUpdater, it's expected that you also add a scheduled restart of the relay node to pick up a fresh topology file fetched by topologyUpdater script with relays that are alive and well.

```bash
25 * * * * /opt/cardano/cnode/scripts/topologyUpdater.sh
```

## Logs

You can check the last result of push message in

```bash
logs/topologyUpdater_lastresult.json.
```

If deployed as systemd service, use

```bash
sudo journalctl -u <service>
```

to check output from service.

If one of the parameters is outside the allowed ranges, invalid, or missing, the returned JSON will tell you what needs to be fixed.

help from: <https://cardano-community.github.io/guild-operators/Scripts/topologyupdater/#deploy-the-script>


# Building the Node

## Building the Node

![image](https://user-images.githubusercontent.com/90267622/134788487-87f8b9a9-88cb-41ae-aa8e-98647d53e821.png)

Integration of the ledger, consensus, networking and node shell repositories.

Logging is provided as a feature by the node shell to the other packages.

The cardano-node is the top level for the node and aggregates the other components from other packages: consensus, ledger and networking, with configuration, CLI, logging and monitoring. The node no longer incorporates wallet or explorer functionality. The wallet backend and explorer backend are separate components that run in separate external processes that communicate with the node via local IPC.

## Network Configuration, Genesis and Topology Files

![image](https://user-images.githubusercontent.com/90267622/134778963-2972d4fe-5c21-4b3b-88ec-e8cd111f8b1c.png)

![image](https://user-images.githubusercontent.com/90267622/134778975-ec566ea2-7ca8-4af8-86bd-cb39b4b245cf.png)

Keep in mind that the latest supported networks can be found at <https://hydra.iohk.io/job/Cardano/cardano-node/cardano-deployment/latest-finished/download/1/index.html>

## How to build

![image](https://user-images.githubusercontent.com/90267622/134779709-56b66784-d191-48a5-93a7-6c7041ea5e08.png)

Documentation for building the node can be found at the following link

(<https://docs.cardano.org/getting-started/installing-the-cardano-node>)

Make sure that you download the latest version of cardano-node and cardano-cli.

<https://hydra.iohk.io/build/7760210> (Linux) <https://hydra.iohk.io/build/7760171> (Win64) <https://hydra.iohk.io/build/7760341> (Macos)

## Windows Executable

![image](https://user-images.githubusercontent.com/90267622/134779721-db3d5cb5-ff7f-488e-8fab-0d2e975ded92.png)

This can be downloaded from the following link. <https://hydra.iohk.io/build/7760171>

The download includes cardano-node.exe and a.dll. to run the node with cardano-node run you need to reference a few files and directories as arguments. You can just copy these directly from the cardano-node repo into the executables directory. The command to run the node on mainnet looks like this.

```
cardano-node.exe run --topology ./mainnet-topology.json --database-path ./state --port 3001 --config ./configuration-mainnet.yaml --socket-path \\.\pipe\cardano-node
```

## Docker image

![image](https://user-images.githubusercontent.com/90267622/134780022-86f9429f-f917-425a-b882-a118fbcb5a2f.png)

The docker image with the latest version of cardano-node is availible at the link below <https://hub.docker.com/r/inputoutput/cardano-node>

## cardano-node

![image](https://user-images.githubusercontent.com/90267622/134782733-55c138e1-8933-420b-8db5-bbff93a4d97d.png)

This refers to the client being used when running a node.

The general synopsis is as follows

```
Usage: cardano-node run [--topology FILEPATH] [--database-path FILEPATH]
                        [--socket-path FILEPATH]
                        [--byron-delegation-certificate FILEPATH]
                        [--byron-signing-key FILEPATH]
                        [--shelley-kes-key FILEPATH]
                        [--shelley-vrf-key FILEPATH]
                        [--shelley-operational-certificate FILEPATH]
                        [--host-addr IPV4-ADDRESS]
                        [--host-ipv6-addr IPV6-ADDRESS]
                        [--port PORT]
                        [--config NODE-CONFIGURATION] [--validate-db]
  Run the node.
```

• --topology - Filepath to a topology file describing which peers the node should connect to. • --database-path - path to the blockchain database.

• --byron-delegation-certificate - An optional path to the Byron delegation certificate. The certificate allows the delegator (The user of the certificate) to give his/her own block signing rights to somebody else (the delegatee). The delegatee can then sign blocks of behalf of the delegator

• --byron-signing-key - Optional path to the Byron signing key.

• --shelly-signing-key - Optional path to the Shelly signing key.

• --shelly-kes-key - Optional path to the shelly KES signing key.

• --shelly-vrf-key - Optional path to the Shelly VRF signing key.

• --shelly-operational-certificate - Optional path to the Shelly operation certificate. • --socket-path - Path to the socket file.

• --host-addr - Optionally specify your node's IPv4 address.

• --host-ipv6-addr - Optionally specify your node's IPv4 address.

• --port - Specify the filepath to the config .ymal file. This is the file that's responsible for all the other node's required settings. You can find examples in configuration (e.g. <https://github.com/input-output-hk/cardano-node/blob/master/configuration/defaults/simpleview/config-0.yaml>).

• --Validate-db - Flag to revalidate all on-disk database files

## Configuration .ymal files

![image](https://user-images.githubusercontent.com/90267622/134782794-ca5943a8-5eea-488d-923a-79517fa8b572.png)

The --config flag points to a .ymal file which is responsible to configurig the logging & other important settings for your node. E.g. see the Byron mainnet configuration in the following link. Some of the more important settings will be below the link.

<https://github.com/input-output-hk/cardano-node/blob/master/configuration/defaults/byron-mainnet/configuration.yaml>

• Protocol: RealPBFT -- The protocol the node will execute

• RequiresNetworkMagic: RequiresNoMagic -- Used to distinquish between the mainnet (RequiresNoMagic) and the testnets (RequiresMagic)

## Logging

![image](https://user-images.githubusercontent.com/90267622/134783031-5a544a51-6720-4c1a-b399-22ad2140310f.png)

Logs are output to the logs/ dir.

## Ptofiling & statistics

![image](https://user-images.githubusercontent.com/90267622/134783089-4e694488-7e07-43b8-807d-81e064499317.png)

Make sure you see scripts/README.md for how to obtain profiling information using the scripts.

## Scripts

![image](https://user-images.githubusercontent.com/90267622/134783124-e649b017-66ea-4759-81fe-ea063cf0c6d1.png)

Be sure you've seen scripts/README.md for information on the various scripts.

## Cardano-cli

![image](https://user-images.githubusercontent.com/90267622/134783185-ed1e2f78-a799-46cd-9b3d-32a1839f5807.png)

A CLI utility to support a variety of key material operations (genesis, migration, pretty-printing) for different system generations. Usage documentation can be found at the following link.

cardano-cli/README.md

The general synopsis is on the following line of code.

```
Usage: cardano-cli (Era based commands | Byron specific commands | Miscellaneous commands)
```

Keep in mind that the exact invocation command depends on the enviornment. If you only have cardano-cli bult, without installing it, then you have to prepend cabal run -- `before` cardano-cli. From now on we'll just assume that the necessary enviornment-specific adjustment has been made. Now you'll only have to mention cardano-cli.

The subcommands are subdivided in groups and their full name list is visible in the output of cardano-cli --help.

Remember that all the subcommands have help availible. An example is visible below.

```
cabal run -- cardano-cli -- byron key migrate-delegate-key-from --help

cardano-cli -- byron key migrate-delegate-key-from
Usage: cardano-cli byron key migrate-delegate-key-from --from FILEPATH
                                                       --to FILEPATH
  Migrate a delegate key from an older version.


Available options:
  --byron-legacy-formats   Byron/cardano-sl formats and compatibility
  --byron-formats          Byron era formats and compatibility
  --from FILEPATH          Signing key file to migrate.
  --to FILEPATH            Non-existent file to write the signing key to.
  -h,--help                Show this help text
```

## Genesis operations

![image](https://user-images.githubusercontent.com/90267622/134783751-f1769f64-a7b4-49d6-9906-1e72f481dc6e.png)

The Byron genesis operations will create a directory that contains all the following bullet points.

• genesis.json: The genesis JSON file itself.

• avvm-seed.\*.seed: Ada Voucher Vending Machine seeds (secret). Affected by --avvm-entry-count and --avvm-entry-balance.

• delegate-keys.\*.key: Delegate private keys. Affected by: --n-delegate-addresses.

• delegation-cert.\*.json: Delegation certificates. Affected by: --n-delegate-addresses.

• genesis-keys.\*.key: Genesis stake private keys. Affected by: --n-delegate-addresses, --total-balance.

• poor-keys.\*.key: Non-delegate private keys with genesis UTxO. Affected by: --n-poor-addresses, --total-balance.

More details on the Byron Genesis JSON file can be found in the following link

docs/reference/byron-genesis.md

Byron genesis delegation and related concepts are also described in detail in the link below

<https://hydra.iohk.io/job/Cardano/cardano-ledger-specs/byronLedgerSpec/latest/download-by-type/doc-pdf/ledger-spec>

## Key operations

![image](https://user-images.githubusercontent.com/90267622/134784005-257dd66b-7e1e-454d-9c32-1a6f8013ce36.png)

Note that key operations don't support password-protected keys.

## Signing key generation & verification key extraction

Signing kets can be generated using the keygen subcommand.

Extracting a verification key out of the signing key is preformed by the to verification subcommand.

## Delegate key migration.

![image](https://user-images.githubusercontent.com/90267622/134785027-c4bbc0b7-ce18-4039-a3b6-46db871733a3.png)

In order to continue using a delegate key from the Byron legacy era in the new implementation, it needs to be migrated over. That is done by the migrate-delegate-key-from the follwing subcommand.

```
$ cabal v2-run -- cardano-cli byron key migrate-delegate-key-from
        --from key0.sk --to key0Converted.sk
```

## Signing key queries

![image](https://user-images.githubusercontent.com/90267622/134785772-6c00af0e-0340-404f-bf04-261933aed549.png)

One can gather information about signing key's properties through the signing-key-public and signing-key-address subcommands. The latter of the two commands requires network magic.

```
$ cabal v2-run -- cardano-cli byron key signing-key-public --byron-formats --secret key0.sk

public key hash: a2b1af0df8ca764876a45608fae36cf04400ed9f413de2e37d92ce04
public key: sc4pa1pAriXO7IzMpByKo4cG90HCFD465Iad284uDYz06dHCqBwMHRukReQ90+TA/vQpj4L1YNaLHI7DS0Z2Vg==

$ cabal v2-run -- cardano-cli signing-key-address --byron-formats --secret key0.pbft --testnet-magic 42

2cWKMJemoBakxhXgZSsMteLP9TUvz7owHyEYbUDwKRLsw2UGDrG93gPqmpv1D9ohWNddx
VerKey address with root e5a3807d99a1807c3f161a1558bcbc45de8392e049682df01809c488, attributes: AddrAttributes { derivation path: {} }
```

### Transactions

![image](https://user-images.githubusercontent.com/90267622/134785869-687b7c3e-37ee-4cbf-a4d6-44f281eead75.png)

## Creation

Transactions can be created via the issue-genesis-utxo-expenditure and issue-utxo-expenditure commands.

The easiest way way to create a transactionis by using the scripts/benchmarking/issue-genesis-utxo-expenditure.sh script as follows.

./scripts/benchmarking/issue-genesis-utxo-expenditure.sh transaction\_file

NB: This by efault creates transactions based on configuration/defaults/liveview/config-0.yaml

If you don't have a genesis\_file you can run scripts/benchmarking/genesis.sh to create an example genesis file for you. The script scripts/benchmarking/issue-genesis-utxo-expenditure.sh has defaults for every requirement of the issue-genesis-utxo-expenditure command.

## Submission

The submit-tx subcommand gives you the option of submitting a pre-signed transaction in its war wire format. (See GenTx for Byron transactions)

The canned scripts/benchmarking/submit-tx.sh script submits the supplied transaction as a testnet launched by scripts/benchmarking/shelly-testnet-liveview\.sh script.

## Issuing UTxO expenditure (genesis and regular)

If you plan to make a transaction using UTxO, you can either the following subcommands directly ot you can use one of the canned scripts that make transactions tailored for the testnet cluster. Keep in mind that the first two commands are the directly used subcommands and the next two commands use the canned scripts.

• issue-genesis-utxo-expenditure (genesis UTxO) • issue-utxo-expenditure (normal UTxO)

• scripts/benchmarking/issue-genesis-utxo-expenditure.sh. • scripts/benchmarking/issue-utxo-expenditure.sh.

Keep in mind that the script requires the target file name so it can write the transaction to it input Txld (If you're using normal UTxO), as well as optionally allows specifying the source txin output index, source and target signing keys and lovelace value to send.

The target adress defaults to the 1-st richman key (configuration/delegate-keys.001.key) of the testnet, and lovelace amount is almost the entirety of its funds.

## Local node queries

![image](https://user-images.githubusercontent.com/90267622/134788550-28bcd4e2-4afd-445d-ae7c-70a61d12d4a9.png)

You can query the tip of your local node with the get-tip command. The instructions are listed below.

1. Open tmux
2. Run cabal build cardano-nano
3. Run ./scripts/lite/shelly-testnet.sh example
4. Run export CARDANO\_NODE\_SOCKET\_PATH=/cardano-node/example/socket/node-1-socket 4. `cabal exec cardano-cli -- get-tip --testnet-magic 42`

You should then see the output from the stdout in the format below.

```
Current tip:
Block hash: 4ab21a10e1b25e39
Slot: 6
Block number: 5
```

## Update proposals

![image](https://user-images.githubusercontent.com/90267622/134788564-baf5baf0-365f-4194-a83d-962efd46dd21.png)

A byron update proposal can be created with the command below

```
cardano-cli -- byron governance
               create-update-proposal
                 (--mainnet | --testnet-magic NATURAL)
                 --signing-key FILEPATH
                 --protocol-version-major WORD16
                 --protocol-version-minor WORD16
                 --protocol-version-alt WORD8
                 --application-name STRING
                 --software-version-num WORD32
                 --system-tag STRING
                 --installer-hash HASH
                 --filepath FILEPATH
               ..
```

The mandatory arguments for this to work are --mainnet | --testnet-magic, signing-key, protocol-version-major, protocol-version-minor, protocol-version-alt, application-name, software-version-num, system-tag, installer-hash and filepath.

Any remaining argument is an optional parameter you want to update in your update proposal.

You can also check your proposal's validity using the validate-cbor command. (Follow the link below) <https://github.com/input-output-hk/cardano-node#validate-cbor-files>

Look at the the following link for more details on update proposals.

<https://hydra.iohk.io/build/5737190/download/1/ledger-spec.pdf>

## Update proposal submission

You can submit your proposal using the submit-upadte-proposal command. An example is listed below

```
cardano-cli -- byron governance
            submit-update-proposal
            --config configuration/defaults/mainnet/configuration.yaml
            (--mainnet | --testnet-magic NATURAL)
            --filepath my-update-proposal
```

See the following link for more details on update proposals

<https://hydra.iohk.io/build/5737190/download/1/ledger-spec.pdf>

## Update proposal voting

![image](https://user-images.githubusercontent.com/90267622/134788569-0f3ac188-7983-4515-9b3c-ba8afbfb53f0.png)

You can create and submit byron update proposal votes woth the create-proposal-vote & submit-proposal-vote commands. Below are two examples of the commands.

Byron vote creation:

```
cabal exec cardano-cli -- byron governance create-proposal-vote
                       (--mainnet | --testnet-magic NATURAL)
                       --signing-key configuration/defaults/liveview/genesis/delegate-keys.000.key
                       --proposal-filepath ProtocolUpdateProposalFile
                       --vote-yes
                       --output-filepath UpdateProposalVoteFile
```

Byron vote submission:

```
cabal exec cardano-cli -- byron governance submit-proposal-vote
                       (--mainnet | --testnet-magic NATURAL)
                       --filepath UpdateProposalVoteFile
```

## Development

![image](https://user-images.githubusercontent.com/90267622/134788583-f8705bc4-de1b-4b4d-8190-6644c72c27a9.png)

GHCID

You can run ghcid with: ghcid -c "cabal repl exe:cardano-node --reorder-goals"

## Haskell Language Server

![image](https://user-images.githubusercontent.com/90267622/134788593-a575ad74-f01b-4780-bfba-94506aab06f1.png)

When using Haskell Language Server with Visual Studio code, you may find HLINT annotations ate ignore<https://github.com/haskell/haskell-language-server/issues/638>.

To work around this, you can run the script ./scripts/reconfigure-hlint.sh which will generate a .hlint.yaml file with HLINT ignore rules derived from the source code.

## Testing

![image](https://user-images.githubusercontent.com/90267622/134788602-9c2bc772-d8c0-48f7-9202-9a20bad27906.png)

Cardano-node is basically a container which implements several components such as networking, consensus, and storage. All of these components have individual test coverage. The node goes through integration and release testing by Devops/QA while automated CLI tests are ongoing alongside development.

Remember that developers on cardano-node can launch their own testnets (<https://github.com/input-output-hk/cardano-node/blob/master/doc/getting-started/launching-a-testnet.md>) or run the chairman tests (<https://github.com/input-output-hk/cardano-node/blob/master/doc/getting-started/running-chairman-tests.md>) locally.

### Debugging

## Pretty printing CBOR encoded files

![image](https://user-images.githubusercontent.com/90267622/134788619-fb60f4c4-f220-48d8-9306-a30547e6f574.png)

It may be useful if you print the on chain. representations of blocks, delegation certificates, txs and update proposals. There are two commands that do this (for any cbor encoded file.), though only one is listed directly below this line.

To pretty print as CBOR: cabal exec cardano-cli -- pretty-print-cbor --filepath CBOREncodedFile

## Validate CBOR files

You can validate Byron era blocks, delegation certificates, txs and update proposals with the validate-cbor command.

cabal exec cardano-cli -- validate-cbor --byron-block 21600 --filepath CBOREncodedByronBlockFile

### Native Tokens

![image](https://user-images.githubusercontent.com/90267622/134788626-5c4bda95-b3bb-4d1b-9ef6-ca34fdcc05a8.png)

Native tokens is a new feature that enables the transacting of multi-assets on Cardano. Native tokens are now supported on mainnet and users can transact with ada, and an unlimited number of user-defined (custom) tokens natively.

Below is a compiled list of resources which can help you get started.

<https://forum.cardano.org/c/developers/cardano-tokens/150>

<https://docs.cardano.org/native-tokens/learn>

additionally to that, you can read more about native token and how they compare to things like ada and ERC20 with the link below. Browse native tokens made on the Cardano blockchain itself as well as see their transactions in an interactive dashboard which allows filtering and searching: nativetokens.da.iogservices.io.

(<https://github.com/input-output-hk/cardano-ledger-specs/blob/master/doc/explanations/features.rst>)

### API Documentation

![image](https://user-images.githubusercontent.com/90267622/134788631-9b675491-f786-4208-a16c-035950095c0c.png)

The API documentation is published at the link below.

<https://input-output-hk.github.io/cardano-node/>

The documentation is built with each push, but is only published from the master branch. If you want to test if the documentation is working, you can build the documentation loccaly with ./scripts/haddocs.sh and ipen haddocs/index.html in the browser.

This guide takes heavy inspiration and much of it's information from the following guide. (<https://github.com/input-output-hk/cardano-node>}


# Managing Hot Keys

![image](https://user-images.githubusercontent.com/90267622/134778474-aa9ff649-cfde-4f7e-8d4f-5944249c7f8a.png)

To create an operational certificate for a block-producing node, you need a KES key pair.

KES stands for Key Evolving Signature in this situation. This means that after a certain period the key evolves into a new key and discards it's old version. This is a useful situation since if an attacker compromises the key and gains access to the signing key, they would only be able to use that key to sign blocks but blocks from earlier points would be safe so an attack couldn't rewrite history.

A KES key will only evolve after a certain number of periods and becomes useless afterwards. This means that until the number of periods has passed, the node operator will need to generate a new KES key pair, issue a new operational node certificate with that new key pair and then restart the node with the new certificate.

To find out how long one period is and for how long a key can evolve, you'll need to look into the genesis file. If that file is called mainnet-shelley-genesis.json, you can type

```
cat mainnet-shelley-genesis.json | grep KES
"slotsPerKESPeriod": 129600,
"maxKESEvolutions": 62,
```

This example has the key evolve after a period of 129600 slots and it can evolve 62 times before it needs to be renewd.

Before making an operational certificate for the node, you need to figure out the start of thr KES validity period which is just the KES evolution period you're in.

To check the current tip of the blockchain you'll use the following command.

```
cardano-cli query tip --mainnet

{
    "epoch": 259,
    "hash": "dbf5104ab91a7a0b405353ad31760b52b2703098ec17185bdd7ff1800bb61aca",
    "slot": 26633911,
    "block": 5580350
}
```

This example sets you in slot 26633911. You know from the genesis file that a single period lasts for 129600 slots. This lets you calculate the current period with this command

```
expr 26633911 / 129600
> 205
```

With that you should be able to generate an operational certificate for the stake pool:

```
cardano-cli node issue-op-cert \
--kes-verification-key-file kes.vkey \
--cold-signing-key-file cold.skey \
--operational-certificate-issue-counter cold.counter \
--kes-period 205 \
--out-file node.cert
```

Above guide based on (<https://github.com/input-output-hk/cardano-node/blob/master/doc/stake-pool-operations/KES_period.md>)


# Operating with Cold Keys

One of the primary things to keep in mind about cold keys is that they are often kept on cold nodes which are not connected to a main blockchain and are offline.

The primary use of cold keys is to generate a operational certificate along with the verification key and KES period.

This will show the code needed to generate an operational certificate or node.cert:

```
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 65 \
 --out-file node.cert
```

(The code used comes from <https://iohk.zendesk.com/hc/en-us/articles/900001209326-Node-s-operational-certificate-and-KES-period-stake-pools->)

![](https://user-images.githubusercontent.com/73238815/134784136-067cb02b-8117-4eb0-b9a3-422a27d670e7.png)


# Key Security

This guide page will go over some general tips regarding key security.

•Backup your private keys onto a text file, seperate directory, flash drive, or even a Google Doc. •These backups should only be accessable by you and cannot be very easily accessed by another. •It is typically a good idea to have at least two key backups, each in a different place.

![](https://user-images.githubusercontent.com/73238815/134782699-91068a86-89e4-4e9b-87df-adf034b0bd20.png)


# Node Monitoring with Prometheus

## Node Monitoring with Prometheus

```bash
mainnet-config.json
```

```bash
nano mainnet-config.json
```

### In this file search for

"hasPrometheus": \[ "127.0.0.1", 12798 ],

## Replace the IP address 127.0.0.1 with 0.0.0.0 to allow listening for external connections.

It should look like this afterwards... "hasPrometheus": \[ "0.0.0.0, 12798 ],

```bash
cd ~
mkdir Downloads
cd Downloads
```

```bash
wget https://github.com/prometheus/node_exporter/releases/download/v1.0.1/node_exporter-1.0.1.linux-amd64.tar.gz
tar xvfz node_exporter-1.0.1.linux-amd64.tar.gz
rm node_exporter-1.0.1.linux-amd64.tar.gz
cd node_exporter-1.0.1.linux-amd64
```

```bash
sudo ufw allow proto tcp from IP.OF.MONITORING.SERVER to any port 9100
sudo ufw allow proto tcp from IP.OF.MONITORING.SERVER to any port 12798
```

```bash
./node_exporter
```

### You are now preparing your monitoring server

```bash
cd ~
mkdir Downloads
cd Downloads
wget https://github.com/prometheus/prometheus/releases/download/v2.22.2/prometheus-2.22.2.linux-amd64.tar.gz
tar xvfz prometheus-2.22.2.linux-amd64.tar.gz
rm prometheus-2.22.2.linux-amd64.tar.gz
cd prometheus-2.22.2.linux-amd64/
```

```bash
nano prometheus.yml
```

### We stick as closely as possible to official cardano documentation. Edit your file to look like this:

### my global config

```bash
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
external_labels:
monitor: 'codelab-monitor'
```

### scrape\_timeout is set to the global default (10s).

### Alertmanager configuration

```bash
alerting:
alertmanagers:
- static_configs:
- targets:
```

### - alertmanager:9093

### Load rules once and periodically evaluate them according to the global 'evaluation\_interval'.

rule\_files:

### - "first\_rules.yml"

### - "second\_rules.yml"

### A scrape configuration containing exactly one endpoint to scrape:

### Here it's Prometheus itself.

### The job name is added as a label `job=` to any timeseries scraped from this config.

Please edit this one before pressing enter.

```bash
scrape_configs:
- job_name: 'cardano_relay1'
scrape_interval: 5s
static_configs:
- targets: ['IP.OF.YOUR.RELAY1:12798']
- job_name: 'node_relay1' 
scrape_interval: 5s
static_configs:
- targets: ['IP.OF.YOUR.RELAY1:9100']
```

### Now for your second relay remember please edit this.

```bash
- job_name: 'cardano_relay2'e
scrape_interval: 5s
static_configs:
- targets: ['IP.OF.YOUR.RELAY2:12798']
- job_name: 'node_relay2' 
scrape_interval: 5s
static_configs:
- targets: ['IP.OF.YOUR.RELAY2:9100']
```

### Please edit

```bash
- job_name: 'cardano_block'
scrape_interval: 5s
static_configs:
- targets: ['IP.OF.YOUR.BLOCKPRODUCER:12798']
- job_name: 'node_relay2' 
scrape_interval: 5s
static_configs:
- targets: ['IP.OF.YOUR.BLOCKPRODUCER:9100']
```

### Thereafter, still on your monitoring server, you need to open two ports so that you can access the statistics in your browser and from any device you want.

```bash
sudo ufw allow proto tcp from any to any port 3000
sudo ufw allow proto tcp from any to any port 9090
```

{% hint style="info" %}
Recap-Port 3000 is used by Grafana. After completing the setup you should be able to view the dashboard of Grafana from any client by opening IP.FROM.MONITORING.SERVER:3000 in your browser. Port 9090 is used by Prometheus. After completing the setup you should be able to view prometheus from any client by opening IP.FROM.MONITORING.SERVER:9090 in your brows
{% endhint %}

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

In your client browser, open IP.FROM.MONITORING.SERVER:9090. You should see the landing page of prometheus. Click on Status -> Targets to view your nodes. The state of all your node jobs should be "up"

When prometheus is working, you can continue with the next step: download and install grafana and start it.

```bash
cd ~/Downloads
wget https://dl.grafana.com/oss/release/grafana-7.3.2.linux-amd64.tar.gz
tar -zxvf grafana-7.3.2.linux-amd64.tar.gz
rm grafana-7.3.2.linux-amd64.tar.gz
cd grafana-7.3.2
cd bin
./grafana-server
```

```bash
In the next step you need to add prometheus as data source. Click on:
```

![image](https://user-images.githubusercontent.com/73615683/134784052-d363489a-e919-46e9-ad23-5bc3a658d707.png)

```bash
In the next screen click on prometheus
```

![image](https://user-images.githubusercontent.com/73615683/134784057-885e1f5f-5c67-406a-9980-d07e11bb46e4.png)

```bash
In the next step, fill out the form as below. Please be careful: prometheus must be written lowercase! Otherwise your dashboard won't work!
```

![image](https://user-images.githubusercontent.com/73615683/134784067-7932c965-2acd-4d6b-b763-46694860c6a1.png)

```bash
In the next step, we need to import the precombiled dashboard of IOHK.
Copy cardano-application-dashboard-v2.json from the cardano-ops repository to your clipboard.
In grafana, in the left menu, click on Dashboards -> Manage.
```

![image](https://user-images.githubusercontent.com/73615683/134784082-111a3bcf-20be-49a6-913e-63dba902e2de.png)

```bash
In the next page, at the top right corner, click on Import and paste your clipboard to the textarea appearing in the next screen..
```

![image](https://user-images.githubusercontent.com/73615683/134784114-054428db-a754-4f1d-adb6-6a00d525357f.png)

```bash
Click on Load.
Go back to your welcome screen of Grafana. You should now be able to open your metrics by clicking Cardano: Application metrics v2.
```

![image](https://user-images.githubusercontent.com/73615683/134784134-85ba2a27-1da7-46f2-ab09-e00abe7fbf39.png)

#### That is all that I have for you now good luck.

link:<https://www.cardanocafe.org/blog/knowledge-base-cardano/how-to-setup-prometheus-grafana-monitor-cardano-nodes> This is where I got my information


# Displaying Node Metrics with Grafana

## What you need before beginning Grafana setup

<https://docs.docker.com/get-docker/>

<https://docs.docker.com/compose/> (included in Docker for Desktop for macOS and Windows)

<https://git-scm.com/>

## Setting up

This guide uses a sample application from the grafana fundamentals tutorial. In this step supporting services such as Prometheus and Loki will also be set up. To complete the exercises in this guide, you need to download the files to your local machine

Clone the github.com/grafana/tutorial-environment repository.

```bash
git clone https://github.com/grafana/tutorial-environment.git
```

Now change to the directory where you cloned this repository

```bash
cd tutorial-environment
```

Make sure Docker is running

```bash
docker ps
```

No errors means it is running. If you get an error, then start Docker and then run the command again.

Start the sample application:

```bash
docker-compose up -d
```

The first time you run docker-compose up -d, Docker downloads all the necessary resources for the tutorial. This might take a few minutes, depending on your internet connection.

{% hint style="info" %}
If you already have Grafana, Loki, or Prometheus running on your system, then you might see errors because the Docker image is trying to use ports that your local installations are already using. Stop the services, then run the command again.
{% endhint %}

Ensure all services are running:

```bash
docker-compose ps
```

In the State column, it should say Up for all services.

Browse to the sample application on localhost:8081.

## Grafana News

The sample application, Grafana News, lets you post links and vote for the ones you like. To add a link: In Title, enter {Example}. In URL, enter <https://example.com>. Then Click Submit to add the link.

## Log in to Grafana

Grafana is an open-source platform for monitoring and observability that lets you visualize and explore the state of your systems. Open a new tab. Browse to localhost:3000. Enter the username and password as admin, then log in. The first time you log in, it asks you to change your password. Remember to click Save. The first thing you see is the Home dashboard, which helps you get started. To the far left you can see the sidebar, a set of quick access icons for navigating Grafana.

## Add a metrics data source

The sample application exposes metrics which are stored in Prometheus. To be able to visualize the metrics from Prometheus, you first need to add it as a data source in Grafana. In the side bar, hover your cursor over the Configuration (gear) icon, and then click Data Sources and then click add data source. In the list of data sources, select Prometheus. In the URL box, enter <http://prometheus:9090>, then save. Prometheus should now available as a data source in Grafana.

## Exploring your metrics

Grafana Explore is a workflow for troubleshooting and data exploration. In this step, you’ll be using Explore to create ad-hoc queries to understand the metrics exposed by the sample application. Ad-hoc queries are queries that are made interactively, with the purpose of exploring data. An ad-hoc query is commonly followed by another, more specific query. In the side bar, click the Explore (compass rose) icon. In the Query editor, where it says Enter a PromQL query, enter

```bash
tns_request_duration_seconds_count
```

and then press Shift + Enter. A graph appears. In the top right corner, click the dropdown arrow on the Run Query button, and then select 5s. Grafana runs your query and updates the graph every 5 seconds. You just made your first PromQL query! PromQL is a powerful query language that lets you select and aggregate time series data stored in Prometheus.

tns\_request\_duration\_seconds\_count is a counter, a type of metric whose value only ever increases. Rather than visualizing the actual value, you can use counters to calculate the rate of change, i.e. how fast the value increases.

Add the rate function to your query to visualize the rate of requests per second. Enter the following in the Query editor and then press Shift + Enter.

```bash
rate(tns_request_duration_seconds_count[5m])
```

Immediately below the graph there’s an area where each time series is listed with a colored icon next to it. This area is called the legend. PromQL lets you group the time series by their labels, using the sum function.

Add the sum function to your query to group time series by route:

```bash
sum(rate(tns_request_duration_seconds_count[5m])) by(route)
```

Go back to the sample application and generate some traffic by adding new links, voting, or just refresh the browser. In the upper right corner, click the time picker, and select Last 5 minutes. By zooming in on the last few minutes, it’s easier to see when you receive new data, Depending on your use case, you might want to group on other labels. Try grouping by other labels, such as status\_code, by changing the by(route) part of the query.

## Add a logging data source

Grafana supports log data sources, like Loki. Just like for metrics, you first need to add your data source to Grafana.

Just like before, In the side bar, click the configuration icon, Data Sources, add, but this time click Loki. In the URL box, enter <http://loki:3100>. Click Save & Test to save your changes. And now Loki is now available as a data source in Grafana.

## Explore your logs

Grafana Explore not only lets you make ad-hoc queries for metrics, but lets you explore your logs as well. In the side bar, click the Explore (compass) icon. In the data source list at the top, select the Loki data source.

In the Query editor, enter:

```bash
{filename="/var/log/tns-app.log"}
```

Grafana displays all logs within the log file of the sample application. The height of each bar encodes the number of logs that were generated at that time. Click and drag across the bars in the graph to filter logs based on time. Not only does Loki let you filter logs based on labels, but on specific occurrences. Let’s generate an error, and analyze it with Explore. In the sample application, post a new link without a URL to generate an error in your browser that says empty url.

Go back to Grafana and enter the following query to filter log lines based on a substring:

```bash
{filename="/var/log/tns-app.log"} |= "error"
```

Click on the log line that says level=error msg="empty url" to see more information about the error. Logs are helpful for understanding what went wrong. Later in this guide, you’ll see how you can correlate logs with metrics from Prometheus to better understand the context of the error.

## Build a dashboard

A dashboard gives you an at-a-glance view of your data and lets you track metrics through different visualizations. Dashboards consist of panels, each representing a part of the story you want your dashboard to tell. Every panel consists of a query and a visualization. The query defines what data you want to display, whereas the visualization defines how the data is displayed. In the side bar, hover your cursor over the Create (plus sign) icon and then click Dashboard. Click Add new panel.

In the Query editor below the graph, enter the query from earlier and then press Shift + Enter:

```bash
sum(rate(tns_request_duration_seconds_count[5m])) by(route)
```

In the Legend field, enter  to rename the time series in the legend. The graph legend updates when you click outside the field. In the Panel editor on the right, under Settings, change the panel title to “Traffic”. Click Apply in the top-right corner to save the panel and go back to the dashboard view. Click the Save dashboard (disk) icon at the top of the dashboard to save your dashboard. Enter a name in the New name field and then click Save.

## Annotate events

When things go bad, it often helps if you understand the context in which the failure occurred. Time of last deploy, system changes, or database migration can offer insight into what might have caused an outage. Annotations allow you to represent such events directly on your graphs. In the next part of the tutorial, we will simulate some common use cases that someone would add annotations for. To manually add an annotation, click anywhere in your graph, then click Add annotation. In Description, enter Migrated user database. Click Save. Grafana adds your annotation to the graph. Hover your mouse over the base of the annotation to read the text. Grafana also lets you annotate a time interval, with region annotations.

Add a region annotation

Press Ctrl (or Cmd on macOS), then click and drag across the graph to select an area. In Description, enter Performed load tests. In Tags, enter testing. Manually annotating your dashboard is fine for those single events. For regularly occurring events, such as deploying a new release, Grafana supports querying annotations from one of your data sources. Let’s create an annotation using the Loki data source we added earlier. At the top of the dashboard, click the Dashboard settings (gear) icon. Go to Annotations and click Add Annotation Query. In Name, enter Errors. In Data source, select Loki.

In Query, enter the following query:

```bash
{filename="/var/log/tns-app.log"} |= "error"
```

Click Add. Grafana displays the Annotations list, with your new annotation. Click the Go back arrow to return to your dashboard. The log lines returned by your query are now displayed as annotations in the graph. Being able to combine data from multiple data sources in one graph allows you to correlate information from both Prometheus and Loki.

## Set up an alert

Alerts allow you to identify problems in your system moments after they occur. By quickly identifying unintended changes in your system, you can minimize disruptions to your services. Alerts consists of two parts:

Notification channel - How the alert is delivered. When the conditions of an alert rule are met, the Grafana notifies the channels configured for that alert. Alert rules - When the alert is triggered. Alert rules are defined by one or more conditions that are regularly evaluated by Grafana.

## Configure a notification channel

In this step, you’ll send alerts using web hooks. To test your alerts, you first need to have a place to send them.

Browse to requestbin.com. Under the Create Request Bin button, click the public bin link. You request bin is now waiting for the first request. Copy the endpoint URL. Next, configure a notification channel for web hooks to send notifications to your Request Bin.

In the side bar, hover your cursor over the Alerting (bell) icon and then click Notification channels. Click Add channel. In Name, enter RequestBin. In Type, select webhook. In Url, paste the endpoint to your request bin. Click Send Test to send a test alert to your request bin. Navigate back to the request bin you created earlier. On the left side, there’s now a POST / entry. Click it to see what information is sent by Grafana. Click Save.

## Configure an alert rule

Now that Grafana knows how to notify you, it’s time to set up an alert rule: In the sidebar, click Dashboards -> Manage.

Click the dashboard you created earlier. Click the Traffic panel title and then click Edit. Click the Alert tab under the graph to access the settings for alerting. Click Create Alert. In Name, enter My alert. In Evaluate every, enter 5s. For the purpose of this tutorial, the evaluation interval is intentionally short to make it easier to test. In For, enter 0m. This setting makes Grafana wait until an alert has fired for a given time, before Grafana sends the notification. In the Conditions section, you can change the white text by clicking it and then choosing a new option or typing text in the blank field.

Change the alert condition to: WHEN last() OF query(A, 1m, now) IS ABOVE 0.2

This condition evaluates whether the last value of any of the time series from one minute back is more than 0.2 requests per second. In the Notifications section, click the plus sign (+) next to Send to and then click RequestBin. Click the Go back arrow and then click the Save dashboard icon. Enter a note to describe your changes. Something like, Added My alert. Notes like this are optional, but can be useful when trying to understand changes made to dashboards over time.

You now have an alert set up to send a notification using a web hook. See if you can trigger it by generating some traffic on the sample application. Browse to localhost:8081. Refresh the page repeatedly to generate traffic. When Grafana triggers the alert, it sends a request to the web hook you set up earlier. Browse to the Request Bin you created earlier, to inspect the alert notification.

## Pause an alert

Once you’ve acknowledged an alert, consider pausing it. This can be useful to avoid sending subsequent alerts, while you work on a fix. In the Grafana side bar, hover your cursor over the Alerting icon and then click Alert Rules. All the alert rules configured so far are listed, along with their current state. Find your alert in the list, and click the Pause icon on the right. The Pause icon turns into a Play icon. Click the Play icon to resume evaluation of your alert. Clean up the local environment The guide has running Docker containers. When you want to clean up this local tutorial environment, run

```bash
docker-compose down -v
```

## Summary

In this guide you learned about fundamental features of Grafana.

help from: <https://grafana.com/tutorials/grafana-fundamentals/>


# Using RTView

RTView is a separate application: you should download, configure, and launch it separately from your node. RTView is a program implemented in the Haskell programming language.

## Set up

First you will need to download a release package and unpack it, inside will be an executable cardano-rt-view

{% hint style="info" %}
macOS notes: To prevent a system warning about "an application downloaded from the Internet", run this command:

```bash
xattr -r -d com.apple.quarantine cardano-rt-view-*-darwin/*
```

{% endhint %}

<https://github.com/input-output-hk/cardano-rt-view/releases>

Or you can build it from source, which will be explained more in depth here.

<https://github.com/input-output-hk/cardano-rt-view/blob/master/doc/getting-started/building-rt-view-from-sources.md>

## Configuration

This guide assumes that you already have at least one instance of cardano-node, if not go read the offical cardano documentation.

After you run an executable cardano-rt-view, an interactive dialog will be started:

```bash
RTView: real-time watching for Cardano nodes

Let's configure RTView...
```

The first question is:

```bash
How many nodes will you connect (1 - 99, default is 3):
```

Now input the amount of cardano-node process that will forward their metrics to RTView

Next question is:

```bash
Input the names of the nodes (default are "node-1", "node-2", "node-3"), one at a time:
```

From RTView's point of view, each cardano-node process that forwards its metrics to RTView, should be identified by a unique name. You can use any name you want.

{% hint style="danger" %}
Note that the names must not include spaces or dots!
{% endhint %}

The next one is:

```bash
Indicate the port for the web server (1024 - 65535, default is 8024):
```

Please input the port RTView will use to display the web-page. For example, if you keep the default port 8024, the web-page will be available on <http://127.0.0.1:8024>.

The next question is:

```bash
Indicate how your nodes should be connected with RTView: networking sockets <S> or named pipes <P>."
Default way is sockets, so if you are not sure - choose <S>:
```

Please choose the way how the nodes should be connected to RTView.

If you chose S, you will be asked about the base port:

```bash
Ok, sockets will be used. Indicate the base port to listen for connections (1024 - 65535, default is 3000):
```

The base port will be used for the first node that forwards its metrics to RTView. For example, if you will launch three cardano-node processes (node-1, node-2, and node-3) that will forward their metrics using network sockets, this is how they will be connected to RTView:

node-1 -> 0.0.0.0:3000 node-2 -> 0.0.0.0:3001 node-3 -> 0.0.0.0:3002 Bit if you selected P, you will be asked about the directory when pipes will be created:

```bash
Ok, pipes will be used. Indicate the directory for them, default is "/run/user/1000/rt-view-pipes":
```

Next question is:

```bash
Now, indicate a host of machine RTView will be launched on (default is 0.0.0.0):
```

If your nodes are launched on the same machine with RTView, you can choose the default address. But if RTView will be launched on another machine, please specify its reachable public IP address. It will allow your nodes to connect with RTView. In this case, it is assumed that a machine with RTView is accessible using that IP address.

The last question is:

```bash
Indicate the directory with static content for the web server, default is "static":
```

Since RTView displays nodes' metrics on the web-page, it uses static web content (CSS, JS, images). By default, it's static directory that is included in the archive you've downloaded. Then you will see this message:

```bash
Great, RTView is ready to run! Its configuration was saved at PATH_TO/rt-view.yaml. Press <Enter> to continue...
```

where PATH\_TO is the full path to the default system configuration directory. After you pressed Enter, RTView will show all the changes you have to make in your node(s) configuration file(s). For example, if you chose all default values on Linux, you will see this:

```bash
Now you have to make the following changes in your node's configuration file:

1. Find TurnOnLogMetrics flag and make sure it is true:

   "TurnOnLogMetrics": true

2. Since you have 3 nodes, add following traceForwardTo sections in the root of their configuration files:

   "traceForwardTo": {
     "tag": "RemoteSocket",
     "contents": [
       "0.0.0.0",
       "3000"
     ]
   }

   "traceForwardTo": {
     "tag": "RemoteSocket",
     "contents": [
       "0.0.0.0",
       "3001"
     ]
   }

   "traceForwardTo": {
     "tag": "RemoteSocket",
     "contents": [
       "0.0.0.0",
       "3002"
     ]
   }

After you are done, press <Enter> to run RTView...
```

After you pressed Enter, RTView will be launched, and you can open <http://127.0.0.1:8024> (if you chose default web-port) and see the web-page.

help from: <https://github.com/input-output-hk/cardano-rt-view>


# Cardano-Cli Basics

## Cardano-Cli Basics

## Set of Cardano-cli Sub Commands

**address:** Shelley payment address commands

**stake-address:** Shelley stake address commands

**transaction:** Shelley transaction commands

**node:** Shelley node operation commands

**stake-pool:** Shelley stake pool commands

**query:** Shelley node query commands. This queries the local node whose Unix domain socket is obtained from the CARDANO\_NODE\_SOCKET\_PATH environment variable.

**block:** Shelley block commands

**system:** Shelley system commands

**genesis:** Shelley genesis block commands

**text-view:** commands for dealing with Shelley text view files that are stored on disk such as transactions or addresses

**governance:** Shelley governance commands

## Cardano-cli Address Sub Commands

**key-gen:** creates a single address key pair

**key-hash:** prints the hash of an address to stdout

**build:** builds a Shelley payment address, with optional delegation to a stake address

**build-multisig:** builds a Shelley payment multi-sig address.

**info:** prints details about the address

## Cardano-clistake address Sub Commands

**key-gen:** creates a single address key pair

**build:** builds a stake address

**register:** registers a stake address

**delegate:** delegates from a stake address to a stake pool

**de-register:** de-registers a stake address

**registration-certificate:** creates a registration certificate

**delegation-certificate:** creates a stake address delegation certificate

**deregistration-certificate:** creates a de-registration certificate

## Cardano-cli Transaction Sub Commands

**build-raw:** builds a low-level transaction

**sign:** signs the transaction

**witness:** witnesses a transaction

**sign-witness:** signs and witnesses a transaction

**check:** checks the transaction

**submit:** submits the transaction to the local node whose Unix domain socket is obtained from the CARANO\_NODE\_SOCKET\_PATH environment variable.

**calculate-min-fee:** calculates the minimum fee for the transaction

**info:** prints information about the transaction

## Cardano-cli Node Sub Commands

**key-gen:** creates a key pair for a node operator’s offline key and a new certificate issue counter

**key-gen-KES:** creates a key pair for a node KES operational key

**key-gen-VRF:** creates a key pair for a node VRF operational key

**issue-op-cert:** issues a node operational certificate

## Cardano-cli Stakepool Sub Commands

**register:** registers a stake pool

**re-register:** re-registers a stake pool

**retire:** retires a stake pool

**registration-certificate:** creates a stake pool registration certificate

**de-registration-certificate:** creates a stake pool de-registration certificate

**id:** builds pool id from the offline key

## Cardano-cli Query Sub Commands

**pool-id:** retrieves the node’s pool ID

**protocol-parameters:** retrieves the node’s current pool parameters

**tip:** gets the node’s current tip (slot number, hash, and block number)

**utxo:** retrieves the node’s current UTxO, filtered by address

**version:** retrieves the node’s version details

**status:** retrieves the current status of the node

**ledger-state:** dumps the current state of the node

**stake-address-info:** get the current delegations and reward accounts filtered by stake address.

**stake-distribution:** get the node's current aggregated stake distribution

## Cardano-cli Block Sub Commands

**info:** retrieves the pool ID that produced a particular block.

### Cardano-cli System Sub Commands

**start:** starts the system

**stop:** stops the system

## Cardano-cli Governence

**create-mir-certificate:** creates an MIR (move instantaneous rewards) certificate

**create-update-proposal:** creates an update proposal

**protocol-update:** performs a protocol update

**cold-keys:** retrieves the cold keys

## Cardano-cli Genisis

**key-gen-genesis:** creates a Shelley genesis key pair

**key-gen-delegate:** creates a Shelley genesis delegate key pair

**key-gen-utxo:** creates a Shelley genesis UTxO key pair

**key-hash:** prints the identifier, or hash, of a public key

**get-ver-key:** derives verification key from a signing key

**initial-addr:** gets the address for an initial UTxO based on the verification key

**initial-txin:** gets the transaction ID for an initial UTxO based on the verification key.

**create:** creates a Shelley genesis file from a genesis template, as well as genesis keys, delegation keys, and spending keys.


# 3rd Party Monitoring Tools (gLiveview, etc.)

If you've used prereqs.sh, you can skip this part, as this is already set up for you. The tool relies on the common env configuration file. To get current epoch blocks, the logMonitor.sh script is needed (and can be combined with CNCLI). This is optional and Guild LiveView will function without it.

-Helpful websites- <https://cardano-community.github.io/guild-operators/Scripts/gliveview/>


# Chrony Configuration

To start go to <https://chrony.tuxfamily.org/download.html> and download the latest version of chrony.

Then edit the /etc/chrony/chrony.conf file to look like this:

```
# 3 sources per time servers.
pool ntp.ubuntu.com        iburst maxsources 3
pool time.nist.gov         iburst maxsources 3
pool us.pool.ntp.org       iburst maxsources 3

keyfile /etc/chrony/chrony.keys

driftfile /var/lib/chrony/chrony.drift

logdir /var/log/chrony

maxupdateskew 10.0

rtcsync

# Make steps in 100ms.
makestep 0.1 3
```

Then restart chrony:

```
systemctl start chrony
```

Next edit /etc/sysctl.conf to look like this:

```
fs.file-max = 10000000
fs.nr_open = 10000000

net.core.netdev_max_backlog = 100000
net.core.somaxconn = 100000
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.ip_local_port_range = 1024 65535
net.ipv4.ip_nonlocal_bind = 1
net.ipv4.tcp_fin_timeout = 10
net.ipv4.tcp_keepalive_time = 300
net.ipv4.tcp_max_orphans = 262144
net.ipv4.tcp_max_syn_backlog = 100000
net.ipv4.tcp_max_tw_buckets = 262144
net.ipv4.tcp_mem = 786432 1697152 1945728
net.ipv4.tcp_reordering = 3
net.ipv4.tcp_rmem = 4096 87380 16777216
net.ipv4.tcp_sack = 0
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_syn_retries = 5
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_wmem = 4096 16384 16777216

net.netfilter.nf_conntrack_max = 10485760
net.netfilter.nf_conntrack_tcp_timeout_fin_wait = 30
net.netfilter.nf_conntrack_tcp_timeout_time_wait = 15

vm.swappiness = 10
```

Afterwards, edit /etc/security/limits.conf to this:

```
root               soft    nofile            32768
<CHANGE TO THE USERNAME WHO RUNS JORMUNGANDR>            soft    nofile            32768
<CHANGE TO THE USERNAME WHO RUNS JORMUNGANDR>            hard    nofile            1048576
```

If your service starts with systemctl then edit /etc/systemd/system/.service to something along the lines of:

```
[Unit]
Description=Shelley Staking Pool
After=multi-user.target

[Service]
Type=simple
ExecStart=<YOUR_NODE_START_SCRIPT>

# 16K Or more
LimitNOFILE=16384

Restart=on-failure
RestartSec=5s
User=<CHANGE TO THE USER ID WHO RUNS JORMUNGANDR>
Group=users

[Install]
WantedBy=multi-user.target
```

And run:

```
systemctl daemon-reload && systemctl enable shelley && systemctl start shelley
```

{% hint style="info" %}
Remove comment above LimitNOFILE
{% endhint %}

Finally, allow the bare minimum of firewall allowance with this:

```
ufw allow <YOUR_NODE_LISTENING_PORT: default: 3000>/tcp
ufw allow <WHERE YOUR SSH SRV IS LISTENING default:22>/tcp
```

This guide was heavily inspired by <https://gist.github.com/ilap/54027fe9af0513c2701dc556221198b2>


# Firewall Configurations

The UFW firewall can be used to control the network access to your node With any new installation, UFW is disabled by default. You will have to enable it with the following steps:

Deny any incoming and outgoing traffit

```
 sudo ufw default deny incoming 
 sudo ufw default allow outgoing
```

Allow ssh access

```
 sudo ufw allow ssh (port 22 or your ssh port number) /tcp
```

Allow cardano-node p2p port

```
 sudo ufw allow (your port #) /tcp
```

Allow chrony ntp

```
 sudo ufw allow 123/udp
```

Enable Firewall

```
 sudo ufw enable
```

Verify status

```
 sudo ufw status numbered
```

Only open these following ports on nodes behind a network firewall Allow grafana web server port

```
 sudo ufw allow 3000/tcp
```

Allow prometheus endpoint port

```
 sudo ufw allow 9100/tcp
```

Allow prometheus cardano-node metric data port

```
 sudo ufw allow 12798/tcp
```

This next step is optional but recomended to follow Permitting connections from a specific IP can be set up by following these next commands

```
 sudo ufw allow (your laptop)
```

Example

* sudo ufw allow from (182.382.84.22)


# Configuration, Topology, Genesis

Starting the node and connecting it to the testnet requires three configuration files:

## config.json

This file defines what a node does, and includes the following four sub sections:

Basic node configuration, this declares the basic node configuration parameters. The basic configuration section might look like this:

```bash
{
  "Protocol": "TPraos",
  "GenesisFile": "ff-genesis.json",
  "RequiresNetworkMagic": "RequiresMagic",
```

Update parameters, Block-producing nodes use a protocol version number as part of the system for the agreement and synchronization of protocol updates. When configuring this section, you need to be aware of the latest version of the protocol supported by the network The update parameters section might look like this:

```bash
  "ApplicationName": "cardano-sl",
  "ApplicationVersion": 0,
  "LastKnownBlockVersion-Alt": 0,
  "LastKnownBlockVersion-Major": 2,
  "LastKnownBlockVersion-Minor": 0,
```

Tracing, Tracers tell the node what information you are interested in when logging. For example, switches that you can turn ON or OFF according to the type and quantity of information that you are interested in. This provides fairly coarse-grained control, but it is relatively efficient at filtering out unwanted trace output.

Logging control, It is possible to have more fine-grained control over filtering of trace output, and to match and route trace output to particular backends. This is less efficient than the coarse trace filters, but offers precise control options.

## topology.json

The information contained in this file tells the node which nodes in the network it should talk to.

A simple topology file might look like this:

```bash
   {
  "Producers": [
    {
      "addr": "x.x.x.x",
      "port": 3001,
      "valency": 1
    }
  ]
}
```

## genesis.json

The genesis file is generated with the cardano-cli by reading a genesis.spec.json file.

The genesis file is very important, as it sets four key parameters:

genDelegs: maps from genesis keys to genesis delegates. initialFunds: maps from the initial addresses to the initial values at those addresses. MaxLovelaceSupply: the total amount of lovelaces in the blockchain. startTime: the time of slot zero.


