-
Notifications
You must be signed in to change notification settings - Fork 0
/
FindMissing.py
95 lines (72 loc) · 2.63 KB
/
FindMissing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env python3
#FINDS MISSING BLOCKS IN DATABASE
# Copyright (C) <2020> <Garth Madden, Garthmadden809@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import pymongo
from web3 import Web3
import config
import collections
from os import system
web3 = config.geth()
blockHeight = []
blockNumber = 0
missingBlocks = []
missingBlocksFinal = []
jump = 0
mylist = 0
#BlockTestHeight = 250000 #UNHASH FOR TESTING
count = 0
for x in config.block.find().sort([('_id', -1)]).limit(1):
BlockTestHeight = x["number"] #HASH FOR TESTING SETS BLOCK LIMIT
def clear():
_ = system('clear')
def find_missing(blockHeight):
return [x for x in range(blockHeight[0], blockHeight[-1]+1) if x not in blockHeight]
while blockNumber < BlockTestHeight:
for x in config.block.find().skip(jump).limit(15000):
blockHeight.append(x["number"])
count = count + 1
clear()
mylist = '{:.2f}%'.format(blockNumber / BlockTestHeight * 100)
print (f'Gathering {mylist} Complete {blockNumber} of {BlockTestHeight}')
print(f'Possible Missing Blocks {len(missingBlocks)}')
print(f'Confirmed Missing Blocks {len(missingBlocksFinal)}')
print(f'Total Blocks Accounted For {count}')
maybemissed = find_missing(blockHeight)
if maybemissed != 0:
missingBlocks.extend(maybemissed)
if len(missingBlocks) > 1000:
print("Flagged Blocks Exceed 1K, Checking Manually To Clear Cache")
for x in missingBlocks:
if myCol.count_documents({"number": x}, limit=1) == 0:
missingBlocksFinal.append(x)
print("NOT FOUND")
missingBlocks = []
#missingBlocks = []
blockHeight = []
blockNumber = blockNumber + 15000
jump = jump + 15000
print()
print("Testing for Flagged Blocks")
for x in missingBlocks:
if myCol.count_documents({"number": x}, limit=1) == 0:
missingBlocksFinal.append(x)
print()
if len(missingBlocksFinal) == 0:
print("No Missing Blocks!")
else:
print(f'MISSING BLOCKS! {missingBlocksFinal}')
print()
print("COMPLETE")