electrum

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

commit 472e82e3871e9fe8535a2750dfd9f5ea7dcb2e4e
parent d383573bc39431f865d83f8e574e7f13e7f15019
Author: ThomasV <thomasv@electrum.org>
Date:   Fri,  1 Feb 2019 18:28:35 +0100

fix channel closure when it was requested by the remote party

Diffstat:
Melectrum/lnbase.py | 16+++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/electrum/lnbase.py b/electrum/lnbase.py @@ -1176,7 +1176,7 @@ class Peer(PrintError): self.shutdown_received[chan_id] = asyncio.Future() self.send_shutdown(chan) payload = await self.shutdown_received[chan_id] - txid = await self._shutdown(chan, payload) + txid = await self._shutdown(chan, payload, True) self.print_error('Channel closed', txid) return txid @@ -1191,7 +1191,7 @@ class Peer(PrintError): else: chan = self.channels[chan_id] self.send_shutdown(chan) - txid = await self._shutdown(chan, payload) + txid = await self._shutdown(chan, payload, False) self.print_error('Channel closed by remote peer', txid) def send_shutdown(self, chan: Channel): @@ -1199,7 +1199,7 @@ class Peer(PrintError): self.send_message('shutdown', channel_id=chan.channel_id, len=len(scriptpubkey), scriptpubkey=scriptpubkey) @log_exceptions - async def _shutdown(self, chan: Channel, payload): + async def _shutdown(self, chan: Channel, payload, is_local): # set state so that we stop accepting HTLCs chan.set_state('CLOSING') while len(chan.hm.htlcs_by_direction(LOCAL, RECEIVED)) > 0: @@ -1218,10 +1218,12 @@ class Peer(PrintError): break # TODO: negociate better our_fee = their_fee - # add their signature - i = chan.get_local_index() - closing_tx.add_signature_to_txin(0, i, bh2u(der_sig_from_sig_string(our_sig) + b'\x01')) - closing_tx.add_signature_to_txin(0, 1-i, bh2u(der_sig_from_sig_string(their_sig) + b'\x01')) + # index of our_sig + i = bool(chan.get_local_index()) + if not is_local: i = not i + # add signatures + closing_tx.add_signature_to_txin(0, int(i), bh2u(der_sig_from_sig_string(our_sig) + b'\x01')) + closing_tx.add_signature_to_txin(0, int(not i), bh2u(der_sig_from_sig_string(their_sig) + b'\x01')) # broadcast await self.network.broadcast_transaction(closing_tx) return closing_tx.txid()