Small optimization for large wallets
Previously the verifier job would scan all transactions in unverified_tx each time it ran. Nothing was ever removed from this map; it would essentially be the full set of transactions. As the job runs about 10 times a second, for a wallet with 500 txs this would be 5,000 useless loops a second. This patch makes unverified_tx be simply the set of confirmed transactions that haven't yet been verified. txs are added once confirmed, and removed once verified. Hence it will almost always be empty.
This commit is contained in:
@@ -33,9 +33,11 @@ class SPV(ThreadJob):
|
||||
self.merkle_roots = {}
|
||||
|
||||
def run(self):
|
||||
lh = self.wallet.get_local_height()
|
||||
unverified = self.wallet.get_unverified_txs()
|
||||
for (tx_hash, tx_height) in unverified:
|
||||
if tx_hash not in self.merkle_roots:
|
||||
for tx_hash, tx_height in unverified.items():
|
||||
# do not request merkle branch before headers are available
|
||||
if tx_hash not in self.merkle_roots and tx_height <= lh:
|
||||
request = ('blockchain.transaction.get_merkle',
|
||||
[tx_hash, tx_height])
|
||||
if self.network.send([request], self.merkle_response):
|
||||
@@ -64,6 +66,8 @@ class SPV(ThreadJob):
|
||||
merkle_root = self.hash_merkle_root(merkle['merkle'], tx_hash, pos)
|
||||
header = header.get('result')
|
||||
if not header or header.get('merkle_root') != merkle_root:
|
||||
# FIXME: we should make a fresh connection to a server to
|
||||
# recover from this, as this TX will now never verify
|
||||
self.print_error("merkle verification failed for", tx_hash)
|
||||
return
|
||||
|
||||
|
||||
Reference in New Issue
Block a user