Browse Source

wallet: don't try to get_input_tx from network when offline

related: https://github.com/spesmilo/electrum/issues/6648#issuecomment-708499893

Trying to fetch the prev tx from the network is a blocking operation with
a 10 sec timeout - we should not hang for 10 seconds if there is no network connection.
patch-4
SomberNight 4 years ago
parent
commit
bde415cae7
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 6
      electrum/network.py
  2. 2
      electrum/wallet.py

6
electrum/network.py

@ -328,6 +328,7 @@ class Network(Logger, NetworkRetryManager[ServerAddr]):
self.debug = False
self._set_status('disconnected')
self._has_ever_managed_to_connect_to_server = False
# lightning network
self.channel_db = None # type: Optional[ChannelDB]
@ -339,6 +340,10 @@ class Network(Logger, NetworkRetryManager[ServerAddr]):
self.local_watchtower.start_network(self)
asyncio.ensure_future(self.local_watchtower.start_watching())
def has_internet_connection(self) -> bool:
"""Our guess whether the device has Internet-connectivity."""
return self._has_ever_managed_to_connect_to_server
def is_lightning_running(self):
return self.channel_db is not None
@ -768,6 +773,7 @@ class Network(Logger, NetworkRetryManager[ServerAddr]):
if server == self.default_server:
await self.switch_to_interface(server)
self._has_ever_managed_to_connect_to_server = True
self._add_recent_server(server)
util.trigger_callback('network_updated')

2
electrum/wallet.py

@ -1613,7 +1613,7 @@ class Abstract_Wallet(AddressSynchronizer, ABC):
# will likely be. If co-signing a transaction it may not have
# all the input txs, in which case we ask the network.
tx = self.db.get_transaction(tx_hash)
if not tx and self.network:
if not tx and self.network and self.network.has_internet_connection():
try:
raw_tx = self.network.run_from_another_thread(
self.network.get_transaction(tx_hash, timeout=10))

Loading…
Cancel
Save