electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 4f741cfcccef00dae94e571de57d914801601d5e
parent 58681e4d077fe9eb9670222252a19db49f671ddd
Author: SomberNight <somber.night@protonmail.com>
Date:   Thu,  5 Sep 2019 18:31:51 +0200

lnpeer: longer timeouts

Diffstat:
Melectrum/lnpeer.py | 19+++++++++++--------
Melectrum/lnworker.py | 4++--
2 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/electrum/lnpeer.py b/electrum/lnpeer.py @@ -53,6 +53,9 @@ if TYPE_CHECKING: from .lnrouter import RouteEdge +LN_P2P_NETWORK_TIMEOUT = 20 + + def channel_id_from_funding_tx(funding_txid: str, funding_index: int) -> Tuple[bytes, bytes]: funding_txid_bytes = bytes.fromhex(funding_txid)[::-1] i = int.from_bytes(funding_txid_bytes, 'big') ^ funding_index @@ -308,12 +311,12 @@ class Peer(Logger): async def query_gossip(self): try: - await asyncio.wait_for(self.initialized.wait(), 10) + await asyncio.wait_for(self.initialized.wait(), LN_P2P_NETWORK_TIMEOUT) except asyncio.TimeoutError as e: raise GracefulDisconnect("initialize timed out") from e if self.lnworker == self.lnworker.network.lngossip: try: - ids, complete = await asyncio.wait_for(self.get_channel_range(), 10) + ids, complete = await asyncio.wait_for(self.get_channel_range(), LN_P2P_NETWORK_TIMEOUT) except asyncio.TimeoutError as e: raise GracefulDisconnect("query_channel_range timed out") from e self.logger.info('Received {} channel ids. (complete: {})'.format(len(ids), complete)) @@ -426,7 +429,7 @@ class Peer(Logger): async def _message_loop(self): try: - await asyncio.wait_for(self.initialize(), 10) + await asyncio.wait_for(self.initialize(), LN_P2P_NETWORK_TIMEOUT) except (OSError, asyncio.TimeoutError, HandshakeFailed) as e: raise GracefulDisconnect(f'initialize failed: {repr(e)}') from e async for msg in self.transport.read_messages(): @@ -480,7 +483,7 @@ class Peer(Logger): # dry run creating funding tx to see if we even have enough funds funding_tx_test = wallet.mktx([TxOutput(bitcoin.TYPE_ADDRESS, wallet.dummy_address(), funding_sat)], password, self.lnworker.config, nonlocal_only=True) - await asyncio.wait_for(self.initialized.wait(), 1) + await asyncio.wait_for(self.initialized.wait(), LN_P2P_NETWORK_TIMEOUT) feerate = self.lnworker.current_feerate_per_kw() local_config = self.make_local_config(funding_sat, push_msat, LOCAL) # for the first commitment transaction @@ -508,7 +511,7 @@ class Peer(Logger): channel_reserve_satoshis=local_config.reserve_sat, htlc_minimum_msat=1, ) - payload = await asyncio.wait_for(self.channel_accepted[temp_channel_id].get(), 5) + payload = await asyncio.wait_for(self.channel_accepted[temp_channel_id].get(), LN_P2P_NETWORK_TIMEOUT) if payload.get('error'): raise Exception('Remote Lightning peer reported error: ' + repr(payload.get('error'))) remote_per_commitment_point = payload['first_per_commitment_point'] @@ -583,13 +586,13 @@ class Peer(Logger): funding_txid=funding_txid_bytes, funding_output_index=funding_index, signature=sig_64) - payload = await asyncio.wait_for(self.funding_signed[channel_id].get(), 5) + payload = await asyncio.wait_for(self.funding_signed[channel_id].get(), LN_P2P_NETWORK_TIMEOUT) self.logger.info('received funding_signed') remote_sig = payload['signature'] chan.receive_new_commitment(remote_sig, []) # broadcast funding tx # TODO make more robust (timeout low? server returns error?) - await asyncio.wait_for(self.network.broadcast_transaction(funding_tx), 5) + await asyncio.wait_for(self.network.broadcast_transaction(funding_tx), LN_P2P_NETWORK_TIMEOUT) chan.open_with_first_pcp(remote_per_commitment_point, remote_sig) return chan @@ -1520,7 +1523,7 @@ class Peer(Logger): while True: our_sig, closing_tx = chan.make_closing_tx(scriptpubkey, payload['scriptpubkey'], fee_sat=our_fee) self.send_message('closing_signed', channel_id=chan.channel_id, fee_satoshis=our_fee, signature=our_sig) - cs_payload = await asyncio.wait_for(self.closing_signed[chan.channel_id].get(), 10) + cs_payload = await asyncio.wait_for(self.closing_signed[chan.channel_id].get(), LN_P2P_NETWORK_TIMEOUT) their_fee = int.from_bytes(cs_payload['fee_satoshis'], 'big') their_sig = cs_payload['signature'] if our_fee == their_fee: diff --git a/electrum/lnworker.py b/electrum/lnworker.py @@ -33,7 +33,7 @@ from .util import ignore_exceptions from .util import timestamp_to_datetime from .logging import Logger from .lntransport import LNTransport, LNResponderTransport -from .lnpeer import Peer +from .lnpeer import Peer, LN_P2P_NETWORK_TIMEOUT from .lnaddr import lnencode, LnAddr, lndecode from .ecc import der_sig_from_sig_string from .lnchannel import Channel, ChannelJsonEncoder @@ -731,7 +731,7 @@ class LNWallet(LNWorker): async def _open_channel_coroutine(self, connect_str, local_amount_sat, push_sat, password): peer = await self.add_peer(connect_str) # peer might just have been connected to - await asyncio.wait_for(peer.initialized.wait(), 5) + await asyncio.wait_for(peer.initialized.wait(), LN_P2P_NETWORK_TIMEOUT) chan = await peer.channel_establishment_flow( password, funding_sat=local_amount_sat + push_sat,