electrum

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

commit 36f32651cc970b3429b56aa1a763374c50eee980
parent dba6cb8a966cc5590162826a5dae6df3b5d25290
Author: ThomasV <thomasv@electrum.org>
Date:   Sun, 16 Feb 2020 12:59:09 +0100

Define network.try_broadcasting() method.
Use it when rebroadcasting a force-close tx,
because the channel state is already set.

Diffstat:
Melectrum/lnworker.py | 19+++++--------------
Melectrum/network.py | 8++++++++
Melectrum/tests/test_lnpeer.py | 2+-
3 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/electrum/lnworker.py b/electrum/lnworker.py @@ -692,12 +692,12 @@ class LNWallet(LNWorker): peer.on_network_update(chan, conf) elif chan.get_state() == channel_states.FORCE_CLOSING: - txid = chan.force_close_tx().txid() + force_close_tx = chan.force_close_tx() + txid = force_close_tx.txid() height = self.lnwatcher.get_tx_height(txid).height - self.logger.info(f"force closing tx {txid}, height {height}") if height == TX_HEIGHT_LOCAL: self.logger.info('REBROADCASTING CLOSING TX') - await self.force_close_channel(chan.channel_id) + await self.network.try_broadcasting(force_close_tx, 'force-close') @ignore_exceptions @log_exceptions @@ -769,12 +769,7 @@ class LNWallet(LNWorker): self.logger.info(f'{name} could not claim output: {prevout}, dust') self.wallet.set_label(tx.txid(), name) if broadcast: - try: - await self.network.broadcast_transaction(tx) - except Exception as e: - self.logger.info(f'could NOT publish {name} for prevout: {prevout}, {str(e)}') - else: - self.logger.info(f'success: broadcasting {name} for prevout: {prevout}') + await self.network.try_broadcasting(tx, name) else: # it's OK to add local transaction, the fee will be recomputed try: @@ -1266,11 +1261,7 @@ class LNWallet(LNWorker): chan = self.channels[chan_id] tx = chan.force_close_tx() chan.set_state(channel_states.FORCE_CLOSING) - try: - await self.network.broadcast_transaction(tx) - except Exception as e: - self.logger.info(f'could NOT publish {tx.txid()}, {str(e)}') - return + await self.network.try_broadcasting(tx, 'force-close') return tx.txid() def remove_channel(self, chan_id): diff --git a/electrum/network.py b/electrum/network.py @@ -854,6 +854,14 @@ class Network(Logger): self.logger.info(f"unexpected txid for broadcast_transaction [DO NOT TRUST THIS MESSAGE]: {out} != {tx.txid()}") raise TxBroadcastHashMismatch(_("Server returned unexpected transaction ID.")) + async def try_broadcasting(self, tx, name): + try: + await self.broadcast_transaction(tx) + except Exception as e: + self.logger.info(f'error: could not broadcast {name} {tx.txid()}, {str(e)}') + else: + self.logger.info(f'success: broadcasting {name} {tx.txid()}') + @staticmethod def sanitize_tx_broadcast_response(server_msg) -> str: # Unfortunately, bitcoind and hence the Electrum protocol doesn't return a useful error code. diff --git a/electrum/tests/test_lnpeer.py b/electrum/tests/test_lnpeer.py @@ -64,7 +64,7 @@ class MockNetwork: def get_local_height(self): return 0 - async def broadcast_transaction(self, tx): + async def try_broadcasting(self, tx, name): if self.tx_queue: await self.tx_queue.put(tx)