Validators

Nym validators secure the network with a staking token, defending the network from Sybil attacks.

Validators also provide privacy-enhanced credentials based on the testimony of a set of decentralized, blockchain-based issuing authorities. Nym validators use a signature scheme called Coconut to issue credentials. This allows privacy apps to generate anonymous resource claims through decentralised authorities, then use them with Service Providers.

The validator is built using Cosmos SDK and Tendermint, with a CosmWasm smart contract controlling the directory service, node bonding, and delegated mixnet staking.

Building the Nym validator

Prerequisites:

  • Go >= v1.15
  • gcc

We use the wasmd version of the Cosmos validator to run our blockchain. Run this to clone, compile, and build it:

WASMD_VERSION=v0.14.1
BECH32_PREFIX=hal
git clone https://github.com/CosmWasm/wasmd.git
cd wasmd
git checkout ${WASMD_VERSION}
mkdir build
go build -o build/nymd -mod=readonly -tags "netgo,ledger" -ldflags "-X github.com/cosmos/cosmos-sdk/version.Name=nymd -X github.com/cosmos/cosmos-sdk/version.AppName=nymd -X github.com/CosmWasm/wasmd/app.NodeDir=.nymd -X github.com/cosmos/cosmos-sdk/version.Version=${WASMD_VERSION} -X github.com/cosmos/cosmos-sdk/version.Commit=1920f80d181adbeaedac1eeea1c1c6e1704d3e49 -X github.com/CosmWasm/wasmd/app.Bech32Prefix=${BECH32_PREFIX} -X 'github.com/cosmos/cosmos-sdk/version.BuildTags=netgo,ledger'" -trimpath ./cmd/wasmd # noqa line-length

At this point, you will have a copy of the nymd binary in your build/ directory. Test that it’s compiled properly by running:

./build/nymd

You should see nymd help text print out.

Both the nymd and libwasmvm.so shared object library binary have been compiled. libwasmvm.so is the wasm virtual machine which is needed to execute Nym smart contracts.

If you have compiled these files locally you need to upload both of them to the server on which the validator will run. If you have instead compiled them on the server skip to the step outlining setting LD_LIBRARY PATH below. To locate these files on your local system run:

WASMVM_SO=$(ldd build/nymd | grep libwasmvm.so | awk '{ print $3 }')
ls ${WASMVM_SO}

This will output something like:

'/home/username/go/pkg/mod/github.com/!cosm!wasm/wasmvm@v0.13.0/api/libwasmvm.so'

When you upload your nymd binary, you’ll need to tell it where libwasmvm.so is when you start your validator, or nymd will not run. If you have compiled them on your server then this is not necessary, as the compiled nymd already has access to libwasmvm.so.

Alternatively, you can check out the repository for nym at https://github.com/nymtech/nym and use the tag for the current release with:

git clone https://github.com/nymtech/nym.git
cd nym
git reset --hard   # in case you made any changes on your branch
git pull           # in case you've checked it out before
git checkout tags/v0.10.0

Inside the folder validator you will find the precompiled binaries to use.

Upload both nymd and libwasmvm.so to your validator machine. If you attempt to run ./nymd on your server, you’ll likely see an error if nymd can’t find libwasmvm.so:

./nymd: error while loading shared libraries: libwasmvm.so: cannot open shared object file: No such file or directory

You’ll need to set LD_LIBRARY_PATH in your user’s ~/.bashrc file, and add that to our path. Replace /home/youruser/path/to/nym/binaries in the command below to the locations of nymd and libwasmvm.so and run it. If you have compiled these on the server, they will be in the build/ folder:

NYM_BINARIES=/home/youruser/path/to/nym/binaries
echo 'export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:'NYM_BINARIES >> ~/.bashrc
echo 'export PATH=$PATH:'${NYM_BINARIES} >> ~/.bashrc
source ~/.bashrc

Test everything worked:

nymd

This should return the regular nymd help text.

Initialize your validator

Prerequisites:

  • FQDN Domain name
  • IPv4 and IPv6 connectivity

Choose a name for your validator and use it in place of yourname in the following command:

nymd init yourname --chain-id testnet-finney

At this point, you have a new validator, with its own genesis file located at $HOME/.nymd/config/genesis.json. You will need to replace the contents of that file that with Nym’s testnet-finney genesis file.

You can use the following command to download the one for Finney with:

wget  -O $HOME/.nymd/config/genesis.json https://nymtech.net/testnets/finney/genesis.json

