How To Set Up A Hive Engine Witness- Step By Step Guide

With hive-engine coming out with their P2P validation layer recently, I thought it might be useful to make a guide in order to help users who want to get set up. While this isn't a true block production layer, it's better than nothing since it can help show if particular nodes are out of sync(though if everyone just uses the "official" node, then the p2p layer is kinda useless, so use other nodes developers).

I decided to write a simple guide so that way anyone who wants to use the programs can do so. I'm assuming you know the basics of how to connect to a server, and how to do basic troubleshooting(if it says "error something's not installed, go ahead and install it) as well as basic security stuff for your server(PLEASE USE SSH KEYS AND NOT PASSWORD AT THE VERY LEAST INSTALL FAIL2BAN https://www.techrepublic.com/article/how-to-install-fail2ban-on-ubuntu-server-18-04/ ESPECIALLY SINCE YOUR IP IS PUBLIC). I'm also using Ubuntu 20.04 while writing this, if you are on other systems it might vary. You'll need a server with at least 4 gigs of ram (I recommend at least 8) and I'd recommend at least 4 cores and 500 GB of NVME. Your server must also have IPv6 connectivity. If you don't, you can tunnel to get the connectivity. If you are looking to rent a server, check out Ryamer.

Doing this WILL REVEAL YOUR IP of the server to the world, since the witness enable command broadcasts the on the chain(its how the nodes find each other to talk to).

Being a top engine witness does take a lot of RC as well. While testing, I delegated 500 HP to my engine witness and that wasn't enough. I'd recommend about 1,000 HP worth of RC.

When you get your server you'll want to install a few basic things, including git, nodejs, mongodb and screen.

sudo apt-get update -y

sudo apt-get upgrade -y

sudo apt install git -y

sudo apt install screen -y

sudo apt install npm -y

sudo apt install ufw -y


wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -

echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list

sudo apt-get update

sudo apt-get install -y mongodb-org

This should install the packages that we need. Next we'll need to change our mongo settings to use replication sets. If you have any problems, feel free to consult https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/.

sudo nano /etc/mongod.conf

On it you'll see a line that looks like #replication:

You'll want to change it so that you remove the # at the start and on the line below it, add two spaces and replSetName: "rs0" and security.javascriptEnabled: false on another line. The final result should look like:

replication:
  replSetName: "rs0"

security.javascriptEnabled: false

Now save that, Press control + O, then control + X.

Next we'll restart mongod.

sudo systemctl stop mongod
sudo systemctl start mongod

Could also use restart here, but I like stop and start :)

Now we want to activate replica sets on mongodb.

mongo
rs.initiate()

You'll see a bunch of stuff and it should say something like "rs0"... at the bottom left. If thats all good, press control + D to exit.

mongo --eval "db.adminCommand({setParameter:1, internalQueryMaxBlockingSortMemoryUsageBytes:2097152000})"

You'll want to run this to increase the max memory used for sorting. The default is 100MB. This sets it to 2 GB. Make sure you have the RAM for this, drop the number if you need to.

Now we'll want to update our version of nodejs.

sudo npm i -g n
sudo n 18

At this point please disconnect and reconnect to the server. It's the easiest way for the update to take place.

Now the following step you want to take ONLY IF YOU GOT A 2 GB RAM SERVER!!! While it won't hurt it if you do on a 4 GB server, it's not necessary. But it is required on a 2 GB server. This is making a swap file on your server, because mongo import takes more than 2 GB of ram. If you have any problems feel free to consult https://linuxize.com/post/create-a-linux-swap-file/. We'll be making a 2GB swap file.

sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

Now if you do sudo swapon --show you should see some number and under size it should be 2048M showing you did it all correctly.

The following steps are for everyone again.

We'll want to grab the latest snapshot for engine from a reliable source. I use https://snap.primersion.com/ or my mirror https://snap.rishipanthee.com/.

wget URL_ARCHIVE

We wait for that to finish. Take note of the name of the file, here it is hsc_20210203_b50993579.archive. If you grab one of a different name, you'll need to update what you do on the following step to match the name.

Then we'll want to import in the snapshot onto mongodb. For this we use a screen so that way if you disconnect it still works as this is the longest part. If you got the bare minimum specs, it'll take about 20 minutes.

screen -S reload
mongorestore --gzip --archive=hsc_20210203_b50993579.archive

If you know how to get out of a screen, you can do so and move onto other steps while waiting for this to finish. If you don't, just sit tight, you can wait a little bit. If you get disconnected from your server and need to reconnect to the screen you can type in screen -r reload. Once it's done, you can press control + D to disconnect from the screen.

Up next is getting the hive engine code. We use git to get this. Yes it is still called steem smart contracts.

git clone https://github.com/hive-engine/hivesmartcontracts.git 
cd hivesmartcontracts

Then we want to install the dependencies to the program as well as pm2 which we will use to run this in the background.

npm ci
sudo npm i -g pm2

If you aren't eturnerx, please skip the next line.
@eturnerx It's npm ci, not npm i. And don't you dare npm audit fix.

You'll want to then modify the config file to work with the import we got, to open it type in nano config.json, as well as add or remove nodes. The list is pretty good right now, the only thing you'll want to change is the part after "startHiveBlock": to be 0. Final result should look like:

 "startHiveBlock": 0,

Make sure the comma after that is there. On the last line, there's witnessEnabled which should say false for now, change that to true. Result should be like:

"witnessEnabled": true

There's stuff about light nodes and all that in there, but we wont' be dealing with that in this guide.

Save the file and exit, control + O, control + X.

Now we need to move the example env file to be a real one.

mv .env.example .env
nano .env

Now this is all blank. You'll want to fill it in with your details, after the = on each line. For the domain, you can buy a domain and point it to your server. Set the AAAA record of the domain to the IPv6 address of the domain, and the A record to the IPv4 record of the server(if it has one). Here's an example of one:

ACTIVE_SIGNING_KEY=5FreeKeysAreNotAThingb
ACCOUNT=h-e
NODE_DOMAIN=example.com

Once you do that, control + O, control + X to save and exit.

Almost there. Now we want to allow access to the ports that are necessary for this.

sudo ufw allow ssh
sudo ufw allow 5001
sudo ufw enable

Now we start the node up.

pm2 start app.js --name engwit --no-treekill --kill-timeout 10000 --no-autorestart

Now we need to wait for it to sync. This can take some time. The older the snapshot that you use, the longer it takes. To monitor your progress, type in pm2 logs. Once you see lines that look like 0|app | 2021-02-03 03:15:04 info: [Streamer] head_block_number 50994938 currentBlock 50994939 Hive blockchain is 0 blocks ahead you are good to go. The 0 blocks ahead part is very important. Otherwise you could miss blocks. You can disconnect while waiting at this point. To close the logs, press control + C.

Once thats up and running, you might need to cd back into the folder cd hivesmartcontracts if you exited the connection to the server.

Then enable your witness

node witness_action.js register

And you did it. You are now a witness. Be sure to vote for me for Hive witness (@hextech) as well as hive-engine witness(@h-e). To vote for hive engine witnesses, you can check out https://cdn.rishipanthee.com/enginewit.html or the official tool at https://tribaldex.com/witnesses.






Now that you've reached here, there's one more thing to say. I've worked on a little tool called EngineSpeed for helping you set up nodes quickly. You can find it here. https://github.com/Rishi556/EngineSpeed. Basically you use it on a fresh Ubuntu 20.04 server and it'll do 95% of the work for you. You just have to come back in a while to see if its ready and register your node.

Usage for a fullnode:

wget https://git.dbuidl.com/rishi556/EngineSpeed/raw/branch/main/install.sh
chmod +x install.sh
./install.sh -w -a YOUR_HIVE_USERNAME_HERE -p YOURHIVEPRIVACTIVEKEYHERE

And that's it. Or if you'd prefer a light node:

wget https://git.dbuidl.com/rishi556/EngineSpeed/raw/branch/main/install.sh
chmod +x install.sh
./install.sh -w -a YOUR_HIVE_USERNAME_HERE -p YOURHIVEPRIVACTIVEKEYHERE -l

Super simple right? Once the scripts done processing(I recommend starting them in a screen so you don't have to stay connected while they do their thing), you can check the sync status using pm2 logs engnode. Once it shows you as caught up, cd into the hivesmartcontracts directory, then use node witness_action.js register -v and you are up and running. Super easy right?

Now I don't recommend everyone do this. There might be bugs I haven't found, and troubleshooting this is harder since it will keep on proceeding step by step even if there's a problem. But for someone who's done this a ton, this script should help them set stuff up faster and they should know how to fix broken things.

If you are looking to rent a server, check out Ryamer.

H2
H3
H4
3 columns
2 columns
1 column
68 Comments
Ecency