Witness Server Sentry v0.0.1 | An Open Source NodeJS + SteemJS Witness Failover Script

in #witness-category6 years ago (edited)

After the overflow blunder of my main witness server and failure of the failover script that was in place to prevent such block missing I set out to create my own missed block application to sign over keys to my backup in case of main server failure. Here it is!

Witness Server Sentry v0.0.1

You'll need a box capable of running NodeJS and the SteemJS library installed for this script to work properly. You can grab the required software and dependencies from the links below:

NodeJS - https://nodejs.org
SteemJS - https://www.npmjs.com/package/steem

I won't go into detail here on how to setup NodeJS or SteemJS at this point. A quick google search should yield the required information needed in order to get these 2 software offerings on your box. Once you have the above installed you can copy the code below:

//=============================================================================
//-----------------------------------------------------------------------------
//----- Witness Server Sentry v0.0.1 ----- Coded by: @KLYE ----- Open Source!
//----- Requires NodeJS + steemjs || Install with: npm install steem -u
//-----------------------------------------------------------------------------
//=============================================================================

// Load the steemjs library
var steem = require('steem');

// NOTE: Edit these 3 variables below with your own information!
var accountName = ""; // Witness Account Name
var wif = ""; // Posting Private Key
var blockSigningKey = ""; // Signing Key of Backup Witness

// No need to modify these variables!
var url;
var props;
var fee;
var initmissed;
var scanmissed;

// Start up Witness Server Sentry
console.log("NodeJS Witness Server Sentry v0.0.1 Starting...");
console.log("Design & Development by: @KLYE - Open Source");

// Retrieve total missed blocks of given witness & save to variables
steem.api.getWitnessByAccount(accountName, function(err, result) {
    if (err) {
        console.log("An Error Occured Fetching Init Missed Blocks!")
    };
    if (result) {
        url = result["url"];
        props = result["props"];
        fee = props["account_creation_fee"];
        initmissed = result["total_missed"];
    }
});

// Start up the real time Witness Server Sentry functionality
console.log("Firing Up Witness Server Sentry Block Detector");

// misswatcher function compares initial missed blocks to current
function misswatcher() {
    sleep(3000);
    steem.api.getWitnessByAccount(accountName, function(err, result) {
        if (err) {
            console.log("An Error Occured Fetching Missed Blocks!")
            console.log(err);
        };

        if (result) {
            console.log("SCAN - Total Missed by @" + accountName + " is " + result["total_missed"]);
            scanmissed = result["total_missed"];
            if (scanmissed > initmissed) {
                console.log("MISS - A Missed Block Was Detected!");
                steem.broadcast.witnessUpdate(wif, accountName, url, blockSigningKey, props, fee, function(err, result) {
                    if (err) {
                        console.log("Error Switching to Backup Witness! Please Check Your Variables!");
                        console.log(err);
                    }
                    if (result) {
                        console.log("Successfully Switched to Backup Witness!");
                        console.log(result);
                    }
                });
            }
            misswatcher();
        }
    });
}

// Call misswatcher() function again to loop
misswatcher();

// SLEEP Function to unfuck some nodeJS things - NO modify
function sleep(milliseconds) {
    var start = new Date().getTime();
    for (var i = 0; i < 1e7; i++) {
        if ((new Date().getTime() - start) > milliseconds) {
            break;
        }
    }
};



Make sure to add the required information in lines 10 through 13. You'll need your witness account name, it's active private key and the signing key for your backup witness in order for this script to function properly. Once you've got your variables set it's just a matter of running the script and letting it handle your key signing to backup server in the event it detects you've missed a block. This script is only good for 1 use and will have to be reset/restarted in the event it signs over to your backup key. Keep in mind this script has had minimum amounts of testing done and can likely be improved on. This is version 0.0.1... So it MAY contain bugs!

Github Link: https://github.com/klye-steem/Witness-Server-Sentry-v0.0.1

@KLYE takes no responsibility for loses caused by this software!


VOTE
KLYE

for Witness!
Sort:  

mmmm bb. * *adjusts wizard hat * *

Interesting. I wish I understood wizard language.

If my half fried brain can figure this stuff out I imagine you can as well. :)

well, aren't you fancY!

lol, this was written out of necessity not because I wanted to be fancy.. :D

Figured I'd share the code in hopes others may be able to use it to protect against missed blocks.. It likely does contain bugs... But was able to test it earlier and it appears to work, surely it can be improved upon though!

I was not being sarcastic... this is very cool and I dropped it in steemdevs post promotion

XD No worries man. I didn't take offence either way!

Thanks for the share of link. Much appreciated.

You coders fascinate me. I wrote, I guess what you could call code, for DBase II years ago around the mid-1980s after tearing up my leg in a training accident.

The Corps was justing starting to implement the use of computers. I was serving as an Operations Clerk while recuperating from my skiing accident.

I don't know much about these things, but good looking out for people that do!

Interesting!!!

Nice

this is a very interesting post.

Phyton language ?

Coin Marketplace

STEEM 0.28
TRX 0.12
JST 0.034
BTC 63152.69
ETH 3233.54
USDT 1.00
SBD 4.45