Zero to Witness: Part 11: Publishing the Price Feed

in #witness2 years ago (edited)

I'm thrilled to report that @steemwow witnessed its first block overnight. Big thanks to everyone who's given us a witness vote!

banner.png

In part 8, I described how one important responsibility of a good witness is to publish a Steem price feed onto the blockchain.

This is used by the network to determine the Steem price in a decentralised, consensus-based way. When Steemit shows you dollar values in your wallet, or next to posts, etc, this consensus-based price is what's used.

To calculate it, the median price is taken from the last 3.5 days of price feeds published by witnesses.

Let's get our witness node set up to automatically push prices onto the chain.

Install pre-requisites

Log in to the server over SSH as usual, update the apt indices, and install git, Node.js, and npm:

sudo apt update
sudo apt install git nodejs npm

NOTE: There are, at last count, about a bazillion ways to install Node.js and npm. If you already have a favourite, feel free to use it. For simplicity we're just installing with apt, which works totally fine for this.

git is a very powerful distributed version control system for programmers. We're not going to be doing any coding today, but we need git to make it easy to pull down codebases from GitHub, a very popular place for open source developers to publish their code.

Node.js allows JavaScript code to run on the server (it's traditionally more commonly run inside a browser instead).

npm is the Node.js Package Manager, and makes it easy to install dependencies and start/stop Node.js applications.

Install the Price Feed script

Building on the work of @yabapmatt and @justyy, I've developed an improved Price Feed script, which is what we'll install today.

The price feed script grabs the latest Steem price from 3 separate sources: CoinMarketCap, CoinGecko and CryptoCompare.

It takes an average of all 3, then publishes the price to the blockchain.

This happens at an adjustable frequency; by default a feed is published every hour.

Let's install it! First, we grab the code from my GitHub:

git clone https://github.com/rexthetech/pricefeed

Next, we'll enter the directory that was created by the clone command, and use npm to install required Node.js packages:

cd pricefeed
npm install

Configure the script

The price feed needs a CoinMarketCap API key. Sign up for a free API key. We only need the lowest level "Basic" key.

Now edit the script config file:

nano config.json

Fill in the following values:

  • feed_steem_account: The Steem name of the witness we're publishing for. In my case, steemwow.

  • feed_steem_active_key: The Private Active Key for the witness account (from the PDF we grabbed from Steemit after creating the account).

  • coinmarketcap_api_key: The API key you just created.

If you really don't want to create a CoinMarketCap API key, edit the exchanges line as follows (otherwise, leave it alone):

 "exchanges": ["coingecko", "cryptocompare"],

That's it -- save and exit nano.

Test it!

Let's manually start the script, just to make sure it runs OK:

npm start

If all goes well, you'll see prices being grabbed, followed by a "Broadcast successful" message:

price feed.PNG

Note that it will take 30 seconds between showing the prices and publishing the feed.

Once you've confirmed it's working, Ctrl-C to stop it for now. Head over to your preferred witness ranking table; this one of @justyy's is my favourite as it shows everything.

On your row, you should see the Steem price that you just published. On justyy's table, you can also see how long ago in hours your feed was last published.

Make it run in the background and start at reboot

This is another case where we have a load of options. We could stick it in a Docker container, we could start it from crontab as for Steem; but in the case of Node.js applications there's a convenient process manager called PM2 that we'll use.

Let's install it with npm:

sudo npm install pm2 -g

The -g switch makes npm install PM2 globally, so that it's available for all Node.js applications. The global install is why it needs the sudo.

We'll now make it so that PM2 itself starts on boot. To do this, run:

pm2 startup

You'll notice it instructs us to copy and paste a command into the shell:

pm2.png

Go ahead and run the command it asks you to.

Next, we'll have PM2 start the price feed script:

pm2 start ~/pricefeed/feed.js

Because PM2 runs the script in the background, you won't see any output. However, there's a nifty tool that lets us peek on the background process to make sure everything's running as it should. To access that, do:

pm2 logs

pm2-more.PNG

Hit Ctrl-C to quit the log viewer.

The final step is to call PM2's "save" command. That tell PM2 that all scripts that it's currently running should be started automatically on reboot.

Let's do it:

pm2 save

That's it, we're all done. You can safely log out of SSH, and the price feed will keep running.

The... End?!

No, young padawan, this is only the beginning!! But, err, yes -- this is actually the last episode of Zero to Witness. If you've followed along and installed your own node, I really hope you've enjoyed becoming a witness as much as I have.

Remember you can set up a Seed Node by following the series again, but stopping at the end of Part 7. You'll be amazed how much faster it is now that you've done it before.

And big thanks, of course, to my teammate @freelance.monkey. We have some exciting Steem projects planned and are just trying to pick which of several ideas we'll pursue first.

Vote for SteemWOW!

At time of writing, we're #128 in the witness ranking table. With your help, we can climb skywards!

We'd be very glad if you would support us by casting a witness vote for SteemWOW.

Simply go to the Steemit Wallet Witness list, scroll to the bottom, and fill in the form:

vote for us.PNG

Series Index

Part 1: We need a big computer!
Part 2: Connecting to the server
Part 3: Securing the server (see also Passwords: A Rant)
Part 4: Enabling certificate authentication
Part 5: Downloading the blockchain
Part 6: Unpacking the blockchain and configuring Steem
Part 7: Starting and syncing Steem
Part 8: Witness responsibilities
Part 9: Generating witness keys
Part 10: Witness Up!

Sort:  

Big thanks for this great series and good luck as Witness!

Two questions are buzzing in my head:

1.) The price feed is optional, right? (I know, a good Witness...)
2.) The final update_witness command in Part 10 activates the Witness. Do you know the command to deactivate the server on the chain?
I found this command here:

update_witness "WITNESS_NAME" "CAMPAIGN_POST_LINK" "STM1111111111111111111111111111111114T1Anm" {"account_creation_fee":"3.370 STEEM","maximum_block_size":65536,"sbd_interest_rate":0} true

Is that still correct?

Thank you!

  1. If you look at @justyy's witness ranking table, only 4 out of the top 50 witnesses do not publish a price feed. While it's technically optional, in that your witness will still produce blocks without publishing it, the price feed is ultimately required for Steem to function correctly. So, if you want witness votes, I think it's basically essential :)

  2. Yes, that specific stop key "STM1111111111111111111111111111111114T1Anm" is still the correct way to deactivate your witness.

I think the original idea of this particular stop key is that it would parse as a valid key in that its checksum is valid, but it's obvious to look at it that it could not have been generated randomly - therefore it's impossible for anyone to have the corresponding private key.

However, it doesn't actually seem to parse as a valid key! Various tools have a special case for it.

Ah, thank you very much! The buzzing is over :-)

I was able to build the environment according to @rexthetech's "Zero to Witness". and became a witness. I'm really thankful to you. By the way, is there a part where you can confirm that you have become a witness without actually feeling that you have become a witness?

@rexthetech さんの「Zero to Witness」に従って、環境構築ができました。そして、証人になりました。本当にありがとうございました。ところで、証人になった実感がなく、証人になったことが確認できる箇所がありますか?

Coin Marketplace

STEEM 0.21
TRX 0.25
JST 0.038
BTC 96989.50
ETH 3378.64
USDT 1.00
SBD 3.23