forked from sigwo/pywavestools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchecknode.py
30 lines (26 loc) · 1.12 KB
/
checknode.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
import requests
REF_NODE = "https://nodes.wavesnodes.com"
MY_NODE = "http://127.0.0.1:6869"
def getSig(node, block):
req = requests.get(node + '/blocks/' + block).json()
return req['signature'], req['height']
def findFork(first, last):
print("..searching fork (%d) " % last)
mySig0 = getSig(MY_NODE, "at/%d" % (last - 1))
refSig0 = getSig(REF_NODE, "at/%d" % (last - 1))
mySig1 = getSig(MY_NODE, "at/%d" % last)
refSig1 = getSig(REF_NODE, "at/%d" % last)
if mySig0==refSig0 and mySig1!=refSig1:
return last
if mySig0==refSig0 and mySig1==refSig1:
return findFork(last, last + round(abs(last -first) / 2))
if mySig0!=refSig0 and mySig1!=refSig1:
return findFork(last, last - round(abs(last -first) / 2))
mySig, myHeight = getSig(MY_NODE, "last")
refSig, refHeight = getSig(REF_NODE, "last")
if mySig==refSig and myHeight==refHeight:
print("NODE OK - SYNCED")
elif myHeight < refHeight and getSig(MY_NODE, "at/%d" % myHeight)[0] == getSig(REF_NODE, "at/%d" % myHeight)[0]:
print("NODE NOT SYNCED")
else:
print("NODE FORKED AT %d" % findFork(0, min(myHeight, refHeight)))