Hive Engine Light Node - One Click Depoloyment

Hive Engine Light Node - One Click Depoloyment

Intro

I was pretty excited to see @primersion recently release the Hive Engine Light Node.

This is a massive improvement from the base code so I wanted to share my experience with everyone and hopefully get a few more nodes up.

A little background. I was one of the first witnesses to launch a Hive Engine witness and I initially garnered a lot of support. Then, around 1.7.0 things got rough. The mongo database was around 40GB and it took at least half a day to restore a recent snapshot. So, to get started you basically needed to invest an entire day. After investing several days, I had no working instance and I gave up. The end result is that I've lots TONS of my votes so I'm trying to get active, drop some insights and a little code, and help support the community to get more light nodes up and running.

The Script

First of all, I'm deploying this to Ubuntu 20.04 and I haven't tested any other releases so your results may vary.

I've had success running everything on just a 2GB node so far.

#!/bin/bash
###################
## SET VARIABLES ##
###################
SERVER_NAME="witness"
GIT_REPO="https://github.com/hive-engine/steemsmartcontracts.git"
GIT_TAG=he_v1.7.1

##################
## INIT UPDATES ##
##################
apt-get update \
  -o Dpkg::Options::=--force-confold \
  -o Dpkg::Options::=--force-confdef \
  -y --allow-downgrades --allow-remove-essential --allow-change-held-packages

####################
## INSTALL BASICS ##
####################
apt install git -y
apt install ufw -y

################
## CLONE REPO ##
################
mkdir -p /var/$SERVER_NAME
cd /var/$SERVER_NAME
git clone --recursive --branch $GIT_TAG $GIT_REPO ./

# Pull the recent PR for the light node
git pull origin pull/144/head

#####################
## INSTALL MONGODB ##
#####################
cd /var/$SERVER_NAME
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | apt-key add -
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-4.4.list
apt-get update -y
apt-get -y -o Dpkg::Options::="--force-confold" install mongodb-org
sed -i '/replication/a \ \ \ replSetName: "rs0"' /etc/mongod.conf
sed -i 's/#replication/replication/g' /etc/mongod.conf
systemctl stop mongod
systemctl start mongod
mongo --eval "rs.initiate()"

##############
## SET SWAP ##
##############
fallocate -l 2G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile

##################
## INSTALL NODE ##
##################
curl -sL https://deb.nodesource.com/setup_14.x | bash -
apt-get install -y nodejs
apt-get -y install npm

#################
## FINAL SETUP ##
#################
cd /var/$SERVER_NAME
npm install dotenv
npm i
npm i -g pm2
sed -i 's/"witnessEnabled": false/"witnessEnabled": true/g' config.json
sed -i 's/"lightNode": false/"lightNode": true/g' config.json
ufw allow 5001

#####################
## SET WITNESS KEY ##
#####################
cat > /var/$SERVER_NAME/.env << EOF
ACTIVE_SIGNING_KEY=youractivesigningkey
ACCOUNT=youraccountname
EOF

################
## RESTORE DB ##
################
mongo --eval "rs.initiate()"
systemctl restart mongod

Snapshots

Before you get started you'll need a recent snapshot. Fortunately, @primersion has you covered.

Head over to https://snap.primersion.com/light/ and get the most recent release.

wget https://snap.primersion.com/light/hsc_05-17-2022_b64465767.archive
mongorestore --gzip --archive=hsc_05-17-2022_b64465767.archive

This will take awhile, but nothing like the 17 hours it took before.

Set the startHiveBlock in config.json to the number in the snapshot URL:

"startHiveBlock": 64465767,

Final Steps

To start, save this as a .sh file and execute it. Once it is complete, you just need to start Hive Engine:

cd /var/witness
pm2 start app.js --no-treekill --kill-timeout 10000 --no-autorestart --name engwit

You can see what's happening two ways:

pm2 logs

or

tail -fn0 /root/.pm2/logs/engwit-out.log

Conclusion

I hope this is a quick and simple way for you to get up and running. I think this is a vast improvement from the base code and the massive database so I hope this makes your life a little easier. And my real hope is to see that witness list growing far more than today, the more active nodes we have the more stable our network.

I'm trying to build back my rank after being away so long so I would sincerely appreciate your vote and consider supporting @primersion as well, thanks for your consideration.

H2
H3
H4
3 columns
2 columns
1 column
Join the conversation now