You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
2.0 KiB

13 years ago
#!/usr/bin/env python
11 years ago
import time, electrum, Queue
from electrum import Interface, SimpleConfig
from electrum.network import filter_protocol, parse_servers
from collections import defaultdict
11 years ago
# 1. start interface and wait for connection
interface = electrum.Interface('ecdsa.net:50002:s')
interface.start(wait = True)
if not interface.is_connected:
print "not connected"
exit()
11 years ago
# 2. get list of peers
q = Queue.Queue()
interface.send([('server.peers.subscribe',[])], lambda i,x: q.put(x))
r = q.get(timeout=10000)
peers = parse_servers(r.get('result'))
peers = filter_protocol(peers,'s')
11 years ago
# start interfaces
config = SimpleConfig()
interfaces = map ( lambda server: Interface(server, config), peers )
results_queue = Queue.Queue()
reached_servers = []
for i in interfaces: i.start(q)
11 years ago
while peers:
11 years ago
i = q.get(timeout=10)
11 years ago
peers.remove(i.server)
if i.is_connected:
i.send([('blockchain.headers.subscribe',[])], lambda i,x: results_queue.put((i,x)))
reached_servers.append(i.server)
def analyze(results):
out = {}
dd = {}
for k, v in results.items():
height = v.get('block_height')
merkle = v.get('merkle_root')
utxo = v.get('utxo_root')
d = dd.get(merkle, defaultdict(int))
d[utxo] += 1
dd[merkle] = d
refs = {}
for merkle, d in dd.items():
v = d.values()
m = max(v)
ref = d.keys()[v.index(m)]
refs[merkle] = ref, m
for k, v in results.items():
height = v.get('block_height')
merkle = v.get('merkle_root')
utxo = v.get('utxo_root')
ref_utxo, num = refs.get(merkle)
if ref_utxo != utxo and num > 1:
out[k] = height, merkle, utxo
return out
results = {}
while reached_servers:
i, r = results_queue.get(timeout=10000)
results[i.server] = r.get('result')
reached_servers.remove(i.server)
errors = analyze(results).keys()
for n,v in results.items():
print "%40s"%n, v['block_height'], v['utxo_root'], "error" if n in errors else "ok"
13 years ago