Skip to content

Running a Validator Node and Bonding CAPS

Marko Petrlić edited this page Sep 15, 2022 · 6 revisions

Overview

Usually when people talk about being a validator they don't know that this is actually a three step process. The first step is to run a node in the validator mode, the second step is to generate session key and the third step is to bond CAPS and to use our session key in order to register our validator node.

In general going from the first to the last step isn't a difficult task and it can be done in 10 minutes. Just because this can be done really quick it doesn't mean anyone can do it. In the paragraph Before you start I have listed all the things that a person needs to know or needs to do before he can start this journey.

Before you start

Makes sure that you are conformable with using a terminal(console) and that you already have experience in debuging terminal errors. Besides knowing how to use the terminal it's also important to know how to manage virtual machines. Your node for testing superposes can be tested on your local machine but for doing anything more critical it's important to have the node running on a VM that has a high up-time.

If you have never used a terminal before or your struggle with it then this might not be something for you since you will encounter a lot of challenges that might cause more issues and problems.

Having said that, make sure that you have already compiled the project (in release mode) before and that you have the Ternoa binary ready to be used. There are instructions on how to do that for Ubuntu, Fedora and Arch in the readme file or in the dockerimages. If you are running a different Linux flavor or a different OS you will need to figure out yourself what dependencies to install in order to build the project.

Using the right flags

Once you have your binary ready, make sure that you place it in the right directory. For testing purposes it can be anywhere and for production environments it makes sense to place them inside /usr/bin/ or on a separate disk like /block/. In my case the root folder of my binary is /home/marko/Projects/test/. In the same folder I have created another folder which is going to stored the data that the node will produce. In a production environment you would want to store that data on a separate disk.

With the binary in the right place and with node-data folder ready, we can start our node by executing the binary with the following command and flags:

./ternoa --name MyRunningNode --validator -d ./node-data/ --chain alphanet --state-pruning archive

Let's go over those flags to see what they do:

  • --name MyRunningNode: This sets the name of the node. This name will be visible in the telemetry data. Depending on what chain has been chosen, the node will be visible either here or here.
  • --validator: This makes the node eligible to produce and finalize blocks. This also tells the node be in a archive mode which means it will store all the blocks instead of keeping only a few of them.
  • -d ./node-data/: This tells the node to store the blockchain and blockchain related data inside the ./node-data/ folder. Besides storing all the blocks and the latest state, this folder will contains all the private keys that the node will generate.
  • --chain alphanet: The last piece of information is to select a network which the node will connect. In this case alphanet is chosen but if you want to connect to Mainnet you would write mainnet.
  • --state-pruning archive: This is optional. With this flag the node will store all the block states. This will significantly increase the size of storage.

Once you start the node you will immediately see that it starts to sync all the blocks. This can take a while (the duration depends on your connection and machine speed) but generally it should be under 12 hours. On the telemetry you should see your node in gray and the block number should be increasing just like in my case: image

It's important to know if you plan to run multiple nodes that you in no case copy the node-data from one node to the other one. You could theoretically copy just the chain database from one node to speed up the sync process for other nodes but that is discouraged and there is a chance that by copying the whole node-data folder you will also copy the private keys of first node and put in danger your other nodes. Every single node needs to have it's own private keys and if you decide to share them the system will penalize you.

Having said that, congratulations to you because you are now officially running a validator node. Does this makes you a validator? Ehmm, not yet.

Generating the session key

I am not going to go into too much details on what are the session keys and why do we need them but it's good to know that some math operations like building and finalizing blocks require us to provide a private key to do it. There are couple of those math operations that need that kind of input and all those private keys mashed up together we call session key.

To generate all those private keys we just need to have our node up and running and we need to execute the following command:

curl -H "Content-Type: application/json" -d '{"id":1, "jsonrpc":"2.0", "method": "author_rotateKeys", "params":[]}' http://localhost:9933

The output of this command is a JSON formatted data that includes our session key inside the result field. This output should be stored somewhere safe since it will be used later. Example of the command output:

{"jsonrpc":"2.0","result":"0x53c11edd560a0701b54399284c63113df32ddede0e37685dfcdcc5a5c9c9b30aee74e2c6f05acf31eef39e4df8b08e85f67c517b3f049c3849808f0610c72c538a0ac2d1122ab8dde2b41216e64718de39dffe7ed10b230bb038429bec9c0329eafca220c00b6d27ae9bc4a105a4b1854fca1b824946c86c7919c39c49c3544e","id":1}

Besides this output we can cd into /node-data/chains/alphanet-live/keystore/ and see for ourselves that those keys are really generated and stored.

image

One more step and we are done. The next part is done via Polkadot JS APPS UI so we don't need to use the terminal anymore (unless you use W3M 😄 )

Bonding CAPS and becoming a real validator

So far what we have done is that we have a running node that is fully synced and we generated the session key. Now we need to visit the Polkadot JS APPS page Alphanet or Mainnet and make sure that we have two accounts. One of those accounts is going to be used as the controller and the other is going to be used as the stash. More about this concept here. Here I will be using my two accounts Marko-Controller and Marko-Stash

image

The next step is to navigate to Network->Staking->Accounts, click on Stash button and follow the on screen instructions. Make sure that you bond more than 150k CAPS so that you become eligible to be a validator. Here is how the screen looked for me:

image

After bonding we are now have a choice to either use our bond to nominate or to set the session key. Let's set the session keys. Here how it looked for me:

image

Besides the Nominate button we should now see the Validate button. Click on it and follow the on screen instructions. Once that's done you are now officially a validator :)

The whole process of Bond, Set Session Keys and Validate can be done in one go by pressing the Validator button instead of Stash but in the end the result is the same. This is how it looked for me in the end:

image

This is just the start...

This was just a short guide on how to set up the node and the JS APP part in order to be a validator. What's missing from here and what's also super important is the information on how to properly setup the VM so that is secure and how to set up telemetry software to observer the node. Maybe in the future we will have a guide for this but a lot info can be found online and it's your responsibility as a node operator to use the best practices in this field 😸