electrum

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

commit d477e3489f88c26ea633187647aea0606c01fdf0
parent 0f00f4f6554d2afc503b63b9510e9c864fc23111
Author: ThomasV <thomasv@electrum.org>
Date:   Sat,  8 Jun 2019 17:46:53 +0200

lnworker: fix reestablish_peer_for_given_channel by passing chan explicitly

Diffstat:
Melectrum/lnworker.py | 42++++++++++++++++++++++--------------------
1 file changed, 22 insertions(+), 20 deletions(-)

diff --git a/electrum/lnworker.py b/electrum/lnworker.py @@ -911,32 +911,34 @@ class LNWallet(LNWorker): self.network.trigger_callback('channels', self.wallet) self.network.trigger_callback('wallet_updated', self.wallet) - async def reestablish_peers_and_channels(self): - async def reestablish_peer_for_given_channel(): - # try last good address first - peer = self.channel_db.get_last_good_address(chan.node_id) - if peer: - last_tried = self._last_tried_peer.get(peer, 0) - if last_tried + PEER_RETRY_INTERVAL_FOR_CHANNELS < now: - await self._add_peer(peer.host, peer.port, peer.pubkey) - return - # try random address for node_id - node_info = self.channel_db.nodes_get(chan.node_id) - if not node_info: return - addresses = self.channel_db.get_node_addresses(node_info) - if not addresses: return - adr_obj = random.choice(addresses) - host, port = adr_obj.host, adr_obj.port - peer = LNPeerAddr(host, port, chan.node_id) + async def reestablish_peer_for_given_channel(self, chan): + now = time.time() + # try last good address first + peer = self.channel_db.get_last_good_address(chan.node_id) + if peer: last_tried = self._last_tried_peer.get(peer, 0) if last_tried + PEER_RETRY_INTERVAL_FOR_CHANNELS < now: - await self._add_peer(host, port, chan.node_id) + await self._add_peer(peer.host, peer.port, peer.pubkey) + return + # try random address for node_id + node_info = self.channel_db.nodes_get(chan.node_id) + if not node_info: + return + addresses = self.channel_db.get_node_addresses(node_info) + if not addresses: + return + adr_obj = random.choice(addresses) + host, port = adr_obj.host, adr_obj.port + peer = LNPeerAddr(host, port, chan.node_id) + last_tried = self._last_tried_peer.get(peer, 0) + if last_tried + PEER_RETRY_INTERVAL_FOR_CHANNELS < now: + await self._add_peer(host, port, chan.node_id) + async def reestablish_peers_and_channels(self): while True: await asyncio.sleep(1) with self.lock: channels = list(self.channels.values()) - now = time.time() for chan in channels: if chan.is_closed(): continue @@ -948,7 +950,7 @@ class LNWallet(LNWorker): if not chan.should_try_to_reestablish_peer(): continue peer = self.peers.get(chan.node_id, None) - coro = peer.reestablish_channel(chan) if peer else reestablish_peer_for_given_channel() + coro = peer.reestablish_channel(chan) if peer else self.reestablish_peer_for_given_channel(chan) await self.network.main_taskgroup.spawn(coro) def current_feerate_per_kw(self):