URI: 
       tln: add two trimming tests, avoid negative numbers in htlc trim decision - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit 605d6ff5cafd8c4e8e502e9cda93819280fa3efa
   DIR parent 03c2b954d9f1caa102af293bdc9487813c32de40
  HTML Author: Janus <ysangkok@gmail.com>
       Date:   Fri,  6 Jul 2018 18:55:17 +0200
       
       ln: add two trimming tests, avoid negative numbers in htlc trim decision
       
       Diffstat:
         M lib/lnbase.py                       |       4 +---
         M lib/lnhtlc.py                       |       4 +++-
         M lib/tests/test_lnutil.py            |     265 +++++++++++++++----------------
       
       3 files changed, 133 insertions(+), 140 deletions(-)
       ---
   DIR diff --git a/lib/lnbase.py b/lib/lnbase.py
       t@@ -851,10 +851,8 @@ class Peer(PrintError):
                self.attempted_route[(chan.channel_id, htlc.htlc_id)] = route
        
                sig_64, htlc_sigs = chan.sign_next_commitment()
       -        htlc_sig = htlc_sigs[0]
       -
       -        self.send_message(gen_msg("commitment_signed", channel_id=chan.channel_id, signature=sig_64, num_htlcs=1, htlc_signature=htlc_sig))
        
       +        self.send_message(gen_msg("commitment_signed", channel_id=chan.channel_id, signature=sig_64, num_htlcs=len(htlc_sigs), htlc_signature=b"".join(htlc_sigs)))
                await self.receive_revoke(chan)
        
                self.revoke(chan)
   DIR diff --git a/lib/lnhtlc.py b/lib/lnhtlc.py
       t@@ -203,7 +203,9 @@ class HTLCStateMachine(PrintError):
                        assert len(htlcs) <= 1
                        for htlc in htlcs:
                            weight = HTLC_SUCCESS_WEIGHT if we_receive else HTLC_TIMEOUT_WEIGHT
       -                    if htlc.amount_msat // 1000 - weight * (self.remote_state.feerate // 1000) < self.remote_config.dust_limit_sat:
       +                    fee = self.remote_state.feerate // 1000 * weight
       +                    if htlc.amount_msat // 1000 < self.remote_config.dust_limit_sat + fee:
       +                        print("value too small, skipping. htlc amt: {}, weight: {}, remote feerate {}, remote dust limit {}".format( htlc.amount_msat, weight, self.remote_state.feerate, self.remote_config.dust_limit_sat))
                                continue
                            original_htlc_output_index = 0
                            args = [self.remote_state.next_per_commitment_point, for_us, we_receive, htlc.amount_msat + htlc.total_fee, htlc.cltv_expiry, htlc.payment_hash, self.pending_remote_commitment, original_htlc_output_index]
   DIR diff --git a/lib/tests/test_lnutil.py b/lib/tests/test_lnutil.py
       t@@ -3,6 +3,7 @@ import json
        from lib import bitcoin
        from lib.lnutil import RevocationStore, get_per_commitment_secret_from_seed, make_offered_htlc, make_received_htlc, make_commitment, make_htlc_tx_witness, make_htlc_tx_output, make_htlc_tx_inputs, secret_to_pubkey, derive_blinded_pubkey, derive_privkey, derive_pubkey, make_htlc_tx
        from lib.util import bh2u, bfh
       +from lib.transaction import Transaction
        
        funding_tx_id = '8984484a580b825b9972d7adb15050b3ab624ccd731946b3eeddb92f4e7ef6be'
        funding_output_index = 0
       t@@ -450,53 +451,40 @@ class TestLNUtil(unittest.TestCase):
                remote_htlcpubkey = remotepubkey
                local_htlcpubkey = localpubkey
        
       -        htlc2_cltv_timeout = 502
       -        htlc2_payment_preimage = b"\x02" * 32
       -        htlc2 = make_offered_htlc(local_revocation_pubkey, remote_htlcpubkey, local_htlcpubkey, bitcoin.sha256(htlc2_payment_preimage))
       -        # HTLC 2 offered amount 2000
       -        ref_htlc2_wscript = "76a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c820120876475527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae67a914b43e1b38138a41b37f7cd9a1d274bc63e3a9b5d188ac6868"
       -        self.assertEqual(htlc2, bfh(ref_htlc2_wscript))
       -
       -        htlc3_cltv_timeout = 503
       -        htlc3_payment_preimage = b"\x03" * 32
       -        htlc3 = make_offered_htlc(local_revocation_pubkey, remote_htlcpubkey, local_htlcpubkey, bitcoin.sha256(htlc3_payment_preimage))
       -        # HTLC 3 offered amount 3000
       -        ref_htlc3_wscript = "76a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c820120876475527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae67a9148a486ff2e31d6158bf39e2608864d63fefd09d5b88ac6868"
       -        self.assertEqual(htlc3, bfh(ref_htlc3_wscript))
       -
       -        htlc0_cltv_timeout = 500
       -        htlc0_payment_preimage = b"\x00" * 32
       -        htlc0 = make_received_htlc(local_revocation_pubkey, remote_htlcpubkey, local_htlcpubkey, bitcoin.sha256(htlc0_payment_preimage), htlc0_cltv_timeout)
       -        # HTLC 0 received amount 1000
       -        ref_htlc0_wscript = "76a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c8201208763a914b8bcb07f6344b42ab04250c86a6e8b75d3fdbbc688527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae677502f401b175ac6868"
       -        self.assertEqual(htlc0, bfh(ref_htlc0_wscript))
       -
       -        htlc1_cltv_timeout = 501
       -        htlc1_payment_preimage = b"\x01" * 32
       -        htlc1 = make_received_htlc(local_revocation_pubkey, remote_htlcpubkey, local_htlcpubkey, bitcoin.sha256(htlc1_payment_preimage), htlc1_cltv_timeout)
       -        # HTLC 1 received amount 2000
       -        ref_htlc1_wscript = "76a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c8201208763a9144b6b2e5444c2639cc0fb7bcea5afba3f3cdce23988527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae677502f501b175ac6868"
       -        self.assertEqual(htlc1, bfh(ref_htlc1_wscript))
       -
       -        htlc4_cltv_timeout = 504
       -        htlc4_payment_preimage = b"\x04" * 32
       -        htlc4 = make_received_htlc(local_revocation_pubkey, remote_htlcpubkey, local_htlcpubkey, bitcoin.sha256(htlc4_payment_preimage), htlc4_cltv_timeout)
       -        # HTLC 4 received amount 4000
       -        ref_htlc4_wscript = "76a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c8201208763a91418bc1a114ccf9c052d3d23e28d3b0a9d1227434288527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae677502f801b175ac6868"
       -        self.assertEqual(htlc4, bfh(ref_htlc4_wscript))
       -
       -        # to_local amount 6988000 wscript 63210212a140cd0c6539d07cd08dfe09984dec3251ea808b892efeac3ede9402bf2b1967029000b2752103fd5960528dc152014952efdb702a88f71e3c1653b2314431701ec77e57fde83c68ac
       -        # to_remote amount 3000000 P2WPKH(0394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b)
       +        htlc_cltv_timeout = {}
       +        htlc_payment_preimage = {}
       +        htlc = {}
       +
       +        htlc_cltv_timeout[2] = 502
       +        htlc_payment_preimage[2] = b"\x02" * 32
       +        htlc[2] = make_offered_htlc(local_revocation_pubkey, remote_htlcpubkey, local_htlcpubkey, bitcoin.sha256(htlc_payment_preimage[2]))
       +
       +        htlc_cltv_timeout[3] = 503
       +        htlc_payment_preimage[3] = b"\x03" * 32
       +        htlc[3] = make_offered_htlc(local_revocation_pubkey, remote_htlcpubkey, local_htlcpubkey, bitcoin.sha256(htlc_payment_preimage[3]))
       +
       +        htlc_cltv_timeout[0] = 500
       +        htlc_payment_preimage[0] = b"\x00" * 32
       +        htlc[0] = make_received_htlc(local_revocation_pubkey, remote_htlcpubkey, local_htlcpubkey, bitcoin.sha256(htlc_payment_preimage[0]), htlc_cltv_timeout[0])
       +
       +        htlc_cltv_timeout[1] = 501
       +        htlc_payment_preimage[1] = b"\x01" * 32
       +        htlc[1] = make_received_htlc(local_revocation_pubkey, remote_htlcpubkey, local_htlcpubkey, bitcoin.sha256(htlc_payment_preimage[1]), htlc_cltv_timeout[1])
       +
       +        htlc_cltv_timeout[4] = 504
       +        htlc_payment_preimage[4] = b"\x04" * 32
       +        htlc[4] = make_received_htlc(local_revocation_pubkey, remote_htlcpubkey, local_htlcpubkey, bitcoin.sha256(htlc_payment_preimage[4]), htlc_cltv_timeout[4])
       +
                remote_signature = "304402204fd4928835db1ccdfc40f5c78ce9bd65249b16348df81f0c44328dcdefc97d630220194d3869c38bc732dd87d13d2958015e2fc16829e74cd4377f84d215c0b70606"
       -        # local_signature = 30440220275b0c325a5e9355650dc30c0eccfbc7efb23987c24b556b9dfdd40effca18d202206caceb2c067836c51f296740c7ae807ffcbfbf1dd3a0d56b6de9a5b247985f06
parazyd.org:70 /git/electrum/commit/605d6ff5cafd8c4e8e502e9cda93819280fa3efa.gph:123: line too long