electrum

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

commit 48252318b8f39885df33d412c5850c69587b8784
parent 520b5703a4918ac46b88e753b3012b19cf8f8a5e
Author: SomberNight <somber.night@protonmail.com>
Date:   Fri, 12 Oct 2018 19:40:12 +0200

rebase follow-up

Diffstat:
Melectrum/lnbase.py | 18+++++++++---------
Melectrum/lnrouter.py | 2+-
Melectrum/lnwatcher.py | 11++++++-----
Melectrum/lnworker.py | 6+++---
4 files changed, 19 insertions(+), 18 deletions(-)

diff --git a/electrum/lnbase.py b/electrum/lnbase.py @@ -17,13 +17,12 @@ from typing import List import cryptography.hazmat.primitives.ciphers.aead as AEAD import aiorpcx -from .util import list_enabled_bits from . import bitcoin from . import ecc from .ecc import sig_string_from_r_and_s, get_r_and_s_from_sig_string from .crypto import sha256 from . import constants -from .util import PrintError, bh2u, print_error, bfh, log_exceptions +from .util import PrintError, bh2u, print_error, bfh, log_exceptions, list_enabled_bits, ignore_exceptions from .transaction import Transaction, TxOutput from .lnonion import new_onion_packet, OnionHopsDataSingle, OnionPerHop, decode_onion_error, OnionFailureCode from .lnaddr import lndecode @@ -506,7 +505,8 @@ class Peer(PrintError): self.lnworker.peers.pop(self.pubkey) return wrapper_func - @aiosafe + @ignore_exceptions # do not kill main_taskgroup + @log_exceptions @handle_disconnect async def main_loop(self): try: @@ -768,7 +768,7 @@ class Peer(PrintError): m.set_state('DISCONNECTED') raise Exception('funding outpoint mismatch') - @aiosafe + @log_exceptions async def reestablish_channel(self, chan): await self.initialized chan_id = chan.channel_id @@ -890,7 +890,7 @@ class Peer(PrintError): self.lnworker.save_channel(chan) asyncio.run_coroutine_threadsafe(coro, self.network.asyncio_loop) - @aiosafe + @log_exceptions async def handle_announcements(self, chan): h, local_node_sig, local_bitcoin_sig = self.send_announcement_signatures(chan) announcement_signatures_msg = await self.announcement_signatures[chan.channel_id].get() @@ -1011,7 +1011,7 @@ class Peer(PrintError): return h, node_signature, bitcoin_signature - @aiosafe + @log_exceptions async def on_update_fail_htlc(self, payload): channel_id = payload["channel_id"] htlc_id = int.from_bytes(payload["id"], "big") @@ -1138,7 +1138,7 @@ class Peer(PrintError): m.receive_new_commitment(commitment_signed_msg["signature"], htlc_sigs) return len(htlc_sigs) - @aiosafe + @log_exceptions async def receive_commitment_revoke_ack(self, htlc, decoded, payment_preimage): chan = self.channels[htlc['channel_id']] channel_id = chan.channel_id @@ -1172,7 +1172,7 @@ class Peer(PrintError): self.lnworker.save_channel(chan) self.commitment_signed[channel_id].put_nowait(payload) - @aiosafe + @log_exceptions async def on_update_fulfill_htlc(self, update_fulfill_htlc_msg): self.print_error("update_fulfill") chan = self.channels[update_fulfill_htlc_msg["channel_id"]] @@ -1251,7 +1251,7 @@ class Peer(PrintError): if chan_id not in self.closing_signed: raise Exception("Got unknown closing_signed") self.closing_signed[chan_id].put_nowait(payload) - @aiosafe + @log_exceptions async def on_shutdown(self, payload): # length of scripts allowed in BOLT-02 if int.from_bytes(payload['len'], 'big') not in (3+20+2, 2+20+1, 2+20, 2+32): diff --git a/electrum/lnrouter.py b/electrum/lnrouter.py @@ -282,7 +282,7 @@ class ChannelDB(JsonDB): self.ca_verifier = LNChannelVerifier(network, self) # FIXME if the channel verifier raises, it kills network.main_taskgroup - asyncio.run_coroutine_threadsafe(self.network.add_job(self.ca_verifier.main()), network.asyncio_loop) + asyncio.run_coroutine_threadsafe(self.network.add_job(self.ca_verifier.main), network.asyncio_loop) self.load_data() diff --git a/electrum/lnwatcher.py b/electrum/lnwatcher.py @@ -5,8 +5,8 @@ from collections import defaultdict import asyncio import jsonrpclib -from .util import PrintError, bh2u, bfh, NoDynamicFeeEstimates, aiosafe -from .lnutil import EncumberedTransaction, Outpoint +from .util import PrintError, bh2u, bfh, log_exceptions, ignore_exceptions +from .lnutil import EncumberedTransaction from . import wallet from .storage import WalletStorage from .address_synchronizer import AddressSynchronizer @@ -47,7 +47,7 @@ class LNWatcher(PrintError): watchtower_url = self.config.get('watchtower_url') self.watchtower = jsonrpclib.Server(watchtower_url) if watchtower_url else None self.watchtower_queue = asyncio.Queue() - self.network.start([self.watchtower_task]) + asyncio.run_coroutine_threadsafe(self.network.add_job(self.watchtower_task), self.network.asyncio_loop) def with_watchtower(func): def wrapper(self, *args, **kwargs): @@ -56,7 +56,8 @@ class LNWatcher(PrintError): return func(self, *args, **kwargs) return wrapper - @aiosafe + @ignore_exceptions + @log_exceptions async def watchtower_task(self): while True: name, args, kwargs = await self.watchtower_queue.get() @@ -89,7 +90,7 @@ class LNWatcher(PrintError): self.channel_info[address] = outpoint self.write_to_disk() - @aiosafe + @log_exceptions async def on_network_update(self, event, *args): if event in ('verified', 'wallet_updated'): wallet = args[0] diff --git a/electrum/lnworker.py b/electrum/lnworker.py @@ -15,8 +15,8 @@ from . import keystore from . import bitcoin from .keystore import BIP32_KeyStore from .bitcoin import sha256, COIN -from .util import bh2u, bfh, PrintError, InvoiceError, resolve_dns_srv, is_ip_address -from .lnbase import Peer, aiosafe +from .util import bh2u, bfh, PrintError, InvoiceError, resolve_dns_srv, is_ip_address, log_exceptions +from .lnbase import Peer from .lnaddr import lnencode, LnAddr, lndecode from .ecc import der_sig_from_sig_string from .lnchan import Channel @@ -158,7 +158,7 @@ class LNWorker(PrintError): self.channel_db.remove_channel(chan.short_channel_id) self.network.trigger_callback('channel', chan) - @aiosafe + @log_exceptions async def on_network_update(self, event, *args): # TODO # Race discovered in save_channel (assertion failing):