Whaleshares Logo

WITNESS ALERT SYSTEM - an email I hope not to receive

ijmmaiwitnessPosted to Public5 months ago3 min read

A witness server is nothing more than a computer, often in a remote location, running blockchain software. Communicating with this computer is done by typing commands in a terminal screen. That is just a black screen with a prompt, waiting for your commands.


As with your own computer, things can go wrong. When the witness server stops, it will not be able to accept blocks from the blockchain. As a witness you want to know when this happens, in order to be able to fix it as soon as possible.

@bushkill-witness wrote about a system to monitor (and switch to backup server) that includes a raspberry pi. I went with another approach. A simple PHP script combined with a cronjob. This script has just basic functionality at the moment. Changes will be made in the future.

The script:

  • retrieves witness account data from a fullnode
  • checks the 'total_missed' value against a given value
  • if these values don't match, sends an email to a given email address
$send = false;
$missedSofar = 137;
$totalMissed = 0;
$witness = 'witnessaccountname';
$email = '[email protected]';
$url = 'https://wls.fullnodeyouwanttoconnectto.ext';
$postData = array(
       "jsonrpc" => "2.0",
       "params" => [$witness, 1],
       "id" => 2,
       "method" => "database_api.get_witnesses_by_vote"

$postFields = json_encode($postData);
$handle = curl_init();
curl_setopt($handle, CURLOPT_URL, $url);
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_POSTFIELDS, $postFields);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);

$reply = curl_exec($handle);
$responseCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);

if ("200" == $responseCode) {
$data = json_decode($reply);
$totalMissed = $data->result[0]->total_missed;

if ( $totalMissed > $missedSofar ) $send = true;

if ( $send ) {
$headers = "From:WITNESS ALERT SYSTEM <[email protected]>";
mail( $email, 'You are missing blocks', "Your witness server $witness, is missing blocks", $headers);

the code displays a little weird after copy paste.

The cronjob

  • runs the script every 10 minutes

Assuming you saved the script to file wintessmonitor.php, the cronjob command would look like:
*/10 * * * * <path to php> <path to script file>witnessmonitor.php

More Functionality

This script can easily be extended to

  • make $missedSofar dynamic by storing it in a file
  • set a threshold before sending a message
  • report on fullnode errors
  • switch to backup server
  • and so on

Image Source

Use your witness votes wisely

Jump over to the Block Producer / Witness page and cast your witness votes. Simply click on the (^) up arrow next to the witness names of your choice (consider voting for "krazywitness" and "ijmmaiwitness") and supply your private active key to lock in your vote. Refresh the page in case your vote doesn't seem to stick.


Sort byOldest