Hive Engine Witness Restore Script

in #hiveengine2 years ago

Hive Engine Witness Restore Script

Some of you may have noticed my missed blocks constantly increasing to a crazy number today, not one of my prouder accomplishments.

The issue is, my Hive Engine witness really does go down. A lot. And the weird part is, I never see a clear reason in the logs, I'm not divergent, and things just continue running.

So, I wrote a script to see if I am offline, and then to just re-enable my witness. This basically works well.

The larger issue here is why I'm going down so much. Like I said, nothing in the logs so I'm not even sure where to begin now. I'm looking for feedback to see how everyone else is handling this to see if we can find some common reason for these issue.

Another consistent issue is that any time we have an upgrade, right after the upgrade I start going down a lot again. Most of my missed blocks are immediately after an upgrade. The ansewr is always to restore a fresh backup and start over, something that takes half a day most times.

I wanna throw this script out for everyone else, as I assume we're all going down for no reason when things really will just continue running without issue. This script basically makes an API call to see if your witness is online, and if not, send a transaction to enable it.

Mostly I'm hoping to hear your thoughts on ways to make these witnesses more reliable and avoid these missed blocks.

The Script

const axios = require('axios')
const hive = require('@hiveio/hive-js');
const fs = require('fs');
const date = require('date-and-time');

var postingKey = 'yourpostingkey';
var requiredAuths = ['yourusername'];
var requiredPostingAuths = []
var id ='ssc-mainnet-hive';

var json = JSON.stringify({
  "contractName": "witnesses",
  "contractAction": "register",
  "contractPayload": {
    "IP": "your_ip_address",
    "RPCPort": 5000,
    "P2PPort": 5001,
    "signingKey": "STM...",
    "enabled": true
  }
});

var url = 'https://api.hive-engine.com/rpc/contracts';

var data = {
    "jsonrpc": "2.0",
    "method": "find",
    "params": {
        "contract": "witnesses",
        "table": "witnesses",
        "query": {"account": "yourusername"}
    },
    "id": 1
}

const now = new Date();
date.format(now, 'YYYY/MM/DD HH:mm:ss');

axios.post(url, data).then(function (response) {
    var enabled = response.data.result[0].enabled;
    if(!enabled){
        hive.broadcast.customJson(postingKey, requiredAuths, requiredPostingAuths, id, json, function(err, result) {
          console.log(err, result);
        });
    } else {
        console.log(date.format(now, 'YYYY/MM/DD HH:mm:ss') + ' - All good');
    }
})

crontab

* * * * * root node /var/nodejs/he_witness_check.js >> /var/log/he_witness_check.log

The crontab writes to a log so you can see what's happening with the script.

Sort:  

Hey mate, sorry to jump in off-topic.
Do you mind reviewing and supporting the Hive Authentication Services proposal? That would be much appreciated.
Your feedback about the project is welcome too.
Thank you.

Congratulations @blervin! You have completed the following achievement on the Hive blockchain and have been rewarded with new badge(s) :

You distributed more than 77000 upvotes.
Your next target is to reach 78000 upvotes.

You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

Check out the last post from @hivebuzz:

Feedback from the November 1st Hive Power Up Day
Support the HiveBuzz project. Vote for our proposal!


@blervin, sorry to see you have less Hive Power.
Your level lowered and you are now a Red Fish!

Check out the last post from @hivebuzz:

Hive Power Up Month - Feedback from Day 21