How to easily test the sync status of your Waves testnodes

in #waves8 years ago

Easy testing of the sync status of Waves nodes

Since the waves community is heavily testing the node code, a couple of people are installing nodes on testnet. After the installation (if you haven't installed a node yet, you are open to follow my tutorial on the node installation) the nodes need to download the history of the blockchain. This process is often referred to as syncing.

The nodes API allows to check the current height of the history of the blockchain of a certain node. Therefore, the current height of a certain node (let's assume your node) could easily be compared to one of the master nodes (let's assume master nodes are those run by Waves developers). In order to not do this always via the Swagger UI (you may check your nodes height and one of the developer nodes height and compare those numbers), i've written a small NodeJS tool that can easily check a number of nodes against a defined master node.

Installation of the tool

The tool itself is written in NodeJS. Therefore, the system you want to run the tool on, needs to have a decent version of NodeJS installed. Under Ubuntu based systems, NodeJS (and necessary tools) could easily be installed via the following command:

sudo apt-get install nodejs nodejs-legacy npm

This line installs NodeJS itself, npm - the node package manager (which we will later on use in oder to install the dependencies of the tool) and finally the nodejs-legacy package installs an alias that allows you to start the NodeJS interpreter via the command node.

The tool is published via git. In order to clone the repository you just have to copy the following code on a system that has git installed:

git clone http://gitlab.dsalab.de/marc.jansen/wavesnodediff.git

After the tool is cloned, you should have a new directory wavesnodediff. If you change to this directory, you should find two files:

app.js 
package.json

The app.js is the sourcecode of the tool itself, while the package.json file holds metadata information about the tool, such as the current version and most important the dependencies of the tool. In order to install the dependencies, we simply call npm (the node package manager) with the parameter install.

npm install

By this, npm then looks in the package.json file for the dependencies and will install those in a newly created folder node_modules. This step finalizes the installation of the tool

Parameterization of the tool

In order to check the nodes you want to check, you need to configure the tool accordingly. If you enter the app.js file, e.g., with vi/vim, you will find a line like:

var addresses = ['jansen.noip.me:6869', 'terrok-nor.de:6869', '159.203.187.109:6869'];

This line defines an array of addresses that should be checked by the tool. Basically, this is the address of the Swagger UI of your node. You can delete the addresses that are currently stored in this array and add your own addresses, e.g.:

var addresses = ['myaddress.me:6869'];


This would lead to a test of the node installed on the domain myaddress.me at port 6869. Additionally, you may enter the line that defines the address of the master node:

var masterNodeIP = '52.28.66.217:6869';

You can change the address there to whatever node you want to compare your node to.

Execution of the tool

Once the tool is properly configure, you can simply execute the tool by running the following command:

node app.js

The output should look like this:

marc@waves-testnet:~/wavesnodediff$ node app.js  
The current difference between address: 159.203.187.109:6869 and the master is: 2 blocks! 
The current difference between address: terrok-nor.de:6869 and the master is: 2 blocks! 
The current difference between address: jansen.noip.me:6869 and the master is: 2 blocks! 
marc@waves-testnet:~/wavesnodediff$ 

As you see, at the time of this writing, my nodes are two blocks behind the node i compared them to. If you encounter an error like the following, this usually means that one or the other node that you try to check, is currently not available.

marc@waves-testnet:~/wavesnodediff$ node app.js  
The current difference between address: 159.203.187.109:6869 and the master is: 2 blocks! 
The current difference between address: 46.101.208.96:6869 and the master is: 2 blocks!
 undefined:1 undefined ^ 
SyntaxError: Unexpected token u at Object.parse (native) at Request._callback (/home/marc/wavesnodediff/app.js:13:42) at self.callback (/home/marc/wavesnodediff/node_modules/request/request.js:187:22) at emitOne (events.js:77:13) at Request.emit (events.js:169:7) at Request.onRequestError (/home/marc/wavesnodediff/node_modules/request/request.js:813:8) at emitOne (events.js:77:13) at ClientRequest.emit (events.js:169:7) at Socket.socketErrorListener (_http_client.js:258:9) at emitOne (events.js:77:13)

If this happens, just remove the node from the list of nodes to check, or try to check the node later.

Usage of the Waves nodes API

If you have a closer look at the function identifyDifferenceBetweenNodes, you find an example of the usage of the Waves nodes API in NodeJS:

request.get('http://' + masterNode + '/debug/info', function(err, response, body) {
var infoFromMasterNode = JSON.parse(body);

request.get('http://' + slaveNode + '/debug/info', function(err, response, body) {
var infoFromSlaveNode = JSON.parse(body);

callback(infoFromMasterNode.stateHeight - infoFromSlaveNode.stateHeight);
});
});

I'm using the requst framework here in oder to perform a ReST call to the API. If you check the SwaggerUI, you'll find a proper documentation of additional API functions that could be called similar. If enough people are interested in this, i may find some time to prepare an additional post towards the execution of API requests from different programming languages.


If you find this tutorial and the tool helpful, please feel free to upvote. Any questions towards this topic are highly appreciated via comments or at the Waves slack in #testnet-maintainers.

Coin Marketplace

STEEM 0.17
TRX 0.15
JST 0.028
BTC 60429.37
ETH 2327.68
USDT 1.00
SBD 2.52