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.
After reading the script and the procedure explanation ...
I can see that the database snapshot is tiny compared to the full node ...
What's the difference in the functionality and in the code between the full node and light node? Why is it so small?
Thank you!
Light nodes do not store transactions and blocks, so the transactions collections is empty and the chain collection gets cleaned up periodically. This means that the rpc calls getBlockInfo and getTransactionInfo won't work. Other than that light nodes are the same as full nodes.
But I still have to make a few improvements as suggested after a review by eon / mancer. Here you will find a few more technical details https://peakd.com/hiveengine/@primersion/hive-engine-light-nodes
Thank you!
@tipu curate
Upvoted 👌 (Mana: 45/55) Liquid rewards.
Nice one for an updated post.
Just a couple of comments and most of the time might not even give problems but as a good practice, we want to respect the contents of the
package-lock.json
file for most of the modules, hence on thenpm
command that does not target any install package, we want to use thec
flag too.The other comment is that may be not obvious, but people need to check which tags are the latest and maybe it would pay off to add a comment before this line, saying to check the latest tag version:
GIT_TAG=he_v1.7.1
Question... why is this part for?
################ ## RESTORE DB ## ################ mongo --eval "rs.initiate()" systemctl restart mongod
Maybe you meant to add the
mongorestore
command here? Just mentioning because it was already done above, the initiate command.Cheers
Thanks for the npm 'c' flag, didn't know that!
And the final mongo stuff were some tweaks I did before when the database was huge that I just carried over. It's likely this can be removed today.
👍
Dear @blervin, we need your help!
The Hivebuzz proposal already got important support from the community. However, it lost its funding a few days ago and only needs a few more HP to get funded again.
May we ask you to support it so our team can continue its work this year?
You can do it on Peakd, ecency,
https://peakd.com/me/proposals/199
Your support would be really helpful and you could make a difference.
Thank you!