Check EOS Node Status - Python Script

in #eosio6 years ago (edited)

Anyone who has been on the launch of a new Blockchain will know that the process can be quite stressful. I have personally been maintaining a testnet node for EOS Argentina and the multiple chain forks inspired me to build this little script that checks your node´s Blockchain head number and compare it to another node, ideally to one that you know is on the main chain, but you could also compare two of you own nodes to check if they are on the same head_block_num.

Our node is in the jungle testnet so I compare my block with @cryptolions node since they are the BPs who maintain this chain and are usually in the latest block. This is what I initially came up with (bare in mind I have had very little sleep in the last few days):

import urllib.request
import json

url = urllib.request.urlopen('https://n2.eosargentina.io/v1/chain/get_info')
arg = url.read()
eosarg  = json.loads(arg)

eosargentina = (eosarg["head_block_num"])
eosargentina1 = str(eosargentina)
print ("eosargentina node is at block " + eosargentina1)

url = urllib.request.urlopen('http://dev.cryptolions.io:8888/v1/chain/get_info')
lion = url.read()
cryptolions  = json.loads(lion)

lionblock = (cryptolions["head_block_num"])
lionblock1 = str(lionblock)
print ("cryptolions node is at block " + lionblock1)

if eosargentina == lionblock:
        print ("is all good")
else :
        print ("we are forked!!!!")

A good friend of mine cleaned this code a little and made it more readable and scalable, I recommend you use his version:

import requests as r
import json

def get_head_block_from(url):
    res = json.loads(r.get('{0}/v1/chain/get_info'.format(url)).text)
    return int(res["head_block_num"])

eosargentina = get_head_block_from("https://n2.eosargentina.io")
cryptolions  = get_head_block_from("http://dev.cryptolions.io:8888")

if eosargentina == cryptolions:
    print ("is all good")
else :
    print ("we are forked!!!!")
    print (" - eosargentina : {0}".format(eosargentina))
    print (" - cryptolions  : {0}".format(cryptolions))

I hope this script can help others too, it certainly saved me a lot of time. I will be publishing more tools as we make them.

Until the next time.

see this code in gist

Sort:  

Great post sir.
You are so much talented person on steemit. 😊💙
I completely agree with you.

Python is very useful script.

I appreciate your work.
Very informative post.
Very well articulated.

Thanks @chitty sir for sharing this post.

Upvoted + resteemed your post.

To get this news delivered to us. Thank you

Even i want learn about coding blockchain , I got good knowledge of Java . Let me know from where to begin .

Great work @chitty, phython and many other softwares like c++, dev c++, apachetom cat are best for programing. Thanks for sharing this helpful program with your steemit friends.

wow nice great work bro........

python is one of the the most important apps for do programe.......

keep it bro
resteemed

Thank you so much for sharing, this is very useful for me, may God avenge the goodness of your heart, sharing that is wonderful

Helpful post for the steemit community. thanks a lot for sharing with us......@chitty

You got a 26.67% upvote from @dailyupvotes courtesy of @hcf27!

Please upvote this comment to support the service.

Si es muy estresante el lanzamiento del nuevo Blockchain. pero bueno el skrip me funciona a la perfecion gracias :D

Coin Marketplace

STEEM 0.19
TRX 0.15
JST 0.029
BTC 63635.72
ETH 2597.20
USDT 1.00
SBD 2.91