commit a48a971ae63b32ce94c1236c05d34d1b25219a84
parent e39a5c9609c1f900a64c014265ea61ff32fdbd29
Author: ThomasV <thomasv@gitorious>
Date: Wed, 7 Nov 2012 09:37:14 +0100
check consistency of results received by get_history
Diffstat:
2 files changed, 26 insertions(+), 6 deletions(-)
diff --git a/lib/interface.py b/lib/interface.py
@@ -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'
diff --git a/lib/wallet.py b/lib/wallet.py
@@ -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: