Last active
January 11, 2019 00:49
-
-
Save StephanieSunshine/8374dfe9ec4bd56891a946d068f8f736 to your computer and use it in GitHub Desktop.
EOS/Telos Find missing blocks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# | |
# This script is a crude way to figure out who is missing what blocks from our block producer logs | |
# usage: cat log/nodeos | egrep --line-buffered 'producer_plugin|start_block' | ./detective_missed.py | |
# | |
import sys | |
import iso8601 | |
import re | |
import json | |
notFirst = False | |
past = 0 | |
pastLine = '' | |
producers = [] | |
scheduleVersion = 0 | |
def on_incoming_block(line): | |
global past | |
global pastLine | |
global notFirst | |
global producers | |
if len(line) < 11 : return | |
current=int(iso8601.parse_date(line[11]).strftime('%s')) | |
if current-past > 1 and notFirst: | |
pastBlock = int(re.sub("#", "", pastLine[9])) | |
block = int(re.sub("#", "", line[9])) | |
blockDelta = block-pastBlock | |
if blockDelta == 1000 or blockDelta == 1 or blockDelta == 0 : | |
past = current | |
pastLine = line | |
notFirst = True | |
return | |
op = producers.index(pastLine[14]) | |
np = producers.index(line[14]) | |
if np > op: | |
violators = producers[op:np] | |
else: | |
violators = producers[op:]+producers[:np] | |
print "Found Gap Past:"+str(pastBlock)+"\tCurrent:"+str(block)+"\tTime Delta:"+str(current-past)+"\tBlocks Missed:"+str(block-pastBlock)+"\tLast Good Producer: "+pastLine[14]+"\tNext Good Producer: "+line[14]+"\tViolators: "+json.dumps(violators) | |
print pastLine | |
print line | |
else: | |
sys.stdout.write(".") | |
sys.stdout.flush() | |
past = current | |
pastLine = line | |
notFirst = True | |
def start_block(line): | |
global producers | |
global scheduleVersion | |
schedule = json.loads(line[21]) | |
if scheduleVersion == int(schedule['version']) : return | |
scheduleVersion = int(schedule['version']) | |
print "Schedule Change: Version "+str(schedule['version']) | |
producers = [] | |
for producer in schedule['producers']: | |
producers.append(producer['producer_name']) | |
#print json.dumps(producers) | |
while True: | |
line=sys.stdin.readline().split() | |
if line[4] == "on_incoming_block" : on_incoming_block(line) | |
if line[4] == "start_block" : start_block(line) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment