URI: 
       tsimplify points, remove side-effect in reestablish_channel - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit c3f63519226675c7da6851fd9dd0954d96705943
   DIR parent b5fd27c64c0254dcca9c9219cfd2cb3918542242
  HTML Author: ThomasV <thomasv@electrum.org>
       Date:   Thu,  7 Mar 2019 15:53:01 +0100
       
       simplify points, remove side-effect in reestablish_channel
       
       Diffstat:
         M electrum/lnchannel.py               |      25 +++++++++----------------
         M electrum/lnpeer.py                  |       6 ++----
       
       2 files changed, 11 insertions(+), 20 deletions(-)
       ---
   DIR diff --git a/electrum/lnchannel.py b/electrum/lnchannel.py
       t@@ -406,10 +406,7 @@ class Channel(PrintError):
            def revoke_current_commitment(self):
                self.print_error("revoke_current_commitment")
        
       -        last_secret, this_point, next_point, _ = self.points()
       -
                new_feerate = self.constraints.feerate
       -
                if self.pending_fee is not None:
                    if not self.constraints.is_initiator and self.pending_fee[FUNDEE_SIGNED]:
                        new_feerate = self.pending_fee.rate
       t@@ -443,19 +440,15 @@ class Channel(PrintError):
                received_this_batch = htlcsum(received)
                sent_this_batch = htlcsum(sent)
        
       +        last_secret, last_point = self.local_points(offset=-1)
       +        next_secret, next_point = self.local_points(offset=1)
                return RevokeAndAck(last_secret, next_point), (received_this_batch, sent_this_batch)
        
       -    def points(self):
       -        last_small_num = self.config[LOCAL].ctn
       -        this_small_num = last_small_num + 1
       -        next_small_num = last_small_num + 2
       -        last_secret = get_per_commitment_secret_from_seed(self.config[LOCAL].per_commitment_secret_seed, RevocationStore.START_INDEX - last_small_num)
       -        this_secret = get_per_commitment_secret_from_seed(self.config[LOCAL].per_commitment_secret_seed, RevocationStore.START_INDEX - this_small_num)
       -        this_point = secret_to_pubkey(int.from_bytes(this_secret, 'big'))
       -        next_secret = get_per_commitment_secret_from_seed(self.config[LOCAL].per_commitment_secret_seed, RevocationStore.START_INDEX - next_small_num)
       -        next_point = secret_to_pubkey(int.from_bytes(next_secret, 'big'))
       -        last_point = secret_to_pubkey(int.from_bytes(last_secret, 'big'))
       -        return last_secret, this_point, next_point, last_point
       +    def local_points(self, *, offset=0):
       +        ctn = self.config[LOCAL].ctn + offset
       +        secret = get_per_commitment_secret_from_seed(self.config[LOCAL].per_commitment_secret_seed, RevocationStore.START_INDEX - ctn)
       +        point = secret_to_pubkey(int.from_bytes(secret, 'big'))
       +        return secret, point
        
            def process_new_revocation_secret(self, per_commitment_secret: bytes):
                if not self.lnwatcher:
       t@@ -584,14 +577,14 @@ class Channel(PrintError):
        
            def pending_commitment(self, subject):
                assert type(subject) is HTLCOwner
       -        this_point = self.config[REMOTE].next_per_commitment_point if subject == REMOTE else self.points()[1]
       +        this_point = self.config[REMOTE].next_per_commitment_point if subject == REMOTE else self.local_points(offset=1)[1]
                ctn = self.config[subject].ctn + 1
                feerate = self.pending_feerate(subject)
                return self.make_commitment(subject, this_point, ctn, feerate, True)
        
            def current_commitment(self, subject):
                assert type(subject) is HTLCOwner
       -        this_point = self.config[REMOTE].current_per_commitment_point if subject == REMOTE else self.points()[3]
       +        this_point = self.config[REMOTE].current_per_commitment_point if subject == REMOTE else self.local_points(offset=0)[1]
                ctn = self.config[subject].ctn
                feerate = self.constraints.feerate
                return self.make_commitment(subject, this_point, ctn, feerate, False)
   DIR diff --git a/electrum/lnpeer.py b/electrum/lnpeer.py
       t@@ -573,10 +573,8 @@ class Peer(PrintError):
                        #    the receiving node sent, AND the receiving node
                        #    hasn't already received a closing_signed:
                        #        MUST re-send the revoke_and_ack.
       -                chan.config[LOCAL]=chan.config[LOCAL]._replace(
       -                    ctn=their_next_remote_ctn,
       -                )
       -                last_secret, this_point, next_point, _ = chan.points()
       +                last_secret, last_point = chan.local_points(offset=-1)
       +                next_secret, next_point = chan.local_points(offset=1)
                        self.send_message(
                            "revoke_and_ack",
                            channel_id=chan.channel_id,