URI: 
       tlnpeer: fix and simplify tests in maybe_send_commitment - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit bbec1dceda76201763d4bfdc33e01db3002f06da
   DIR parent 39bae1c7cf56c62725975ed5293c00f80c091f7c
  HTML Author: ThomasV <thomasv@electrum.org>
       Date:   Mon, 12 Aug 2019 14:22:57 +0200
       
       lnpeer: fix and simplify tests in maybe_send_commitment
       
       Diffstat:
         M electrum/lnpeer.py                  |      20 +++++++-------------
       
       1 file changed, 7 insertions(+), 13 deletions(-)
       ---
   DIR diff --git a/electrum/lnpeer.py b/electrum/lnpeer.py
       t@@ -84,8 +84,6 @@ class Peer(Logger):
                #
                self.attempted_route = {}
                self.orphan_channel_updates = OrderedDict()
       -        self.sent_commitment_for_ctn_last = defaultdict(lambda: None)  # type: Dict[Channel, Optional[int]]
       -        self.recv_commitment_for_ctn_last = defaultdict(lambda: None)  # type: Dict[Channel, Optional[int]]
                self._local_changed_events = defaultdict(asyncio.Event)
                self._remote_changed_events = defaultdict(asyncio.Event)
                Logger.__init__(self)
       t@@ -1089,17 +1087,16 @@ class Peer(Logger):
                        self.network.path_finder.add_to_blacklist(short_chan_id)
        
            def maybe_send_commitment(self, chan: Channel):
       -        ctn_to_sign = chan.get_next_ctn(REMOTE)
       +        # REMOTE should revoke first before we can sign a new ctx
       +        if chan.hm.is_revack_pending(REMOTE):
       +            return
                # if there are no changes, we will not (and must not) send a new commitment
                next_htlcs, latest_htlcs = chan.hm.get_htlcs_in_next_ctx(REMOTE), chan.hm.get_htlcs_in_latest_ctx(REMOTE)
       -        if (next_htlcs == latest_htlcs
       -                and chan.get_next_feerate(REMOTE) == chan.get_latest_feerate(REMOTE)) \
       -                or ctn_to_sign == self.sent_commitment_for_ctn_last[chan]:
       +        if next_htlcs == latest_htlcs and chan.get_next_feerate(REMOTE) == chan.get_latest_feerate(REMOTE):
                    return
                self.logger.info(f'send_commitment. old number htlcs: {len(latest_htlcs)}, new number htlcs: {len(next_htlcs)}')
                sig_64, htlc_sigs = chan.sign_next_commitment()
                self.send_message("commitment_signed", channel_id=chan.channel_id, signature=sig_64, num_htlcs=len(htlc_sigs), htlc_signature=b"".join(htlc_sigs))
       -        self.sent_commitment_for_ctn_last[chan] = ctn_to_sign
        
            async def await_remote(self, chan: Channel, ctn: int):
                self.maybe_send_commitment(chan)
       t@@ -1157,12 +1154,9 @@ class Peer(Logger):
                if (chan.hm.get_htlcs_in_next_ctx(LOCAL) == chan.hm.get_htlcs_in_latest_ctx(LOCAL)
                        and chan.get_next_feerate(LOCAL) == chan.get_latest_feerate(LOCAL)):
                    raise RemoteMisbehaving('received commitment_signed without pending changes')
       -        # make sure ctn is new
       -        ctn_to_recv = chan.get_next_ctn(LOCAL)
       -        if ctn_to_recv == self.recv_commitment_for_ctn_last[chan]:
       -            raise RemoteMisbehaving('received commitment_signed with same ctn')
       -        self.recv_commitment_for_ctn_last[chan] = ctn_to_recv
       -
       +        # REMOTE should wait until we have revoked
       +        if chan.hm.is_revack_pending(LOCAL):
       +            raise RemoteMisbehaving('received commitment_signed before we revoked previous ctx')
                data = payload["htlc_signature"]
                htlc_sigs = [data[i:i+64] for i in range(0, len(data), 64)]
                chan.receive_new_commitment(payload["signature"], htlc_sigs)