Setup a node

Introduction

Nodes are important to propagate transactions and to verify blocks. This guide would show you how to setup a public node to support the network. Preferably, you should have some basic knowledge on setting up a web server application to proceed with this. ChaCha3 nodes can run on any major server operating system. However, this guide is specifically for Ubuntu Linux server.

Install Node.js

There are many ways to install Node.js on your server. The two ways we suggest are with:

  1. Apt using NodeSource PPA
  2. Node Version Manager (NVM)

Here we would cover how to install it with the first method using APT. NVM makes it easier to switch versions later if you need to, if you prefer to use that you can refer to their documentation here.

To install the PPA, navigate to your home directory and run the following:

$ cd ~
$ curl -sL https://deb.nodesource.com/setup_16.x -o nodesource_setup.sh

Then run the script with sudo

$ sudo bash nodesource_setup.sh

Now that the PPA has been added to your configuration, you can install it using APT.

$ sudo apt install nodejs

Verify that you have installed version 16 as that is our currently supported version

$ node -v
v16.13.2

For some of the Node.js packages to work, we will need to install the build-essentials package

$ sudo apt install build-essential

Install Git

You would need to install Git to retrieve the code for the node. Git is likely already installed if your are running Ubuntu 20. You can confirm it using the following command:

$ git --version
git version 2.25.1

If you do not get the version number output as above, then you would need to install Git. If you do get the version as the above, then you can skip this installation and proceed to the next step.

First, update your local package index

$ sudo apt update

Then proceed to install Git

$ sudo apt install git

You can verify that it is installed by checking the version again.

Setup ChaCha3 Core

Firstly, decide on the directory where you want to install the ChaCha3 core then navigate to it. Typically it would be in /var/www or the home ~ directory

$ cd /var/www

If the directory does not exist, then you can create it with mkdir

Download the code using Git

git clone https://github.com/chacha-3/chacha3-core.git

Navigate into the code directory and install the necessary packages using NPM (installed with Node.js)

$ cd chacha3-core
$ npm install --production

One more package that we need to install is PM2. It's the process manager to keep the program running in the background. Install PM2 globally using:

$ npm install pm2@latest -g

Once it is installed, start the program using PM2, (recommended) with the configuration file

$ pm2 start ecosystem.config.js

Info

For those familiar with PM2, avoid running the application using PM2 cluster mode as it is not supported. Clustering would be implemented in the application itself in future updates.

Verify that the server is running and accessible.

$ curl localhost:5438
{"message":"Welcome to ChaCha3!"}

To check that it is publicly accessible, change localhost to your domain name or public IP address.

$ curl devnode1.chacha3.net:5438
{"message":"Welcome to ChaCha3!"}

Add Environment config

You need to a add just one config to be considered a public node, which is your host url. Firstly, create the .env file in the application base directory if it is not already created. Then you can set the HOST config in the file. Below is the basic config you can add.

HOST=node.mydomain.com
PORT=5438
NODE_ENV=production

You only need to add the HOST config. You can skip the PORT and NODE_ENV lines as those are already the default config. However, if you would like to config the setting such as the port, you can do so as the above. The HOST config is required for other nodes to identify your publicly accessible host address. The host can be either an IP address or a domain name.

To run a node for the test network (testnet), change NODE_ENV from 'production' to 'staging'.

Restart application

Any changes to the application and the environment requires a restart. You would have to restart the PM2 process once you have changed the environment config for the configuration to update.

First, view the list of PM2 processes running using:

$ pm2 list

You should see a process running named chacha3-core. It would be named as such if you have started the processed using the ecosystem.config.js file in the previous section. Take note of either the process name or ID, either one can be used to restart the process. Then, run the command to restart the application as follows, inputting either the process name or ID.

$ pm2 restart chacha3-core

Verify

Now, you can check that your node is running and is publicly accessible by viewing it's url page at http://node.mydomain.com:5438, following on the host url. You can also ping the node through your local shell. Run the following in the shell of your locally running node, not the publicly accessible server node. It would send a node info request to the node to check that it is active.

$ pingNode host:node.mydomain.com port:5438
Pong

Keep up-to-date

It is recommended that you keep the code up to date. Periodically fetch the latest code from the repository and do a quick restart of the client.

git pull

Then, run the install again. You only need to run the install once after pulling the latest code. Next, restart the PM2 process.

npm install --production
pm2 restart chacha3-core