URI: 
       tlnhtlc: also check received htlcs when validating commitment sigs - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit cc7ef49c43f3d6902e03068d9d7e9387becc4b27
   DIR parent 224226f427dd26594d30f9db5c252b38ecd497ec
  HTML Author: Janus <ysangkok@gmail.com>
       Date:   Fri, 21 Sep 2018 20:44:51 +0200
       
       lnhtlc: also check received htlcs when validating commitment sigs
       
       Diffstat:
         M electrum/lnhtlc.py                  |      23 ++++++++++++++---------
       
       1 file changed, 14 insertions(+), 9 deletions(-)
       ---
   DIR diff --git a/electrum/lnhtlc.py b/electrum/lnhtlc.py
       t@@ -316,13 +316,21 @@ class HTLCStateMachine(PrintError):
        
                _, this_point, _ = self.points
        
       -        if len(self.htlcs_in_remote) > 0 and len(pending_local_commitment.outputs()) == 3:
       +        if len(pending_local_commitment.outputs()) >= 3:
                    print("CHECKING HTLC SIGS")
       -            we_receive = True
       -            payment_hash = self.htlcs_in_remote[0].payment_hash
       -            amount_msat = self.htlcs_in_remote[0].amount_msat
       -            cltv_expiry = self.htlcs_in_remote[0].cltv_expiry
       -            htlc_tx = make_htlc_tx_with_open_channel(self, this_point, True, we_receive, amount_msat, cltv_expiry, payment_hash, pending_local_commitment, 0)
       +            assert len(pending_local_commitment.outputs()) == 3
       +            if len(self.htlcs_in_remote) > 0:
       +                assert len(self.htlcs_in_remote) == 1
       +                we_receive = True
       +                htlc = self.htlcs_in_remote[0]
       +            elif len(self.htlcs_in_local) > 0:
       +                assert len(self.htlcs_in_local) == 1
       +                we_receive = False
       +                htlc = self.htlcs_in_local[0]
       +            else:
       +                assert False
       +
       +            htlc_tx = make_htlc_tx_with_open_channel(self, this_point, True, we_receive, htlc.amount_msat, htlc.cltv_expiry, htlc.payment_hash, pending_local_commitment, 0)
                    pre_hash = Hash(bfh(htlc_tx.serialize_preimage(0)))
                    remote_htlc_pubkey = derive_pubkey(self.remote_config.htlc_basepoint.pubkey, this_point)
                    if not ecc.verify_signature(remote_htlc_pubkey, htlc_sigs[0], pre_hash):
       t@@ -451,9 +459,6 @@ class HTLCStateMachine(PrintError):
                    amount_msat = self.local_state.amount_msat + (received_this_batch - sent_this_batch)
                )
        
       -        self.balance(LOCAL)
       -        self.balance(REMOTE)
       -
                for pending_fee in self.fee_mgr:
                    if pending_fee.is_proposed():
                        if self.constraints.is_initiator: