URI: 
       tchannel_reestablish: assume that DLP is enabled, because we require it - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit 69ef9aa3d7c0dbbcb576f11cdb12552eea4b8af8
   DIR parent e42e17779d90ad45aa2c31fc8972376f07baa126
  HTML Author: ThomasV <thomasv@electrum.org>
       Date:   Tue, 11 Feb 2020 21:32:10 +0100
       
       channel_reestablish: assume that DLP is enabled, because we require it
       
       Diffstat:
         M electrum/lnpeer.py                  |      48 ++++++++++++-------------------
         M electrum/tests/test_lnpeer.py       |       1 +
       
       2 files changed, 20 insertions(+), 29 deletions(-)
       ---
   DIR diff --git a/electrum/lnpeer.py b/electrum/lnpeer.py
       t@@ -728,28 +728,21 @@ class Peer(Logger):
                oldest_unrevoked_remote_ctn = chan.get_oldest_unrevoked_ctn(REMOTE)
                latest_remote_ctn = chan.get_latest_ctn(REMOTE)
                next_remote_ctn = chan.get_next_ctn(REMOTE)
       +        assert self.localfeatures & LnLocalFeatures.OPTION_DATA_LOSS_PROTECT_OPT
                # send message
       -        dlp_enabled = self.localfeatures & LnLocalFeatures.OPTION_DATA_LOSS_PROTECT_OPT
       -        if dlp_enabled:
       -            if oldest_unrevoked_remote_ctn == 0:
       -                last_rev_secret = 0
       -            else:
       -                last_rev_index = oldest_unrevoked_remote_ctn - 1
       -                last_rev_secret = chan.revocation_store.retrieve_secret(RevocationStore.START_INDEX - last_rev_index)
       -            latest_secret, latest_point = chan.get_secret_and_point(LOCAL, latest_local_ctn)
       -            self.send_message(
       -                "channel_reestablish",
       -                channel_id=chan_id,
       -                next_local_commitment_number=next_local_ctn,
       -                next_remote_revocation_number=oldest_unrevoked_remote_ctn,
       -                your_last_per_commitment_secret=last_rev_secret,
       -                my_current_per_commitment_point=latest_point)
       +        if oldest_unrevoked_remote_ctn == 0:
       +            last_rev_secret = 0
                else:
       -            self.send_message(
       -                "channel_reestablish",
       -                channel_id=chan_id,
       -                next_local_commitment_number=next_local_ctn,
       -                next_remote_revocation_number=oldest_unrevoked_remote_ctn)
       +            last_rev_index = oldest_unrevoked_remote_ctn - 1
       +            last_rev_secret = chan.revocation_store.retrieve_secret(RevocationStore.START_INDEX - last_rev_index)
       +        latest_secret, latest_point = chan.get_secret_and_point(LOCAL, latest_local_ctn)
       +        self.send_message(
       +            "channel_reestablish",
       +            channel_id=chan_id,
       +            next_local_commitment_number=next_local_ctn,
       +            next_remote_revocation_number=oldest_unrevoked_remote_ctn,
       +            your_last_per_commitment_secret=last_rev_secret,
       +            my_current_per_commitment_point=latest_point)
                self.logger.info(f'channel_reestablish: sent channel_reestablish with '
                                 f'(next_local_ctn={next_local_ctn}, '
                                 f'oldest_unrevoked_remote_ctn={oldest_unrevoked_remote_ctn})')
       t@@ -823,8 +816,7 @@ class Peer(Logger):
                # option_data_loss_protect
                def are_datalossprotect_fields_valid() -> bool:
                    if their_local_pcp is None or their_claim_of_our_last_per_commitment_secret is None:
       -                # if DLP was enabled, absence of fields is not OK
       -                return not dlp_enabled
       +                return False
                    if their_oldest_unrevoked_remote_ctn > 0:
                        our_pcs, __ = chan.get_secret_and_point(LOCAL, their_oldest_unrevoked_remote_ctn - 1)
                    else:
       t@@ -845,14 +837,12 @@ class Peer(Logger):
        
                if not are_datalossprotect_fields_valid():
                    raise RemoteMisbehaving("channel_reestablish: data loss protect fields invalid")
       -        else:
       -            if dlp_enabled and should_close_they_are_ahead:
       -                self.logger.warning(f"channel_reestablish: remote is ahead of us! luckily DLP is enabled. remote PCP: {bh2u(their_local_pcp)}")
       -                # data_loss_protect_remote_pcp is used in lnsweep
       -                chan.set_data_loss_protect_remote_pcp(their_next_local_ctn - 1, their_local_pcp)
       -                self.lnworker.save_channel(chan)
       +
                if should_close_they_are_ahead:
       -            self.logger.warning(f"channel_reestablish: remote is ahead of us! They should force-close.")
       +            self.logger.warning(f"channel_reestablish: remote is ahead of us! They should force-close. Remote PCP: {bh2u(their_local_pcp)}")
       +            # data_loss_protect_remote_pcp is used in lnsweep
       +            chan.set_data_loss_protect_remote_pcp(their_next_local_ctn - 1, their_local_pcp)
       +            self.lnworker.save_channel(chan)
                    chan.peer_state = peer_states.BAD
                    return
                elif should_close_we_are_ahead:
   DIR diff --git a/electrum/tests/test_lnpeer.py b/electrum/tests/test_lnpeer.py
       t@@ -85,6 +85,7 @@ class MockLNWallet:
                self.logs = defaultdict(list)
                self.wallet = MockWallet()
                self.localfeatures = LnLocalFeatures(0)
       +        self.localfeatures |= LnLocalFeatures.OPTION_DATA_LOSS_PROTECT_OPT
                self.pending_payments = defaultdict(asyncio.Future)
        
            def get_invoice_status(self, key):