# Anatha Validator Guide

## Infrastructure

Recommended configuration:

* Number of CPUs: **2**
* Memory: **8GB**
* Disk: **250GB SSD**
* OS: Ubuntu **20.04 LTS**
* Allow all incoming connections from TCP port **26656** and **26657**
* Static IP address

The recommended configuration from AWS is the equivalent of a **t3.large** machine with 250GB EBS attached storage.

## Prerequisites

Update the system and install dependencies:

```bash
sudo apt update
sudo apt upgrade -y
sudo apt install build-essential jq -y
```

Install Golang:

```bash
# Install latest go version https://golang.org/doc/install
wget -q -O - https://raw.githubusercontent.com/canha/golang-tools-install-script/master/goinstall.sh | bash -s -- --version 1.15.3

source ~/.profile
```

To verify that Golang is installed:

```bash
go version
# Should return go version go1.15.3 linux/amd64
```

## Running a Validator Node

### Install the executables

```bash
git clone https://github.com/anathatech/project-anatha.git
cd project-anatha
git checkout v0.1.1

# install executables
make install
```

### Initialize the validator

```bash
# Replace <your-moniker> with the publicly viewable name for your validator.
anathad init --chain-id mainnet <your-moniker>
```

### Set up your keys

```bash
# Create a wallet for your node. <your-wallet-name> is just a human-readable name you can use to remember your wallet. It can be the same or different than your moniker.
anathacli keys add <your_wallet_name> --keyring-backend test

# If you have a wallet with a balance assigned to it, you need to import it by. You will be prompted to enter your bip39 mnemonic
anathacli keys add <your_wallet_name> --recover --keyring-backend test
```

### Create the upgrade manager directory structure

```bash
mkdir -p ~/.anathad/upgrade_manager/genesis/bin && mkdir -p ~/.anathad/upgrade_manager/upgrades
```

### Copy the genesis binary to the upgrade manager

```bash
cp $(which anathad) ~/.anathad/upgrade_manager/genesis/bin
```

### Verify that the binary has been copied

```bash
ls -las  ~/.anathad/upgrade_manager/genesis/bin

# Should return the anathad binary in the correct location
```

### Fetch the genesis file

```bash
# Copy the genesis file to the anathad directory
curl https://guardians.mainnet.anatha.net:26657/genesis | jq ".result.genesis" > ~/.anathad/config/genesis.json
```

### Create the service file with the following content

```bash
sudo nano /etc/systemd/system/anathad.service
```

```bash
[Unit]
Description=anathad
Requires=network-online.target
After=network-online.target

[Service]
Restart=on-failure
RestartSec=3
User=ubuntu
Group=ubuntu
Environment=DAEMON_NAME=anathad
Environment=DAEMON_HOME=/home/ubuntu/.anathad
Environment=DAEMON_ALLOW_DOWNLOAD_BINARIES=on
Environment=DAEMON_RESTART_AFTER_UPGRADE=on
PermissionsStartOnly=true
ExecStart=/home/ubuntu/go/bin/anathad-manager start --pruning="nothing"
StandardOutput=file:/var/log/anathad/anathad.log
StandardError=file:/var/log/anathad/anathad_error.log
ExecReload=/bin/kill -HUP $MAINPID
KillSignal=SIGTERM
LimitNOFILE=4096

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

If you are not logged in as the `ubuntu` user and/or if your home directory is not `/home/ubuntu`, please change the `User`, `Group`, `Environment`, and `ExecStart` variables in the service config above appropriately.

### Start the Daemon service

```bash
# Create log files for anathad
make log-files

# Enable the anathad service
sudo systemctl enable anathad

# Add seed nodes to ~/.anathad/config/config.toml, replace line 172 with
seeds = "aed92dab9de41325b1d0ed39b0d4fc30c6192868@node101.mainnet.anatha.net:26656,f54086e191a9735bbaca614ae91124fd1407f77f@node201.mainnet.anatha.net:26656,05e2de3ff3249216c4043922ad744c8abb9f45eb@node301.mainnet.anatha.net:26656"

