Browse Source

verifier: small clean-up

this code runs in the interface's group, so it's confusing to call the network's methods
patch-4
SomberNight 3 years ago
parent
commit
250795f137
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 11
      electrum/verifier.py

11
electrum/verifier.py

@ -32,7 +32,6 @@ from .bitcoin import hash_decode, hash_encode
from .transaction import Transaction
from .blockchain import hash_header
from .interface import GracefulDisconnect
from .network import UntrustedServerReturnedError
from . import constants
if TYPE_CHECKING:
@ -82,13 +81,13 @@ class SPV(NetworkJobOnDefaultServer):
if tx_hash in self.requested_merkle or tx_hash in self.merkle_roots:
continue
# or before headers are available
if tx_height <= 0 or tx_height > local_height:
if not (0 < tx_height <= local_height):
continue
# if it's in the checkpoint region, we still might not have the header
header = self.blockchain.read_header(tx_height)
if header is None:
if tx_height < constants.net.max_checkpoint():
await self.taskgroup.spawn(self.network.request_chunk(tx_height, None, can_return_early=True))
await self.taskgroup.spawn(self.interface.request_chunk(tx_height, None, can_return_early=True))
continue
# request now
self.logger.info(f'requested merkle {tx_hash}')
@ -98,10 +97,8 @@ class SPV(NetworkJobOnDefaultServer):
async def _request_and_verify_single_proof(self, tx_hash, tx_height):
try:
async with self._network_request_semaphore:
merkle = await self.network.get_merkle_for_transaction(tx_hash, tx_height)
except UntrustedServerReturnedError as e:
if not isinstance(e.original_exception, aiorpcx.jsonrpc.RPCError):
raise
merkle = await self.interface.get_merkle_for_transaction(tx_hash, tx_height)
except aiorpcx.jsonrpc.RPCError:
self.logger.info(f'tx {tx_hash} not at height {tx_height}')
self.wallet.remove_unverified_tx(tx_hash, tx_height)
self.requested_merkle.discard(tx_hash)

Loading…
Cancel
Save