electrum

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

commit ea3e3ddbb8280f499bf2535d2a8a63dd174e2e44
parent 261ad804cad9c8a4f9dbc6595727a35cadc0204e
Author: SomberNight <somber.night@protonmail.com>
Date:   Sun, 13 Sep 2020 16:55:37 +0200

lnpeer: handle cooperative close edge-case

fix #6317

Diffstat:
Melectrum/address_synchronizer.py | 10+---------
Melectrum/gui/qt/main_window.py | 4++--
Melectrum/lnpeer.py | 8++++++--
Melectrum/util.py | 9+++++++++
4 files changed, 18 insertions(+), 13 deletions(-)

diff --git a/electrum/address_synchronizer.py b/electrum/address_synchronizer.py @@ -30,7 +30,7 @@ from typing import TYPE_CHECKING, Dict, Optional, Set, Tuple, NamedTuple, Sequen from . import bitcoin, util from .bitcoin import COINBASE_MATURITY -from .util import profiler, bfh, TxMinedInfo +from .util import profiler, bfh, TxMinedInfo, UnrelatedTransactionException from .transaction import Transaction, TxOutput, TxInput, PartialTxInput, TxOutpoint, PartialTransaction from .synchronizer import Synchronizer from .verifier import SPV @@ -48,14 +48,6 @@ TX_HEIGHT_LOCAL = -2 TX_HEIGHT_UNCONF_PARENT = -1 TX_HEIGHT_UNCONFIRMED = 0 -class AddTransactionException(Exception): - pass - - -class UnrelatedTransactionException(AddTransactionException): - def __str__(self): - return _("Transaction is unrelated to this wallet.") - class HistoryItem(NamedTuple): txid: str diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py @@ -60,12 +60,12 @@ from electrum.util import (format_time, UserFacingException, get_new_wallet_name, send_exception_to_crash_reporter, InvalidBitcoinURI, maybe_extract_bolt11_invoice, NotEnoughFunds, - NoDynamicFeeEstimates, MultipleSpendMaxTxOutputs) + NoDynamicFeeEstimates, MultipleSpendMaxTxOutputs, + AddTransactionException) from electrum.invoices import PR_TYPE_ONCHAIN, PR_TYPE_LN, PR_DEFAULT_EXPIRATION_WHEN_CREATING, Invoice from electrum.invoices import PR_PAID, PR_FAILED, pr_expiration_values, LNInvoice, OnchainInvoice from electrum.transaction import (Transaction, PartialTxInput, PartialTransaction, PartialTxOutput) -from electrum.address_synchronizer import AddTransactionException from electrum.wallet import (Multisig_Wallet, CannotBumpFee, Abstract_Wallet, sweep_preparations, InternalAddressCorruption) from electrum.version import ELECTRUM_VERSION diff --git a/electrum/lnpeer.py b/electrum/lnpeer.py @@ -23,7 +23,8 @@ from . import bitcoin, util from . import ecc from .ecc import sig_string_from_r_and_s, get_r_and_s_from_sig_string, der_sig_from_sig_string from . import constants -from .util import bh2u, bfh, log_exceptions, ignore_exceptions, chunks, SilentTaskGroup +from .util import (bh2u, bfh, log_exceptions, ignore_exceptions, chunks, SilentTaskGroup, + UnrelatedTransactionException) from . import transaction from .transaction import Transaction, TxOutput, PartialTxOutput, match_script_against_template from .logging import Logger @@ -1518,7 +1519,10 @@ class Peer(Logger): signing_pubkey=chan.config[REMOTE].multisig_key.pubkey.hex(), sig=bh2u(der_sig_from_sig_string(their_sig) + b'\x01')) # save local transaction and set state - self.lnworker.wallet.add_transaction(closing_tx) + try: + self.lnworker.wallet.add_transaction(closing_tx) + except UnrelatedTransactionException: + pass # this can happen if (~all the balance goes to REMOTE) chan.set_state(ChannelState.CLOSING) # broadcast await self.network.try_broadcasting(closing_tx, 'closing') diff --git a/electrum/util.py b/electrum/util.py @@ -119,6 +119,15 @@ class InvalidPassword(Exception): return _("Incorrect password") +class AddTransactionException(Exception): + pass + + +class UnrelatedTransactionException(AddTransactionException): + def __str__(self): + return _("Transaction is unrelated to this wallet.") + + class FileImportFailed(Exception): def __init__(self, message=''): self.message = str(message)