-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathverify_blocks.py
103 lines (77 loc) · 2.89 KB
/
verify_blocks.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
95
96
97
98
99
100
101
102
103
#! /usr/bin/env python
# coding: utf-8
# Licensed under the MIT License.
from pymongo import MongoClient, DESCENDING, ASCENDING
from Block.RpcClient import RpcClient
from Storage.Mongo import Mongo
from bson.objectid import ObjectId
import time
import os
from multiprocessing import Pool, cpu_count
from binascii import unhexlify
from utils.tools import Tool
from binascii import unhexlify
# import argparse
from dotenv import load_dotenv, find_dotenv
import logzero
from logzero import logger
from handle import save_block
from utils.tools import get_best_node
logzero.logfile(os.getcwd() + "/log/main.log", maxBytes=1e10, backupCount=1)
load_dotenv(find_dotenv(), override=True)
m = Mongo(os.environ.get('MONGODB'), os.environ.get('DB'))
work_count = cpu_count()
def verify_blocks(start):
try:
## random node
node = get_best_node()
if node == '':
return
b = RpcClient(node)
end = b.get_block_count()
print('end',end)
m_block = m.connection()['block'].find({'index': {'$gte': 0}},{'index':1}).sort('index',ASCENDING)
print('m_block',m_block.count())
point = 0
for item in m_block:
print('item.index',item['index'])
if point != item['index']:
logger.info('verify_blocks %s',point)
m_block = save_block(b, point, 0)
if m_block is None:
save_block(b, point, 0)
m.connection()['state'].update_one({'_id':ObjectId('5a95047efc2a4961941484e6')},{
'$set':{
'height': point
}
})
point = point + 1
print('end')
# for i in range(0,end,skip):
# print('i',i)
# print('i + skip - 1',i + skip - 1)
# m_count = m.connection()['block'].find({'index': {'$gte': i, '$lte': i + skip - 1}}).count()
# print('m_count',m_count)
# if m_count != skip:
# logger.info('verify_blocks %s',i)
# end = b.get_block_count()
# for i in range(start,end):
# #print('index',i)
# m_block = m.connection()['block'].find_one({'index': i},{'index':1})
# if m_block is None:
# logger.error('verify_blocks txid %s',i)
# #print('save_block',i)
# save_block(i, 0)
# m.connection()['state'].update_one({'_id':ObjectId('5a95047efc2a4961941484e6')},{
# '$set':{
# 'height': i
# }
# })
except Exception as e:
logger.exception(e)
if __name__ == "__main__":
try:
verify_blocks(0)
# verify_blocks(m.connection()['state'].find_one({'_id':ObjectId('5a95047efc2a4961941484e6')})['height'])
except Exception as e:
logger.exception(e)