config.toml setup

Add the Nym validator as a persistent peer so that your validator can start pulling blocks from the rest of the network, by editing the following config options in $HOME/.nymd/config/config.toml to match the information below:

  • cors_allowed_origins = ["*"] allows the web wallet to make HTTPS requests to your validator.
  • persistent_peers = "e7163ea63219504344c669164d083f52434f382b@testnet-finney-validator.nymtech.net:26656" allows your validator to start pulling blocks from other validators
  • create_empty_blocks = false may save a bit of space

Optionally, if you want to enable Prometheus metrics then the following must also match in the config.toml:

  • prometheus = true
  • prometheus_listen_addr = ":26660"

And if you wish to add a human-readable moniker to your node:

  • moniker = "yourname"

Finally, if you plan on using Cockpit on your server, change the grpc port from 9090 as this is the port used by Cockpit.

app.toml setup

In the file $HOME/.nymd/config/app.toml, set the following values:

  1. minimum-gas-prices = "0.025uhal"
  2. enable = true in the [api] section to get the API server running

Set up your validator’s admin user:

You’ll need an admin account to be in charge of your validator. Set that up with:

nymd keys add nymd-admin

This will add keys for your administrator account to your system’s keychain.

The command output should look something like:

$ nymd keys add nymd-admin
Enter keyring passphrase:
password must be at least 8 characters
Enter keyring passphrase:
Re-enter keyring passphrase:

- name: nymd-admin
type: local
address: hal1x4twq82ew2c49ctr36mafksyrtnxwvrkey939u
pubkey: halpub1addwnpepqdfcf5786qry8g8ef9nad5vnl0rs5cmkcywzrwwvvdye27ktjmqw2ygr2hr
mnemonic: ""
threshold: 0
pubkeys: []


**Important** write this mnemonic phrase in a safe place.
It is the only way to recover your account if you ever forget your password.

design payment apple input doll left badge never toe claw coconut neither travel side castle know plate unit mercy weekend pelican stay fortune road

As the instructions say, remember to write down your mnemonic.

You can get the admin account’s address with:

nymd keys show nymd-admin -a

Type in your keychain password, not the mnemonic, when asked. The output should look something like this:

hal1x4twq82ew2c49ctr36mafksyrtnxwvrkey939u

Start your validator

Everything should now be ready to go. You’ve got the validator set up, all changes made in config.toml and app.toml, the Nym genesis file copied into place (replacing the initial auto-generated one). Now let’s validate the whole setup:

nymd validate-genesis

If this check passes, you should receive the following output:

File at /path/to/.nymd/config/genesis.json is a valid genesis file

If this test did not pass, check that you have replaced the contents of /path/to/.nymd/config/genesis.json with that of the testnet-finney genesis file.

Before starting the validator, we will need to open the firewall ports (adapt if not using firewalld):

for port in 1317/tcp 9090/tcp 26656/tcp 22/tcp 26660/tcp 80/tcp 443/tcp; do
firewall-cmd --add-port=${port}
firewall-cmd --add-port=${port} --permanent
done

If you are planning to use Cockpit on your validator server then you will have defined a different grpc port in your config.toml above: remember to open this port as well.

Start the validator:

nymd start

Once your validator starts, it will start requesting blocks from other validators. This may take several hours. Once it’s up to date, you can issue a request to join the validator set:

PUB_KEY=$(/home/youruser/path/to/nym/binaries/nymd tendermint show-validator) # e.g. halvalconspub1zcjduepqzw38hj6edjc5wldj3d37hwc4savn0t95uakhy6tmeqqz5wrfmntsnyehsq
MONIKER="nym-secondary"                                                       # whatever you called your validator
FROM_ACCOUNT="nymd-admin"                                                     # your keychain name

nymd tx staking create-validator \
--amount=10000000stake \
--fees=5000uhal \
--pubkey="${PUB_KEY}" \
--moniker=${MONIKER} \
--chain-id=testnet-finney \
--commission-rate="0.10" \
--commission-max-rate="0.20" \
--commission-max-change-rate="0.01" \
--min-self-delegation="1" \
--gas="auto" \
--gas-adjustment=1.15 \
--from=${FROM_ACCOUNT} \
--node https://testnet-finney-validator.nymtech.net:443

You’ll need stake coins for this.

Note: we are currently working towards building up a closed set of reputable validators. You can ask us for coins to get in, but please don’t be offended if we say no - validators are part of our system’s core security and we are starting out with people we already know or who have a solid reputation.

If you want to edit some details for your node you will use a command like this:

nymd tx staking edit-validator   --chain-id=testnet-finney   --moniker=${MONIKER}   --details="Nym validator"   --security-contact="YOUREMAIL"   --identity="XXXXXXX"   --gas="auto"   --gas-adjustment=1.15   --from=${FROM_ACCOUNT} --fees 2000uhal

With above command you can specify the gpg key last numbers (as used in keybase) as well as validator details and your email for security contact~

Automating your validator with systemd

You will most likely want to automate your validator restarting if your server reboots. Below is a systemd unit file to place at /etc/systemd/system/nymd.service:

[Unit]
Description=Nymd (0.10.0)

[Service]
User=nym                                                          # change to your user
Type=simple
Environment="LD_LIBRARY_PATH=/home/youruser/path/to/nym/binaries" # change to correct path
ExecStart=/home/youruser/path/to/nym/binaries/nymd start          # change to correct path
Restart=on-failure
RestartSec=30
StartLimitInterval=350
StartLimitBurst=10

[Install]
WantedBy=multi-user.target

Proceed to start it with:

systemctl daemon-reload # to pickup the new unit file
systemctl enable nymd   # to enable the service
systemctl start nymd    # to actually start the service
journalctl -f           # to monitor system logs showing the service start

Install and configure nginx for HTTPS

Setup

Nginx is an open source software used for operating high-performance web servers. It allows us to set up reverse proxying on our validator server to improve performance and security.

Install nginx and enable “Nginx Full” in your firewall.

Check nginx is running via systemctl:

systemctl status nginx

Which should return:

● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2018-04-20 16:08:19 UTC; 3 days ago
     Docs: man:nginx(8)
 Main PID: 2369 (nginx)
    Tasks: 2 (limit: 1153)
   CGroup: /system.slice/nginx.service
           ├─2369 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
           └─2380 nginx: worker process

Configuration

Proxying your validator’s port 26657 to nginx port 80 can then be done by including the following in /etc/nginx/conf.d/validator.conf:

server {
  listen 80;
  listen [::]:80;
  server_name {{ domain }};

  location / {
    proxy_pass http://127.0.0.1:26657;
    proxy_set_headerX-Real-IP $remote_addr;
    proxy_set_headerHost $host;
    proxy_set_headerX-Real-IP $remote_addr;
  }
}

Followed by:

sudo apt install certbot nginx python3
certbot --nginx -d nym-validator.yourdomain.com -m you@yourdomain.com --agree-tos --noninteractive --redirect

These commands will get you an HTTPS encrypted nginx proxy in front of the API.

In the next testnet we will be focusing more on things such as validator TLS and sentry nodes.

Unjailing your validator

If, for some reason, your validator gets jailed, you can fix it with the following command:

nymd tx slashing unjail \
  --broadcast-mode=block \
  --from=${FROM_ACCOUNT} \
  --chain-id=testnet-finney \
  --gas=auto \
  --gas-adjustment=1.4 \
  --fees=7000uhal

Day 2 operations with your validator

As part of the execution of the validator, it will be able to get some rewards.

With this command, we can query our outstanding rewards:

nymd query distribution validator-outstanding-rewards <halvaloperaddress>

Using the values obtained from the previous command, you can withdraw all rewards with:

nymd tx distribution withdraw-rewards <halvaloperaddress> --from ${FROM_ACCOUNT} --keyring-backend=os --chain-id="testnet-finney" --gas="auto" --gas-adjustment=1.15 --commission --fees 5000uhal

You can check your current balances with:

nymd query bank balances hal<address>

For example:

balances:
- amount: "22976200"
denom: stake
- amount: "919376"
denom: uhal
pagination:
next_key: null
total: "0"

You can, of course, stake back the available balance to your validator with the following command:

nymd tx staking delegate <halvaloperaddress> <amount>stake--from ${FROM_ACCOUNT} --keyring-backend=os --chain-id "testnet-finney" --gas="auto" --gas-adjustment=1.15 --fees 5000uhal

NOTE: The value to be used instead of the <amount>stake can be calculated from the available balance. For example, if you’ve 999989990556 in the balance, you can stake 999909990556, note that the 5th digit, has been changed from 8 to 0 to leave some room for fees (amounts are multiplied by 10^6).

Also remember to replace halvaloper with your validator address and nym-admin with the user you created during initialization.