check consistency of results received by get_history

This commit is contained in:
ThomasV 2012-11-07 09:37:14 +01:00
parent e39a5c9609
commit a48a971ae6
2 changed files with 26 additions and 6 deletions

View File

@ -31,6 +31,7 @@ DEFAULT_SERVERS = [
#'uncle-enzo.info:50001:t',
#'electrum.bitcoin.cz:50001:t',
#'electrum.bitfoo.org:50001:t',
'webbtc.net:50001:t',
'electrum.bysh.me:50001:t',
'electrum.pdmc.net:50001:t',
'ecdsa.org:50001:t'

View File

@ -525,9 +525,11 @@ class Wallet:
return s
def get_status(self, address):
def get_history(self, address):
with self.lock:
h = self.history.get(address)
return self.history.get(address)
def get_status(self, h):
if not h: return None
status = ''
for tx_hash, height in h:
@ -981,17 +983,34 @@ class WalletSynchronizer(threading.Thread):
if method == 'blockchain.address.subscribe':
addr = params[0]
if self.wallet.get_status(addr) != result:
if self.wallet.get_status(self.wallet.get_history(addr)) != result:
self.interface.send([('blockchain.address.get_history', [addr])], 'synchronizer')
requested_histories[addr] = result
elif method == 'blockchain.address.get_history':
addr = params[0]
hist = []
# in the new protocol, we will receive a list of (tx_hash, height)
for item in result: hist.append( (item['tx_hash'], item['height']) )
# store it
# check that txids are unique
txids = []
for item in result:
tx_hash = item['tx_hash']
if tx_hash not in txids:
txids.append(tx_hash)
hist.append( (tx_hash, item['height']) )
if len(hist) != len(result):
print "error: non-unique txid"
continue
# check that the status corresponds to what was announced
if self.wallet.get_status(hist) != requested_histories.pop(addr):
print "error: status mismatch:", addr
continue
# store received history
self.wallet.receive_history_callback(addr, hist)
# request transactions that we don't have
for tx_hash, tx_height in hist:
if self.wallet.transactions.get(tx_hash) is None: