How To Setup Hive Witness Pricefeed Using Hivefeed-JS

in #witness3 years ago (edited)

Setting up a pricefeed is quite a simple task to do yet so many witnesses don't do it. I use it as one of my basic qualifiers on who I'll vote for a witness(if yours isn't updated in 3.5 days, no chance of getting my witness vote). It's a very basic thing to do and its just a quick and easy way to see how much a witness is paying attention to their own witness.

The pricefeed is how Hive knows about the price of Hive. Some events require Hive knowing its price, including post payout and hbd -> hive conversions. While only the top 20 witnesses's price feed is used(from what I've been told, please correct me if this is wrong), I believe its important for everyone running a witness to run a pricefeed. We have some pretty old pricefeeds in our witness rank, including some in the top 100 who've never broadcast a pricefeed at all and 4 in the top 30 who haven't updated their pricefeed in over a month.

I personally use @someguy123's hivefeed-js as I've been updating it myself too. It's quite easy to use and anyone on privex's node in a box gets it on their box so knowledge on how to use it might be useful. The codebase can be found here: https://github.com/someguy123/hivefeed-js.

Let's get onto the guide. If you are using privex's node in a box, you can skip the download the codebase part (the git pull). I'll also be explaining how to start it with node and pm2, not docker. The docker instructions are clear enough on the readme. Someguy says that he uses the docker version so he can restart it easily every few hours in case this breaks, but I've never seen it break due to reasons other than a bad node(which has since been fixed).

Set up

Always start with an update to the server, especially if you are like me and the first time is usually the only time you update your server. We'll also need git since we'll need to get the codebase. We'll also need nodejs and npm.

sudo apt update
sudo apt upgrade -y
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt install nodejs -y
sudo apt install npm -y
hash -r
sudo npm install -g npm

This will install node 18.

Clone the repo(if you already have it, skip this step)

git clone https://github.com/Someguy123/hivefeed-js.git

Navigate to the directory we cloned or already have, if it's named something else, just change over to it.

cd hivefeed-js

Install the dependencies with npm.

npm i

Install pm2 globally.

sudo npm i -g pm2

Modifying the config

Now we'll need to change the config file to our liking. First we'll need to copy the example config to just config.

cp config.example.json config.json

Then we'll want to open it up using a text editor. I like nano, it's the easiest to use by far.

nano config.json

I won't be explaining advanced config, just the simple stuff. The main fields that you want to pay attention to is name which should be your username, wif which should be your private active key(yes there is a way to sign price feed updates with just your witness signing key, so far the easiest way to do that is with beem, someguy was looking into incorporating that into hivefeed and if I have time, I'm trying to do the same as well), and interval which is how often you want to broadcast in minutes. I recommend somewhere between 1-6 hours. Broadcasting too much will have no use with slight price changes and you don't want to broadcast too little either as the opposite problem can occur with larger price changes(one of the things I want to add is broadcasting upon a price shift of x% from your last broadcast).

Those are the only ones you really need to change. There are a few other ones that I think you should know. node will let you pick the running node, the default being https://hived.privex.io and alternate_nodes will let you specify some alternate nodes to switch to if the default one fails. The default alternate nodes are https://api.hive.blog and https://api.deathwing.me. Node should just be a string and alternate_nodes should be an array of strings. Don't worry too much about these if you don't understand(feel free to ask me questions if you would like to learn more though).

Save your config. Time to start it up.

Starting up

Staring up is pretty simple.

pm2 start app.js --name priceFeed

Thanks to pm2, if it crashes, it will automatically restart(though if it has other errors not leading to a crash it will not restart). If you want to monitor it, you can do pm2 monitor to see the running program with live logs, or pm2 logs to see some older logs logs and as more are written to the logs, it will add more. If you need to stop it for any reason, you can do pm2 stop priceFeed.

You won't see the price feed immediately publish. The first publish will happen after the amount of minutes that you set in the config. And there you go, you have setup your pricefeed.

If you make any configuration changes, you'd need to restart it:

pm2 reload priceFeed

I do maintain the repo and so if you have any suggestions for features that you'd like, just lmk and if I ever find time for it, I'll get around to it. If you like what I do, considering voting my witness, @rishi556. Here's a handy link for that: https://vote.hive.uno/@rishi556

Sort:  

Hi @rishi556, is this still up to date?
My pricefeed was not working, a simple restart didn´t help, so I started from scratch.
When I was at this stage sudo apt install nodejs -y
I got this error:
image.png

Where I can find an updated nodejs?

Also, you are no longer under @hextech, aren´t you?

Think we got this up and running via discord. Even though this error appeared, node was still successfully installed. And no, I'm no longer under hextech, but have my own witness under my own name.

Many thanks!

Great post.

You are absolutely correct.

As you've described it is super easy to set up the price feed.

There is really no excuse for a witness to do it.

Yup, it's so simple yet so many out of the top 20 seem to ignore it.

Interestingly my price feed dropped out over the last 24 hours.
All I had to do was type ./run.sh restart to get it going again.

Which version were you running?

Good timing with this post. I need to set up HIVE price feed for my Witness node

Awesome to see that you got yours set up. Was the guide easy to follow?

Yes it was buddy :)

Hi @rishi556, it´s me again.
After sudo apt update it seems my storage is already too small, right?

image.png

I have ordered a larger one (+400GB), but in order to expand the existing partition, I have to run a script sudo apt install cloud-utils -y but this is also not possible due to lack of disc space ☹️.
Is there a way to remove some files from the hive-docker directory in order to change the partitoning?
If not I have to restart everything from scratch, right? At least now I know how to do it, but it is unfortunate to be offline again for 3 days after I have send out my announcement email :(.

You can delete stuff using rm FILENAME, if it's a folder, use rm -rf FOLDERNAME. Reclaiming storage might be a bit hard, I'd try with the logs first, generally located at :
/var/lib/docker/containers (you can just do cd /var/lib/docker/containers to get there.

You are going to need your container id, which you can figure out by doing docker ps and it'll be the first part listed:

ss.png

Copy that container id, type in cd past in the container id, and press tab for it to be auto completed. In that folder, there's going to be a CONATINAERID-json.log file. That's probably going to be the largest thing there, and might give you the room you need to get things going again. I normally install ncdu upon first setting up machines in order to have a good tool to easily see what's using my storage with, you can install it with sudo apt install ncdu. I don't know if there's a real lot you can gain from within the hive-engine directory though as the p2p logs are usually what's going to be the fullest and those have always been very tiny for me.

docker ps does not show any number, just an empty table:

image.png

Um, that's not a good sign. When you nagivate back to your hive-docker folder and do ./run.sh logs, is it able to pull up logs or not? Weird things happen when a device's storage gets full because applications aren't able to write the data they need and spew out errors and this might have been affected by that.

It shows recent blocks, but it is not continously tracking them like yesterday, but it stops always after app. 20 blocks :(

Hmm thats very weird, I'd definitely look into what could be eating that storage. How much space do you have? df -h should give a nice summary.

image.png
so there is some left, but not too much I guess