Skip to content
Snippets Groups Projects
Commit 5ec702e5 authored by Robert Martin-Legene's avatar Robert Martin-Legene
Browse files

Check local computer time against NIST

parent 587434ac
No related branches found
No related tags found
No related merge requests found
...@@ -9,10 +9,15 @@ use warnings; ...@@ -9,10 +9,15 @@ use warnings;
use Carp; use Carp;
use Math::BigInt; use Math::BigInt;
use JSON; use JSON;
use IO::Socket::INET;
BEGIN { BEGIN {
die "\$BFAHOME not set. Did you source bfa/bin/env ?\n" die "\$BFAHOME not set. Did you source bfa/bin/env ?\n"
unless exists $ENV{BFAHOME}; unless exists $ENV{BFAHOME};
} }
my %network = (
47525974938 => 'BFA red principal [est. 2018]',
55555000000 => 'BFA red de pruebas numero 2 [est. 2019]',
);
chdir $ENV{BFAHOME} or die $!; chdir $ENV{BFAHOME} or die $!;
use lib $ENV{'BFAHOME'}.'/bin'; use lib $ENV{'BFAHOME'}.'/bin';
use libbfa; use libbfa;
...@@ -151,8 +156,49 @@ sub rpc ...@@ -151,8 +156,49 @@ sub rpc
my $netversion = rpc( $libbfa, 'net_version' ); my $netversion = rpc( $libbfa, 'net_version' );
if ( $netversion ) if ( $netversion )
{ {
printf "Running on network number %s\n", $netversion; if ( exists $network{$netversion} )
{
printf "Running on network %s (#%s)\n", $network{$netversion}, $netversion;
} else {
printf "Running on network %s\n", $netversion;
}
} }
### compare time
use constant days70y => 25567;
my $s = IO::Socket::INET->new(
PeerAddr => "time.nist.gov:37",
Timeout => 3,
);
if ( defined $s )
{
$s->recv(my $data, 8);
my $i = unpack('N', $data);
if ( $i > 0 )
{
# rfc868 offset (seconds from 1900-01-01 to 1970-01-01)
$i -= 2208988800;
printf "NIST time: %s\n", scalar(localtime($i));
my $heretime = time();
printf "Here time: %s\n", scalar(localtime($i));
if ( abs($i - $heretime) > 5 )
{
print "WHY IS YOUR CLOCK OFF?";
}
}
}
### latest block
$result = rpc( $libbfa, 'eth_getBlockByNumber', '"latest"', "true" );
my $block = block->new( $result );
my $timediff = time()-$block->timestamp;
printf
"Our latest block number is %d. It's timestamp says %s (%s old).\n",
$block->number,
gmt($block->timestamp),
nicetimedelta( $timediff );
### syncing ? ### syncing ?
my $syncing = rpc( $libbfa, 'eth_syncing' ); my $syncing = rpc( $libbfa, 'eth_syncing' );
if ( $syncing ) if ( $syncing )
...@@ -167,31 +213,22 @@ if ( $syncing ) ...@@ -167,31 +213,22 @@ if ( $syncing )
} }
else else
{ {
print "We are currently not syncing (this is normal if you have all the blocks).\n"; if ( $timediff > 90 )
{
print "We are currently not syncing. WHY ARE OUR BLOCKS SO OLD?\n";
} else {
print "We have all the blocks and are not syncing.\n";
}
} }
### mining ? ### mining ?
$result = rpc( $libbfa, 'eth_mining' ); $result = rpc( $libbfa, 'eth_mining' );
if ( $result ) if ( $result )
{ {
printf "We mine when we can.\n"; printf "We are a sealer and are configured seal.\n";
} else {
print "We do not seal.\n";
} }
else
{
print "We do not mine.\n";
}
### latest block
$result = rpc( $libbfa, 'eth_getBlockByNumber', '"latest"', "true" );
my $block = block->new( $result );
my $timediff = time()-$block->timestamp;
printf
"Our latest block number is %d. It's timestamp says %s (%s old).\n",
$block->number,
gmt($block->timestamp),
nicetimedelta( $timediff );
print "WHY IS IT SO OLD?\n"
if $timediff > 90;
# List peers # List peers
$result = rpc( $libbfa, 'admin_peers' ); $result = rpc( $libbfa, 'admin_peers' );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment