Browse Source

verifier: small clean-up

this code runs in the interface's group, so it's confusing to call the network's methods
master
SomberNight 4 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 .transaction import Transaction
from .blockchain import hash_header from .blockchain import hash_header
from .interface import GracefulDisconnect from .interface import GracefulDisconnect
from .network import UntrustedServerReturnedError
from . import constants from . import constants
if TYPE_CHECKING: if TYPE_CHECKING:
@ -82,13 +81,13 @@ class SPV(NetworkJobOnDefaultServer):
if tx_hash in self.requested_merkle or tx_hash in self.merkle_roots: if tx_hash in self.requested_merkle or tx_hash in self.merkle_roots:
continue continue
# or before headers are available # or before headers are available
if tx_height <= 0 or tx_height > local_height: if not (0 < tx_height <= local_height):
continue continue
# if it's in the checkpoint region, we still might not have the header # if it's in the checkpoint region, we still might not have the header
header = self.blockchain.read_header(tx_height) header = self.blockchain.read_header(tx_height)
if header is None: if header is None:
if tx_height < constants.net.max_checkpoint(): 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 continue
# request now # request now
self.logger.info(f'requested merkle {tx_hash}') 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): async def _request_and_verify_single_proof(self, tx_hash, tx_height):
try: try:
async with self._network_request_semaphore: async with self._network_request_semaphore:
merkle = await self.network.get_merkle_for_transaction(tx_hash, tx_height) merkle = await self.interface.get_merkle_for_transaction(tx_hash, tx_height)
except UntrustedServerReturnedError as e: except aiorpcx.jsonrpc.RPCError:
if not isinstance(e.original_exception, aiorpcx.jsonrpc.RPCError):
raise
self.logger.info(f'tx {tx_hash} not at height {tx_height}') self.logger.info(f'tx {tx_hash} not at height {tx_height}')
self.wallet.remove_unverified_tx(tx_hash, tx_height) self.wallet.remove_unverified_tx(tx_hash, tx_height)
self.requested_merkle.discard(tx_hash) self.requested_merkle.discard(tx_hash)

Loading…
Cancel
Save