Hive Engine Witness Restore Script

@blervin · 2021-10-29 15:38 · hiveengine

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.

#hiveengine #witness #hive #hivedev #blockchain #dev #node #nodejs
Payout: 0.000 HBD
Votes: 6
More interactions (upvote, reblog, reply) coming soon.