# Start the node
sudo systemctl start anathad
```

To check on the status of the node use:

```bash
anathacli status
# or
sudo journalctl -u anathad -f
```

To view the logs use:

```bash
# Standard output of anathad
tail -f /var/log/anathad/anathad.log

# Standard error of anathad
tail -f /var/log/anathad/anathad_error.log
```

### Applying for being a validator

```bash
# Create the validator
# Be sure to replace <your-wallet-name>, <your-moniker>
anathacli tx astaking create-validator --from <your-wallet-name> --moniker <your-moniker> --pubkey $(anathad tendermint show-validator) --chain-id mainnet --keyring-backend test
```

### Verify the node is in the validator list

```bash
# Check all validators
anathacli q astaking validators

# Check current validator
# Be sure to replace <your-wallet-name>
anathacli q astaking validator $(anathacli keys show <your-wallet-name> --keyring-backend test --bech val -a) --chain-id mainnet
```

## Recovering From a Slashing Infraction

First, you need to verify the state of your validator by running:

```bash
# Check current validator
# Be sure to replace <your-wallet-name>
anathacli q astaking validator $(anathacli keys show <your-wallet-name> --keyring-backend test --bech val -a) --chain-id mainnet
```

The response would be similar to the following:

```bash
  operatoraddress: anathavaloper1q9se95mxzmckc3drtrc4facayn8l408w0avqrk
  conspubkey: anathavalconspub1zcjduepqjl5uxahun435923psjzuf8epeuung5gyjs5gtdxkg902qqzlzrvs2xx797
  jailed: true
  status: 1
  tokens: "9900000000000"
  delegatorshares: "10000000000000.000000000000000000"
  description:
    moniker: node1
    identity: ""
    website: ""
    security_contact: ""
    details: ""
  unbondingheight: 194
  unbondingcompletiontime: 2020-05-29T08:28:58.089254769Z
  minselfdelegation: "10000000000000"
  ticket: 16
```

As you can see the jailed status is set to true and the delegation tokens are below the needed amount. You need to perform top up your token balance and send an unjail transaction.

To check when is the earliest time the validator can be unjailed run:&#x20;

```bash
anathacli q slashing signing-info $(anathad tendermint show-validator) --chain-id mainnet
```

The response will return the `jailed_until` parameter in the UTC time zone:

```bash
address: anathavalcons1jw0yhuzpqrqxlnxu44lu3vsu0246md6eeak0eg
start_height: 0
index_offset: 2
jailed_until: 2020-05-29T08:28:58.089254769Z
tombstoned: false
missed_blocks_counter: 2
```

To top up your validator balance, run:

```bash
# Be sure to replace <your-wallet-name>
anathacli tx astaking delegate $(anathacli keys show <your-wallet-name> --keyring-backend test --bech val -a) --from <your-wallet-name> --chain-id mainnet --keyring-backend test
```

To unjail your validator run:

```bash
# Be sure to replace <your-wallet-name>
anathacli tx slashing unjail --from <your-wallet-name> --keyring-backend test --chain-id mainnet
```

## Stopping a Validator Node

To gracefully shutdown a validator node which is in the active validator set, the operator must first unbond their tokens before being able to shut down the node and withdraw their stake.

```bash
# Be sure to replace <your-wallet-name>
anathacli tx astaking unbond --from <your-wallet-name> --chain-id mainnet --keyring-backend test
```

After running the unbonding transaction, you need to check the length of the unbonding time by running:

```bash
anathacli q astaking params
```

After that period of time, your stake will be returned to your account. During the unbounding period, you can be slashed for any infraction that happened before the unbonding transaction.

As soon as you run the unbond transaction, you are free to shut down your validator node.

```bash
sudo systemctl stop anathad
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://project-anatha.gitbook.io/validator-guide/master.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
