Define network.try_broadcasting() method.

Use it when rebroadcasting a force-close tx,
because the channel state is already set.
This commit is contained in:
ThomasV 2020-02-16 12:59:09 +01:00
parent dba6cb8a96
commit 36f32651cc
3 changed files with 14 additions and 15 deletions

View file

@ -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):

View file

@ -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.

View file

@ -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)