fix prefetch proofs for unconfirmed and separate prefetch logic
This commit is contained in:
parent
7bdcaa6737
commit
44b1178cfe
1 changed files with 13 additions and 6 deletions
|
@ -348,18 +348,25 @@ class BaseLedger(metaclass=LedgerRegistry):
|
||||||
)
|
)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def update_history(self, address):
|
def _prefetch_history(self, remote_history, local_history):
|
||||||
remote_history = yield self.network.get_history(address)
|
|
||||||
local_history = yield self.get_local_history(address)
|
|
||||||
proofs = {
|
proofs = {
|
||||||
entry['tx_hash']: self.network.get_merkle(entry['tx_hash'], entry['height'])
|
entry['tx_hash']: (
|
||||||
|
self.network.get_merkle(entry['tx_hash'], entry['height']) if entry['height'] > 0 else None
|
||||||
|
)
|
||||||
for index, entry in enumerate(remote_history)
|
for index, entry in enumerate(remote_history)
|
||||||
if index >= len(local_history) or (entry['tx_hash'], entry['height']) != local_history[index]
|
if index >= len(local_history) or (entry['tx_hash'], entry['height']) != local_history[index]
|
||||||
}
|
}
|
||||||
network_txs = {key: self.network.get_transaction(key) for key in proofs.keys()}
|
network_txs = {key: self.network.get_transaction(key) for key in proofs.keys()}
|
||||||
yield defer.DeferredList(list(proofs.values()) + list(network_txs.values()))
|
yield defer.DeferredList(list(filter(None, proofs.values())) + list(network_txs.values()))
|
||||||
proofs = {key: value.result for key, value in proofs.items()}
|
proofs = {key: value.result for key, value in proofs.items() if value}
|
||||||
network_txs = {key: value.result for key, value in network_txs.items()}
|
network_txs = {key: value.result for key, value in network_txs.items()}
|
||||||
|
return proofs, network_txs
|
||||||
|
|
||||||
|
@defer.inlineCallbacks
|
||||||
|
def update_history(self, address):
|
||||||
|
remote_history = yield self.network.get_history(address)
|
||||||
|
local_history = yield self.get_local_history(address)
|
||||||
|
proofs, network_txs = yield self._prefetch_history(remote_history, local_history)
|
||||||
|
|
||||||
synced_history = StringIO()
|
synced_history = StringIO()
|
||||||
for i, (hex_id, remote_height) in enumerate(map(itemgetter('tx_hash', 'height'), remote_history)):
|
for i, (hex_id, remote_height) in enumerate(map(itemgetter('tx_hash', 'height'), remote_history)):
|
||||||
|
|
Loading…
Add table
Reference in a new issue